/* ==========================================================================
   Value Scanner - design system
   Calm surfaces, one accent, semantic colour reserved for value/risk only.
   ========================================================================== */

:root {
  --bg:            #fafafb;
  --surface:       #ffffff;
  --surface-2:     #f5f6f8;
  --surface-3:     #eef0f4;
  --border:        #e6e8ed;
  --border-strong: #d4d7e0;

  --text:   #16181d;
  --text-2: #5b6170;
  --text-3: #8d93a3;

  --accent:      #4f46e5;
  --accent-hover:#4338ca;
  --accent-soft: #eef2ff;
  --accent-line: #c7d0fb;

  --pos:      #0d8f5b;
  --pos-soft: #e7f6ee;
  --neg:      #cf4436;
  --neg-soft: #fdeeec;
  --warn:     #a8710e;
  --warn-soft:#fdf4e3;
  --info-soft:#eaf2fd;

  --radius:    10px;
  --radius-sm: 7px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(16, 20, 34, .05);
  --shadow:    0 4px 14px rgba(16, 20, 34, .08);
  --shadow-lg: 0 18px 48px rgba(16, 20, 34, .16);

  --sidebar-w: 232px;
  --topbar-h:  57px;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg:            #0c0d11;
  --surface:       #13151b;
  --surface-2:     #191c23;
  --surface-3:     #21242d;
  --border:        #23262f;
  --border-strong: #333743;

  --text:   #e9ebf1;
  --text-2: #98a0b0;
  --text-3: #6b7284;

  --accent:      #7b78f5;
  --accent-hover:#8f8cf8;
  --accent-soft: #1c1d33;
  --accent-line: #3a3866;

  --pos:      #35c48a;
  --pos-soft: #0f2a20;
  --neg:      #f0665a;
  --neg-soft: #2e1715;
  --warn:     #e0a63f;
  --warn-soft:#2b2110;
  --info-soft:#141f2e;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow:    0 4px 14px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

::selection { background: var(--accent-soft); color: var(--text); }

/* scrollbars ------------------------------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 6px;
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

/* ==========================================================================
   layout
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand-mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: linear-gradient(140deg, var(--accent), #8b5cf6);
  display: grid; place-items: center;
  color: #fff; font-size: 13px; font-weight: 700;
  flex-shrink: 0;
}

.brand-name { font-weight: 620; letter-spacing: -.01em; font-size: 14.5px; }
.brand-sub  { font-size: 11px; color: var(--text-3); margin-top: -2px; }

.nav { padding: 12px 10px; overflow-y: auto; flex: 1; min-height: 0; }
.nav-group { margin-bottom: 18px; }
.nav-label {
  font-size: 10.5px; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-3);
  padding: 0 10px 7px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  user-select: none;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 560; }
.nav-item .ico { width: 16px; display: grid; place-items: center; opacity: .85; }
.nav-item .badge {
  margin-left: auto;
  font-family: var(--mono); font-size: 10.5px;
  color: var(--text-3);
  background: var(--surface-2);
  padding: 1px 6px; border-radius: 20px;
}
.nav-item.active .badge { background: #fff2; color: inherit; }

.sidebar-foot {
  padding: 12px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-3);
  flex-shrink: 0;
}

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
  flex-shrink: 0;
}
.topbar h1 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.topbar .sub { font-size: 12px; color: var(--text-3); }
.topbar .spacer { flex: 1; }

.content { flex: 1; overflow: auto; min-height: 0; }
.view { padding: 22px 24px 60px; max-width: 1560px; }
.view.wide { max-width: none; }

/* ==========================================================================
   primitives
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 16px; }
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.card-head h2 { margin: 0; font-size: 13.5px; font-weight: 600; letter-spacing: -.005em; }
.card-head .hint { font-size: 12px; color: var(--text-3); font-weight: 400; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.card-body.tight { padding: 12px; }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 1fr) 372px; align-items: start; }
@media (max-width: 1180px) {
  .grid.c3, .grid.c4, .grid.side { grid-template-columns: minmax(0, 1fr); }
}

.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* buttons ---------------------------------------------------------------- */
.btn {
  appearance: none;
  font: inherit;
  font-size: 13px;
  font-weight: 520;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--neg); border-color: var(--border-strong); }
.btn.danger:hover { background: var(--neg-soft); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.icon { padding: 6px; width: 30px; justify-content: center; }

/* inputs ----------------------------------------------------------------- */
label.field { display: block; }
.field-label {
  display: block;
  font-size: 11.5px; font-weight: 560; color: var(--text-2);
  margin-bottom: 5px;
  letter-spacing: .005em;
}
input[type="text"], input[type="number"], input[type="password"],
input[type="search"], select, textarea {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
textarea { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 12.5px; line-height: 1.65; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M1 1l4 4 4-4' stroke='%238d93a3' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; user-select: none; }
.check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; margin: 0; }

/* chips ------------------------------------------------------------------ */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500;
  padding: 3px 9px;
  border-radius: 20px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  transition: all .12s;
}
.chip:hover { background: var(--surface-2); color: var(--text); }
.chip.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.chip .n { font-family: var(--mono); font-size: 10.5px; opacity: .7; }
.chip.static { cursor: default; }

.tag {
  display: inline-flex; align-items: center;
  font-size: 10.5px; font-weight: 620; letter-spacing: .03em;
  padding: 2px 7px; border-radius: 5px;
  text-transform: uppercase;
  white-space: nowrap;
}
.tag.strong { background: var(--pos-soft); color: var(--pos); }
.tag.value  { background: var(--info-soft); color: var(--accent); }
.tag.thin   { background: var(--surface-3); color: var(--text-2); }
.tag.unver  { background: var(--warn-soft); color: var(--warn); }
.tag.neutral{ background: var(--surface-3); color: var(--text-3); }
.tag.neg    { background: var(--neg-soft); color: var(--neg); }

.grade {
  display: inline-grid; place-items: center;
  width: 20px; height: 20px; border-radius: 5px;
  font-size: 11px; font-weight: 700;
  font-family: var(--mono);
}
.grade.A { background: var(--pos-soft); color: var(--pos); }
.grade.B { background: var(--info-soft); color: var(--accent); }
.grade.C { background: var(--surface-3); color: var(--text-2); }
.grade.D { background: var(--warn-soft); color: var(--warn); }
.grade.E { background: var(--neg-soft); color: var(--neg); }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--text-3); }
.dim { color: var(--text-2); }

/* stats ------------------------------------------------------------------ */
.stat { padding: 14px 16px; }
.stat-label {
  font-size: 11px; font-weight: 560; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .06em;
}
.stat-value {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 23px; font-weight: 600; letter-spacing: -.02em;
  margin-top: 4px; line-height: 1.15;
}
.stat-sub { font-size: 12px; color: var(--text-3); margin-top: 3px; }

/* meter ------------------------------------------------------------------ */
.meter { height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width .25s; }
.meter.pos > i { background: var(--pos); }
.meter.warn > i { background: var(--warn); }
.meter.neg > i { background: var(--neg); }

/* ==========================================================================
   table
   ========================================================================== */

.table-wrap { overflow: auto; max-height: calc(100vh - var(--topbar-h) - 210px); }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.data thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  font-size: 11px; font-weight: 620; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
table.data thead th:hover { color: var(--text); }
table.data thead th.sorted { color: var(--accent); }
table.data thead th.r, table.data td.r { text-align: right; }
table.data thead th.c, table.data td.c { text-align: center; }
table.data tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tbody tr.sel td { background: var(--accent-soft); }
table.data tbody tr.picked td { box-shadow: inset 2px 0 0 var(--accent); }
table.data td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.ev-name { font-weight: 520; }
.ev-meta { font-size: 11.5px; color: var(--text-3); margin-top: 1px; }
.cell-tight { line-height: 1.35; }

.empty {
  padding: 56px 20px;
  text-align: center;
  color: var(--text-3);
}
.empty .big { font-size: 15px; color: var(--text-2); margin-bottom: 5px; font-weight: 520; }

/* ==========================================================================
   filter bar
   ========================================================================== */

.filters { padding: 14px 18px; display: flex; flex-direction: column; gap: 12px; }
.filter-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.filter-row .field { width: 108px; flex-shrink: 0; }
.filter-row .field.grow { flex: 1; min-width: 190px; width: auto; }
.facets { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.facet-label {
  font-size: 11px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .05em;
  width: 62px; flex-shrink: 0;
}

/* ==========================================================================
   drawer
   ========================================================================== */

.drawer-back {
  position: fixed; inset: 0;
  background: rgba(12, 14, 20, .34);
  z-index: 40;
  opacity: 0; pointer-events: none;
  transition: opacity .18s;
}
.drawer-back.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 470px; max-width: 94vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 41;
  transform: translateX(102%);
  transition: transform .22s cubic-bezier(.32, .72, 0, 1);
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head {
  padding: 15px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 12px; flex-shrink: 0;
}
.drawer-body { overflow-y: auto; padding: 18px; flex: 1; }
.drawer-foot {
  padding: 12px 18px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; flex-shrink: 0;
}

.kv { display: grid; grid-template-columns: 1fr auto; gap: 7px 14px; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }

.section-title {
  font-size: 11px; font-weight: 620; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-3); margin: 22px 0 9px;
}
.section-title:first-child { margin-top: 0; }

/* ==========================================================================
   slip
   ========================================================================== */

.slip-leg {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  display: flex; gap: 10px; align-items: flex-start;
}
.slip-leg + .slip-leg { margin-top: 8px; }
.slip-leg .x { margin-left: auto; }
.slip-leg.carrier { border-left: 2px solid var(--accent); }
.slip-leg.support { border-left: 2px solid var(--text-3); }

.check-list { display: flex; flex-direction: column; gap: 6px; }
.check-item {
  display: flex; align-items: center; gap: 9px;
  font-size: 12.5px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.check-item .dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
  background: var(--pos);
}
.check-item.bad { background: var(--neg-soft); }
.check-item.bad .dot { background: var(--neg); }
.check-item .detail { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--text-3); }

/* ==========================================================================
   misc
   ========================================================================== */

.spark { display: block; width: 100%; height: 42px; }

.toast-host {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.toast {
  background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 20px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow);
  animation: rise .22s ease-out;
}
.toast.err { background: var(--neg); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.spinner {
  width: 14px; height: 14px; flex-shrink: 0;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.dot-live {
  width: 7px; height: 7px; border-radius: 50%; background: var(--pos);
  box-shadow: 0 0 0 3px var(--pos-soft);
  flex-shrink: 0;
}
.dot-live.off { background: var(--text-3); box-shadow: 0 0 0 3px var(--surface-3); }

code.inline {
  font-family: var(--mono); font-size: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 4px;
}

.formula {
  font-family: var(--mono); font-size: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  color: var(--text);
  overflow-x: auto;
  white-space: nowrap;
}

.note {
  font-size: 12.5px; color: var(--text-2); line-height: 1.6;
}
.note strong { color: var(--text); font-weight: 560; }

.callout {
  border-left: 2px solid var(--accent-line);
  background: var(--accent-soft);
  padding: 10px 14px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.6;
}
.callout.warn { border-color: var(--warn); background: var(--warn-soft); }


/* ==========================================================================
   ticket capture
   ========================================================================== */

video { display: block; }

.shot-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* On a phone the sidebar would eat the screen, so it collapses to a strip
   of icons and the content takes over. */
@media (max-width: 720px) {
  :root { --sidebar-w: 62px; }
  .brand-name, .brand-sub, .nav-item span:not(.ico), .nav-label,
  .sidebar-foot { display: none; }
  .nav-item { justify-content: center; padding: 10px 0; }
  .brand { justify-content: center; padding: 0; }
  .view { padding: 14px 12px 48px; }
  .grid.side, .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: minmax(0, 1fr); }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar h1 { font-size: 14px; }
  .topbar .sub { display: none; }
  .filter-row .field { width: calc(50% - 5px); }
}


/* ==========================================================================
   login gate
   Signed out there is no application to show, so the shell collapses to a
   single centred column and the sidebar is not rendered at all.
   ========================================================================== */

body[data-gate="on"] .app { grid-template-columns: 1fr; }
body[data-gate="on"] .sidebar { display: none; }
body[data-gate="on"] .topbar { justify-content: center; }
body[data-gate="on"] .topbar h1 { font-size: 14px; }
body[data-gate="on"] .content { display: grid; place-items: start center; }
body[data-gate="on"] .view { width: 100%; max-width: 470px; padding-top: 6vh; }
