/* Staff screens: operator scanner + admin console. Loaded after app.css */
:root { --s1: #0086B3; --s2: #D08A1C; --s3: #7A5BC0; --s4: #3E9E6A; --grid: #E6ECEA }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --s1: #2A9CC8; --s2: #B87A12; --s3: #9479D8; --s4: #3FA06C; --grid: #24333A } }
:root[data-theme="dark"] { --s1: #2A9CC8; --s2: #B87A12; --s3: #9479D8; --s4: #3FA06C; --grid: #24333A }

.topbar {
  background: var(--ink); color: var(--on-ink); position: sticky; top: 0; z-index: 30;
  padding: calc(8px + env(safe-area-inset-top, 0px)) max(14px, env(safe-area-inset-right, 0px)) 8px max(14px, env(safe-area-inset-left, 0px));
  display: flex; align-items: center; gap: 10px; min-height: 60px
}
.topbar .brand { display: flex; align-items: center; gap: 10px; min-width: 0 }
.topbar .brand b { display: block; font-size: 14.5px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.topbar .brand small { display: block; font-size: 11.5px; opacity: .75 }
.topbar .seal { width: 34px; height: 34px; font-size: 11px }
.topbar .sp { flex: 1 }
.icon-btn {
  background: transparent; border: 1px solid rgba(255, 255, 255, .22); color: inherit; border-radius: 10px; min-width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0 10px; gap: 6px; font-size: 13.5px
}
.icon-btn svg { width: 19px; height: 19px }
.icon-btn:hover { background: var(--ink-2) }

/* ---------- login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--ink); position: relative; overflow: hidden }
.login-wrap::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: repeating-radial-gradient(circle at 15% 115%, transparent 0 18px, rgba(169, 122, 34, .13) 18px 19px) }
.login-card { position: relative; z-index: 1; width: 100%; max-width: 400px }

/* ---------- operator ---------- */
.op-main { max-width: 640px; margin: 0 auto; padding: 14px max(14px, env(safe-area-inset-left, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) }
.counters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px }
.counter { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; text-align: center }
.counter b { display: block; font-size: 22px; font-weight: 800; line-height: 1.3; font-variant-numeric: tabular-nums }
.counter span { font-size: 12px; color: var(--muted) }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px }
.tabs button { flex: 1; border: 0; background: transparent; border-radius: 9px; min-height: 42px; font-weight: 700; font-size: 14px; cursor: pointer; color: var(--muted) }
.tabs button.on { background: var(--ink); color: var(--on-ink) }
.scanner { position: relative; border-radius: 16px; overflow: hidden; background: #000; aspect-ratio: 1 / 1; max-height: 62vh; width: 100%; margin-inline: auto }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block }
.scanner .frame { position: absolute; inset: 14%; border-radius: 18px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); pointer-events: none }
.scanner .frame::before, .scanner .frame::after { content: ""; position: absolute; inset: 0; border-radius: 18px; border: 3px solid var(--brass); clip-path: polygon(0 0, 22% 0, 22% 3%, 3% 3%, 3% 22%, 0 22%, 0 78%, 3% 78%, 3% 97%, 22% 97%, 22% 100%, 78% 100%, 78% 97%, 97% 97%, 97% 78%, 100% 78%, 100% 22%, 97% 22%, 97% 3%, 78% 3%, 78% 0, 100% 0, 100% 100%, 0 100%) }
.scanner .frame::after { border: 0; height: 2px; top: 50%; background: linear-gradient(90deg, transparent, var(--brass), transparent); animation: scanline 2.2s ease-in-out infinite; clip-path: none; inset: 50% 6% auto }
@keyframes scanline { 0%, 100% { transform: translateY(-110px) } 50% { transform: translateY(110px) } }
.scanner .overlay { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; text-align: center; padding: 24px; background: rgba(14, 58, 68, .92) }
.scanner .tools { position: absolute; bottom: 10px; inset-inline: 10px; display: flex; gap: 8px; justify-content: center }
.scanner .tools .icon-btn { background: rgba(0, 0, 0, .45); color: #fff; border-color: rgba(255, 255, 255, .3) }

.result { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: var(--paper); overflow: auto; animation: rise .18s ease-out }
@keyframes rise { from { transform: translateY(16px); opacity: .4 } }
.result .rhead { padding: calc(18px + env(safe-area-inset-top, 0px)) 18px 18px; color: #fff; display: flex; gap: 12px; align-items: center }
.result .rhead .big { width: 52px; height: 52px; border-radius: 50%; background: rgba(255, 255, 255, .2); display: grid; place-items: center; flex-shrink: 0 }
.result .rhead .big svg { width: 30px; height: 30px }
.result .rhead b { font-size: 19px; display: block; line-height: 1.4 }
.result .rhead span { font-size: 14px; opacity: .92 }
.result.ok .rhead { background: #1E7A4C }
.result.warn .rhead { background: #9A6200 }
.result.bad .rhead { background: #A23A2C }
.result .rbody { padding: 16px 18px; max-width: 640px; width: 100%; margin: 0 auto; flex: 1 }
.person { display: flex; gap: 14px; align-items: flex-start }
.person .ph { width: 108px; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; color: var(--muted); flex-shrink: 0 }
.person .ph img { width: 100%; height: 100%; object-fit: cover }
.person .ph svg { width: 40px; height: 40px; opacity: .5 }
.person h2 { font-size: 22px }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 14.5px; margin-top: 6px }
.kv dt { color: var(--muted) }
.kv dd { margin: 0; font-weight: 500 }
.history { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px }
.history li { font-size: 13.5px; color: var(--muted); padding: 3px 0 }
.history ul { list-style: none; padding: 0; margin: 4px 0 0 }
.result .rfoot { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px)); display: flex; gap: 10px }
.result .rfoot .btn { flex: 1; min-height: 58px; font-size: 17px }
.recent { list-style: none; padding: 0; margin: 0 }
.recent li { display: flex; justify-content: space-between; gap: 8px; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: 14px }
.recent li:last-child { border: 0 }
.tag { font-size: 11.5px; padding: 1px 8px; border-radius: 99px; background: var(--ok-bg); color: var(--ok); font-weight: 700; white-space: nowrap }
.tag.warn { background: var(--warn-bg); color: var(--warn) }
.tag.bad { background: var(--bad-bg); color: var(--bad) }
.tag.mute { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line) }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; user-select: none }
.switch input { appearance: none; width: 44px; height: 26px; border-radius: 99px; background: var(--line-2); position: relative; cursor: pointer; transition: .15s; flex-shrink: 0; margin: 0 }
.switch input::after { content: ""; position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 3px rgba(0, 0, 0, .2) }
.switch input:checked { background: var(--ok) }
.switch input:checked::after { right: 21px }
select.input { appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235B6D70' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-position: left 10px center; background-size: 16px 16px; background-repeat: no-repeat; padding-left: 32px }
.icon-btn { text-decoration: none }
.gate-row { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px }
.gate-row label { font-size: 13px; color: var(--muted); white-space: nowrap }
.gate-row select { min-height: 40px; font-size: 15px; font-weight: 700; border: 0; background-color: transparent; padding-right: 4px }
.counters.two { grid-template-columns: 1fr 1fr }

/* ---------- admin ---------- */
.admin { display: grid; grid-template-columns: 230px 1fr; min-height: calc(100dvh - 60px) }
.side { background: var(--surface); border-left: 1px solid var(--line); padding: 14px 10px; position: sticky; top: 60px; height: calc(100dvh - 60px); overflow: auto }
.side button { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; text-align: right; border-radius: 10px; padding: 10px 12px; cursor: pointer; font-size: 14.5px; color: var(--fg) }
.side button svg { width: 19px; height: 19px; opacity: .75 }
.side button:hover { background: var(--surface-2) }
.side button.on { background: var(--ink); color: var(--on-ink); box-shadow: inset -3px 0 0 var(--brass) }
.side button.on svg { opacity: 1 }
.content { padding: 18px clamp(14px, 2.5vw, 28px) 40px; min-width: 0 }
.ph-title { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px }
.ph-title h1 { font-size: 24px }
@media (max-width: 860px) {
  .admin { grid-template-columns: 1fr }
  .side { position: sticky; top: 60px; height: auto; display: flex; overflow-x: auto; border: 0; border-bottom: 1px solid var(--line); padding: 6px 8px; z-index: 20; gap: 2px }
  .side button { width: auto; white-space: nowrap; padding: 8px 12px; font-size: 13.5px }
  .side button.on { box-shadow: inset 0 -3px 0 var(--brass) }
  .side hr { display: none }
}
.side hr { border: 0; border-top: 1px solid var(--line); margin: 8px 4px }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 14px }
.filters .f { display: flex; flex-direction: column; gap: 2px; min-width: 130px; flex: 1 1 140px }
.filters .f label { font-size: 12px; color: var(--muted) }
.filters .input { min-height: 40px; padding: 6px 10px; font-size: 14px; border-radius: 9px }
.filters .btn { min-height: 40px }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 12px }
.fchip { display: inline-flex; gap: 6px; align-items: center; background: var(--brass-soft); border: 1px solid rgba(169, 122, 34, .35); border-radius: 99px; padding: 2px 4px 2px 10px; font-size: 13px }
.fchip button { border: 0; background: transparent; cursor: pointer; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; color: inherit }
.fchip button svg { width: 13px; height: 13px }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px }
.kpi span { font-size: 12.5px; color: var(--muted); display: block }
.kpi b { font-size: 28px; font-weight: 800; line-height: 1.35; display: block; font-variant-numeric: tabular-nums }
.kpi small { font-size: 12px; color: var(--muted) }
.kpi.hl { border-top: 3px solid var(--brass) }
.charts { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px }
.chart { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; grid-column: span 6; min-width: 0 }
.chart.w12 { grid-column: span 12 }
.chart.w4 { grid-column: span 4 }
.chart.w8 { grid-column: span 8 }
@media (max-width: 1100px) { .chart.w4 { grid-column: span 6 } .chart.w8 { grid-column: span 12 } }
@media (max-width: 760px) { .chart, .chart.w4, .chart.w8 { grid-column: span 12 } }
.chart h3 { font-family: var(--body); font-size: 15px; font-weight: 700 }
.chart .csub { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center }
.chart .cbox { position: relative; height: 260px }
.chart .cbox.tall { height: 360px }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--muted); margin-top: 6px }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 5px; vertical-align: -1px }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 40px 0 }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden }
.seg button { border: 0; background: var(--surface); padding: 3px 10px; font-size: 12.5px; cursor: pointer; color: var(--muted) }
.seg button.on { background: var(--ink); color: var(--on-ink) }

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: auto }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 760px }
table.t th { text-align: right; font-weight: 700; font-size: 12.5px; color: var(--muted); background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; white-space: nowrap }
table.t td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle }
table.t tr:last-child td { border-bottom: 0 }
table.t tbody tr { cursor: pointer }
table.t tbody tr:hover { background: var(--surface-2) }
table.t td.n { font-variant-numeric: tabular-nums; direction: ltr; text-align: right }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 2px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted) }
.pager .row { gap: 6px }

.drawer-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 70 }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(460px, 100vw); background: var(--paper); z-index: 71; overflow: auto; box-shadow: 0 0 40px rgba(0, 0, 0, .3); animation: slide .2s ease-out }
@keyframes slide { from { transform: translateX(-30px); opacity: .5 } }
.drawer header { background: var(--ink); color: var(--on-ink); padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 14px; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 2 }
.drawer .dbody { padding: 16px }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 12px }
.panel h3 { font-family: var(--body); font-size: 15.5px; margin-bottom: 10px }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px }
.form-grid .full { grid-column: 1 / -1 }
textarea.input { min-height: 110px; resize: vertical; line-height: 1.8 }
.poster { background: #fff; color: #0E3A44; border-radius: 14px; padding: 28px; text-align: center; max-width: 520px; margin: 0 auto; border: 1px solid var(--line) }
.poster h2 { font-size: 26px; color: #0E3A44 }
.poster img.qr { width: 78%; margin: 16px auto; image-rendering: pixelated }
.poster .ins { font-size: 17px; font-weight: 700 }
.poster .bar { background: #0E3A44; color: #F2F6F5; border-radius: 10px; padding: 10px; margin-top: 14px; font-size: 15px }
.poster .bar b { color: #E1B75E }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0) }

@media print {
  .topbar, .side, .no-print, .filters { display: none !important }
  .admin { display: block }
  .content { padding: 0 }
  .poster { border: 0; max-width: none; -webkit-print-color-adjust: exact; print-color-adjust: exact }
  @page { size: A4 portrait; margin: 14mm }
}

.kv dd.ltr { display: block; text-align: right }
.scanner .scan-status { position: absolute; top: 10px; inset-inline: 10px; text-align: center; color: #fff; font-size: 12.5px; background: rgba(0,0,0,.5); border-radius: 8px; padding: 4px 8px; pointer-events: none }
