:root {
  --paper: #EEF0F2; --surface: #FFFFFF; --sunken: #E4E8EC; --rest: #F4F6F8; --today: #EAF1FC;
  --ink: #16202B; --muted: #5A6672; --line: #D6DCE2; --line-strong: #AEB8C2;
  --accent: #1F4E9E; --accent-ink: #FFFFFF; --accent-tint: #E3ECFA;
  --present-bg: #DCE8FB; --present-fg: #17407F; --half-bg: #FFEFC7; --half-fg: #7A5200;
  --red: #B42318; --red-tint: #FDECEA; --green: #17734A; --green-tint: #E3F4EA; --amber: #9A5B00;
  --shadow: 0 8px 28px rgba(22, 32, 43, .18);
  --font-ui: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #11161C; --surface: #1A212A; --sunken: #232C37; --rest: #1E2630; --today: #1F2D44;
    --ink: #E7ECF2; --muted: #98A5B3; --line: #2C3744; --line-strong: #46556A;
    --accent: #7FA8F0; --accent-ink: #0E1620; --accent-tint: #1F2F4A;
    --present-bg: #223656; --present-fg: #A9C6FF; --half-bg: #3D3216; --half-fg: #F2C66B;
    --red: #FF8A7D; --red-tint: #3A1D1A; --green: #5FD08F; --green-tint: #15301F; --amber: #F0B25A; --shadow: 0 8px 28px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #11161C; --surface: #1A212A; --sunken: #232C37; --rest: #1E2630; --today: #1F2D44;
  --ink: #E7ECF2; --muted: #98A5B3; --line: #2C3744; --line-strong: #46556A;
  --accent: #7FA8F0; --accent-ink: #0E1620; --accent-tint: #1F2F4A;
  --present-bg: #223656; --present-fg: #A9C6FF; --half-bg: #3D3216; --half-fg: #F2C66B;
  --red: #FF8A7D; --red-tint: #3A1D1A; --green: #5FD08F; --green-tint: #15301F; --amber: #F0B25A; --shadow: 0 8px 28px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--paper); color: var(--ink); font-family: var(--font-ui); font-size: 14px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.mono, .num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
#app { display: flex; flex-direction: column; min-height: 100%; }
.boot { margin: auto; text-align: center; color: var(--muted); }

/* ---------- top bar ---------- */
.top { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.topin { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; text-decoration: none; color: inherit; }
.brand img { width: 34px; height: 34px; border-radius: 8px; flex: none; }
.brand b { display: block; font-size: 1rem; letter-spacing: .02em; line-height: 1.1; }
.brand small { display: block; color: var(--muted); font-size: .72rem; }
.who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.who .av { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-tint); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; overflow: hidden; }
.who .av img { width: 100%; height: 100%; object-fit: cover; }
.who .nm { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.who .nm b { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 12rem; }
.chip { display: inline-block; font-size: .66rem; letter-spacing: .06em; text-transform: uppercase; font-weight: 600; color: var(--muted); }
.nav { display: flex; gap: 2px; padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { flex: none; padding: 9px 10px 8px; border-bottom: 3px solid transparent; color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap; }
.nav a:hover { color: var(--ink); }
.nav a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.demo-bar { background: var(--half-bg); color: var(--half-fg); font-size: .8rem; padding: 6px 16px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.demo-bar button { border: 1px solid currentColor; background: transparent; border-radius: 6px; padding: 1px 8px; font-weight: 600; }

/* ---------- page ---------- */
main { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: 16px 16px 40px; }
.ph { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-bottom: 14px; }
.ph h1 { margin: 0; font-size: 1.3rem; letter-spacing: -.01em; }
.ph p { margin: 2px 0 0; color: var(--muted); font-size: .85rem; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.btn { height: 2.3rem; padding: 0 14px; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; color: inherit; }
.btn:hover:not(:disabled) { background: var(--sunken); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.sm { height: 1.9rem; padding: 0 10px; font-size: .82rem; }
.btn:disabled { opacity: .45; }
.iconbtn { width: 2.3rem; height: 2.3rem; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; font-size: 1.15rem; line-height: 1; display: inline-grid; place-items: center; }
.iconbtn:hover { background: var(--sunken); }
input.in, select.in { height: 2.3rem; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 0 10px; min-width: 0; }
input[type=search].in { width: 13rem; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 0 12px; height: 2.2rem; font-weight: 500; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.period { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.period .pl { min-width: 11rem; text-align: center; font-weight: 600; }
.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .85rem; }
.chk input { width: 1rem; height: 1rem; accent-color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0; }
.card h3 { margin: 0 0 8px; font-size: .95rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 12px; }
.stat .k { font-size: .72rem; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.stat .v { font-family: var(--font-num); font-size: 1.7rem; font-weight: 500; letter-spacing: -.02em; }
.stat .s { color: var(--muted); font-size: .8rem; }
.muted { color: var(--muted); }
.note { padding: 10px 12px; border-radius: 10px; background: var(--accent-tint); font-size: .86rem; margin-bottom: 12px; }
.note.warn { background: var(--half-bg); color: var(--half-fg); }
.note.bad { background: var(--red-tint); color: var(--red); }
.note.ok { background: var(--green-tint); color: var(--green); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h2 { color: var(--ink); margin: 0 0 6px; font-size: 1.2rem; }

/* ---------- tables ---------- */
.tw { overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); max-height: calc(100vh - 220px); }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .86rem; }
.t th { position: sticky; top: 0; z-index: 3; background: var(--sunken); padding: 9px 10px; text-align: left; font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
.t td { padding: 0 10px; height: 2.7rem; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface); }
.t tbody tr:last-child td { border-bottom: 0; }
.t tbody tr:hover td { background: color-mix(in srgb, var(--accent-tint) 55%, var(--surface)); }
.t tr.click { cursor: pointer; }
.t .r { text-align: right; }
.t tfoot td { position: sticky; bottom: 0; z-index: 3; background: var(--sunken); font-weight: 600; border-top: 1px solid var(--line-strong); border-bottom: 0; }
.t .stick { position: sticky; left: 0; z-index: 2; border-right: 1px solid var(--line); }
.t thead .stick, .t tfoot .stick { z-index: 4; }
.t tr.arch td { color: var(--muted); }
.t .wn { display: flex; flex-direction: column; line-height: 1.2; }
.t .wn b { font-weight: 600; }
.t .wn small { color: var(--muted); font-size: .72rem; }
.tag { display: inline-block; font-size: .66rem; letter-spacing: .05em; text-transform: uppercase; border: 1px solid var(--line-strong); color: var(--muted); border-radius: 4px; padding: 0 5px; margin-left: 4px; font-weight: 600; }
.tag.ok { border-color: var(--green); color: var(--green); }
.tag.bad { border-color: var(--red); color: var(--red); }
.tag.blue { border-color: var(--accent); color: var(--accent); }

/* ---------- muster grid ---------- */
.grid th.day, .grid td.day { text-align: center; padding: 0 2px; }
.grid th.day { padding: 4px 2px; }
.grid .rest { background: var(--rest); }
.grid thead th.rest { background: var(--sunken); }
.grid td.today { background: var(--today); }
.grid thead th.today { background: var(--accent-tint); color: var(--accent); }
.grid tfoot td.rest, .grid tfoot td.today { background: var(--sunken); }
.dayhead { display: flex; flex-direction: column; align-items: center; width: 2.6rem; margin: 0 auto; padding: 2px 0; border: 0; border-radius: 6px; background: none; color: inherit; line-height: 1.1; font-size: .66rem; }
.dayhead:hover:not(:disabled) { background: var(--accent-tint); }
.dayhead .dd { font-family: var(--font-num); font-size: .92rem; letter-spacing: 0; }
.cell { position: relative; width: 2.4rem; height: 2rem; border-radius: 6px; border: 1px solid var(--line); background: transparent; font-family: var(--font-num); font-size: .88rem; font-weight: 600; color: transparent; }
.cell:hover:not(:disabled) { border-color: var(--line-strong); background: var(--sunken); }
.cell.v1 { background: var(--present-bg); border-color: transparent; color: var(--present-fg); }
.cell.vh { background: var(--half-bg); border-color: transparent; color: var(--half-fg); }
.cell.vo { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.cell.gps::after { content: ""; position: absolute; top: 2px; right: 2px; width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.cell.gps.far::after { background: var(--red); }
.cell:disabled { opacity: .8; }
@media (pointer: coarse) { .cell { width: 2.7rem; height: 2.3rem; } }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: .78rem; color: var(--muted); align-items: center; }
.legend .cell { width: 1.5rem; height: 1.3rem; font-size: .7rem; display: inline-grid; place-items: center; cursor: default; }
.ni { width: 5.6rem; height: 2rem; text-align: right; border: 1px solid transparent; border-radius: 6px; background: transparent; padding: 0 6px; font-family: var(--font-num); font-size: .85rem; }
.ni:hover:not(:disabled) { border-color: var(--line-strong); }
.ni:focus { background: var(--surface); border-color: var(--accent); outline: none; }
.ni::placeholder { color: var(--line-strong); }
.mini { width: 1.6rem; height: 1.6rem; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); font-size: .8rem; line-height: 1; color: var(--green); vertical-align: middle; }
td.due-pos { color: var(--amber); font-weight: 600; }
td.due-neg { color: var(--red); font-weight: 600; }
td.due-ok { color: var(--green); font-weight: 600; }

/* ---------- letterhead / welcome / login ---------- */
.lh { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.lh img { width: 72px; height: 72px; border-radius: 16px; margin-bottom: 8px; }
.lh .co { font-size: clamp(1.5rem, 5vw, 2.1rem); font-weight: 700; letter-spacing: .06em; line-height: 1.1; }
.lh .ad { color: var(--muted); font-size: .9rem; }
.lh .ph2 { font-family: var(--font-num); font-size: .9rem; margin-top: 2px; }
.centerpage { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.loginbox { width: min(26rem, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 22px; display: flex; flex-direction: column; gap: 18px; align-items: center; box-shadow: 0 1px 0 var(--line); }
.loginbox h2 { margin: 0; font-size: 1.05rem; }
.loginbox p { margin: 0; text-align: center; color: var(--muted); font-size: .86rem; }
.demolist { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.demolist button { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 10px; text-align: left; }
.demolist button:hover { background: var(--sunken); }
.welcome { max-width: 46rem; margin: 4vh auto 0; display: flex; flex-direction: column; gap: 24px; }
.greet { text-align: center; }
.greet h2 { margin: 0; font-size: 1.5rem; }
.greet p { margin: 4px 0 0; color: var(--muted); }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 10px; }
.quick a { display: flex; flex-direction: column; gap: 2px; padding: 14px; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; text-decoration: none; color: inherit; }
.quick a:hover { border-color: var(--accent); }
.quick a b { font-size: .95rem; }
.quick a span { color: var(--muted); font-size: .8rem; }

/* ---------- check-in ---------- */
.ci { max-width: 34rem; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.ci .big { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 26px 16px; }
.ci .clock { font-family: var(--font-num); font-size: 2.4rem; font-weight: 500; letter-spacing: -.02em; }
.ci .bigbtn { width: 11rem; height: 11rem; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 1.15rem; font-weight: 700; box-shadow: var(--shadow); }
.ci .bigbtn.out { background: var(--ink); color: var(--paper); }
.ci .bigbtn:disabled { opacity: .5; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .88rem; }
.kv:last-child { border-bottom: 0; }
.kv b { font-family: var(--font-num); font-weight: 500; }

/* ---------- dialogs + toast ---------- */
dialog { border: 1px solid var(--line-strong); border-radius: 14px; padding: 0; background: var(--surface); color: var(--ink); width: min(34rem, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: var(--shadow); }
dialog.wide { width: min(60rem, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(10, 16, 22, .5); }
.df { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.df h2 { margin: 0; font-size: 1.1rem; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-size: .78rem; font-weight: 600; color: var(--muted); min-width: 0; }
.fields label.wide { grid-column: 1 / -1; }
.fields input, .fields select, .df textarea { height: 2.4rem; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 0 10px; color: var(--ink); font-weight: 400; min-width: 0; }
.fields label.chk { flex-direction: row; font-weight: 500; }
.df textarea { height: 9rem; padding: 8px 10px; font-family: var(--font-num); font-size: .78rem; resize: vertical; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.hint { margin: 0; font-size: .8rem; color: var(--muted); }
.dact { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dact .sp { flex: 1; }
.err { color: var(--red); font-size: .84rem; margin: 0; }
#toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 60; display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px); background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: .86rem; }
#toast button { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; padding: 0; }

.printhead { display: none; }
@media (max-width: 640px) {
  .topin { padding: 8px 12px; }
  .brand small, .who .nm { display: none; }
  main { padding: 12px 12px 32px; }
  .fields { grid-template-columns: 1fr; }
  input[type=search].in { width: 100%; }
  .period .pl { min-width: 0; flex: 1; }
  .tw { max-height: none; }
}
@media print {
  .top, .bar, .demo-bar, .noprint, #toast, .legend { display: none !important; }
  body { background: #fff; color: #000; font-size: 11px; }
  main { padding: 0; max-width: none; }
  .printhead { display: block; text-align: center; margin-bottom: 10px; }
  .printhead b { font-size: 16px; letter-spacing: .06em; }
  .tw { overflow: visible; max-height: none; border: 0; }
  .t th, .t td { position: static !important; height: auto; padding: 3px 5px; border: 1px solid #999; background: #fff !important; color: #000 !important; }
  .ni { border: 0; width: auto; }
  .cell { border: 0; color: #000 !important; background: none !important; width: auto; height: auto; }
  .cell.gps::after { display: none; }
  .mini { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
