:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #f8f6f1;
  --text: #1b1a17;
  --muted: #6b665c;
  --line: #ddd7cc;
  --accent: #1f5fd1;
  --accent-text: #ffffff;
  --brand: #ff5a1f;
  --ok: #138a43;
  --ok-bg: #e3f5ea;
  --warn: #a86200;
  --warn-bg: #fff1d6;
  --bad: #c22a1e;
  --bad-bg: #fde7e4;
  --flash-ok: #12924a;
  --flash-warn: #d98a00;
  --flash-error: #c9281c;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141310;
    --surface: #1f1d19;
    --surface-2: #26241f;
    --text: #f2efe8;
    --muted: #a39d90;
    --line: #3a372f;
    --accent: #5b8ff0;
    --accent-text: #0b1220;
    --ok-bg: #12301f;
    --warn-bg: #36280c;
    --bad-bg: #3a1714;
    --ok: #4fd18a;
    --warn: #f2b14a;
    --bad: #ff7a6e;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141310; --surface: #1f1d19; --surface-2: #26241f; --text: #f2efe8; --muted: #a39d90; --line: #3a372f;
  --accent: #5b8ff0; --accent-text: #0b1220; --ok-bg: #12301f; --warn-bg: #36280c; --bad-bg: #3a1714;
  --ok: #4fd18a; --warn: #f2b14a; --bad: #ff7a6e; 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;
  min-height: 100vh;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.15; margin: 0 0 .5em; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; margin-top: 1.2em; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.error { color: var(--bad); font-weight: 600; }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.row.gap { gap: 12px; }
.row.small-gap, .small-gap { gap: 6px; }
.row.between { justify-content: space-between; gap: 12px; }

/* ── buttons & inputs ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  min-height: 44px;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: .85rem; border-radius: 8px; }
.btn.big-btn { min-height: 60px; padding: 14px 26px; font-size: 1.15rem; border-radius: 12px; }
.btn.huge { min-height: 84px; padding: 18px 36px; font-size: 1.5rem; border-radius: 16px; flex: 1; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; max-width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: 6px; font-weight: 600; margin-bottom: 14px; }
label.radio { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-bottom: 8px; }
label.radio input { min-height: 0; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 0 0 14px; }
legend { font-weight: 700; padding: 0 6px; }

/* ── frame ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.1rem; }
.logo {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: var(--brand); color: #fff; font-weight: 900; font-size: 1.2rem; transform: rotate(-6deg);
  box-shadow: 2px 2px 0 var(--text);
}
.station-info { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-weight: 600; font-size: .9rem; }
.chip-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.inset { box-shadow: none; background: var(--surface-2); margin-top: 16px; }
.warn-card { border-color: var(--warn); }
.center-view { display: grid; place-items: start center; padding: 40px 16px; }
.login, .start { width: min(460px, 100%); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .8rem; font-weight: 700; background: var(--surface-2); border: 1px solid var(--line); }
.pill.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.count { display: inline-block; min-width: 1.6em; text-align: center; font-size: .85rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }

/* ── kiosk ── */
.kiosk-page.in-kiosk { overflow: hidden; height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.in-kiosk main { flex: 1; min-height: 0; }
#view-kiosk { height: 100%; }
.kiosk-grid { display: grid; grid-template-columns: minmax(280px, 42%) 1fr; gap: 16px; padding: 16px; height: 100%; }
.camera-card { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.camera-frame { position: relative; flex: 1; min-height: 200px; background: #000; border-radius: var(--radius); overflow: hidden; }
.camera-frame video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera-frame video.mirror { transform: scaleX(-1); }
.target {
  position: absolute; inset: 18% 14%; border: 3px solid rgb(255 255 255 / 85%); border-radius: 16px;
  box-shadow: 0 0 0 9999px rgb(0 0 0 / 25%); pointer-events: none;
}
.camera-error { position: absolute; inset: auto 12px 12px; margin: 0; background: rgb(0 0 0 / 70%); color: #fff; padding: 10px 12px; border-radius: 10px; }
.camera-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.panel-wrap { overflow-y: auto; min-height: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); min-height: 100%; }
.big { font-size: clamp(1.8rem, 3.6vw, 2.8rem); font-weight: 800; letter-spacing: -0.01em; }
.big .soft { font-weight: 600; color: var(--muted); font-size: .6em; }
.lede { font-size: 1.2rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-weight: 700; color: var(--muted); margin: 0 0 4px; font-size: .85rem; }
.phone-display {
  font: 700 clamp(1.6rem, 3.4vw, 2.4rem)/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .04em;
  padding: 14px 16px; border-radius: 12px; background: var(--surface-2); border: 2px dashed var(--line); color: var(--muted);
  text-align: center; margin-bottom: 14px;
}
.phone-display.typing { color: var(--text); border-style: solid; border-color: var(--accent); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 420px; margin: 0 auto; }
.keypad button {
  font: 700 1.8rem/1 system-ui, sans-serif; min-height: 68px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text); cursor: pointer;
}
.keypad button:active { background: var(--accent); color: var(--accent-text); }
.keypad .muted-key { font-size: 1.1rem; color: var(--muted); }
.agreement { font-size: 1.15rem; background: var(--surface-2); border-left: 4px solid var(--brand); padding: 10px 14px; border-radius: 6px; }
.sign-box { position: relative; height: clamp(180px, 34vh, 320px); background: #fff; border: 2px solid var(--line); border-radius: 12px; margin-bottom: 12px; touch-action: none; }
.sign-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.sign-line { position: absolute; left: 6%; right: 6%; bottom: 26%; border-top: 2px solid #c8c2b6; color: #9a9385; font-size: .85rem; padding-top: 4px; pointer-events: none; }
.countdown { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 12px 0 16px; }
.countdown.thin { height: 6px; margin: 14px 0 0; }
.countdown > div { height: 100%; width: 100%; background: var(--accent); border-radius: 999px; }
.items { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 8px; }
.items li { background: var(--surface-2); padding: 12px 14px; border-radius: 10px; font-size: 1.1rem; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; margin: -6px 0 12px; }
.choice { border: 1px solid var(--line); background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; min-height: 44px; }
.picked { background: var(--ok-bg); padding: 8px 12px; border-radius: 10px; margin-bottom: 12px; }
.hint { background: var(--surface-2); padding: 10px 12px; border-radius: 10px; }

.flash {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; padding: 24px; cursor: pointer;
  animation: flash-in .15s ease-out;
}
.flash p { color: #fff; font-size: clamp(1.8rem, 4.5vw, 3.4rem); font-weight: 800; text-align: center; max-width: 18em; margin: 0; text-shadow: 0 2px 8px rgb(0 0 0 / 25%); }
.flash-ok { background: color-mix(in srgb, var(--flash-ok) 94%, transparent); }
.flash-warn { background: color-mix(in srgb, var(--flash-warn) 95%, transparent); }
.flash-error { background: color-mix(in srgb, var(--flash-error) 95%, transparent); }
@keyframes flash-in { from { opacity: 0; transform: scale(1.02); } to { opacity: 1; transform: none; } }

.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; justify-content: center; padding: 16px; pointer-events: none; }
.sheet-inner { pointer-events: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 -4px 40px rgb(0 0 0 / 20%); padding: 20px 24px; width: min(720px, 100%); }
.sheet-title { font-size: 1.5rem; font-weight: 800; margin: 0 0 2px; }
.modal { position: fixed; inset: 0; background: rgb(0 0 0 / 45%); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal-inner { background: var(--surface); border-radius: 18px; padding: 24px; width: min(620px, 100%); max-height: 90vh; overflow: auto; position: relative; }
.modal-inner.wide { width: min(880px, 100%); }
.modal-close { position: absolute; top: 12px; right: 12px; }
.tap-start { font: 800 2rem/1.2 system-ui, sans-serif; padding: 40px 60px; border-radius: 24px; border: none; background: var(--brand); color: #fff; cursor: pointer; box-shadow: 4px 4px 0 #000; }

@media (max-width: 820px), (orientation: portrait) {
  .kiosk-page.in-kiosk { overflow: auto; height: auto; }
  .kiosk-grid { grid-template-columns: 1fr; height: auto; }
  .camera-frame { min-height: 0; aspect-ratio: 16 / 10; flex: none; }
  .panel { min-height: 0; }
}

/* ── admin ── */
.tabs { display: flex; gap: 4px; padding: 8px 16px 0; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: none; background: none; color: var(--muted); font: inherit; font-weight: 700; padding: 10px 14px; border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--brand); }
.admin-main { padding: 16px; max-width: 1200px; margin: 0 auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.data th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 2px solid var(--line); padding: 8px; }
table.data td { border-bottom: 1px solid var(--line); padding: 8px; vertical-align: top; }
table.data tr.inactive td { opacity: .6; }
.card:has(> table.data), .card > table.data { overflow-x: auto; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.grid-form .span2 { grid-column: 1 / -1; }
.sheet-picker { display: grid; grid-template-columns: repeat(3, 56px); gap: 4px; }
.sheet-picker button { height: 22px; font-size: .7rem; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); border-radius: 4px; cursor: pointer; }
.sheet-picker button.used { background: repeating-linear-gradient(45deg, var(--line), var(--line) 3px, transparent 3px, transparent 6px); }
.sheet-picker button.start { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.label-form { display: grid; grid-template-columns: 1fr auto; gap: 16px; }
.sheet-preview { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; max-width: 720px; }
.sheet-preview .slot { border: 1px dashed var(--line); border-radius: 6px; padding: 6px 8px; min-height: 44px; display: grid; font-size: .8rem; }
.sheet-preview .slot.used { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 4px, transparent 4px, transparent 8px); }
.sheet-preview .span3 { grid-column: 1 / -1; }
.visits { display: grid; gap: 10px; }
.visit { display: flex; gap: 12px; align-items: center; }
.visit img, .visit .nosig { width: 180px; height: 60px; border: 1px solid var(--line); border-radius: 6px; background: #fff; object-fit: contain; flex: none; }
.visit .nosig { display: grid; place-items: center; color: #666; font-size: .8rem; font-style: italic; }
ul.plain { list-style: none; padding: 0; display: grid; gap: 6px; }
@media (max-width: 700px) {
  .label-form { grid-template-columns: 1fr; }
  .admin-main { padding: 12px; }
}

/* ── phase 2 ── */
.filter-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 12px; align-items: end; }
.filter-row > .row { grid-column: 1 / -1; margin-bottom: 14px; }
.filter-row input, .filter-row select { width: 100%; min-width: 0; }
.linkish { background: none; border: none; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-align: left; text-decoration: underline; }
.ok-text { color: var(--ok); font-weight: 600; }
.chip.small { font-size: .78rem; padding: 3px 10px; }

/* ── phase 3 ── */
.links { display: grid; gap: 10px; }
.link-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.link-row .link-label { min-width: 9em; font-weight: 700; }
.link-row input { flex: 1 1 200px; min-height: 36px; padding: 6px 10px; }
.link-row .choices { flex-basis: 100%; margin: 0; }
details.merge { margin-top: 16px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
details.merge summary { cursor: pointer; font-weight: 700; }
details.merge input { width: 100%; margin: 6px 0 10px; }
