/* =============================================================================
   Painel da clínica — sistema visual
   Tokens em :root; modo escuro por preferência do sistema. Sem recursos externos
   (CSP 'self'): fonte do sistema, ícones SVG inline.
   ============================================================================= */
:root {
  --brand: #0e7c86;
  --brand-strong: #0a5f67;
  --brand-soft: #e3f3f4;
  --brand-ink: #ffffff;

  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e3e8ec;
  --border-strong: #cfd7dd;
  --text: #13202b;
  --text-2: #4a5866;
  --muted: #7a8794;

  --ok: #1f8a4c;      --ok-soft: #e4f4ea;
  --warn: #a8670a;    --warn-soft: #fbf0dc;
  --danger: #c23b3b;  --danger-soft: #fbe6e6;
  --info: #2a78d6;    --info-soft: #e5effb;
  --series-1: #2a78d6;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 40px -12px rgba(16, 24, 40, .25);
  --sidebar-w: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #34b3bd;
    --brand-strong: #5cc8d0;
    --brand-soft: #123a3e;
    --brand-ink: #071a1c;
    --bg: #0f1418;
    --surface: #161d23;
    --surface-2: #1b242b;
    --border: #26313a;
    --border-strong: #33414c;
    --text: #e8eef2;
    --text-2: #b3c0ca;
    --muted: #8796a3;
    --ok: #4cc47f;      --ok-soft: #12321f;
    --warn: #e7a83f;    --warn-soft: #3a2a0d;
    --danger: #f07474;  --danger-soft: #3d1717;
    --info: #6aa8f0;    --info-soft: #132a45;
    --series-1: #3987e5;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 20px 40px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; } h4 { font-size: 13px; }
p { margin: 0; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon.lg { width: 22px; height: 22px; }
.icon.xl { width: 40px; height: 40px; stroke-width: 1.4; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn:focus-visible, .nav a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 1px; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Formulários ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
label.field > small { display: block; color: var(--muted); margin-top: 5px; font-size: 12px; }
input, select, textarea {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
select[multiple] { height: auto; padding: 6px; }
input.code { font-size: 26px; letter-spacing: .5em; text-align: center; height: 56px; font-variant-numeric: tabular-nums; }
.form-grid { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* ---------- Autenticação ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-side {
  background: linear-gradient(150deg, var(--brand) 0%, var(--brand-strong) 100%);
  color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-side h1 { font-size: 32px; margin-top: 28px; max-width: 420px; }
.auth-side p { opacity: .9; margin-top: 12px; max-width: 420px; font-size: 15px; }
.auth-side ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.auth-side li { display: flex; gap: 10px; align-items: center; opacity: .95; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 32px 20px; background: var(--surface); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 { font-size: 24px; }
.auth-card .lead { color: var(--text-2); margin: 6px 0 24px; }
.brand-mark { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-mark .logo { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: rgba(255,255,255,.18); }
.alert { display: flex; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 14px; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }

.steps { display: flex; gap: 8px; margin-bottom: 22px; }
.steps .step { flex: 1; height: 4px; border-radius: 4px; background: var(--border); }
.steps .step.done { background: var(--brand); }
.qr-box { display: grid; place-items: center; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; margin: 4px 0 14px; }
.qr-box img { width: 208px; height: 208px; image-rendering: pixelated; }
.secret { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; word-break: break-all; background: var(--surface-2); }
.secret code { flex: 1; }
.howto { margin: 0 0 16px; padding-left: 18px; color: var(--text-2); font-size: 13.5px; }
.howto li { margin-bottom: 4px; }

/* ---------- Layout do app ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 20px 18px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); }
.sidebar .brand .logo { width: 36px; height: 36px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; }
.sidebar .brand strong { display: block; font-size: 14px; line-height: 1.2; }
.sidebar .brand small { color: var(--muted); font-size: 12px; }
.nav { padding: 12px 10px; display: grid; gap: 2px; overflow-y: auto; flex: 1; }
.nav .section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 6px; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm); color: var(--text-2); text-decoration: none; font-weight: 550; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-strong); }
.nav a .count { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.user-card { border-top: 1px solid var(--border); padding: 14px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-strong); display: grid; place-items: center; font-weight: 700; flex: none; }
.user-card .who { flex: 1; min-width: 0; }
.user-card .who strong { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card .who small { color: var(--muted); font-size: 11.5px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 22px 32px 6px; }
.topbar p { color: var(--text-2); margin-top: 4px; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.content { padding: 18px 32px 40px; display: grid; gap: 20px; align-content: start; }
.menu-btn { display: none; }

/* ---------- Cartões, tabelas ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head p { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-body { padding: 18px 20px; }
.card-body.flush { padding: 0; }
.grid-2 { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td .row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.brand { background: var(--brand-soft); color: var(--brand-strong); border-color: transparent; }

.empty { display: grid; place-items: center; text-align: center; gap: 8px; padding: 40px 20px; color: var(--muted); }
.empty .icon.xl { color: var(--border-strong); }
.empty strong { color: var(--text-2); font-size: 15px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font: inherit; font-size: 13px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

/* ---------- Indicadores ---------- */
.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .label { color: var(--text-2); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }

.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr 56px; gap: 12px; align-items: center; font-size: 13px; }
.bar-row .name { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .track { height: 14px; background: var(--surface-2); border-radius: 0 4px 4px 0; position: relative; }
.bar-row .fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.bar-row[title] { cursor: default; }

/* ---------- Inbox ---------- */
.inbox { display: grid; grid-template-columns: 360px 1fr; min-height: 560px; }
.inbox-list { border-right: 1px solid var(--border); overflow-y: auto; max-height: calc(100vh - 220px); }
.inbox-item { display: block; width: 100%; text-align: left; padding: 14px 16px; border: 0; border-bottom: 1px solid var(--border); background: transparent; color: inherit; font: inherit; cursor: pointer; }
.inbox-item:hover { background: var(--surface-2); }
.inbox-item[aria-current="true"] { background: var(--brand-soft); }
.inbox-item .top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.inbox-item .reason { font-weight: 600; }
.inbox-item .meta { color: var(--muted); font-size: 12px; margin-top: 4px; display: flex; gap: 8px; align-items: center; }
.conv { display: flex; flex-direction: column; min-width: 0; }
.conv-head { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.summary-box { margin: 14px 20px 0; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--text); font-size: 13px; white-space: pre-wrap; border: 1px solid color-mix(in srgb, var(--warn) 25%, transparent); }
.chat { flex: 1; padding: 18px 20px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; max-height: 52vh; background: var(--surface-2); margin: 14px 20px; border-radius: var(--radius); }
.msg { max-width: 76%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; box-shadow: var(--shadow); font-size: 13.5px; }
.msg.inbound { align-self: flex-start; background: var(--surface); border-top-left-radius: 4px; }
.msg.outbound { align-self: flex-end; background: var(--brand-soft); border-top-right-radius: 4px; }
.msg small { display: block; color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.composer { display: flex; gap: 10px; padding: 0 20px 18px; align-items: flex-end; }
.composer textarea { min-height: 44px; height: 44px; }

/* ---------- Agenda ---------- */
.timeline { display: grid; gap: 10px; }
.slot { display: grid; grid-template-columns: 76px 1fr auto; gap: 14px; align-items: center; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.slot .time { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }

/* ---------- Base de conhecimento ---------- */
.kb-list { display: grid; gap: 12px; }
.kb-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; background: var(--surface); display: grid; gap: 8px; }
.kb-item .head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.kb-item .q { font-weight: 650; }
.kb-item .a { color: var(--text-2); white-space: pre-wrap; }
.kb-item .foot { display: flex; justify-content: space-between; gap: 10px; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: 12px; }

/* ---------- Interruptores ---------- */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: 0; }
.switch-row p { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.switch { position: relative; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); transition: background .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent); }

/* ---------- Modal e toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 16, 22, .45); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .12s ease-out; }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); }
.modal .card-head { border-bottom: 1px solid var(--border); }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.toasts { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 60; }
.toast { display: flex; align-items: center; gap: 10px; min-width: 260px; max-width: 380px; padding: 12px 14px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); font-size: 13.5px; animation: fade .15s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Responsivo ---------- */
@media (max-width: 1100px) { .inbox { grid-template-columns: 1fr; } .inbox-list { max-height: 320px; border-right: 0; border-bottom: 1px solid var(--border); } }
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; } .auth-side { display: none; }
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; width: var(--sidebar-w); transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .bar-row { grid-template-columns: 110px 1fr 44px; }
  .slot { grid-template-columns: 60px 1fr; } .slot .row-actions { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Chave liga/desliga da assistente (barra lateral) */
.assistant-switch { margin: 8px 12px; display: grid; gap: 8px; }
.assistant-switch:empty { display: none; }
.assistant-status { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); }
.assistant-status strong { display: block; font-size: 13px; }
.assistant-status small { display: block; font-size: 12px; color: var(--muted); }
.assistant-status .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.assistant-status.on { background: var(--ok-soft); border-color: transparent; }
.assistant-status.on .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.assistant-status.off { background: var(--danger-soft); border-color: transparent; }
.assistant-status.off .dot { background: var(--danger); }
