/* ==========================================================================
   Tally dashboard — built on the SOAi brand tokens (brand/tokens.css v1).
   Palette values are copied, never invented.

   No webfonts on purpose: the demo is specified to run with no network at all,
   and a blocked font request is a visible reflow in front of a prospect. The
   brand stacks already fall back to Georgia (display) and the system sans
   (body), which keeps the serif/sans pairing intact offline.
   ========================================================================== */

:root {
  /* --- CORE PALETTE --- */
  --navy: #1B2A4A;
  --navy-l: #253660;
  --navy-d: #0F1B30;
  --cream: #E8E0C8;
  --cream-d: #D4C9A8;
  --gold: #C9A961;

  /* --- NEUTRALS --- */
  --bg: #FDFCFA;
  --bg-warm: #F5F2EC;
  --text: #1B2A4A;
  --text-muted: #6B7280;
  --text-faint: #9CA3AF;
  --border: #E8E4DC;
  --border-n: rgba(27, 42, 74, 0.14);

  --navy-xl: rgba(27, 42, 74, 0.07);
  --navy-xxl: rgba(27, 42, 74, 0.04);

  /* --- STATES --- */
  --error: #B8483D;
  --success: #6B8E5A;

  /* --- RADII --- */
  --r-full: 9999px;
  --r-lg: 20px;
  --r: 12px;
  --r-sm: 8px;

  /* --- SHADOWS: navy-tinted, layered, never flat black --- */
  --shadow-sm: 0 2px 8px rgba(27, 42, 74, 0.06), 0 1px 2px rgba(27, 42, 74, 0.04);
  --shadow-md: 0 8px 24px rgba(27, 42, 74, 0.09), 0 2px 6px rgba(27, 42, 74, 0.05);
  --shadow-lg: 0 20px 48px rgba(27, 42, 74, 0.12), 0 6px 16px rgba(27, 42, 74, 0.07);

  /* --- TYPOGRAPHY --- */
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  /* --- SPACING SCALE: one ladder, used everywhere --- */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px; --s8: 72px;

  --container: 1160px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  /* Layered radial washes, not a single flat fill, plus an SVG grain layer so
     large empty areas have depth instead of reading as dead space. */
  background-color: var(--bg);
  background-image:
    radial-gradient(1100px 620px at 12% -8%, rgba(201, 169, 97, 0.10), transparent 62%),
    radial-gradient(900px 560px at 92% 4%, rgba(27, 42, 74, 0.07), transparent 60%),
    radial-gradient(760px 520px at 50% 108%, rgba(232, 224, 200, 0.34), transparent 66%);
  background-attachment: fixed;
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}

.shell { position: relative; z-index: 1; max-width: var(--container); margin: 0 auto; padding: 0 var(--s5) var(--s8); }

/* --- header ------------------------------------------------------------- */
.masthead { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s3); padding: var(--s6) 0 var(--s5); }
.wordmark { font-family: var(--font-display); font-size: 2.1rem; letter-spacing: -0.03em; margin: 0; line-height: 1.1; }
.wordmark .dot { color: var(--gold); }
.tagline { color: var(--text-muted); font-size: 0.875rem; margin: 0; }
.build-chip {
  margin-left: auto; font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-muted); background: var(--navy-xxl); border: 1px solid var(--border);
  border-radius: var(--r-full); padding: var(--s1) var(--s3);
}

/* --- tabs --------------------------------------------------------------- */
.tabs { display: flex; flex-wrap: wrap; gap: var(--s1); border-bottom: 1px solid var(--border); margin-bottom: var(--s6); }
.tab {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font: inherit; font-size: 0.9rem; font-weight: 500; color: var(--text-muted);
  padding: var(--s3) var(--s4); border-radius: var(--r-sm) var(--r-sm) 0 0;
  position: relative; transition: color 160ms var(--ease), transform 160ms var(--ease);
}
.tab::after {
  content: ""; position: absolute; left: var(--s4); right: var(--s4); bottom: -1px; height: 2px;
  background: var(--gold); border-radius: var(--r-full);
  transform: scaleX(0); transform-origin: center; transition: transform 220ms var(--ease);
}
.tab:hover { color: var(--text); }
.tab:active { transform: translateY(1px); }
.tab:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.tab[aria-selected="true"] { color: var(--text); font-weight: 600; }
.tab[aria-selected="true"]::after { transform: scaleX(1); }

.panel[hidden] { display: none; }

/* --- cards -------------------------------------------------------------- */
.card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); padding: var(--s5); margin-bottom: var(--s5);
}
.card h2 { font-family: var(--font-display); font-size: 1.35rem; letter-spacing: -0.02em; margin: 0 0 var(--s1); line-height: 1.25; }
.card .sub { color: var(--text-muted); font-size: 0.875rem; margin: 0 0 var(--s5); }

/* --- buttons ------------------------------------------------------------ */
.btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 600; font-size: 0.9rem;
  border-radius: var(--r-full); padding: var(--s3) var(--s5); border: 1px solid transparent;
  transition: transform 180ms var(--ease), box-shadow 180ms var(--ease), opacity 180ms var(--ease);
}
.btn-primary { background: var(--navy); color: var(--cream); box-shadow: var(--shadow-sm); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: transparent; color: var(--navy); border-color: var(--border-n); }
.btn-ghost:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.btn-ghost:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.btn[disabled] { opacity: 0.5; cursor: progress; transform: none; }
.actions { display: flex; flex-wrap: wrap; gap: var(--s3); }

/* --- stat tiles --------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--s3); margin-top: var(--s5); }
.tile { background: var(--bg-warm); border: 1px solid var(--border); border-radius: var(--r); padding: var(--s4); }
.tile .n { font-family: var(--font-display); font-size: 2rem; line-height: 1; letter-spacing: -0.03em; }
.tile .k { font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); margin-top: var(--s2); }
.tile.is-flag .n { color: var(--error); }

/* --- table -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; min-width: 720px; }
th {
  text-align: left; font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 600; padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: var(--s3); border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { transition: background-color 140ms var(--ease); }
tbody tr:hover { background: var(--navy-xxl); }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.vendor { font-weight: 600; }
.vendor small { display: block; font-weight: 400; color: var(--text-faint); font-size: 0.75rem; }

/* Tier badge: the number is the claim, so it is never colour-only — the digit
   and the word both appear. */
.tier { display: inline-flex; align-items: center; gap: var(--s1); font-size: 0.72rem; font-weight: 600;
        border-radius: var(--r-full); padding: 2px var(--s2); border: 1px solid var(--border-n); white-space: nowrap; }
.tier-1 { background: rgba(107, 142, 90, 0.14); color: #3F5B33; }
.tier-2 { background: rgba(27, 42, 74, 0.10); color: var(--navy); }
.tier-3 { background: rgba(201, 169, 97, 0.20); color: #7A6427; }
.tier-4 { background: rgba(184, 72, 61, 0.12); color: #7A2E27; }

.status { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.status-posted { color: var(--success); }
.status-queued { color: #7A6427; }
.status-failed { color: var(--error); }
.status-new { color: var(--text-muted); }

/* Confidence: a bar plus the number. The bar alone would be colour-only. */
.conf { display: flex; align-items: center; gap: var(--s2); }
.conf-track { width: 52px; height: 5px; background: var(--navy-xl); border-radius: var(--r-full); overflow: hidden; }
.conf-fill { height: 100%; background: var(--navy); border-radius: var(--r-full); }
.conf-n { font-variant-numeric: tabular-nums; font-size: 0.78rem; color: var(--text-muted); }

/* --- exception cards ---------------------------------------------------- */
.ex-grid { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.ex {
  background: #fff; border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); padding: var(--s5);
  transition: transform 200ms var(--ease), box-shadow 200ms var(--ease);
}
.ex:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.ex .q { font-family: var(--font-display); font-size: 1.1rem; line-height: 1.4; letter-spacing: -0.01em; margin: 0 0 var(--s2); }
.ex .meta { font-size: 0.78rem; color: var(--text-muted); margin: 0 0 var(--s4); }
.ex-choices { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s3); }
.chip {
  appearance: none; cursor: pointer; font: inherit; font-size: 0.82rem; font-weight: 500;
  background: var(--bg-warm); color: var(--navy); border: 1px solid var(--border-n);
  border-radius: var(--r-full); padding: var(--s2) var(--s4);
  transition: transform 160ms var(--ease), box-shadow 160ms var(--ease);
}
.chip:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.chip:active { transform: translateY(0); }
.chip:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.ex-free { display: flex; gap: var(--s2); }
.ex-free input {
  flex: 1; min-width: 0; font: inherit; font-size: 0.85rem; color: var(--text);
  background: var(--bg); border: 1px solid var(--border-n); border-radius: var(--r-full);
  padding: var(--s2) var(--s4);
}
.ex-free input:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* Receipt thumbnail. No border, no box-shadow on the image itself — the frame
   is the card. A gradient scrim plus a multiply wash ties it to the palette. */
.thumb { position: relative; border-radius: var(--r); overflow: hidden; margin-bottom: var(--s4); aspect-ratio: 16 / 9; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(15, 27, 48, 0.55), transparent 62%), var(--cream);
  mix-blend-mode: multiply; pointer-events: none;
}

/* --- rules -------------------------------------------------------------- */
.rule-list { list-style: none; margin: 0; padding: 0; }
.rule-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--border); }
.rule-list .pattern { font-weight: 600; }
.rule-list .arrow { color: var(--text-faint); }
.prov { margin-left: auto; font-size: 0.72rem; color: var(--text-muted); background: var(--navy-xxl); border-radius: var(--r-full); padding: 2px var(--s3); white-space: nowrap; }
.prov.learned { background: rgba(201, 169, 97, 0.20); color: #7A6427; }

/* --- chart -------------------------------------------------------------- */
.chart-wrap { position: relative; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--text-faint); font-size: 11px; font-family: var(--font-body); }
.chart .series-line { fill: none; stroke: var(--navy); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart .series-area { fill: url(#tallyArea); }
/* Gold reads at 2.19:1 on this surface — under the 3:1 floor — so it never
   carries meaning on its own. It marks the two endpoints that also get a
   direct label, which is the required relief. */
.chart .cap { fill: var(--gold); stroke: #fff; stroke-width: 2; }
.chart .cap-label { fill: var(--text); font-size: 12px; font-weight: 600; font-family: var(--font-body); }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .crosshair { stroke: var(--navy); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; transition: opacity 120ms var(--ease); }
.chart-wrap.is-hover .crosshair { opacity: 0.45; }
.tip {
  position: absolute; pointer-events: none; opacity: 0;
  transform: translate(-50%, -118%); transition: opacity 120ms var(--ease);
  background: var(--navy-d); color: var(--bg); font-size: 0.76rem; line-height: 1.5;
  border-radius: var(--r-sm); padding: var(--s2) var(--s3); box-shadow: var(--shadow-lg); white-space: nowrap;
}
.chart-wrap.is-hover .tip { opacity: 1; }

.table-toggle {
  appearance: none; background: none; border: 0; cursor: pointer; font: inherit;
  font-size: 0.78rem; color: var(--text-muted); text-decoration: underline;
  text-underline-offset: 3px; padding: var(--s2) 0; margin-top: var(--s3);
  transition: color 140ms var(--ease);
}
.table-toggle:hover { color: var(--text); }
.table-toggle:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

/* --- empty / feedback --------------------------------------------------- */
.empty { color: var(--text-muted); font-size: 0.9rem; padding: var(--s6) 0; text-align: center; }
.toast {
  position: fixed; left: 50%; bottom: var(--s5); transform: translateX(-50%) translateY(12px);
  background: var(--navy-d); color: var(--bg); font-size: 0.85rem;
  border-radius: var(--r-full); padding: var(--s3) var(--s5); box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; z-index: 40;
  transition: opacity 220ms var(--ease), transform 220ms var(--ease);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--error); }

@media (max-width: 640px) {
  .shell { padding: 0 var(--s4) var(--s7); }
  .wordmark { font-size: 1.7rem; }
  .card { padding: var(--s4); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}

/* --- replay badge -------------------------------------------------------
   Deliberately loud. A recorded run shown as a live one is the single most
   damaging thing this dashboard could do in front of a prospect, so the label
   is persistent, high-contrast, and sits in the masthead rather than in the
   panel a viewer might have scrolled past. */
.replay-badge {
  margin-left: auto; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: #fff; background: var(--error);
  border-radius: var(--r-full); padding: var(--s1) var(--s3); white-space: nowrap;
}
.replay-badge + .build-chip { margin-left: var(--s2); }
