:root {
  --primary: #1A56DB; --primary-light: #E8EDFB; --primary-dark: #0F3A8A;
  --surface-base: #FFFFFF; --surface-raised: #F8F8F6; --surface-sunken: #EFEFEC;
  --ink: #2C2C2A; --ink-muted: #73726C; --ink-subtle: #A3A29C;
  --border: rgba(0,0,0,0.12); --border-hover: rgba(0,0,0,0.25);
  --success-bg: #EAF3DE; --success-text: #27500A; --success-dot: #639922;
  --warning-bg: #FAEEDA; --warning-text: #633806; --warning-dot: #BA7517; --warning-border: #854F0B;
  --danger-bg: #FCEBEB; --danger-text: #791F1F; --danger-dot: #E24B4A;
  --info-bg: #E6F1FB; --info-text: #0C447C; --info-dot: #378ADD;
  --review-bg: #EEEDFE; --review-text: #3C3489; --review-dot: #7F77DD;
  --auto-bg: #E1F5EE; --auto-text: #085041; --auto-dot: #1D9E75;
  --neutral-bg: #F1EFE8; --neutral-text: #444441; --neutral-dot: #888780;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', monospace;
  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font); background: var(--surface-raised); color: var(--ink); height: 100vh; overflow: hidden; display: flex; flex-direction: column; -webkit-font-smoothing: antialiased; }

/* ═══ Topbar ═══ */
.topbar { height: 48px; background: var(--surface-base); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; flex-shrink: 0; }
.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon { width: 28px; height: 28px; border-radius: var(--radius-md); background: var(--primary); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: 700; }
.logo-text { font-size: 14px; font-weight: 600; }
.logo-sub { font-size: 11px; color: var(--ink-subtle); margin-left: 2px; }
.topbar-center { display: flex; align-items: center; gap: 10px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--surface-sunken); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: var(--ink-muted); }

/* ═══ Play/Pause ═══ */
.play-btn { display: flex; align-items: center; gap: 6px; padding: 5px 14px; border-radius: 999px; border: 1.5px solid var(--primary); background: var(--primary-light); color: var(--primary); font-family: var(--font); font-size: 12px; font-weight: 600; cursor: pointer; transition: all 150ms; }
.play-btn:hover { background: var(--primary); color: #fff; }
.play-btn.playing { background: var(--primary); color: #fff; }
.play-btn svg { width: 14px; height: 14px; }
.progress-info { font-size: 11px; color: var(--ink-subtle); font-family: var(--mono); }
.hdr-btn { font-size: 11px; padding: 5px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-base); color: var(--ink-muted); cursor: pointer; font-family: var(--font); font-weight: 500; }
.hdr-btn:hover { background: var(--surface-raised); color: var(--ink); }

/* ═══ Main Layout ═══ */
.main { flex: 1; display: flex; overflow: hidden; }

/* ═══ Three-Panel Layout ═══ */
.panel-left { width: 260px; min-width: 260px; background: var(--surface-base); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.panel-center { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.panel-right { width: 280px; min-width: 280px; background: var(--surface-base); border-left: 1px solid var(--border); overflow-y: auto; padding: 16px; }

/* ═══ Left Panel — Patient + Appointments ═══ */
.panel-section { border-bottom: 1px solid var(--border); }
.panel-section-hdr { padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; }
.panel-section-hdr h4 { font-size: 11px; font-weight: 600; color: var(--ink-subtle); text-transform: uppercase; letter-spacing: .06em; }
.panel-section-badge { font-size: 10px; padding: 1px 6px; border-radius: 999px; background: var(--surface-sunken); color: var(--ink-subtle); font-weight: 600; }

/* Patient card */
.patient-card { padding: 12px 14px; }
.patient-name { font-size: 15px; font-weight: 600; color: var(--ink); }
.patient-meta { font-size: 11px; color: var(--ink-muted); margin-top: 3px; }
.patient-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.stat-box { padding: 6px 8px; background: var(--surface-raised); border-radius: var(--radius-sm); }
.stat-label { font-size: 9px; color: var(--ink-subtle); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 14px; font-weight: 600; margin-top: 2px; }

/* Appointment list */
.appt-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.appt-item { padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); margin-bottom: 4px; cursor: pointer; transition: all 120ms; }
.appt-item:hover { background: var(--surface-raised); border-color: var(--border-hover); }
.appt-item.active { background: var(--primary-light); border-color: var(--primary); }
.appt-item-top { display: flex; justify-content: space-between; align-items: center; }
.appt-date { font-size: 12px; font-weight: 600; color: var(--ink); }
.appt-detail { font-size: 10px; color: var(--ink-muted); margin-top: 2px; }
.appt-agents { display: flex; gap: 3px; margin-top: 5px; flex-wrap: wrap; }

/* ═══ Badges ═══ */
.badge { font-size: 9px; padding: 2px 7px; border-radius: 999px; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.badge .dot { width: 4px; height: 4px; border-radius: 50%; }
.b-success { background: var(--success-bg); color: var(--success-text); } .b-success .dot { background: var(--success-dot); }
.b-info { background: var(--info-bg); color: var(--info-text); } .b-info .dot { background: var(--info-dot); }
.b-warning { background: var(--warning-bg); color: var(--warning-text); } .b-warning .dot { background: var(--warning-dot); }
.b-danger { background: var(--danger-bg); color: var(--danger-text); } .b-danger .dot { background: var(--danger-dot); }
.b-review { background: var(--review-bg); color: var(--review-text); } .b-review .dot { background: var(--review-dot); }
.b-auto { background: var(--auto-bg); color: var(--auto-text); } .b-auto .dot { background: var(--auto-dot); }
.b-neutral { background: var(--neutral-bg); color: var(--neutral-text); } .b-neutral .dot { background: var(--neutral-dot); }
.b-running { background: var(--info-bg); color: var(--info-text); animation: pulse 2s infinite; } .b-running .dot { background: var(--info-dot); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.6} }

/* ═══ Center — Event Timeline ═══ */
.timeline-hdr { padding: 10px 20px; border-bottom: 1px solid var(--border); background: var(--surface-base); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.timeline-hdr h3 { font-size: 14px; font-weight: 600; }
.timeline-hdr .meta { font-size: 11px; color: var(--ink-muted); }
.timeline { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 4px; }

/* Event bar */
.t-entry { max-width: 85%; animation: fadeIn 300ms ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.t-event { align-self: center; max-width: 100%; padding: 6px 0; text-align: center; }
.event-bar { display: flex; align-items: center; gap: 8px; justify-content: center; font-size: 11px; }
.event-bar::before, .event-bar::after { content: ''; flex: 1; max-width: 80px; height: 1px; background: var(--border); }
.event-name { font-family: var(--mono); font-size: 9px; font-weight: 600; letter-spacing: .04em; padding: 2px 8px; border-radius: 999px; }
.event-time { font-size: 9px; color: var(--ink-subtle); font-family: var(--mono); }
.ev-info .event-name { background: var(--info-bg); color: var(--info-text); }
.ev-success .event-name { background: var(--success-bg); color: var(--success-text); }
.ev-warning .event-name { background: var(--warning-bg); color: var(--warning-text); }
.ev-danger .event-name { background: var(--danger-bg); color: var(--danger-text); }
.ev-neutral .event-name { background: var(--neutral-bg); color: var(--neutral-text); }
.ev-review .event-name { background: var(--review-bg); color: var(--review-text); }
.ev-auto .event-name { background: var(--auto-bg); color: var(--auto-text); }

/* Agent message */
.t-agent { align-self: flex-start; background: var(--surface-raised); border-radius: 2px 12px 12px 12px; padding: 12px 16px; border: 1px solid var(--border); }
.agent-hdr { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.agent-ico { width: 18px; height: 18px; border-radius: 4px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 9px; font-weight: 700; }
.agent-ico.patient { background: var(--review-dot); }
.agent-ico.appointment { background: var(--info-dot); }
.agent-ico.worker { background: var(--auto-dot); }
.agent-lbl { font-size: 10px; font-weight: 600; }
.agent-lbl.patient { color: var(--review-text); }
.agent-lbl.appointment { color: var(--info-text); }
.agent-lbl.worker { color: var(--auto-text); }
.agent-ts { font-size: 9px; color: var(--ink-subtle); font-family: var(--mono); margin-left: auto; }
.agent-body { font-size: 12px; line-height: 1.6; color: var(--ink); }
.agent-body code { font-family: var(--mono); font-size: 10px; background: var(--surface-sunken); padding: 1px 4px; border-radius: 3px; color: var(--primary); }
.agent-body strong { font-weight: 600; }

/* Tool calls */
.tool-blk { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 6px; }
.tool-tog { font-size: 10px; color: var(--ink-subtle); cursor: pointer; display: flex; align-items: center; gap: 4px; user-select: none; }
.tool-tog:hover { color: var(--ink-muted); }
.tool-arr { font-size: 7px; transition: transform 120ms; display: inline-block; }
.tool-arr.open { transform: rotate(90deg); }
.tool-det { display: none; margin-top: 4px; padding: 6px 8px; background: var(--surface-sunken); border-radius: var(--radius-sm); font-family: var(--mono); font-size: 10px; line-height: 1.5; color: var(--ink-muted); }
.tool-det.open { display: block; }
.tf { color: var(--review-text); } .tr { color: var(--success-text); } .td { color: var(--ink-subtle); font-size: 9px; }

/* Result card */
.result-card { margin-top: 8px; background: var(--surface-base); border-radius: var(--radius-md); padding: 10px 12px; border: 1px solid var(--border); }
.result-card table { width: 100%; font-size: 11px; border-collapse: collapse; }
.result-card td { padding: 3px 0; }
.result-card td:first-child { color: var(--ink-muted); width: 120px; }
.result-card td:last-child { font-family: var(--mono); font-size: 10px; }

/* Human confirmation */
.confirm-card { margin-top: 8px; background: var(--warning-bg); border: 1px solid var(--warning-border); border-radius: var(--radius-md); padding: 10px 12px; }
.confirm-title { font-size: 11px; font-weight: 600; color: var(--warning-text); margin-bottom: 4px; }
.confirm-btns { display: flex; gap: 4px; margin-top: 6px; }
.confirm-btns button { font-size: 10px; padding: 4px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); cursor: pointer; font-family: var(--font); font-weight: 600; }
.btn-approve { background: var(--success-bg); color: var(--success-text); border-color: var(--success-dot); }
.btn-approve:hover { background: var(--success-dot); color: #fff; }
.btn-reject { background: var(--danger-bg); color: var(--danger-text); }

/* Human task */
.t-task { align-self: center; max-width: 90%; padding: 10px 14px; background: var(--warning-bg); border: 1px dashed var(--warning-border); border-radius: var(--radius-md); display: flex; align-items: center; gap: 10px; }
.spinner { width: 12px; height: 12px; border: 2px solid var(--warning-dot); border-top-color: transparent; border-radius: 50%; animation: spin 1s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.task-text { font-size: 11px; color: var(--warning-text); font-weight: 500; }

/* Human message */
.t-human { align-self: flex-end; background: var(--primary-light); border-radius: 12px 2px 12px 12px; padding: 12px 16px; border: 1px solid rgba(26,86,219,.15); }
.human-hdr { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.human-ico { width: 18px; height: 18px; border-radius: 50%; background: var(--primary); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 9px; font-weight: 600; }
.human-lbl { font-size: 10px; font-weight: 600; color: var(--primary-dark); }

/* Input area */
.input-area { padding: 10px 20px; border-top: 1px solid var(--border); background: var(--surface-base); flex-shrink: 0; }
.input-box { display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px; border-radius: var(--radius-lg); border: 1px solid var(--border); transition: border-color 150ms; }
.input-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,.08); }
.input-box textarea { flex: 1; border: none; outline: none; font-family: var(--font); font-size: 12px; color: var(--ink); resize: none; line-height: 1.5; max-height: 100px; background: transparent; }
.input-box textarea::placeholder { color: var(--ink-subtle); }
.send-btn { width: 28px; height: 28px; border-radius: var(--radius-sm); background: var(--primary); border: none; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.send-btn:hover { background: var(--primary-dark); }
.input-hint { font-size: 9px; color: var(--ink-subtle); margin-top: 4px; padding-left: 4px; }

/* ═══ Right Panel — Context ═══ */
.ctx-sec { margin-bottom: 16px; }
.ctx-sec h4 { font-size: 10px; font-weight: 600; color: var(--ink-subtle); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; padding-bottom: 5px; border-bottom: 1px solid var(--border); }
.ctx-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 11px; }
.ctx-row .l { color: var(--ink-muted); }
.ctx-row .v { color: var(--ink); font-weight: 500; text-align: right; max-width: 55%; font-family: var(--mono); font-size: 10px; }

/* Pipeline */
.pipeline { display: flex; flex-direction: column; }
.pipe-step { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: var(--radius-sm); font-size: 10px; color: var(--ink-muted); }
.pipe-step.done { color: var(--success-text); font-weight: 500; }
.pipe-step.act { color: var(--primary); background: var(--primary-light); font-weight: 600; }
.pipe-step.up { color: var(--ink-subtle); }
.pipe-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.pipe-step.done .pipe-dot { background: var(--success-dot); }
.pipe-step.act .pipe-dot { background: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,.12); }
.pipe-step.up .pipe-dot { background: var(--ink-subtle); opacity: .25; }
.pipe-conn { width: 1px; height: 4px; background: var(--border); margin-left: 9px; }

/* Agent list in context */
.agent-list-item { padding: 5px 8px; border-radius: var(--radius-sm); border: 1px solid var(--border); margin-bottom: 3px; font-size: 10px; }
.agent-list-item .agent-type { font-weight: 600; }

/* ═══ Chat Tabs ═══ */
.chat-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); background: var(--surface-base); flex-shrink: 0; padding: 0 20px; }
.chat-tab { padding: 8px 16px; font-size: 11px; font-weight: 500; color: var(--ink-muted); cursor: pointer; border-bottom: 2px solid transparent; transition: all 120ms; display: flex; align-items: center; gap: 5px; }
.chat-tab:hover { color: var(--ink); }
.chat-tab.active { border-bottom-color: var(--primary); color: var(--primary); font-weight: 600; }
.chat-tab .tab-ico { width: 14px; height: 14px; border-radius: 3px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 8px; font-weight: 700; }
.chat-tab .tab-ico.patient { background: var(--review-dot); }
.chat-tab .tab-ico.appointment { background: var(--info-dot); }
.chat-tab .tab-count { font-size: 9px; padding: 1px 5px; border-radius: 999px; background: var(--surface-sunken); color: var(--ink-subtle); font-weight: 600; }
.chat-tab.active .tab-count { background: var(--primary-light); color: var(--primary); }

/* Multiple timelines (hidden/shown) */
.timeline-container { flex: 1; overflow: hidden; position: relative; }
.timeline-view { position: absolute; top: 0; left: 0; right: 0; bottom: 0; overflow-y: auto; padding: 16px 20px; display: none; flex-direction: column; gap: 4px; }
.timeline-view.active { display: flex; }

/* ═══ Nav Bar (top-level Patients/Appointments) ═══ */
.nav-bar { height: 36px; background: var(--surface-sunken); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; gap: 0; flex-shrink: 0; }
.nav-bar.hidden { display: none; }
.nav-tab { padding: 6px 16px; font-size: 12px; font-weight: 500; color: var(--ink-muted); cursor: pointer; border-bottom: 2px solid transparent; transition: all 120ms; }
.nav-tab:hover { color: var(--ink); }
.nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.back-to-list { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--ink-muted); cursor: pointer; border: none; background: none; font-family: var(--font); font-weight: 500; padding: 3px 8px; border-radius: var(--radius-sm); }
.back-to-list:hover { background: var(--surface-raised); color: var(--primary); }

/* ═══ List View ═══ */
.list-view { flex: 1; overflow: auto; display: none; flex-direction: column; }
.list-view.active { display: flex; }
.list-hdr { padding: 16px 24px 0; flex-shrink: 0; }
.list-hdr h2 { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.list-hdr .subtitle { font-size: 12px; color: var(--ink-muted); margin-bottom: 14px; }
.summary-cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; margin-bottom: 14px; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.summary-card { padding: 12px 14px; border-right: 1px solid var(--border); }
.summary-card:last-child { border-right: none; }
.sc-label { font-size: 10px; color: var(--ink-muted); margin-bottom: 4px; }
.sc-value { font-size: 22px; font-weight: 600; }
.sc-sub { font-size: 10px; color: var(--ink-subtle); margin-top: 1px; }
.list-table-wrap { flex: 1; overflow: auto; padding: 0 24px 24px; }
.list-table { width: 100%; border-collapse: collapse; }
.list-table thead th { font-size: 10px; font-weight: 500; color: var(--ink-subtle); text-transform: uppercase; letter-spacing: .05em; text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface-base); z-index: 1; }
.list-table tbody tr { cursor: pointer; transition: background 80ms; border-bottom: 1px solid var(--border); }
.list-table tbody tr:hover { background: var(--surface-raised); }
.list-table tbody td { padding: 9px 10px; font-size: 12px; vertical-align: middle; }
.td-name { font-weight: 500; }
.td-sub { font-size: 10px; color: var(--ink-subtle); margin-top: 1px; }
.td-mono { font-family: var(--mono); font-size: 11px; color: var(--ink-muted); }

/* Session view hidden by default */
.session-view { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.session-view.active { display: flex; }

/* ═══ Filter Chips ═══ */
.filter-bar { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.filter-chip { font-size: 11px; padding: 4px 12px; border-radius: 999px; background: var(--surface-raised); color: var(--ink-muted); cursor: pointer; border: 1px solid transparent; font-family: var(--font); font-weight: 500; transition: all 120ms; }
.filter-chip:hover { background: var(--surface-sunken); color: var(--ink); }
.filter-chip.active { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.filter-chip .chip-count { font-size: 9px; padding: 0 4px; border-radius: 999px; background: rgba(0,0,0,.06); margin-left: 3px; }
.filter-chip.active .chip-count { background: rgba(26,86,219,.15); }

/* ═══ Settings / Demo Panel ═══ */
.settings-panel { position: fixed; top: 48px; right: 0; width: 300px; height: calc(100vh - 48px); background: var(--surface-base); border-left: 1px solid var(--border); box-shadow: -4px 0 20px rgba(0,0,0,.08); z-index: 200; display: none; flex-direction: column; overflow: hidden; }
.settings-panel.open { display: flex; }
.sp-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.sp-header h3 { font-size: 13px; font-weight: 600; }
.sp-close { width: 24px; height: 24px; border-radius: 4px; border: none; background: none; color: var(--ink-subtle); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.sp-close:hover { background: var(--surface-raised); }
.sp-body { flex: 1; overflow-y: auto; padding: 12px; }
.sp-group { margin-bottom: 14px; }
.sp-group-label { font-size: 10px; font-weight: 600; color: var(--ink-subtle); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; padding-left: 2px; }
.sp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.sp-btn { font-size: 10px; font-family: var(--mono); font-weight: 500; padding: 6px 8px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-base); color: var(--ink-muted); cursor: pointer; text-align: left; line-height: 1.3; transition: all 100ms; }
.sp-btn:hover { background: var(--surface-raised); border-color: var(--border-hover); color: var(--ink); }
.settings-toggle { font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm); border: none; background: none; color: var(--ink-muted); }
.settings-toggle:hover { background: var(--surface-raised); color: var(--ink); }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
