:root {
  /* Black royal finance palette (dark — the default) */
  --navy-900: #090909;   /* base black */
  --navy-800: #0f0f10;
  --navy-700: #161617;
  --navy-600: #1e1e20;
  --ink: #f2f0ea;         /* warm off-white */
  --ink-dim: #a8a6a0;
  --ink-faint: #6f6d68;
  --gold: #c9a227;
  --gold-bright: #e8cd7e; /* readable gold accent text */
  --gold-soft: rgba(201, 162, 39, 0.12);
  --line: rgba(201, 162, 39, 0.20);
  --line-soft: rgba(255, 255, 255, 0.07);
  --ok: #4ea87a;
  --ok-bright: #6fd0a0;
  --err: #d98a8a;

  /* semantic surfaces — the only tokens that flip between themes */
  --bg: var(--navy-900);
  --surface: var(--surface);
  --surface-2: #141416;        /* opaque: sticky headers, stat tiles, code */
  --topbar-bg: rgba(9, 9, 9, 0.78);
  --input-bg: rgba(0, 0, 0, 0.5);
  --hover: rgba(255, 255, 255, 0.03);
  --shadow: 0 24px 60px -28px rgba(0, 0, 0, 0.9);
  --on-accent: var(--navy-900);
  --glow-a: rgba(201, 162, 39, 0.10);
  --glow-b: rgba(255, 255, 255, 0.03);
  --tint-live: rgba(201, 162, 39, 0.05);

  --radius: 12px;
  --sans: "Carlito", Calibri, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: Consolas, ui-monospace, "SF Mono", Menlo, monospace;
}

:root[data-theme="light"] {
  /* Parchment & antique-gold — the light counterpart */
  --ink: #23211b;
  --ink-dim: #565248;
  --ink-faint: #857f70;
  --gold: #8a6f1c;
  --gold-bright: #7c6214;
  --gold-soft: rgba(154, 125, 30, 0.13);
  --line: rgba(154, 125, 30, 0.30);
  --line-soft: rgba(28, 24, 10, 0.13);
  --ok: #2f8f5f;
  --ok-bright: #1f7a4c;
  --err: #c0392b;

  --bg: #f3f1e9;
  --surface: #ffffff;
  --surface-2: #f5f2e9;
  --topbar-bg: rgba(247, 245, 238, 0.85);
  --input-bg: #ffffff;
  --hover: rgba(28, 24, 10, 0.05);
  --shadow: 0 18px 44px -26px rgba(80, 66, 20, 0.24);
  --glow-a: rgba(201, 162, 39, 0.16);
  --glow-b: rgba(255, 255, 255, 0.55);
  --tint-live: rgba(154, 125, 30, 0.10);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.mono { font-family: var(--mono); }

.royal-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(1000px 560px at 50% -12%, var(--glow-a), transparent 60%),
    radial-gradient(800px 500px at 100% 100%, var(--glow-b), transparent 55%),
    var(--bg);
}
.royal-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 54px 54px;
  mask-image: radial-gradient(circle at 50% 15%, #000, transparent 70%);
  opacity: 0.35;
}

/* ---------- top bar ---------- */
.topbar {
  position: relative;
  z-index: 2;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
}
.topbar-inner {
  max-width: 1060px;
  margin: 0 auto;
  padding: 16px 26px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
}
.crest {
  color: var(--gold);
  font-size: 18px;
  line-height: 1;
}
.brand-text {
  font-family: var(--sans);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand-sub { color: var(--gold-bright); font-weight: 600; }
.tag {
  color: var(--ink-faint);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.topbar-form { margin-left: auto; }

/* ---------- layout ---------- */
.wrap {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: 1060px;
  margin: 0 auto;
  padding: 60px 26px;
}
.wrap-narrow { max-width: 452px; }

/* ---------- cards ---------- */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 30px;
  margin-bottom: 22px;
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: 0.7;
}
.login-card { padding: 36px 34px 30px; }
.card-head { margin-bottom: 24px; }
.card-muted { color: var(--ink-dim); }
.card-muted h2 { color: var(--ink); }

.eyebrow {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 10px;
}

h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
}
h2 {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 700;
}
.sub { margin: 0; color: var(--ink-dim); font-size: 14px; }

/* ---------- form ---------- */
.form { display: flex; flex-direction: column; gap: 18px; }
.form-inline { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.form-inline input { width: auto; }
.form-inline input[type="time"] {
  font-family: var(--mono);
  font-size: 15px;
  color-scheme: dark;
}
.form-inline .btn-primary { width: auto; margin-top: 0; }
.field { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.field-row { display: flex; gap: 16px; }

label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

input {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  background: var(--input-bg);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input.mono { letter-spacing: 0.3em; }
input::placeholder { color: var(--ink-faint); letter-spacing: normal; }
input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.account-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  font-size: 13.5px;
  color: var(--ink-dim);
  background: var(--gold-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.account-chip strong { color: var(--gold-bright); font-weight: 600; }
.account-chip .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 8px var(--gold);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s, background 0.15s, border-color 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 8px 14px; font-size: 11px; }
.btn-block { width: 100%; }
a.btn { text-decoration: none; }
.btn.is-disabled { opacity: 0.4; pointer-events: none; filter: grayscale(0.5); }

.btn-primary {
  width: 100%;
  margin-top: 4px;
  color: var(--on-accent);
  background: linear-gradient(135deg, #e8cd7e, #c9a227);  /* stays bright gold in both themes */
  box-shadow: 0 12px 30px -12px rgba(201, 162, 39, 0.6);
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(0.5); }

.btn-ghost {
  color: var(--ink);
  background: transparent;
  border-color: var(--line);
}
.btn-ghost:hover { border-color: var(--err); color: var(--err); }

/* ---------- misc ---------- */
.hint {
  margin: 22px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
  font-size: 11.5px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}

code {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--ink-dim);
}

.flashes { margin-bottom: 22px; }
.flash {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  margin-bottom: 10px;
  border: 1px solid transparent;
}
.flash-error { background: rgba(217, 138, 138, 0.1); border-color: rgba(217, 138, 138, 0.4); color: #f0cccc; }
.flash-success { background: rgba(78, 168, 122, 0.12); border-color: rgba(78, 168, 122, 0.4); color: #bfe8d3; }
:root[data-theme="light"] .flash-error { background: rgba(192, 57, 43, 0.08); border-color: rgba(192, 57, 43, 0.35); color: #8a241a; }
:root[data-theme="light"] .flash-success { background: rgba(47, 143, 95, 0.10); border-color: rgba(47, 143, 95, 0.35); color: #1b5a3b; }

.status-row { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.status-text { font-size: 16px; font-weight: 700; }
.badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-bright);
  background: var(--gold-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
}
.pulse {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ok-bright);
  animation: pulse 2.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(111, 208, 160, 0.55); }
  70% { box-shadow: 0 0 0 9px rgba(111, 208, 160, 0); }
  100% { box-shadow: 0 0 0 0 rgba(111, 208, 160, 0); }
}

.hero {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  padding: 20px 0 24px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--line-soft);
}
.hero > div { display: flex; flex-direction: column; gap: 4px; }
.hero-balance { margin-left: auto; text-align: right; }
.hero-label {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.hero-name strong, .hero-balance strong {
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
}
.hero-balance strong { color: var(--gold-bright); }
.hero-id { font-size: 12px; color: var(--ink-dim); }
.hero-sub { font-size: 12px; color: var(--ink-faint); }
.hero-since { margin: 4px 0 0; font-size: 12.5px; color: var(--ink-faint); }

.kv { display: grid; grid-template-columns: 128px 1fr; gap: 11px 18px; margin: 0; }
.kv dt {
  color: var(--ink-faint);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding-top: 2px;
}
.kv dd { margin: 0; word-break: break-all; font-size: 14px; }

@media (max-width: 480px) {
  .field-row { flex-direction: column; }
  .wrap { padding: 36px 20px; }
}

/* ============================ nav ============================ */
.mainnav { display: flex; gap: 4px; }
.mainnav a {
  padding: 7px 13px;
  font-size: 13px;
  color: var(--ink-dim);
  text-decoration: none;
  border-radius: 8px;
  border: 1px solid transparent;
}
.mainnav a:hover { color: var(--ink); background: var(--line-soft); }
.mainnav a.active {
  color: var(--gold-bright);
  border-color: var(--line);
  background: var(--gold-soft);
}

/* ---------- theme toggle ---------- */
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-right .topbar-form { margin: 0; }
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--gold-soft);
  color: var(--gold-bright);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.15s, filter 0.15s;
}
.theme-toggle:hover { border-color: var(--gold); filter: brightness(1.1); }
.theme-toggle::before { content: "\2600"; }              /* ☀ — dark active, offers light */
:root[data-theme="light"] .theme-toggle::before { content: "\263E"; }  /* ☾ — light active, offers dark */

/* ======================== wide layout ======================== */
.wrap-wide { max-width: 1400px; }

/* ====================== scanner top bar ====================== */
.scanner-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 18px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}
.sb-left { display: flex; align-items: baseline; gap: 10px; }
.sb-clock {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: 0.04em;
}
.sb-sep { color: var(--ink-faint); }
.sb-dim { color: var(--ink-faint); font-size: 13px; }
.sb-right { display: flex; gap: 8px; flex-wrap: wrap; }

.linkbtn {
  background: none;
  border: 1px solid var(--line-soft);
  color: var(--ink-faint);
  font: inherit;
  font-size: 11.5px;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.linkbtn:hover { color: var(--ink); border-color: var(--line); }

.chip {
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line-soft);
  color: var(--ink-dim);
  white-space: nowrap;
}
.chip-ok   { color: var(--ok-bright);   border-color: rgba(111,208,160,0.4); background: rgba(78,168,122,0.10); }
.chip-warn { color: var(--gold-bright); border-color: var(--line);          background: var(--gold-soft); }
.chip-bad  { color: var(--err);         border-color: rgba(217,138,138,0.4); background: rgba(217,138,138,0.10); }
.chip-dim  { color: var(--ink-faint); }

/* ======================== scan table ======================== */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
}
.table-hint {
  margin: 0;
  padding: 8px 15px;
  font-size: 11.5px;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--line-soft);
}
.scan-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
}
.scan-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--ink-dim);
  font-weight: 700;
  font-size: 13.5px;
  text-align: right;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  cursor: grab;
  user-select: none;
}
.scan-table thead th:active { cursor: grabbing; }
.scan-table thead th.dragging { opacity: 0.35; }
.scan-table thead th.drop-target { box-shadow: inset 3px 0 0 0 var(--gold-bright); }
.scan-table thead tr.grp th {
  cursor: default;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: center;
  padding: 7px 16px;
}
.scan-table thead tr.grp .grp-static { color: var(--ink-dim); }
.scan-table thead tr.grp .grp-live { color: var(--gold-bright); }
.scan-table thead tr.grp .grp-none { color: transparent; }
.scan-table th.col-sym, .scan-table td.col-sym { text-align: left; }
.scan-table th[data-k]:hover { color: var(--ink); }
.scan-table th.sorted { color: var(--gold-bright); }
.scan-table th.sorted::after { content: " ▾"; font-size: 9px; }
.scan-table th.sorted[data-dir="asc"]::after { content: " ▴"; }

.scan-table tbody td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-soft);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.scan-table tbody tr:hover td { background: var(--hover); }
.scan-table td.col-sym { font-weight: 600; color: var(--ink); }
.scan-table td.live { background: var(--tint-live); }
.scan-table th.live { color: var(--gold-bright); }
.scan-table td.up { color: var(--ok-bright); }
.scan-table td.down { color: var(--err); }

/* ================= split: scanner | positions ================= */
.wrap-scanner { max-width: 1600px; padding-top: 24px; padding-bottom: 24px; }

.scan-split {
  display: flex;
  gap: 16px;
  align-items: stretch;
  height: calc(100vh - 116px);
  min-height: 460px;
}

/* left — scanner, scrolls inside its own pane */
.scan-pane {
  flex: 1 1 60%;
  min-width: 0;                 /* let the table scroll instead of the page */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.scan-pane .scanner-bar { flex: none; margin-bottom: 12px; }
.scan-pane .table-wrap {
  flex: 1 1 auto;
  overflow: auto;               /* sticky thead anchors to this box */
}
.scan-pane .table-hint {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface-2);
}
.scan-pane #empty { flex: none; }

/* right — day positions */
.pos-pane {
  flex: 0 0 40%;
  min-width: 360px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
}

.pos-stats {
  flex: none;
  display: flex;
  gap: 1px;
  background: var(--line-soft);
  border-bottom: 1px solid var(--line);
}
.pos-stats .stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  background: var(--surface-2);
}
.stat-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.stat-val {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.stat-val.up { color: var(--ok-bright); }
.stat-val.down { color: var(--err); }

.pos-head {
  flex: none;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px 8px;
}
.pos-head .eyebrow { margin: 0; }
.pos-err { font-size: 11.5px; color: var(--err); text-align: right; }

.pos-tablewrap { flex: 1 1 auto; overflow: auto; position: relative; }

.pos-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.pos-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--ink-dim);
  font-weight: 700;
  font-size: 12px;
  text-align: right;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.pos-table th.col-sym, .pos-table td.col-sym { text-align: left; }
.pos-table tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line-soft);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.pos-table td.col-sym { font-weight: 600; color: var(--ink); }
.pos-table td.num { font-family: var(--mono); }
.pos-table td.dim { color: var(--ink-faint); }
.pos-table td.up { color: var(--ok-bright); }
.pos-table td.down { color: var(--err); }
.pos-table tbody tr:hover td { background: var(--hover); }
.pos-table tbody tr.closed td { opacity: 0.5; }

.pos-empty {
  margin: 0;
  padding: 20px 16px;
  font-size: 13px;
  color: var(--ink-faint);
}

@media (max-width: 980px) {
  .scan-split { flex-direction: column; height: auto; }
  .scan-pane, .pos-pane { flex: none; overflow: visible; }
  .scan-pane .table-wrap { max-height: 60vh; }
  .pos-pane { flex: none; }
  .pos-tablewrap { max-height: 50vh; }
}

/* ==================== controls validation ==================== */
textarea {
  width: 100%;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--input-bg);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  resize: vertical;
}
textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }

.valresults { margin-top: 24px; }
.vallist { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.vallist li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
  border: 1px solid var(--line-soft);
}
.vallist li.ok  { background: rgba(78,168,122,0.08); }
.vallist li.bad { background: rgba(217,138,138,0.08); }
.vmark { font-weight: 700; }
.vallist li.ok .vmark  { color: var(--ok-bright); }
.vallist li.bad .vmark { color: var(--err); }
.vsym { color: var(--ink); }
.vdim { color: var(--ink-faint); }

/* ======================== mobile ======================== */
@media (max-width: 600px) {
  .topbar-inner {
    padding: 10px 14px;
    gap: 8px 10px;
    flex-wrap: wrap;
  }
  .brand-text { font-size: 17px; white-space: nowrap; }
  .crest { font-size: 15px; }
  .tag { display: none; }

  .mainnav {
    order: 3;
    width: 100%;
    gap: 6px;
  }
  .mainnav a { flex: 1; text-align: center; padding: 7px 8px; font-size: 12.5px; }
  .topbar-right { order: 2; gap: 8px; }
  .btn-sm { padding: 7px 11px; }
  .theme-toggle { width: 30px; height: 30px; font-size: 13px; }

  .wrap { padding: 18px 14px; }
  .wrap-scanner { padding: 14px 12px; }
  .card { padding: 22px 18px; }

  .scanner-bar { padding: 10px 12px; margin-bottom: 10px; }
  .sb-clock { font-size: 16px; }
  .chip { font-size: 11px; padding: 4px 9px; }

  .scan-split { height: auto; min-height: 0; }
  .scan-pane .table-wrap { max-height: 66vh; }
  .pos-tablewrap { max-height: none; }

  .stat-val { font-size: 17px; }
  .pos-stats .stat { padding: 12px 14px; }
}
