/* Brevo Link Engine — dashboard design system.
 * Tokens sourced from config/campaign.json .brand (primary #0B996E) plus the fixed
 * palette below. Every color is a variable — light on :root, dark under
 * prefers-color-scheme. 8px spacing grid (paddings/margins/gaps are multiples of 4),
 * except table cell padding which the spec pins to 10px/12px explicitly.
 * Dense tables, not cards: the user scans hundreds of rows a day and the load-bearing
 * view is #approve.
 */

:root {
  /* brand */
  --brevo-green: #0B996E;
  --brevo-green-dark: #087A58;
  --brevo-green-light: #E6F5F0;
  --ink: #1F2937;
  --ink-muted: #6B7280;
  --line: #E5E7EB;
  --surface: #FFFFFF;
  --canvas: #F8FAFC;
  --amber: #F5A623;
  --red: #DC2626;
  --blue: #2563EB;

  /* derived surfaces */
  --surface-hover: #F1F5F9;
  --red-bg: #FEF2F2;
  --amber-bg: #FFFBEB;
  --green-bg: #ECFDF5;
  --blue-bg: #EFF6FF;
  --mut-bg: #F1F5F9;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .08);

  /* type scale — exactly these sizes, nothing in between */
  --fs-12: 12px;
  --fs-13: 13px;
  --fs-14: 14px;
  --fs-16: 16px;
  --fs-20: 20px;
  --fs-26: 26px;

  /* 8px grid (values are multiples of 4) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 28px;
  --sp-8: 32px;

  --sidebar-w: 220px;
  --sidebar-w-collapsed: 64px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #E5E7EB;
    --ink-muted: #94A3B8;
    --line: #263043;
    --surface: #131B2C;
    --canvas: #0B1220;
    --brevo-green-light: #0F2A20;
    --surface-hover: #1B2740;
    --red-bg: #3F1D1D;
    --amber-bg: #332608;
    --green-bg: #0F2A20;
    --blue-bg: #16233D;
    --mut-bg: #1B2740;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Arial, sans-serif;
  font-size: var(--fs-13);
  font-weight: 400;
  line-height: 1.5;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brevo-green); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-weight: 600; margin: 0; }

.num, td.num, .stat-tile .n, td[data-num] {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ── app shell: sidebar + content ─────────────────────────────────────────── */

#app { display: flex; min-height: 100vh; }

#sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
  display: flex; flex-direction: column;
  background: var(--canvas); border-right: 1px solid var(--line);
  z-index: 20;
}

.brand-lockup {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-5) var(--sp-4);
  font-size: var(--fs-14); font-weight: 600; letter-spacing: -.1px;
  white-space: nowrap; overflow: hidden;
}
.brand-mark {
  flex: none; width: 20px; height: 20px; border-radius: 6px;
  background: var(--brevo-green);
  box-shadow: 0 0 0 1px rgba(11,153,110,.25);
}
.brand-name { overflow: hidden; text-overflow: ellipsis; }

nav#nav { display: flex; flex-direction: column; gap: var(--sp-1); padding: var(--sp-2); flex: 1; overflow-y: auto; }

.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-left: 3px solid transparent;
  border-radius: 0 8px 8px 0;
  color: var(--ink-muted);
  text-decoration: none;
  font-size: var(--fs-13); font-weight: 500;
  white-space: nowrap;
  position: relative;
}
.nav-item:hover { color: var(--ink); background: var(--surface-hover); }
.nav-item.active {
  color: var(--brevo-green-dark);
  background: var(--brevo-green-light);
  border-left-color: var(--brevo-green);
  font-weight: 600;
}
.nav-icon { flex: none; width: 16px; height: 16px; display: flex; }
.nav-icon svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-badge {
  flex: none; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--amber); color: #1F2937; font-size: 10.5px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.nav-item.active .nav-badge { background: var(--brevo-green); color: #fff; }
.nav-item[hidden] { display: none; }

/* icon-only collapse under 1100px */
@media (max-width: 1100px) {
  #sidebar { width: var(--sidebar-w-collapsed); }
  .brand-name { display: none; }
  .brand-lockup { justify-content: center; padding: var(--sp-5) var(--sp-2); }
  .nav-label { display: none; }
  .nav-item { justify-content: center; padding: var(--sp-3); border-radius: 8px; border-left: none; }
  .nav-item.active { border-left: none; box-shadow: inset 3px 0 0 var(--brevo-green); }
  .nav-badge { position: absolute; top: 2px; right: 2px; min-width: 14px; height: 14px; font-size: 9px; padding: 0 3px; }
  #content { margin-left: var(--sidebar-w-collapsed) !important; }
}

/* top-bar collapse under 720px */
@media (max-width: 720px) {
  #app { flex-direction: column; }
  #sidebar {
    position: static; width: 100%; height: auto; flex-direction: row;
    border-right: none; border-bottom: 1px solid var(--line);
  }
  .brand-lockup { display: none; }
  nav#nav { flex-direction: row; overflow-x: auto; overflow-y: visible; padding: var(--sp-1) var(--sp-2); }
  .nav-item { flex-direction: column; gap: 2px; padding: var(--sp-2); min-width: 56px; }
  .nav-item.active { box-shadow: inset 0 -3px 0 var(--brevo-green); }
  .nav-label { display: block; font-size: 9.5px; }
  #content { margin-left: 0 !important; }
}

#content { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

#topbar {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: 0 var(--sp-6); height: 48px; flex: none;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
#health { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-12); color: var(--ink-muted); white-space: nowrap; }
#health-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-muted); flex: none; }
#health-dot.ok { background: var(--brevo-green); }
#health-dot.bad { background: var(--red); }
#topbar .spacer { flex: 1; }
#token-form { display: flex; align-items: center; gap: var(--sp-2); }
#token-form input {
  width: 180px; padding: 5px var(--sp-2); border-radius: 6px; border: 1px solid var(--line);
  background: var(--canvas); color: var(--ink); font-size: var(--fs-12);
}
#token-form button {
  padding: 5px var(--sp-3); border-radius: 6px; border: 1px solid var(--brevo-green);
  background: var(--brevo-green); color: #fff; font-weight: 600; font-size: var(--fs-12); cursor: pointer;
}

main#view { flex: 1; overflow: auto; padding: var(--sp-6); }
.view-inner { max-width: 1400px; margin: 0 auto; }

/* ── view head ────────────────────────────────────────────────────────────── */

.view-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.view-head h1 { font-size: var(--fs-20); letter-spacing: -.2px; }
.view-head .hint { font-size: var(--fs-12); color: var(--ink-muted); }
.view-actions { display: flex; gap: var(--sp-2); }

/* ── stat tiles ───────────────────────────────────────────────────────────── */

.stat-row { display: flex; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-5); }
.stat-tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: var(--sp-3) var(--sp-4); min-width: 128px; min-height: 64px; box-shadow: var(--shadow);
}
.stat-tile .n { font-size: var(--fs-26); font-weight: 600; letter-spacing: -.5px; line-height: 1.2; }
.stat-tile .l { font-size: 11px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .4px; margin-top: var(--sp-1); }
.stat-tile.accent .n { color: var(--amber); }
.stat-tile.primary .n { color: var(--brevo-green); }
.stat-tile.danger .n { color: var(--red); }
.stat-tile.info .n { color: var(--blue); }

/* ── filter bar ───────────────────────────────────────────────────────────── */

.filterbar {
  display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: flex-end;
  padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-4);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.filterbar .field { display: flex; flex-direction: column; gap: var(--sp-1); font-size: 11px; color: var(--ink-muted); }
.filterbar .field.checkbox-field { flex-direction: row; align-items: center; gap: var(--sp-2); }
.filterbar input[type="text"],
.filterbar input[type="number"],
.filterbar input[type="search"],
.filterbar select {
  padding: 5px var(--sp-2); border: 1px solid var(--line); border-radius: 6px;
  background: var(--canvas); color: var(--ink); font-size: var(--fs-12); min-height: 28px;
}
.filterbar input[type="range"] { width: 120px; accent-color: var(--brevo-green); }
.filterbar input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--brevo-green); }
.filterbar .range-pair { display: flex; align-items: center; gap: var(--sp-1); }
.filterbar .range-pair input { width: 72px; }
.filterbar .slider-value { font-size: 10.5px; color: var(--ink-muted); text-align: right; }
.filterbar .disabled-note { font-size: 10.5px; color: var(--ink-muted); max-width: 160px; }
.filterbar [disabled] { opacity: .5; cursor: not-allowed; }

.btn {
  padding: 6px var(--sp-3); border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
  cursor: pointer; font-size: var(--fs-12); font-weight: 600; color: var(--ink); white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); }
.btn.primary { background: var(--brevo-green); color: #fff; border-color: var(--brevo-green); }
.btn.primary:hover { background: var(--brevo-green-dark); }
.btn.danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { background: transparent; }

.filter-meta { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px var(--sp-2); border-radius: 999px;
  background: var(--mut-bg); color: var(--ink-muted); font-size: 11px; font-weight: 600;
}
.chip.on { background: var(--brevo-green-light); color: var(--brevo-green-dark); }
.row-count { font-size: var(--fs-12); color: var(--ink-muted); font-variant-numeric: tabular-nums; }

/* ── tables ───────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
table.grid { width: 100%; border-collapse: collapse; min-width: 640px; }
table.grid th, table.grid td {
  padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap;
}
table.grid th {
  background: var(--canvas); font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--ink-muted); font-weight: 500; position: sticky; top: 0; z-index: 1;
}
table.grid th.num, table.grid td.num { text-align: right; }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover { background: var(--surface-hover); }
table.grid tbody tr.clickable { cursor: pointer; }
table.grid tbody tr.selected { box-shadow: inset 3px 0 0 var(--brevo-green); background: var(--brevo-green-light); }
table.grid tbody tr.selected td:first-child { font-weight: 600; }
table.grid td.wrap { white-space: normal; max-width: 380px; }
table.grid tfoot td { font-weight: 600; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--ink); }
th[data-sort].active { color: var(--brevo-green-dark); }

/* ── status pill (one mapping, used everywhere) ──────────────────────────── */

.pill { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 20px; letter-spacing: .3px; text-transform: uppercase; white-space: nowrap; }
.pill-ok   { background: var(--green-bg); color: #166534; }
.pill-warn { background: var(--amber-bg); color: #92400E; }
.pill-bad  { background: var(--red-bg); color: #991B1B; }
.pill-info { background: var(--blue-bg); color: #1E40AF; }
.pill-mut  { background: var(--mut-bg); color: var(--ink-muted); }

/* ── three explicit states ───────────────────────────────────────────────── */

.skeleton-row { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.skeleton-line {
  height: 14px; margin: 14px 16px; border-radius: 4px;
  background: linear-gradient(90deg, var(--mut-bg) 25%, var(--surface-hover) 37%, var(--mut-bg) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .skeleton-line { animation: none; opacity: .6; } }

.empty-state, .error-state {
  padding: var(--sp-7) var(--sp-5); text-align: center; border-radius: 8px;
  background: var(--surface); min-height: 120px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-3);
}
.empty-state { border: 1px dashed var(--line); color: var(--ink-muted); }
.empty-state p { margin: 0; font-size: var(--fs-13); max-width: 520px; }
.error-state { border: 1px solid var(--red); background: var(--red-bg); color: #991B1B; }
.error-state p { margin: 0; font-size: var(--fs-13); }

.error-banner {
  background: var(--red-bg); color: #991B1B; border: 1px solid var(--red); border-radius: 6px;
  padding: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-3); font-size: var(--fs-12);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
}

/* ── approve view ─────────────────────────────────────────────────────────── */

#approve-wrap { display: flex; flex-direction: column; gap: var(--sp-4); }
.approve-status { display: flex; gap: var(--sp-3); align-items: center; font-size: var(--fs-12); color: var(--ink-muted); flex-wrap: wrap; }
.approve-status strong { color: var(--ink); }

.approve-queue-wrap { max-height: 220px; overflow: auto; }
.approve-queue-wrap table.grid { min-width: 480px; }

.approve-split { display: grid; grid-template-columns: 1.15fr 1fr; gap: var(--sp-4); min-height: 0; }
@media (max-width: 860px) { .approve-split { grid-template-columns: 1fr; } }

.pane {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: var(--sp-4); overflow: auto; box-shadow: var(--shadow);
}
.pane h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-muted); margin: 0 0 var(--sp-3); font-weight: 500; }

.draft-meta { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-3); align-items: center; }
.draft-subject { font-weight: 600; font-size: var(--fs-14); margin-bottom: var(--sp-2); }
textarea#draft-body {
  width: 100%; min-height: 260px; resize: vertical; border: 1px solid var(--line); border-radius: 8px;
  padding: var(--sp-3); background: var(--canvas); color: var(--ink); font: 13px/1.55 ui-monospace, Menlo, monospace;
}
textarea#draft-body:read-only { background: var(--surface); }
textarea#draft-body.editing { border-color: var(--brevo-green); box-shadow: 0 0 0 2px rgba(11,153,110,.2); }

.evidence-row { display: flex; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-2) 0; border-bottom: 1px solid var(--line); font-size: var(--fs-12); }
.evidence-row:last-child { border-bottom: none; }
.evidence-row .k { color: var(--ink-muted); }
.evidence-row .v { text-align: right; font-weight: 600; word-break: break-word; }
.snippet { background: var(--canvas); border: 1px solid var(--line); border-radius: 8px; padding: var(--sp-3); font-size: var(--fs-12); line-height: 1.6; margin: var(--sp-2) 0 var(--sp-3); }
.snippet mark { background: #FDE68A; color: #1F2937; border-radius: 3px; padding: 0 2px; }

#keyhint {
  flex: none; padding: var(--sp-2) var(--sp-4); border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); font-size: var(--fs-12); color: var(--ink-muted); display: flex; gap: var(--sp-4); flex-wrap: wrap;
}
#keyhint kbd {
  background: var(--canvas); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px;
  padding: 1px 6px; font: 11px ui-monospace, Menlo, monospace; color: var(--ink);
}

/* ── detail expansion rows ────────────────────────────────────────────────── */

tr.detail-row td { background: var(--canvas); padding: 0; }
.detail-inner { padding: var(--sp-4); display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
@media (max-width: 760px) { .detail-inner { grid-template-columns: 1fr; } }

.kv { font-size: var(--fs-12); }
.kv .row { display: flex; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-1) 0; border-bottom: 1px dotted var(--line); }
.kv .row .k { color: var(--ink-muted); }

/* ── policy ───────────────────────────────────────────────────────────────── */

.kill-switch { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4); border-radius: 8px; border: 1px solid var(--line); background: var(--surface); margin-bottom: var(--sp-5); }
.kill-switch.armed { border-color: var(--red); background: var(--red-bg); }
.switch-btn { padding: 7px var(--sp-4); border-radius: 6px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 700; font-size: var(--fs-12); }
.switch-btn.on { background: var(--red); color: #fff; border-color: var(--red); }

.section-title { font-size: var(--fs-14); font-weight: 600; margin: var(--sp-5) 0 var(--sp-3); }

/* focus ring, used consistently (selected table rows, focused controls) */
:focus-visible { outline: 2px solid var(--brevo-green); outline-offset: 2px; }

@media (max-width: 480px) {
  #topbar { gap: var(--sp-2); padding: 0 var(--sp-3); }
  #token-form input { width: 100px; }
  .stat-tile { min-width: 44%; }
  main#view { padding: var(--sp-4); }
}

/* Missing-token state. Deliberately NOT styled as an error: it is a setup step. */
.token-prompt {
  border: 1px solid var(--line);
  border-left: 3px solid var(--brevo-green);
  background: var(--brevo-green-light);
  border-radius: 0 8px 8px 0;
  padding: 20px 24px;
  max-width: 640px;
}
.token-prompt h3 { margin: 0 0 8px; font-size: 16px; font-weight: 600; color: var(--ink); }
.token-prompt p  { margin: 0 0 8px; font-size: 14px; line-height: 1.6; color: var(--ink); }
.token-prompt p.muted { color: var(--ink-muted); margin-bottom: 0; }
.info-banner {
  border: 1px solid var(--line);
  border-left: 3px solid var(--brevo-green);
  background: var(--brevo-green-light);
  padding: 10px 14px; border-radius: 0 6px 6px 0;
  font-size: 13px; color: var(--ink);
}
.brand-mark { flex: 0 0 auto; display: block; }
