/* ── Keytag Design System ───────────────────────────────────────────────── */
:root {
  /* Depth planes */
  --bg:           #120F28;
  --sidebar:      #171432;
  --surface:      #1B1738;
  --surface-2:    #241F49;
  --surface-3:    #2E2857;

  /* Borders */
  --border:       #332A5E;
  --border-light: #453C7D;

  /* Text */
  --text:         #F2EEFC;
  --text-muted:   #8F87B8;
  --text-dim:     #5A5289;

  /* Keytag brand — warm gradient on navy */
  --accent-orange: #F5821F;
  --accent-pink:   #E8388C;
  --accent:        #F5821F;
  --accent-light:  #FF9D4D;
  --accent-glow:   rgba(245, 130, 31, 0.20);
  --accent-glow2:  rgba(245, 130, 31, 0.09);
  --accent-gradient: linear-gradient(135deg, #F5821F 0%, #EF3E6E 55%, #E8388C 100%);
  --accent-text-gradient: linear-gradient(90deg, #F5821F 0%, #EF3E6E 50%, #E8388C 100%);
  --accent-shadow: rgba(245, 130, 31, 0.32);

  /* Graph node palette (entity legend — kept distinct from brand accent) */
  --node-blue:    #4E9FE5;
  --node-green:   #3DB87A;
  --node-red:     #E5534B;
  --node-gold:    #D4A843;
  --node-purple:  #9470E8;
  --node-indigo:  #4A6FD4;
  --node-amber:   #D4773A;
  --node-gray:    #6B8097;

  --radius:    6px;
  --radius-sm: 4px;
  --radius-lg: 10px;

  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", ui-monospace, monospace;

  --sidebar-edge: linear-gradient(to bottom, transparent 5%, var(--accent-orange) 35%, var(--accent-pink) 65%, transparent 95%);
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ──────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
#sidebar {
  width: 224px;
  min-width: 224px;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 0 16px;
  position: relative;
}

#sidebar::after {
  content: "";
  position: absolute;
  top: 0; right: 0;
  width: 1px;
  height: 100%;
  background: var(--sidebar-edge);
  opacity: 0.35;
  pointer-events: none;
}

/* ── Logo — two-line brand lockup ───────────────────────────────────────── */
.logo {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
  text-decoration: none;
}

.logo-mark {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
  background: var(--accent-text-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.logo-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.logo-app {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
  line-height: 1.1;
}

.logo-company {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  line-height: 1;
}

/* ── Identity badge — "who am I signed in as", distinct from the data-scope
   selectors below (which user/project's data to view) ───────────────────── */
#identity-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: calc(100% - 28px);
  margin: 4px 14px 6px;
  padding: 6px 10px;
  background: var(--accent-glow2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent-light);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
#identity-badge:hover { background: var(--accent-glow); }
#identity-badge:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 1px; }
#identity-badge[aria-expanded="true"] .nav-chev { transform: rotate(0deg); }
#identity-badge .nav-chev { transform: rotate(-90deg); }

#account-menu { display: flex; flex-direction: column; margin-bottom: 4px; }

/* ── Project / user selectors — project nests visually under user ───────── */
#user-selector { padding: 8px 10px 3px; }

#project-selector {
  padding: 3px 10px 8px 24px;
  position: relative;
}

/* Tree connector: signals "this project belongs to the user above" */
#project-selector::before {
  content: "";
  position: absolute;
  left: 16px;
  top: -3px;
  width: 8px;
  height: 15px;
  border-left: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
  border-radius: 0 0 0 5px;
}

.project-label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  padding: 5px 9px;
}

#project-selector select,
#user-selector select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 5px 28px 5px 9px;
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235B7899' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

#project-selector select:focus,
#user-selector select:focus { outline: none; border-color: var(--accent); }

/* ── Navigation ─────────────────────────────────────────────────────────── */
nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 8px;
  flex: 1;
}

/* ── Nav groups ─────────────────────────────────────────────────────────────
   Related panels are grouped so the sidebar reads as a few subjects rather
   than one flat list of ten. Groups collapse; the chevron rotates rather than
   swapping glyphs so the control stays in place while it animates. */
.nav-group { display: flex; flex-direction: column; margin-bottom: 2px; }

.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 7px 11px 5px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  text-align: left;
  cursor: pointer;
}
.nav-group-toggle:hover { color: var(--text-muted); }
.nav-group-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--radius); }

.nav-chev {
  display: inline-block;
  font-size: 9px;
  line-height: 1;
  transition: transform .15s ease;
}
.nav-group.is-collapsed .nav-chev { transform: rotate(-90deg); }

.nav-group-items {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}
.nav-group.is-collapsed .nav-group-items { display: none; }

/* Grouped items indent under their header; standalone items keep the original
   alignment so they read as peers of the group headers, not orphaned children. */
.nav-group-items .nav-btn { padding-left: 20px; }
.nav-btn-standalone { margin-top: 2px; }

@media (prefers-reduced-motion: reduce) {
  .nav-chev { transition: none; }
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  text-align: left;
  transition: color 0.12s, background 0.12s;
  position: relative;
  letter-spacing: -0.005em;
}

.nav-btn .nav-icon {
  font-size: 14px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  opacity: 0.75;
}

.nav-btn:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text);
}

.nav-btn:hover .nav-icon { opacity: 1; }

/* Signature: graph edge from left to the selected node */
.nav-btn.active {
  color: var(--text);
  background: linear-gradient(90deg, var(--accent-glow) 0%, var(--accent-glow2) 65%, transparent 100%);
  font-weight: 500;
}

.nav-btn.active .nav-icon { opacity: 1; color: var(--accent-light); }

.nav-btn.active::before {
  content: "";
  position: absolute;
  left: 0; top: 5px; bottom: 5px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--accent-light);
  box-shadow: 0 0 10px var(--accent);
}

/* ── Stats bar ──────────────────────────────────────────────────────────── */
#stats-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.stat {
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 9px 4px;
}

.stat span {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat label {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-top: 1px;
}

/* ── Node detail panel ──────────────────────────────────────────────────── */
#node-detail {
  margin: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 13px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

#node-detail.hidden { display: none; }

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

#detail-label-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  background: var(--badge-color, var(--accent));
  color: #fff;
}

#btn-close-detail {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 5px;
  border-radius: var(--radius-sm);
  line-height: 1;
}

#btn-close-detail:hover { color: var(--text); background: var(--surface-3); }

#node-detail h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}

#detail-props {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 10px;
}

#detail-props dt {
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  align-self: start;
  padding-top: 1px;
}

#detail-props dd { color: var(--text-muted); word-break: break-all; font-size: 11px; }

#detail-actions {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#detail-actions button {
  width: 100%;
  padding: 5px 9px;
  background: var(--surface-3);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font);
  text-align: left;
  transition: color 0.12s, border-color 0.12s;
}

#detail-actions button:hover { color: var(--text); border-color: var(--accent); }

/* ── Main content area ──────────────────────────────────────────────────── */
#content {
  flex: 1;
  overflow: hidden;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

/* ── Topbar ─────────────────────────────────────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 42px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}

#topbar-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

#topbar-end { display: flex; align-items: center; gap: 10px; }

#topbar-project-label {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Panel ──────────────────────────────────────────────────────────────── */
.panel { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.panel.active { display: flex; }
.hidden { display: none !important; }

/* ── Login screen ───────────────────────────────────────────────────────── */
#login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 100;
}
.login-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  width: 320px;
  padding: 32px 28px;
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
.login-card .logo { align-self: center; margin-bottom: 4px; }
.login-card h2 { margin: 0; font-size: 17px; color: var(--text); text-align: center; }
.login-card .panel-sub { margin: 0 0 4px; text-align: center; }
#login-key-input {
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
}
#login-key-input:focus { outline: none; border-color: var(--accent); }
#login-key-input::placeholder { color: var(--text-dim); }
.login-card .action-btn { justify-content: center; }
.login-error { margin: 0; font-size: 12px; color: var(--node-red); text-align: center; }
.login-hint { margin: 4px 0 0; font-size: 11px; color: var(--text-dim); text-align: center; }
.login-hint code { font-family: var(--font-mono); color: var(--text-muted); }

#btn-logout, #btn-copy-init-script {
  margin: 0 14px 6px;
  padding: 6px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  display: block;
  width: calc(100% - 28px);
  text-align: left;
}
#btn-logout:hover { color: var(--node-red); border-color: var(--node-red); }
#btn-copy-init-script:hover { color: var(--accent-light); border-color: var(--accent); }

/* ── Admin panel ────────────────────────────────────────────────────────── */
.admin-inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 20px 10px;
}
.admin-inline-form input[type="text"] {
  flex: 1;
  max-width: 240px;
  padding: 7px 10px;
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
}
.admin-inline-form select {
  padding: 7px 10px;
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
}
.admin-inline-form input:focus, .admin-inline-form select:focus { outline: none; border-color: var(--accent); }

.date-filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 20px 14px;
  padding: 10px 14px;
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.date-filter-bar label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}
.date-filter-bar input[type="date"] {
  padding: 5px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  color-scheme: dark;
}
.date-filter-bar input[type="date"]:focus { outline: none; border-color: var(--accent); }

/* Sessions panel keeps the same calendar filter, just docked into the panel
   header's top-right corner (the header is already a space-between flex
   row) instead of its own full-width bar above the list. */
.date-filter-bar--inline { margin: 0; padding: 6px 10px; gap: 8px; background: transparent; border-color: var(--border); }
.date-filter-bar--inline label { font-size: 11px; }
.date-filter-bar--inline input[type="date"] { padding: 3px 6px; font-size: 11px; }

#admin-users-table select.admin-role-select {
  padding: 4px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
}
#admin-new-key-banner {
  margin: 0 20px 16px;
  padding: 12px 16px;
  background: rgba(245, 130, 31, 0.08);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
}
#admin-new-key-banner code {
  display: inline-block;
  margin: 0 8px;
  padding: 2px 8px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  color: var(--accent-light);
}
#admin-new-key-banner .login-hint { text-align: left; margin-top: 6px; }

/* ── Panel header ───────────────────────────────────────────────────────── */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 20px 13px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

.panel-sub {
  width: 100%;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: -4px;
  line-height: 1.5;
}

.panel-subheading {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  padding: 16px 20px 8px;
}

.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 8px;
}
.admin-section-header .panel-subheading { padding: 0; }
.admin-section-header input[type="text"] {
  padding: 6px 10px;
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  width: 200px;
}
.admin-section-header input[type="text"]:focus { outline: none; border-color: var(--accent); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
button { font-family: var(--font); }

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 15px;
  background: var(--accent-gradient);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  letter-spacing: -0.005em;
}

.action-btn:hover {
  opacity: 0.9;
  box-shadow: 0 4px 16px var(--accent-shadow);
}

.action-btn-sm {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  background: var(--surface-3);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
  white-space: nowrap;
}

.action-btn-sm:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-glow2);
}

.btn-group { display: flex; align-items: center; gap: 6px; }

/* ── Graph panel ────────────────────────────────────────────────────────── */
#panel-graph { position: relative; }

#graph-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.graph-meta {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  margin-right: 4px;
  padding-right: 9px;
  border-right: 1px solid var(--border);
}

/* Row of relationship-type chips, directly under the toolbar */
#edge-legend {
  padding: 6px 12px;
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#edge-legend:empty { display: none; }

#graph-toolbar button {
  padding: 5px 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font);
  transition: color 0.12s, border-color 0.12s, background 0.12s;
  white-space: nowrap;
  letter-spacing: -0.005em;
}

#graph-toolbar button:hover {
  color: var(--text);
  border-color: var(--border-light);
  background: rgba(255,255,255,0.07);
}

#graph-search {
  padding: 5px 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  width: 180px;
}

#graph-search:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-2);
}

#graph-search::placeholder { color: var(--text-dim); }

/* ── Filter chips ───────────────────────────────────────────────────────── */
.filter-chips { display: flex; gap: 4px; flex-wrap: wrap; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid color-mix(in srgb, var(--chip-color, var(--border)) 40%, transparent);
  background: transparent;
  color: color-mix(in srgb, var(--chip-color, var(--text-muted)) 70%, var(--text-muted));
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  font-family: var(--font);
  letter-spacing: 0.01em;
}

.chip.active {
  background: color-mix(in srgb, var(--chip-color, var(--accent)) 12%, transparent);
  border-color: color-mix(in srgb, var(--chip-color, var(--accent)) 60%, transparent);
  color: var(--chip-color, var(--text));
}

.chip::before { content: "●"; font-size: 7px; opacity: 0.8; }

/* ── Cytoscape canvas ───────────────────────────────────────────────────── */
#cy { flex: 1; background: var(--bg); min-height: 0; }

/* ── Graph legend ───────────────────────────────────────────────────────── */
#graph-legend {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  background: rgba(7, 11, 20, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 9px 13px;
  max-width: 340px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.legend-item {
  font-size: 11px;
  font-weight: 500;
  color: var(--c, var(--text-muted));
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

#graph-cap-warn {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(212, 168, 67, 0.1);
  border: 1px solid var(--node-gold);
  color: var(--node-gold);
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 12px;
  z-index: 10;
}

/* ── Search panel ───────────────────────────────────────────────────────── */
#panel-search { overflow-y: auto; padding-bottom: 24px; }

.search-box { display: flex; gap: 8px; padding: 16px 20px; }

.search-box input {
  flex: 1;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  transition: border-color 0.12s, background 0.12s;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-3);
  box-shadow: 0 0 0 3px var(--accent-glow2);
}

.search-box input::placeholder { color: var(--text-dim); }

.search-box button {
  padding: 10px 18px;
  background: var(--accent-gradient);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  transition: opacity 0.15s;
  white-space: nowrap;
}

.search-box button:hover { opacity: 0.88; }

#search-filters {
  display: flex;
  gap: 16px;
  padding: 0 20px 14px;
}

#search-filters label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}

#search-filters input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; }

#search-results { padding: 0 20px; }

.search-result-item {
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 8px;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}

.search-result-item:hover {
  border-color: var(--accent);
  background: var(--surface-3);
  box-shadow: 0 0 0 1px var(--accent-glow2);
}

.search-result-item .result-kind {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-light);
  margin-bottom: 3px;
}

.search-result-item .result-name {
  font-weight: 600;
  color: var(--text);
  font-size: 13px;
  letter-spacing: -0.01em;
}

.search-result-item .result-path {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 3px;
}

.search-result-item .result-score { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

/* ── Prose content ──────────────────────────────────────────────────────── */
.prose-content {
  flex: 1;
  overflow-y: auto;
  padding: 22px 26px;
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
}

.prose-content h1,
.prose-content h2,
.prose-content h3,
.prose-content h4 {
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 1.6em 0 0.5em;
  line-height: 1.25;
}

.prose-content h1 { font-size: 22px; }
.prose-content h2 { font-size: 17px; border-bottom: 1px solid var(--border); padding-bottom: 7px; }
.prose-content h3 { font-size: 15px; }
.prose-content h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); font-weight: 600; }

.prose-content p { margin: 0.75em 0; }
.prose-content ul, .prose-content ol { padding-left: 1.5em; margin: 0.5em 0; }
.prose-content li { margin: 0.3em 0; }

.prose-content code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  color: var(--accent-light);
}

.prose-content pre {
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  overflow-x: auto;
  margin: 1.1em 0;
}

.prose-content pre code { background: none; border: none; padding: 0; font-size: 12px; color: var(--text); }

.prose-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 1em 0;
  padding: 0.6em 1em;
  color: var(--text-muted);
  background: var(--accent-glow2);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.prose-content table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 1em 0; }

.prose-content th {
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 8px 13px;
  text-align: left;
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.prose-content td { border: 1px solid var(--border); padding: 8px 13px; color: var(--text); }
.prose-content tr:hover td { background: var(--surface-2); }

/* ── Log box ────────────────────────────────────────────────────────────── */
.log-box {
  margin: 10px 20px;
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  max-height: 140px;
  overflow-y: auto;
  line-height: 1.6;
  flex-shrink: 0;
}

/* ── Tab bar ────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 0;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.tab-btn {
  padding: 10px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  white-space: nowrap;
  transition: color 0.12s, border-color 0.12s;
  margin-bottom: -1px;
  letter-spacing: -0.005em;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* ── Sessions panel ─────────────────────────────────────────────────────── */
#panel-sessions { overflow: hidden; }

#session-list {
  overflow-y: auto;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-height: 0;
}

/* Sessions panel — connection status + daily usage dashboard */
.connection-status {
  margin: 0 20px 4px;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  gap: 12px;
}

.connection-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
  background: var(--node-gray);
  box-shadow: 0 0 0 3px transparent;
}
.connection-status.is-connected .connection-dot { background: var(--node-green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--node-green) 20%, transparent); }
.connection-status.is-stale .connection-dot     { background: var(--node-amber); box-shadow: 0 0 0 3px color-mix(in srgb, var(--node-amber) 20%, transparent); }
.connection-status.is-none .connection-dot      { background: var(--node-red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--node-red) 20%, transparent); }

.connection-body { display: flex; flex-direction: column; gap: 2px; }
.connection-text { font-size: 13px; font-weight: 600; color: var(--text); }
.connection-detail { font-size: 11px; color: var(--text-muted); }

/* Same amber used for a stale connection — this is the same "needs a look,
   not an error" register, not a new color vocabulary. */
.session-health-banner {
  margin: 0 20px 4px;
  padding: 8px 14px;
  background: color-mix(in srgb, var(--node-amber) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--node-amber) 35%, transparent);
  border-radius: var(--radius);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
}
.session-health-icon { color: var(--node-amber); flex-shrink: 0; }

/*
 * A vertical chart's height is fixed regardless of how many days it shows —
 * unlike the horizontal-rows version this replaced, which grew taller with
 * every day and pushed the date filter and session list past
 * #panel-sessions' clip boundary (overflow: hidden; #session-list is the
 * panel's one flex:1 scrolling region, nothing else in it scrolls). A fixed
 * 15-column chart needs no bound/scrollbar of its own to keep that from
 * happening again.
 */
.daily-usage { padding: 4px 20px 8px; display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }

.daily-usage-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 2px 10px 10px;
  font-size: 11px;
  color: var(--text-muted);
}
.daily-usage-legend-item { display: flex; align-items: center; }
.daily-usage-legend .dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px;
}
.daily-usage-window { margin-left: auto; }

/* A pill group, not a <select> — the whole point is that switching ranges
   should feel as immediate as clicking a day, not open a dropdown. */
.daily-usage-range { display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2px; }
.daily-usage-range-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.daily-usage-range-btn:hover { color: var(--text); }
.daily-usage-range-btn.active { background: var(--accent-gradient); color: #fff; }
.daily-usage-range-btn:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }

/* Which categories size the "Used" segment — independent of the date-range
   pills above, so both controls stay legible as separate groups. */
.daily-usage-category-filter {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px 8px;
  font-size: 11px;
  color: var(--text-muted);
}
.daily-usage-cat-check { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.daily-usage-cat-check input[type="checkbox"] { margin: 0; cursor: pointer; }

.daily-usage-chart {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 152px;
  padding: 0 4px;
}
/* The baseline the bars grow up from — without it, a short bar for a slow
   day and an empty track for a no-activity day are hard to tell apart at a
   glance, since neither has anything to measure itself against. */
.daily-usage-chart::after {
  content: "";
  position: absolute;
  left: 4px; right: 4px; bottom: 26px;
  border-top: 1px solid var(--border);
  pointer-events: none;
}

.daily-usage-col {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  padding: 4px 2px 2px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  position: relative;
}
.daily-usage-col:hover, .daily-usage-col:focus-visible { background: var(--surface-2); }
.daily-usage-col:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; }
/* Today is still accumulating, not a finished day like the rest of the
   window — a quiet tint is enough to say so without a second legend entry. */
.daily-usage-col.is-today { background: var(--accent-glow2); }
.daily-usage-col.is-today .daily-usage-col-label { color: var(--accent-light); font-weight: 700; }

.daily-usage-track {
  width: 100%;
  max-width: 64px;
  height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: var(--surface-3);
  border-radius: 4px 4px 1px 1px;
  overflow: hidden;
}
.bar-seg-vert { width: 100%; flex-shrink: 0; }
/* Four real categories instead of one solid "Used" block, each its own
   color — see the legend dots below for the matching key. */
.bar-seg-vert.bar-input       { background: var(--node-blue); }
.bar-seg-vert.bar-output      { background: var(--node-purple); }
.bar-seg-vert.bar-cache-write { background: var(--accent-pink); }
.bar-seg-vert.bar-cache-read  { background: var(--node-gold); }
.bar-seg-vert.bar-saved       { background: var(--node-green); border-radius: 2px 2px 0 0; }
@media (prefers-reduced-motion: no-preference) {
  .bar-seg-vert { transition: height 320ms cubic-bezier(.2,.8,.2,1); }
}

.daily-usage-col-label {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* A single shared node, repositioned per bar on hover/focus — cheaper than
   one tooltip per column, and lets it render above #panel-sessions' own
   overflow:hidden by living in <body> rather than inside the panel. */
.daily-usage-tooltip {
  position: fixed;
  transform: translate(-50%, calc(-100% - 10px));
  background: var(--surface-3);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-muted);
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  z-index: 500;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
}
@media (prefers-reduced-motion: no-preference) {
  .daily-usage-tooltip { transition: opacity .12s ease; }
}
.daily-usage-tooltip.visible { opacity: 1; visibility: visible; }
.daily-usage-tooltip::after {
  content: "";
  position: absolute;
  top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--surface-3);
}
.daily-usage-tooltip .tt-date { font-weight: 700; color: var(--text); margin-bottom: 2px; }
.daily-usage-tooltip .tt-saved { color: var(--node-green); }
.daily-usage-tooltip .tt-breakdown { color: var(--text-muted); font-size: 10px; }

.daily-usage-hint { font-size: 11px; padding: 6px 10px 0; text-align: right; }

.session-card {
  padding: 11px 15px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-card:hover { border-color: var(--border-light); box-shadow: 0 2px 12px rgba(0,0,0,0.2); }
.session-card.selected { border-color: var(--accent); background: var(--surface-3); box-shadow: 0 0 0 1px var(--accent-glow2); }

.session-card .session-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.session-card .session-id { font-family: var(--font-mono); font-size: 12px; font-weight: 600; color: var(--text); }
.session-card .session-tokens { font-size: 11px; font-weight: 700; color: var(--node-green); white-space: nowrap; font-variant-numeric: tabular-nums; }
.session-card .session-tokens-estimate { font-weight: 400; color: var(--text-dim); font-style: italic; }
.session-card .session-time { font-size: 11px; color: var(--text-muted); }
.session-card .session-scope { font-size: 11px; color: var(--accent-light); }

#session-actions {
  border-top: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px 20px;
  flex-shrink: 0;
  max-height: 40vh;
}

#session-actions h3 {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  margin-bottom: 12px;
}

#actions-timeline { display: flex; flex-direction: column; gap: 3px; }

.action-item {
  display: grid;
  grid-template-columns: 60px auto 1fr auto;
  align-items: baseline;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.action-item:last-child { border-bottom: none; }
.action-item .action-time { font-family: var(--font-mono); font-size: 10px; color: var(--text-dim); }
.action-item .action-type { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent-light); }
.action-item .action-target { color: var(--text-muted); font-family: var(--font-mono); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.action-item .action-tokens { font-size: 10px; color: var(--text-dim); white-space: nowrap; }
.action-item .action-tokens.is-estimate { opacity: .65; font-style: italic; }

/* ── Savings panel ──────────────────────────────────────────────────────── */
#panel-savings { overflow-y: auto; padding-bottom: 8px; }
#panel-admin { overflow-y: auto; padding-bottom: 8px; }
#panel-insights { overflow-y: auto; padding-bottom: 24px; }

.admin-table { margin: 0 20px 10px; }
.admin-table table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th {
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 8px 13px;
  text-align: left;
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}
.admin-table td { border: 1px solid var(--border); padding: 8px 13px; color: var(--text); }
.admin-table tr.admin-user-row:hover td { background: var(--surface-2); cursor: pointer; }
.admin-table code { font-family: var(--font-mono); font-size: 12px; color: var(--accent-light); }

.admin-rate-input {
  width: 72px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 3px 6px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.admin-rate-input:focus { outline: none; border-color: var(--accent); }
.admin-rate-default { font-size: 10px; color: var(--text-muted); margin-top: 2px; font-variant-numeric: tabular-nums; }

.panel-sub-inline { font-size: 12px; font-weight: 400; text-transform: none; letter-spacing: normal; color: var(--text-dim); }

.admin-expand-toggle {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 6px;
}
.admin-expand-toggle:hover { color: var(--accent-light); }

tr.admin-user-detail td { background: var(--sidebar); border-top: none; padding: 0; }
tr.admin-user-detail.hidden { display: none; }
.admin-user-detail-inner { padding: 14px 20px; }
.admin-subtable { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 10px; }
.admin-subtable th {
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  font-weight: 700;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}
.admin-subtable td { border: 1px solid var(--border); padding: 6px 10px; color: var(--text); }
.admin-subtable code { font-family: var(--font-mono); font-size: 11px; color: var(--accent-light); }
.admin-copy-keyid {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  padding: 0 2px;
  vertical-align: middle;
}
.admin-copy-keyid:hover { color: var(--accent-light); }

.admin-status { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
.admin-status-active { color: var(--node-green); background: rgba(61, 184, 122, 0.12); }
.admin-status-inactive { color: var(--text-dim); background: var(--surface-2); }

.admin-remove-user { color: var(--node-red); border-color: var(--node-red); }
.admin-remove-user:hover { color: #fff; background: var(--node-red); }
.admin-detail-form { margin: 0; }

.admin-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 10px 0;
  font-size: 12px;
  color: var(--text-muted);
}
.admin-pagination button {
  padding: 5px 12px;
  background: var(--surface-3);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
}
.admin-pagination button:hover:not(:disabled) { color: var(--text); border-color: var(--accent); }
.admin-pagination button:disabled { opacity: 0.4; cursor: default; }

/* The receipt: one hero number, one honesty meter */
.savings-hero {
  margin: 16px 20px 4px;
  padding: 22px 26px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}

.savings-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 480px 220px at 10% 0%, var(--accent-glow2), transparent 70%);
  pointer-events: none;
}

.hero-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  position: relative;
}

.hero-value {
  display: inline-block;
  margin: 4px 0 16px;
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  background: var(--accent-text-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  position: relative;
}

.hero-meter {
  display: flex;
  height: 6px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface-3);
  position: relative;
}

.meter-seg { height: 100%; }
.meter-seg.meter-hard { background: var(--node-green); }
.meter-seg.meter-estimated { background: var(--accent-orange); }

.hero-meter-legend {
  display: flex;
  gap: 20px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
  position: relative;
}

.hero-meter-legend .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
}

.dot-hard { background: var(--node-green); }
.dot-estimated { background: var(--accent-orange); }

/* ── Team Insights ────────────────────────────────────────────────────────
   No charting library is vendored (and CDN deps are forbidden), so the
   department comparison is built from the same percentage-width flex bar as
   the savings hero meter — just taller, since a 6px bar reads as a hairline
   when stacked a dozen rows deep. */
.meter-seg.meter-spend { background: var(--accent-orange); }
.meter-seg.meter-saved { background: var(--node-green); }
.dot-spend { background: var(--accent-orange); }
.dot-saved { background: var(--node-green); }
.dot-input       { background: var(--node-blue); }
.dot-output      { background: var(--node-purple); }
.dot-cache-write { background: var(--accent-pink); }
.dot-cache-read  { background: var(--node-gold); }

.hero-meter.insight-bar { height: 10px; margin-top: 4px; }

.insight-dept { display: flex; align-items: center; gap: 6px; }

.insight-dept-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0 2px;
  line-height: 1;
}
.insight-dept-toggle:hover { color: var(--accent-orange); }

.insight-bar-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) 3fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 7px 14px;
  flex: 1;
  min-width: 0;
}

.insight-bar-row.is-team {
  padding-left: 42px;
  font-size: 12px;
  opacity: 0.85;
}

.insight-bar-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.insight-cost {
  font-size: 12px;
  font-weight: 700;
  color: var(--node-green);
  font-variant-numeric: tabular-nums;
  min-width: 56px;
  text-align: right;
}

/* A rough estimate must not borrow the solid green weight of a measured
   figure — that color/weight combination is a claim of precision this number
   does not have. */
.insight-cost.is-rough {
  color: var(--accent-light);
  font-weight: 600;
  font-style: italic;
  opacity: .85;
}

/* Department/team manager, collapsed by default so it doesn't crowd the
   admin panel's primary job (keys and roles). */
.admin-org-manager {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 18px;
  background: var(--surface-2);
}
.admin-org-manager > summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.admin-org-manager > summary:hover { color: var(--accent-orange); }
.admin-org-forms { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }

/* Org manager: one grid so a department and its teams keep the same columns,
   with indent applied to the row's leading cell only. */
.admin-org-unit { border-top: 1px solid var(--border); }

.admin-org-row {
  display: grid;
  grid-template-columns: 20px minmax(140px, 1fr) 66px auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 12px;
}
.admin-org-row.is-team { padding-left: 20px; opacity: 0.9; }
.admin-org-name { min-width: 160px; font-weight: 600; }

.admin-org-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  line-height: 1;
}
.admin-org-toggle:hover { color: var(--accent-orange); }
.admin-org-toggle-spacer { display: block; width: 20px; }

/* Editable in place — the field IS the name, so there's no separate edit mode
   to enter and forget to leave. */
.admin-org-input {
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  width: 100%;
  min-width: 0;
}
.admin-org-input:hover { border-color: var(--border-light); }
.admin-org-input:focus { outline: none; border-color: var(--accent-orange); background: var(--surface-3); }
.admin-org-row.is-team .admin-org-input { font-weight: 500; }

.admin-org-count { font-size: 11px; color: var(--text-dim); white-space: nowrap; }
.admin-org-empty { padding: 4px 0 6px 40px; font-size: 11px; }

#admin-users-table select.admin-org-select { max-width: 190px; }

/* ── Cumulative rollup rows (organisation → department → team → user) ──
   One grid so every level's columns line up regardless of indent depth;
   indent is applied to the label cell only, never to the row. */
.insight-head-row,
.insight-row {
  display: grid;
  grid-template-columns: 18px minmax(150px, 1.5fr) 2fr 52px 68px 72px;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
}

.insight-head-row {
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}
.insight-head-row span:nth-child(4),
.insight-head-row span:nth-child(5),
.insight-head-row span:nth-child(6) { text-align: right; }

.insight-row { border-bottom: 1px solid var(--border); }
.insight-row:hover { background: var(--surface-2); }

.insight-row.is-total {
  font-weight: 700;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-light);
}
.insight-row.is-dept .insight-bar-label { font-weight: 600; }
.insight-row.is-team .insight-bar-label { padding-left: 16px; font-size: 12px; opacity: .92; }
.insight-row.is-user .insight-bar-label { padding-left: 32px; font-size: 12px; opacity: .78; }
.insight-row.is-user .hero-meter { opacity: .55; }

.insight-caret-spacer { display: block; width: 18px; }

/* ── Usage per user ─────────────────────────────────────────────────────────
   The table previously inherited no styling at all: headers ran into each
   other, every column was left-aligned, and digits used proportional figures
   so nothing lined up vertically. Numerics are right-aligned with tabular
   figures, which is what makes a column of costs scannable. */
.insight-users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: auto;
}
.insight-users-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  text-align: left;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.insight-users-table th.col-num { text-align: right; }
.insight-users-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.insight-users-table td.col-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.insight-user-row:hover td { background: var(--surface-2); }
.insight-user-row.is-open td { background: var(--surface-2); border-bottom-color: transparent; }

.insight-users-table td.col-user { white-space: nowrap; }
.insight-user-name { font-weight: 600; }
.insight-users-table td.col-user .insight-caret-spacer,
.insight-user-toggle { display: inline-block; vertical-align: middle; margin-right: 7px; }
.insight-user-toggle {
  width: 18px; height: 18px; padding: 0; line-height: 1;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 11px;
}
.insight-user-toggle:hover { color: var(--text); }
.insight-user-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 3px; }

.insight-users-table .org-sep { opacity: .45; }
.insight-users-table td.col-saved { color: var(--node-green); }

/* Cost carries a share-of-max bar behind the figure, so the biggest spender is
   visible without reading every row. */
.insight-users-table td.col-cost { position: relative; font-weight: 700; }
.insight-cost-bar {
  position: absolute; right: 0; top: 6px; bottom: 6px;
  background: var(--accent); opacity: .16; border-radius: 2px;
  pointer-events: none;
}
.insight-cost-val { position: relative; }

/* Per-user model mix, revealed by the caret. */
.insight-user-detail td { padding: 0 14px 12px 14px; background: var(--surface-2); }
.insight-models { display: flex; flex-direction: column; gap: 5px; padding: 4px 0 2px 25px; }
.insight-model-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.4fr) 78px minmax(80px, 2fr) 108px 72px;
  align-items: center;
  gap: 10px;
  font-size: 11px;
}
.insight-model-name { font-family: var(--font-mono); color: var(--text); }
.insight-model-calls,
.insight-model-out { color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.insight-model-bar { height: 5px; }
.insight-model-cost { text-align: right; font-weight: 700; color: var(--node-green); font-variant-numeric: tabular-nums; }

@media (max-width: 900px) {
  .insight-model-row { grid-template-columns: 1fr auto; }
  .insight-model-bar { display: none; }
}

.insight-share {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.insight-row .breakdown-value { text-align: right; font-size: 12px; }
.insight-row .insight-cost { text-align: right; }

/* Secondary tiles */
.savings-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  padding: 14px 20px 4px;
}

.savings-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.12s;
}

.savings-tile:hover { border-color: var(--border-light); }

.savings-tile label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
}

.savings-tile .savings-tile-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Breakdown by category */
#savings-breakdown { padding: 4px 20px 6px; display: flex; flex-direction: column; gap: 6px; }

.breakdown-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.breakdown-row .breakdown-label { flex: 1; font-size: 13px; color: var(--text); }

.tier-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 20px;
  flex-shrink: 0;
}

.tier-badge.tier-hard { background: color-mix(in srgb, var(--node-green) 16%, transparent); color: var(--node-green); }
.tier-badge.tier-estimated { background: var(--accent-glow2); color: var(--accent-light); }

.breakdown-row .breakdown-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 72px;
  text-align: right;
}

/* Top files — a real ranking, so the rank number carries information */
#savings-top-files {
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.savings-file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition: border-color 0.12s;
}

.savings-file-row:hover { border-color: var(--border); }

.file-rank {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  width: 16px;
  flex-shrink: 0;
}

.file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }

.file-path {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-hits { font-size: 10px; color: var(--text-dim); }

.file-tokens {
  font-size: 12px;
  font-weight: 700;
  color: var(--node-green);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* ── Chat panel ─────────────────────────────────────────────────────────── */
#panel-chat { overflow: hidden; }

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.chat-msg {
  max-width: 78%;
  padding: 11px 15px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  line-height: 1.65;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--accent-gradient);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
  box-shadow: 0 4px 14px var(--accent-shadow);
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: var(--radius-sm);
}

.chat-msg.assistant code { font-family: var(--font-mono); font-size: 11px; background: var(--sidebar); border-radius: var(--radius-sm); padding: 1px 5px; color: var(--accent-light); }
.chat-msg.error { align-self: flex-start; background: rgba(229, 83, 75, 0.08); border: 1px solid var(--node-red); color: var(--node-red); }

#chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--sidebar);
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  padding: 10px 13px;
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  resize: none;
  min-height: 40px;
  transition: border-color 0.12s, box-shadow 0.12s;
}

#chat-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow2); }
#chat-input::placeholder { color: var(--text-dim); }

#btn-chat-send {
  padding: 10px 18px;
  background: var(--accent-gradient);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  align-self: flex-end;
  transition: opacity 0.15s, box-shadow 0.15s;
}

#btn-chat-send:hover { opacity: 0.88; box-shadow: 0 4px 14px var(--accent-shadow); }

/* ── Onboarding tour navigator ──────────────────────────────────────────── */
#tour-nav { flex-shrink: 0; border-bottom: 1px solid var(--border); }

.tour-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  gap: 12px;
}

.tour-nav-header button {
  padding: 5px 13px;
  background: var(--surface-3);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  transition: color 0.12s, border-color 0.12s;
}

.tour-nav-header button:hover { color: var(--text); border-color: var(--accent); }
#tour-step-indicator { font-size: 12px; color: var(--text-muted); text-align: center; }
#tour-step-content { padding: 10px 20px 14px; font-size: 13px; color: var(--text-muted); line-height: 1.65; }

/* ── Scrollbars ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ── Status text utilities (containers already carry horizontal padding) ── */
.muted { color: var(--text-muted); font-size: 13px; padding: 4px 0; }
.error { color: var(--node-red); font-size: 13px; padding: 4px 0; }

/* ── Base form elements ─────────────────────────────────────────────────── */
input, select, textarea { color-scheme: dark; }

/* ── Keyboard focus ─────────────────────────────────────────────────────── */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #sidebar { width: 56px; min-width: 56px; }
  .logo-text { display: none; }
  .nav-btn span:not(.nav-icon) { display: none; }
  .nav-btn { justify-content: center; padding: 10px; }
  #stats-bar { display: none; }
  #node-detail { display: none; }
  #topbar-project-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}


/* Archived users stay listed — they must be findable to restore — but must not
   read as active. */
.admin-user-row.is-archived td { opacity: .55; }
.admin-status-archived {
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border-light);
}

/* ── Read scope on the create-key form ──────────────────────────────────────
   Shown only for viewers: a developer's scope follows what they work in and an
   admin is unscoped, so the controls would imply a restriction that isn't real. */
.admin-key-scope {
  margin: 4px 0 14px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.admin-key-scope .panel-sub { margin: 0 0 10px; }
.admin-scope-all { display: flex; align-items: center; gap: 6px; font-size: 12px; margin-bottom: 10px; cursor: pointer; }
.admin-scope-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.admin-scope-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 5px;
}
.admin-scope-list { display: flex; flex-direction: column; gap: 4px; max-height: 132px; overflow-y: auto; }
.admin-scope-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text); cursor: pointer; }
.admin-scope-item.is-filtered-out { display: none; }

/* Search box above a project checklist — a project list grows with the org
   and needs to be findable. Used by the create-key form's Individual
   Projects column. */
.admin-project-filter {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 6px;
  padding: 4px 8px;
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  color: var(--text);
}
.admin-project-filter:focus { outline: none; border-color: var(--accent); }

/* The mix behind a blended savings rate — shown so the figure can be audited
   rather than taken on trust. */
.savings-blend { display: flex; flex-wrap: wrap; gap: 8px 16px; padding: 4px 14px 10px; }
.savings-blend-item { display: flex; align-items: baseline; gap: 6px; font-size: 11px; }
.savings-blend-item code { font-size: 11px; color: var(--text); }
.savings-blend-share { font-weight: 700; color: var(--accent-light); font-variant-numeric: tabular-nums; }

/* ── Project Insights: master → sub-project rollup ─────────────────────────── */
#panel-projects { overflow-y: auto; padding-bottom: 24px; }

.proj-master { margin-bottom: 4px; }
.proj-master.is-ungrouped { opacity: .82; }

.proj-row {
  display: grid;
  grid-template-columns: 22px minmax(140px, 1.4fr) auto minmax(80px, 2fr) 80px 88px;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
}
.proj-row.is-master { background: var(--surface-2); font-weight: 600; }
.proj-row.is-sub { padding-left: 34px; font-size: 12px; }
.proj-row:hover { background: var(--surface-2); }

.proj-toggle {
  width: 18px; height: 18px; padding: 0; line-height: 1;
  background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 11px;
}
.proj-toggle:hover { color: var(--text); }
.proj-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 3px; }

.proj-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-meta { font-size: 11px; white-space: nowrap; }

/* The role a repo plays inside its product — reads as a tag, not a value. */
.proj-label {
  font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 10px; white-space: nowrap;
  background: var(--accent-glow); color: var(--accent-light); border: 1px solid var(--accent);
}

.proj-calls, .proj-cost { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.proj-cost { font-weight: 700; color: var(--node-green); }

.proj-breakdown { padding: 8px 14px 10px 56px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.proj-sub-detail .proj-breakdown { padding-left: 76px; }
.proj-breakdown-title {
  display: block; font-size: 10px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-dim); margin-bottom: 5px;
}
.proj-breakdown-row {
  display: grid; grid-template-columns: minmax(140px, 1fr) 96px 80px;
  gap: 12px; font-size: 11px; padding: 2px 0;
}
.proj-breakdown-key { font-family: var(--font-mono); color: var(--text); }
.proj-breakdown-calls { text-align: right; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.proj-breakdown-cost { text-align: right; font-weight: 700; color: var(--node-green); font-variant-numeric: tabular-nums; }

.proj-master-select, .proj-label-input {
  width: 100%; padding: 4px 7px; font-size: 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}

@media (max-width: 900px) {
  .proj-row { grid-template-columns: 22px 1fr 70px 80px; }
  .proj-row .share-bar, .proj-meta { display: none; }
}

/* ── Share bars: what part took how much ────────────────────────────────────
   A share bar, not a magnitude bar. Each segment is a fraction of ITS OWN row's
   total, so a master shows how its repos split and a repo shows how its people
   split — which is the question actually being asked. Scaling every row against
   the org total instead drew a full-width bar for a master with one paying repo
   and an identical one for that repo: true, and useless. */
.share-bar {
  display: flex;
  height: 10px;
  width: 100%;
  border-radius: 5px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
}
.share-bar.is-empty { opacity: .4; }
.share-seg { display: block; height: 100%; }
.share-seg:not(:last-child) { border-right: 1px solid rgba(0, 0, 0, .28); }

.share-block { padding: 10px 14px 12px 56px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.proj-sub-detail .share-block { padding-left: 76px; }

.share-legend { display: flex; flex-wrap: wrap; gap: 5px 16px; margin-top: 6px; }
.share-legend-item { display: flex; align-items: center; gap: 6px; font-size: 11px; }
.share-swatch { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.share-legend-key { color: var(--text); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-legend-pct { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }

/* ── Donut charts on the Projects panel ─────────────────────────────────────
   Drawn as one stroked circle per slice, offset by the running total. No
   charting library: nothing external loads, and it stays crisp at any size. */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px 24px;
  padding: 14px 14px 16px 56px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.proj-sub-detail .chart-grid { padding-left: 76px; }

.chart-block { min-width: 0; }
.chart-row { display: flex; align-items: center; gap: 14px; margin-top: 8px; }

.donut { width: 104px; height: 104px; flex-shrink: 0; }
.donut.is-empty { opacity: .45; }
.donut-centre {
  text-anchor: middle; font-size: 15px; font-weight: 700;
  fill: var(--text); font-variant-numeric: tabular-nums;
}
.donut-centre-sub { text-anchor: middle; font-size: 10px; fill: var(--text-muted); }

.chart-row .share-legend { flex-direction: column; flex-wrap: nowrap; gap: 4px; margin-top: 0; min-width: 0; }
