/* Veridian Surveys — admin design system (PLATFORM.md §10.2).
 * Tokens match the assistant (static/styles.css). Light first, dark via
 * prefers-color-scheme. Pages use ONLY these tokens + component classes;
 * page-specific CSS goes in a <style> the page module injects once, with
 * selectors prefixed by the page's root class (e.g. .pg-editor ...). */

:root {
  --vrd-navy: #1F2452; --vrd-navy-soft: #2D3677; --vrd-ink: #3A3F5C; --vrd-muted: #5B6285;
  --vrd-orange: #D9531A; --vrd-orange-hover: #B8420F;
  --vrd-wash: #EEF3FC; --vrd-wash-2: #D7E9FF; --vrd-line: #E3EAF6;

  --bg: #F6F8FD; --surface: #FFFFFF; --surface-2: #FAFBFE; --sidebar: #FFFFFF;
  --heading: var(--vrd-navy); --ink: var(--vrd-ink); --muted: var(--vrd-muted); --faint: #8A93B8;
  --line: var(--vrd-line); --line-strong: #D3DCEE; --wash: var(--vrd-wash); --wash-2: var(--vrd-wash-2);
  --accent: var(--vrd-orange); --accent-hover: var(--vrd-orange-hover); --accent-soft: #FCEEE7; --accent-ink: #B8420F;
  --ok: #2F8F64; --ok-soft: #E4F4EC; --warn: #A16207; --warn-soft: #FEF6DC; --bad: #C2410C; --bad-soft: #FDEDE5;
  --info: #2D3677; --info-soft: #E8ECFA;
  --focus: 0 0 0 3px rgba(217, 83, 26, .22);
  --shadow-sm: 0 1px 2px rgba(31, 36, 82, .06); --shadow: 0 8px 24px rgba(31, 36, 82, .08); --shadow-lg: 0 20px 48px rgba(31, 36, 82, .16);
  --radius: 12px; --radius-sm: 8px;
  --font: Montserrat, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --bg-card: #FFFFFF; --text-primary: #3A3F5C; --bar: var(--vrd-navy);   /* chart-editorial handshake */
  --sb-w: 236px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1229; --surface: #181C3B; --surface-2: #1B2044; --sidebar: #12152F;
    --heading: #FFFFFF; --ink: #E6E9F5; --muted: #A9B0D0; --faint: #6E76A0;
    --line: #262B52; --line-strong: #323866; --wash: #1E2347; --wash-2: #283061;
    --accent-soft: rgba(217, 83, 26, .16); --accent-ink: #F2A27A;
    --ok: #5CC792; --ok-soft: rgba(92, 199, 146, .14); --warn: #E7B84B; --warn-soft: rgba(231, 184, 75, .14);
    --bad: #F08A5D; --bad-soft: rgba(240, 138, 93, .14); --info: #AFC0FF; --info-soft: rgba(175, 192, 255, .12);
    --bg-card: #181C3B; --text-primary: #E6E9F5; --bar: #8A93B8;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { color: var(--heading); margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; } h2 { font-size: 17px; font-weight: 700; } h3 { font-size: 15px; font-weight: 600; }
p { margin: 0 0 .75em; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ── shell ─────────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--sb-w) 1fr; min-height: 100vh; }
.sb { background: var(--sidebar); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 18px 12px; gap: 4px; }
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 18px; }
.sb-brand img { height: 28px; }
.sb-brand span { font-weight: 700; color: var(--heading); font-size: 14px; letter-spacing: .01em; }
.sb-link { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--ink); font-weight: 500; }
.sb-link svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.sb-link:hover { background: var(--wash); text-decoration: none; }
.sb-link.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.sb-link.active svg { color: var(--accent); }
.sb-spacer { flex: 1; }
.sb-assist { margin: 8px 0; }
.sb-user { display: flex; align-items: center; gap: 10px; padding: 10px 8px 0; border-top: 1px solid var(--line); margin-top: 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--vrd-navy); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.sb-user .who { min-width: 0; flex: 1; } .sb-user .who b { display: block; color: var(--heading); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-user .who span { display: block; color: var(--muted); font-size: 11.5px; text-transform: capitalize; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.page { padding: 28px 36px 64px; max-width: 1280px; width: 100%; margin: 0 auto; }
.page.wide { max-width: none; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-header p { margin: 4px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* survey sub-header (rendered by the shell on /surveys/:id/*) */
.sv-head { background: var(--surface); border-bottom: 1px solid var(--line); padding: 16px 36px 0; }
.sv-head-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sv-back { color: var(--muted); display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.sv-title { font-size: 18px; font-weight: 700; color: var(--heading); }
.tabs { display: flex; gap: 2px; margin-top: 12px; overflow-x: auto; }
.tab { padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; background: none; border-top: 0; border-left: 0; border-right: 0; font: inherit; cursor: pointer; }
.tab:hover { color: var(--heading); text-decoration: none; }
.tab.active { color: var(--heading); border-bottom-color: var(--accent); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sb { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  body.sb-open .sb { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40; }
  .topbar img { height: 24px; }
  .page { padding: 20px 16px 48px; }
  .sv-head { padding: 12px 16px 0; }
}

/* ── components ────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--heading); font: 600 13.5px var(--font); cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, box-shadow .12s; }
.btn:hover { background: var(--wash); text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.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-navy { background: var(--vrd-navy); border-color: var(--vrd-navy); color: #fff; }
.btn-navy:hover { background: var(--vrd-navy-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink); }
.btn-ghost:hover { background: var(--wash); }
.btn-danger { color: var(--bad); border-color: var(--line-strong); }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn-icon { width: 36px; padding: 0; } .btn-sm.btn-icon { width: 30px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label, .label { font-size: 12.5px; font-weight: 600; color: var(--heading); }
.field .hint { font-size: 12px; color: var(--muted); }
.input, .select, .textarea { width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--ink); font: 14px var(--font); }
.textarea { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input.invalid, .textarea.invalid { border-color: var(--bad); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { appearance: none; width: 36px; height: 20px; border-radius: 20px; background: var(--line-strong); position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: var(--shadow-sm); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-body { padding: 20px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.row { display: flex; align-items: center; gap: 10px; } .row.wrap { flex-wrap: wrap; } .row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; } .table tr.clickable:hover td { background: var(--wash); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: var(--wash); color: var(--vrd-navy-soft); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.plain::before { display: none; }
.badge-draft { background: var(--wash); color: var(--muted); }
.badge-live { background: var(--ok-soft); color: var(--ok); }
.badge-scheduled { background: var(--info-soft); color: var(--info); }
.badge-paused { background: var(--warn-soft); color: var(--warn); }
.badge-closed { background: var(--bad-soft); color: var(--bad); }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 12.5px; color: var(--ink); }

.empty { text-align: center; padding: 56px 24px; color: var(--muted); }
.empty h3 { margin: 12px 0 6px; }
.empty svg { width: 40px; height: 40px; color: var(--faint); }
.skeleton { background: linear-gradient(90deg, var(--wash) 25%, var(--surface-2) 50%, var(--wash) 75%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; min-height: 14px; }
@keyframes sk { to { background-position: -200% 0; } }
.kpi { padding: 18px 20px; }
.kpi .kpi-label { font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.kpi .kpi-value { font-size: 28px; font-weight: 700; color: var(--heading); margin-top: 6px; font-variant-numeric: tabular-nums; }
.divider { height: 1px; background: var(--line); margin: 16px 0; border: 0; }
.menu { position: absolute; z-index: 60; min-width: 180px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 6px; }
.menu button, .menu a { display: flex; width: 100%; align-items: center; gap: 8px; padding: 8px 10px; border: 0; background: none; color: var(--ink); font: 500 13.5px var(--font); border-radius: 7px; cursor: pointer; text-align: left; }
.menu button:hover, .menu a:hover { background: var(--wash); text-decoration: none; }
.menu .danger { color: var(--bad); }

/* modal + toast + drawer (driven by shell.js helpers) */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 18, 41, .45); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .12s; }
.modal { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.modal.lg { width: min(820px, 100%); }
.modal-head { padding: 20px 22px 0; } .modal-head p { color: var(--muted); margin: 6px 0 0; }
.modal-body { padding: 18px 22px; }
.modal-foot { padding: 14px 22px 20px; display: flex; justify-content: flex-end; gap: 8px; }
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--vrd-navy); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 500; animation: rise .18s; }
.toast.bad { background: var(--bad); } .toast.ok { background: var(--ok); }
.assist-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); background: var(--surface); box-shadow: var(--shadow-lg); z-index: 90; transform: translateX(100%); transition: transform .22s ease; border-left: 1px solid var(--line); }
.assist-drawer.open { transform: none; }
.assist-drawer iframe { width: 100%; height: 100%; border: 0; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
