:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16191d;
  --muted: #5d6570;
  --border: #dde1e6;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --work: #1e8a4c;
  --pause: #c77700;
  --off: #7a828c;
  --danger: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f252d;
    --text: #e8ebef;
    --muted: #9aa3ad;
    --border: #2a313a;
    --accent: #5b9bff;
    --accent-text: #0b1220;
    --work: #3ecf7a;
    --pause: #f0a431;
    --off: #8a939d;
    --danger: #ff6b5b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }

header.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
header.top .brand { font-weight: 700; letter-spacing: -.01em; }
header.top .who { font-size: .9rem; color: var(--muted); }

main { max-width: 560px; margin: 0 auto; padding: 16px; }
main.wide { max-width: 1200px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card h2 { font-size: 1rem; margin: 0 0 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 600;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0 4px; min-height: 32px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- PIN pad ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-box h1 { font-size: 1.35rem; margin: 0 0 4px; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 28px 0 8px; min-height: 18px; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots span.on { background: var(--text); border-color: var(--text); }
.pin-err { color: var(--danger); min-height: 1.5em; margin-bottom: 8px; font-size: .95rem; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pad button {
  height: 68px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface);
  font-size: 1.6rem; font-weight: 600; cursor: pointer; box-shadow: var(--shadow);
}
.pad button:active { background: var(--surface-2); }
.pad button.ok { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-size: 1.1rem; }
.pad button.del { font-size: 1.1rem; }

/* ---------- worker main ---------- */
.status { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.status .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--off); flex: none; }
.status.working .dot { background: var(--work); box-shadow: 0 0 0 6px color-mix(in srgb, var(--work) 20%, transparent); }
.status.pause .dot { background: var(--pause); box-shadow: 0 0 0 6px color-mix(in srgb, var(--pause) 20%, transparent); }
.status.stale .dot { background: var(--danger); }
.status .label { font-size: 1.15rem; font-weight: 700; }
.status .since { color: var(--muted); font-size: .95rem; }
.timer { font-size: 2.4rem; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 16px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions button {
  min-height: 64px; border-radius: 14px; border: 0; font-size: 1.15rem; font-weight: 700; cursor: pointer; color: #fff;
}
.actions .start { background: var(--work); grid-column: span 2; }
.actions .pause { background: var(--pause); }
.actions .resume { background: var(--work); }
.actions .end { background: var(--danger); }
.actions button:disabled { opacity: .3; cursor: not-allowed; }
.actions.off .pause, .actions.off .resume, .actions.off .end { display: none; }
.actions.working .start, .actions.working .resume { display: none; }
.actions.working .pause, .actions.working .end { grid-column: auto; }
.actions.pause .start, .actions.pause .pause { display: none; }

.list { width: 100%; border-collapse: collapse; }
.list th, .list td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.list th { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.list td.r, .list th.r { text-align: right; }
.list tr.open td { color: var(--work); font-weight: 600; }
.list tr.stale td { color: var(--danger); font-weight: 600; }
.list tr.voided td { text-decoration: line-through; color: var(--muted); }
.list tfoot td { font-weight: 700; border-bottom: 0; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
select, input[type=text], input[type=number], input[type=datetime-local], input[type=time], textarea {
  min-height: 44px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
input[type=month] { min-height: 44px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
label.field { display: grid; gap: 6px; font-size: .9rem; color: var(--muted); }
label.field > * { color: var(--text); }

.plan-item { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.plan-item:last-child { border-bottom: 0; }

/* ---------- admin ---------- */
nav.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
nav.tabs button {
  border: 0; background: none; padding: 14px 14px 12px; cursor: pointer; font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent; white-space: nowrap;
}
nav.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; border: 1px solid var(--border); }
.pill.on { color: var(--work); border-color: currentColor; }
.pill.offp { color: var(--muted); }
.pill.admin { color: var(--accent); border-color: currentColor; }

.totals { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.totals .t { padding: 12px; border: 1px solid var(--border); border-radius: 10px; }
.totals .t b { display: block; font-size: 1.2rem; }

.grid-plan { border-collapse: collapse; width: 100%; font-size: .9rem; }
.grid-plan th, .grid-plan td { border: 1px solid var(--border); padding: 6px 8px; vertical-align: top; }
.grid-plan th { background: var(--surface-2); text-align: left; }
.grid-plan td.we { background: var(--surface-2); }
.grid-plan .slot { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 2px 0; cursor: pointer; }
.grid-plan .slot.empty { color: var(--danger); font-weight: 600; }
.grid-plan .slot:hover { text-decoration: underline; }

.shift-def { display: grid; grid-template-columns: 1.4fr 1fr 1fr .7fr auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.days { display: flex; gap: 4px; flex-wrap: wrap; grid-column: 1 / -1; }
.days label { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: .85rem; cursor: pointer; }
.chk-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.chk-list label { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 20px; width: min(460px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h3 { margin: 0 0 16px; }
dialog form { display: grid; gap: 12px; }
dialog .row { justify-content: flex-end; }
.pin-show { font-size: 2.2rem; font-weight: 700; letter-spacing: .3em; text-align: center; padding: 12px; border: 1px dashed var(--border); border-radius: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 10px; font-weight: 600; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.err { background: var(--danger); color: #fff; }

@media (max-width: 640px) {
  .shift-def { grid-template-columns: 1fr 1fr; }
  .list th, .list td { padding: 8px 4px; font-size: .9rem; }
  .list th { font-size: .7rem; letter-spacing: .02em; }
}
