:root {
  color-scheme: dark;
  /* Sequential blue ramp for the users map: more users = more contrast. */
  --seq-0: #232327;
  --seq-1: #184f95;
  --seq-2: #256abf;
  --seq-3: #3987e5;
  --seq-4: #6da7ec;
  --seq-5: #b7d3f6;
  --bg: #0c0c0d;
  --surface: #141416;
  --surface-2: #1b1b1e;
  --border: #2a2a2e;
  --grid: #26262a;
  --text: #f4f4f5;
  --text-2: #b4b4bb;
  --muted: #7d7d86;
  --accent: #5b7ff0;
  --accent-soft: rgba(91, 127, 240, 0.16);
  --good: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    color-scheme: light;
    --seq-0: #ececea;
    --seq-1: #b7d3f6;
    --seq-2: #86b6ef;
    --seq-3: #3987e5;
    --seq-4: #256abf;
    --seq-5: #104281;
    --bg: #f6f6f5;
    --surface: #ffffff;
    --surface-2: #f1f1ef;
    --border: #e2e2df;
    --grid: #ececea;
    --text: #111113;
    --text-2: #4a4a50;
    --muted: #7a7a80;
    --accent: #4169e1;
    --accent-soft: rgba(65, 105, 225, 0.1);
    --good: #1a7f37;
    --warn: #9a6700;
    --bad: #cf222e;
  }
}
:root[data-theme='light'] {
  color-scheme: light;
  --seq-0: #ececea;
  --seq-1: #b7d3f6;
  --seq-2: #86b6ef;
  --seq-3: #3987e5;
  --seq-4: #256abf;
  --seq-5: #104281;
  --bg: #f6f6f5;
  --surface: #ffffff;
  --surface-2: #f1f1ef;
  --border: #e2e2df;
  --grid: #ececea;
  --text: #111113;
  --text-2: #4a4a50;
  --muted: #7a7a80;
  --accent: #4169e1;
  --accent-soft: rgba(65, 105, 225, 0.1);
  --good: #1a7f37;
  --warn: #9a6700;
  --bad: #cf222e;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
a { color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); min-height: 1em; }
.num { font-variant-numeric: tabular-nums; }

.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand span { color: var(--accent); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; display: grid; gap: 12px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 180px 1fr; grid-template-rows: 56px 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.menu-btn { display: none; background: none; border: 0; color: var(--text); font-size: 20px; cursor: pointer; }
.sidebar { border-right: 1px solid var(--border); padding: 14px 8px; display: flex; flex-direction: column; gap: 2px; background: var(--surface); }
.sidebar a { text-decoration: none; padding: 9px 12px; border-radius: 8px; color: var(--text-2); }
.sidebar a:hover { background: var(--surface-2); color: var(--text); }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.main { padding: 22px 28px 60px; min-width: 0; max-width: 1280px; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .menu-btn { display: block; }
  .sidebar { position: fixed; top: 56px; left: 0; bottom: 0; width: 220px; z-index: 6; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .main { padding: 16px 16px 60px; }
}

/* ---------- page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 20px; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 600; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.page-head .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.section-title { font-size: 12px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-2); margin: 28px 0 4px; }
.section-sub { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

/* ---------- controls ---------- */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { background: none; border: 0; color: var(--text-2); padding: 7px 13px; cursor: pointer; font: inherit; }
.seg button.on { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.btn { text-decoration: none; display: inline-block; background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 7px 13px; border-radius: 8px; cursor: pointer; font: inherit; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.link-btn { background: none; border: 0; color: var(--text-2); cursor: pointer; font: inherit; padding: 0; }
.link-btn:hover { color: var(--text); }
input, select, textarea { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font: inherit; width: 100%; }
textarea { min-height: 90px; resize: vertical; }
label.field { display: grid; gap: 5px; font-size: 12px; color: var(--text-2); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 10px; }
.checks label { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--text); }
.checks input { width: auto; }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .v { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile .k { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-2); margin-top: 2px; }
.delta { font-size: 12px; font-weight: 600; margin-left: 6px; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }

/* ---------- attention ---------- */
.attention { display: grid; gap: 8px; }
.attention a { display: flex; gap: 10px; align-items: center; text-decoration: none; background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--warn); border-radius: 8px; padding: 9px 12px; }
.attention a.overdue { border-left-color: var(--bad); }
.attention a:hover { background: var(--surface-2); }
.attention .icon { font-size: 13px; }

/* ---------- app cards ---------- */
.app-card { display: grid; gap: 12px; align-content: start; }
.app-card h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kv div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.kv b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.kv span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; font-variant-numeric: tabular-nums; }
th { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); font-weight: 600; }
th:first-child, td:first-child { text-align: left; }
td.wrap { white-space: normal; text-align: left; min-width: 220px; }
tr:last-child td { border-bottom: 0; }
td .na { color: var(--muted); font-style: italic; }
.pbadge { display: inline-grid; place-items: center; min-width: 24px; height: 18px; padding: 0 4px; border-radius: 4px; font-size: 10px; font-weight: 700; margin-right: 8px; color: #fff; background: var(--accent); }
.pbadge.threads { background: var(--text); color: var(--bg); }

/* ---------- chart ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.chart .crosshair { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }
.empty { color: var(--muted); padding: 24px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.35); min-width: 140px; }
.tooltip .t-head { color: var(--text-2); margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; }
.tooltip .t-row b { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }

/* ---------- campaigns ---------- */
.stages { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin: 12px 0 16px; }
.stage { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px; text-align: center; cursor: pointer; color: var(--text); font: inherit; }
.stage b { display: block; font-size: 17px; }
.stage span { font-size: 12px; color: var(--text-2); }
.stage.on { border-color: var(--accent); background: var(--accent-soft); }
.cgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.ccard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; text-align: left; color: var(--text); font: inherit; padding: 0; }
.ccard:hover { border-color: var(--text-2); }
.ccard .thumb { aspect-ratio: 16 / 9; background: var(--surface-2) center / cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 28px; }
.ccard .body { padding: 12px 14px 14px; display: grid; gap: 6px; }
.ccard .row { display: flex; gap: 8px; align-items: flex-start; }
.ccard h4 { margin: 0; font-size: 14px; flex: 1; }
.ccard p { margin: 0; color: var(--text-2); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ccard .meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.sbadge { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; color: var(--text-2); }
.sbadge.review { color: var(--warn); border-color: currentColor; }
.sbadge.ready { color: var(--accent); border-color: currentColor; }
.sbadge.scheduled { color: #9085e9; border-color: currentColor; }
.sbadge.posted { color: var(--good); border-color: currentColor; }
.overdue-tag { color: var(--bad); font-weight: 600; }

/* ---------- feed ---------- */
.feed { display: grid; gap: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.feed .item { display: grid; grid-template-columns: 90px 1fr auto; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); align-items: center; }
.feed .item:last-child { border-bottom: 0; }
.feed .kind { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); }
.feed .kind.failure { color: var(--bad); }
.feed .kind.release { color: var(--good); }
.feed a { text-decoration: none; }
.feed a:hover { text-decoration: underline; }
@media (max-width: 600px) { .feed .item { grid-template-columns: 1fr; gap: 2px; } }

/* ---------- settings ---------- */
.list { display: grid; gap: 10px; }
.list .card { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.list .card .grow { flex: 1; min-width: 200px; }
.status-ok { color: var(--good); }
.status-bad { color: var(--bad); }
pre.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; font: 12px/1.5 var(--mono); }

/* ---------- dialog / toast ---------- */
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(560px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog form { padding: 20px; display: grid; gap: 14px; }
dialog h2 { margin: 0; font-size: 18px; }
dialog .foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
dialog .foot .left { margin-right: auto; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 16px; z-index: 60; max-width: calc(100% - 32px); }

/* ---------- users: map + list ---------- */
.map-wrap { display: grid; grid-template-columns: minmax(0, 2fr) minmax(220px, 1fr); gap: 12px; }
@media (max-width: 900px) { .map-wrap { grid-template-columns: 1fr; } }
.map svg { display: block; width: 100%; height: auto; }
.map path { stroke: var(--surface); stroke-width: 0.5; }
.map path.hover { stroke: var(--text); stroke-width: 1; }
.seq-0 { fill: var(--seq-0); background: var(--seq-0); }
.seq-1 { fill: var(--seq-1); background: var(--seq-1); }
.seq-2 { fill: var(--seq-2); background: var(--seq-2); }
.seq-3 { fill: var(--seq-3); background: var(--seq-3); }
.seq-4 { fill: var(--seq-4); background: var(--seq-4); }
.seq-5 { fill: var(--seq-5); background: var(--seq-5); }
.legend i.swatch { width: 14px; height: 10px; border-radius: 2px; }
.country-list { max-height: 420px; overflow-y: auto; padding: 0; }
.country-list table th, .country-list table td { padding: 8px 12px; }
.country-list .muted { padding: 16px; }
.user-tools { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.user-tools input { flex: 1; min-width: 200px; }
.user-tools select { width: auto; }

/* ---------- campaign: linked posts ---------- */
.post-picks { display: grid; gap: 6px; max-height: 220px; overflow-y: auto; margin-top: 6px; border: 1px solid var(--border); border-radius: 8px; padding: 6px; }
.post-pick { display: flex; align-items: flex-start; gap: 8px; padding: 6px; border-radius: 6px; color: var(--text); font-size: 13px; cursor: pointer; }
.post-pick:hover { background: var(--surface-2); }
.post-pick input { width: auto; margin-top: 3px; }
.post-pick .grow { flex: 1; min-width: 0; }

/* ---------- chart type picker ---------- */
.chart-types { display: flex; flex-wrap: wrap; gap: 2px; justify-content: flex-end; margin: -4px 0 8px; }
.chart-types button { background: none; border: 1px solid transparent; color: var(--muted); font: inherit; font-size: 11px; padding: 3px 8px; border-radius: 6px; cursor: pointer; }
.chart-types button:hover { color: var(--text); }
.chart-types button.on { color: var(--accent); border-color: var(--border); background: var(--accent-soft); font-weight: 600; }
.chart .crosshair-band { fill: var(--text); fill-opacity: 0.06; }
.chart-table { max-height: 320px; overflow-y: auto; }
.chart-table tfoot td { border-top: 1px solid var(--border); }

/* ---------- sign in / sign up ---------- */
.auth-tabs { width: 100%; }
.auth-tabs button { flex: 1; }
.login-card .field { font-size: 13px; }
.invite-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.invite-row input { flex: 1; min-width: 220px; }
