:root {
  --bg: #f4f6f5; --surface: #ffffff; --ink: #14201d; --muted: #5d6b67; --line: #dce3e0;
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: #e1f2ef;
  --ok: #15803d; --ok-soft: #e3f5e8; --warn: #b45309; --warn-soft: #fdf0d9; --bad: #b91c1c; --bad-soft: #fde6e6;
  --wait: #475569; --wait-soft: #e8edf2; --radius: 12px; --shadow: 0 1px 2px rgba(20,32,29,.06), 0 2px 8px rgba(20,32,29,.05);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513; --surface: #17211e; --ink: #e8efec; --muted: #9fb0aa; --line: #2a3733;
    --brand: #2dd4bf; --brand-ink: #062320; --brand-soft: #123530;
    --ok: #4ade80; --ok-soft: #12301d; --warn: #fbbf24; --warn-soft: #36290c; --bad: #f87171; --bad-soft: #3b1717;
    --wait: #a6b4c2; --wait-soft: #202b33; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.55; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
h2 { font-size: 1.15rem; } h3 { font-size: 1.02rem; }
p { margin: 0 0 .8em; }
.boot, .muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; } .center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; }
.stack > * + * { margin-top: .9rem; }
.hidden { display: none !important; }

/* ---- 共通レイアウト ---- */
.shell { max-width: 1100px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }
.topbar { background: var(--brand); color: var(--brand-ink); padding: calc(10px + env(safe-area-inset-top)) 16px 10px; }
.topbar .in { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.topbar .name { font-weight: 700; flex: 1; }
.topbar button { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.55); min-height: 36px; padding: 0 12px; font-size: .85rem; }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 10px 0 0; scrollbar-width: none; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; border: 0; background: transparent; color: var(--muted); padding: 10px 14px; border-radius: 10px 10px 0 0; font-weight: 600; min-height: 44px; position: relative; }
.tab[aria-selected="true"] { color: var(--brand); box-shadow: inset 0 -3px 0 var(--brand); }
.tab .dot { position: absolute; top: 6px; right: 4px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--bad); color: #fff; font-size: .7rem; line-height: 18px; text-align: center; padding: 0 4px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

/* ---- フォーム ---- */
button, input, select, textarea { font: inherit; color: inherit; }
button { min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; }
button:hover { border-color: var(--brand); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .tab:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 1px; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }
button.small { min-height: 34px; padding: 0 10px; font-size: .85rem; }
button.icon { min-height: 36px; width: 36px; padding: 0; font-size: 1.3rem; line-height: 1; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
textarea { min-height: 120px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9rem; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; }
.field { display: block; }
.field .lbl { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field .hint { display: block; font-size: .8rem; color: var(--muted); margin-top: 3px; }
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.error { color: var(--bad); background: var(--bad-soft); padding: 10px 12px; border-radius: 10px; }
.notice { background: var(--warn-soft); color: var(--ink); border-left: 4px solid var(--warn); padding: 10px 12px; border-radius: 6px; }
.okbox { background: var(--ok-soft); border-left: 4px solid var(--ok); padding: 10px 12px; border-radius: 6px; }

/* ---- 表 ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: nowrap; }
th { font-size: .78rem; color: var(--muted); font-weight: 700; background: color-mix(in srgb, var(--bg) 60%, var(--surface)); position: sticky; top: 0; }
td.wrap { white-space: normal; }
td.r, th.r { text-align: right; }
tr.sum td { font-weight: 700; border-top: 2px solid var(--line); }

/* ---- バッジ ---- */
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--wait-soft); color: var(--wait); margin: 1px 3px 1px 0; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); } .badge.bad { background: var(--bad-soft); color: var(--bad); } .badge.brand { background: var(--brand-soft); color: var(--brand); }

/* ---- ログイン ---- */
.auth { max-width: 420px; margin: 8vh auto 0; padding: 0 16px; }
.auth h1 { font-size: 1.4rem; text-align: center; margin-bottom: 4px; }
.auth .sub { text-align: center; color: var(--muted); margin-bottom: 20px; }

/* ---- 打刻（スタッフ） ---- */
.clockface { text-align: center; padding: 8px 0 4px; }
.clockface .date { color: var(--muted); font-weight: 600; }
.clockface .time { font-size: 3.2rem; font-weight: 800; letter-spacing: .02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.state { text-align: center; margin: 8px 0 14px; font-weight: 700; }
.punch { width: 100%; min-height: 96px; font-size: 1.6rem; border-radius: 18px; border: 0; color: #fff; background: var(--brand); box-shadow: 0 6px 18px color-mix(in srgb, var(--brand) 35%, transparent); }
.punch.out { background: #c2410c; box-shadow: 0 6px 18px rgba(194,65,12,.3); }
.punch:disabled { box-shadow: none; }
.pinbox input { text-align: center; font-size: 1.6rem; letter-spacing: .5em; font-variant-numeric: tabular-nums; }
.meter { height: 12px; background: var(--wait-soft); border-radius: 6px; overflow: hidden; margin: 6px 0; }
.meter > i { display: block; height: 100%; background: var(--ok); }
.meter.near > i { background: var(--warn); } .meter.over > i { background: var(--bad); }
.shift-item { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.shift-item:last-child { border: 0; }
.shift-item .d { width: 5.5em; font-weight: 700; flex: none; }

/* ---- 本日の出勤状況 ---- */
.summary { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stat .n { font-size: 1.8rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { font-size: .8rem; color: var(--muted); font-weight: 600; }
.stat.late { background: var(--bad-soft); border-color: var(--bad); } .stat.late .n { color: var(--bad); }
.stat.working .n { color: var(--ok); }
.brow { display: grid; grid-template-columns: 6.5em 1fr auto; gap: 8px 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.brow:last-child { border: 0; }
.brow .st { font-weight: 800; font-size: .85rem; padding: 4px 8px; border-radius: 8px; text-align: center; }
.st.late, .st.absent { background: var(--bad-soft); color: var(--bad); }
.st.waiting { background: var(--wait-soft); color: var(--wait); }
.st.working { background: var(--ok-soft); color: var(--ok); }
.st.done { background: var(--brand-soft); color: var(--brand); }
.st.substituted { background: var(--warn-soft); color: var(--warn); }
.brow .who { font-weight: 700; }
.brow .meta { font-size: .85rem; color: var(--muted); }
.extra { background: var(--warn-soft); border-radius: 10px; padding: 10px 12px; margin-top: 8px; }
.extra .cands { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* ---- モーダル・トースト ---- */
.modal-back { position: fixed; inset: 0; background: rgba(8,14,12,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
@media (min-width: 640px) { .modal-back { align-items: center; } }
.modal { background: var(--surface); width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; }
@media (min-width: 640px) { .modal { border-radius: 16px; } }
.modal.wide { max-width: 900px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 6px; position: sticky; top: 0; background: var(--surface); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 8px 16px 16px; }
.modal-foot { padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface); }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #14201d; color: #fff; padding: 12px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 80; max-width: min(92vw, 520px); font-weight: 600; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #991b1b; }

/* ---- 請求書（印刷用） ---- */
.invoice { background: #fff; color: #111; padding: 28px; max-width: 800px; margin: 0 auto; border: 1px solid var(--line); }
.invoice h1 { text-align: center; letter-spacing: .5em; font-size: 1.6rem; }
.invoice table th { background: #f1f1f1; color: #333; position: static; }
.invoice td, .invoice th { border: 1px solid #bbb; }
.invoice .total { font-size: 1.3rem; font-weight: 800; }
@media print {
  body { background: #fff; }
  .topbar, .tabs, .noprint, .toast { display: none !important; }
  .shell { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .invoice { border: 0; padding: 0; }
}
@media (max-width: 520px) {
  .brow { grid-template-columns: 5.2em 1fr; }
  .brow .act { grid-column: 1 / -1; }
  .clockface .time { font-size: 2.8rem; }
}

/* ---- 微調整 ---- */
.shell { padding-top: 14px; }
.topbar .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar button { padding: 0 10px; flex: none; }
.who .badge { margin-left: 6px; }
.table-wrap + p, .table-wrap + .notice { margin-top: 10px; }
.tabs { margin-top: -14px; }

/* ---- 向かう・遅れる ---- */
.nextcard { border-color: var(--brand); border-width: 2px; }
.nextcard .where { font-weight: 700; }
.countdown { font-size: 2.4rem; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; text-align: center; margin: 6px 0 2px; }
.countdown.late { color: var(--bad); }
.countdown.notified { color: var(--warn); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.btn-row button { min-height: 64px; font-size: 1.1rem; }
.btn-go { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn-late { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 48px; min-width: 64px; padding: 0 14px; border-radius: 999px; font-size: 1rem; }
.chip[aria-pressed="true"] { background: var(--warn); border-color: var(--warn); color: #fff; }
.st.notified { background: var(--warn-soft); color: var(--warn); }
.stat.notified { background: var(--warn-soft); border-color: var(--warn); } .stat.notified .n { color: var(--warn); }
.commute { margin-top: 2px; font-size: .85rem; color: var(--warn); font-weight: 600; }
details.guide { background: var(--brand-soft); border-radius: 10px; padding: 10px 14px; }
details.guide summary { cursor: pointer; font-weight: 700; min-height: 32px; }
details.guide ol { margin: 8px 0 0; padding-left: 1.3em; } details.guide li { margin-bottom: 6px; }
a { color: var(--brand); }

/* ---- ふりがな・英語表記 ---- */
ruby { ruby-position: over; }
rt { font-size: .5em; font-weight: 500; letter-spacing: 0; }
.i18n .en { display: block; font-size: .78em; font-weight: 500; opacity: .85; line-height: 1.3; margin-top: 1px; }
.punch .i18n .en, .btn-row .i18n .en { font-size: .6em; }
button .i18n { display: block; line-height: 1.35; }
th .i18n .en { font-size: .85em; }
.langbtn { min-width: 44px; padding: 0 10px; font-weight: 800; }
body:has(ruby) .state, body:has(ruby) .shift-item { line-height: 1.9; }

.topbar .in.wrap { flex-wrap: wrap; row-gap: 6px; }
.topbar .in.wrap .name { flex: 1 1 8em; }
.topbar button { font-size: .8rem; line-height: 1.25; padding: 4px 10px; }
.topbar button .i18n .en { font-size: .7em; opacity: .9; }

.auth form button.primary { width: 100%; }
.state .where { font-weight: 700; margin-top: 2px; }
