:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #111827;
  --muted: #5b6472;
  --border: #d9dee5;
  --brand: #1f2a37;
  --brand-text: #ffffff;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --in: #15803d;
  --in-bg: #e8f6ec;
  --out: #b42318;
  --out-bg: #fdecea;
  --warn: #92400e;
  --warn-bg: #fff4d6;
  --focus: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #18202a;
    --surface-2: #1d2733;
    --text: #edf0f4;
    --muted: #9aa5b4;
    --border: #2d3846;
    --brand: #0b1016;
    --accent: #f08c4a;
    --accent-text: #1a0d04;
    --in: #4ade80;
    --in-bg: #12301d;
    --out: #f87171;
    --out-bg: #3a1717;
    --warn: #fbbf24;
    --warn-bg: #3a2c0b;
    --focus: #60a5fa;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--focus); }
.loading { padding: 2rem; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---- top bar & nav ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: var(--brand-text);
  padding: calc(env(safe-area-inset-top) + 0.6rem) 16px 0.6rem;
  display: flex; align-items: center; gap: 0.75rem;
}
.topbar .title { font-weight: 700; font-size: 1.05rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .who { font-size: 0.85rem; opacity: 0.85; white-space: nowrap; }
.topbar button { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,0.35); min-height: 36px; padding: 0 0.7rem; font-size: 0.85rem; }
.tabs {
  display: flex; gap: 0.25rem; overflow-x: auto; scrollbar-width: none;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 12px; position: sticky; top: calc(env(safe-area-inset-top) + 52px); z-index: 19;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: none; padding: 0.8rem 0.7rem; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.95rem;
  border-bottom: 3px solid transparent;
}
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 460px; margin: 0 auto; }

/* ---- cards, lists ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 0.75rem; }
.grid-cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid-cards .card { margin: 0; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.item { display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 0; min-height: 52px; }
.item .main { flex: 1; min-width: 0; }
.item .name { font-weight: 600; }
.item .sub { color: var(--muted); font-size: 0.875rem; }
button.item { width: 100%; text-align: left; background: none; border: 0; border-radius: 0; color: inherit; font: inherit; padding: 0.7rem 0; cursor: pointer; }

/* Selectable worker rows on the crew screen */
label.pick {
  display: flex; align-items: center; gap: 0.85rem; padding: 0.65rem 0.75rem; margin: 0 -0.75rem;
  min-height: 56px; cursor: pointer; border-radius: 10px;
}
label.pick:hover { background: var(--surface-2); }
label.pick input { width: 26px; height: 26px; flex: none; accent-color: var(--accent); }
label.pick.checked { background: var(--surface-2); }
.pick .name { font-weight: 600; font-size: 1.05rem; }
.pick .sub { color: var(--muted); font-size: 0.875rem; }

.badge { display: inline-block; font-size: 0.78rem; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 999px; white-space: nowrap; }
.badge.in { background: var(--in-bg); color: var(--in); }
.badge.out { background: var(--out-bg); color: var(--out); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.plain { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.notice { padding: 0.75rem 1rem; border-radius: 10px; background: var(--warn-bg); color: var(--warn); margin-bottom: 16px; }
.notice.error { background: var(--out-bg); color: var(--out); }
.empty { color: var(--muted); padding: 0.5rem 0; }

/* ---- forms ---- */
label.field { display: block; }
label.field > span { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.3rem; }
label.field > small { display: block; color: var(--muted); margin-top: 0.25rem; font-size: 0.82rem; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 0.65rem 0.75rem; min-height: 48px;
}
textarea { min-height: 72px; resize: vertical; }
input[type="checkbox"] { width: auto; min-height: 0; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus); outline-offset: 2px;
}
.form-grid { display: grid; gap: 0.9rem; grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 520px) { .form-grid { grid-template-columns: 1fr; } }
.check-row { display: flex; align-items: center; gap: 0.6rem; min-height: 44px; }
.check-row input { width: 22px; height: 22px; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: inherit; font-weight: 700; min-height: 48px; padding: 0 1.1rem; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none;
}
button:disabled { opacity: 0.55; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.go-in { background: var(--in); border-color: var(--in); color: #fff; }
button.go-out { background: var(--out); border-color: var(--out); color: #fff; }
@media (prefers-color-scheme: dark) { button.go-in, button.go-out { color: #0b0f14; } }
button.danger { color: var(--out); border-color: var(--out); background: transparent; }
button.link { background: none; border: 0; color: var(--focus); padding: 0; min-height: 0; font-weight: 600; }
button.small, .btn.small { min-height: 38px; padding: 0 0.8rem; font-size: 0.9rem; }
button.wide { width: 100%; }

.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chips button { min-height: 44px; padding: 0 0.95rem; font-weight: 600; }
.chips button.on { background: var(--brand); color: var(--brand-text); border-color: var(--brand); }
@media (prefers-color-scheme: dark) { .chips button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); } }

/* Sticky action bar on the crew screen */
.actionbar {
  position: sticky; bottom: 0; z-index: 15; margin: 0 -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border); display: flex; gap: 0.6rem; flex-wrap: wrap;
}
.actionbar button { flex: 1 1 140px; min-height: 54px; font-size: 1.02rem; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
th, td { text-align: left; padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 0.8rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.total td { font-weight: 700; border-top: 2px solid var(--border); }
td.ot { color: var(--accent); font-weight: 700; }
tr.sub td { background: var(--surface-2); }

/* ---- dialog ---- */
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
dialog::backdrop { background: rgba(10, 15, 20, 0.55); }
dialog .dlg { padding: 20px; overflow-y: auto; max-height: calc(100vh - 32px); }
dialog .dlg-actions { display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 1.25rem; flex-wrap: wrap; }
dialog .dlg-actions .spacer { flex: 1; }
@media (max-width: 520px) {
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  dialog .dlg { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--brand); color: var(--brand-text); padding: 0.75rem 1.1rem; border-radius: 10px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 100; max-width: calc(100vw - 32px);
}
@media (prefers-color-scheme: dark) { #toast { background: #e5e9ef; color: #111; } }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--out); color: #fff; }

.login-logo { display: block; width: 72px; height: 72px; margin: 1.5rem auto 0.75rem; }
.center { text-align: center; }
.period { display: flex; align-items: center; gap: 0.5rem; }
.period strong { min-width: 0; text-align: center; flex: 1; }
.period button { min-width: 48px; padding: 0; }
.mb { margin-bottom: 12px; }
.mt { margin-top: 1rem; }
.mt-s { margin-top: 0.2rem; }
.pull-up { margin-top: -0.3rem; }

/* ---- camera ---- */
.cam { position: relative; width: 100%; aspect-ratio: 4 / 3; background: #000; border-radius: 12px; overflow: hidden; }
.cam-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-video.mirror { transform: scaleX(-1); }
.cam-oval {
  position: absolute; left: 50%; top: 50%; width: 46%; height: 78%; transform: translate(-50%, -50%);
  border: 3px dashed rgba(255, 255, 255, 0.85); border-radius: 50%; pointer-events: none;
}
.cam-status { font-weight: 600; margin: 0.75rem 0 0.25rem; }
.cam-status.error { color: var(--out); }
.cam-status.ok { color: var(--in); }

/* ---- worker phone ---- */
button.huge { width: 100%; min-height: 84px; font-size: 1.5rem; border-radius: 16px; }
.big-status { font-size: 1.35rem; font-weight: 800; margin: 0.25rem 0; }
.big-status.in { color: var(--in); }
.center { text-align: center; }

.result { text-align: center; padding: 0.5rem 0 0.25rem; }
.result-mark {
  width: 84px; height: 84px; margin: 0 auto 0.75rem; border-radius: 50%; display: grid; place-items: center;
  font-size: 2.6rem; font-weight: 800; color: #fff; background: var(--in);
}
.result.out .result-mark { background: var(--out); }
.result p { font-size: 1.1rem; }

/* ---- site tablet ---- */
.kiosk-head h1 { font-size: 1.6rem; margin: 0; }
.kiosk-clock { font-size: 1.6rem; font-weight: 800; }
.kiosk-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
button.kiosk-name {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 0.2rem;
  min-height: 92px; padding: 0.8rem 1rem; text-align: left; background: var(--surface); border: 2px solid var(--border);
}
button.kiosk-name .name { font-size: 1.15rem; font-weight: 800; }
button.kiosk-name .sub { font-size: 0.85rem; font-weight: 500; color: var(--muted); }
button.kiosk-name.on { border-color: var(--in); background: var(--in-bg); }
.pin-dots { text-align: center; font-size: 1.6rem; letter-spacing: 0.3em; min-height: 2.4rem; margin-bottom: 0.75rem; color: var(--muted); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 320px; margin: 0 auto; }
.pin-key { min-height: 64px; font-size: 1.5rem; }

/* ---- evidence / review ---- */
.evidence { margin: 0.5rem 0 1rem; }
.ev-photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 0.5rem; }
.ev-photo { margin: 0; }
.ev-photo img, .ev-none { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 10px; background: var(--surface-2); display: block; }
.ev-none { display: grid; place-items: center; color: var(--muted); font-size: 0.8rem; border: 1px dashed var(--border); }
.ev-photo figcaption { font-size: 0.78rem; color: var(--muted); text-align: center; margin-top: 0.2rem; }
.review-actions .row button { flex: 1; }
.face-thumb { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; flex: none; background: var(--surface-2); }
.empty-thumb { display: grid; place-items: center; color: var(--muted); font-weight: 700; border: 1px dashed var(--border); }

fieldset.geo { border: 1px solid var(--border); border-radius: 12px; padding: 0.75rem 1rem 1rem; margin: 0; }
fieldset.geo legend { font-weight: 700; padding: 0 0.35rem; }
fieldset.geo > * + * { margin-top: 0.6rem; }
