/* ── Design Tokens ──────────────────────────────── */
:root {
  color-scheme: light;

  --rail-bg: #ffffff;
  --rail-surface: #f7f8fa;
  --rail-fg: #111827;
  --rail-muted: #8b929e;
  --rail-border: #e8eaed;
  --rail-hover: rgba(0,0,0,.04);
  --rail-active: rgba(226,0,116,.07);

  --bg: #f2f4f7;
  --surface: #ffffff;
  --fg: #111111;
  --muted: #6b7280;
  --border: #e5e5e5;
  --border-strong: #d1d5db;

  --accent: #e20074;
  --accent-dim: rgba(226,0,116,.10);
  --accent-hover: #c8006a;
  --success: #17a34a;
  --success-bg: rgba(23,163,74,.08);
  --warn: #eab308;
  --warn-bg: rgba(234,179,8,.08);
  --danger: #dc2626;
  --danger-bg: rgba(220,38,38,.08);
  --info: #2563eb;
  --info-bg: rgba(37,99,235,.08);

  --font-display: "TeleNeoWeb-Bold", "Inter", -apple-system, sans-serif;
  --font-body: "TeleNeoWeb-Regular", "Inter", -apple-system, sans-serif;
  --font-mono: ui-monospace, "JetBrains Mono", Menlo, monospace;

  --sidebar-w: 240px;
  --topbar-h: 54px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-pill: 9999px;
  --shadow-card: 0 2px 8px rgba(0,0,0,.06), 0 0 0 1px rgba(0,0,0,.04);
}

/* Auto dark: matches system preference unless user chose light explicitly */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --rail-bg: #17181d;
    --rail-surface: #1d1f26;
    --rail-fg: #f5f7fb;
    --rail-muted: #a2a9b8;
    --rail-border: #2a2d35;
    --rail-hover: rgba(255,255,255,.06);
    --rail-active: rgba(226,0,116,.15);

    --bg: #0f1014;
    --surface: #17181d;
    --fg: #f5f7fb;
    --muted: #a2a9b8;
    --border: #2a2d35;
    --border-strong: #3a3d48;

    --success: #22c55e;
    --success-bg: rgba(34,197,94,.10);
    --warn: #facc15;
    --warn-bg: rgba(250,204,21,.10);
    --danger: #f87171;
    --danger-bg: rgba(248,113,113,.10);
  }
}

/* Explicit dark mode (user toggled) */
[data-theme="dark"] {
  color-scheme: dark;
  --rail-bg: #17181d;
  --rail-surface: #1d1f26;
  --rail-fg: #f5f7fb;
  --rail-muted: #a2a9b8;
  --rail-border: #2a2d35;
  --rail-hover: rgba(255,255,255,.06);
  --rail-active: rgba(226,0,116,.15);

  --bg: #0f1014;
  --surface: #17181d;
  --fg: #f5f7fb;
  --muted: #a2a9b8;
  --border: #2a2d35;
  --border-strong: #3a3d48;

  --success: #22c55e;
  --success-bg: rgba(34,197,94,.10);
  --warn: #facc15;
  --warn-bg: rgba(250,204,21,.10);
  --danger: #f87171;
  --danger-bg: rgba(248,113,113,.10);
}

/* Explicit light (overrides auto dark) */
[data-theme="light"] {
  color-scheme: light;
}

/* ── Base Reset ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  height: 100%;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
#root { height: 100%; }

/* ── Utility Classes ────────────────────────────── */
.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}
.status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status.ok   { color: var(--success); background: var(--success-bg); }
.status.ok::before { background: var(--success); }
.status.warn { color: var(--warn); background: var(--warn-bg); }
.status.warn::before { background: var(--warn); }
.status.risk { color: var(--danger); background: var(--danger-bg); }
.status.risk::before { background: var(--danger); }
.status.error { color: var(--danger); background: var(--danger-bg); }
.status.error::before { background: var(--danger); }
.status.info { color: var(--info); background: var(--info-bg); }
.status.info::before { background: var(--info); }

.card {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 16px 18px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-body);
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.sm { height: 30px; font-size: 13px; padding: 0 11px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

/* ── Sidebar ────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--rail-bg);
  border-right: 1px solid var(--rail-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--rail-border);
}
.brand-logo {
  height: 32px;
  width: auto;
  max-width: 48px;
  object-fit: contain;
  flex-shrink: 0;
}
.brand-name { font-size: 15px; font-weight: 700; font-family: var(--font-display); color: var(--rail-fg); }
.brand-sub  { font-size: 12px; color: var(--rail-muted); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }

.nav-group { margin-bottom: 4px; }
.nav-group-label {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--rail-muted);
  padding: 8px 16px 4px;
}

.nav-item {
  display: flex; align-items: center; gap: 9px;
  height: 38px; padding: 0 14px 0 16px;
  text-decoration: none;
  color: var(--rail-fg);
  font-size: 14px;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s;
  position: relative;
}
.nav-item:hover { background: var(--rail-hover); }
.nav-item.active {
  background: var(--rail-active);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}
.nav-icon { display: flex; align-items: center; color: inherit; flex-shrink: 0; }
.nav-label { flex: 1; }
.nav-badge {
  font-size: 10px; font-weight: 700; font-family: var(--font-mono);
  background: var(--accent-dim); color: var(--accent);
  padding: 1px 6px; border-radius: var(--radius-pill);
}

.sidebar-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--rail-border);
}
.sidebar-user { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.user-avatar {
  width: 30px; height: 30px;
  background: var(--accent-dim); color: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; color: var(--rail-fg); }
.user-role { font-size: 11px; color: var(--rail-muted); }

.theme-btn {
  width: 28px; height: 28px;
  border: 1px solid var(--rail-border);
  background: var(--rail-surface);
  color: var(--rail-muted);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background 0.12s;
}
.theme-btn:hover { background: var(--rail-hover); color: var(--rail-fg); }

/* ── Topbar ─────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.topbar-title { font-size: 17px; font-weight: 700; font-family: var(--font-display); color: var(--fg); }
.topbar-sub { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

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

/* ── Search Box ─────────────────────────────────── */
.search-box { display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); font-size: 14px; color: var(--muted); }
.search-box input { border: none; background: transparent; outline: none; font-size: 14px; color: var(--fg); width: 160px; }

/* ── Filter Bar / Chips ─────────────────────────── */
.filter-bar { display: flex; align-items: center; gap: 12px; padding: 10px 22px; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.chip-group { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { height: 28px; padding: 0 11px; border-radius: var(--radius-pill); border: 1px solid var(--border); background: transparent; font-size: 12px; font-weight: 500; cursor: pointer; color: var(--muted); transition: all 0.12s; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.filter-sep { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; }

/* ── Page Footer (live dot) ─────────────────────── */
.page-footer { padding: 12px 22px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); background: var(--surface); flex-shrink: 0; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 2px var(--success-bg); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ── Overview Page ──────────────────────────────── */
/* Outer container fills content-area and handles scrolling.          */
/* Inner .overview-page constrains width and holds the page content.  */
.overview-scroll-wrapper {
  flex: 1;
  overflow-y: auto;
  height: 100%;
}
.overview-page {
  padding: 32px;
  max-width: 960px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.overview-hero { display: flex; flex-direction: column; gap: 12px; }
.hero-eyebrow { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.hero-title { font-size: 34px; font-weight: 700; font-family: var(--font-display); line-height: 1.15; }
.hero-desc { font-size: 15px; color: var(--muted); max-width: 520px; line-height: 1.6; }
.hero-actions { display: flex; gap: 10px; padding-top: 4px; }

.overview-summary { display: flex; align-items: center; gap: 0; }
.summary-item { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1; padding: 14px; }
.summary-num { font-size: 24px; font-weight: 700; font-family: var(--font-display); color: var(--accent); }
.summary-label { font-size: 12px; color: var(--muted); }
.summary-divider { width: 1px; height: 40px; background: var(--border); flex-shrink: 0; }

.section-title { font-size: 14px; font-weight: 700; font-family: var(--font-display); color: var(--fg); margin-bottom: 14px; }

.workflow-steps { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.workflow-step { display: flex; flex-direction: column; gap: 4px; padding: 12px; background: var(--surface); border-radius: var(--radius-md); box-shadow: var(--shadow-card); }
.step-num { font-size: 11px; font-weight: 700; font-family: var(--font-mono); color: var(--accent); }
.step-label { font-size: 14px; font-weight: 700; font-family: var(--font-display); }
.step-desc { font-size: 12px; color: var(--muted); line-height: 1.4; }

.screen-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.screen-card { text-align: left; cursor: pointer; border: none; transition: box-shadow 0.15s; display: flex; flex-direction: column; gap: 6px; }
.screen-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.10), 0 0 0 2px var(--accent-dim); }
.screen-icon { width: 36px; height: 36px; background: var(--accent-dim); color: var(--accent); border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; margin-bottom: 4px; }
.screen-label { font-size: 14px; font-weight: 700; font-family: var(--font-display); }
.screen-desc { font-size: 13px; color: var(--muted); line-height: 1.4; }

/* ── Status Page ────────────────────────────────── */
.status-page { display: flex; flex-direction: column; height: 100%; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
}
.stat-cell {
  padding: 18px 22px;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}
.stat-cell:last-child { border-right: none; }
.stat-value { font-size: 28px; font-weight: 700; font-family: var(--font-display); }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-cell.danger .stat-value { color: var(--danger); }

.panel-grid { display: grid; grid-template-columns: 1.4fr 0.9fr; gap: 16px; }
.panel-left, .panel-right { display: flex; flex-direction: column; gap: 16px; }

.card-header { font-size: 13px; font-weight: 700; font-family: var(--font-display); color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 12px; }

.task-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); }
.task-info { flex: 1; min-width: 0; }
.task-name { font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.task-progress-bar { height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; }
.task-progress-fill { height: 100%; background: var(--accent); border-radius: 2px; }

.program-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--border); }
.program-pct { font-size: 12px; font-weight: 700; font-family: var(--font-mono); color: var(--muted); }

.kpi-strip { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.kpi-item { display: flex; align-items: center; gap: 10px; }
.kpi-label { font-size: 11px; color: var(--muted); width: 130px; flex-shrink: 0; }
.kpi-bar { flex: 1; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.kpi-fill { height: 100%; background: var(--accent); border-radius: 2px; }
.kpi-value { font-size: 11px; font-weight: 700; font-family: var(--font-mono); color: var(--fg); width: 36px; text-align: right; flex-shrink: 0; }

.service-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--border); }
.service-name { font-size: 14px; }

.event-row { padding: 10px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 3px; }
.event-date { font-size: 11px; font-family: var(--font-mono); color: var(--muted); }
.event-title { font-size: 14px; font-weight: 600; }
.event-summary { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ── Perception Page ────────────────────────────── */
.perception-page { display: flex; flex-direction: column; height: 100%; }

.stats-bar { display: flex; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.sbar-cell { flex: 1; padding: 14px 22px; border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 3px; }
.sbar-cell:last-child { border-right: none; }
.sbar-val { font-size: 24px; font-weight: 700; font-family: var(--font-display); }
.sbar-lbl { font-size: 12px; color: var(--muted); }
.sbar-cell.danger .sbar-val { color: var(--danger); }
.sbar-cell.warn   .sbar-val { color: var(--warn); }
.sbar-cell.accent .sbar-val { color: var(--accent); }

.perception-split { display: grid; grid-template-columns: 360px 1fr; flex: 1; overflow: hidden; }

.feed-pane { overflow-y: auto; border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 0; }
.ev-card { padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.12s; border-left: 3px solid transparent; }
.ev-card:hover { background: var(--bg); }
.ev-card.selected { border-left-color: var(--accent); background: var(--accent-dim); box-shadow: inset 0 0 0 1px var(--accent-dim); }
.ev-top { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; }
.ev-std { font-size: 11px; font-family: var(--font-mono); color: var(--muted); }
.ev-title { font-size: 14px; font-weight: 600; line-height: 1.35; margin-bottom: 5px; }
.ev-summary { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: 8px; }
.ev-bottom { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ev-date { font-size: 11px; font-family: var(--font-mono); color: var(--muted); }
.ev-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.ev-tag { font-size: 11px; padding: 1px 6px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-pill); color: var(--muted); }
.impact-dot { font-size: 11px; font-weight: 700; margin-left: auto; }
.impact-high   { color: var(--danger); }
.impact-medium { color: var(--warn); }
.impact-low    { color: var(--success); }

.source-tag { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: var(--radius-pill); background: var(--accent-dim); color: var(--accent); }

.analysis-pane { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.analysis-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--muted); font-size: 13px; }
.empty-ring { width: 56px; height: 56px; border-radius: 50%; border: 2px dashed var(--border); }

.detail-card { display: flex; flex-direction: column; gap: 10px; }
.detail-header { display: flex; align-items: center; gap: 8px; }
.detail-title { font-size: 16px; font-weight: 700; font-family: var(--font-display); }
.detail-summary { font-size: 14px; color: var(--muted); line-height: 1.6; }
.detail-actions { display: flex; gap: 8px; padding-top: 4px; }

.docs-card { display: flex; flex-direction: column; gap: 0; }
.doc-row { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.doc-score { font-size: 11px; font-weight: 700; font-family: var(--font-mono); color: var(--success); width: 34px; flex-shrink: 0; padding-top: 1px; }
.doc-name { font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.doc-clause { font-size: 11px; font-family: var(--font-mono); color: var(--muted); margin-left: 5px; }
.doc-snippet { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.ai-card .ai-output { font-size: 14px; line-height: 1.7; white-space: pre-wrap; font-family: var(--font-mono); }
.blink-cursor { animation: blink 1s step-end infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* ── Documents Page ─────────────────────────────── */
.docs-page { display: flex; flex-direction: column; height: 100%; }

.docs-controls { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.select-input { height: 30px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); font-size: 13px; color: var(--fg); outline: none; cursor: pointer; }

.batch-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--accent-dim); border: 1px solid var(--accent); border-radius: var(--radius-sm); margin-bottom: 12px; font-size: 13px; color: var(--accent); font-weight: 600; }
.risk-btn { color: var(--danger); border-color: var(--danger-bg); }

.docs-table { background: var(--surface); border-radius: var(--radius-md); box-shadow: var(--shadow-card); overflow: hidden; }
.table-header {
  display: grid;
  grid-template-columns: 28px 1fr 90px 100px 70px 100px 90px 120px;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
  align-items: center;
}
.table-row {
  display: grid;
  grid-template-columns: 28px 1fr 90px 100px 70px 100px 90px 120px;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  align-items: center;
  transition: background 0.1s, opacity 0.3s;
}
.table-row:last-child { border-bottom: none; }
.table-row:hover { background: var(--bg); }
.table-row.row-selected { background: var(--accent-dim); }
.table-row.row-deleting { opacity: 0.4; pointer-events: none; }
.doc-name-cell { font-weight: 500; }
.cell-mono { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.cell-muted { font-size: 13px; color: var(--muted); }
.row-actions { display: flex; gap: 10px; }
.text-link { background: none; border: none; font-size: 13px; color: var(--accent); cursor: pointer; font-weight: 500; padding: 0; }
.text-link:hover { text-decoration: underline; }
.danger-link { color: var(--danger); }

/* ── Compliance Page ────────────────────────────── */
.compliance-page { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

.compliance-hero { padding: 20px 24px 0; flex-shrink: 0; }
.compliance-title { font-size: 18px; font-weight: 700; font-family: var(--font-display); margin-bottom: 4px; }
.compliance-desc { font-size: 13px; color: var(--muted); }

.compliance-workspace { display: grid; grid-template-columns: 0.95fr 1.25fr 0.9fr; gap: 14px; padding: 16px 24px 24px; flex: 1; overflow: hidden; min-height: 0; }

.comp-col { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.col-header { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 0 2px 4px; flex-shrink: 0; }

.source-item { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.source-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.source-std { font-size: 14px; font-weight: 700; font-family: var(--font-display); }
.source-helper { font-size: 12px; color: var(--muted); }
.source-scores { display: flex; gap: 5px; flex-wrap: wrap; }
.score-pill { font-size: 11px; font-family: var(--font-mono); padding: 2px 6px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-pill); color: var(--muted); }

.para-card { flex-shrink: 0; }
.para-text { font-size: 14px; line-height: 1.7; color: var(--fg); }
.para-text mark { background: rgba(226,0,116,.15); color: var(--accent); padding: 0 2px; border-radius: 2px; }

.stages-card { flex-shrink: 0; }
.stage-row { padding: 8px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 5px; }
.stage-label-row { display: flex; justify-content: space-between; align-items: center; }
.stage-label { font-size: 13px; }
.stage-pct { font-size: 12px; font-family: var(--font-mono); color: var(--muted); }
.stage-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.stage-fill { height: 100%; border-radius: 2px; }
.stage-fill.stage-ok   { background: var(--success); }
.stage-fill.stage-warn { background: var(--warn); }
.stage-fill.stage-info { background: var(--info); }

.finding-item { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.finding-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.finding-title { font-size: 14px; font-weight: 600; line-height: 1.3; }
.finding-desc { font-size: 13px; color: var(--muted); line-height: 1.5; }

.conclusion-box { display: flex; flex-direction: column; gap: 10px; flex-shrink: 0; }
.conclusion-text { font-size: 13px; line-height: 1.6; color: var(--fg); }
.action-items { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.action-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; }
.action-label { color: var(--muted); }
.action-value { font-weight: 600; }
.risk-text { color: var(--danger); }

/* ── Chat Page ──────────────────────────────────── */
.chat-page { display: flex; flex-direction: column; height: 100%; }
.chat-body { display: grid; grid-template-columns: 280px minmax(0,1fr) 320px; flex: 1; overflow: hidden; min-height: 0; }

.history-pane { border-right: 1px solid var(--border); overflow-y: auto; padding: 14px 0; background: var(--surface); display: flex; flex-direction: column; gap: 0; }
.history-header, .quick-header { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 10px 16px 6px; }
.history-item { padding: 8px 16px; cursor: pointer; border-radius: 0; transition: background 0.1s; }
.history-item:hover { background: var(--bg); }
.history-title { font-size: 13px; font-weight: 500; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.history-date { font-size: 11px; font-family: var(--font-mono); color: var(--muted); margin-top: 2px; }
.quick-item { background: none; border: none; text-align: left; padding: 8px 16px; font-size: 13px; color: var(--muted); cursor: pointer; line-height: 1.4; transition: color 0.1s, background 0.1s; }
.quick-item:hover { color: var(--accent); background: var(--accent-dim); }

.chat-main { display: flex; flex-direction: column; overflow: hidden; }
.messages { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; }
.message { display: flex; gap: 10px; align-items: flex-end; }
.msg-user { flex-direction: row-reverse; }
.msg-avatar { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; flex-shrink: 0; background: var(--accent-dim); color: var(--accent); }
.msg-avatar.user-av { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.msg-bubble { max-width: 72%; padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.6; }
.msg-assistant .msg-bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-user .msg-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }

.composer { padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.quick-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer-input { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); font-size: 14px; font-family: var(--font-body); color: var(--fg); resize: none; outline: none; line-height: 1.5; }
.composer-input:focus { border-color: var(--accent); }

.citation-rail { border-left: 1px solid var(--border); overflow-y: auto; padding: 14px 0; background: var(--surface); }
.citation-header { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 0 16px 8px; }
.citation-item { display: flex; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); transition: background 0.15s; }
.citation-item.highlighted { background: var(--accent-dim); border-left: 3px solid var(--accent); }
.cit-score { font-size: 11px; font-weight: 700; font-family: var(--font-mono); color: var(--success); width: 34px; flex-shrink: 0; padding-top: 1px; }
.cit-index { font-size: 10px; font-weight: 700; font-family: var(--font-mono); color: var(--muted); width: 18px; flex-shrink: 0; padding-top: 2px; }
.cit-name { font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.cit-clause { font-size: 11px; font-family: var(--font-mono); color: var(--muted); margin-left: 5px; }
.cit-snippet { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.5; }

/* Inline citation badge [N] in message text */
.cite-ref {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 16px;
  padding: 0 4px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  background: var(--accent-dim);
  color: var(--accent);
  cursor: pointer;
  vertical-align: middle;
  margin: 0 1px;
  border: none;
  line-height: 1;
  transition: background 0.12s;
}
.cite-ref:hover { background: var(--accent); color: #fff; }

/* ── Loading States ─────────────────────────────── */
.loading-shimmer {
  background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
  display: inline-block;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.stat-value-loading { height: 32px; width: 64px; }

/* ── Upload Modal ───────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(3px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-dialog {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  max-width: 1000px;
  width: 100%;
  max-height: 90vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 14px 48px rgba(0,0,0,.22);
  position: relative;
}
.modal-panel {
  padding: 28px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.modal-panel + .modal-panel {
  border-left: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 76%, var(--bg) 24%);
}
.modal-eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 8px;
}
.modal-title { font-size: 22px; font-weight: 700; font-family: var(--font-display); line-height: 1.2; }
.modal-lead { font-size: 13px; color: var(--muted); margin-top: 8px; line-height: 1.6; }
.modal-close {
  position: absolute;
  top: 16px; right: 20px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--muted);
  transition: background 0.12s;
}
.modal-close:hover { background: var(--bg); color: var(--fg); }

.dropzone {
  margin-top: 20px;
  border: 1px dashed rgba(226,0,116,.46);
  border-radius: var(--radius-md);
  background: rgba(226,0,116,.04);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  min-height: 180px;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.dropzone.drag-over { background: rgba(226,0,116,.08); border-color: var(--accent); }
.drop-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  border: 1px solid rgba(226,0,116,.35);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px; font-weight: 700;
}
.drop-label { font-size: 15px; font-weight: 600; font-family: var(--font-display); }
.drop-hint { font-size: 12px; color: var(--muted); }
.drop-actions { display: flex; gap: 10px; margin-top: 4px; }

.staged-files { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.file-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.file-row-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.file-name { font-size: 13px; font-weight: 500; }
.file-meta { font-size: 11px; color: var(--muted); font-family: var(--font-mono); }
.file-remove { background: none; border: none; cursor: pointer; color: var(--muted); padding: 2px; }
.file-remove:hover { color: var(--danger); }
.file-progress { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.file-progress-fill { height: 100%; background: var(--accent); border-radius: 2px; }

.upload-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.upload-field { display: flex; flex-direction: column; gap: 5px; }
.upload-field label { font-size: 12px; color: var(--muted); }
.upload-field input,
.upload-field select,
.upload-field textarea {
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 0 10px;
  font-size: 13px; color: var(--fg);
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.12s;
}
.upload-field input:focus,
.upload-field select:focus,
.upload-field textarea:focus { border-color: var(--accent); }
.upload-field textarea { min-height: 72px; padding: 8px 10px; resize: vertical; }
.upload-field.full-width { grid-column: 1 / -1; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }

.queue-section { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.queue-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.queue-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.queue-name { font-size: 13px; font-weight: 600; }
.queue-desc { font-size: 11px; color: var(--muted); margin-top: 2px; }
.queue-progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.queue-progress-fill { height: 100%; border-radius: 3px; background: color-mix(in srgb, var(--accent) 74%, white 26%); transition: width 0.4s ease; }

.summary-cards { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.summary-card-sm {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 88%, var(--bg) 12%);
  padding: 12px 14px;
}
.summary-card-sm strong { font-size: 13px; font-family: var(--font-mono); }
.summary-card-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ═══════════════════════════════════════════════
   COMPLIANCE ANALYSIS — NEW ANALYSIS FEATURE
   ═══════════════════════════════════════════════ */

/* Modal tabs */
.modal-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.modal-tab {
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s, border-color 0.12s;
  font-family: var(--font-body);
}
.modal-tab:hover { color: var(--fg); }
.modal-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Domain chips */
.domain-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.domain-chip {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.12s;
}
.domain-chip.selected {
  background: rgba(226,0,116,.12);
  border-color: rgba(226,0,116,.5);
  color: var(--accent);
}

/* Doc select list */
.doc-select-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
  margin-top: 8px;
}
.doc-select-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.doc-select-item:hover { border-color: rgba(226,0,116,.4); }
.doc-select-item.selected {
  border-color: var(--accent);
  background: rgba(226,0,116,.06);
}
.doc-select-check {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.12s;
}
.doc-select-item.selected .doc-select-check {
  background: var(--accent);
  border-color: var(--accent);
}
.doc-select-name { font-size: 14px; font-weight: 500; flex: 1; }
.doc-select-meta { font-size: 12px; color: var(--muted); }

/* Stage running animation */
@keyframes stage-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.stage-running .stage-fill {
  animation: stage-pulse 1.2s ease-in-out infinite;
}
.stage-fill.stage-running {
  background: var(--accent);
  animation: stage-pulse 1.2s ease-in-out infinite;
}

/* Compliance status bar */
.compliance-status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 16px;
  font-size: 12px;
}
.compliance-status-bar .status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.compliance-status-bar.streaming .status-dot {
  background: var(--accent);
  animation: stage-pulse 1s ease-in-out infinite;
}
.compliance-status-bar.done .status-dot { background: var(--ok); }
.compliance-status-bar.error .status-dot { background: var(--danger); }
.status-bar-label { color: var(--fg); font-weight: 500; }
.status-bar-sub { color: var(--muted); margin-left: 4px; }

/* Risk score badge */
.risk-score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px; height: 42px;
  border-radius: 50%;
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font-mono);
  flex-shrink: 0;
}
.risk-score-badge.low { background: rgba(34,197,94,.15); color: #22c55e; }
.risk-score-badge.med { background: rgba(234,179,8,.15); color: #eab308; }
.risk-score-badge.high { background: rgba(239,68,68,.15); color: #ef4444; }

/* Analysis empty state */
.analysis-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 60px 24px;
  text-align: center;
  color: var(--muted);
}
.analysis-empty-icon {
  width: 56px; height: 56px;
  border-radius: 16px;
  border: 1px dashed rgba(226,0,116,.4);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  opacity: 0.7;
}
.analysis-empty h3 { font-size: 16px; font-weight: 600; color: var(--fg); margin: 0; }
.analysis-empty p { font-size: 14px; max-width: 280px; line-height: 1.6; margin: 0; }

/* Highlight terms in paragraph */
mark.comp-highlight {
  background: rgba(226,0,116,.18);
  color: inherit;
  border-radius: 2px;
  padding: 0 2px;
}

/* Conclusion box enhancements */
.risk-meter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}
.risk-bar-track {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.risk-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(to right, #22c55e 0%, #eab308 50%, #ef4444 100%);
  transition: width 0.6s ease;
}

/* ── Login Page ─────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 36px 32px 28px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.login-logo { width: 32px; height: 32px; object-fit: contain; }
.login-brand-name { font-size: 14px; font-weight: 700; font-family: var(--font-display); color: var(--fg); }
.login-brand-sub  { font-size: 11px; color: var(--muted); }

.login-title {
  font-size: 20px;
  font-weight: 700;
  font-family: var(--font-display);
  margin-bottom: 20px;
  color: var(--fg);
}

.login-form { display: flex; flex-direction: column; gap: 16px; }

.login-field { display: flex; flex-direction: column; gap: 5px; }
.login-label { font-size: 12px; font-weight: 600; color: var(--fg); }

.login-input {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
.login-input:focus { border-color: var(--accent); }
.login-input:disabled { opacity: 0.6; }

.login-error {
  font-size: 12px;
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid rgba(220,38,38,.2);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin: 0;
}

.login-btn {
  height: 40px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.login-btn:hover:not(:disabled) { background: var(--accent-hover); }
.login-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.login-hint {
  margin-top: 16px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}
.login-hint code {
  font-family: var(--font-mono);
  background: var(--bg);
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

/* ── Sidebar user block (authenticated) ─────────── */
.user-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--accent-dim);
  color: var(--accent);
  letter-spacing: 0.04em;
}
.logout-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: color 0.15s;
}
.logout-btn:hover { color: var(--danger); }

/* ── Detail Tabs (Perception) ──────────────────── */
.detail-tabs {
  display: flex;
  gap: 2px;
  margin: 8px 0 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.detail-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.detail-tab:hover { color: var(--text); }
.detail-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.detail-tab.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.spin { animation: spin 1s linear infinite; }
