/* SF auto-clock - design system. One file, no framework, no CDN. Mobile-first; light + dark by prefers-color-scheme.
   Tokens: 8 px spacing scale, 12/16 px radii, one system font stack, semantic status colours (WCAG AA on their tints). */
:root {
  color-scheme: light dark;
  --bg: #f3f5f9; --surface: #ffffff; --surface-2: #eaeef5; --text: #152033; --muted: #55627a; --line: #d5dce8;
  --brand: #1b5cc0; --brand-ink: #ffffff; --brand-soft: #e1ebfb;
  --ok: #11693a; --ok-bg: #dcf2e4; --warn: #7d4a00; --warn-bg: #fcebc6; --bad: #a8221a; --bad-bg: #fadedb;
  --info: #0a559f; --info-bg: #dbeafb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 16px rgba(16, 24, 40, .07);
  --s1: 8px; --s2: 16px; --s3: 24px; --s4: 32px; --r: 12px; --r-lg: 16px; --tap: 44px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* calendar categories */
  --c-work: #e3f3e8; --c-weekend: #e4e8ef; --c-holiday: #f8cfcb; --c-holiday_unconfirmed: #f8cfcb; --c-leave: #cbdaf8;
  --c-sick: #d3ecfb; --c-other_leave: #dde1e8; --c-remote: #c6ece7; --c-off: #edeff3; --c-worked: #e1d3f6;
  --purple: #6b35b0; --amber: #e0a100;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141e; --surface: #172030; --surface-2: #212c40; --text: #e8edf5; --muted: #a0aec3; --line: #2b3850;
    --brand: #6aa6ff; --brand-ink: #08111f; --brand-soft: #1b2c4a;
    --ok: #7de3a3; --ok-bg: #12301f; --warn: #ffd27a; --warn-bg: #3a2a06; --bad: #ffaca4; --bad-bg: #40161a;
    --info: #9fcbff; --info-bg: #112b4c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 16px rgba(0, 0, 0, .35);
    --c-work: #17372a; --c-weekend: #232d3f; --c-holiday: #4a1f26; --c-holiday_unconfirmed: #4a1f26; --c-leave: #1f3566;
    --c-sick: #1b4560; --c-other_leave: #2d3647; --c-remote: #15474a; --c-off: #1e2737; --c-worked: #3a2a63;
    --purple: #b794f6; --amber: #f5c542;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 var(--font); color: var(--text); background: var(--bg); padding-bottom: 76px; overflow-x: hidden; }
h1 { font-size: 1.35rem; line-height: 1.25; margin: 0 0 var(--s2); }
h2 { font-size: 1.05rem; margin: 0 0 var(--s1); }
h3 { font-size: .95rem; margin: var(--s2) 0 var(--s1); }
a { color: var(--brand); }
small, .muted { color: var(--muted); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 6px; font-size: .9em; word-break: break-all; }
.i { width: 20px; height: 20px; flex: none; vertical-align: -4px; }
.page { max-width: 1040px; margin: 0 auto; padding: var(--s2); }
.stack > * + * { margin-top: var(--s2); }
.row { display: flex; gap: var(--s1); align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; gap: var(--s2); grid-template-columns: 1fr; }
@media (min-width: 720px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.hide { display: none !important; }
.right { margin-left: auto; }
.nowrap { white-space: nowrap; }

/* top bar + navigation (tab bar on phones, top links on wide screens) */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .in { max-width: 1040px; margin: 0 auto; padding: 0 var(--s2); min-height: 52px; display: flex; align-items: center; gap: var(--s2); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand .i { color: var(--brand); }
.topnav { display: none; gap: 4px; margin-left: var(--s2); }
.topnav a, .tabbar a { color: var(--muted); text-decoration: none; display: flex; align-items: center; gap: 6px; border-radius: 10px; }
.topnav a { padding: 8px 12px; }
.topnav a.active { color: var(--brand); background: var(--brand-soft); font-weight: 600; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 14px rgba(0, 0, 0, .06); }
.tabbar a { flex-direction: column; justify-content: center; min-height: 58px; font-size: .72rem; gap: 2px; border-radius: 0; }
.tabbar a.active { color: var(--brand); font-weight: 600; }
.tabbar a.active .i { stroke-width: 2.6; }
@media (min-width: 820px) { .topnav { display: flex; } .tabbar { display: none; } body { padding-bottom: 0; } }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s2); box-shadow: var(--shadow); }
.card > h2:first-child { display: flex; align-items: center; gap: 8px; }
.card + .card { margin-top: var(--s2); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 calc(var(--s2) * -1); padding: 0 var(--s2); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.empty { text-align: center; color: var(--muted); padding: var(--s3) var(--s2); border: 1px dashed var(--line); border-radius: var(--r); }

/* buttons */
.btn, button { font: inherit; min-height: var(--tap); padding: 0 var(--s2); border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--brand); color: var(--brand-ink); font-weight: 600; text-decoration: none; }
.btn:hover, button:hover { filter: brightness(1.06); }
.btn:focus-visible, button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.btn.secondary, button.secondary, button.sec { background: transparent; color: var(--brand); border-color: var(--brand); }
.btn.danger, button.danger { background: var(--bad); color: #fff; }
.btn.ghost, button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.lg, button.lg { min-height: 64px; font-size: 1.05rem; flex-direction: column; gap: 4px; }
.btn.sm, button.sm { min-height: 36px; padding: 0 12px; font-size: .88rem; }
button:disabled, .btn[aria-disabled=true] { background: var(--surface-2); color: var(--muted); border-color: var(--line); cursor: not-allowed; filter: none; }
button[aria-busy=true] { position: relative; color: transparent; }
button[aria-busy=true]::after { content: ""; position: absolute; width: 18px; height: 18px; border: 3px solid var(--brand-ink); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
a.linkbtn { color: var(--brand); font-weight: 600; text-decoration: none; padding: 6px 4px; display: inline-block; }

/* form controls */
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; min-height: var(--tap); padding: 0 12px; max-width: 100%; }
input[type=checkbox], input[type=radio] { min-height: 0; width: 22px; height: 22px; accent-color: var(--brand); vertical-align: middle; }
label { display: inline-flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); margin: 0 var(--s1) var(--s1) 0; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: .95rem; color: var(--text); min-height: var(--tap); }
input[size], .w-time { width: 7rem; } .w-num { width: 6rem; }
form .row { margin-bottom: var(--s1); }
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s1); }
.fgrid label { display: flex; margin: 0; }
.fgrid input, .fgrid select { width: 100%; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label.check { min-height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; }

/* chips / badges */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--surface-2); color: var(--text); white-space: nowrap; }
.chip .i { width: 14px; height: 14px; vertical-align: -2px; }
.chip.ok { background: var(--ok-bg); color: var(--ok); } .chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); } .chip.info { background: var(--info-bg); color: var(--info); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.neg { color: var(--bad); font-weight: 700; }

/* toasts */
#toasts { position: fixed; z-index: 60; left: var(--s1); right: var(--s1); bottom: 76px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; align-items: center; }
@media (min-width: 820px) { #toasts { bottom: var(--s2); } }
.toast { pointer-events: auto; max-width: 520px; width: 100%; padding: 12px 14px; border-radius: var(--r); box-shadow: var(--shadow); background: var(--surface); border: 1px solid var(--line);
  border-left: 5px solid var(--info); display: flex; gap: 10px; white-space: pre-wrap; }
.toast.ok { border-left-color: var(--ok); } .toast.bad { border-left-color: var(--bad); } .toast.warn { border-left-color: var(--warn); }

/* confirm sheet (bottom sheet on phones, centred dialog on wide screens) */
dialog#sheet { border: 0; padding: 0; background: transparent; color: var(--text); max-width: 100vw; width: 100%; margin: auto 0 0; }
dialog#sheet::backdrop { background: rgba(5, 10, 20, .55); }
.sheet-in { background: var(--surface); border-radius: var(--r-lg) var(--r-lg) 0 0; padding: var(--s2) var(--s2) calc(var(--s2) + env(safe-area-inset-bottom)); max-height: 88vh; overflow: auto; }
.sheet-in h2 { font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.sheet-in .body { white-space: pre-wrap; margin: var(--s1) 0 var(--s2); }
.sheet-in .actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s1); }
.sheet-in .choices label.check { display: flex; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; margin: 0 0 6px; }
@media (min-width: 720px) { dialog#sheet { max-width: 460px; margin: auto; } .sheet-in { border-radius: var(--r-lg); } }

/* skeleton / loading */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sk 1.4s ease infinite; border-radius: 8px; min-height: 1em; color: transparent; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* compact control panel on non-control pages */
.cpanel { display: flex; gap: var(--s1); align-items: center; flex-wrap: wrap; margin-bottom: var(--s2); padding: 10px var(--s2); }
.cpanel .st { flex: 1 1 200px; min-width: 0; font-size: .85rem; color: var(--muted); }
.cpanel .btn { padding: 0 12px; }
.cpanel .btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; flex: 1 1 100%; }
.cpanel .lbl-full { display: none; }
@media (min-width: 560px) { .cpanel .btns { flex: 0 0 auto; display: flex; } .cpanel .lbl-full { display: inline; } .cpanel .lbl-short { display: none; } }

/* control (Today) page */
.cmdgrid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s1); }
.live { background: #000; border-radius: var(--r); aspect-ratio: 9 / 16; max-height: 42vh; margin: 0 auto; display: grid; place-items: center; overflow: hidden; color: #9aa; }
.live img { width: 100%; height: 100%; object-fit: contain; }
#reasons { white-space: pre-wrap; font-size: .85rem; color: var(--muted); margin: var(--s1) 0 0; }
details > summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; font-weight: 600; }

/* calendar */
.cal { display: grid; grid-template-columns: 30px repeat(7, 1fr); gap: 3px; }
.cal .h { text-align: center; font-size: .72rem; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal .wk { font-size: .62rem; color: var(--muted); display: grid; place-items: center; }
.day { position: relative; border-radius: 10px; min-height: 54px; padding: 4px; border: 1px solid transparent; background: var(--c-work);
  color: var(--text); text-align: left; font: inherit; display: flex; flex-direction: column; justify-content: space-between; text-decoration: none; cursor: pointer; overflow: hidden; }
.day .num { font-weight: 700; font-size: .95rem; line-height: 1; }
.day .mk { font-size: .66rem; font-weight: 800; align-self: flex-end; line-height: 1; }
.day .tm { display: none; font-size: .7rem; color: var(--muted); }
.day .dot { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: transparent; }
.day .dot.synced { background: var(--ok); } .day .dot.not_delivered { background: var(--bad); } .day .dot.pending { background: var(--muted); opacity: .5; }
.day.out { opacity: .35; } .day.past { opacity: .72; }
.day.today { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.day.ovr { outline: 2px solid var(--purple); outline-offset: -2px; }
.day.pin::before { content: ""; position: absolute; left: 0; bottom: 0; border: 7px solid transparent; border-left-color: var(--amber); border-bottom-color: var(--amber); }
.c-work { background: var(--c-work); } .c-weekend { background: var(--c-weekend); color: var(--muted); } .c-holiday { background: var(--c-holiday); }
.c-holiday_unconfirmed { background-color: var(--c-holiday_unconfirmed); background-image: repeating-linear-gradient(45deg, transparent 0 5px, rgba(168, 34, 26, .28) 5px 7px); }
.c-leave { background: var(--c-leave); } .c-sick { background: var(--c-sick); } .c-other_leave { background: var(--c-other_leave); }
.c-remote { background: var(--c-remote); } .c-off { background: var(--c-off); } .c-worked { background: var(--c-worked); }
.legend { display: flex; flex-wrap: wrap; gap: 6px; font-size: .75rem; }
.legend span { padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); }
.legend span.ovr { outline: 2px solid var(--purple); outline-offset: -2px; }
@media (min-width: 640px) { .day { min-height: 92px; padding: 6px; } .day .tm { display: block; } .cal { grid-template-columns: 44px repeat(7, 1fr); gap: 4px; } .cal .wk { font-size: .72rem; } }
.ym { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; font-size: .7rem; text-align: center; }
.ym a { border-radius: 6px; padding: 5px 0; color: var(--text); text-decoration: none; display: block; min-height: 30px; }
.ym .h { font-weight: 700; color: var(--muted); }
.year { display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.year .card { padding: 12px; }
.periodtag { font-size: .72rem; }
.segment { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segment a { padding: 8px 14px; text-decoration: none; color: var(--muted); min-height: 40px; display: inline-flex; align-items: center; }
.segment a.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.kv { display: grid; grid-template-columns: minmax(110px, 36%) 1fr; gap: 6px var(--s1); font-size: .92rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }

/* auth pages */
.auth { max-width: 420px; margin: 8vh auto 0; }
.auth .card { padding: var(--s3); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.mb1 { margin-bottom: 8px; } .m0 { margin: 0 !important; } .mt1 { margin-top: 12px; } .mt2 { margin-top: 16px; }

.banner { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-radius: var(--r); margin-bottom: var(--s2); }
.banner.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }
.banner span { flex: 1 1 220px; }
.steppad { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 8px; }
.steppad button { min-height: 68px; flex-direction: column; gap: 2px; font-size: .9rem; position: relative; }
.steppad button .n { position: absolute; top: 4px; left: 8px; font-size: .68rem; opacity: .8; }
@media (min-width: 640px) { .steppad { grid-template-columns: repeat(5, 1fr); } }

.refimg { max-width: 100%; max-height: 360px; border-radius: 8px; border: 1px solid var(--line); background: #000; display: block; }
textarea { min-height: 96px; padding: 8px 12px; width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
figure.m0 { margin: 0; }
.cpanel .btns button { padding: 0 6px; min-width: 0; font-size: .85rem; gap: 4px; }
@media (min-width: 560px) { .cpanel .btns button { padding: 0 12px; font-size: 1rem; gap: 8px; } }

.qrbox { text-align: center; } .qrbox img { background: #fff; padding: 8px; border-radius: 12px; border: 1px solid var(--line); max-width: 100%; height: auto; }
