/* Painel ap-doctor — casca clara. Azul no lugar do verde.
   Layout dos mockups (sidebar 240px, topo 76px, cartões 14px). Sem estilo em linha: CSP style-src 'self'. */
:root {
  --brand-700: #164e9c;
  --brand-600: #1d63c1;
  --brand-500: #2879e3;
  --brand-100: #e8f1ff;
  --brand-050: #f5f9ff;
  --ink: #101828;
  --muted: #475467;
  --subtle: #667085;
  --border: #dfe5ee;
  --line: #edf1f6;
  --canvas: #f6f8fb;
  --side: #fbfcfe;
  --card: #fff;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --bg: var(--canvas);
  --fg: var(--ink);
  --accent: var(--brand-600);
  --banner: var(--brand-100);
  --banner-fg: var(--brand-700);
  --focus: var(--brand-600);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .04);
  --tap: 44px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 15px;
  background: var(--canvas);
  color: var(--ink);
  line-height: 1.5;
}
a { color: var(--brand-700); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0 0 8px; }
code { font-size: .875em; background: var(--brand-050); padding: 1px 5px; border-radius: 6px; }

.ico {
  width: 20px; height: 20px; flex: 0 0 auto;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}
.skip { position: absolute; left: -9999px; top: 0; }
.skip:focus { left: 0; z-index: 9; padding: .5rem 1rem; background: var(--brand-100); color: var(--ink); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- casca ---------- */
.banner {
  background: var(--banner); color: var(--banner-fg);
  margin: 0; padding: 6px 16px; font-size: 13px; font-weight: 600;
}
.ops-list {
  list-style: none; display: flex; flex-wrap: wrap; gap: 4px 20px;
  margin: 0; padding: 6px 16px; font-size: 13px; color: var(--muted);
  background: #fff; border-bottom: 1px solid var(--border);
}
.ops-list span { color: var(--ink); font-weight: 600; }
.panel-layout { display: flex; min-height: 100vh; align-items: stretch; }
.panel-nav {
  flex: 0 0 240px; width: 240px;
  background: var(--side); border-right: 1px solid var(--border);
  padding: 20px 12px 16px; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink); font-weight: 700; font-size: 22px; letter-spacing: -.01em;
  padding: 4px 10px 24px; margin: 0;
}
.brand:hover { text-decoration: none; }
.brand .ico { width: 30px; height: 30px; color: var(--brand-600); stroke-width: 1.6; }
.panel-nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; flex: 1; gap: 4px; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--tap); padding: 10px 12px; border-radius: 10px;
  color: var(--ink); font-size: 15.5px;
}
.nav-link .ico { width: 22px; height: 22px; color: var(--muted); }
.nav-link span:first-of-type { flex: 1; }
.nav-link:hover { background: var(--brand-050); text-decoration: none; }
.panel-nav li.active .nav-link { background: var(--brand-100); color: var(--brand-700); font-weight: 600; }
.panel-nav li.active .nav-link .ico { color: var(--brand-700); }
.nav-badge, .dot {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
  background: var(--brand-700); color: #fff; border-radius: 99px; font-size: 12px; font-weight: 600;
}
.nav-divider { height: 1px; margin: auto 8px 12px; background: var(--border); list-style: none; }
.panel-column { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

/* Barra lateral: busca por cima de "Configurações"; "Sair" à direita de "Configurações". */
.nav-search { margin: 0 0 8px; }
.search { position: relative; display: flex; align-items: center; }
.search .ico { position: absolute; left: 12px; width: 18px; height: 18px; color: var(--subtle); }
.search input {
  width: 100%; height: 40px; border: 1px solid var(--border); border-radius: 10px;
  padding: 0 12px 0 38px; background: #fff; color: var(--ink); font: inherit; font-size: 14px;
}
.search input::placeholder { color: var(--subtle); }
.nav-split { display: flex; align-items: center; gap: 4px; }
.nav-split .nav-link { flex: 1 1 auto; min-width: 0; }
.nav-split .logout { flex: 0 0 auto; }
.avatar {
  display: inline-grid; place-items: center; flex: 0 0 auto;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--brand-100); color: var(--brand-700); font-weight: 700; font-size: 15px;
}
.avatar .ico { width: 22px; height: 22px; }
.avatar-lg { width: 52px; height: 52px; font-size: 18px; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; padding: 0;
  border: 1px solid transparent; border-radius: 10px; background: none; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--danger-bg); color: var(--danger); }
.logout { margin: 0; }
.nav-toggle, .nav-open { position: absolute; left: -9999px; }

/* ---------- área principal ---------- */
.panel-main { flex: 1 1 auto; padding: 28px 32px 48px; width: 100%; max-width: 1360px; }
.crumbs { color: var(--subtle); font-size: 14px; margin: 0 0 6px; }
.panel-main > h1, .page-head h1 { font-size: 30px; font-weight: 700; letter-spacing: -.01em; margin: 0 0 6px; }
.page-head { margin-bottom: 4px; }
.date { color: var(--muted); font-size: 15px; margin: 0 0 6px; }
.greet { font-size: 34px; }
.lead { color: var(--muted); font-size: 16px; max-width: 70ch; margin: 0 0 24px; }
section + section, .card + .card, .card + section, section + .card { margin-top: 16px; }

/* ---------- cartões ---------- */
.card, .kpi, .vm-section {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px;
}
.card-head {
  display: flex; align-items: center; gap: 12px;
  margin: -2px 0 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); min-height: 44px;
}
.card-head .ico { width: 24px; height: 24px; color: var(--brand-600); }
.card-head h2 { font-size: 18px; font-weight: 600; flex: 1; }
.more { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 500; color: var(--brand-700); }
.more .ico { width: 16px; height: 16px; }
.card-wide { margin-top: 16px; }
.card > h2, aside > h2, article > h2, .vm-section > h2, section > h2 { font-size: 18px; font-weight: 600; margin: 0 0 12px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { display: flex; flex-direction: column; gap: 6px; min-height: 164px; color: inherit; }
a.kpi:hover { border-color: var(--brand-500); text-decoration: none; }
.kpi-ico { color: var(--brand-600); }
.kpi-ico .ico { width: 30px; height: 30px; stroke-width: 1.6; }
.kpi h2 { font-size: 16px; font-weight: 600; color: var(--ink); margin: 0; }
.kpi-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.kpi-num { font-size: 34px; font-weight: 700; margin: 0; color: var(--ink); letter-spacing: -.02em; line-height: 1.15; }
.kpi-num.kpi-na { font-size: 18px; font-weight: 600; color: var(--muted); letter-spacing: 0; padding: 8px 0 4px; }
.kpi > p:not([class]) { font-size: 20px; font-weight: 600; color: var(--muted); margin: 6px 0 0; }
.kpi-note { color: var(--muted); font-size: 14px; margin: auto 0 0; }
.kpi p.muted, .kpi .muted { margin-top: auto; }
.badge, .chip {
  display: inline-flex; align-items: center; gap: 4px; width: fit-content;
  background: var(--brand-100); color: var(--brand-700);
  border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 600; margin: 0;
}
.chip-ok { background: var(--ok-bg); color: var(--ok); }
.chip-warn { background: var(--warn-bg); color: var(--warn); }
.chip-danger { background: var(--danger-bg); color: var(--danger); }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 6px 0 2px; }
.bar span { display: block; height: 100%; background: var(--brand-600); border-radius: 99px; }
.bar .p0 { width: 0; } .bar .p1 { width: 10%; } .bar .p2 { width: 20%; }
.bar .p3 { width: 30%; } .bar .p4 { width: 40%; } .bar .p5 { width: 50%; }
.bar .p6 { width: 60%; } .bar .p7 { width: 70%; } .bar .p8 { width: 80%; }
.bar .p9 { width: 90%; } .bar .p10 { width: 100%; }

.dash-split { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 16px; margin-top: 16px; }
.dash-split > .card { display: flex; flex-direction: column; }

/* estado vazio */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 20px 12px 16px; gap: 4px; }
.empty-ico { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--brand-050); color: var(--brand-600); margin-bottom: 6px; }
.empty-ico .ico { width: 26px; height: 26px; }
.empty-title { font-weight: 600; margin: 0; }
.empty-text { color: var(--muted); font-size: 14px; max-width: 46ch; margin: 0; }
.placeholder { color: var(--muted); }
.card.placeholder { padding: 32px; }
.skel { min-height: 72px; background: linear-gradient(90deg, var(--brand-050), #fff, var(--brand-050)); border-radius: 12px; color: var(--muted); padding: 12px; }
.skel-rows { display: grid; gap: 8px; }

/* linha do tempo */
.who-row { display: flex; align-items: center; gap: 14px; padding: 4px 0 16px; border-bottom: 1px solid var(--line); }
.who { display: flex; flex-direction: column; margin: 0; flex: 1; }
.who strong { font-size: 17px; }
.who span { color: var(--muted); font-size: 14px; }
.tl { list-style: none; margin: 8px 0 0; padding: 0; }
.tl li { position: relative; display: flex; align-items: flex-start; gap: 16px; padding: 14px 0 14px 4px; border-bottom: 1px solid var(--line); }
.tl li:last-child { border-bottom: 0; }
.tl li::before { content: ""; position: absolute; left: 10px; top: 32px; bottom: -14px; width: 2px; background: var(--border); }
.tl li:last-child::before { display: none; }
.tl-dot { flex: 0 0 14px; width: 14px; height: 14px; margin-top: 4px; border-radius: 50%; border: 2px solid var(--border); background: #fff; position: relative; z-index: 1; }
.tl li:first-child .tl-dot { background: var(--brand-600); border-color: var(--brand-600); }
.tl-body { flex: 1; display: flex; flex-direction: column; }
.tl-body span { color: var(--muted); font-size: 14px; }
.tl-open { font-size: 14px; }

/* resumo IA */
.sum { display: flex; align-items: center; gap: 16px; background: var(--brand-050); border-radius: 12px; padding: 16px 18px; margin-bottom: 8px; }
.sum-ring { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; border: 3px solid var(--brand-600); color: var(--brand-600); flex: 0 0 auto; }
.sum-ring.busy { border-color: var(--brand-100); border-top-color: var(--brand-600); }
.sum-ring .ico { width: 26px; height: 26px; stroke-width: 2.2; }
.sum-title { font-size: 17px; font-weight: 600; margin: 0; }
.sum-sub { color: var(--muted); font-size: 14px; margin: 0; }
.steps { list-style: none; margin: 0 0 14px; padding: 0; counter-reset: step; }
.steps li { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.steps li:last-child { border-bottom: 0; }
.step-mark { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--line); color: #fff; flex: 0 0 auto; }
.steps li.done .step-mark { background: var(--brand-100); color: var(--brand-700); }
.step-mark .ico { width: 15px; height: 15px; stroke-width: 2.5; }
.summary .steps { counter-reset: step; }
.summary .steps li { align-items: flex-start; counter-increment: step; }
.summary .steps li::before {
  content: counter(step); display: grid; place-items: center; flex: 0 0 28px; height: 28px;
  border-radius: 50%; background: var(--brand-100); color: var(--brand-700); font-weight: 700; font-size: 14px;
}

/* atividade */
.acts { list-style: none; margin: 0; padding: 0; }
.acts > li { border-bottom: 1px solid var(--line); }
.acts > li:last-child { border-bottom: 0; }
.acts a, .acts .act {
  display: grid; grid-template-columns: 28px minmax(140px, 1fr) minmax(0, 2.2fr) auto;
  align-items: center; gap: 16px; min-height: 52px; padding: 8px 6px; border-radius: 10px; color: inherit;
}
.acts a:hover { background: var(--brand-050); text-decoration: none; }
.acts .ico { color: var(--brand-600); width: 22px; height: 22px; }
.acts strong { font-size: 14.5px; }
.acts span { color: var(--muted); font-size: 14px; }
.acts time { color: var(--muted); font-size: 14px; white-space: nowrap; }
.acts form { display: inline; }

/* ---------- botões e formulários ---------- */
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: 10px; font: inherit; font-weight: 600; font-size: 14.5px;
  border: 1px solid var(--border); background: #fff; color: var(--ink); cursor: pointer; text-decoration: none;
}
.btn:hover, button:hover { border-color: var(--brand-500); text-decoration: none; }
.btn { border-color: var(--brand-600); color: var(--brand-700); }
.btn-primary, .wa-demo-send, .login-form button[type=submit] { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.btn-primary:hover { background: var(--brand-700); }
.btn-ghost { display: flex; width: 100%; margin-top: auto; }
.btn-soft { background: var(--brand-050); border-color: var(--brand-100); color: var(--brand-700); width: 100%; }
.btn .ico, button .ico { width: 18px; height: 18px; }
button[disabled], .btn[disabled] { opacity: .55; cursor: not-allowed; }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--border); border-radius: 10px; min-height: 42px; padding: 8px 12px;
}
input:disabled, select:disabled, textarea:disabled { background: var(--side); color: var(--subtle); }
textarea { width: 100%; resize: vertical; }
label { display: inline-flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.note {
  display: flex; gap: 8px; align-items: flex-start;
  background: var(--brand-050); border: 1px solid var(--brand-100); color: var(--brand-700);
  border-radius: 10px; padding: 10px 14px; font-size: 14px; margin: 0 0 12px;
}
.note::before { content: "i"; flex: 0 0 18px; height: 18px; border-radius: 50%; border: 1.5px solid currentColor; display: grid; place-items: center; font: 700 11px/1 serif; margin-top: 1px; }
.note-danger { background: var(--danger-bg); border-color: #fecdca; color: var(--danger); }
/* Aviso de conclusão: flutua no topo, ao centro, e some sozinho (só CSS; as páginas Demo não têm scripts inline). */
.toast {
  position: fixed; top: 16px; left: 50%; z-index: 50; margin: 0;
  width: max-content; max-width: min(560px, calc(100vw - 32px));
  box-shadow: 0 10px 28px rgba(16, 24, 40, .16); pointer-events: none;
  animation: toast-life 4.5s ease forwards;
}
@keyframes toast-life {
  0% { opacity: 0; transform: translate(-50%, -10px); }
  7% { opacity: 1; transform: translate(-50%, 0); }
  85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -10px); visibility: hidden; }
}
@media (prefers-reduced-motion: reduce) {
  @keyframes toast-life { 0%, 90% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, 0); visibility: hidden; } }
}
.muted { display: block; color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.cadastro, .count, .conn { color: var(--muted); font-size: 14px; }
.form-errors { border: 1px solid #fecdca; background: var(--danger-bg); color: var(--danger); padding: 12px 16px 12px 32px; border-radius: 12px; }
.job-progress { border-left: 4px solid var(--brand-600); background: var(--brand-050); padding: 12px 16px; border-radius: 0 12px 12px 0; margin: 16px 0; }
.req-id { font-size: 12px; color: var(--subtle); margin-top: 24px; }
details { border: 1px solid var(--border); border-radius: 12px; background: #fff; padding: 12px 16px; margin: 8px 0; }
summary { font-weight: 600; cursor: pointer; }

/* abas (sub-navegação) */
.tabs, .audit-tabs, .cost-tabs, .set-sub, .pt-links ul {
  display: flex; flex-wrap: wrap; gap: 4px 6px; margin: 0 0 20px; padding: 0;
  border-bottom: 1px solid var(--border); list-style: none;
}
.tabs a, .audit-tabs a, .cost-tabs a, .set-sub a, .pt-links a {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px;
  color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover, .audit-tabs a:hover, .cost-tabs a:hover, .set-sub a:hover, .pt-links a:hover { color: var(--brand-700); text-decoration: none; background: var(--brand-050); border-radius: 8px 8px 0 0; }
.tabs a[aria-current], .pt-links a[aria-current] { color: var(--brand-700); border-bottom-color: var(--brand-600); font-weight: 600; }
.pt-links { margin: 0 0 16px; }

/* tabelas */
.pt-table, .vm-table { width: 100%; border-collapse: collapse; background: #fff; }
.pt-table { table-layout: fixed; }
.pt-table th, .pt-table td, .vm-table td { text-align: left; padding: 14px 10px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.pt-table th { font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--subtle); font-weight: 600; background: var(--side); }
.pt-table td:first-child a { font-weight: 600; }
.pt-table tbody tr:hover { background: var(--brand-050); }
.pt-table .pt-links ul { border: 0; gap: 4px; margin: 0; }
.pt-table .pt-links a { min-height: 28px; padding: 0 8px; font-size: 12.5px; border: 1px solid var(--border); border-radius: 999px; margin: 0; }
.table-card { padding: 0; overflow: hidden; }
.table-card .card-head { margin: 0; padding: 18px 22px; }
.empty-table { color: var(--muted); font-style: italic; }
.pager { display: flex; justify-content: flex-end; gap: 12px; padding: 14px 22px; }

.toolbar, .pt-tools {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin: 16px 0;
}
.pt-tools label:first-child { flex: 1 1 260px; }
.pt-tools label:first-child input { width: 100%; }

/* ---------- páginas ---------- */
.split-2, .sum-split, .audit-split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: stretch; margin-top: 16px; }
.sum-split > section, .sum-split > aside, .audit-split > article, .audit-split > aside,
.summary > section, .msg-grid > section, .msg-grid > aside {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px;
}
.sum-list { list-style: none; padding: 0; margin: 0; }
.sum-list li { padding: 12px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.sum-list li:last-child { border-bottom: 0; }
.summary > p:not(.lead):not(.note), .settings .set-body:not(.card) > p, .audit > p:not(.lead):not(.note),
.costs > p:not(.lead):not(.note), .messages > p:not(.lead):not(.note), .help > p:not(.lead):not(.note) {
  background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; margin: 0 0 10px;
}
.summary ul:not([class]) { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 0 0 12px; }
.summary ul:not([class]) li, .cost-prices li { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 10px 16px; font-weight: 600; }
.cost-prices { list-style: none; padding: 0; display: grid; gap: 8px; }
.set-grid, .help-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.set-card {
  display: flex; flex-direction: column; gap: 6px; background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-height: 140px; color: inherit;
}
.set-card .ico { width: 26px; height: 26px; color: var(--brand-600); }
.set-card h2 { font-size: 16px; font-weight: 600; margin: 4px 0 0; }
.set-card p { margin: 0; color: var(--muted); font-size: 14px; }
.set-card:hover, .set-card:focus-visible { border-color: var(--brand-500); text-decoration: none; }
.set-body { margin-top: 8px; }
.help-foot { margin-top: 24px; color: var(--muted); font-size: 14px; }
.settings > label, .help > label, .patients > label, .messages label { margin: 0 0 16px; }

/* mensagens */
.msg-grid, .wa-demo-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr) 320px; gap: 16px; align-items: start; margin-top: 16px; }
.msg-list, .msg-lines, .wa-demo-peers, .wa-demo-sync { list-style: none; padding: 0; margin: 0; }
.msg-list a { display: block; padding: 12px; border-radius: 12px; color: inherit; }
.msg-list a:hover { background: var(--brand-050); text-decoration: none; }
.msg-lines li { background: var(--brand-050); border-radius: 14px; padding: 10px 14px; margin: 8px 0; overflow-wrap: anywhere; max-width: 72%; }
.wa-demo-banner { border-radius: 10px; margin-bottom: 12px; }
.wa-demo-toolbar { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 10px 16px; }
.wa-demo-toolbar p { margin: 0; }
.wa-demo-sidebar, .wa-demo-thread, .wa-demo-context {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
.wa-demo-sidebar label { display: flex; margin-bottom: 12px; }
.wa-demo-search { width: 100%; }
.wa-demo-peer {
  display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 10px; border-radius: 12px;
  color: inherit; font-weight: 500;
}
.wa-demo-peer:hover { background: var(--brand-050); text-decoration: none; }
.wa-demo-peer.active { background: var(--brand-100); color: var(--brand-700); font-weight: 600; }
.wa-demo-peer .avatar { width: 40px; height: 40px; font-size: 14px; }
.wa-demo-peer .nav-badge { margin-left: auto; }
.wa-demo-heading { display: flex; align-items: center; gap: 12px; font-size: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--line); margin: 0 0 8px; }
.wa-demo-history { display: flex; flex-direction: column; min-height: 320px; max-height: 60vh; overflow-y: auto; padding: 8px 4px; }
.wa-demo-day { align-self: center; color: var(--muted); font-size: 12.5px; background: var(--side); border: 1px solid var(--border); border-radius: 999px; padding: 2px 12px; margin: 12px 0 6px; }
.wa-demo-bubble {
  background: #fff; border: 1px solid var(--border); border-radius: 14px 14px 14px 4px;
  padding: 10px 14px; margin: 6px 0; max-width: 70%; align-self: flex-start; overflow-wrap: anywhere;
}
.wa-demo-bubble.outbound { align-self: flex-end; background: var(--brand-100); border-color: var(--brand-100); border-radius: 14px 14px 4px 14px; }
.wa-demo-bubble .muted { display: inline; font-size: 12px; margin-left: 6px; }
.wa-demo-audio, .wa-demo-image { display: inline-flex; gap: 6px; font-weight: 600; color: var(--brand-700); }
.wa-demo-bubble audio { display: block; max-width: 100%; height: 34px; margin: 6px 0; }
.wa-demo-composer { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px; }
.wa-demo-composer label { grid-column: 1; }
.wa-demo-composer .note { grid-column: 1 / -1; }
.wa-demo-composer textarea { min-height: 48px; }
.wa-demo-context h2 { font-size: 16px; margin: 16px 0 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.wa-demo-context h2:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.wa-demo-context form { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.wa-demo-context .acts { display: grid; gap: 8px; }
.wa-demo-context .acts li { border: 0; }
.wa-demo-context .acts button { width: 100%; }
.wa-demo-sync li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.inline-form { display: inline; }

/* login e páginas públicas */
.public { max-width: none; min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.public-card {
  width: min(560px, 100%); background: #fff; border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow); padding: 32px;
}
.public-card .brand { padding: 0 0 20px; }
.public-back { margin-top: 20px; }
.login-split { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 32px; width: min(1180px, 100%); align-items: center; }
.login-hero {
  background: linear-gradient(160deg, var(--brand-050), #fff 60%, var(--brand-100));
  border: 1px solid var(--border); border-radius: 20px; padding: 40px; min-height: 560px;
}
.login-hero .brand { font-size: 22px; padding: 0 0 28px; }
.hero-title { font-size: 40px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 14px; max-width: 14ch; }
.hero-lead { color: var(--muted); font-size: 17px; max-width: 44ch; margin: 0 0 28px; }
.features { list-style: none; padding: 0; margin: 0; display: grid; gap: 22px; }
.features li, .secure { display: flex; gap: 16px; align-items: flex-start; }
.features div, .secure p { display: flex; flex-direction: column; margin: 0; }
.features strong { font-size: 16.5px; }
.features span, .secure span { color: var(--muted); font-size: 14.5px; }
.feat-ico { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 12px; background: var(--brand-100); color: var(--brand-700); flex: 0 0 auto; }
.feat-ico .ico { width: 26px; height: 26px; }
.login.card { padding: 40px; border-radius: 20px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { font-size: 32px; font-weight: 700; letter-spacing: -.01em; }
.login .lead { margin-bottom: 8px; }
.login form { display: flex; flex-direction: column; gap: 8px; margin: 0; }
.login form + form { margin-top: 4px; }
.login form button { width: 100%; min-height: 50px; font-size: 16px; }
.login-form label { font-size: 14.5px; color: var(--ink); margin-top: 6px; }
.field { position: relative; display: flex; align-items: center; }
.field .ico { position: absolute; left: 14px; color: var(--subtle); }
.field input { width: 100%; min-height: 50px; padding-left: 46px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; margin: 10px 0 2px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.login .btn-soft { min-height: 50px; font-size: 15.5px; }
.secure { border-top: 1px solid var(--line); padding-top: 18px; margin-top: 8px; }
.secure .feat-ico { width: 44px; height: 44px; }

/* página de ViewModel (/apd/api/dispatch?format=html) */
.vm-section { margin-top: 16px; }
.field-key { color: var(--muted); font-weight: 600; }
.ops-form { display: inline-flex; margin: 0 8px 8px 0; }
.vm-messages p { background: var(--brand-050); border-radius: 10px; padding: 10px 14px; }
.pagination { color: var(--muted); font-size: 14px; margin-top: 12px; }

/* peças partilhadas das páginas */
.page-actions, .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 0 0 16px; }
.actions, * + .page-actions { margin-top: 16px; }
.page-actions .muted { display: inline; }
.actions .muted { display: inline; }
.status-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.status-list { list-style: none; margin: 0; padding: 0; }
.status-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.status-list li:last-child { border-bottom: 0; }
.tabs-sub { border-bottom: 0; gap: 8px; }
.tabs-sub a { min-height: 36px; border: 1px solid var(--border); border-radius: 999px; background: #fff; margin: 0; font-size: 14px; }
.tabs-sub a:hover { border-radius: 999px; }
.tabs-sub a[aria-current] { background: var(--brand-100); border-color: var(--brand-100); color: var(--brand-700); }
.set-body.card > p { margin: 0; padding: 12px 0; border-bottom: 1px solid var(--line); }
.set-body.card > p:last-child { border-bottom: 0; }
.set-card .chip { margin-top: auto; }
.help-hero { text-align: center; padding: 28px; margin-bottom: 8px; }
.help-hero h2 { font-size: 22px; margin-bottom: 14px; }
.help-hero label { display: flex; max-width: 640px; margin: 0 auto 12px; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; margin: 0; }
.chips .muted { display: inline; }
.link-list { list-style: none; margin: 16px 0; padding: 8px 22px; }
.link-list li { border-bottom: 1px solid var(--line); }
.link-list li:last-child { border-bottom: 0; }
.link-list a { display: flex; align-items: center; min-height: 48px; font-weight: 500; }
.prose p { max-width: 75ch; }
.levels { list-style: none; padding: 0; margin: 4px 0 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.levels li { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; border: 1px solid var(--border); border-radius: 12px; padding: 14px 8px; }
.levels li:last-child { border-color: var(--brand-600); background: var(--brand-050); }
.levels strong { font-size: 16px; }
.levels .muted { font-size: 12.5px; }
.stars { display: inline-flex; gap: 1px; color: var(--border); }
.stars .ico { width: 16px; height: 16px; fill: currentColor; stroke-width: 1; }
.stars .on { color: var(--brand-600); }
.pt-who { display: flex; align-items: flex-start; gap: 10px; }
.pt-who .avatar { width: 36px; height: 36px; font-size: 13px; }
.pt-who > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.pt-table td.na { color: var(--subtle); font-size: 13.5px; }
.pt-table th:first-child { width: 24%; }
.pt-table th:last-child { width: 30%; }
.msg-row { display: flex; align-items: center; gap: 12px; }
.msg-row .avatar { width: 40px; height: 40px; }
.msg-who { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; min-width: 0; }
.msg-who .muted { width: 100%; overflow: hidden; text-overflow: ellipsis; }
.msg-grid > section > label { display: flex; margin-bottom: 12px; }
.msg-grid > section > label input { width: 100%; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.composer textarea { min-height: 48px; }
.wa-demo-heading > span:last-child { display: flex; flex-direction: column; line-height: 1.3; }
.wa-demo-heading .conn { font-size: 13px; font-weight: 400; }
.elig { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 14px; color: var(--muted); }

/* caixa do médico (conta demo) */
.note-ok { background: var(--ok-bg); border-color: #abefc6; color: var(--ok); }
.inline-form { display: inline-flex; margin: 0; }
.status-row .inline-form { margin-left: auto; }
.inbox-grid { grid-template-columns: 330px minmax(0, 1fr) 280px; }
.inbox-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.inbox-item { display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 12px; color: inherit; border-left: 3px solid transparent; }
.inbox-item:hover { background: var(--brand-050); text-decoration: none; }
.inbox-item.active { background: var(--brand-100); border-left-color: var(--brand-600); }
.inbox-item .avatar { width: 42px; height: 42px; font-size: 14px; }
.inbox-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.inbox-top, .inbox-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.inbox-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-top time { font-size: 12.5px; color: var(--subtle); white-space: nowrap; }
.inbox-preview { font-size: 13.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.inbox-list li, .inbox-top, .inbox-bottom, .inbox-top strong { min-width: 0; }
.msg-grid.inbox-grid > section, .msg-grid.inbox-grid > aside { margin-top: 0; }
.msg-grid > section.inbox-thread { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.inbox-head { display: flex; align-items: center; gap: 14px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.inbox-head h2 { font-size: 18px; margin: 0; }
.inbox-head .muted { margin: 0; }
.inbox-history { display: flex; flex-direction: column-reverse; overflow-y: auto; max-height: 60vh; min-height: 320px; background: var(--brand-050); padding: 14px 20px; }
.inbox-history-in { display: flex; flex-direction: column; gap: 6px; }
.inbox-day { align-self: center; font-size: 12.5px; color: var(--muted); background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 2px 12px; margin: 8px 0 4px; }
.inbox-msg { display: flex; }
.inbox-msg.out { justify-content: flex-end; }
.inbox-bubble { max-width: 72%; background: #fff; border: 1px solid var(--border); border-radius: 14px 14px 14px 4px; padding: 8px 12px 6px; }
.inbox-msg.out .inbox-bubble { background: var(--brand-100); border-color: #c3d8fb; border-radius: 14px 14px 4px 14px; }
.inbox-msg.pending .inbox-bubble { border-style: dashed; }
.inbox-bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.inbox-meta { display: flex; justify-content: flex-end; align-items: center; gap: 8px; font-size: 11.5px; color: var(--subtle); margin-top: 4px; }
.inbox-meta .chip { font-size: 11.5px; padding: 1px 8px; }
.inbox-retry { margin-top: 6px; }
.inbox-retry button { min-height: 34px; font-size: 13px; }
.inbox-composer { display: flex; gap: 10px; align-items: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); }
.inbox-composer textarea { flex: 1; min-height: 46px; }
.inbox-hint { padding: 0 16px 12px; margin: 0; font-size: 12px; }
@media (max-width: 1279px) and (min-width: 1024px) {
  .msg-grid.inbox-grid { grid-template-columns: 260px minmax(0, 1fr) 240px; }
  .msg-grid.inbox-grid > aside { grid-column: auto; }
}
@media (max-width: 1023px) { .inbox-grid { grid-template-columns: 260px minmax(0, 1fr); } }
@media (max-width: 767px) { .inbox-grid { grid-template-columns: 1fr; } }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto; } }

@media (max-width: 1279px) {
  .msg-grid, .wa-demo-layout { grid-template-columns: 280px minmax(0, 1fr); }
  .msg-grid > aside, .wa-demo-context { grid-column: 1 / -1; }
}
@media (max-width: 1199px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sum-split, .audit-split, .split-2, .dash-split { grid-template-columns: 1fr; }
  .set-grid, .help-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .levels { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .login-split { grid-template-columns: 1fr; }
  .login-hero { min-height: 0; }
}
@media (max-width: 767px) {
  .panel-layout { flex-direction: column; }
  .nav-open {
    position: static; display: inline-flex; align-items: center; min-height: 44px; margin: 8px 16px;
    color: var(--brand-700); font-weight: 600;
  }
  .panel-nav { display: none; flex-basis: auto; width: 100%; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--border); }
  .nav-toggle:checked ~ .panel-layout .panel-nav { display: flex; }
  .msg-grid, .wa-demo-layout, .set-grid, .help-grid, .levels { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { min-height: 0; padding: 14px; }
  .kpi-num { font-size: 26px; }
  .kpi-num.kpi-na { font-size: 14.5px; }
  .pt-table thead { display: none; }
  .pt-table, .pt-table tbody, .pt-table tr, .pt-table td { display: block; width: 100%; }
  .pt-table tr { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 12px; background: #fff; }
  .panel-main { padding-left: 16px; padding-right: 16px; }
  .acts a, .acts .act { grid-template-columns: 24px 1fr; }
  .acts a span, .acts .act span, .acts time { grid-column: 2; }
  .login-hero { display: none; }
  .login.card, .public-card { padding: 24px; }
  .greet { font-size: 28px; }
}

/* Login: diálogo de erro de credenciais (nativo, sem JavaScript) */
.login-dialog[open] {
  position: fixed; inset: 0; margin: auto; z-index: 50; width: min(420px, calc(100vw - 32px)); height: fit-content;
  padding: 22px 24px; border: 1px solid var(--border); border-radius: 14px; background: var(--card); color: var(--ink);
  box-shadow: 0 0 0 100vmax rgba(15, 23, 42, .45), 0 20px 40px rgba(15, 23, 42, .25);
}
.login-dialog h2 { margin: 0 0 8px; font-size: 18px; color: var(--danger); }
.login-dialog p { margin: 0 0 16px; color: var(--fg); }
.login-dialog form { display: flex; justify-content: flex-end; margin: 0; }

/* ---------------- Cadastro de pacientes ---------------- */
.pt-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 0 0 12px; }
.pt-head .lead { margin: 0; }
.pt-head .btn { display: inline-flex; align-items: center; gap: 8px; width: auto; }
/* Diálogo sem JavaScript: a página /pacientes/novo já vem com ele aberto, por cima da lista. */
.modal-layer {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgba(16, 24, 40, .45);
}
.modal {
  position: static; margin: 0; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--ink);
  padding: 22px 24px; box-shadow: 0 24px 48px rgba(16, 24, 40, .22);
}
.modal-form { display: flex; flex-direction: column; gap: 14px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.modal-head h2 { margin: 0 0 2px; font-size: 20px; }
.modal-head .muted { margin: 0; }
.modal-head .icon-btn:hover { background: var(--brand-050); color: var(--ink); }
.modal-form label, .data-form label { width: 100%; }
.modal-form input, .modal-form select, .data-form input, .data-form select, .data-form textarea { width: 100%; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.modal-foot .btn-ghost { width: auto; margin: 0; }
[aria-invalid="true"] { border-color: var(--danger) !important; box-shadow: 0 0 0 3px var(--danger-bg); }
.data-form { display: flex; flex-direction: column; gap: 16px; }
.data-form fieldset { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 18px 20px; }
.data-form legend { font-weight: 700; font-size: 15px; padding: 0 6px; }
.form-actions { display: flex; justify-content: flex-end; }
@media (max-width: 767px) {
  .modal { padding: 18px 16px; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn, .modal-foot button { width: 100%; justify-content: center; }
}

/* Sincronizar conversas: só o ícone, no cabeçalho de "Conversas" */
.card-head .inline-form { margin: 0; }
.sync-btn { color: var(--brand-700); }
.sync-btn .ico { width: 20px; height: 20px; color: inherit; }
.sync-btn:hover { background: var(--brand-050); color: var(--brand-700); }

/* Mensagens: as três colunas ocupam o resto da altura do ecrã; cada uma rola por dentro (a partir de 1024 px). */
@media (min-width: 1024px) {
  .panel-main:has(> .inbox) { display: flex; flex-direction: column; height: 100vh; padding-bottom: 24px; }
  .panel-main > .inbox { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
  .inbox > .inbox-grid { flex: 1 1 auto; min-height: 0; align-items: stretch; }
  .inbox-grid > section, .inbox-grid > aside { min-height: 0; overflow-y: auto; }
  .inbox-grid > section.inbox-thread { overflow: hidden; }
  .inbox-grid .inbox-history { flex: 1 1 auto; max-height: none; min-height: 0; }
}
.lead.lead-sm { font-size: 14px; margin-bottom: 16px; }

/* Lista de conversas de ponta a ponta no cartão (o cabeçalho mantém a margem) */
.inbox-grid > section[aria-label="Conversas"] .inbox-list { margin: 0 -22px; gap: 0; }
.inbox-grid > section[aria-label="Conversas"] .inbox-item { border-radius: 0; padding: 10px 22px 10px 19px; }
/* Mensagens usa a largura toda da janela (sem o teto de 1360 px das outras páginas) */
.panel-main:has(> .inbox) { max-width: none; }
