/* Design tokens -- see dataviz skill's references/palette.md */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --success-text: #006300;

  --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: #6250d6; /* violet */
  --series-8: #e34948; /* red */

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  --radius-sm: 6px;
  --radius-md: 10px;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  /* A wide table must never widen the page itself -- only its own
     .table-wrap scrolls (see below). Without this, a wide table pushes
     body wider, and scrolling right drags the sidebar out of view since
     it's a normal flex sibling, not fixed -- that's the "blank on the
     right" bug. */
  overflow-x: hidden;
}
a { color: var(--series-1); }

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

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--text-primary);
  color: #f0efec;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  /* Stays put even if anything to its right somehow still overflows. */
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
  padding: 0 20px 20px;
  display: block;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 8px;
}
.sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; }
.sidebar .nav-section-label {
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: #8f8d87;
  padding: 14px 10px 6px;
}
.sidebar nav a {
  color: #d7d6d0;
  text-decoration: none;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar nav a.active { background: var(--series-1); color: #fff; }
.sidebar .tag-link { font-size: 12.5px; color: #b7b5ae; padding: 5px 10px 5px 24px; }
.sidebar .tag-link:hover { color: #fff; }

.sidebar .user-box {
  margin-top: auto;
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 12.5px;
}
.sidebar .user-box .email { color: #d7d6d0; display: block; margin-bottom: 8px; word-break: break-all; }
.sidebar .user-box button {
  background: transparent; border: 1px solid #55534d; color: #d7d6d0;
  border-radius: var(--radius-sm); padding: 5px 10px; cursor: pointer; font-size: 12px; width: 100%;
}
.sidebar .user-box button:hover { background: rgba(255,255,255,0.08); }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-x: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px; background: var(--surface-1); border-bottom: 1px solid var(--gridline);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.content { padding: 24px 28px; max-width: 1200px; width: 100%; margin: 0 auto; flex: 1; min-width: 0; }

/* ---------- Cards / panels ---------- */
.card, .panel {
  background: var(--surface-1);
  border: 1px solid var(--gridline);
  border-radius: var(--radius-md);
  padding: 18px;
  min-width: 0;
}
.panel { margin-bottom: 20px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-header h2 { font-size: 14px; margin: 0; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.03em; }

.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin: 4px 0 24px; }
.dashboard-card {
  display: block; background: var(--surface-1); border: 1px solid var(--gridline);
  border-radius: var(--radius-md); padding: 18px; text-decoration: none; color: inherit;
  transition: border-color .12s, transform .12s;
}
.dashboard-card:hover { border-color: var(--series-1); transform: translateY(-1px); }
.dashboard-card h3 { margin: 0 0 4px; font-size: 15px; }
.dashboard-card p { margin: 0; color: var(--text-muted); font-size: 12.5px; }

/* ---------- Stat tiles ---------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-tile { background: var(--surface-1); border: 1px solid var(--gridline); border-radius: var(--radius-md); padding: 16px 18px; cursor: help; }
.stat-tile .stat-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.info-icon { color: var(--text-muted); font-size: 12px; }
.chart-card[title] { cursor: help; }
.stat-tile .stat-value { font-size: 26px; font-weight: 600; font-variant-numeric: proportional-nums; }
.stat-tile .stat-delta { font-size: 12px; margin-top: 4px; }
.stat-tile .stat-delta.up { color: var(--success-text); }
.stat-tile .stat-delta.down { color: var(--status-critical); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; max-width: 100%; }
.column-toggle { margin-bottom: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border-bottom: 1px solid var(--gridline); padding: 8px 12px; text-align: left; white-space: nowrap; }
th { background: transparent; color: var(--text-muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; cursor: pointer; user-select: none; }
th:hover { color: var(--text-primary); }
th .sort-arrow { opacity: 0.4; margin-left: 3px; font-size: 10px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--page-plane); }

/* ---------- Badges / pills ---------- */
.badge { display: inline-block; font-size: 10.5px; padding: 2px 8px; border-radius: 10px; font-weight: 600; letter-spacing: 0.02em; }
.badge-stale { background: #fff3da; color: #92400e; }
.badge-source { background: #e9f0fc; color: var(--series-1); }
.badge-role { background: #ece9fb; color: var(--series-7); margin: 2px 4px 2px 0; }
.badge-tag { background: var(--page-plane); color: var(--text-secondary); border: 1px solid var(--gridline); }
.source-tag { font-size: 11px; color: var(--text-muted); }

/* ---------- Forms / buttons ---------- */
.btn {
  background: var(--text-primary); color: #fff; border: none; padding: 9px 16px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn:hover { opacity: 0.88; }
.btn-secondary { background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--gridline); }
.btn-secondary:hover { background: var(--page-plane); opacity: 1; }
.btn-danger { background: var(--status-critical); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

input[type=text], input[type=email], input[type=password], input[type=search], textarea, select {
  padding: 9px 11px; border: 1px solid var(--gridline); border-radius: var(--radius-sm);
  font-size: 13.5px; font-family: inherit; background: var(--surface-1); color: var(--text-primary);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--series-1); outline-offset: -1px; border-color: var(--series-1); }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
.form-card { max-width: 440px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; flex-direction: row; font-size: 13.5px; color: var(--text-primary); }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 14px; }

/* ---------- Misc ---------- */
.empty { color: var(--text-muted); font-style: italic; padding: 24px 0; text-align: center; }
.meta { color: var(--text-muted); font-size: 12.5px; }
.error { color: var(--status-critical); font-size: 13px; background: #fdecea; border: 1px solid #f6c6c1; border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 14px; }
.success-msg { color: var(--success-text); font-size: 13px; background: #eaf7ea; border: 1px solid #c3e6c3; border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 14px; }
.filter-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filter-row input[type=date] { padding: 6px 8px; }
.facet-dropdown { position: relative; }
.facet-dropdown summary { list-style: none; cursor: pointer; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: top; }
.facet-dropdown summary::-webkit-details-marker { display: none; }
.facet-dropdown .facet-caret { color: var(--text-muted); margin-left: 2px; }
.facet-panel {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; width: 260px;
  background: var(--surface-1); border: 1px solid var(--gridline); border-radius: var(--radius-md);
  padding: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); display: flex; flex-direction: column; gap: 8px;
}
.facet-search {
  width: 100%; padding: 7px 10px; font-size: 13px; border: 1px solid var(--gridline); border-radius: var(--radius-sm);
  background: var(--surface-2, var(--surface-1));
}
.facet-search:focus { outline: none; border-color: var(--series-1); }
.facet-actions { display: flex; align-items: center; gap: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--gridline); }
.btn-link { background: none; border: none; color: var(--series-1); cursor: pointer; font-size: 12px; padding: 0; }
.facet-count { margin-left: auto; font-size: 11px; color: var(--text-muted); }
.facet-options { max-height: 260px; overflow-y: auto; }
.facet-option { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 5px 4px; cursor: pointer; border-radius: var(--radius-sm); }
.facet-option:hover { background: var(--surface-2, rgba(0,0,0,0.03)); }
/* A class-based `display` rule beats the browser's default [hidden]
   { display: none } (author stylesheet always wins over the UA sheet,
   regardless of selector specificity) -- confirmed live: typing into the
   facet search box set the `hidden` attribute via JS but every option
   stayed visible until this explicit override was added. */
.facet-option[hidden] { display: none; }
.facet-empty { font-size: 12px; color: var(--text-muted); text-align: center; padding: 8px 0; margin: 0; }
.search-box { position: relative; margin-bottom: 18px; max-width: 360px; }
.search-box input { width: 100%; }
.chart-card canvas { max-height: 280px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--gridline); margin-bottom: 18px; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--text-secondary); font-size: 13px; border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--text-primary); border-bottom-color: var(--series-1); font-weight: 600; }
.breadcrumb { font-size: 12.5px; color: var(--text-muted); margin-bottom: 4px; }
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--series-1); }

/* ---------- Login ---------- */
.login-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--text-primary); }
.login-card { background: var(--surface-1); padding: 32px; border-radius: var(--radius-md); width: 340px; box-shadow: 0 20px 60px rgba(0,0,0,0.35); }
.login-card h1 { font-size: 19px; margin: 0 0 18px; }

/* ---------- Ask / chat ---------- */
.ask-form { display: flex; gap: 8px; margin-bottom: 20px; }
.ask-form input { flex: 1; }
.sql-preview { background: #0f172a; color: #e2e8f0; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 12px; overflow-x: auto; margin-bottom: 12px; }
