:root {
  --bg: #f4f6fb; --card: #ffffff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --accent: #0ea5e9; --accent-ink: #ffffff; --danger: #dc2626; --warn: #d97706; --ok: #16a34a;
  --off: #f1f5f9; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.05);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --card: #111a2e; --text: #e5edf7; --muted: #8fa0b8; --line: #1f2b44;
    --off: #0e1626; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden; max-width: 100vw; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, Segoe UI, Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* layout */
.topbar { position: sticky; top: 0; z-index: 20; background: #0f172a; color: #fff; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 800; letter-spacing: -.02em; font-size: 17px; }
.brand span { color: #38bdf8; }
.topbar nav { display: flex; gap: 2px; margin-left: 8px; overflow-x: auto; }
.topbar nav a { color: #cbd5e1; padding: 6px 10px; border-radius: 8px; font-weight: 600; font-size: 14px; white-space: nowrap; }
.topbar nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; color: #94a3b8; white-space: nowrap; }
.topbar .who b { color: #fff; }
.page { max-width: 1100px; margin: 0 auto; padding: 16px; padding-bottom: 80px; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 760px) { .grid.two { grid-template-columns: 1fr; } .topbar nav { display: none; } .page { padding: 12px; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card h2 { margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* bottom tab bar (mobile) */
.tabbar { display: none; width: 100%; box-sizing: border-box; position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 20; }
.tabbar a { flex: 1; text-align: center; color: var(--muted); font-size: 11px; font-weight: 600; padding: 4px 0; border-radius: 10px; }
.tabbar a .ico { display: block; font-size: 20px; line-height: 1.1; }
.tabbar a.active { color: var(--accent); }
@media (max-width: 760px) { .tabbar { display: flex; } }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600; font-size: 14px; }
.btn:hover { border-color: #94a3b8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { padding: 7px 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field label:has(> input[type=checkbox]) { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
.field label > input[type=checkbox] { width: 18px; height: 18px; margin: 0; }
.field input, .field select, .field textarea { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field .hint { font-size: 12px; color: var(--muted); }
.seg { display: inline-flex; background: var(--off); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.monthnav { display: flex; align-items: center; gap: 8px; }
.monthnav .label { font-weight: 800; font-size: 20px; min-width: 150px; text-align: center; letter-spacing: -.02em; }
@media (max-width: 760px) { .monthnav { width: 100%; justify-content: space-between; } .monthnav .label { font-size: 18px; } .toolbar { flex-direction: column; align-items: stretch; } .toolbar .row:last-child { justify-content: space-between; } }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
@media (max-width: 1000px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 760px) {
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .tiles .tile:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .tile { padding: 12px 14px; }
  .tile .v { font-size: 24px; }
}
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .k { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 28px; font-weight: 800; letter-spacing: -.03em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* tables */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.card > table, .card > div > table { min-width: 0; }
@media (max-width: 760px) { th, td { padding: 8px 6px; } .card h2 { font-size: 16px; } }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 7px; vertical-align: -1px; }
.bar { height: 6px; border-radius: 4px; background: var(--off); overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; border-radius: 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--off); border: 1px solid var(--line); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.tfoot td { font-weight: 700; border-top: 2px solid var(--line); }

/* calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .h { font-size: 11px; font-weight: 700; color: var(--muted); text-align: center; text-transform: uppercase; padding: 4px 0; }
.cal .d { min-width: 0; overflow: hidden; min-height: 74px; border: 1px solid var(--line); border-radius: 10px; padding: 6px; background: var(--card); cursor: pointer; position: relative; display: flex; flex-direction: column; gap: 4px; transition: border-color .15s; }
.cal .d:hover { border-color: var(--accent); }
.cal .d.off { background: var(--off); }
.cal .d.empty { border: 0; background: transparent; cursor: default; }
.cal .d.future { opacity: .55; }
.cal .d.today .n { background: var(--accent); color: #fff; }
.cal .d .n { font-size: 12px; font-weight: 700; width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.cal .d.leave { background: color-mix(in srgb, var(--danger) 14%, var(--card)); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.cal .d.leave .n { color: var(--danger); }
.cal .p.lv { background: var(--danger); color: #fff; }
.cal .d.missed::after { content: ""; position: absolute; right: 8px; top: 10px; width: 6px; height: 6px; border-radius: 50%; background: var(--warn); opacity: .8; }
.cal .p { font-size: 11.5px; font-weight: 600; line-height: 1.2; padding: 3px 6px; border-radius: 6px; color: #fff; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cal .x { font-size: 10px; font-weight: 700; color: var(--warn); }
@media (max-width: 760px) {
  .cal { gap: 3px; }
  .cal .h { font-size: 10px; }
  .cal .d { min-height: 58px; padding: 4px 3px; border-radius: 8px; gap: 3px; }
  .cal .d .n { width: 20px; height: 20px; font-size: 11px; }
  .cal .p { font-size: 9.5px; padding: 2px 3px; border-radius: 4px; display: block; white-space: nowrap; text-overflow: ellipsis; -webkit-line-clamp: unset; }
  .cal .x { font-size: 8.5px; }
  .cal .d.missed::after { right: 4px; top: 5px; width: 5px; height: 5px; }
  .card { padding: 12px; }
  .legend { gap: 8px 12px; font-size: 11px; }
}
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 10px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(2,6,23,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 50; padding: 0; }
.modal { background: var(--card); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; }
@media (min-width: 640px) { .modal-bg { align-items: center; padding: 20px; } .modal { border-radius: 18px; } }
.modal h2 { margin-bottom: 14px; }
@media (max-width: 640px) { .modal .btn { padding: 11px 14px; } .modal .row.actions { flex-direction: column-reverse; align-items: stretch; } .modal .row.actions .row { flex-direction: column-reverse; } .modal .row.actions .btn { width: 100%; } }
.btn, .seg button, .cal .d { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.tabbar a { padding: 6px 0; }

/* login */
.login-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(1200px 600px at 20% -10%, #0ea5e933, transparent), var(--bg); }
.login { width: 100%; max-width: 380px; }
.login .brand { color: var(--text); font-size: 26px; margin-bottom: 4px; }
.login .brand span { color: var(--accent); }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 99; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.err { background: var(--danger); }
.empty { text-align: center; padding: 26px; color: var(--muted); }
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 140px; }
.list-item select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.input-inline { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
@media (max-width: 760px) { .row > .input-inline, .row > select.input-inline { flex: 1 1 140px; min-width: 0; } .list-item select { flex: 1 1 120px; min-width: 0; } .list-item .grow { flex-basis: 100%; } }
.pill-days { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-days label { display: inline-flex; align-items: center; gap: 4px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 600; }
.pill-days input { margin: 0; }
.notice { padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--warn) 12%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); color: var(--text); font-size: 13px; margin-bottom: 12px; }

/* month log list */
.loglist { display: flex; flex-direction: column; }
.logrow { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.logrow:last-child { border-bottom: 0; }
.logrow .grow { flex: 1; min-width: 0; }
.logrow .grow > div:first-child { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logrow .ld { width: 40px; text-align: center; line-height: 1.1; flex-shrink: 0; }
.logrow .ld b { display: block; font-size: 16px; }
.logrow .ld span { font-size: 10px; color: var(--muted); text-transform: uppercase; font-weight: 700; }
.logrow .dot { margin: 0; flex-shrink: 0; }

/* calendar hint */
.hintpill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; padding: 5px 11px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); white-space: nowrap; animation: hintpulse 2.4s ease-in-out 3; }
@keyframes hintpulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); } 50% { box-shadow: 0 0 0 6px transparent; } }
@media (max-width: 760px) { .hintpill { font-size: 11.5px; padding: 4px 9px; } }
