:root {
  --surface:   #fcfcfb;
  --page:      #f9f9f7;
  --ink:       #0b0b0b;
  --ink2:      #52514e;
  --muted:     #898781;
  --grid:      #e1e0d9;
  --baseline:  #c3c2b7;
  --border:    rgba(11,11,11,0.10);

  --blue:    #2a78d6;
  --orange:  #eb6834;
  --aqua:    #1baf7a;
  --yellow:  #eda100;
  --magenta: #e87ba4;
  --green:   #008300;
  --violet:  #4a3aa7;
  --red:     #e34948;

  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;
  --up:       #006300;
  --down:     #d03b3b;

  --radius: 10px;
  --radius-sm: 6px;
  --space: 16px;
  --space-sm: 8px;
  --space-xs: 4px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "SF Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1180px; margin: 0 auto; padding: var(--space); }

/* --- Topbar --- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 10px var(--space);
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 15px; }
.brand .sub { color: var(--muted); font-weight: 400; font-size: 12px; font-family: var(--font-mono); margin-left: 6px; }
.nav { display: flex; gap: 14px; flex-wrap: wrap; }
.nav a { color: var(--ink2); font-size: 13px; padding: 4px 2px; border-bottom: 2px solid transparent; }
.nav a.active { color: var(--ink); border-bottom-color: var(--blue); font-weight: 600; }
.cost-pill {
  margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--ink2);
  background: var(--page); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px;
}
.cost-pill b { color: var(--ink); }
.cost-pill.cap-near { color: var(--critical); border-color: var(--critical); }

/* --- Cards / grids --- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--space);
}
.grid { display: grid; gap: var(--space); }
.grid > * { min-width: 0; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat-tile { display: flex; flex-direction: column; gap: 2px; }
.stat-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat-val { font-family: var(--font-mono); font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--ink2); }
.stat-sub.up { color: var(--up); }
.stat-sub.down { color: var(--down); }

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.section { margin-top: 28px; }
.hint { color: var(--muted); font-size: 12px; }

/* --- Forms --- */
.form-row { display: flex; gap: var(--space-sm); flex-wrap: wrap; align-items: center; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=password], select {
  background: var(--surface); border: 1px solid var(--baseline); border-radius: var(--radius-sm);
  padding: 8px 10px; font-family: var(--font-ui); font-size: 13px; color: var(--ink);
}
.input-date { max-width: 150px; }

/* --- Login --- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px; width: 100%; max-width: 340px;
}
.login-box h1 { font-size: 18px; margin: 0 0 18px; }
.login-box label { display: block; font-size: 12px; color: var(--ink2); margin-bottom: 14px; }
.login-box input { display: block; width: 100%; margin-top: 4px; }
.login-box .remember { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.login-box .remember input { width: auto; margin: 0; }
.login-box button { width: 100%; margin-top: 4px; }
.login-error { color: var(--critical); font-size: 13px; margin-bottom: 14px; }
button, .btn {
  background: var(--blue); color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 8px 14px; font-size: 13px; cursor: pointer; font-family: var(--font-ui);
}
button:hover, .btn:hover { background: #1c5cab; text-decoration: none; }
.btn-secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--baseline); }
.btn-secondary:hover { background: var(--page); }

/* --- Tables --- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; cursor: pointer; user-select: none; }
th.sort-asc::after { content: " \25B2"; }
th.sort-desc::after { content: " \25BC"; }
td.num, th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
td.kw { white-space: normal; max-width: 320px; }
tr:hover td { background: var(--page); }

/* --- badges / pills --- */
.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-family: var(--font-mono); }
.badge.top3 { background: rgba(12,163,12,.12); color: var(--good); }
.badge.top10 { background: rgba(42,120,214,.12); color: var(--blue); }
.badge.top100 { background: rgba(137,135,129,.15); color: var(--ink2); }
.badge.new { background: rgba(12,163,12,.12); color: var(--good); }
.badge.lost { background: rgba(208,59,59,.12); color: var(--critical); }
.delta-up { color: var(--up); font-family: var(--font-mono); }
.delta-down { color: var(--down); font-family: var(--font-mono); }

/* --- Tabs --- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: var(--space); flex-wrap: wrap; }
.tab { padding: 8px 14px; font-size: 13px; color: var(--ink2); border-bottom: 2px solid transparent; cursor: pointer; }
.tab.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--blue); }

canvas.chart { max-width: 100%; }
.sparkline { width: 90px; height: 26px; vertical-align: middle; }

.empty-state { color: var(--muted); padding: 30px 0; text-align: center; }

/* --- traffic-kwaliteit: verdachte-sessies-lijst (lange UA/landingpagina-strings) --- */
.lp-cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: help; }
.footer { margin-top: 40px; padding: 20px 0 40px; text-align: center; color: var(--muted); font-size: 12px; }

/* --- kanaal-kleuren (DESIGN.md: vaste toewijzing per referrer_class) --- */
.ch-organic_search { color: var(--blue); }
.ch-social { color: var(--magenta); }
.ch-paid { color: var(--orange); }
.ch-ai { color: var(--green); }
.ch-direct { color: var(--ink2); }
.ch-mail { color: var(--aqua); }
.ch-referral { color: var(--violet); }
.ch-unknown { color: var(--warning); font-weight: 600; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: currentColor; }

/* --- attributie-toggle --- */
.model-toggle { display: flex; gap: 4px; }
.model-toggle a { padding: 6px 12px; border: 1px solid var(--baseline); border-radius: var(--radius-sm); font-size: 12px; color: var(--ink2); }
.model-toggle a.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* --- orders bewijsscherm --- */
.order-row { cursor: pointer; }
.touchpath { display: none; padding: 10px 14px; background: var(--page); border-radius: var(--radius-sm); margin: 4px 0 10px; }
.touchpath.open { display: block; }
.touchpoint { display: flex; gap: 10px; align-items: center; padding: 4px 0; font-size: 12px; border-bottom: 1px dashed var(--grid); flex-wrap: wrap; }
.touchpoint > * { min-width: 0; overflow-wrap: anywhere; }
.touchpoint:last-child { border-bottom: none; }
.touchpoint .tp-idx { font-family: var(--font-mono); color: var(--muted); width: 18px; }
.touchpoint .tp-time { font-family: var(--font-mono); color: var(--muted); width: 66px; flex-shrink: 0; }
.badge.matched { background: rgba(12,163,12,.12); color: var(--good); }
.badge.unmatched { background: rgba(250,178,25,.15); color: #a06600; }
.badge.purchase { background: rgba(12,163,12,.15); color: var(--good); font-weight: 600; }
.touchpoint-purchase { background: rgba(12,163,12,.08); border-radius: var(--radius-sm); border-bottom: none; padding: 6px 8px; }
.touchpoint-purchase b { color: var(--good); }
.tp-weight { margin-left: auto; font-family: var(--font-mono); font-size: 11px; padding: 1px 7px; border-radius: 999px; background: rgba(42,120,214,.12); color: var(--blue); white-space: nowrap; }
.tp-weight-zero { background: var(--grid); color: var(--muted); }
.ch-conversion { color: var(--good); font-weight: 600; }

/* --- funnel (fase 2) --- */
.funnel { display: flex; flex-direction: column; gap: 12px; margin: 16px 0 8px; }
.funnel-row { display: flex; align-items: center; gap: 14px; }
.funnel-label { width: 150px; font-size: 13px; color: var(--ink2); flex-shrink: 0; }
.funnel-bar-wrap { flex: 1; background: var(--page); border-radius: var(--radius-sm); height: 30px; }
.funnel-bar { height: 100%; min-width: 2px; background: var(--blue); display: flex; align-items: center;
  padding-left: 10px; color: #fff; font-family: var(--font-mono); font-size: 12px; white-space: nowrap;
  border-radius: var(--radius-sm); transition: width .2s; }
.funnel-meta { width: 190px; text-align: right; font-family: var(--font-mono); font-size: 12px; color: var(--ink2); flex-shrink: 0; }
.funnel-dropoff { color: var(--down); }

/* --- journeys (fase 2) --- */
.journey-path { font-family: var(--font-mono); font-size: 12px; }
.journey-path .arrow { color: var(--muted); margin: 0 3px; }
.role-bar-wrap { display: flex; height: 18px; border-radius: var(--radius-sm); overflow: hidden; min-width: 120px; background: var(--grid); }
.role-bar { height: 100%; }
.role-bar.discoverer { background: var(--blue); }
.role-bar.middle { background: var(--baseline); }
.role-bar.closer { background: var(--aqua); }
.role-legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink2); margin-top: 8px; }
.role-legend .dot.discoverer { background: var(--blue); }
.role-legend .dot.middle { background: var(--baseline); }
.role-legend .dot.closer { background: var(--aqua); }

/* fase 3: kanaal-uitklap, subtotaalrijen, device-split, ad-labels */
.channel-group { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 8px; }
.channel-group summary { cursor: pointer; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; font-weight: 600; }
.channel-summary-stats { font-family: var(--font-mono); font-size: 12px; color: var(--ink2); font-weight: 400; }
/* laatste run: boomtabel kanaal -> bron -> campagne -> ad, 3 geneste uitklapniveaus */
.tree-lvl1 > summary { font-size: 15px; }
.tree-lvl2 { margin: 8px 0 0 18px; padding: 8px 12px; }
.tree-lvl2 > summary { font-weight: 500; font-size: 13px; }
.tree-lvl3 { margin: 6px 0 0 18px; padding: 6px 10px; }
.tree-lvl3 > summary { font-weight: 400; font-size: 12px; color: var(--ink2); }
.subtotal-row td { font-weight: 600; border-top: 1px solid var(--grid); }
.device-split { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.device-split-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.device-split-label { width: 80px; flex-shrink: 0; color: var(--ink2); }
.device-split-bar-wrap { flex: 1; background: var(--page); border-radius: var(--radius-sm); height: 16px; }
.device-split-bar { height: 100%; background: var(--blue); border-radius: var(--radius-sm); }
.device-split-val { width: 110px; text-align: right; font-family: var(--font-mono); font-size: 12px; color: var(--ink2); flex-shrink: 0; }
.ad-labels-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.ad-labels-form input[type="text"] { padding: 6px 10px; border: 1px solid var(--baseline); border-radius: var(--radius-sm); font-family: var(--font-ui); font-size: 13px; }

/* --- realtime tab (opdracht 2026-09-11) --- */
.rt-feed { display: flex; flex-direction: column; gap: 0; max-height: 420px; overflow-y: auto; }
.rt-feed-row { display: flex; gap: 10px; align-items: baseline; padding: 5px 0; border-bottom: 1px dashed var(--grid); font-size: 12px; }
.rt-feed-row:last-child { border-bottom: none; }
.rt-feed-row.purchase { background: rgba(12,163,12,.08); border-radius: var(--radius-sm); }
.rt-feed-row.purchase .rt-feed-type { color: var(--good); }
.rt-feed-time { font-family: var(--font-mono); color: var(--muted); width: 66px; flex-shrink: 0; }
.rt-feed-type { font-weight: 600; width: 90px; flex-shrink: 0; }
.rt-feed-url { color: var(--ink2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
#rtMap circle { transition: r .2s, cx .2s, cy .2s; }

@media (max-width: 640px) {
  .stat-val { font-size: 21px; }
  .wrap { padding: var(--space-sm); }
  .cost-pill { margin-left: 0; }
  .funnel-row { flex-direction: column; align-items: stretch; gap: 4px; }
  .funnel-label { width: auto; }
  .funnel-meta { width: auto; text-align: left; }
}
