:root {
  --navy: #1f4e79;
  --navy-d: #163a5c;
  --bg: #f4f6f9;
  --card: #fff;
  --line: #dde3ea;
  --text: #1c2430;
  --muted: #6b7686;
  --ok: #1e7f4f;
  --ok-bg: #e3f4ea;
  --warn: #a15c00;
  --warn-bg: #fff1d6;
  --err: #b3261e;
  --err-bg: #fde7e5;
  --in: #1e7f4f;
  --out: #b3261e;
  --brk: #8a6d00;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 15px; line-height: 1.6;
}
a { color: var(--navy); }
h1 { font-size: 1.35rem; margin: .4em 0 .6em; }
h2 { font-size: 1.05rem; margin: 1.2em 0 .5em; }
.card h2:first-child, .card h2.span2:first-of-type { margin-top: 0; }
small, .small { font-size: .82rem; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- ヘッダー ---------- */
.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1180px; margin: 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; padding: 8px 14px; }
.brand { color: #fff; font-weight: 700; text-decoration: none; }
.nav { display: flex; flex-wrap: wrap; gap: 2px; flex: 1; }
.nav a { color: #dbe7f3; text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.nav a.active, .nav a:hover { background: rgba(255,255,255,.15); color: #fff; }
.nav .count { background: #ffb020; color: #222; border-radius: 10px; font-size: .75rem; padding: 0 6px; margin-left: 4px; font-weight: 700; }
.userbox { display: flex; gap: 10px; align-items: center; font-size: .85rem; }
.userbox a { color: #dbe7f3; }
.linkbtn { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }
.topbar .linkbtn { color: #dbe7f3; }
.linkbtn.danger { color: var(--err); }
form.inline { display: inline; }

.container { max-width: 1180px; margin: 0 auto; padding: 14px; }
.is-employee .container { max-width: 560px; }
.narrow { max-width: 560px; }

/* ---------- 部品 ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin: 12px 0; }
.flash { padding: 10px 14px; border-radius: 8px; margin: 8px 0; background: var(--ok-bg); color: var(--ok); border: 1px solid #bfe3cd; }
.flash.error { background: var(--err-bg); color: var(--err); border-color: #f3c2bd; }
.flash.warn { background: var(--warn-bg); color: var(--warn); border-color: #f1d79c; }
.flash.info { background: #e8f0fa; color: var(--navy); border-color: #c6d8ee; }
.badge { display: inline-block; font-size: .75rem; padding: 1px 7px; border-radius: 10px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.muted { background: #eceff3; color: var(--muted); }
.chip { display: inline-block; background: #eef2f7; border-radius: 6px; padding: 1px 7px; margin: 2px 4px 2px 0; font-size: .85rem; }

.btn { display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 7px 14px; border-radius: 8px; font: inherit; cursor: pointer; text-decoration: none; line-height: 1.3; }
.btn:hover { background: #f0f3f7; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-d); }
.btn.danger { background: #fff; border-color: #e5a29c; color: var(--err); }
.btn.small { padding: 3px 9px; font-size: .85rem; }
.btn.block { display: block; width: 100%; padding: 12px; font-size: 1rem; }
.btn.disabled { opacity: .4; pointer-events: none; }

label { display: block; margin: 0 0 12px; font-size: .9rem; color: #3a4554; }
label.check, label.radio { display: flex; align-items: center; gap: 6px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid #c8d1dc; border-radius: 8px;
  font: inherit; font-size: 16px; background: #fff; color: var(--text);
}
input[type=checkbox], input[type=radio] { display: inline-block; width: auto; margin: 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 14px; padding: 10px 12px; }
legend { font-weight: 600; padding: 0 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.form-grid .span2 { grid-column: 1 / -1; }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; margin: 8px 0; }
.inline-form label { margin: 0; }
.inline-form input, .inline-form select { width: auto; }
.filters { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

.tbl { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 8px 0 16px; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid #edf0f4; text-align: left; vertical-align: top; }
.tbl th { background: #f3f6fa; font-size: .82rem; color: #4a5565; font-weight: 600; white-space: nowrap; }
.tbl tr.invalid td { color: #9aa3ae; text-decoration: line-through; }
.tbl tr.invalid td:last-child, .tbl tr.invalid td .badge { text-decoration: none; }
.tbl tr.group-start td { border-top: 2px solid #e2e7ee; }
.tbl tr.retired td { color: var(--muted); }
.tbl .reason { max-width: 260px; }
.tbl.audit .json { font-family: ui-monospace, Menlo, monospace; font-size: .75rem; word-break: break-all; max-width: 320px; }

.dl { display: grid; grid-template-columns: 7em 1fr; gap: 4px 10px; margin: 0; }
.dl dt { color: var(--muted); font-size: .85rem; }
.dl dd { margin: 0; word-break: break-all; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.map { width: 100%; height: 260px; border: 1px solid var(--line); border-radius: 8px; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 10px 0; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px; text-decoration: none; color: var(--text); display: flex; flex-direction: column; }
.stat .num { font-size: 1.8rem; font-weight: 700; text-align: left; }
.stat .lbl { font-size: .85rem; color: var(--muted); }
.stat.alert { border-color: #f1c26b; background: #fffaf0; }
.stat.alert .num { color: var(--warn); }
.state-pill { font-size: .8rem; padding: 2px 9px; border-radius: 10px; background: #eceff3; color: var(--muted); white-space: nowrap; }
.state-pill.working { background: var(--ok-bg); color: var(--ok); }
.state-pill.break { background: var(--warn-bg); color: var(--warn); }
.req-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.req-actions input { width: 160px; margin: 0; padding: 5px 8px; font-size: .85rem; }

/* ---------- 認証 ---------- */
.auth-card { max-width: 380px; margin: 40px auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.note { font-size: .82rem; color: var(--muted); }

/* ---------- 打刻（スマホ） ---------- */
.clock-card { text-align: center; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 16px 12px; }
.clock-card .who { color: var(--muted); font-size: .9rem; }
.clock { font-size: 3rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em; line-height: 1.2; }
.clock-card .date { color: var(--muted); }
.clock-card .state { margin-top: 8px; display: inline-block; padding: 4px 14px; border-radius: 20px; font-weight: 700; background: #eceff3; color: var(--muted); }
.clock-card .state.working { background: var(--ok-bg); color: var(--ok); }
.clock-card .state.break { background: var(--warn-bg); color: var(--warn); }
.punch-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0 6px; }
.punch-btn {
  border: 0; border-radius: 14px; padding: 26px 10px; font-size: 1.25rem; font-weight: 700; color: #fff; cursor: pointer;
  font-family: inherit; touch-action: manipulation; box-shadow: 0 2px 0 rgba(0,0,0,.12);
}
.punch-btn.in { background: var(--in); }
.punch-btn.out { background: var(--out); }
.punch-btn.brk { background: var(--brk); }
.punch-btn:disabled { background: #d3d8de; color: #8d96a1; box-shadow: none; cursor: default; }
.punch-btn.busy { opacity: .7; }
.punch-status { text-align: center; min-height: 1.4em; color: var(--navy); font-weight: 600; margin: 4px 0; }
.punch-list { list-style: none; margin: 0; padding: 0; }
.punch-list li { display: flex; gap: 12px; align-items: center; padding: 6px 0; border-bottom: 1px solid #eef1f5; }
.punch-list .t { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 4.5em; }

.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0; }
.summary { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; font-weight: 600; }
.day-cards { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.day-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.day-card.incomplete { border-color: #f1c26b; }
.day-head { display: flex; justify-content: space-between; }
.day-head span { font-weight: 700; font-variant-numeric: tabular-nums; }
.req-list { list-style: none; padding: 0; margin: 0; }
.req-list li { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; }
.punch-choice { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; padding: 6px 0; border-top: 1px dashed var(--line); }
.punch-choice span { font-weight: 600; min-width: 8em; }
.punch-choice label { margin: 0; }

@media (max-width: 720px) {
  .form-grid, .detail-grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: 1fr; }
  .tbl { font-size: .85rem; }
  .is-admin .tbl { display: block; overflow-x: auto; }
  .topbar-inner { padding: 6px 10px; }
  .nav { order: 3; flex: 1 1 100%; justify-content: space-around; }
  .brand { flex: 1; }
}

/* ---------- 勤怠集計（第2段階） ---------- */
.month-nav.left { justify-content: flex-start; }
.nowrap { white-space: nowrap; }
.warn-text { color: var(--warn); }
.tbl.book td, .tbl.book th { padding: 5px 8px; }
.tbl.book tr.sun td:first-child { color: var(--err); }
.tbl.book tr.sat td:first-child { color: var(--navy); }
.tbl.book tr.empty td { background: #fafbfc; }
.tbl tfoot th { background: #eef2f7; color: var(--text); }

/* ---------- 給与（第3段階） ---------- */
.err-text { color: var(--err); }
.slip-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.slip-grid .card { margin: 0; }
.tbl.plain { border: 0; margin: 0; }
.tbl.plain td { padding: 5px 4px; }
.tbl tr.total td { font-weight: 700; background: #f3f6fa; }
.net-box { margin: 14px 0; text-align: right; font-size: 1.1rem; background: #fff; border: 2px solid var(--navy); border-radius: 10px; padding: 12px 16px; }
.net-box strong { font-size: 1.6rem; margin-left: 12px; }
.run-actions { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; }
.run-actions p { flex-basis: 100%; margin: 0; }
.month-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0 12px; }
.scroll-x { overflow-x: auto; }
.tbl.ledger td, .tbl.ledger th { padding: 5px 7px; }
.year-input { width: 6em; }
.slip-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
button:disabled.btn { opacity: .45; cursor: not-allowed; }
@media (max-width: 720px) {
  .slip-grid { grid-template-columns: 1fr; }
  .month-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- 設定：打刻場所の地図 ---------- */
.loc-map-wrap p { margin: 4px 0 0; }
.loc-map { height: 360px; border: 1px solid var(--line, #d6dde6); border-radius: 8px; cursor: crosshair; z-index: 0; }
@media (max-width: 720px) { .loc-map { height: 300px; } }

/* ---------- シフト・残業申請 ---------- */
.today-shift { margin-top: 6px; font-size: .95rem; opacity: .9; }
.shift-list { list-style: none; padding: 0; margin: 0; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.shift-list li { display: flex; justify-content: space-between; padding: 8px 12px; border-top: 1px solid var(--line); }
.shift-list li:first-child { border-top: 0; }
.shift-list li.muted { color: var(--muted, #888); }
.inline-form.compact { gap: 4px; margin: 2px 0; }
.inline-form.compact input { padding: 4px 6px; font-size: .85rem; max-width: 12em; }
