:root {
  --navy: #1f3864;
  --navy-light: #2f4f8f;
  --gold: #b8912f;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #6b7280;
  --line: #e3e6ec;
  --green: #17803d;
  --red: #c0392b;
  --amber: #b06f00;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(20, 30, 60, 0.07);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font-family: inherit; font-size: 16px; }
button { cursor: pointer; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f7f8fa; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-light); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--navy); text-decoration: underline; }
.btn.danger { color: var(--red); border-color: #f0c9c4; }
.btn.danger:hover { background: #fdf2f1; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

.hidden { display: none !important; }

/* ============ 打刻画面 ============ */
.punch-body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(170deg, #1f3864 0%, #16294a 100%);
  color: #fff;
}
.punch-head {
  padding: 18px 16px 6px;
  text-align: center;
}
.punch-store { font-size: 14px; opacity: .8; letter-spacing: .04em; }
.punch-clock {
  font-size: 60px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.punch-date { font-size: 15px; opacity: .85; margin-top: 2px; }

.punch-main {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.punch-main > section { display: flex; flex-direction: column; gap: 12px; }

.panel-title { font-size: 15px; opacity: .85; text-align: center; margin-bottom: 2px; }

.staff-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.staff-btn {
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .25);
  color: #fff;
  border-radius: 12px;
  padding: 18px 10px;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
}
.staff-btn:hover { background: rgba(255, 255, 255, .18); }
.staff-btn .working { display: block; font-size: 12px; font-weight: 500; color: #ffd97a; margin-top: 4px; }

.me-name { font-size: 30px; font-weight: 700; text-align: center; }
.me-status { text-align: center; font-size: 15px; opacity: .85; min-height: 22px; }

.big-btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 18px;
  padding: 34px 16px;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: .1em;
  color: #fff;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .18);
  transition: transform .08s, box-shadow .08s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, .18); }
.big-btn.in { background: linear-gradient(180deg, #1fa055 0%, #17803d 100%); }
.big-btn.out { background: linear-gradient(180deg, #e08a2b 0%, #c06a10 100%); }
.big-btn .sub { display: block; font-size: 14px; font-weight: 600; letter-spacing: .04em; opacity: .9; margin-top: 6px; }

/* 打刻画面のシフト表示 */
.my-shifts { margin-top: 4px; }
.next-shift {
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: center;
  font-size: 15px;
  line-height: 1.6;
}
.next-shift .label { display: block; font-size: 12px; opacity: .75; letter-spacing: .06em; margin-bottom: 2px; }
.next-shift .when { font-size: 20px; font-weight: 800; }
.next-shift .time { font-size: 22px; font-weight: 800; color: #ffd97a; font-variant-numeric: tabular-nums; }
.shift-toggle {
  display: block; width: 100%; margin-top: 8px;
  background: none; border: none; color: #fff; opacity: .8;
  font-size: 14px; text-decoration: underline; padding: 6px;
}
.shift-list {
  margin-top: 6px;
  background: rgba(0, 0, 0, .18);
  border-radius: 12px;
  padding: 6px 4px;
  max-height: 260px;
  overflow-y: auto;
}
.shift-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; font-size: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.shift-row:last-child { border-bottom: none; }
.shift-row .d { font-variant-numeric: tabular-nums; }
.shift-row .t { font-weight: 700; font-variant-numeric: tabular-nums; }
.shift-row.past { opacity: .4; }
.shift-row.today { background: rgba(255, 217, 122, .16); border-radius: 8px; }
.shift-row.today .t { color: #ffd97a; }
.shift-empty { padding: 14px; text-align: center; font-size: 14px; opacity: .7; }

.punch-foot { padding: 10px 16px 22px; text-align: center; }
.punch-foot button { color: #fff; opacity: .75; background: none; border: none; text-decoration: underline; font-size: 14px; }

.msg {
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
}
.msg.err { background: rgba(255, 90, 70, .16); border: 1px solid rgba(255, 120, 100, .4); }
.admin-link {
  display: inline-block;
  color: #ffd97a;
  font-weight: 700;
  text-decoration: underline;
  padding: 6px 4px;
}
.msg.warn { background: rgba(255, 200, 60, .16); border: 1px solid rgba(255, 210, 90, .45); }

/* 打刻完了 */
.done { text-align: center; padding: 10px; }
.done-mark { font-size: 76px; line-height: 1; }
.done-title { font-size: 30px; font-weight: 800; margin-top: 8px; }
.done-time { font-size: 54px; font-weight: 800; font-variant-numeric: tabular-nums; margin: 10px 0 4px; }
.done-note { font-size: 15px; opacity: .88; line-height: 1.7; }

.spinner {
  width: 26px; height: 26px; margin: 0 auto;
  border: 3px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ 管理画面 ============ */
.admin-head {
  background: var(--navy);
  color: #fff;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.admin-head h1 { font-size: 17px; margin: 0; font-weight: 700; }
.admin-head .spacer { flex: 1; }
.admin-head button { background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.25); color: #fff; }
.admin-head button:hover { background: rgba(255,255,255,.24); }

.tabs { display: flex; gap: 4px; padding: 0 18px; background: var(--navy); }
.tab {
  background: none; border: none; color: rgba(255,255,255,.7);
  padding: 10px 16px; font-size: 14px; font-weight: 600;
  border-bottom: 3px solid transparent;
}
.tab.active { color: #fff; border-bottom-color: var(--gold); }

.wrap { max-width: 1100px; margin: 0 auto; padding: 18px; }
/* 勤務予定表はスタッフ数だけ横に伸びる。実際の幅は表に合わせてJSが決める
   （少人数のときに右側が大きく空かないよう、必要な分だけ広げる） */
.wrap.wide { max-width: none; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; color: var(--navy); }
.card h2 .hint { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 8px; }

.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input, .field select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
}
.field input:focus, .field select:focus { outline: 2px solid #c9d6f0; border-color: var(--navy-light); }
.field.w-sm input, .field.w-sm select { width: 110px; }
.field.w-md input, .field.w-md select { width: 180px; }
.field.w-lg input { width: 280px; }

.check { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.check input { width: 17px; height: 17px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { background: #f7f8fa; font-size: 12px; color: var(--muted); font-weight: 700; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.ctr, th.ctr { text-align: center; }
tr.warn td { background: #fff8e6; }
tbody tr:hover td { background: #f4f7fd; }
tr.warn:hover td { background: #fdf2d8; }
.table-scroll { overflow-x: auto; }

td input[type="time"], td input[type="text"], td input[type="date"] {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}
td input.dirty { border-color: var(--amber); background: #fffbf0; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.pill.gray { background: #eceef2; color: var(--muted); }
.pill.red { background: #fdeceb; color: var(--red); }
.pill.amber { background: #fff3d9; color: var(--amber); }
.pill.green { background: #e7f5ec; color: var(--green); }

.sum-cards { display: flex; gap: 12px; flex-wrap: wrap; }
.sum-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  min-width: 150px;
  background: #fbfcfe;
}
.sum-card .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.sum-card .v { font-size: 24px; font-weight: 800; color: var(--navy); font-variant-numeric: tabular-nums; }
.sum-card .v small { font-size: 13px; font-weight: 600; color: var(--muted); }

.note { font-size: 12px; color: var(--muted); line-height: 1.7; }
/* シフト表 */
/* 縦スクロールを表の中に閉じ込める。こうしないと見出し行のstickyが成立しない
   （高さ制限のないスクロール枠では top:0 が効かず、見出しがページごと流れ去る） */
.shift-scroll { max-height: calc(100vh - 180px); overflow: auto; }

/* stickyなセルは border-collapse:collapse だと枠線が消えるので separate にする。
   table-layout:fixed が肝。既定の auto だと余った幅が列に不均等に配られ、
   スタッフが少ないとき列幅が 218/758/758 のようにバラバラになる。
   fixed なら余りをスタッフ列に均等配分できる。狭いときは JS が付ける
   min-width（1人あたり222px）で下限を守り、横スクロールに切り替わる。 */
.shift-table { border-collapse: separate; border-spacing: 0; table-layout: fixed; width: 100%; }
.shift-table th, .shift-table td { padding: 4px 8px; white-space: nowrap; }

/* 見出し行（スタッフ名）を上に固定 */
.shift-table thead th { position: sticky; top: 0; z-index: 3; background: #f7f8fa; }

/* 日付・曜の2列を左に固定。横スクロールしても「何日の行か」を見失わないため */
.shift-table th:nth-child(1), .shift-table td:nth-child(1) {
  position: sticky; left: 0; z-index: 2; width: 58px; min-width: 58px;
}
.shift-table th:nth-child(2), .shift-table td:nth-child(2) {
  position: sticky; left: 58px; z-index: 2; width: 36px; min-width: 36px;
  border-right: 2px solid var(--line);
}
.shift-table thead th:nth-child(1), .shift-table thead th:nth-child(2) { z-index: 4; }
/* 固定列は不透明にしないと、下を流れるセルが透けて見える */
.shift-table tbody td:nth-child(1), .shift-table tbody td:nth-child(2) { background: #fff; }

.shift-table td.day { font-variant-numeric: tabular-nums; font-weight: 600; }
.shift-table tr.sat td { background: #f0f6ff; }
.shift-table tr.sun td { background: #fff4f4; }
.shift-table tr.today td { background: #fffbe6; }
.shift-table tr.today td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
.shift-table input[type="time"] { width: 92px; font-size: 13px; padding: 3px 5px; }
.shift-table input.filled { background: #eef4ff; border-color: #b9cbee; font-weight: 600; }
.shift-table input.pending { border-color: var(--amber); background: #fffbf0; }

.save-state { font-size: 13px; font-weight: 600; color: var(--muted); }
.save-state.saving { color: var(--navy); }
.save-state.saved { color: var(--green); }
.save-state.pending { color: var(--amber); }
.save-state.error { color: var(--red); }
.shift-table tfoot td { font-weight: 700; background: #f7f8fa; border-top: 2px solid var(--line); }
.shift-table tfoot td:nth-child(1) { position: sticky; left: 0; z-index: 2; background: #f7f8fa; }
/* 列が広がったときに見出し（中央寄せ）と入力欄の位置がずれないよう中央に置く */
.shift-cell { display: flex; align-items: center; justify-content: center; gap: 3px; }

/* 1日分の削除ボタン。予定がある日にだけ出す（is-hidden のときも幅は保って列がガタつかないようにする） */
.cell-clear {
  flex: none;
  width: 22px; height: 22px;
  margin-left: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 15px; line-height: 1;
  display: grid; place-items: center;
  transition: background .12s, color .12s, border-color .12s;
}
.cell-clear:hover { background: #fdf2f1; color: var(--red); border-color: #f0c9c4; }
.cell-clear.is-hidden { visibility: hidden; }
.shift-cell span { color: var(--muted); font-size: 12px; }

.wd-picker { display: flex; gap: 3px; }
.wd-picker label {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px; font-weight: 700; cursor: pointer; background: #fff; user-select: none;
}
.wd-picker input { display: none; }
.wd-picker input:checked + span { color: #fff; }
.wd-picker label:has(input:checked) { background: var(--navy); border-color: var(--navy); color: #fff; }

.warn-box {
  margin-top: 12px;
  background: #fff8e6;
  border: 1px solid #f0dcae;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.8;
  color: var(--amber);
}
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #1c2333; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.2); z-index: 50;
}
.toast.err { background: var(--red); }

/* ログイン */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; width: 100%; max-width: 340px; text-align: center; }
.login-card h1 { font-size: 18px; color: var(--navy); margin: 0 0 4px; }
.login-card p { font-size: 13px; color: var(--muted); margin: 0 0 18px; }
.login-card input { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; margin-bottom: 10px; }
.login-card .btn { width: 100%; }
.login-err { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* QR */
.qr-box { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.qr-img { width: 260px; height: 260px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.qr-url { font-size: 12px; word-break: break-all; background: #f7f8fa; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--muted); }

/* 印刷用ポスター */
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .print-poster { display: block !important; }
}
.print-poster { display: none; text-align: center; padding: 30px; }
.print-poster h1 { font-size: 34px; margin: 0 0 6px; }
.print-poster h2 { font-size: 20px; color: #444; margin: 0 0 24px; font-weight: 500; }
.print-poster img { width: 380px; height: 380px; }
.print-poster ol { text-align: left; max-width: 420px; margin: 24px auto 0; font-size: 15px; line-height: 2; }

@media (max-width: 640px) {
  .wrap { padding: 12px; }
  .card { padding: 14px; }
  .field.w-lg input { width: 100%; }
}
