:root {
  --bg: #f5f7f6; --surface: #ffffff; --surface-2: #eef2f0; --line: #dde4e1; --fg: #15201c; --muted: #5d6b66; --faint: #8a9792;
  --brand: #0f766e; --brand-2: #0d9488; --brand-soft: #d9f2ee; --on-brand: #ffffff;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #a16207; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2; --info: #1d4ed8; --info-soft: #dbeafe;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .06);
  --r: 12px; --f: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1412; --surface: #141d1a; --surface-2: #1b2622; --line: #26332e; --fg: #e5ece9; --muted: #9aa8a2; --faint: #6f7d77;
    --brand: #2dd4bf; --brand-2: #5eead4; --brand-soft: #123a35; --on-brand: #04201c;
    --ok: #4ade80; --ok-soft: #14301f; --warn: #fbbf24; --warn-soft: #382b0c; --bad: #f87171; --bad-soft: #3a1515; --info: #93c5fd; --info-soft: #172a4a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1412; --surface: #141d1a; --surface-2: #1b2622; --line: #26332e; --fg: #e5ece9; --muted: #9aa8a2; --faint: #6f7d77;
  --brand: #2dd4bf; --brand-2: #5eead4; --brand-soft: #123a35; --on-brand: #04201c;
  --ok: #4ade80; --ok-soft: #14301f; --warn: #fbbf24; --warn-soft: #382b0c; --bad: #f87171; --bad-soft: #3a1515; --info: #93c5fd; --info-soft: #172a4a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 var(--f); -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.carregando { padding: 40vh 16px 0; text-align: center; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .85rem; } .nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- botões e campos ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--fg); white-space: nowrap; }
.btn:hover { border-color: var(--faint); }
.btn.pri { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.pri:hover { background: var(--brand-2); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); padding-left: 8px; padding-right: 8px; }
.btn.perigo { color: var(--bad); }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: default; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .nav a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
label.campo { display: grid; gap: 4px; font-size: .8rem; font-weight: 600; color: var(--muted); }
input, select, textarea { width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 1rem; }
textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
input[type=checkbox] { width: 18px; min-height: 18px; height: 18px; accent-color: var(--brand); }
.grade { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.grade .full { grid-column: 1 / -1; }
.chk { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--fg); font-size: .92rem; }

/* ---------- estrutura ---------- */
.layout { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.lateral { background: var(--surface); border-right: 1px solid var(--line); padding: 16px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 14px; }
.marca { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.marca .logo { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; color: var(--on-brand); font-weight: 800; }
.marca b { display: block; font-size: .95rem; } .marca span { display: block; font-size: .78rem; color: var(--muted); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--fg); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.nav svg { width: 19px; height: 19px; flex: none; }
.lateral .pe { margin-top: auto; display: grid; gap: 6px; font-size: .85rem; }
.lateral .pe .eu { padding: 8px 10px; border-top: 1px solid var(--line); }
.principal { padding: 22px 28px 60px; max-width: 1180px; width: 100%; min-width: 0; }
.topo { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.topo .acoes { display: flex; gap: 8px; flex-wrap: wrap; }
.barra-mobile, .nav-mobile { display: none; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); }
.card + .card, .card + .sec, .sec + .card { margin-top: 14px; }
.card h3 { margin-bottom: 10px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-h h3 { margin: 0; }
.vazio { padding: 28px 12px; text-align: center; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi .n { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: .8rem; color: var(--muted); font-weight: 600; }

/* ---------- tabelas e listas ---------- */
.tabela { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tabela th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tabela td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tabela tr:last-child td { border-bottom: 0; }
.tabela tr.click { cursor: pointer; } .tabela tr.click:hover td { background: var(--surface-2); }
.rolavel { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: .74rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); } .pill.info { background: var(--info-soft); color: var(--info); }
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.busca { display: flex; gap: 8px; margin-bottom: 12px; } .busca input { flex: 1; }

/* ---------- ficha do paciente ---------- */
.ficha-h { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: 1.1rem; flex: none; }
.ficha-h .info { flex: 1; min-width: 200px; } .ficha-h .info .muted { font-size: .88rem; }
.abas { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 16px 0 14px; overflow-x: auto; scrollbar-width: none; }
.abas a { padding: 9px 12px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.abas a.on { color: var(--brand); border-bottom-color: var(--brand); }
.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 16px; margin: 0; }
.dl div { min-width: 0; } .dl dt { font-size: .75rem; color: var(--muted); font-weight: 600; } .dl dd { margin: 0; overflow-wrap: anywhere; }

/* prontuário */
.registro { border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; background: var(--surface); }
.registro + .registro { margin-top: 12px; }
.registro.rascunho { border-style: dashed; border-color: var(--warn); }
.registro .cab { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; margin-bottom: 8px; }
.registro .cab b { font-size: .98rem; }
.registro .secao { margin-top: 8px; } .registro .secao dt { font-size: .74rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.registro .secao dd { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.registro .assin { margin-top: 10px; font-size: .78rem; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.adendo { margin-top: 10px; padding: 8px 12px; border-left: 3px solid var(--info); background: var(--info-soft); border-radius: 0 8px 8px 0; font-size: .92rem; }
.adendo .q { font-size: .76rem; color: var(--muted); }
.diag { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.diag:last-child { border-bottom: 0; }
.diag .cod { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 54px; }
.diag .desc { flex: 1; min-width: 160px; }
.diag.resolvido .desc, .diag.resolvido .cod { color: var(--faint); text-decoration: line-through; }
.sugestoes { border: 1px solid var(--line); border-radius: 10px; margin-top: 4px; max-height: 260px; overflow-y: auto; background: var(--surface); }
.sugestoes button { display: block; width: 100%; text-align: left; padding: 8px 12px; border: 0; background: none; cursor: pointer; border-bottom: 1px solid var(--line); }
.sugestoes button:hover, .sugestoes button:focus { background: var(--surface-2); }
.sugestoes button:last-child { border-bottom: 0; }

/* agenda */
.dia-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dia-nav b { min-width: 210px; text-align: center; text-transform: capitalize; }
.slot { display: grid; grid-template-columns: 74px 1fr auto; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: center; }
.slot:last-child { border-bottom: 0; }
.slot .h { font-weight: 800; font-variant-numeric: tabular-nums; } .slot .h span { display: block; font-size: .75rem; color: var(--muted); font-weight: 500; }
.slot .p a { font-weight: 700; color: var(--fg); text-decoration: none; } .slot .p a:hover { color: var(--brand); }
.slot .p .muted { font-size: .84rem; }
.slot.cancelada, .slot.faltou { opacity: .55; }
.slot .acoes { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- login ---------- */
.entrada { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.entrada .caixa { width: 100%; max-width: 400px; }
.entrada .marca { justify-content: center; margin-bottom: 18px; }
.entrada form { display: grid; gap: 14px; }
.qr { display: grid; place-items: center; background: #fff; border-radius: 12px; padding: 10px; margin: 0 auto; width: fit-content; }
.qr svg { display: block; width: 200px; height: 200px; }
.codigo { font-size: 1.6rem; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.segredo { font-family: ui-monospace, monospace; font-size: .85rem; word-break: break-all; background: var(--surface-2); padding: 8px; border-radius: 8px; }
.erro { color: var(--bad); font-size: .9rem; font-weight: 600; min-height: 1.2em; }

/* ---------- modal e aviso ---------- */
.fundo { position: fixed; inset: 0; background: rgba(5, 12, 10, .5); display: grid; place-items: start center; padding: 6vh 12px 12px; z-index: 50; overflow-y: auto; }
.janela { background: var(--surface); border-radius: 16px; width: 100%; max-width: 680px; padding: 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.janela.larga { max-width: 860px; }
.janela h2 { margin-bottom: 4px; } .janela .ajuda { font-size: .88rem; color: var(--muted); margin: 0 0 14px; }
.janela .rodape { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.janela .rodape .dir { display: flex; gap: 8px; margin-left: auto; }
.janela fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 12px; margin: 12px 0 0; }
.janela legend { font-size: .8rem; font-weight: 700; color: var(--muted); padding: 0 4px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; pointer-events: none; }
#toast div { background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; box-shadow: var(--shadow); max-width: 90vw; }
#toast div.ruim { background: var(--bad); color: #fff; }
.senha-mostra { font-family: ui-monospace, monospace; font-size: 1.15rem; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; user-select: all; text-align: center; }

/* ---------- celular ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .lateral { display: none; }
  .barra-mobile { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
  .nav-mobile { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
  .nav-mobile a { display: grid; justify-items: center; gap: 2px; padding: 8px 2px; font-size: .7rem; color: var(--muted); text-decoration: none; font-weight: 600; }
  .nav-mobile a.on { color: var(--brand); } .nav-mobile svg { width: 22px; height: 22px; }
  .principal { padding: 16px 16px 90px; }
  .slot { grid-template-columns: 60px 1fr; } .slot .acoes { grid-column: 1 / -1; justify-content: flex-start; }
  .esconde-mobile { display: none; }
  .fundo { padding: 0; place-items: end center; } .janela { border-radius: 16px 16px 0 0; max-height: 92vh; overflow-y: auto; }
}
@media print {
  .lateral, .barra-mobile, .nav-mobile, .topo .acoes, .btn, .abas { display: none !important; }
  .layout { display: block; } .card { box-shadow: none; border: 0; padding: 0; }
}
