/* ============================================================
   Dalaran — arcane dashboard theme (deliberately dark-only)
   ============================================================ */

:root {
  color-scheme: dark;
  /* surfaces */
  --page: #120e22;
  --surface: #1d1833;        /* card / chart surface (palette validated on this) */
  --surface-2: #241d40;
  --surface-3: #2c2450;
  /* ink */
  --ink: #efecfa;
  --ink-2: #b7b0d4;
  --muted: #8b85a8;
  /* chrome */
  --border: rgba(216, 205, 255, 0.11);
  --grid: #2e2750;
  --baseline: #3a3260;
  /* brand */
  --gold: #d9b96a;
  --gold-bright: #eed9a4;
  --arcane: #9085e9;
  --arcane-deep: #4a3aa7;
  /* chart series (validated order — see CLAUDE.md) */
  --series-1: #9085e9;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #3987e5;
  --series-8: #e66767;
  --finance: #c98500;
  --traffic: #9085e9;
  /* status */
  --good: #0ca30c;
  --danger: #e66767;
  --warning: #fab219;

  --serif: 'Iowan Old Style', 'Palatino Nova', Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1100px 500px at 75% -10%, rgba(74, 58, 167, 0.28), transparent 65%),
    radial-gradient(900px 420px at 10% 110%, rgba(217, 185, 106, 0.07), transparent 60%),
    var(--page);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
}

a { color: var(--arcane); text-decoration: none; }
a:hover { color: var(--gold-bright); }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }

.sidebar {
  border-right: 1px solid var(--border);
  background: rgba(18, 14, 34, 0.6);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.brand {
  font-family: var(--serif);
  font-size: 26px;
  letter-spacing: 0.14em;
  color: var(--gold);
  text-transform: uppercase;
  text-align: center;
  padding: 6px 0 2px;
  text-shadow: 0 0 18px rgba(217, 185, 106, 0.35);
}
.brand-sub {
  text-align: center; color: var(--muted); font-size: 11px;
  letter-spacing: 0.28em; text-transform: uppercase; margin-bottom: 18px;
}
.nav-section {
  color: var(--muted); font-size: 11px; letter-spacing: 0.18em;
  text-transform: uppercase; margin: 16px 8px 4px;
}
.nav-link {
  display: block; padding: 8px 10px; border-radius: 8px;
  color: var(--ink-2); font-size: 14px;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.active {
  background: linear-gradient(90deg, rgba(144, 133, 233, 0.18), transparent);
  color: var(--ink);
  box-shadow: inset 2px 0 0 var(--arcane);
}
.nav-link.sub { padding-left: 24px; font-size: 13px; }
.sidebar-foot { margin-top: auto; padding: 10px 8px; color: var(--muted); font-size: 12px; }
.sidebar-foot button { width: 100%; margin-top: 8px; }

.main { padding: 22px 26px 60px; min-width: 0; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin-bottom: 20px;
}
.topbar h1 {
  font-family: var(--serif); font-weight: 500; font-size: 24px;
  letter-spacing: 0.04em; margin: 0; color: var(--ink);
}
.topbar .crumb { color: var(--muted); font-size: 13px; }
.topbar .spacer { flex: 1; }

.menu-btn { display: none; }

/* ---------- Range picker ---------- */
.range-picker { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.range-picker button {
  background: transparent; border: 1px solid transparent; color: var(--ink-2);
  padding: 5px 11px; border-radius: 999px; font-size: 13px; cursor: pointer;
}
.range-picker button:hover { background: var(--surface-2); color: var(--ink); }
.range-picker button.active {
  background: var(--surface-3); color: var(--gold-bright);
  border-color: rgba(217, 185, 106, 0.35);
}

/* ---------- Cards ---------- */
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 14px; }
.grid-2 { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; margin-bottom: 14px; }

/* Cards placed directly in the main column (admin tabs, tables) stack with a
   gap; cards inside .cards/.grid-2 are spaced by the grid's own gap. */
.main > .card { margin-bottom: 14px; }

.card {
  background: linear-gradient(180deg, rgba(144, 133, 233, 0.05), transparent 40%), var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  min-width: 0;
}
.card h2 {
  font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 0 0 12px;
  letter-spacing: 0.06em; text-transform: uppercase;
  display: flex; align-items: center; gap: 8px;
}
.card h2 .hint { color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }

/* ---------- Stat tiles ---------- */
.tile .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 28px; font-weight: 600; margin-top: 2px; }
.tile .value.hero { font-size: 48px; line-height: 1.1; }
.tile .delta { font-size: 13px; margin-top: 4px; color: var(--muted); }
.tile .delta .up { color: var(--good); }
.tile .delta .down { color: var(--danger); }

/* ---------- Charts ---------- */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.chart-tip {
  position: absolute; pointer-events: none; display: none;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 12.5px;
  color: var(--ink); white-space: nowrap; z-index: 5;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}
.chart-tip .tip-date { color: var(--ink-2); }
.chart-tip .tip-val { font-weight: 600; }
.chart-empty { color: var(--muted); text-align: center; padding: 40px 0 46px; font-size: 13.5px; }

/* ---------- Bar list ---------- */
.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 1fr) 2fr auto; gap: 10px; align-items: center; }
.bar-row .bar-label { font-size: 13.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row a.bar-label:hover { color: var(--gold-bright); }
.bar-row .bar-track { height: 14px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar-row .bar-fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .bar-value { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  letter-spacing: 0.05em; text-transform: uppercase;
  padding: 6px 10px; border-bottom: 1px solid var(--baseline);
}
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--grid); }
table.data tr:last-child td { border-bottom: none; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .sub { color: var(--muted); font-size: 12px; }
table.data tr.indent td:first-child { padding-left: 28px; }

.pill {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-3); color: var(--ink-2); letter-spacing: 0.03em;
}
.pill.gold { color: var(--gold-bright); background: rgba(217, 185, 106, 0.12); }
.pill.dim { color: var(--muted); }

/* ---------- Forms ---------- */
form.stack { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12.5px; color: var(--ink-2); }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 120px; }

input, select, textarea {
  background: var(--page);
  border: 1px solid var(--baseline);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: var(--sans);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--arcane);
  box-shadow: 0 0 0 3px rgba(144, 133, 233, 0.22);
}
textarea { min-height: 90px; resize: vertical; }

button {
  font-family: var(--sans); font-size: 14px; cursor: pointer;
  border-radius: 8px; padding: 8px 16px; border: 1px solid transparent;
}
button.primary {
  background: linear-gradient(180deg, #e3c47c, #c9a44f);
  color: #241d40; font-weight: 600;
  box-shadow: 0 0 14px rgba(217, 185, 106, 0.25);
}
button.primary:hover { background: linear-gradient(180deg, #eed9a4, #d9b96a); }
button.ghost { background: transparent; border-color: var(--baseline); color: var(--ink-2); }
button.ghost:hover { border-color: var(--arcane); color: var(--ink); }
button.danger { background: transparent; border-color: rgba(230, 103, 103, 0.4); color: var(--danger); }
button.danger:hover { background: rgba(230, 103, 103, 0.12); }
button.small { font-size: 12.5px; padding: 4px 10px; }
button:disabled { opacity: 0.55; cursor: wait; }
button .spin {
  display: inline-block; width: 12px; height: 12px; margin-right: 6px;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  animation: spin 0.7s linear infinite; vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login / setup ---------- */
.portal {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.portal-card {
  width: 100%; max-width: 380px;
  background: linear-gradient(180deg, rgba(144, 133, 233, 0.08), transparent 50%), var(--surface);
  border: 1px solid rgba(217, 185, 106, 0.25);
  border-radius: 16px; padding: 34px 30px 30px;
  box-shadow: 0 0 60px rgba(74, 58, 167, 0.35);
}
.portal-card .brand { font-size: 34px; }
.portal-card .brand-sub { margin-bottom: 26px; }
.portal-err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 6px 0 2px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--baseline); margin-bottom: 16px; }
.tabs a {
  padding: 8px 14px; color: var(--ink-2); font-size: 14px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a.active { color: var(--gold-bright); border-bottom-color: var(--gold); }
.tabs a:hover { color: var(--ink); }

/* ---------- Dialogs ---------- */
dialog.card {
  margin: auto; width: min(440px, calc(100vw - 32px));
  border: 1px solid rgba(217, 185, 106, 0.3);
  box-shadow: 0 0 80px rgba(74, 58, 167, 0.5);
  max-height: 85vh; overflow-y: auto;
}
dialog.card::backdrop { background: rgba(10, 7, 22, 0.72); backdrop-filter: blur(2px); }
dialog.card h2 { font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--ink); }

/* ---------- Toasts ---------- */
#toasts {
  position: fixed; bottom: 18px; right: 18px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast {
  background: var(--surface-3); color: var(--ink);
  border: 1px solid var(--border); border-left: 3px solid var(--arcane);
  border-radius: 8px; padding: 10px 16px; font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.2s ease-out;
  max-width: 340px;
}
.toast.ok { border-left-color: var(--good); }
.toast.err { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mt { margin-top: 14px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty-note { color: var(--muted); font-size: 13.5px; padding: 14px 0; }
details.editor { margin-top: 8px; }
details.editor summary { cursor: pointer; color: var(--arcane); font-size: 13.5px; }
details.editor .card { margin-top: 10px; }

/* ---------- Mobile ---------- */
@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 25% 0 0; z-index: 50; min-width: 250px;
    transform: translateX(-100%); transition: transform 0.2s ease;
    background: var(--page); border-right: 1px solid var(--baseline);
    overflow-y: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); box-shadow: 30px 0 60px rgba(0,0,0,0.5); }
  .menu-btn {
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--surface-2); border: 1px solid var(--baseline);
    color: var(--gold); border-radius: 8px; width: 38px; height: 38px; font-size: 18px;
  }
  .main { padding: 14px 14px 60px; }
  .grid-2 { grid-template-columns: 1fr; }
  .tile .value.hero { font-size: 38px; }
  .bar-row { grid-template-columns: minmax(70px, 1fr) 1.4fr auto; }
}
