/* ═══ CSS Variables ═══ */
:root {
  /* Layout */
  --topbar-h: 48px;
  --sidebar-w: 200px;
  --demo-panel-w: 280px;

  /* Core palette */
  --bg: #F8F9FA;
  --surface: #FFFFFF;
  --surface-raised: #F3F4F6;
  --border: #E5E7EB;
  --border-strong: #D1D5DB;

  /* Text */
  --ink: #111827;
  --ink-muted: #6B7280;
  --ink-subtle: #9CA3AF;

  /* Primary (blue) */
  --primary: #1A56DB;
  --primary-light: #EBF5FF;
  --primary-dark: #1E429F;

  /* Concept: Events (purple) */
  --event-bg: #F5F3FF;
  --event-text: #6D28D9;
  --event-dot: #7C3AED;
  --event-border: #C4B5FD;

  /* Concept: Flows (indigo) */
  --flow-bg: #EEF2FF;
  --flow-text: #3730A3;
  --flow-dot: #4F46E5;
  --flow-border: #A5B4FC;

  /* Concept: Works (teal/emerald) */
  --work-bg: #ECFDF5;
  --work-text: #065F46;
  --work-dot: #059669;

  /* Work type colors */
  --bv-bg: #EFF6FF;        --bv-text: #1D4ED8;       --bv-dot: #3B82F6;
  --coding-bg: #F5F3FF;    --coding-text: #6D28D9;   --coding-dot: #8B5CF6;
  --claims-bg: #FFFBEB;    --claims-text: #92400E;   --claims-dot: #F59E0B;
  --denial-bg: #FFF1F2;    --denial-text: #9F1239;   --denial-dot: #F43F5E;
  --auth-bg: #F0FDF4;      --auth-text: #14532D;     --auth-dot: #22C55E;
  --intake-bg: #F0F9FF;    --intake-text: #075985;   --intake-dot: #0EA5E9;
  --encounter-bg: #FDF4FF; --encounter-text: #701A75; --encounter-dot: #C026D3;

  /* Status colors */
  --status-queued-bg: #F3F4F6;      --status-queued-text: #374151;
  --status-executing-bg: #EFF6FF;   --status-executing-text: #1D4ED8;
  --status-waiting-bg: #FFFBEB;     --status-waiting-text: #92400E;
  --status-completed-bg: #F0FDF4;   --status-completed-text: #15803D;
  --status-failed-bg: #FFF1F2;      --status-failed-text: #9F1239;

  /* Signals */
  --success-bg: #F0FDF4; --success-text: #15803D;
  --warning-bg: #FFFBEB; --warning-text: #92400E;
  --error-bg: #FFF1F2;   --error-text: #9F1239;
  --info-bg: #EFF6FF;    --info-text: #1D4ED8;

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

  /* Radius */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
}

/* ═══ Reset ═══ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); font-size: 13px; background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
button { font-family: var(--font); cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }
input, textarea { font-family: var(--font); }
table { border-collapse: collapse; }

/* ═══ App Shell ═══ */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ═══ Topbar ═══ */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  z-index: 100;
}
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
}
.logo-icon {
  width: 26px; height: 26px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.logo-sub {
  font-size: 12px;
  color: var(--ink-muted);
  font-weight: 400;
  padding-left: 8px;
  border-left: 1px solid var(--border);
  margin-left: 2px;
}
.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.back-btn {
  display: none;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--ink-muted);
  padding: 4px 8px;
  border-radius: var(--r-sm);
  transition: background 80ms;
}
.back-btn:hover { background: var(--surface-raised); }
.back-btn.visible { display: flex; }
.back-btn svg { width: 14px; height: 14px; }

/* ═══ Body Layout ═══ */
.app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ═══ Nav Tabs (top of main content) ═══ */
.nav-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0 20px;
  flex-shrink: 0;
}
.nav-tab {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 100ms;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.nav-tab:hover { color: var(--ink); }
.nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.nav-tab .tab-count {
  font-size: 10px;
  background: var(--surface-raised);
  color: var(--ink-muted);
  padding: 1px 5px;
  border-radius: 999px;
}
.nav-tab.active .tab-count {
  background: var(--primary-light);
  color: var(--primary);
}

/* ═══ Main Content ═══ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* ═══ Views (swap via display) ═══ */
.view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}
.view.active { display: flex; }

/* ═══ Shared: Page header ═══ */
.page-hdr {
  padding: 16px 20px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.page-hdr h2 { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.page-hdr p { font-size: 11px; color: var(--ink-muted); }

/* ═══ Scrollable content area ═══ */
.scroll-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ═══ Badge ═══ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 10px; font-weight: 600;
  white-space: nowrap;
}
.badge .dot {
  width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0;
}

/* ═══ Concept pills (Events/Flows/Works) ═══ */
.pill-event { background: var(--event-bg); color: var(--event-text); }
.pill-flow  { background: var(--flow-bg);  color: var(--flow-text); }
.pill-work  { background: var(--work-bg);  color: var(--work-text); }

/* ═══ Type badges ═══ */
.type-bv       { background: var(--bv-bg);        color: var(--bv-text); }
.type-coding   { background: var(--coding-bg);    color: var(--coding-text); }
.type-claims   { background: var(--claims-bg);    color: var(--claims-text); }
.type-denial   { background: var(--denial-bg);    color: var(--denial-text); }
.type-auth,
.type-prior_auth,
.type-concurrent_review,
.type-reauth { background: var(--auth-bg);      color: var(--auth-text); }
.type-intake   { background: var(--intake-bg);    color: var(--intake-text); }
.type-encounter_doc { background: var(--encounter-bg); color: var(--encounter-text); }
.type-claims_grouping,
.type-claims_scrub,
.type-claims_submit,
.type-payment_posting,
.type-secondary_billing,
.type-patient_billing { background: var(--claims-bg); color: var(--claims-text); }
.type-appeal { background: var(--denial-bg); color: var(--denial-text); }

/* ═══ Status badges ═══ */
.status-queued     { background: var(--status-queued-bg);    color: var(--status-queued-text); }
.status-executing  { background: var(--status-executing-bg); color: var(--status-executing-text); }
.status-waiting_human { background: var(--status-waiting-bg);  color: var(--status-waiting-text); }
.status-completed  { background: var(--status-completed-bg); color: var(--status-completed-text); }
.status-failed     { background: var(--status-failed-bg);    color: var(--status-failed-text); }
.status-waiting_event { background: var(--flow-bg); color: var(--flow-text); }
.status-cancelled  { background: var(--surface-raised); color: var(--ink-muted); }

/* ═══ Pulse animation for active items ═══ */
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.dot-pulse { animation: pulse-dot 1.5s ease-in-out infinite; }

/* ═══ Flash animation for new items ═══ */
@keyframes flash-in {
  from { background: #FEFCE8; }
  to   { background: transparent; }
}
.flash-new { animation: flash-in 1.2s ease-out forwards; }

/* ═══ Slide in from right ═══ */
@keyframes slide-in-right {
  from { transform: translateX(8px); opacity: 0; }
  to   { transform: translateX(0);   opacity: 1; }
}
.slide-in { animation: slide-in-right 200ms ease-out; }

/* ═══ User avatar ═══ */
.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}

/* ═══ Icon button ═══ */
.icon-btn {
  width: 28px; height: 28px;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-muted);
  transition: background 80ms, color 80ms;
}
.icon-btn:hover { background: var(--surface-raised); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }

/* ═══ Utility ═══ */
.text-muted  { color: var(--ink-muted); }
.text-subtle { color: var(--ink-subtle); }
.mono        { font-family: var(--mono); }
.ellipsis    { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
