:root {
  --bg: #f4f7f7;
  --surface: #ffffff;
  --surface-2: #eef4f3;
  --text: #17302d;
  --muted: #5c726f;
  --line: #dbe5e3;
  --brand: #0f8a7e;
  --brand-ink: #ffffff;
  --brand-soft: #d9f1ee;
  --ok: #1f8a4c;   --ok-soft: #dcf3e5;
  --warn: #a8640a; --warn-soft: #fbecd2;
  --bad: #b3261e;  --bad-soft: #fbe0de;
  --info: #2f5fb3; --info-soft: #e1e9f8;
  --neutral-soft: #e8ecec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 40, 37, .06), 0 2px 8px rgba(16, 40, 37, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1716; --surface: #162120; --surface-2: #1c2a28; --text: #e3eeec; --muted: #94aaa6;
    --line: #2a3a38; --brand: #34b3a5; --brand-ink: #062320; --brand-soft: #173a36;
    --ok: #5fcf8e; --ok-soft: #173826; --warn: #e8a94a; --warn-soft: #3a2c12;
    --bad: #f2867d; --bad-soft: #43201d; --info: #8fb0f0; --info-soft: #1d2a45; --neutral-soft: #26302f;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); }
.brand-name { font-weight: 650; }
.brand-sub { color: var(--muted); font-size: 12px; }
.agent-status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

.shell { display: grid; grid-template-columns: 180px 1fr; min-height: calc(100vh - 57px); }
.sidenav { display: flex; flex-direction: column; gap: 4px; padding: 16px 12px; border-right: 1px solid var(--line); background: var(--surface); }
.sidenav button { text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; }
.sidenav button:hover { background: var(--surface-2); color: var(--text); }
.sidenav button.active { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
main { padding: 20px; min-width: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

/* patients */
.patients-layout { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
.patient-list { padding: 10px; position: sticky; top: 77px; max-height: calc(100vh - 100px); display: flex; flex-direction: column; }
.patient-list input { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); margin-bottom: 8px; }
.list { list-style: none; margin: 0; padding: 0; overflow: auto; }
.list li { padding: 10px; border-radius: 8px; cursor: pointer; display: grid; gap: 2px; }
.list li:hover { background: var(--surface-2); }
.list li.active { background: var(--brand-soft); }
.list .name { font-weight: 600; }
.list .meta { color: var(--muted); font-size: 12px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.detail { display: grid; gap: 16px; min-width: 0; }
.patient-head { padding: 18px 20px; display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.patient-head h1 { margin-bottom: 4px; }
.patient-head .meta { color: var(--muted); }
.facts { display: flex; gap: 24px; flex-wrap: wrap; }
.fact .label { color: var(--muted); font-size: 12px; }
.fact .value { font-weight: 650; font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 12px; }
.tabs button { border: 0; background: none; padding: 12px 10px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--brand); border-color: var(--brand); font-weight: 600; }
.tab-body { padding: 4px 0; }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-card { overflow-x: auto; }
.summary { max-width: 520px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 5px 10px; border-radius: 7px; cursor: pointer; font-size: 12px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; padding: 8px 14px; font-size: 14px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-neutral { background: var(--neutral-soft); color: var(--muted); }

.call-item, .note-item { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.call-item:last-child, .note-item:last-child { border-bottom: 0; }
.call-top { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
details summary { cursor: pointer; color: var(--brand); font-size: 12px; margin-top: 6px; }
pre.transcript { white-space: pre-wrap; background: var(--surface-2); padding: 10px; border-radius: 8px; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; }
.note-form { padding: 14px 16px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.note-form textarea { width: 100%; min-height: 70px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); resize: vertical; }
.note-form .actions { display: flex; justify-content: flex-end; }
.note-item .who { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* agenda */
.day-nav { display: flex; gap: 6px; align-items: center; }
.day-nav button, .day-nav input { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 10px; }
.day-nav button { cursor: pointer; }
.agenda { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.agenda .col { padding: 14px; }
.agenda .col h2 { margin-bottom: 10px; }
.slot { display: grid; grid-template-columns: 64px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.slot .time { font-weight: 650; font-variant-numeric: tabular-nums; }
.slot .who { font-weight: 600; cursor: pointer; }
.slot .who:hover { color: var(--brand); }
.slot .meta { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* kpis */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 13px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidenav { flex-direction: row; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 12px; overflow-x: auto; }
  main { padding: 16px; }
  .patients-layout { grid-template-columns: 1fr; }
  .patient-list { position: static; max-height: 300px; }
  .agent-status { display: none; }
}

a { color: var(--brand); }
.patients-layout > *, .detail > * { min-width: 0; }
.detail .card { overflow: hidden; }
.tab-body .table-card { overflow-x: auto; }
