/* Velocity Clinical Research palette (brand: #274396 St Tropaz, #061E47 Deep Cove, #FBBF7F peach accent). */
:root {
  --vel-navy: #061e47;
  --vel-blue: #274396;
  --vel-peach: #fbbf7f;

  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --border: #dde2ee;
  --ink: #0f1c36;
  --ink-2: #4a5670;
  --ink-3: #7a849a;
  --primary: #274396;
  --primary-ink: #ffffff;
  --header-bg: #061e47;
  --header-ink: #ffffff;
  --grid: #e6e9f1;

  --good: #1b7f4c;
  --bad: #b3261e;
  --warn: #9a5b00;

  /* Validated categorical order (light surface): FB, IG, Google Ads, GA4 */
  --c-facebook: #3556b8;
  --c-instagram: #d9822b;
  --c-google_ads: #17917f;
  --c-ga4: #9b5bb0;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(6, 30, 71, 0.06), 0 2px 8px rgba(6, 30, 71, 0.05);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #07142b;
    --surface: #0b1a33;
    --surface-2: #112446;
    --border: #1e335a;
    --ink: #e8edf7;
    --ink-2: #aab5cc;
    --ink-3: #7d8aa6;
    --primary: #5b7bdb;
    --header-bg: #030d20;
    --grid: #182b4d;
    --good: #4cc38a;
    --bad: #f07b72;
    --warn: #e0a64a;
    --c-facebook: #5b7bdb;
    --c-instagram: #c77b30;
    --c-google_ads: #2ba391;
    --c-ga4: #a874c4;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #07142b;
  --surface: #0b1a33;
  --surface-2: #112446;
  --border: #1e335a;
  --ink: #e8edf7;
  --ink-2: #aab5cc;
  --ink-3: #7d8aa6;
  --primary: #5b7bdb;
  --header-bg: #030d20;
  --grid: #182b4d;
  --good: #4cc38a;
  --bad: #f07b72;
  --warn: #e0a64a;
  --c-facebook: #5b7bdb;
  --c-instagram: #c77b30;
  --c-google_ads: #2ba391;
  --c-ga4: #a874c4;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* Header */
header.top {
  background: var(--header-bg); color: var(--header-ink);
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 60px;
  border-bottom: 3px solid var(--vel-peach);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand .mark { width: 28px; height: 28px; border-radius: 7px; background: var(--vel-blue); display: grid; place-items: center; font-weight: 800; color: #fff; border: 2px solid var(--vel-peach); }
.brand .sub { font-weight: 400; opacity: 0.7; font-size: 13px; }
nav.tabs { display: flex; gap: 4px; height: 100%; }
nav.tabs a { color: rgba(255,255,255,0.72); text-decoration: none; padding: 0 14px; display: flex; align-items: center; border-bottom: 3px solid transparent; margin-bottom: -3px; font-weight: 500; }
nav.tabs a.active, nav.tabs a:hover { color: #fff; border-bottom-color: var(--vel-peach); }
.top .right { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; }
.top .right a { color: rgba(255,255,255,0.8); text-decoration: none; }
.src-dots { display: flex; gap: 10px; }
.src-dot { display: inline-flex; align-items: center; gap: 5px; color: rgba(255,255,255,0.85); font-size: 12px; }
.src-dot i { width: 8px; height: 8px; border-radius: 50%; background: #7a849a; display: inline-block; }
.src-dot.live i { background: #4cc38a; }
.src-dot.demo i { background: var(--vel-peach); }
.src-dot.error i { background: #f07b72; }

main { max-width: 1440px; margin: 0 auto; padding: 20px 24px 60px; }

/* Filter bar: one row above the charts */
.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; box-shadow: var(--shadow); margin-bottom: 16px;
  position: sticky; top: 72px; z-index: 10;
}
.filters label { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
select, input[type='date'], input[type='text'], input[type='number'], input[type='password'] {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; padding: 6px 9px;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 13px; color: var(--ink-2); user-select: none; }
.chip .sw { width: 10px; height: 10px; border-radius: 3px; }
.chip.on { background: var(--surface-2); color: var(--ink); border-color: var(--ink-3); }
.chip:not(.on) .sw { opacity: 0.3; }
.divider { width: 1px; align-self: stretch; background: var(--border); }
.btn { text-decoration: none; display: inline-block; font: inherit; font-weight: 550; border: 1px solid var(--border); background: var(--surface); color: var(--ink); border-radius: 7px; padding: 7px 12px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12px; }

.banner { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: 13px; border: 1px solid var(--border); background: var(--surface); }
.banner.demo { border-left: 4px solid var(--vel-peach); }
.banner.error { border-left: 4px solid var(--bad); }
.banner.ok { border-left: 4px solid var(--good); }

/* KPI groups */
.group { margin-bottom: 22px; }
.group-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.group-head h2 { border-left: 4px solid var(--vel-peach); padding-left: 8px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: 12px; color: var(--ink-2); font-weight: 550; text-transform: uppercase; letter-spacing: 0.03em; }
.tile .value { font-size: 26px; font-weight: 700; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.tile .delta { font-size: 12px; font-weight: 600; display: inline-flex; gap: 4px; align-items: center; }
.tile .delta.good { color: var(--good); }
.tile .delta.bad { color: var(--bad); }
.tile .delta.flat { color: var(--ink-3); }
.tile .target { font-size: 12px; color: var(--ink-3); margin-left: 8px; }
.tile .split { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; display: grid; gap: 3px; }
.tile .split div { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.tile .split span.k { display: inline-flex; align-items: center; gap: 6px; }
.tile .split span.k i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* Charts */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.chart-box { position: relative; height: 260px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
thead th { background: var(--vel-navy); color: #fff; font-weight: 600; font-size: 12px; cursor: pointer; position: sticky; top: 0; }
thead th:first-child { border-top-left-radius: 7px; }
thead th:last-child { border-top-right-radius: 7px; }
tbody tr:nth-child(even) td { background: var(--surface-2); }
td .pdot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 6px; }

/* Connections + settings */
.step { display: flex; align-items: center; gap: 8px; margin: 16px 0 6px; }
.step span { width: 20px; height: 20px; border-radius: 50%; background: var(--vel-navy); color: #fff; font-size: 11px; display: grid; place-items: center; border: 1.5px solid var(--vel-peach); }
.cred-form { display: grid; gap: 10px; margin: 8px 0 4px; }
.cred { display: grid; gap: 4px; }
.cred-label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.cred input { width: 100%; }
.cred-form details summary { cursor: pointer; color: var(--primary); margin-bottom: 6px; }
.cred-form .btn { justify-self: start; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.conn-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 14px; margin-bottom: 18px; }
.status-pill { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.status-pill.ok { color: var(--good); }
.status-pill.bad { color: var(--bad); }
.checklist { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 6px; }
.checklist li { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; }
.checklist .ic { font-weight: 700; width: 16px; }
.checklist .ic.ok { color: var(--good); }
.checklist .ic.no { color: var(--bad); }
code, .code { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12px; background: var(--surface-2); padding: 2px 6px; border-radius: 5px; word-break: break-all; }
.acct-list { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 6px; }
.acct-list label { display: flex; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
.acct-list label:hover { background: var(--surface-2); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 10px; }
.kpi-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 12px; margin-top: 8px; }
.kpi-pick label { display: flex; gap: 6px; font-size: 13px; }
.rules td, .rules th { text-align: left; }
.rules input { width: 100%; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--vel-navy); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); border-left: 4px solid var(--vel-peach); z-index: 50; }

@media (max-width: 980px) { .grid2 { grid-template-columns: 1fr; } }
@media (max-width: 720px) {
  header.top { gap: 12px; padding: 0 16px; height: auto; flex-wrap: wrap; padding-top: 8px; }
  .brand .sub, .src-dots { display: none; }
  main { padding: 16px; }
  .filters { position: static; }
  .grid2, .conn-grid { grid-template-columns: 1fr; }
}

.good-ink { color: var(--good); }
.bad-ink { color: var(--bad); }
.acct-list .lbl { margin-left: auto; width: 150px; padding: 3px 6px; font-size: 12px; }
#accountSel { max-width: 320px; }
.tile .split div { gap: 8px; }
.tile .split span.k { flex: 1 1 auto; min-width: 0; }
.tile .split span.k i { flex: none; }
.tile .split span.k .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .split div > span:last-child { flex: none; }
.tile { min-width: 0; }
.tile .split { grid-template-columns: minmax(0, 1fr); }
.tile .split div { min-width: 0; }

.viewer .admin-ctl { display: none !important; }
.user-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; align-items: end; }
.user-form label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.user-form input, .user-form select { width: 100%; }
.role-pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); text-transform: uppercase; letter-spacing: 0.04em; }
.role-pill.admin { color: var(--primary); }
#userTable td .row { justify-content: flex-end; gap: 6px; }
