/* Design tokens - validated categorical/sequential palette (see dataviz skill reference). */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #f9f9f7;
  --surface-3: #f0efec;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --good: #006300;
  --bad: #b3261e;
  --warn: #9a6b00;

  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red */

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  /* Spacing scale used everywhere - cards, sections, forms, tables, headers,
     footer - so gaps are consistent instead of one-off pixel values. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --shadow-1: 0 1px 2px rgba(11,11,11,0.06), 0 1px 1px rgba(11,11,11,0.04);
  --shadow-2: 0 4px 16px rgba(11,11,11,0.10), 0 1px 3px rgba(11,11,11,0.06);
  --content-max-width: 1400px;
  --form-max-width: 880px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --surface-2: #0d0d0d;
  --surface-3: #232322;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255,255,255,0.10);
  --good: #0ca30c;
  --bad: #e66767;
  --warn: #d9a441;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-1: #1a1a19;
    --surface-2: #0d0d0d;
    --surface-3: #232322;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255,255,255,0.10);
    --good: #0ca30c;
    --bad: #e66767;
    --warn: #d9a441;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: var(--space-4);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.sidebar-user {
  font-size: 0.78rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-backdrop { display: none; }

.nav-toggle {
  display: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1.05rem;
  line-height: 1;
  padding: 8px 10px;
  cursor: pointer;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--series-1); }

.nav-group { margin-bottom: var(--space-5); }
.nav-group h6 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 var(--space-2) 0;
}
.nav-link {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.92rem;
  margin-bottom: 2px;
}
.nav-link:hover { background: var(--surface-3); text-decoration: none; }
.nav-link.active { background: var(--surface-3); color: var(--text-primary); font-weight: 600; }

.main-content { flex: 1; min-width: 0; padding: var(--space-5) var(--space-6); }

.page-content { max-width: var(--content-max-width); }

.page-footer { margin-top: var(--space-6); }
.page-footer p { margin: 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-5);
  gap: var(--space-3);
  flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.topbar h1 { font-size: 1.4rem; margin: 0; }
.status-pills { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
}
.pill-dot { width: 7px; height: 7px; border-radius: 50%; }
.pill-dot.ok { background: var(--good); }
.pill-dot.warn { background: var(--warn); }
.pill-dot.bad { background: var(--bad); }

.theme-toggle {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
  box-shadow: var(--shadow-1);
}
.card h2, .card h3 { margin-top: 0; }
.card h3 { margin-bottom: var(--space-3); }

.card.form-card { max-width: var(--form-max-width); }

/* Every top-level grid of tiles/cards (e.g. the dashboard's 3 status tiles)
   gets the same bottom margin as a .card, so consecutive sections never sit
   flush against each other regardless of what follows. */
.grid { display: grid; gap: var(--space-4); margin-bottom: var(--space-5); }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }

  .sidebar {
    display: flex;
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-2);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
}
@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .main-content { padding: var(--space-4); }
  .card { padding: var(--space-4); }
}

.metric-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
}
.metric-tile .label {
  font-size: 0.74rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.metric-tile .value {
  font-size: 1.35rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.metric-tile .sub { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }

.delta { font-weight: 600; }
.delta.pos::before { content: "▲ "; font-size: 0.75em; }
.delta.neg::before { content: "▼ "; font-size: 0.75em; }
.delta.pos { color: var(--good); }
.delta.neg { color: var(--bad); }

form .field { margin-bottom: var(--space-4); }
label { display: block; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 6px; font-weight: 500; }
label .hint { color: var(--text-muted); font-weight: 400; }
.form-help {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: -4px 0 var(--space-4) 0;
}
input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 0.92rem;
  transition: border-color 0.15s ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--baseline); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--series-1); outline-offset: 1px; border-color: var(--series-1); }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5) var(--space-5);
  margin: 0 0 var(--space-5) 0;
  background: color-mix(in srgb, var(--surface-3) 35%, transparent);
}
fieldset:last-of-type { margin-bottom: var(--space-4); }
legend {
  padding: 2px 10px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}
legend .hint { font-weight: 400; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s ease, filter 0.15s ease;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
.btn-primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--series-1); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--gridline); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.03em; }
td { font-variant-numeric: tabular-nums; }
tbody tr:hover td { background: var(--surface-3); }
.table-scroll { overflow-x: auto; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  background: var(--surface-3);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.tooltip-term {
  border-bottom: 1px dotted var(--text-muted);
  cursor: help;
}

.flash-stack { margin-bottom: var(--space-4); display: flex; flex-direction: column; gap: 8px; }
.flash {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  border: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.flash-error { background: color-mix(in srgb, var(--bad) 12%, var(--surface-1)); }
.flash-warning { background: color-mix(in srgb, var(--warn) 14%, var(--surface-1)); }
.flash-success { background: color-mix(in srgb, var(--good) 12%, var(--surface-1)); }
.flash-info { background: var(--surface-3); }

.empty-state {
  text-align: center;
  padding: var(--space-7) var(--space-4);
  color: var(--text-secondary);
}
.empty-state .icon { font-size: 2.25rem; margin-bottom: var(--space-3); }
.empty-state p { max-width: 480px; margin-left: auto; margin-right: auto; }
.empty-state-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: center;
  flex-wrap: wrap;
  margin-top: var(--space-4);
}

.loading-overlay {
  display: none;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}
.loading-overlay.active { display: flex; }
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--series-1);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chart-box { width: 100%; height: 340px; }
.chart-box.small { height: 220px; }
.chart-box.tall { height: 420px; }

.disclaimer-banner {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}

.badge-confidence {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.badge-confidence.low { background: color-mix(in srgb, var(--warn) 16%, var(--surface-1)); }
.badge-confidence.medium { background: var(--surface-3); }
.badge-confidence.high { background: color-mix(in srgb, var(--good) 14%, var(--surface-1)); }

.chat-log { display: flex; flex-direction: column; gap: var(--space-3); max-height: 60vh; overflow-y: auto; padding-right: 4px; }
.chat-msg { max-width: 88%; padding: var(--space-3); border-radius: var(--radius-md); }
.chat-msg.user { align-self: flex-end; background: var(--series-1); color: #fff; }
.chat-msg.assistant { align-self: flex-start; background: var(--surface-3); }
.chat-msg .msg-section { margin-top: 8px; font-size: 0.85rem; }
.chat-msg .msg-section h6 { margin: 0 0 4px 0; font-size: 0.72rem; text-transform: uppercase; color: var(--text-muted); }
.chat-msg.user .msg-section h6 { color: rgba(255,255,255,0.75); }
.chat-input-row { display: flex; gap: 8px; margin-top: var(--space-3); }
.chat-input-row textarea { flex: 1; resize: vertical; min-height: 44px; }

.chat-error-box {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--bad);
  min-height: 1.2em;
  margin-top: 6px;
}

.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.small { font-size: 0.82rem; }
hr.hairline { border: none; border-top: 1px solid var(--gridline); margin: var(--space-4) 0; }

/* Auth pages (login/register): a standalone centered layout, no sidebar. */
.auth-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-5);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  padding: var(--space-6);
}
.auth-brand { justify-content: center; margin-bottom: var(--space-5); }
.auth-title { font-size: 1.3rem; margin: 0 0 var(--space-2) 0; text-align: center; }
.auth-subtitle { text-align: center; margin: 0 0 var(--space-5) 0; }
.auth-form .field { margin-bottom: var(--space-4); }
.auth-submit { width: 100%; justify-content: center; margin-top: var(--space-2); }
.auth-footer-link { text-align: center; margin: var(--space-5) 0 0 0; }
.auth-disclaimer { max-width: 420px; text-align: center; }
