:root {
  --bg: #f5f6f8; --surface: #fff; --surface-2: #f0f2f5; --border: #e1e4e8; --text: #1b1f24; --muted: #5d6673;
  --accent: #2357d9; --accent-ink: #fff;
  --good: #1a7f37; --good-bg: #e6f4ea; --warn: #9a6700; --warn-bg: #fff4d6; --bad: #c62828; --bad-bg: #fde8e8;
  --info: #1f5fbf; --info-bg: #e3edfb; --leave: #6f42c1; --leave-bg: #efe8fb; --off: #6b7280; --off-bg: #eceef1;
  --radius: 8px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1f242c; --border: #2c333d; --text: #e6e9ee; --muted: #9aa4b2;
    --accent: #6b9bff; --accent-ink: #0b1020;
    --good: #57c27a; --good-bg: #16301f; --warn: #e3b341; --warn-bg: #33290f; --bad: #ff7b72; --bad-bg: #3a1a1a;
    --info: #79b0ff; --info-bg: #15263f; --leave: #b694f5; --leave-bg: #2a2140; --off: #9aa4b2; --off-bg: #232830; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 12px; } h2 { font-size: 16px; margin: 20px 0 8px; } h3 { font-size: 14px; margin: 12px 0 6px; }
button, .btn { font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--bad); }
button.sm { padding: 2px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: inline-flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }

.layout { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
nav.side { background: var(--surface); border-right: 1px solid var(--border); padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow: auto; }
nav.side .brand { font-weight: 700; padding: 4px 10px 14px; }
nav.side a { display: block; padding: 8px 10px; border-radius: 6px; color: var(--text); }
nav.side a.on { background: var(--info-bg); color: var(--info); font-weight: 600; }
nav.side a:hover { text-decoration: none; background: var(--surface-2); }
main { padding: 16px 22px 60px; min-width: 0; }
.topbar { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-bottom: 10px; flex-wrap: wrap; }
.topbar .who { color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; border-bottom: 2px solid transparent; color: var(--muted); }
.tabs a.on { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; } .nowrap { white-space: nowrap; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12px; color: var(--muted); }
.delta { font-size: 12px; font-weight: 600; white-space: nowrap; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); } .delta.flat { color: var(--muted); }

table.t { width: 100%; border-collapse: collapse; background: var(--surface); }
table.t th, table.t td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; z-index: 1; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t tfoot td { font-weight: 650; background: var(--surface-2); }
.scroll { overflow: auto; max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius); }
.scroll.tall { max-height: 70vh; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-present { background: var(--good-bg); color: var(--good); }
.st-working { background: var(--info-bg); color: var(--info); }
.st-half, .st-pending { background: var(--warn-bg); color: var(--warn); }
.st-absent { background: var(--bad-bg); color: var(--bad); }
.st-leave { background: var(--leave-bg); color: var(--leave); }
.st-off, .st-holiday, .st-future, .st-na { background: var(--off-bg); color: var(--off); }
.flag { color: var(--bad); font-weight: 600; } .ok { color: var(--good); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); font-size: 12px; margin: 1px; }
.chip.manual { background: var(--warn-bg); }
.chip button { border: 0; background: none; padding: 0 2px; color: var(--muted); }

/* spreadsheet */
.sheet-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
table.sheet { border-collapse: collapse; background: var(--surface); }
table.sheet th { font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 6px; text-align: left; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
table.sheet td { border: 1px solid var(--border); padding: 0; }
table.sheet td.ro { padding: 4px 8px; white-space: nowrap; color: var(--muted); }
table.sheet input, table.sheet select { border: 0; border-radius: 0; width: 100%; min-width: 70px; padding: 6px; background: transparent; }
table.sheet input[data-k="name"] { min-width: 160px; }
table.sheet tr.dirty td { background: var(--warn-bg); }
table.sheet tr.err td { background: var(--bad-bg); }
table.sheet td.act { padding: 2px 4px; white-space: nowrap; border: 0; }
.err-list { color: var(--bad); margin: 6px 0; }

/* calendar */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); max-width: min(1100px, 96vw); width: 100%; }
dialog.narrow { max-width: 440px; }
dialog::backdrop { background: rgb(0 0 0 / .45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); gap: 10px; }
.dlg-body { padding: 14px 16px; max-height: 80vh; overflow: auto; }
.dlg-body form { display: grid; gap: 10px; }
.dlg-body form label { width: 100%; } .dlg-body form input, .dlg-body form select { width: 100%; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; min-width: 0; }
.cal .wd { font-size: 11px; color: var(--muted); text-align: center; }
.cal .d { min-height: 64px; border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; cursor: pointer; font-size: 11px; background: var(--surface); text-align: left; display: flex; flex-direction: column; gap: 1px; }
.cal .d:hover, .cal .d.sel { outline: 2px solid var(--accent); }
.cal .d .n { font-weight: 700; font-size: 13px; }
.cal .d { overflow: hidden; }
.cal .d.present { background: var(--good-bg); } .cal .d.half, .cal .d.pending { background: var(--warn-bg); } .cal .d.absent { background: var(--bad-bg); }
.cal .d.leave { background: var(--leave-bg); } .cal .d.off, .cal .d.holiday { background: var(--off-bg); } .cal .d.working { background: var(--info-bg); }
.cal .d.na { opacity: .35; }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.metrics div { background: var(--surface-2); border-radius: 6px; padding: 8px 10px; }
.metrics b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.metrics span { font-size: 12px; color: var(--muted); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; }

.login { max-width: 360px; margin: 12vh auto; }
.login form { display: grid; gap: 12px; } .login label, .login input { width: 100%; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 99; max-width: 90vw; }
#toast.show { opacity: 1; } #toast.err { background: var(--bad); color: #fff; }
.rule { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; }
.rule input[type=number] { width: 90px; }
.qr { width: 260px; height: 260px; background: #fff; padding: 8px; border-radius: 8px; }
.perm select { padding: 2px 4px; font-size: 12px; }
.menu-btn { display: none; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  nav.side { position: fixed; z-index: 50; width: 230px; transform: translateX(-100%); transition: transform .2s; }
  nav.side.open { transform: none; box-shadow: 0 0 40px rgb(0 0 0 / .3); }
  .menu-btn { display: inline-block; margin-right: auto; }
  main { padding: 12px 12px 60px; }
  .cal .d { min-height: 48px; font-size: 10px; padding: 2px 3px; }
  .cal .d .x { display: none; }
}
#attT { width: max-content; min-width: 100%; }
#attT td:nth-last-child(2) { max-width: 220px; }
#attT td:last-child { max-width: 320px; }
.chip { white-space: nowrap; }
[hidden] { display: none !important; }
