/* MarketingOS design system. Tokens first, then base, components, layout, page-specific. */

:root {
  color-scheme: light;
  /* Surfaces */
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef0f4;
  --border: #e2e5eb;
  --border-strong: #c9ced8;
  /* Ink */
  --text: #131a26;
  --text-2: #475162;
  --text-3: #667083;
  /* Accent: one confident cobalt */
  --accent: #1f5fd1;
  --accent-hover: #184fb1;
  --accent-weak: #e8effc;
  --accent-text: #1a51b8;
  --on-accent: #ffffff;
  /* Status */
  --good: #137a4f; --good-bg: #e3f4ec;
  --warn: #8f5a00; --warn-bg: #fcf1d8;
  --bad: #bf2d2d; --bad-bg: #fce8e8;
  --info: #1d62a8; --info-bg: #e4f0fb;
  --neutral: #4d5769; --neutral-bg: #eceef2;
  --demo: #7a3e00; --demo-bg: #ffdf9e; --demo-border: #e0a43a;
  /* Sidebar: deep ink */
  --side-bg: #0e1a2b;
  --side-border: #1e2c42;
  --side-text: #b4c0d2;
  --side-strong: #ffffff;
  --side-muted: #7686a0;
  --side-hover: rgba(255,255,255,.07);
  --side-active: rgba(91,141,255,.2);
  /* Data palette (validated categorical order) */
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --grid: #e9ebf0;
  /* Type scale */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-11: 11px; --fs-12: 12px; --fs-13: 13px; --fs-14: 14px; --fs-16: 16px; --fs-18: 18px; --fs-22: 22px; --fs-28: 28px;
  /* Spacing */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px;
  /* Radius and elevation */
  --r-sm: 4px; --r: 6px; --r-lg: 10px; --r-full: 999px;
  --e1: 0 1px 2px rgba(16,24,40,.05);
  --e2: 0 4px 12px rgba(16,24,40,.09), 0 1px 3px rgba(16,24,40,.06);
  --e3: 0 16px 40px rgba(16,24,40,.18), 0 4px 10px rgba(16,24,40,.08);
  --focus: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
  --side-w: 236px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0c121c;
    --surface: #141c2a;
    --surface-2: #192335;
    --surface-3: #212d42;
    --border: #273449;
    --border-strong: #3a4a64;
    --text: #edf1f7;
    --text-2: #b1bccc;
    --text-3: #8b98ac;
    --accent: #5b8dff;
    --accent-hover: #7aa3ff;
    --accent-weak: #1c2c4d;
    --accent-text: #8fb2ff;
    --on-accent: #0a1222;
    --good: #4cc792; --good-bg: #123427;
    --warn: #e7b24c; --warn-bg: #3a2a0c;
    --bad: #f27f7f; --bad-bg: #401c1f;
    --info: #71b3f2; --info-bg: #15304b;
    --neutral: #aeb9c9; --neutral-bg: #27324a;
    --demo: #ffdf9e; --demo-bg: #5a3a05; --demo-border: #a06f18;
    --side-bg: #0a111c;
    --side-border: #1b2638;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --grid: #232f43;
    --e1: 0 1px 2px rgba(0,0,0,.4);
    --e2: 0 4px 14px rgba(0,0,0,.45);
    --e3: 0 18px 44px rgba(0,0,0,.6);
  }
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 var(--fs-14)/1.5 var(--font); -webkit-font-smoothing: antialiased; overflow-x: hidden; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: var(--fs-22); font-weight: 650; letter-spacing: -.01em; line-height: 1.25; }
h2 { font-size: var(--fs-16); font-weight: 620; line-height: 1.35; }
h3 { font-size: var(--fs-14); font-weight: 620; }
h4 { font-size: var(--fs-12); font-weight: 620; color: var(--text-2); }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { margin: 0; padding-left: 18px; }
code, pre { font-family: var(--mono); font-size: var(--fs-12); }
pre { white-space: pre-wrap; word-break: break-word; margin: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s4) 0; }
:focus { outline: none; }
:focus-visible { box-shadow: var(--focus); border-radius: var(--r-sm); }
[hidden] { display: none !important; }
svg.ico { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 200; background: var(--surface); padding: 8px 12px; border-radius: var(--r); }
.skip-link:focus { left: 8px; }
.tnum, td.num, th.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.subtle { color: var(--text-2); }
.small { font-size: var(--fs-12); }
.xs { font-size: var(--fs-11); }
.strong { font-weight: 620; }
.mono { font-family: var(--mono); font-size: var(--fs-12); word-break: break-all; }
.nowrap { white-space: nowrap; }
.wrap-any { overflow-wrap: anywhere; }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: var(--s2); }
.row.wrap { flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.stack-lg { display: flex; flex-direction: column; gap: var(--s5); }
.stack-sm { display: flex; flex-direction: column; gap: var(--s1); }
.mt1 { margin-top: var(--s1); } .mt2 { margin-top: var(--s2); } .mt3 { margin-top: var(--s3); } .mt4 { margin-top: var(--s4); }
.mb2 { margin-bottom: var(--s2); } .mb3 { margin-bottom: var(--s3); } .mb4 { margin-bottom: var(--s4); }
.grid { display: grid; gap: var(--s4); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.auto-cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.span2 { grid-column: span 2; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 550 var(--fs-13)/1 var(--font); cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--surface-2); border-color: var(--text-3); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.danger.solid { background: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-3); color: var(--text); }
.btn.sm { height: 26px; padding: 0 8px; font-size: var(--fs-12); }
.btn.lg { height: 40px; padding: 0 18px; font-size: var(--fs-14); }
.btn.block { width: 100%; }
.btn.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-busy::after { content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--text-3); border-top-color: transparent; animation: spin .7s linear infinite; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 0; background: transparent; border-radius: var(--r); color: var(--text-2); cursor: pointer; position: relative; flex: none; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.sm { width: 24px; height: 24px; }
.info-btn { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--border-strong); background: transparent; color: var(--text-3); font: 600 11px/1 var(--font); cursor: pointer; padding: 0; flex: none; }
.info-btn:hover { color: var(--accent-text); border-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Forms */
label.field, .field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span.lbl, .lbl { font-size: var(--fs-12); font-weight: 580; color: var(--text-2); }
.field .hint { font-size: var(--fs-12); color: var(--text-3); }
.req::after { content: " *"; color: var(--bad); }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input[type=url], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; min-height: 34px; padding: 6px 10px; border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface); color: var(--text); font: 400 var(--fs-14)/1.4 var(--font);
}
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
textarea.code, .code { font-family: var(--mono); font-size: var(--fs-12); }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); border-radius: var(--r); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-3); color: var(--text-3); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; flex: none; }
.check { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: var(--fs-13); }
.check.pill { border: 1px solid var(--border); border-radius: var(--r); padding: 6px 10px; align-items: center; background: var(--surface); }
.check.pill:has(input:checked) { border-color: var(--accent); background: var(--accent-weak); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3) var(--s4); }
.form-grid .full { grid-column: 1 / -1; }
.toggle-group { display: flex; flex-wrap: wrap; gap: 6px; }
select.inline, input.inline { width: auto; min-height: 30px; padding: 4px 8px; font-size: var(--fs-13); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--e1); min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-b { padding: var(--s4); }
.card-b.flush { padding: 0; }
.card-f { padding: var(--s3) var(--s4); border-top: 1px solid var(--border); }
.card.clickable { cursor: pointer; transition: border-color .12s, box-shadow .12s; }
.card.clickable:hover { border-color: var(--border-strong); box-shadow: var(--e2); }

/* KPI tiles */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--s3); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s3) var(--s4); display: flex; flex-direction: column; gap: 4px; min-width: 0; box-shadow: var(--e1); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 18px; }
.kpi-label { font-size: var(--fs-12); color: var(--text-2); font-weight: 560; }
.kpi-value { font-size: var(--fs-22); font-weight: 640; letter-spacing: -.01em; line-height: 1.2; }
.kpi-value.nodata { font-size: var(--fs-16); color: var(--text-3); font-weight: 560; }
.kpi-foot { font-size: var(--fs-12); color: var(--text-3); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-height: 18px; }
.delta { font-weight: 620; font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 2px; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); } .delta.flat { color: var(--text-3); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; height: 20px; border-radius: var(--r-full); font-size: var(--fs-11); font-weight: 620; white-space: nowrap; background: var(--neutral-bg); color: var(--neutral); line-height: 1; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.accent { background: var(--accent-weak); color: var(--accent-text); }
.badge.outline { background: transparent; border: 1px solid var(--border-strong); color: var(--text-2); }
.badge.demo { background: var(--demo-bg); color: var(--demo); border: 1px solid var(--demo-border); letter-spacing: .04em; border-radius: var(--r-sm); }
.badge .dot, .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; flex: none; }
.count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-full); background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tag { display: inline-flex; align-items: center; padding: 1px 6px; border-radius: var(--r-sm); background: var(--surface-3); color: var(--text-2); font-size: var(--fs-11); }
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; font-size: var(--fs-13); }
.t th { text-align: left; font-size: var(--fs-12); font-weight: 600; color: var(--text-2); padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
.t td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t th.num, .t td.num { text-align: right; }
.t tr.clickable { cursor: pointer; }
.t tr.clickable:hover td { background: var(--surface-2); }
.t td.ellip { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; margin-bottom: var(--s4); }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 8px 12px; border: 0; background: none; color: var(--text-2); font: 560 var(--fs-13)/1.2 var(--font); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent-text); border-bottom-color: var(--accent); }
.seg { display: inline-flex; background: var(--surface-3); padding: 2px; border-radius: var(--r); gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 4px 10px; border-radius: var(--r-sm); font: 560 var(--fs-12)/1.3 var(--font); color: var(--text-2); cursor: pointer; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--e1); }

/* Empty, error, skeleton */
.empty { padding: var(--s8) var(--s5); text-align: center; color: var(--text-2); display: flex; flex-direction: column; align-items: center; gap: var(--s2); }
.empty .em-ico { width: 40px; height: 40px; border-radius: var(--r-lg); background: var(--surface-3); display: flex; align-items: center; justify-content: center; color: var(--text-3); }
.empty h3 { color: var(--text); }
.empty p { max-width: 460px; font-size: var(--fs-13); }
.skel { background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--r); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } * { transition: none !important; } }
.callout { display: flex; gap: 10px; padding: 10px 12px; border-radius: var(--r); font-size: var(--fs-13); background: var(--info-bg); color: var(--text); align-items: flex-start; }
.callout > svg { color: var(--info); margin-top: 2px; }
.callout.warn { background: var(--warn-bg); } .callout.warn > svg { color: var(--warn); }
.callout.bad { background: var(--bad-bg); } .callout.bad > svg { color: var(--bad); }
.callout.good { background: var(--good-bg); } .callout.good > svg { color: var(--good); }
.kv { display: grid; grid-template-columns: minmax(90px, max-content) minmax(0, 1fr); gap: 4px 16px; font-size: var(--fs-13); }
.kv dt { color: var(--text-3); margin: 0; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
dl { margin: 0; }

/* Overlays */
.overlay { position: fixed; inset: 0; background: rgba(9,14,24,.5); z-index: 100; display: flex; align-items: center; justify-content: center; padding: var(--s4); animation: fade .12s; }
.overlay.right { justify-content: flex-end; padding: 0; align-items: stretch; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--e3); width: min(560px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; }
.modal.lg { width: min(820px, 100%); }
.modal.xl { width: min(1180px, 100%); }
.design-grid { display: grid; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: var(--s4); align-items: start; }
.design-grid iframe { width: 100%; height: min(640px, calc(100dvh - 240px)); border: 1px solid var(--border); border-radius: 8px; background: #fff; position: sticky; top: 0; }
.design-grid input[type=color] { width: 100%; height: 36px; padding: 2px; cursor: pointer; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--border); vertical-align: -1px; margin-right: 3px; }
@media (max-width: 860px) { .design-grid { grid-template-columns: minmax(0, 1fr); } .design-grid iframe { height: 420px; position: static; } }
.modal.sm { width: min(420px, 100%); }
.drawer { background: var(--surface); box-shadow: var(--e3); width: min(520px, 100vw); height: 100dvh; display: flex; flex-direction: column; animation: slide .16s ease-out; }
.drawer.lg { width: min(760px, 100vw); }
@keyframes slide { from { transform: translateX(24px); opacity: .5; } }
.ov-h { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); flex: none; }
.ov-b { padding: var(--s4); overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.ov-f { padding: var(--s3) var(--s4); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--s2); flex: none; flex-wrap: wrap; }
.popover { position: fixed; z-index: 150; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--e2); padding: var(--s3); width: max-content; max-width: min(320px, calc(100vw - 16px)); font-size: var(--fs-13); }
.menu { position: fixed; z-index: 150; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--e2); padding: 4px; min-width: 180px; }
.menu a, .menu button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; font: 500 var(--fs-13)/1.2 var(--font); border: 0; background: none; color: var(--text); border-radius: var(--r-sm); cursor: pointer; text-align: left; }
.menu a:hover, .menu button:hover { background: var(--surface-3); text-decoration: none; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; max-width: min(400px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: var(--r); box-shadow: var(--e2); font-size: var(--fs-13); display: flex; gap: 10px; align-items: flex-start; animation: fade .15s; overflow-wrap: anywhere; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.good { background: var(--good); color: #fff; }
@media (prefers-color-scheme: dark) { .toast.good, .toast.bad { color: #0a1222; } }
.toast button { background: none; border: 0; color: inherit; cursor: pointer; padding: 0; opacity: .8; }

/* App shell */
.boot { padding: 80px; text-align: center; color: var(--text-3); }
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100dvh; }
.side { background: var(--side-bg); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh; z-index: 60; border-right: 1px solid var(--side-border); }
.brand { display: flex; align-items: center; gap: 10px; padding: 14px 16px; color: var(--side-strong); font-weight: 680; font-size: var(--fs-16); letter-spacing: -.01em; flex: none; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.side-nav { flex: 1 1 auto; overflow-y: auto; padding: 4px 8px 12px; scrollbar-width: thin; scrollbar-color: var(--side-border) transparent; }
.nav-group { margin-top: 12px; }
.nav-label { font-size: 11px; font-weight: 620; color: var(--side-muted); padding: 4px 8px; letter-spacing: .02em; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--r); color: var(--side-text); font-size: var(--fs-13); font-weight: 500; }
.nav-item:hover { background: var(--side-hover); color: var(--side-strong); text-decoration: none; }
.nav-item.active { background: var(--side-active); color: var(--side-strong); }
.nav-item svg.ico { opacity: .85; }
.nav-item .count { margin-left: auto; background: #5b8dff; color: #0a1222; }
.nav-item:focus-visible { box-shadow: 0 0 0 2px #5b8dff; }
.side-foot { padding: 8px; border-top: 1px solid var(--side-border); flex: none; }
.mainwrap { display: flex; flex-direction: column; min-width: 0; min-height: 100dvh; }
.topbar { display: flex; align-items: center; gap: var(--s3); height: 54px; padding: 0 var(--s5); background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.switcher { display: flex; align-items: center; gap: 6px; min-width: 0; }
.switcher select { max-width: 240px; font-weight: 580; font-size: var(--fs-13); }
.search-box { position: relative; flex: 1 1 280px; max-width: 420px; min-width: 0; }
.search-box input { padding-left: 32px; background: var(--surface-2); }
.search-box > svg { position: absolute; left: 10px; top: 9px; color: var(--text-3); }
.search-results { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--e2); max-height: 380px; overflow-y: auto; z-index: 70; padding: 4px; }
.search-results a { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: var(--r-sm); color: var(--text); font-size: var(--fs-13); }
.search-results a:hover, .search-results a:focus-visible { background: var(--surface-3); text-decoration: none; }
.top-actions { display: flex; align-items: center; gap: 2px; margin-left: auto; flex: none; }
.notif-dot { position: absolute; top: 3px; right: 3px; min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px; background: var(--bad); color: #fff; font-size: 10px; font-weight: 700; line-height: 15px; text-align: center; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-weak); color: var(--accent-text); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
#demo-banner { position: sticky; top: 54px; z-index: 45; }
.demo-banner { background: var(--demo-bg); color: var(--demo); border-bottom: 1px solid var(--demo-border); padding: 7px var(--s5); font-size: var(--fs-13); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-weight: 500; }
.demo-short { display: none; }
.demo-banner strong { letter-spacing: .05em; font-weight: 750; }
.demo-banner a { color: inherit; text-decoration: underline; }
.content { padding: var(--s5); flex: 1 1 auto; max-width: 1500px; width: 100%; margin: 0 auto; min-width: 0; }
.page-h { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s4); flex-wrap: wrap; }
.page-title { display: flex; align-items: center; gap: 8px; }
.page-sub { color: var(--text-2); font-size: var(--fs-13); margin-top: 2px; }
.page-actions { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }
.filters { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-bottom: var(--s3); }
.filters > input[type=search], .filters > .grow-input { flex: 1 1 200px; max-width: 320px; }
.filters select, .filters input { width: auto; min-height: 32px; font-size: var(--fs-13); padding: 4px 8px; }
.scrim { position: fixed; inset: 0; background: rgba(9,14,24,.5); z-index: 55; }
.menu-btn { display: none; }
.mobile-search-toggle { display: none; }

/* Auth */
.auth { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-side { background: var(--side-bg); color: var(--side-text); padding: 48px; display: flex; flex-direction: column; justify-content: space-between; gap: 32px; }
.auth-side h2 { color: #fff; font-size: var(--fs-28); line-height: 1.2; letter-spacing: -.02em; font-weight: 650; max-width: 440px; }
.auth-side ul { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 12px; max-width: 420px; font-size: var(--fs-14); }
.auth-side li { display: flex; gap: 10px; }
.auth-side li svg { color: #5b8dff; margin-top: 3px; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 32px 20px; }
.auth-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: var(--s4); }
.auth-brand { display: none; align-items: center; gap: 10px; font-weight: 680; font-size: var(--fs-18); }

/* Wizard */
.wizard { max-width: 820px; margin: 0 auto; }
.steps { display: flex; gap: 4px; margin-bottom: var(--s4); }
.steps .st { flex: 1; height: 4px; border-radius: 2px; background: var(--surface-3); }
.steps .st.done { background: var(--accent); }

/* Charts */
.chart { margin: 0; position: relative; min-width: 0; }
.chart:focus-visible { box-shadow: var(--focus); border-radius: var(--r-sm); }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font: 400 11px var(--font); fill: var(--text-3); font-variant-numeric: tabular-nums; }
.chart text.val { fill: var(--text); font-weight: 600; }
.chart text.lab { fill: var(--text-2); }
.chart .g-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .xh { stroke: var(--text-3); stroke-width: 1; shape-rendering: crispEdges; opacity: 0; pointer-events: none; }
.chart [data-tip] { cursor: default; outline: none; }
.chart [data-tip]:hover .mark, .chart [data-tip]:focus .mark, .chart [data-tip].mark:hover { opacity: .78; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: var(--fs-12); color: var(--text-2); margin-bottom: 8px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chart-legend i.line { height: 2px; width: 14px; border-radius: 1px; }
.chart-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: var(--s6); gap: 4px; color: var(--text-3); font-size: var(--fs-13); border: 1px dashed var(--border); border-radius: var(--r); min-height: 140px; }
.chart-table { margin-top: 6px; font-size: var(--fs-12); }
.chart-table summary { cursor: pointer; color: var(--text-3); }
.chart-table .table-wrap { max-height: 220px; overflow-y: auto; margin-top: 4px; border: 1px solid var(--border); border-radius: var(--r); }
.chart-tip { position: fixed; z-index: 400; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--e2); padding: 8px 10px; font-size: var(--fs-12); pointer-events: none; min-width: 120px; max-width: 280px; }
.chart-tip .tt { color: var(--text-3); margin-bottom: 4px; }
.chart-tip .tr { display: flex; align-items: center; gap: 6px; line-height: 1.6; }
.chart-tip .tr b { font-weight: 650; font-variant-numeric: tabular-nums; color: var(--text); }
.chart-tip .tr span { color: var(--text-2); }
.chart-tip .tr i { width: 12px; height: 2px; border-radius: 1px; display: inline-block; flex: none; }
.meter { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.meter > div { height: 100%; background: var(--accent); border-radius: 3px; }
.meter.warn > div { background: var(--warn); }
.meter.bad > div { background: var(--bad); }
.meter.busy > div { width: 35%; animation: meter-busy 1.1s ease-in-out infinite; }
@keyframes meter-busy { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
@media (prefers-reduced-motion: reduce) { .meter.busy > div { animation: none; width: 100%; opacity: .5; } }
.uploads { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 310; display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 32px)); }
.upload { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--e2); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; animation: fade .15s; }
.upload-top { display: flex; justify-content: space-between; gap: 12px; font-size: var(--fs-13); font-weight: 560; }
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.upload-pct { color: var(--text-2); font-variant-numeric: tabular-nums; }
.upload-step { font-size: var(--fs-12); color: var(--text-2); }

/* Prose (safe markdown output) */
.prose { font-size: var(--fs-14); line-height: 1.6; overflow-wrap: anywhere; }
.prose h1 { font-size: var(--fs-18); margin: 14px 0 6px; }
.prose h2 { font-size: var(--fs-16); margin: 14px 0 6px; }
.prose h3 { font-size: var(--fs-14); margin: 12px 0 4px; }
.prose p { margin: 0 0 10px; }
.prose ul, .prose ol { margin: 0 0 10px; }
.prose li { margin-bottom: 3px; }
.prose code { background: var(--surface-3); padding: 1px 4px; border-radius: 3px; }
.prose pre { background: var(--surface-3); padding: 10px; border-radius: var(--r); margin-bottom: 10px; }
.prose pre code { background: none; padding: 0; }
.prose blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 3px solid var(--border-strong); color: var(--text-2); }

/* Lists / feeds */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: var(--s3); padding: 10px var(--s4); border-bottom: 1px solid var(--border); align-items: flex-start; min-width: 0; }
.list-item:last-child { border-bottom: 0; }
.list-item.clickable { cursor: pointer; }
.list-item.clickable:hover { background: var(--surface-2); }
.list-item.unread { background: var(--accent-weak); }
.timeline { display: flex; flex-direction: column; gap: var(--s3); }
.timeline .ev { display: flex; gap: 10px; font-size: var(--fs-13); }
.timeline .ev::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); margin-top: 6px; flex: none; }
.check-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.check-list li { display: flex; gap: 8px; align-items: flex-start; font-size: var(--fs-13); }
.check-list .ok { color: var(--good); } .check-list .no { color: var(--bad); }

/* Payload preview */
.payload { display: grid; grid-template-columns: minmax(80px, max-content) minmax(0, 1fr); gap: 3px 14px; font-size: var(--fs-13); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 10px 12px; }
.payload dt { color: var(--text-3); }
.payload dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }

/* Chat */
.chat { display: flex; flex-direction: column; gap: var(--s3); }
.bubble { padding: 9px 12px; border-radius: var(--r-lg); max-width: 88%; font-size: var(--fs-13); overflow-wrap: anywhere; }
.bubble.me { align-self: flex-end; background: var(--accent); color: var(--on-accent); }
.bubble.ai, .bubble.staff { align-self: flex-start; background: var(--surface-3); }
.bubble .prose { font-size: var(--fs-13); }
.bubble .prose p:last-child { margin-bottom: 0; }

/* Content studio */
.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--s4); align-items: start; }
.editor-body { min-height: 420px; font-family: var(--mono); font-size: 13px; }
.score-ring { font-size: var(--fs-28); font-weight: 680; font-variant-numeric: tabular-nums; }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; background: var(--border); gap: 1px; }
.cal-dow { background: var(--surface-2); text-align: center; font-size: var(--fs-11); font-weight: 620; color: var(--text-2); padding: 6px 2px; }
.cal-cell { background: var(--surface); min-height: 96px; padding: 4px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-cell.out { background: var(--surface-2); }
.cal-cell.tall { min-height: 300px; }
.cal-date { font-size: var(--fs-11); color: var(--text-3); padding: 1px 3px; font-variant-numeric: tabular-nums; }
.cal-cell.today .cal-date { color: var(--on-accent); background: var(--accent); border-radius: 3px; align-self: flex-start; font-weight: 700; }
.cal-ev { display: block; font-size: var(--fs-11); padding: 2px 5px; background: var(--accent-weak); color: var(--accent-text); border-radius: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev:hover { text-decoration: none; filter: brightness(.97); }
.cal-ev.published { background: var(--good-bg); color: var(--good); }
.cal-ev.in_review { background: var(--warn-bg); color: var(--warn); }

/* Kanban */
.kanban { display: flex; gap: var(--s3); overflow-x: auto; padding-bottom: var(--s3); align-items: flex-start; -webkit-overflow-scrolling: touch; }
.kcol { flex: 0 0 248px; background: var(--surface-3); border-radius: var(--r-lg); display: flex; flex-direction: column; max-height: calc(100dvh - 240px); }
.kcol.drop { outline: 2px solid var(--accent); outline-offset: -2px; }
.kcol-h { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; font-size: var(--fs-13); font-weight: 620; gap: 6px; }
.kcol-b { padding: 0 8px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; min-height: 60px; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 8px 10px; font-size: var(--fs-13); box-shadow: var(--e1); display: flex; flex-direction: column; gap: 4px; user-select: none; -webkit-user-select: none; cursor: grab; }
.kcard.dragging { opacity: .35; }
.kcard.ghost { position: fixed; z-index: 500; pointer-events: none; box-shadow: var(--e3); opacity: .95; width: 232px; }
.kcard .handle { touch-action: none; color: var(--text-3); cursor: grab; display: inline-flex; padding: 4px; margin: -4px; }
.kcard select { font-size: var(--fs-12); min-height: 26px; padding: 2px 6px; }

/* Automation builder */
.builder { display: grid; grid-template-columns: 170px minmax(0, 1fr) 300px; gap: var(--s3); align-items: stretch; }
.palette { display: flex; flex-direction: column; gap: 6px; }
.pal-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); font: 550 var(--fs-13)/1.2 var(--font); color: var(--text); cursor: pointer; text-align: left; }
.pal-item:hover { border-color: var(--accent); }
.canvas-wrap { background-color: var(--surface-2); background-image: radial-gradient(var(--border-strong) 1px, transparent 1px); background-size: 20px 20px; border: 1px solid var(--border); border-radius: var(--r-lg); overflow: auto; height: 520px; position: relative; }
.canvas-wrap svg { display: block; touch-action: none; }
.wf-node rect.bd { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1; }
.wf-node { cursor: grab; }
.wf-node.sel rect.bd { stroke: var(--accent); stroke-width: 2; }
.wf-node text { font: 400 11px var(--font); fill: var(--text-3); pointer-events: none; }
.wf-node text.ttl { font: 600 12.5px var(--font); fill: var(--text); }
.wf-node rect.stripe { pointer-events: none; }
.wf-port { fill: var(--surface); stroke: var(--text-3); stroke-width: 1.5; cursor: crosshair; }
.wf-port:hover, .wf-port.armed { fill: var(--accent); stroke: var(--accent); }
.wf-edge { fill: none; stroke: var(--text-3); stroke-width: 1.5; cursor: pointer; }
.wf-edge.sel { stroke: var(--accent); stroke-width: 2.5; }
.wf-hit { fill: none; stroke: transparent; stroke-width: 14; cursor: pointer; }
.wf-branch { font: 620 10.5px var(--font); }
.wf-readonly .wf-node, .wf-readonly .wf-port { cursor: default; }

/* Misc */
.integ-card { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s4); }
.integ-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s2); }
.plan-card { padding: var(--s4); display: flex; flex-direction: column; gap: var(--s2); }
.plan-card.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.agent-card { padding: var(--s4); display: flex; flex-direction: column; gap: var(--s2); }
.stat-row { display: flex; gap: var(--s4); flex-wrap: wrap; font-size: var(--fs-12); color: var(--text-2); }
.stat-row b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 640; }
.secret-box { background: var(--surface-3); padding: 10px 12px; border-radius: var(--r); font-family: var(--mono); font-size: var(--fs-13); word-break: break-all; }
.dep-node { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: var(--fs-13); flex-wrap: wrap; }

/* Responsive */
@media (max-width: 1180px) {
  .editor-layout { grid-template-columns: minmax(0, 1fr); }
  .builder { grid-template-columns: 150px minmax(0, 1fr); }
  .builder .cfg-panel { grid-column: 1 / -1; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; transform: translateX(-100%); transition: transform .18s ease; }
  .side.open { transform: none; box-shadow: var(--e3); }
  .menu-btn { display: inline-flex; }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-side { display: none; }
  .auth-brand { display: flex; }
  .builder { grid-template-columns: minmax(0, 1fr); }
  .builder .palette { display: none; }
}
@media (max-width: 640px) {
  .content { padding: var(--s3); }
  .topbar { padding: 0 var(--s2); gap: var(--s1); }
  .search-box { display: none; position: absolute; left: 8px; right: 8px; top: 8px; max-width: none; z-index: 80; }
  .search-box.open { display: block; }
  .mobile-search-toggle { display: inline-flex; }
  .switcher select { max-width: 150px; }
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  .span2 { grid-column: auto; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); }
  .kpi { padding: var(--s2) var(--s3); }
  .kpi-value { font-size: var(--fs-18); }
  .auto-cards { grid-template-columns: minmax(0, 1fr); }
  .overlay { padding: var(--s2); }
  .cal-cell { min-height: 58px; }
  .cal-ev { font-size: 10px; padding: 1px 3px; }
  .demo-banner { padding: 5px var(--s3); font-size: var(--fs-12); }
  .demo-more { display: none; }
  .demo-short { display: inline; }
  .filters > input[type=search], .filters > .grow-input { max-width: none; flex-basis: 100%; }
  .page-h { margin-bottom: var(--s3); }
}
@media print { .side, .topbar, .page-actions { display: none !important; } }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.th-sort { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; white-space: nowrap; }
.th-sort:hover { color: var(--accent-text); }
