/* Option A v2 — sidebar nav, Organization-scoped cards + live search, right-sliding detail
   panel, net-new Admin page. Palette + roles per the dataviz skill (references/palette.md). */

* { box-sizing: border-box; }

.viz-root {
  color-scheme: dark;
  --page-plane:     #0d0d0d;
  --surface-1:      #1a1a19;
  --surface-2:      #202020;
  --surface-3:      #262625;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border-hairline: rgba(255,255,255,0.10);

  --series-1: #3987e5; /* blue   — used for LLM */
  --series-2: #d95926; /* orange */
  --series-3: #199e70; /* aqua   — used for embedding */
  --series-4: #c98500; /* yellow */
  --series-5: #d55181; /* magenta */
  --series-6: #008300; /* green */
  --series-7: #9085e9; /* violet */
  --series-8: #e66767; /* red */

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

  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-plane);
  color: var(--text-primary);
}
body { margin: 0; overflow-x: hidden; }

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

.sidebar {
  width: 76px; flex-shrink: 0;
  background: var(--surface-1); border-right: 1px solid var(--border-hairline);
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 0; gap: 6px; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
  width: 36px; height: 36px; border-radius: 9px; background: var(--series-1);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; margin-bottom: 14px;
}
.nav-item {
  width: 60px; display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: none; border: none; color: var(--text-muted); font-family: inherit;
  font-size: 10.5px; padding: 9px 4px; border-radius: 9px; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { color: var(--text-secondary); background: var(--surface-2); }
.nav-item.active { color: var(--text-primary); background: var(--surface-3); }
.sidebar-footer { margin-top: auto; }
.badge {
  font-size: 9px; font-weight: 700; letter-spacing: 0.05em;
  color: var(--status-warning); border: 1px solid var(--status-warning);
  padding: 2px 5px; border-radius: 4px; writing-mode: vertical-rl;
}

.content { flex: 1; min-width: 0; }
/* The `hidden` attribute is how nav switches views (see script.js) — it must win over the
   `.view` class's own display rule, otherwise (real bug, since fixed) both views render at
   once. Author CSS always beats the browser's built-in [hidden] style unless we say so
   explicitly here. */
.view { display: none; }
.view:not([hidden]) { display: block; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 32px; border-bottom: 1px solid var(--border-hairline);
  position: sticky; top: 0; background: var(--page-plane); z-index: 10;
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 600; }
.topbar-controls { display: flex; gap: 20px; align-items: end; }
.control { display: flex; flex-direction: column; gap: 4px; }
.control label { font-size: 11px; color: var(--text-muted); }
.control select, .control input {
  background: var(--surface-2); color: var(--text-primary);
  border: 1px solid var(--border-hairline); border-radius: 6px;
  padding: 7px 10px; font-size: 13px; font-family: inherit;
}
.control.cost-input input { width: 100px; font-variant-numeric: tabular-nums; }
.control.cost-input input:focus, .control select:focus { outline: 2px solid var(--series-1); outline-offset: 1px; }

.control.custom-range-fields {
  flex-direction: row; align-items: center; gap: 6px;
  overflow: hidden; max-width: 320px; opacity: 1;
  transition: max-width 200ms ease, opacity 160ms ease, margin 200ms ease;
}
.control.custom-range-fields label { margin: 0; }
.control.custom-range-fields input[type="date"] { padding: 6px 8px; font-size: 12.5px; }
.control.custom-range-fields.hidden { max-width: 0; opacity: 0; pointer-events: none; margin-left: -20px; }

.content > .view { padding: 0 0 64px; }
.topbar + .totals-row, .totals-row { margin: 24px 32px 0; }
.orgs-section, .admin-block { margin: 32px 32px 0; }

.section-title { font-size: 14px; font-weight: 600; color: var(--text-secondary); margin: 0 0 4px; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- Stat tiles ---------- */
.totals-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat-tile { background: var(--surface-1); border: 1px solid var(--border-hairline); border-radius: 10px; padding: 16px 18px; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* ---------- Org search + grid ---------- */
.orgs-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 14px; }
.orgs-count { display: block; font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.org-search-wrap { position: relative; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
#orgSearch {
  background: var(--surface-2); border: 1px solid var(--border-hairline); border-radius: 8px;
  color: var(--text-primary); padding: 8px 12px 8px 30px; font-size: 13px; width: 280px; font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#orgSearch:focus { outline: none; border-color: var(--series-1); box-shadow: 0 0 0 2px rgba(57,135,229,0.25); }

.org-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.org-card {
  background: var(--surface-1); border: 1px solid var(--border-hairline); border-radius: 10px;
  padding: 16px 18px; cursor: pointer; text-align: left; color: var(--text-primary); font-family: inherit;
  transition: opacity 180ms ease, transform 180ms ease, border-color 0.15s, box-shadow 0.15s;
  transform: scale(1); opacity: 1;
}
.org-card:hover { border-color: var(--series-1); }
.org-card.selected { border-color: var(--series-1); box-shadow: 0 0 0 1px var(--series-1) inset; }
/* Search filtering removes non-matching cards from the grid entirely (no leftover blank
   cell) and FLIP-animates the remaining/entering cards into their new positions — see
   scheduleOrgFilter() in script.js. These two classes are the enter/exit endpoints only;
   the slide itself is a per-card inline transform set from JS, not a class. */
.org-card.org-card-exit { opacity: 0; transform: scale(0.92); pointer-events: none; }
.org-card.org-card-enter { opacity: 0; transform: scale(0.92); }

.org-card-name { font-size: 15px; font-weight: 600; }
.org-card-uuid { font-size: 11px; color: var(--text-muted); font-family: "SF Mono", ui-monospace, monospace; margin-top: 2px; margin-bottom: 12px; word-break: break-all; }
.org-card-divider { height: 1px; background: var(--gridline); margin: 10px 0; }
.org-card-stat { display: flex; justify-content: space-between; align-items: baseline; padding: 5px 0; font-size: 13px; }
.org-card-stat .k { color: var(--text-secondary); }
.org-card-stat .v { font-variant-numeric: tabular-nums; font-weight: 500; }
.org-card-stat .v-sub { display: block; font-size: 11px; color: var(--text-muted); font-weight: 400; text-align: right; }
.org-card-stat.llm .v { color: var(--series-1); }
.org-card-stat.embedding .v { color: var(--series-3); }

.empty-state { padding: 40px 0; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ---------- Settings page ---------- */
.admin-block { background: var(--surface-1); border: 1px solid var(--border-hairline); border-radius: 10px; padding: 20px 22px; margin-bottom: 20px !important; }
.admin-note { font-size: 12px; color: var(--text-muted); max-width: 560px; margin: 6px 0 0; line-height: 1.5; }

/* ---------- Detail panel (right-sliding sidebar) ---------- */
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); opacity: 0; pointer-events: none;
  transition: opacity 240ms ease; z-index: 30;
}
.scrim.open { opacity: 1; pointer-events: auto; }

.detail-panel {
  position: fixed; top: 0; right: 0; height: 100vh; width: 420px; max-width: 92vw;
  background: var(--surface-1); border-left: 1px solid var(--border-hairline);
  transform: translateX(100%); transition: transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 31; padding: 22px 22px 32px; overflow-y: auto;
}
.detail-panel.open { transform: translateX(0); }

.detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.detail-name { font-size: 17px; font-weight: 600; }
.detail-uuid { font-size: 11.5px; color: var(--text-muted); font-family: "SF Mono", ui-monospace, monospace; margin-top: 3px; word-break: break-all; }
.close-btn {
  background: var(--surface-2); border: 1px solid var(--border-hairline); color: var(--text-secondary);
  width: 28px; height: 28px; border-radius: 7px; cursor: pointer; font-size: 13px; flex-shrink: 0;
}
.close-btn:hover { color: var(--text-primary); }

.detail-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.detail-stats .d-stat { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.detail-stats .d-stat .k { font-size: 11px; color: var(--text-muted); }
.detail-stats .d-stat .v { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }

.tabs { display: flex; gap: 4px; background: var(--surface-2); border-radius: 8px; padding: 3px; margin-bottom: 14px; }
.tab { background: transparent; border: none; color: var(--text-secondary); font-family: inherit; font-size: 12.5px; padding: 6px 12px; border-radius: 6px; cursor: pointer; flex: 1; }
.tab.active { background: var(--surface-3); color: var(--text-primary); }
.tab:hover:not(.active) { color: var(--text-primary); }

.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th { text-align: left; color: var(--text-muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--baseline); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table td { padding: 7px 8px; border-bottom: 1px solid var(--gridline); font-variant-numeric: tabular-nums; }

.legend { display: flex; gap: 14px; margin-bottom: 10px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

.bar-chart { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 60px; align-items: center; gap: 8px; }
.bar-row-label { font-size: 11.5px; color: var(--text-secondary); }
.bar-track { position: relative; height: 18px; }
.bar-fill { position: absolute; top: 3px; height: 12px; border-radius: 4px; }
.bar-row-value { font-size: 11.5px; color: var(--text-secondary); font-variant-numeric: tabular-nums; text-align: right; }

.line-chart-wrap { position: relative; }
.line-chart { width: 100%; height: 180px; display: block; overflow: visible; }
.chart-tooltip {
  position: absolute; background: var(--surface-2); border: 1px solid var(--border-hairline);
  border-radius: 6px; padding: 8px 10px; font-size: 11.5px; pointer-events: none;
  transform: translate(-50%, -110%); white-space: nowrap; z-index: 5;
}
.chart-tooltip .tt-date { color: var(--text-muted); margin-bottom: 4px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.chart-tooltip .tt-swatch { width: 8px; height: 8px; border-radius: 2px; }

.chart-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 12.5px;
}
/* Same message, used inline (no positioned ancestor) inside the non-relative bar-chart box. */
.bar-chart .chart-empty { position: static; padding: 10px 0; }
