/* ═══════════════════════════════════════════════════════════════════════════════
   AIOS Design System — aios-theme.css
   Shared design tokens, base styles, and component classes for all dashboard pages.
   Based on UI/UX Pro Max design rules.
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ─── Google Fonts: Inter ───────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

/* ─── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
  /* Colour palette */
  --bg: #060b16;
  --surface: #0c1322;
  --card: rgba(16, 25, 46, 0.85);
  --card-solid: #10192e;
  --surface-elevated: #142036;
  --border: rgba(26, 42, 72, 0.6);
  --border-hover: rgba(139, 92, 246, 0.35);
  --dim: #1e2d48;

  /* Semantic colours */
  --blue: #3b82f6;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #8b5cf6;
  --cyan: #06b6d4;
  --orange: #f97316;
  --teal: #14b8a6;

  /* Text */
  --text: #f0f4ff;
  --text-secondary: #c0ccdf;
  --muted: #7a90b5;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', ui-monospace, monospace;

  /* Type scale */
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 13px;
  --text-md: 14px;
  --text-lg: 16px;
  --text-xl: 18px;
  --text-2xl: 20px;
  --text-3xl: 24px;
  --text-4xl: 28px;
  --text-5xl: 32px;
  --text-hero: 36px;

  /* Spacing (4px grid) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* Border radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows (elevation scale) */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35), 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4), 0 4px 8px rgba(0, 0, 0, 0.25);
  --shadow-glow: 0 0 20px rgba(139, 92, 246, 0.08);
  --shadow-glow-hover: 0 4px 20px rgba(139, 92, 246, 0.15);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease-out;
  --transition-slow: 300ms ease-out;

  /* Z-index scale */
  --z-base: 0;
  --z-dropdown: 10;
  --z-sticky: 20;
  --z-overlay: 40;
  --z-modal: 100;
  --z-toast: 1000;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Focus States ──────────────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

/* ─── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--dim); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
* { scrollbar-width: thin; scrollbar-color: var(--dim) transparent; }

/* ─── Header ────────────────────────────────────────────────────────────────── */
.header {
  background: rgba(12, 19, 34, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--sp-6);
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}
.header-left { display: flex; align-items: center; gap: var(--sp-3); }
.header-right { display: flex; align-items: center; gap: var(--sp-3); }
.logo-wrap { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--purple), var(--blue));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-md);
  font-weight: 900;
  color: #fff;
  box-shadow: 0 2px 12px rgba(139, 92, 246, 0.25);
}
.brand {
  font-size: var(--text-lg);
  font-weight: 800;
  letter-spacing: -0.4px;
  background: linear-gradient(135deg, #f0f4ff, #8b9cc7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
}
.back-link:hover { border-color: var(--purple); color: var(--text); background: rgba(139, 92, 246, 0.06); }

/* ─── Subnav / Tabs ─────────────────────────────────────────────────────────── */
.subnav, .tabs {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--sp-6);
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.subnav::-webkit-scrollbar, .tabs::-webkit-scrollbar { display: none; }
.subnav a, .tab {
  padding: 12px var(--sp-4);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-base);
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 7px;
}
.subnav a:hover, .tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.02); }
.subnav a.active { color: var(--purple); border-bottom-color: var(--purple); background: rgba(139, 92, 246, 0.04); }
.tab.active { color: var(--text); border-bottom-color: var(--blue); }
.tab .tab-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dim); }
.tab .tab-dot.ran { background: var(--green); }
.tab .tab-dot.running { background: var(--amber); animation: pulse 1s infinite; }

/* ─── Container ─────────────────────────────────────────────────────────────── */
.container { max-width: 1440px; margin: 0 auto; padding: var(--sp-6) var(--sp-6); }
.page { display: none; padding: var(--sp-6); max-width: 1440px; margin: 0 auto; }
.page.active { display: block; }

/* ─── Grid Helpers ──────────────────────────────────────────────────────────── */
.g4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-4); }
.g3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }
.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.g2-wide { display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--sp-4); }
.g2-sidebar { display: grid; grid-template-columns: 1fr 340px; gap: var(--sp-4); }

/* ─── Section Labels ────────────────────────────────────────────────────────── */
.section, .section-title {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--sp-3);
}
.section { margin: var(--sp-6) 0 var(--sp-3); }
.section:first-child { margin-top: 0; }

/* ─── Cards ─────────────────────────────────────────────────────────────────── */
.card, .section-card, .agent-card {
  background: var(--card);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-xl);
  padding: var(--sp-4);
  transition: border-color var(--transition-base);
}
.card:hover, .section-card:hover { border-color: var(--border-hover); }
.agent-card { margin-bottom: var(--sp-5); }
.card-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .7px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--sp-4);
}

/* ─── KPI / Stat Cards ──────────────────────────────────────────────────────── */
.kpi, .stat-card {
  background: var(--card);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
.kpi:hover, .stat-card:hover {
  border-color: var(--border-hover);
}
.kpi::after { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; }
.kpi.c-green::after { background: var(--green); }
.kpi.c-blue::after { background: var(--blue); }
.kpi.c-purple::after { background: var(--purple); }
.kpi.c-amber::after { background: var(--amber); }
.kpi.c-cyan::after { background: var(--cyan); }
.kpi.c-orange::after { background: var(--orange); }
.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  background: var(--purple);
  opacity: 0;
  transition: opacity var(--transition-base);
}
.stat-card:hover::before { opacity: 1; }

.kpi-label, .stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--sp-2);
}
.kpi-val, .stat-value {
  font-size: var(--text-4xl);
  font-weight: 800;
  letter-spacing: -0.8px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.kpi-sub, .stat-sub {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-top: var(--sp-1);
}
.kpi-sub.up { color: var(--green); }
.kpi-sub.down { color: var(--red); }
.kpi-sub.neutral { color: var(--muted); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

/* ─── Agent Components ──────────────────────────────────────────────────────── */
.agent-header { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.agent-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--purple), var(--blue));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 2px 12px rgba(139, 92, 246, 0.2);
  color: #fff;
}
.agent-icon svg { width: 22px; height: 22px; stroke: #fff; }
.agent-name { font-size: var(--text-lg); font-weight: 700; }
.agent-role { font-size: var(--text-sm); color: var(--muted); }
.agent-desc { font-size: var(--text-base); color: var(--muted); line-height: 1.6; margin-bottom: var(--sp-3); }
.agent-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn, .run-btn {
  padding: var(--sp-2) var(--sp-5);
  font-size: var(--text-base);
  font-weight: 700;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 36px;
  font-family: var(--font-sans);
}
.btn-primary, .run-btn-primary {
  background: linear-gradient(135deg, var(--purple), #7c3aed);
  color: #fff;
  box-shadow: 0 2px 10px rgba(139, 92, 246, 0.25);
}
.btn-primary:hover, .run-btn-primary:hover {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.35);
  transform: translateY(-1px);
}
.btn-primary:disabled, .run-btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn-ghost, .run-btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover, .run-btn-secondary:hover {
  border-color: var(--purple);
  background: rgba(139, 92, 246, 0.06);
  color: var(--text);
}
.run-status { font-size: var(--text-sm); color: var(--muted); }

/* ─── Status Badges ─────────────────────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  letter-spacing: 0.03em;
}
.status-on { background: rgba(16, 185, 129, 0.12); color: var(--green); border: 1px solid rgba(16, 185, 129, 0.3); }
.status-off { background: rgba(239, 68, 68, 0.12); color: var(--red); border: 1px solid rgba(239, 68, 68, 0.3); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-dot.pulse { animation: pulse 2s infinite; }

.badge { display: inline-block; padding: 2px 8px; border-radius: var(--radius-sm); font-size: var(--text-xs); font-weight: 700; }
.badge-green { background: rgba(16, 185, 129, 0.2); color: var(--green); }
.badge-blue { background: rgba(59, 130, 246, 0.2); color: var(--blue); }
.badge-amber { background: rgba(245, 158, 11, 0.2); color: var(--amber); }
.badge-red { background: rgba(239, 68, 68, 0.2); color: var(--red); }
.badge-dim { background: rgba(30, 45, 72, 0.8); color: var(--muted); }

/* ─── Location Filter ───────────────────────────────────────────────────────── */
.loc-filter {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: fit-content;
}
.loc-filter-btn {
  font-size: var(--text-xs);
  font-weight: 700;
  padding: var(--sp-2) var(--sp-4);
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all var(--transition-base);
  letter-spacing: 0.02em;
  font-family: var(--font-sans);
}
.loc-filter-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.loc-filter-btn.active { background: var(--purple); color: #fff; box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3); }
.loc-filter-btn.active.tsv { background: var(--blue); box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3); }
.loc-filter-btn.active.mky { background: var(--orange); box-shadow: 0 2px 8px rgba(249, 115, 22, 0.3); }

/* ─── Department Cards ──────────────────────────────────────────────────────── */
.dept-card {
  background: var(--card);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  cursor: pointer;
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}
.dept-card:hover { border-color: var(--blue); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.dept-card::after { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; }
.dept-card.healthy::after { background: var(--green); }
.dept-card.warning::after { background: var(--amber); }
.dept-card.inactive::after { background: var(--dim); }
.dept-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.dept-icon { font-size: 20px; display: flex; align-items: center; }
.dept-icon svg { width: 22px; height: 22px; }
.dept-badge { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 10px; }
.dept-badge.healthy { background: rgba(16, 185, 129, 0.15); color: var(--green); }
.dept-badge.warning { background: rgba(245, 158, 11, 0.15); color: var(--amber); }
.dept-badge.inactive { background: rgba(30, 45, 72, 0.8); color: var(--muted); }
.dept-name { font-weight: 700; font-size: var(--text-md); margin-bottom: 4px; }
.dept-metric { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; font-variant-numeric: tabular-nums; }
.dept-sub { font-size: var(--text-xs); color: var(--muted); margin-top: 2px; }

/* ─── Tables ────────────────────────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.tbl th {
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.tbl td {
  padding: 9px var(--sp-3);
  border-bottom: 1px solid var(--dim);
  color: var(--text-secondary);
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: rgba(255, 255, 255, 0.02); }

/* ─── Progress Bars ─────────────────────────────────────────────────────────── */
.prog-wrap { display: flex; flex-direction: column; gap: var(--sp-2); }
.prog-row { display: flex; align-items: center; gap: 10px; }
.prog-label { font-size: var(--text-sm); font-weight: 600; min-width: 130px; color: var(--text-secondary); }
.prog-bar { flex: 1; height: 6px; background: var(--dim); border-radius: 3px; overflow: hidden; }
.prog-fill { height: 100%; border-radius: 3px; transition: width 0.5s ease-out; }
.prog-pct { font-size: var(--text-xs); font-weight: 700; min-width: 36px; text-align: right; font-variant-numeric: tabular-nums; }
.prog-stats { font-size: 10px; color: var(--muted); margin-left: 140px; }

/* ─── Tech Chips ────────────────────────────────────────────────────────────── */
.tech-grid { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.tech-chip {
  padding: 5px var(--sp-3);
  border-radius: 7px;
  font-size: var(--text-sm);
  font-weight: 600;
  border: 1px solid var(--border);
}
.tech-chip.full { background: rgba(16, 185, 129, 0.12); border-color: rgba(16, 185, 129, 0.3); color: var(--green); }
.tech-chip.active { background: rgba(59, 130, 246, 0.12); border-color: rgba(59, 130, 246, 0.3); color: var(--blue); }
.tech-chip.standby { background: rgba(30, 45, 72, 0.5); color: var(--muted); }

/* ─── Tab Content ───────────────────────────────────────────────────────────── */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── Animations ────────────────────────────────────────────────────────────── */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes replyPulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ─── Reduced Motion ────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ─── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .g2-sidebar { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .g4, .g3, .g2 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .header { padding: 0 var(--sp-4); }
  .container, .page { padding: var(--sp-4); }
}

/* ─── Lucide Icon Defaults ──────────────────────────────────────────────────── */
[data-lucide] {
  width: 18px;
  height: 18px;
  stroke-width: 1.75;
  display: inline-block;
  vertical-align: middle;
}

/* ─── Utility Classes ───────────────────────────────────────────────────────── */
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); animation: pulse 2s infinite; }
.updated { color: var(--muted); font-size: var(--text-xs); }
.text-muted { color: var(--muted); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.text-purple { color: var(--purple); }
.font-mono { font-family: var(--font-mono); }
.tabular-nums { font-variant-numeric: tabular-nums; }

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

/* ═══════════════════════════════════════════════════════════════════════════════
   Leaky Bucket — Strategies Tab Components
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ─── Bucket Container ─────────────────────────────────────────────────────── */
.bucket-wrapper {
  display: flex;
  gap: 32px;
  align-items: flex-start;
  margin-bottom: 32px;
}
.bucket-container {
  flex: 1;
  max-width: 640px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: blur(8px);
  position: relative;
  overflow: hidden;
}
.bucket-container::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(59,130,246,0.03) 0%, rgba(139,92,246,0.02) 100%);
  pointer-events: none;
}
.bucket-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  font-size: 16px;
  font-weight: 700;
}
.bucket-header svg { color: var(--blue); }
.bucket-inflow {
  text-align: center;
  padding: 12px 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  position: relative;
}
.bucket-inflow::after {
  content: '';
  display: block;
  width: 2px;
  height: 16px;
  background: linear-gradient(180deg, var(--blue), transparent);
  margin: 6px auto 0;
  animation: waterDrip 1.5s ease-in-out infinite;
}

/* ─── Bucket Stages ────────────────────────────────────────────────────────── */
.bucket-body {
  border: 2px solid var(--border);
  border-radius: 4px 4px 16px 16px;
  overflow: hidden;
  position: relative;
}
.bucket-stage {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--dim);
  position: relative;
  transition: background var(--transition-fast);
  cursor: default;
}
.bucket-stage:last-child { border-bottom: none; }
.bucket-stage:hover { background: rgba(139,92,246,0.04); }
.bucket-stage.leak-critical { border-left: 3px solid var(--red); }
.bucket-stage.leak-warning { border-left: 3px solid var(--amber); }
.bucket-stage.leak-healthy { border-left: 3px solid var(--green); }

.bucket-stage-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, rgba(59,130,246,0.08), rgba(59,130,246,0.03));
  transition: width 1s ease-out;
  pointer-events: none;
}
.bucket-stage-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 1;
}
.bucket-stage-name {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  min-width: 120px;
}
.bucket-stage-count {
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.bucket-stage-bar {
  flex: 1;
  height: 6px;
  background: var(--dim);
  border-radius: 3px;
  overflow: hidden;
  min-width: 60px;
}
.bucket-stage-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--blue), var(--purple));
  transition: width 1.2s ease-out;
}

/* ─── Leak Indicators ──────────────────────────────────────────────────────── */
.bucket-leak {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  cursor: pointer;
}
.bucket-leak-drops {
  display: flex;
  gap: 2px;
  align-items: flex-end;
}
.bucket-leak-drop {
  width: 6px;
  height: 6px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  opacity: 0.7;
}
.bucket-leak-drop.drop-red { background: var(--red); }
.bucket-leak-drop.drop-amber { background: var(--amber); }
.bucket-leak-drop.drop-green { background: var(--green); }
.bucket-leak-drop.animated {
  animation: dripFall 2s ease-in infinite;
}
.bucket-leak-drop.animated:nth-child(2) { animation-delay: 0.4s; }
.bucket-leak-drop.animated:nth-child(3) { animation-delay: 0.8s; }

.bucket-leak-label {
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.bucket-leak-label.text-red { color: var(--red); }
.bucket-leak-label.text-amber { color: var(--amber); }
.bucket-leak-label.text-green { color: var(--green); }

/* Leak tooltip */
.bucket-leak-tooltip {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 6px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 11px;
  min-width: 200px;
  z-index: 20;
  box-shadow: var(--shadow-lg);
}
.bucket-leak:hover .bucket-leak-tooltip { display: block; }
.bucket-leak-tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 3px 0;
  color: var(--muted);
}
.bucket-leak-tooltip-row span:last-child {
  font-weight: 700;
  color: var(--text);
}

/* ─── Bucket Outflow ───────────────────────────────────────────────────────── */
.bucket-outflow {
  text-align: center;
  padding: 12px 0 4px;
  font-size: 14px;
  font-weight: 700;
  color: var(--green);
}
.bucket-outflow-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  margin-top: 2px;
}

/* ─── Insights Summary (beside bucket) ─────────────────────────────────────── */
.bucket-insights {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.insight-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  backdrop-filter: blur(8px);
  transition: border-color var(--transition-fast);
}
.insight-card:hover { border-color: var(--border-hover); }
.insight-card-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.insight-card-title svg { width: 14px; height: 14px; }
.insight-card-value {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 4px;
}
.insight-card-detail {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}
.insight-comparison {
  display: flex;
  gap: 16px;
  margin-top: 8px;
}
.insight-comparison-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.insight-comparison-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.insight-comparison-value {
  font-size: 15px;
  font-weight: 700;
}

/* ─── Lost Leads Table ─────────────────────────────────────────────────────── */
.lost-leads-section {
  margin-top: 32px;
}
.lost-leads-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.lost-leads-title {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.lost-leads-filters {
  display: flex;
  gap: 8px;
  align-items: center;
}
.lost-leads-filter-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 11px;
  padding: 6px 10px;
  font-family: var(--font-body);
  cursor: pointer;
}
.lost-leads-filter-select:focus { outline: 2px solid var(--purple); outline-offset: 2px; }

.lost-leads-table {
  width: 100%;
  border-collapse: collapse;
}
.lost-leads-table th {
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.lost-leads-table th:hover { color: var(--text); }
.lost-leads-table th .sort-arrow { font-size: 9px; margin-left: 4px; opacity: 0.5; }
.lost-leads-table th.sorted .sort-arrow { opacity: 1; color: var(--purple); }

.lost-leads-table td {
  font-size: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--dim);
  vertical-align: middle;
}
.lost-leads-row {
  transition: background var(--transition-fast);
  cursor: pointer;
}
.lost-leads-row:hover { background: rgba(139,92,246,0.04); }
.lost-leads-row.expanded { background: rgba(59,130,246,0.04); }

.lost-lead-name { font-weight: 600; }
.lost-lead-stage-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.lost-lead-reason {
  font-size: 11px;
  color: var(--muted);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lost-lead-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ─── Lost Lead Expanded Detail ────────────────────────────────────────────── */
.lost-lead-detail {
  display: none;
  padding: 0;
}
.lost-lead-detail.visible {
  display: table-row;
}
.lost-lead-detail-inner {
  padding: 16px 20px;
  background: var(--surface);
  border-radius: var(--radius-md);
  margin: 4px 0;
}

/* Stage timeline */
.stage-timeline {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 16px;
  padding: 12px 0;
  overflow-x: auto;
}
.stage-timeline-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 80px;
}
.stage-timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
}
.stage-timeline-dot.active { background: var(--blue); border-color: var(--blue); }
.stage-timeline-dot.terminal { background: var(--red); border-color: var(--red); }
.stage-timeline-label {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
}
.stage-timeline-date {
  font-size: 9px;
  color: var(--muted);
  opacity: 0.7;
}
.stage-timeline-connector {
  flex: 1;
  height: 2px;
  background: var(--dim);
  min-width: 20px;
  margin-top: -20px;
}
.stage-timeline-connector.active { background: var(--blue); }

/* Conversation thread (mini view inside lost lead) */
.mini-thread {
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--card);
}
.mini-thread-msg {
  margin-bottom: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
}
.mini-thread-msg.inbound {
  background: rgba(59,130,246,0.08);
  border-left: 3px solid var(--blue);
  margin-right: 40px;
}
.mini-thread-msg.outbound {
  background: rgba(16,185,129,0.08);
  border-left: 3px solid var(--green);
  margin-left: 40px;
}
.mini-thread-meta {
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
}
.mini-thread-loading {
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: 12px;
}

/* ─── Recommendations ──────────────────────────────────────────────────────── */
.recommendations-section { margin-top: 32px; }
.recommendation-card {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 10px;
  backdrop-filter: blur(8px);
  transition: border-color var(--transition-fast);
}
.recommendation-card:hover { border-color: var(--border-hover); }
.recommendation-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.recommendation-icon.impact-high { background: rgba(239,68,68,0.12); color: var(--red); }
.recommendation-icon.impact-medium { background: rgba(245,158,11,0.12); color: var(--amber); }
.recommendation-icon.impact-low { background: rgba(16,185,129,0.12); color: var(--green); }
.recommendation-body { flex: 1; }
.recommendation-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
}
.recommendation-detail {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.recommendation-badges {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.impact-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.impact-badge-high { background: rgba(239,68,68,0.15); color: var(--red); }
.impact-badge-medium { background: rgba(245,158,11,0.15); color: var(--amber); }
.impact-badge-low { background: rgba(16,185,129,0.15); color: var(--green); }
.leads-affected-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(139,92,246,0.12);
  color: var(--purple);
}

/* ─── Hero KPI Cards ───────────────────────────────────────────────────────── */
.kpi-hero {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition-base);
}
.kpi-hero:hover { border-color: var(--border-hover); }
.kpi-hero::after { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; }
.kpi-hero.c-green::after { background: var(--green); }
.kpi-hero.c-blue::after { background: var(--blue); }
.kpi-hero.c-purple::after { background: var(--purple); }
.kpi-hero.c-amber::after { background: var(--amber); }
.kpi-hero.c-cyan::after { background: var(--cyan); }
.kpi-hero-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--sp-2);
}
.kpi-hero-val {
  font-size: var(--text-hero);
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.kpi-hero-sub {
  font-size: var(--text-sm);
  color: var(--muted);
  margin-top: var(--sp-2);
}
.kpi-hero-sub.up { color: var(--green); }
.kpi-hero-sub.down { color: var(--red); }

/* ─── 5-column hero grid ───────────────────────────────────────────────────── */
.g5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--sp-4); }
@media (max-width: 1024px) { .g5 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 768px) { .g5 { grid-template-columns: 1fr; } }

/* ─── Unified Navigation ──────────────────────────────────────────────────── */
.aios-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--sp-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.aios-nav-links {
  display: flex;
  gap: 2px;
}
.aios-nav-item {
  padding: 12px var(--sp-5);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-base);
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.aios-nav-item:hover { color: var(--text); background: rgba(255, 255, 255, 0.02); }
.aios-nav-item.active { color: var(--text); border-bottom-color: var(--purple); }
.aios-nav-item i[data-lucide] { width: 16px; height: 16px; }
.aios-nav-right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.aios-loc-toggle {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.aios-loc-btn {
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all var(--transition-base);
  font-family: var(--font-sans);
}
.aios-loc-btn:hover { color: var(--text); }
.aios-loc-btn.active { background: var(--purple); color: #fff; }
.aios-loc-badge {
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--purple);
  color: #fff;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ─── Report Content (shared across agent pages) ──────────────────────────── */
.report-content { line-height: 1.7; color: var(--text-secondary); }
.report-content h1 { font-size: var(--text-xl); font-weight: 800; color: var(--text); margin: var(--sp-5) 0 var(--sp-3); }
.report-content h2 { font-size: var(--text-lg); font-weight: 700; color: var(--report-accent, var(--blue)); margin: var(--sp-5) 0 var(--sp-3); }
.report-content h3 { font-size: var(--text-md); font-weight: 600; color: var(--text); margin: var(--sp-4) 0 var(--sp-2); }
.report-content p { margin-bottom: var(--sp-3); font-size: var(--text-base); }
.report-content ul, .report-content ol { padding-left: var(--sp-5); margin-bottom: var(--sp-3); }
.report-content li { margin-bottom: var(--sp-1); font-size: var(--text-base); }
.report-content blockquote {
  border-left: 3px solid var(--report-accent, var(--blue));
  padding: var(--sp-3) var(--sp-4);
  margin: var(--sp-3) 0;
  background: rgba(59, 130, 246, 0.06);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic;
  color: var(--muted);
}
.report-content table { width: 100%; border-collapse: collapse; margin: var(--sp-3) 0; font-size: var(--text-sm); }
.report-content th { text-align: left; padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); color: var(--muted); font-weight: 700; text-transform: uppercase; font-size: 10px; letter-spacing: 0.05em; }
.report-content td { padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid rgba(26, 42, 72, 0.3); }
.report-content code { background: rgba(139, 92, 246, 0.1); padding: 2px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: var(--text-sm); }
.report-content hr { border: none; border-top: 1px solid var(--border); margin: var(--sp-5) 0; }
.report-content strong { color: var(--text); font-weight: 700; }
.report-empty { text-align: center; padding: var(--sp-10) var(--sp-5); color: var(--muted); }
.report-empty-icon { font-size: 48px; margin-bottom: var(--sp-4); opacity: 0.3; }
.report-empty-title { font-size: var(--text-lg); font-weight: 700; color: var(--text); margin-bottom: var(--sp-2); }
.report-empty-sub { font-size: var(--text-sm); }

/* ─── Report History Sidebar ──────────────────────────────────────────────── */
.history-section { margin-top: var(--sp-5); }
.history-list { display: flex; flex-direction: column; gap: 2px; }
.history-item {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-base);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.history-item:hover { background: rgba(255, 255, 255, 0.03); }
.history-item.active { background: rgba(139, 92, 246, 0.08); border-left: 2px solid var(--purple); }
.history-item-name { font-size: var(--text-sm); font-weight: 600; color: var(--text); }
.history-item-date { font-size: var(--text-xs); color: var(--muted); font-variant-numeric: tabular-nums; }

/* ─── Rev by Tech Table ───────────────────────────────────────────────────── */
.tech-rev-table { width: 100%; border-collapse: collapse; }
.tech-rev-table th {
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.tech-rev-table td {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-base);
  border-bottom: 1px solid rgba(26, 42, 72, 0.3);
  font-variant-numeric: tabular-nums;
}
.tech-rev-table tr:hover td { background: rgba(255, 255, 255, 0.02); }
.tech-rev-table .tech-name { font-weight: 600; color: var(--text); }
.tech-rev-table .tech-val { font-weight: 700; }
.tech-rev-table .tech-val.revenue { color: var(--green); }

/* ─── Quick Status Bar ────────────────────────────────────────────────────── */
.quick-status {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  padding: var(--sp-3) var(--sp-4);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--sp-4);
}
.quick-status-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--muted);
}
.quick-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.quick-status-dot.healthy { background: var(--green); box-shadow: 0 0 6px rgba(16, 185, 129, 0.4); }
.quick-status-dot.warning { background: var(--amber); box-shadow: 0 0 6px rgba(245, 158, 11, 0.4); }
.quick-status-dot.error { background: var(--red); box-shadow: 0 0 6px rgba(239, 68, 68, 0.4); }

/* ─── Bucket Animations ────────────────────────────────────────────────────── */
@keyframes waterDrip {
  0%, 100% { opacity: 0.3; transform: scaleY(0.5); }
  50% { opacity: 1; transform: scaleY(1); }
}
@keyframes dripFall {
  0% { opacity: 0.9; transform: rotate(-45deg) translateY(0); }
  60% { opacity: 0.6; }
  100% { opacity: 0; transform: rotate(-45deg) translateY(12px); }
}

@media (prefers-reduced-motion: reduce) {
  .bucket-leak-drop.animated { animation: none; opacity: 0.7; }
  .bucket-inflow::after { animation: none; }
  .bucket-stage-bar-fill { transition: none; }
  .bucket-stage-fill { transition: none; }
}

@media (max-width: 768px) {
  .bucket-wrapper { flex-direction: column; }
  .bucket-container { max-width: 100%; }
  .bucket-stage-name { min-width: 80px; font-size: 10px; }
  .lost-leads-table { font-size: 11px; }
  .lost-leads-table th, .lost-leads-table td { padding: 8px 6px; }
  .insight-comparison { flex-direction: column; gap: 8px; }
}
