/* ═══════════════════════════════════════════════════════════════════
   Semantic Memory Dashboard — Sidebar Layout
   Typography: system UI + monospace stack (no external CSS — CSP style-src 'self')
   ═══════════════════════════════════════════════════════════════════ */

/* ── Variables ──────────────────────────────────────────────────── */
:root {
  --bg:              #0c0e14;
  --surface-0:       #10131b;
  --surface-1:       #161a25;
  --surface-2:       #1c2130;
  --surface-3:       #242a3b;
  --border:          #2a3149;
  --border-subtle:   #1f2640;
  --border-accent:   #3d4f7a;

  --text:            #e4e8f1;
  --text-secondary:  #9ba4bf;
  --text-muted:      #6b7394;
  --text-dim:        #4a5270;

  --teal:    #36d8b7;
  --teal-dim:   rgba(54,216,183,0.12);
  --blue:    #5b8af5;
  --blue-dim:   rgba(91,138,245,0.12);
  --violet:  #9b7aff;
  --violet-dim: rgba(155,122,255,0.12);
  --amber:   #f5a623;
  --amber-dim:  rgba(245,166,35,0.12);
  --coral:   #f56565;
  --coral-dim:  rgba(245,101,101,0.12);
  --green:   #48bb78;
  --green-dim:  rgba(72,187,120,0.12);

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

  --font-ui:   system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;

  --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --sidebar-w: 220px;
  --topbar-h:  52px;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

a { color: var(--teal); text-decoration: none; }

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

/* ── Sidebar ────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface-0);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  transition: transform 0.25s var(--ease-out);
  z-index: 50;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-brain {
  font-size: 24px;
  line-height: 1;
  flex-shrink: 0;
}

.sidebar-title-block {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.sidebar-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.sidebar-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ── Sidebar Nav ────────────────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}

.sidebar-nav::-webkit-scrollbar { display: none; }

/* Visual grouping: 5 sections (Pulse / Knowledge / Quality / Operations / Tools)
   each with a small uppercase label header. URL hashes still target the original 9 pages. */
.nav-section {
  padding: 6px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.nav-section:last-child { border-bottom: none; }
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 4px 18px;
  font-family: var(--font-mono);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all 0.18s var(--ease-out);
  position: relative;
}

.nav-subitem {
  padding-left: 34px;
  font-size: 12px;
  color: var(--text-dim);
}
.nav-subitem .nav-icon { font-size: 11px; }

.nav-item:hover {
  color: var(--text-secondary);
  background: rgba(255,255,255,0.03);
}

.nav-item.active {
  color: var(--teal);
  background: var(--teal-dim);
  border-left-color: var(--teal);
}

.nav-icon {
  font-size: 12px;
  opacity: 0.6;
  flex-shrink: 0;
}

.nav-item.active .nav-icon {
  opacity: 1;
}

/* ── Sidebar Footer ─────────────────────────────────────────────── */
.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px rgba(72,187,120,0.5);
  animation: pulse-dot 2.5s ease infinite;
  flex-shrink: 0;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 4px rgba(72,187,120,0.3); }
  50%       { box-shadow: 0 0 12px rgba(72,187,120,0.6); }
}

.status-text {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.sidebar-last-refresh {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-dim);
}

.refresh-btn {
  margin-top: 6px;
  width: 100%;
  padding: 6px 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.refresh-btn:hover { background: var(--surface-3); color: var(--text); }
.refresh-btn:disabled { opacity: 0.5; cursor: wait; }

/* ── Content Area ───────────────────────────────────────────────── */
.content-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Topbar ─────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  background: rgba(16,19,27,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  z-index: 40;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
}

.hamburger:hover { color: var(--text); }

.page-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
  flex: 1;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ctrl-select,
.ctrl-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font-ui);
  font-weight: 500;
  transition: all 0.2s var(--ease-out);
  outline: none;
  height: 32px;
}

.ctrl-select { font-family: var(--font-mono); }

.ctrl-select:hover,
.ctrl-btn:hover {
  background: var(--surface-3);
  border-color: var(--border-accent);
  color: var(--text);
}

/* ── Topbar lookback (global time scope) ───────────────────────── */
.topbar-lookback {
  display: inline-flex;
  align-items: center;
  gap: 0;
  height: 32px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.topbar-lookback-label {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 10px 0 6px;
  border-right: 1px solid var(--border-subtle);
  align-self: stretch;
  display: inline-flex;
  align-items: center;
}
.topbar-lookback-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 0 12px;
  height: 26px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}
.topbar-lookback-btn:hover { color: var(--text); }
.topbar-lookback-btn.active {
  background: var(--teal-dim);
  color: var(--teal);
}

/* ── Page Content ───────────────────────────────────────────────── */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.page-content::-webkit-scrollbar { width: 6px; }
.page-content::-webkit-scrollbar-track { background: transparent; }
.page-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.page-content::-webkit-scrollbar-thumb:hover { background: var(--border-accent); }

/* ── Page fade-in ───────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page-fade {
  animation: fadeIn 0.28s var(--ease-out);
}

/* ── Section ────────────────────────────────────────────────────── */
.section {
  margin-bottom: 28px;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

/* ── KPI Grid ───────────────────────────────────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: all 0.22s var(--ease-out);
  position: relative;
  overflow: hidden;
  cursor: default;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  opacity: 0;
  transition: opacity 0.22s;
}

.kpi-card:hover {
  border-color: var(--border);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.kpi-card:hover::before { opacity: 1; }

.kpi-card .label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-bottom: 8px;
}

.kpi-card .value {
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--text);
}

.kpi-card .sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 5px;
  font-family: var(--font-mono);
}

/* Color variants */
.kpi-card.green  .value { color: var(--green);  }
.kpi-card.green::before  { background: var(--green);  }
.kpi-card.amber  .value { color: var(--amber);  }
.kpi-card.amber::before  { background: var(--amber);  }
.kpi-card.red    .value { color: var(--coral);  }
.kpi-card.red::before    { background: var(--coral);  }
.kpi-card.blue   .value { color: var(--blue);   }
.kpi-card.blue::before   { background: var(--blue);   }
.kpi-card.purple .value { color: var(--violet); }
.kpi-card.purple::before { background: var(--violet); }
.kpi-card.accent .value { color: var(--teal);   }
.kpi-card.accent::before { background: var(--teal);   }
.kpi-card.accent2 .value { color: var(--blue);  }
.kpi-card.accent2::before { background: var(--blue);  }

/* Anomaly states */
@keyframes anomaly-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245,101,101,0); }
  50%       { box-shadow: 0 0 20px 2px rgba(245,101,101,0.15); }
}

.kpi-card.anomaly {
  animation: anomaly-pulse 2.5s ease infinite;
  border-color: var(--coral);
}
.kpi-card.anomaly .value { color: var(--coral); }
.kpi-card.anomaly::before { background: var(--coral); opacity: 1; }

.kpi-card.anomaly-warn { border-color: var(--amber); }
.kpi-card.anomaly-warn .value { color: var(--amber); }
.kpi-card.anomaly-warn::before { background: var(--amber); opacity: 1; }

/* ── Chart Grid ─────────────────────────────────────────────────── */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.chart-grid.two-col { grid-template-columns: repeat(2, 1fr); }
.chart-grid.three-col { grid-template-columns: repeat(3, 1fr); }
.chart-grid.full { grid-template-columns: 1fr; }

.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: border-color 0.2s;
}

.chart-card:hover { border-color: var(--border); }

.chart-card h3 {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chart-card canvas { max-height: 260px; }

/* ── Table Card ─────────────────────────────────────────────────── */
.table-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  overflow-x: auto;
}

.table-card h3 {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Collapsible (details/summary) ──────────────────────────────── */
details.table-card > summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
}

details.table-card > summary::-webkit-details-marker { display: none; }

details.table-card > summary h3 {
  margin-bottom: 0;
}

details.table-card > summary h3::before {
  content: '';
  width: 0; height: 0;
  border-left: 5px solid var(--text-muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.2s var(--ease-out);
}

details.table-card[open] > summary h3::before {
  transform: rotate(90deg);
}

details.table-card[open] > summary h3 {
  margin-bottom: 14px;
}

/* ── Tables ─────────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: auto;
}

th, td { white-space: nowrap; }

th {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--font-mono);
}

td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13px;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.015); }

td.col-expand, td.col-expand-sm, td.col-expand-lg {
  white-space: nowrap;
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

td.col-expand     { width: 50%; }
td.col-expand-sm  { width: 30%; }
td.col-expand-lg  { width: 70%; }

td.col-expand:hover, td.col-expand-sm:hover, td.col-expand-lg:hover {
  color: var(--teal);
}

#tableSyncCheckpoints code {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
}
#tableSyncCheckpoints code:hover { color: var(--teal); }

/* ── Table Search ───────────────────────────────────────────────── */
.table-search {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-ui);
  margin-bottom: 12px;
  width: 100%;
  max-width: 400px;
  outline: none;
  transition: border-color 0.2s;
}

.table-search:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-dim);
}

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

/* ── Alert Banner ───────────────────────────────────────────────── */
.alert-banner {
  margin-bottom: 20px;
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 13px;
  margin-bottom: 8px;
}

.alert:last-child { margin-bottom: 0; }

.alert.alert-ok     { background: var(--green-dim);  border-color: rgba(72,187,120,0.25);  color: var(--green); }
.alert.alert-info   { background: var(--blue-dim);   border-color: rgba(91,138,245,0.25);  color: var(--blue);  }
.alert.alert-warn   { background: var(--amber-dim);  border-color: rgba(245,166,35,0.25);  color: var(--amber); }
.alert.alert-crit   { background: var(--coral-dim);  border-color: rgba(245,101,101,0.25); color: var(--coral); }

.alert-icon { font-size: 14px; flex-shrink: 0; }

/* ── Quality Windows ────────────────────────────────────────────── */
.quality-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.quality-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: all 0.2s var(--ease-out);
}

.quality-card:hover { border-color: var(--border); }

.quality-card h4 {
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--teal);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.quality-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 12px;
}

.quality-row .qlabel { color: var(--text-muted); }
.quality-row span:last-child {
  font-family: var(--font-mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* ── Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge.green  { background: var(--green-dim);  color: var(--green);  }
.badge.red    { background: var(--coral-dim);  color: var(--coral);  }
.badge.amber  { background: var(--amber-dim);  color: var(--amber);  }
.badge.blue   { background: var(--blue-dim);   color: var(--blue);   }
.badge.purple { background: var(--violet-dim); color: var(--violet); }
.badge.gray   { background: rgba(107,115,148,0.12); color: var(--text-muted); }
.badge.accent { background: var(--teal-dim);   color: var(--teal);   }
.badge.accent2 { background: var(--blue-dim);  color: var(--blue);   }
.badge.orange { background: var(--amber-dim);  color: var(--amber);  }

/* ── Log Count Badge ────────────────────────────────────────────── */
.log-count {
  font-size: 11px;
  font-weight: 500;
  font-family: var(--font-mono);
  color: var(--teal);
}

/* ── Export Buttons ─────────────────────────────────────────────── */
.export-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: 6px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: all 0.15s;
}

.export-btn:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-accent);
}

/* ── Feature Buttons ────────────────────────────────────────────── */
.feature-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font-ui);
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.2s var(--ease-out);
  flex: 1;
  min-width: 140px;
}

.feature-btn:hover {
  background: var(--surface-3);
  transform: translateY(-1px);
}

.feature-btn-label { font-weight: 600; }
.feature-btn-count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ── Learning Profile ───────────────────────────────────────────── */
.profile-section {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
}

.profile-section h3 {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.weight-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 0;
  font-size: 12px;
}

.wb-label {
  flex: 0 0 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
}

.wb-label:hover { color: var(--text-secondary); }

.wb-label.clickable { color: var(--teal); }
.wb-label.clickable:hover { text-decoration: underline; color: var(--blue); }

.wb-bar {
  flex: 1;
  height: 13px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}

.wb-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s var(--ease-out);
}

.wb-value {
  flex: 0 0 55px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}

/* ── Modal ──────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
  animation: fadeIn 0.2s var(--ease-out);
}

#loginModal { z-index: 300; }

.modal {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 720px;
  width: 90%;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 2px 8px;
  line-height: 1;
  border-radius: 4px;
  transition: all 0.15s;
}

.close-btn:hover { color: var(--text); background: var(--surface-2); }

.modal-body {
  padding: 18px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.6;
}

.modal-body .detail-row {
  display: flex;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-body .detail-label {
  flex: 0 0 110px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.modal-body .detail-value {
  flex: 1;
  word-break: break-all;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
}

.modal-body .detail-value:hover { color: var(--teal); }

.modal-body .chunk-text {
  margin-top: 12px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 12px;
  max-height: 280px;
  overflow-y: auto;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  transition: border-color 0.15s;
}

.modal-body .chunk-text:hover { border-color: var(--teal); }

/* ── Loading / Empty ────────────────────────────────────────────── */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 13px;
}

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

/* ── Copy Toast ─────────────────────────────────────────────────── */
.copy-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--teal);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  z-index: 9999;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.22s var(--ease-out);
  pointer-events: none;
  box-shadow: 0 8px 28px rgba(54,216,183,0.25);
}

.copy-toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ── Playground ─────────────────────────────────────────────────── */
.playground-controls {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.playground-textarea {
  flex: 1;
  min-width: 280px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 13px;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

.playground-textarea:focus { border-color: var(--teal); }

.playground-sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 180px;
}

.topk-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topk-label {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

.topk-val {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 20px;
  font-family: var(--font-mono);
}

.run-btn {
  background: var(--teal);
  color: var(--bg);
  border: 1px solid var(--teal);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font-ui);
  font-weight: 700;
  transition: all 0.2s var(--ease-out);
}

.run-btn:hover { filter: brightness(1.1); }

/* ── Entity Explorer search ──────────────────────────────────────── */
.entity-search-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 14px 0;
}

.entity-search-input {
  flex: 1;
  min-width: 260px;
}

/* ── Scrollbar Styling ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-accent); }

/* ── Selection ──────────────────────────────────────────────────── */
::selection {
  background: rgba(54,216,183,0.25);
  color: var(--text);
}

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .hamburger { display: block; }

  .content-area { width: 100%; }

  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .chart-grid { grid-template-columns: 1fr !important; }
  .quality-grid { grid-template-columns: 1fr; }
  .playground-controls { flex-direction: column; }
  .page-content { padding: 16px; }
}

/* ── Intelligence tab ─────────────────────────────────────── */

.notification-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.notification-card.past_failure { border-left-color: var(--coral); }
.notification-card.recurring_pattern { border-left-color: var(--amber); }
.notification-card.similar_memory { border-left-color: var(--teal); }

.notification-text {
  flex: 1;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.notification-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

.dismiss-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.dismiss-btn:hover {
  color: var(--text-secondary);
  border-color: var(--text-muted);
}

.level-chip {
  background: none;
  border: 1px solid;
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s;
}
.level-chip:hover { opacity: 0.8; }
.level-chip.active { font-weight: 600; }

.param-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  margin: 8px 0;
}
.param-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
}
.param-item .label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.param-item .value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 2px;
}

.optimizer-btn {
  background: var(--teal);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}
.optimizer-btn:hover { opacity: 0.85; }
.optimizer-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.topic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.topic-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-secondary);
}
.topic-chip .count {
  color: var(--text-muted);
  margin-left: 4px;
}

@media (max-width: 480px) {
  .kpi-row { grid-template-columns: 1fr; }
  .param-grid { grid-template-columns: 1fr; }
}

/* Dream page colors */
.text-coral { color: var(--coral); font-weight: 600; }
.text-purple { color: #9b7aff; font-weight: 600; }

/* ── Tags (inline labels) ──────────────────────────────────────── */
.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  background: var(--surface-3);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

/* ── Hero Metric (Health page) ─────────────────────────────────── */
.hero-metric {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 28px 36px;
  margin-bottom: 24px;
  background: linear-gradient(135deg, var(--surface-1) 0%, var(--surface-0) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}

.hero-metric::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--teal);
  opacity: 0.6;
}

.hero-metric.degraded::before { background: var(--coral); }
.hero-metric.attention::before { background: var(--amber); }

.hero-tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hero-tab {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.hero-tab:hover {
  border-color: var(--text-dim);
  color: var(--text);
}

.hero-tab.active {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--bg);
}

.hero-metric.attention .hero-tab.active {
  background: var(--amber);
  border-color: var(--amber);
}

.hero-metric.degraded .hero-tab.active {
  background: var(--coral);
  border-color: var(--coral);
}

.hero-number {
  font-size: 56px;
  font-weight: 700;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--teal);
}

.hero-metric.degraded .hero-number { color: var(--coral); }
.hero-metric.attention .hero-number { color: var(--amber); }

.hero-detail {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.hero-sub {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.hero-trend {
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-mono);
}

.hero-trend.up { color: var(--green); }
.hero-trend.down { color: var(--coral); }
.hero-trend.flat { color: var(--text-muted); }

/* ── System Pulse Badge ────────────────────────────────────────── */
.pulse-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pulse-badge.healthy {
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid rgba(72,187,120,0.3);
}

.pulse-badge.attention {
  background: var(--amber-dim);
  color: var(--amber);
  border: 1px solid rgba(245,166,35,0.3);
}

.pulse-badge.degraded {
  background: var(--coral-dim);
  color: var(--coral);
  border: 1px solid rgba(245,101,101,0.3);
}

.pulse-dot-inline {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
  animation: pulse-dot 2.5s ease infinite;
}

/* ── Quick Summary Row ─────────────────────────────────────────── */
.quick-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}

.qs-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  font-size: 13px;
}

.qs-icon {
  font-size: 16px;
  flex-shrink: 0;
  opacity: 0.7;
}

.qs-text {
  color: var(--text-secondary);
}

.qs-value {
  margin-left: auto;
  font-family: var(--font-mono);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ── Observability ────────────────────────────────────────────── */
.observability-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

.observability-toolbar label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.obs-meta-inline {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 12px;
}

/* ── Health bar ─────────────────────────────────────────────── */
.obs-health-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
}

.obs-health-banner-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor;
}

.obs-health-banner.obs-health-green   { color: var(--green); background: var(--green-dim); border-color: rgba(72,187,120,0.3); }
.obs-health-banner.obs-health-yellow  { color: var(--amber); background: var(--amber-dim); border-color: rgba(245,166,35,0.3); }
.obs-health-banner.obs-health-red     { color: var(--coral); background: var(--coral-dim); border-color: rgba(245,101,101,0.4); }

.obs-health-banner-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.obs-health-banner-link:hover { text-decoration-thickness: 2px; }

.obs-health-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}

.obs-health-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  text-decoration: none;
  color: inherit;
  transition: transform 0.1s ease, border-color 0.1s ease;
}

.obs-health-chip:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
}

.obs-health-chip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.obs-health-chip.obs-health-green  .obs-health-chip-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.obs-health-chip.obs-health-yellow .obs-health-chip-dot { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.obs-health-chip.obs-health-red    .obs-health-chip-dot { background: var(--coral); box-shadow: 0 0 6px var(--coral); }

.obs-health-chip.obs-health-yellow { border-color: rgba(245,166,35,0.4); background: rgba(245,166,35,0.04); }
.obs-health-chip.obs-health-red    { border-color: rgba(245,101,101,0.5); background: rgba(245,101,101,0.06); }

.obs-health-chip-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.obs-health-chip-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.obs-health-chip-headline {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 1300px) {
  .obs-health-strip { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 900px) {
  .obs-health-strip { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .obs-health-strip { grid-template-columns: 1fr; }
}

/* ── Activity overview row (top KPIs) ──────────────────────── */
.obs-activity-row {
  margin-bottom: 18px;
}
.obs-activity-row .kpi-row {
  margin: 0;
}

/* ── Section card with status indicator ─────────────────────── */
.obs-card {
  position: relative;
  margin-bottom: 14px;
}

.obs-card[data-status="yellow"] > summary::before {
  content: '';
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 3px;
  background: var(--amber);
  border-radius: 2px;
}

.obs-card[data-status="red"] > summary::before {
  content: '';
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 3px;
  background: var(--coral);
  border-radius: 2px;
}

.obs-card > summary {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.obs-card-subtitle {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: normal;
}

.obs-card-body {
  padding-top: 8px;
}

.obs-pre {
  margin: 0;
  padding: 12px 14px;
  max-height: 420px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-secondary);
  background: var(--surface-0);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  word-break: break-word;
}

.obs-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.obs-section {
  margin-bottom: 10px;
}

.obs-section > summary h3 {
  margin: 0;
}

.obs-kpi-row {
  margin-bottom: 10px;
}

.obs-subcard {
  margin: 12px 0 16px;
  padding: 0 0 4px;
  border-bottom: 1px solid var(--border-subtle);
}

.obs-subcard:last-child {
  border-bottom: none;
}

.obs-h4 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.obs-empty {
  font-size: 12px;
  color: var(--text-dim);
  margin: 8px 0;
}

.obs-inline-note {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.45;
  margin: 8px 0 12px;
}

.obs-file-list {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 12px;
  color: var(--text-secondary);
  max-height: 200px;
  overflow: auto;
}

.obs-file-list li {
  margin: 2px 0;
}

.obs-schema-table {
  margin: 8px 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  background: var(--surface-0);
}

.obs-drift-mini {
  width: 100%;
  font-size: 11px;
  border-collapse: collapse;
}

.obs-drift-mini th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 500;
  width: 140px;
  vertical-align: top;
  padding: 4px 8px 4px 0;
}

.obs-drift-mini td {
  padding: 4px 0;
  color: var(--text-secondary);
}

.obs-json-fallback {
  margin-top: 20px;
}

.obs-json-fallback summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
