/* Figure Admin: dark-first theme matching the app, with a light variant.
   Served under CSP style-src 'self': every visual is a class here; app.js
   never sets inline styles (chart geometry uses SVG attributes). */

:root {
  color-scheme: dark;
  --bg: #061124;
  --surface: #0D1B33;
  --surface-2: #13233F;
  --border: #1F3354;
  --text: #E8F1FF;
  --muted: #8FA3C0;
  --accent: #3FE0E8;
  --purple: #9B6BFF;
  --success: #3DDC97;
  --warning: #FFB547;
  --danger: #FF5C7A;
  --on-accent: #04121F;
  --accent-soft: rgba(63, 224, 232, 0.13);
  --purple-soft: rgba(155, 107, 255, 0.15);
  --success-soft: rgba(61, 220, 151, 0.14);
  --warning-soft: rgba(255, 181, 71, 0.14);
  --danger-soft: rgba(255, 92, 122, 0.14);
  --muted-soft: rgba(143, 163, 192, 0.13);
  --grid: rgba(143, 163, 192, 0.16);
  --tip-shadow: rgba(0, 0, 0, 0.35);

  /* Chart series */
  --c-signups: #3FE0E8;
  --c-knocks: #9B6BFF;
  --c-accepted: #3DDC97;
  --c-chats: #FFB547;
  --c-messages: #5B9DFF;
  --c-questions: #FF8AD8;
  --c-reports: #FF5C7A;

  --radius: 16px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #F3F6FB;
    --surface: #FFFFFF;
    --surface-2: #EEF2F9;
    --border: #D5DEEB;
    --text: #0B1A33;
    --muted: #536480;
    --accent: #087F88;
    --purple: #6A3FD9;
    --success: #11804F;
    --warning: #9A5A00;
    --danger: #CF2848;
    --on-accent: #FFFFFF;
    --accent-soft: rgba(8, 127, 136, 0.1);
    --purple-soft: rgba(106, 63, 217, 0.1);
    --success-soft: rgba(17, 128, 79, 0.1);
    --warning-soft: rgba(154, 90, 0, 0.1);
    --danger-soft: rgba(207, 40, 72, 0.09);
    --muted-soft: rgba(83, 100, 128, 0.1);
    --grid: rgba(83, 100, 128, 0.16);
    --tip-shadow: rgba(11, 26, 51, 0.12);

    --c-signups: #0A929C;
    --c-knocks: #6A3FD9;
    --c-accepted: #11804F;
    --c-chats: #B86A00;
    --c-messages: #2F6BDB;
    --c-questions: #C2369A;
    --c-reports: #CF2848;
  }
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
a { color: var(--accent); }
code { font-family: var(--mono); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h2:focus { outline: none; }
main:focus { outline: none; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { left: 16px; }

.num, .tile-value, .stat dd, .kv dd, td, .funnel-val, .legend-total, .rate-value, .count {
  font-variant-numeric: tabular-nums;
}

/* ---------- Header ---------- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
.brand h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.brand-mark { width: 28px; height: 28px; flex: none; }
.brand-mark .ring { fill: none; stroke: var(--accent); stroke-width: 1.5; opacity: 0.75; }
.brand-mark .blip { fill: var(--purple); }

.topbar-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; flex-basis: 100%; }
.updated { margin-right: auto; color: var(--muted); font-size: 13px; }
.updated.is-stale { color: var(--warning); }

@media (min-width: 720px) {
  .topbar { position: sticky; top: 0; z-index: 20; }
  .topbar-inner { padding: 14px 24px; }
  .topbar-actions { flex-basis: auto; }
  .updated { margin-right: 4px; }
}

/* Health pill */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.pill-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill--ok { color: var(--success); background: var(--success-soft); border-color: transparent; }
.pill--down { color: var(--danger); background: var(--danger-soft); border-color: transparent; }

/* ---------- Buttons & controls ---------- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; min-height: 44px; }
.btn-ghost { background: transparent; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { border-color: transparent; filter: brightness(1.08); }
.btn-ok { color: var(--success); }
.btn-danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn-danger:hover:not(:disabled) { border-color: var(--danger); }
.caret { font-size: 11px; }

.icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.is-busy .icon { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Segmented toggle groups (range, report status) */
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  max-width: 100%;
}
.seg button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.seg button:hover { color: var(--text); }
@media (max-width: 480px) {
  .seg { display: flex; width: 100%; }
  .seg button { flex: 1 1 auto; justify-content: center; padding: 5px 8px; }
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); }

.count {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #FFFFFF;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
}
.count:empty { display: none; }

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--muted-soft);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 20px;
  white-space: nowrap;
}
.chip--ok { background: var(--success-soft); color: var(--success); }
.chip--warn { background: var(--warning-soft); color: var(--warning); }
.chip--danger { background: var(--danger-soft); color: var(--danger); }
.chip--accent { background: var(--accent-soft); color: var(--accent); }
.chip--purple { background: var(--purple-soft); color: var(--purple); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Layout ---------- */

.page {
  flex: 1;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px;
}

.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }

@media (min-width: 720px) {
  .page { padding: 24px; }
}

@media (min-width: 1100px) {
  .grid { grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 20px; }
  .span-12 { grid-column: span 12; }
  .span-8 { grid-column: span 8; }
  .span-4 { grid-column: span 4; }
}

.card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.section-bare { min-width: 0; }

@media (min-width: 720px) {
  .card { padding: 20px; }
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 14px;
}
.card-head h2 { font-size: 17px; font-weight: 700; }
.card-sub { margin-top: 2px; color: var(--muted); font-size: 13px; }

.group-title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
* + .group-title { margin-top: 18px; }

/* Section states */
.msg {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--text);
  font-size: 14px;
}
.placeholder { padding: 16px 0; color: var(--muted); font-size: 14px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }
.empty {
  padding: 20px 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}
.note { margin-top: 10px; color: var(--muted); font-size: 13px; }
.note--warn {
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  color: var(--text);
}
.is-stale { opacity: 0.55; transition: opacity 0.2s; }

/* Status / announcements */
.status-wrap { width: 100%; max-width: 1440px; margin: 0 auto; padding: 0 16px; }
.status {
  margin-top: 12px;
  padding: 10px 14px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: 14px;
}
.status--error { border-color: var(--danger); background: var(--danger-soft); }
@media (min-width: 720px) { .status-wrap { padding: 0 24px; } }

/* ---------- Sign in ---------- */

.signin { max-width: 420px; margin: 8vh auto 0; }
.signin h2 { font-size: 20px; }
.field { display: grid; gap: 6px; margin: 18px 0 12px; }
label { font-size: 14px; font-weight: 600; }
input[type="password"] {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
input[type="password"]:focus-visible { border-color: var(--accent); }
.form-error { margin-bottom: 12px; color: var(--danger); font-size: 14px; font-weight: 600; }
.form-error:empty { display: none; }

/* ---------- Overview tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}
@media (min-width: 720px) {
  .tiles { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}
.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.tile-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.tile-value { margin: 2px 0; font-size: 28px; font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; }
.tile-sub { color: var(--muted); font-size: 12.5px; }
.tile-link { margin-top: 4px; font-size: 13px; font-weight: 600; }
.tile--accent .tile-value { color: var(--accent); }
.tile--alert { border-color: var(--warning); background: linear-gradient(var(--warning-soft), var(--warning-soft)), var(--surface); }
.tile--alert .tile-value { color: var(--warning); }

/* ---------- Last 24 h ---------- */

.rate { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; margin-bottom: 12px; }
.rate-value { color: var(--success); font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.rate-label { color: var(--muted); font-size: 13px; }

.funnel { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.funnel-row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}
.funnel-label { color: var(--muted); }
.funnel-val { min-width: 64px; text-align: right; font-weight: 600; }
.funnel-pct { margin-left: 6px; color: var(--muted); font-size: 12px; font-weight: 500; }
.bar { display: block; width: 100%; height: 8px; }
.bar-track { fill: var(--muted-soft); }
.bar-fill { fill: var(--accent); }
.bar-fill--accepted { fill: var(--success); }
.bar-fill--declined { fill: var(--danger); }
.bar-fill--expired { fill: var(--warning); }
.bar-fill--cancelled { fill: var(--muted); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin: 0;
}
.stat { min-width: 0; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.stat dt { color: var(--muted); font-size: 12.5px; }
.stat dd { margin: 0; font-size: 20px; font-weight: 700; }

/* ---------- Activity chart ---------- */

.legend { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.legend-item[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }
.legend-item .sw { width: 10px; height: 10px; border-radius: 50%; box-shadow: inset 0 0 0 2px var(--sc); }
.legend-item[aria-pressed="true"] .sw { background: var(--sc); }
.legend-total { color: var(--muted); font-size: 12px; }

.chart-wrap { position: relative; min-width: 0; min-height: 220px; }
.chart { display: block; width: 100%; touch-action: pan-y; }
.chart text { font-family: var(--font); }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--border); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .series-line { fill: none; stroke: var(--sc); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-dot { fill: var(--sc); }
.chart .hover-dot { fill: var(--sc); stroke: var(--surface); stroke-width: 2; }
.chart .guide { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .chart-empty { fill: var(--muted); font-size: 13px; }
.chart .guide, .chart .hover-layer, .chart .tip { pointer-events: none; }
.chart .off { display: none; }
.tip-shadow { fill: var(--tip-shadow); }
.tip-box { fill: var(--surface-2); stroke: var(--border); }
.tip-title { fill: var(--text); font-size: 12px; font-weight: 700; }
.tip-label { fill: var(--muted); font-size: 12px; }
.tip-value { fill: var(--text); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tip-dot { fill: var(--sc); }

.s-signups { --sc: var(--c-signups); }
.s-knocks { --sc: var(--c-knocks); }
.s-accepted { --sc: var(--c-accepted); }
.s-chats { --sc: var(--c-chats); }
.s-messages { --sc: var(--c-messages); }
.s-questions { --sc: var(--c-questions); }
.s-reports { --sc: var(--c-reports); }

/* ---------- System ---------- */

.sys-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 12px;
}
.sys-block { min-width: 0; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.sys-block--wide { margin-top: 12px; }
.sys-block h3 {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; margin: 0; font-size: 14px; }
.kv dt { min-width: 0; color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; }
.kv-pct { margin-left: 6px; color: var(--muted); font-size: 12px; font-weight: 500; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
table { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
tbody tr:last-child td { border-bottom: 0; }
tfoot td { border-top: 1px solid var(--border); border-bottom: 0; font-weight: 700; }
td.zero { color: var(--muted); }
td.bad { color: var(--danger); font-weight: 700; }

/* ---------- Reports & questions ---------- */

.list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.item {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}
.item--flagged { border-color: var(--danger); }
.item-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.item-time { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }

.quote {
  margin: 10px 0 0;
  padding: 8px 12px;
  border-left: 3px solid var(--purple);
  border-radius: 0 8px 8px 0;
  background: var(--purple-soft);
}
.quote figcaption { color: var(--muted); font-size: 12px; font-weight: 600; }
.quote blockquote, .q-text { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.q-text { font-size: 15px; }

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}
.meta-hot { color: var(--danger); font-weight: 700; }
.ref {
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.suspend-opts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  border: 1px dashed var(--danger);
  border-radius: var(--radius-sm);
}
.suspend-label { margin-right: 2px; color: var(--muted); font-size: 13px; font-weight: 600; }

/* ---------- Footer ---------- */

.footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
