:root {
  --bg-base:      #0B0E14;
  --bg-surface:   #131722;
  --bg-elevated:  #1C2030;
  --border:       #2A2F45;
  --text:         #E8ECF4;
  --muted:        #8A93A6;
  --accent:       #5B8DEF;
  --win:          #22C55E;
  --loss:         #EF4444;
  --warn:         #F59E0B;
  --neutral-num:  #C9D1E0;
  --r:            14px;
  --r-sm:         10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  background: var(--bg-base);
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }

.mono { font-family: 'JetBrains Mono', ui-monospace, SF Mono, Menlo, monospace; font-variant-numeric: tabular-nums; }

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; }
.pipeline-status { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.pipeline-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pipeline-status[data-status="idle"] .dot { background: var(--win); }
.pipeline-status[data-status="running"] .dot { background: var(--warn); }
.pipeline-status[data-status="error"] .dot { background: var(--loss); }
.topnav { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.topnav a { color: var(--muted); font-weight: 600; }
.topnav a.active { color: var(--text); }
.logout-form { display: inline-flex; }
.logout-form button { color: var(--muted); font-weight: 600; }

.page { padding: 24px; max-width: 1280px; margin: 0 auto; padding-bottom: 80px; }

/* cards */
.card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r); padding: 18px; }
.card + .card { margin-top: 16px; }
.section-title { text-transform: uppercase; font-size: 12px; letter-spacing: 0.06em; font-weight: 600; color: var(--muted); margin-bottom: 12px; }

/* hero KPI */
.hero-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.kpi-hero { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r); padding: 20px; }
.kpi-hero .badge { font-size: 11px; letter-spacing: 0.08em; color: var(--muted); }
.kpi-hero .value { font-size: 36px; font-weight: 600; margin-top: 6px; }
.kpi-hero .delta-pos { color: var(--win); }
.kpi-hero .delta-neg { color: var(--loss); }
.kpi-hero .substat { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* pick rows */
.pick-row { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; padding: 12px; border-radius: var(--r-sm); background: var(--bg-elevated); border: 1px solid var(--border); cursor: pointer; }
.pick-row + .pick-row { margin-top: 8px; }
.pick-row:hover { border-color: var(--accent); }
.pick-row .badge-domain { font-size: 10px; font-weight: 700; padding: 4px 6px; border-radius: 6px; background: var(--bg-base); color: var(--muted); align-self: start; }
.pick-row .meta { color: var(--muted); font-size: 12px; }
.pick-row .edge-pos { color: var(--win); font-weight: 600; }
.pick-row .edge-neg { color: var(--loss); font-weight: 600; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.tbl th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.tbl td.num { text-align: right; font-family: 'JetBrains Mono', ui-monospace, monospace; color: var(--neutral-num); font-variant-numeric: tabular-nums; }

/* filter chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* modal */
dialog#modal-host { padding: 0; border: 0; border-radius: var(--r); background: var(--bg-surface); color: var(--text); width: min(720px, 95vw); max-height: 80vh; }
dialog#modal-host::backdrop { background: rgba(0, 0, 0, 0.6); }
.modal-sticky-head { position: sticky; top: 0; padding: 16px 20px; background: var(--bg-surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.modal-body { padding: 20px; overflow-y: auto; }
.kpi-strip { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 12px 0 18px; }
.kpi-strip .kpi { background: var(--bg-elevated); padding: 10px; border-radius: var(--r-sm); text-align: center; }
.kpi-strip .kpi .label { font-size: 10px; color: var(--muted); text-transform: uppercase; }
.kpi-strip .kpi .val { font-family: 'JetBrains Mono', monospace; font-size: 16px; font-weight: 600; color: var(--neutral-num); }
.collapsible { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 14px; }
.collapsible summary { cursor: pointer; font-weight: 600; color: var(--text); }
.collapsible[open] summary { color: var(--accent); }

/* auth screens */
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-title { font-size: 24px; font-weight: 700; margin-bottom: 24px; text-align: center; }
.auth-form { display: flex; flex-direction: column; gap: 14px; width: min(360px, 100%); padding: 24px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r); }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.auth-form input { padding: 10px 12px; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text); font-size: 14px; }
.auth-form button { padding: 10px 16px; border-radius: var(--r-sm); background: var(--accent); color: #fff; font-weight: 600; }
.auth-error { color: var(--loss); font-size: 13px; }

/* bottom nav (mobile only) */
.bottom-nav { display: none; }

@media (max-width: 639px) {
  .topnav { display: none; }
  .hero-grid {
    /* mobile: turn into horizontal swipe */
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 12px;
    padding-bottom: 8px;
  }
  .hero-grid > .kpi-hero {
    min-width: 85%;
    scroll-snap-align: center;
  }
  .kpi-strip { grid-template-columns: repeat(3, 1fr); }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--bg-surface); border-top: 1px solid var(--border);
    justify-content: space-around; padding: 10px 0; z-index: 10;
  }
  .bottom-nav a { padding: 8px 16px; min-width: 44px; min-height: 44px; display: grid; place-items: center; font-size: 22px; color: var(--muted); }
  .bottom-nav a.active { color: var(--accent); }
  dialog#modal-host { width: 100vw; max-height: 100vh; height: 100vh; border-radius: 0; }
}
