:root {
  --bg: #f6f4f0;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --border: #e6e1d9;
  --text: #1c1b19;
  --muted: #77736c;
  --faint: #a9a49b;
  --accent: #1d4e89;
  --accent-text: #ffffff;
  --up: #1d7a55;
  --down: #b03a3a;
  --warn-bg: #fff6dc;
  --warn-text: #7a5b12;
  --header: #0b0918;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121216;
    --surface: #1b1b21;
    --surface-2: #22222a;
    --border: #2e2e37;
    --text: #ecebe8;
    --muted: #a19d96;
    --faint: #6f6b65;
    --accent: #6ea4e6;
    --accent-text: #0b0918;
    --up: #4cc38a;
    --down: #ef6b6b;
    --warn-bg: #3a3014;
    --warn-text: #f1d58a;
    --header: #08070f;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121216;
  --surface: #1b1b21;
  --surface-2: #22222a;
  --border: #2e2e37;
  --text: #ecebe8;
  --muted: #a19d96;
  --faint: #6f6b65;
  --accent: #6ea4e6;
  --accent-text: #0b0918;
  --up: #4cc38a;
  --down: #ef6b6b;
  --warn-bg: #3a3014;
  --warn-text: #f1d58a;
  --header: #08070f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }

/* ── Shell ───────────────────────── */
.topbar {
  background: var(--header);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 54px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.topbar .brand small { font-weight: 400; color: rgba(255, 255, 255, 0.5); margin-left: 8px; font-size: 12px; }
.topbar nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
.topbar nav a {
  color: rgba(255, 255, 255, 0.65);
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
  font-size: 13px;
}
.topbar nav a:hover { color: #fff; text-decoration: none; background: rgba(255, 255, 255, 0.08); }
.topbar nav a.active { color: #fff; background: rgba(255, 255, 255, 0.14); }
.topbar .user { font-size: 12px; color: rgba(255, 255, 255, 0.55); white-space: nowrap; }
.topbar .user button { background: none; border: 0; color: rgba(255, 255, 255, 0.75); cursor: pointer; padding: 4px 6px; }

main { max-width: 1240px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 20px; margin: 4px 0 16px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 10px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card + .card { margin-top: 0; }
.stack > * + * { margin-top: 16px; }

/* ── KPI tiles ───────────────────── */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* ── Tables ──────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
th:first-child, td:first-child { text-align: left; white-space: normal; }
td { font-variant-numeric: tabular-nums; }
td .sub { display: block; font-size: 11px; color: var(--faint); }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.new {
  font-size: 9px; font-weight: 700; color: #fff; background: var(--down);
  border-radius: 3px; padding: 1px 4px; margin-left: 4px; vertical-align: 1px;
}

/* ── Alerts ──────────────────────── */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters select, .filters input, .field input, .field select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 6px 9px; min-width: 0;
}
.filters input[type="search"] { flex: 1; min-width: 180px; }
.alert { padding: 12px 0; border-bottom: 1px solid var(--border); }
.alert:last-child { border-bottom: 0; }
.alert .meta { font-size: 11px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.alert .title { font-weight: 600; font-size: 14px; margin: 3px 0; display: block; color: var(--text); }
.alert .excerpt { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.alert .actions { margin-top: 6px; display: flex; gap: 6px; }
.tier {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  border-radius: 4px; padding: 1px 6px; color: #fff;
}
.chip { font-size: 11px; border: 1px solid var(--border); border-radius: 999px; padding: 0 7px; }
.chip.pos { color: var(--up); border-color: currentColor; }
.chip.neg { color: var(--down); border-color: currentColor; }

/* ── Sentiment ───────────────────── */
.sent { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.sent:last-child { border-bottom: 0; }
.sent .name { font-weight: 600; }
.sent .desc { font-size: 12px; color: var(--muted); grid-column: 1 / -1; }
.bar { position: relative; height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; grid-column: 1 / -1; }
.bar .mid { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--faint); }
.bar .fill { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.score { font-weight: 700; font-variant-numeric: tabular-nums; }
.spark { grid-column: 1 / -1; }

/* ── Forms / buttons ─────────────── */
.btn {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 7px;
  padding: 7px 12px; cursor: pointer; font-weight: 600; font-size: 13px;
}
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.small { padding: 3px 8px; font-size: 12px; font-weight: 500; }
.btn.danger { background: var(--down); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }
.field { display: grid; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.notice { background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--header); color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13px; z-index: 50;
}

/* ── Login ───────────────────────── */
.login { max-width: 380px; margin: 10vh auto; }
.login h1 { margin-bottom: 4px; }
.login .btn { width: 100%; padding: 9px; }

.calendar-item { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.calendar-item:last-child { border-bottom: 0; }
.empty { color: var(--faint); font-style: italic; padding: 10px 0; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 16px; gap: 6px; }
  .topbar nav { order: 3; width: 100%; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  main { padding: 16px 16px 48px; }
}
