/* BKRY Gate Pass — shared styles
   Layout: dense operator console. Brand bar on top, work surfaces below,
   status carried by coloured chips + left stripes. */
:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --line: #e2dbd1;
  --line-strong: #cbbfb0;
  --ink: #1f1813;
  --ink-2: #5d5046;
  --ink-3: #8b7e72;
  --brand: #3b2a1e;
  --brand-ink: #f6eee4;
  --accent: #b5652b;
  --ok: #2f7d4f;   --ok-bg: #e4f2e9;
  --warn: #a8670a; --warn-bg: #fbf0d9;
  --bad: #b23b2e;  --bad-bg: #f9e3e0;
  --info: #2d6190; --info-bg: #e2ecf6;
  --mute: #6f6a65; --mute-bg: #ece9e5;
  --shadow: 0 1px 2px rgba(40, 25, 10, .06), 0 4px 14px rgba(40, 25, 10, .06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, "Roboto Mono", monospace;
  --r: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17120e; --surface: #211a15; --surface-2: #1c1612; --line: #3a2f27; --line-strong: #52443a;
    --ink: #f1e9e0; --ink-2: #c4b5a7; --ink-3: #8f8073; --brand: #2a1e15; --brand-ink: #f6eee4; --accent: #e08a4a;
    --ok: #6cc28f; --ok-bg: #1d3326; --warn: #e2a849; --warn-bg: #3a2c12; --bad: #ef7b6d; --bad-bg: #3d1e1a;
    --info: #79aee0; --info-bg: #1b2c3d; --mute: #aaa29a; --mute-bg: #2c2620;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17120e; --surface: #211a15; --surface-2: #1c1612; --line: #3a2f27; --line-strong: #52443a;
  --ink: #f1e9e0; --ink-2: #c4b5a7; --ink-3: #8f8073; --brand: #2a1e15; --brand-ink: #f6eee4; --accent: #e08a4a;
  --ok: #6cc28f; --ok-bg: #1d3326; --warn: #e2a849; --warn-bg: #3a2c12; --bad: #ef7b6d; --bad-bg: #3d1e1a;
  --info: #79aee0; --info-bg: #1b2c3d; --mute: #aaa29a; --mute-bg: #2c2620;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
img { max-width: 100%; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
a { color: var(--info); }
.muted { color: var(--ink-3); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar { background: var(--brand); color: var(--brand-ink); display: flex; align-items: center; gap: 18px; padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { font-weight: 800; letter-spacing: .14em; font-size: 18px; }
.brand-sub { font-size: 12px; opacity: .75; letter-spacing: .06em; text-transform: uppercase; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: var(--brand-ink); text-decoration: none; padding: 6px 12px; border-radius: 6px; opacity: .8; font-weight: 500; }
.topbar nav a.on, .topbar nav a:hover { background: rgba(255,255,255,.12); opacity: 1; }
.topbar .spacer { flex: 1; }
.clock { font-family: var(--mono); font-size: 13px; opacity: .85; }
.who { font-size: 13px; opacity: .9; }
.topbar .btn { background: rgba(255,255,255,.1); color: var(--brand-ink); border-color: rgba(255,255,255,.2); }

/* ---------- buttons & inputs ---------- */
.btn { font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
:root[data-theme="dark"] .btn.primary { background: var(--accent); border-color: var(--accent); color: #1a120c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { background: var(--accent); border-color: var(--accent); color: #1a120c; } }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.bad { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--mute-bg); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.big { padding: 12px 22px; font-size: 16px; }
.btn.quiet { opacity: .55; }

label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; letter-spacing: .02em; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--ink); }
textarea { resize: vertical; min-height: 60px; }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
.req::after { content: " *"; color: var(--bad); }
.field { min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 560px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.hint { font-size: 12px; color: var(--ink-3); margin-top: 4px; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); min-width: 0; }
.panel-h { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel-h h2 { font-size: 15px; }
.panel-b { padding: 16px; }
.count { font-size: 12px; font-weight: 700; background: var(--mute-bg); color: var(--ink-2); border-radius: 99px; padding: 1px 8px; font-variant-numeric: tabular-nums; }

/* ---------- status chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-pending { color: var(--warn); background: var(--warn-bg); }
.s-approved { color: var(--ok); background: var(--ok-bg); }
.s-inside { color: var(--info); background: var(--info-bg); }
.s-rejected, .s-cancelled { color: var(--bad); background: var(--bad-bg); }
.s-out, .s-expired { color: var(--mute); background: var(--mute-bg); }

/* ---------- desk ---------- */
.desk { display: grid; grid-template-columns: minmax(360px, 460px) 1fr; gap: 16px; padding: 16px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); align-items: start; }
@media (max-width: 980px) { .desk { grid-template-columns: 1fr; } }
.entry-form { display: grid; gap: 12px; }
.cam { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cam-slot { position: relative; background: var(--surface-2); border: 1.5px dashed var(--line-strong); border-radius: var(--r); aspect-ratio: 4 / 3; overflow: hidden; display: grid; place-items: center; max-width: 100%; }
.cam-slot.main { grid-column: 1 / -1; aspect-ratio: auto; height: clamp(200px, 32vh, 280px); }
.cam-slot video, .cam-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-slot video { transform: scaleX(-1); }
.cam-slot .cam-label { position: absolute; left: 8px; top: 8px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; background: rgba(20,12,6,.65); color: #fff; padding: 2px 8px; border-radius: 4px; }
.cam-slot .cam-empty { text-align: center; color: var(--ink-3); padding: 12px; font-size: 13px; }
.cam-slot.taken { border-style: solid; border-color: var(--ok); }
.cam-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cam-guide { position: absolute; inset: 12% 28%; border: 2px solid rgba(255,255,255,.55); border-radius: 50% / 42%; pointer-events: none; }
.returning { background: var(--info-bg); color: var(--info); border-radius: 6px; padding: 8px 10px; font-size: 13px; display: flex; gap: 10px; align-items: center; }
.returning img { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; }

.queues { display: grid; gap: 16px; min-width: 0; }
@media (min-width: 981px) { .queues { position: sticky; top: 68px; } .queues .cards { max-height: calc(100vh - 220px); overflow-y: auto; } }
.scanbar { display: flex; gap: 8px; align-items: center; padding: 12px 16px; flex-wrap: wrap; }
.scanbar input { flex: 1; min-width: 200px; font-family: var(--mono); font-size: 15px; }
.cards { display: grid; gap: 10px; padding: 12px; }
.cards:empty::after { content: attr(data-empty); color: var(--ink-3); font-size: 13px; padding: 8px 4px; }
.vcard { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px 10px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); position: relative; overflow: hidden; }
.vcard::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--line-strong); }
.vcard.st-pending::before { background: var(--warn); }
.vcard.st-approved::before { background: var(--ok); }
.vcard.st-inside::before { background: var(--info); }
.vcard.st-rejected::before, .vcard.st-cancelled::before { background: var(--bad); }
.vcard.flash { animation: flash 1.6s ease-out 2; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 var(--ok); } 60% { box-shadow: 0 0 0 6px transparent; } }
@media (prefers-reduced-motion: reduce) { .vcard.flash { animation: none; outline: 2px solid var(--ok); } }
.vcard img, .vcard .noimg { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; background: var(--mute-bg); }
.vcard .meta { min-width: 0; }
.vcard .name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vcard .sub { color: var(--ink-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vcard .tiny { font-size: 12px; color: var(--ink-3); display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.vcard .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.vcard .warnline { color: var(--bad); }
@media (max-width: 560px) { .vcard { grid-template-columns: 48px 1fr; } .vcard .acts { grid-column: 1 / -1; justify-content: flex-start; } .vcard img, .vcard .noimg { width: 48px; height: 48px; } }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 12px; overflow-x: auto; }
.tabs button { font: inherit; font-weight: 600; background: none; border: 0; padding: 10px 12px; color: var(--ink-3); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- toast & dialog ---------- */
.toast { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 100; max-width: min(420px, calc(100vw - 32px)); font-weight: 500; }
.toast.err { background: var(--bad); color: #fff; }
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--surface); color: var(--ink); width: min(640px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(20, 12, 6, .45); }
.dlg-h { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dlg-h h3 { font-size: 16px; flex: 1; }
.dlg-b { padding: 16px 18px; display: grid; gap: 12px; max-height: 70vh; overflow: auto; }
.dlg-f { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.detail-top { display: grid; grid-template-columns: 140px 1fr; gap: 16px; }
@media (max-width: 520px) { .detail-top { grid-template-columns: 1fr; } }
.detail-top img { width: 140px; aspect-ratio: 3/4; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 12px; margin: 0; font-size: 13.5px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.photos { display: flex; gap: 10px; flex-wrap: wrap; }
.photos figure { margin: 0; font-size: 12px; color: var(--ink-3); }
.photos img { width: 120px; height: 90px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; margin-bottom: 4px; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.timeline li { display: grid; grid-template-columns: 150px 1fr; gap: 10px; }
.timeline time { color: var(--ink-3); font-family: var(--mono); font-size: 12px; }
@media (max-width: 520px) { .timeline li { grid-template-columns: 1fr; gap: 0; } }

/* ---------- admin ---------- */
.page { padding: 16px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left)); display: grid; gap: 16px; max-width: 1400px; margin: 0 auto; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.tile .k { font-size: 12px; color: var(--ink-3); font-weight: 600; letter-spacing: .03em; }
.tile .v { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile .d { font-size: 12px; color: var(--ink-2); }
.tile.alert .v { color: var(--warn); }
.two { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .two { grid-template-columns: 1fr; } }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.filters .field { flex: 1 1 140px; }
.filters .field.wide { flex: 2 1 220px; }
.tablewrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); font-weight: 700; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
table.data td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: var(--surface-2); }
table.data td.thumb { width: 44px; padding-right: 0; }
table.data td.thumb img { width: 36px; height: 36px; border-radius: 5px; object-fit: cover; display: block; }
table.data .nowrap { white-space: nowrap; }
.bars { display: flex; align-items: end; gap: 6px; height: 140px; padding: 8px 4px 0; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; height: 100%; justify-content: end; }
.bars .bar { width: 100%; max-width: 34px; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.bars .b.today .bar { opacity: 1; background: var(--brand); }
:root[data-theme="dark"] .bars .b.today .bar { background: var(--ink); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bars .b.today .bar { background: var(--ink); } }
.bars .lbl { font-size: 10.5px; color: var(--ink-3); font-family: var(--mono); }
.bars .val { font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rank li { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 13px; }
.rank .track { grid-column: 1 / -1; height: 6px; background: var(--mute-bg); border-radius: 3px; overflow: hidden; }
.rank .fill { height: 100%; background: var(--accent); }
.settings { display: grid; gap: 16px; max-width: 760px; }
.settings fieldset { border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px 16px; display: grid; gap: 12px; margin: 0; background: var(--surface); }
.settings legend { font-weight: 700; padding: 0 6px; }
.note { background: var(--warn-bg); color: var(--ink); border-left: 3px solid var(--warn); padding: 10px 12px; border-radius: 4px; font-size: 13px; }
.linkbox { display: flex; gap: 6px; }
.linkbox input { font-family: var(--mono); font-size: 12px; }

/* ---------- login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); background: var(--brand); }
.login { width: min(380px, 100%); background: var(--surface); border-radius: 12px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.3); display: grid; gap: 14px; }
.login .brand-mark { color: var(--ink); font-size: 26px; }
.login p { margin: 0; }
.err-text { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ---------- approval page (host's phone) ---------- */
.approve-body { min-height: 100vh; }
.approve { max-width: 560px; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left)); }
.approve-head { display: flex; gap: 10px; align-items: baseline; padding: 18px 0; color: var(--ink-2); font-size: 13px; }
.approve-head .brand-mark { color: var(--ink); }
.approve-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); display: grid; gap: 16px; }
.approve-top { display: grid; grid-template-columns: 120px 1fr; gap: 16px; align-items: start; }
.approve-top h1 { font-size: 22px; }
.approve-top p { margin: 4px 0 0; }
.approve-photo { width: 120px; aspect-ratio: 3/4; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.approve-photo.empty { display: grid; place-items: center; color: var(--ink-3); background: var(--mute-bg); font-size: 12px; }
.approve-grid { display: grid; gap: 0; margin: 0; border-top: 1px solid var(--line); }
.approve-grid .r { display: grid; grid-template-columns: 120px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.approve-grid dt { color: var(--ink-3); font-size: 13px; }
.approve-grid dd { margin: 0; overflow-wrap: anywhere; }
.approve-form { display: grid; gap: 10px; }
.approve-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.flash { padding: 12px 14px; border-radius: 8px; font-weight: 600; margin: 0; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.bad { background: var(--bad-bg); color: var(--bad); }
.status-line { margin: 0; padding: 12px 14px; background: var(--surface-2); border-radius: 8px; }
.foot { text-align: center; color: var(--ink-3); font-size: 12px; margin-top: 18px; }

/* ---------- printable pass (CR80-ish badge, prints on A4/A5 or badge printer) ---------- */
.pass-body { background: var(--bg); padding: 24px 16px; }
.pass-tools { text-align: center; margin-bottom: 16px; display: flex; gap: 8px; justify-content: center; }
.pass { width: 86mm; margin: 0 auto; background: #fff; color: #1a120c; border: 1px solid #cbbfb0; border-radius: 4mm; overflow: hidden; font-size: 9pt; }
.pass header { background: #3b2a1e; color: #f6eee4; display: flex; justify-content: space-between; align-items: center; padding: 2.5mm 4mm; }
.pass header b { letter-spacing: .18em; font-size: 12pt; }
.pass header span { font-size: 7.5pt; letter-spacing: .12em; font-weight: 700; }
.pass-main { display: grid; grid-template-columns: 26mm 1fr; gap: 3.5mm; padding: 3.5mm 4mm 2mm; }
.pass-main img, .pass-nophoto { width: 26mm; height: 32mm; object-fit: cover; border-radius: 1.5mm; border: .3mm solid #cbbfb0; background: #eee; display: grid; place-items: center; font-size: 7pt; color: #888; }
.pass-info h2 { font-size: 12pt; margin: 0 0 .5mm; }
.pass-info p { margin: 0 0 1.5mm; color: #5d5046; }
.pass-info dl { display: grid; grid-template-columns: auto 1fr; gap: .6mm 2.5mm; margin: 0; font-size: 8pt; }
.pass-info dt { color: #8b7e72; }
.pass-info dd { margin: 0; overflow-wrap: anywhere; }
.pass-code { display: grid; justify-items: center; padding: 1mm 4mm 2mm; }
.pass-code svg { width: 100%; height: 11mm; }
.pass-code span { font-family: var(--mono); font-size: 8.5pt; letter-spacing: .1em; }
.pass footer { background: #f3efe9; color: #5d5046; text-align: center; font-size: 6.8pt; padding: 1.5mm 3mm; }
@media print {
  @page { margin: 8mm; }
  .noprint { display: none !important; }
  .pass-body { background: #fff; padding: 0; }
  .pass { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
