:root {
  --accent: #2b8286;
  --accent-dark: #1f6669;
  --accent-soft: #dff1f1;
  --blush: #fbe4e4;
  --bg: #f8f5f1;
  --surface: #ffffff;
  --text: #2f3a44;
  --muted: #68737d;
  --border: #e8e3dc;
  --side-bg: #ffffff;
  --side-text: #55616b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.10);
  --late: #b91c1c; --late-soft: #fef2f2;
  --ok: #15803d; --ok-soft: #dcfce7;
  --warn: #92400e; --warn-soft: #fef3c7;
  --sun: #f6c445; --sun-ink: #4a3600;
}
/* Cor da família e da ficha, conforme o paciente */
body[data-tema="menino"] { --accent: #3a70ad; --accent-dark: #2d5a8e; --accent-soft: #e1ecf8; --blush: #e6eff9; --bg: #f2f6fb; --border: #dde6f0; }
body[data-tema="menina"] { --accent: #b94a70; --accent-dark: #973a5a; --accent-soft: #fbe4ec; --blush: #fde9ef; --bg: #fdf6f8; --border: #f2e1e7; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: Nunito, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { letter-spacing: -.01em; margin: 0; }
h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0; }
input, select, textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; width: 100%; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
input[type=radio], input[type=checkbox] { width: auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn { border: 1px solid transparent; border-radius: 8px; padding: 9px 16px; cursor: pointer; font: inherit; font-weight: 600; background: #eef1f5; color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 7px; text-decoration: none; white-space: nowrap; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { background: #fff; border-color: var(--border); }
.btn.ghost:hover { background: #f8fafc; }
.btn.danger { background: var(--late-soft); color: var(--late); border-color: #fecaca; }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.big { padding: 12px 20px; font-size: 15px; width: 100%; }
.icon-btn { background: none; border: 0; font-size: 18px; cursor: pointer; color: inherit; padding: 6px; border-radius: 8px; }

/* ---------- Login ---------- */
.login { position: fixed; inset: 0; background: var(--accent); display: flex; overflow-y: auto; }
.login-content { flex: 1; display: flex; align-items: center; justify-content: space-around; gap: 28px; padding: 24px 6vw; flex-wrap: wrap; }
.login-hero { max-width: 460px; display: grid; gap: 22px; justify-items: center; }
.login-logo { width: min(420px, 80vw); height: auto; }
.login-dra { width: min(190px, 44vw); height: auto; }
.login-card { background: #fff; width: 320px; max-width: 100%; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.35); padding: 0 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.login-card-head { margin: 0 -16px; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.login-card-head .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.error { color: var(--late); font-size: 13px; }

/* ---------- Estrutura ---------- */
.app { display: flex; height: 100%; }
.sidebar { width: 232px; background: var(--side-bg); color: var(--side-text); border-right: 1px solid var(--border); flex-shrink: 0; display: flex; flex-direction: column; overflow-y: auto; }
.sidebar-brand { padding: 18px 16px 14px; }
.sidebar-brand img { width: 100%; height: auto; display: block; }
.side-dra { margin-top: auto; padding: 12px 20px 16px; display: grid; gap: 12px; justify-items: center; }
.som { background: none; border: 0; font: inherit; font-size: 12px; color: var(--muted); cursor: pointer; text-decoration: underline; padding: 2px 6px; }
.fala-side { min-height: 52px; position: relative; background: var(--accent-soft); color: var(--text); border-radius: 12px; padding: 8px 10px; font-size: 13px; font-weight: 600; line-height: 1.3; text-align: center; max-width: 190px; }
.fala-side::after { content: ""; position: absolute; left: 50%; bottom: -6px; margin-left: -6px; border: 6px solid transparent; border-bottom: 0; border-top-color: var(--accent-soft); }
.fala-side:empty { visibility: hidden; }

/* ---------- Laurinha boneca ---------- */
.boneca { position: relative; display: block; background: none; border: 0; padding: 0; cursor: pointer; transform-origin: 50% 90%; animation: respira 3s ease-in-out infinite; }
.boneca img { width: 100%; height: auto; display: block; }
.boneca.menu { width: 130px; }
.boneca.grande { width: 240px; max-width: 72%; cursor: default; }
/* Boca: oval escuro sobre o focinho (x 51%, y 61% do desenho), aberta só enquanto ela fala */
.boneca .boca { position: absolute; left: 51.2%; top: 61.5%; width: 9%; height: 8%; margin-left: -4.5%; margin-top: -2%; border-radius: 45% 45% 50% 50%; background: radial-gradient(ellipse at 50% 85%, #f08c98 0 38%, #5f6873 40%); transform: scaleY(0); transform-origin: 50% 0; }
.boneca.falando .boca { animation: fala .26s ease-in-out infinite alternate; }
.boneca.falando { animation: cabeca 1s ease-in-out infinite; }
/* Pálpebras na cor do pelo, sobre os olhos (x 37%/59%, y 33%/30%) */
.boneca .palpebra { position: absolute; width: 5.5%; height: 7.5%; margin: -3.75% 0 0 -2.75%; border-radius: 50%; background: #f4ede6; transform: scaleY(0); transform-origin: 50% 0; animation: pisca 4.5s infinite; }
.boneca .p1 { left: 37%; top: 33%; }
.boneca .p2 { left: 59.4%; top: 29.8%; }
.boneca.pula { animation: pula .9s ease; }
.boneca.balanca { animation: balanca 1s ease; }
.boneca.cresce { animation: cresce 1.6s ease; }
.boneca.falando.pula { animation: pula .9s ease, cabeca 1s ease-in-out .9s infinite; }
/* Corações saem do coração que ela abraça */
.coracoes { position: absolute; left: 72%; top: 50%; pointer-events: none; }
.coracao { position: absolute; width: 16px; height: 16px; left: -8px; top: -8px; background: #ee8fa0; transform: rotate(45deg); border-radius: 0 0 3px 0; opacity: 0; animation: sobe 1.8s ease-out var(--d) forwards; }
.coracao::before, .coracao::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; background: inherit; }
.coracao::before { left: -8px; top: 0; }
.coracao::after { left: 0; top: -8px; }
@keyframes fala { from { transform: scaleY(.15); } to { transform: scaleY(1); } }
@keyframes cabeca { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-3deg) translateY(-2px); } 75% { transform: rotate(3deg) translateY(-1px); } }
@keyframes pisca { 0%, 93%, 100% { transform: scaleY(0); } 96% { transform: scaleY(1); } }
@keyframes sobe { 0% { opacity: 0; transform: translate(0, 0) rotate(45deg) scale(.4); } 15% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--x), -110px) rotate(45deg) scale(1.1); } }
#nav { display: grid; gap: 2px; padding: 0 10px; }
#nav button { background: none; border: 0; color: inherit; font: inherit; font-weight: 500; text-align: left; padding: 10px 12px; border-radius: 8px; cursor: pointer; }
#nav button:hover { background: var(--accent-soft); }
#nav button.active { background: var(--accent); color: #fff; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 20px; }
.page-title { font-size: 17px; font-weight: 600; flex: 1; min-width: 0; }
.menu-toggle { display: none; }
.user-box { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-dark); display: grid; place-items: center; font-weight: 700; }
.user-info { display: grid; line-height: 1.2; }
.user-info small { color: var(--muted); }
.view { flex: 1; overflow-y: auto; padding: 20px; }
.stack { display: grid; gap: 14px; max-width: 1040px; margin: 0 auto; min-width: 0; }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: grid; gap: 12px; min-width: 0; }
.head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nums { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.num { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.num strong { display: block; font-size: 28px; font-variant-numeric: tabular-nums; }
.row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 12px 0; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.when { font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; }
.when small { display: block; font-weight: 500; color: var(--muted); }
.row-main { display: grid; gap: 4px; overflow-wrap: anywhere; }
.pills { display: flex; flex-wrap: wrap; gap: 4px; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #eef1f5; color: var(--muted); white-space: nowrap; }
.pill.late { background: var(--late-soft); color: var(--late); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.gift { background: var(--sun); color: var(--sun-ink); }
.act { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.notice { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; background: var(--warn-soft); color: var(--warn); padding: 10px 14px; border-radius: 8px; font-weight: 600; }
.alert { background: var(--late-soft); color: var(--late); padding: 9px 12px; border-radius: 8px; font-weight: 600; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 18px; margin: 0; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
tr.link { cursor: pointer; }
tr.link:hover td { background: #f8fafc; }
.ages { display: grid; gap: 8px; }
.age { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 10px; }
.age > span { font-weight: 700; font-size: 13px; padding-top: 5px; }
.stamps { display: flex; flex-wrap: wrap; gap: 6px; }
.stamp { border: 1.5px dashed var(--border); background: none; border-radius: 7px; padding: 4px 9px; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); }
button.stamp { cursor: pointer; }
.stamp.done { border: 1.5px solid var(--ok); background: var(--ok-soft); color: var(--ok); }
.stamp.done::before { content: "✓ "; }
.stamp.late { border-color: var(--late); color: var(--late); }
.stamp.fora { opacity: .55; text-decoration: line-through; }
.chart { width: 100%; height: auto; display: block; }
.chart polyline { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart circle { fill: var(--accent); }
.chart line { stroke: var(--border); }
.chart text { fill: var(--muted); font-size: 11px; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.tip { background: var(--blush); border-radius: 8px; padding: 10px 12px; }
.palco { justify-items: center; text-align: center; }
.resumo-hoje { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; width: 100%; border: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; background: var(--accent-soft); }
.consulta-card { border-left: 5px solid var(--accent); }
.consulta-card h2 { font-size: 20px; }
.atalhos { display: flex; flex-wrap: wrap; gap: 6px; position: sticky; top: -20px; z-index: 5; background: var(--bg); padding: 8px 0; }
.atalhos .pill { border: 1px solid var(--border); background: var(--surface); cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; padding: 4px 12px; }
.atalhos .pill:hover { border-color: var(--accent); color: var(--accent); }
[id^="f-"] { scroll-margin-top: 56px; }
.relatorio { width: 100%; height: 78vh; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.atalhos .pill.ativo { background: var(--accent); border-color: var(--accent); color: #fff; }
label.btn { cursor: pointer; }
.secao { font-size: 16px; color: var(--muted); margin-top: 6px; }
.grupo { margin: 8px 0 -4px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); border-top: 1px solid var(--border); padding-top: 12px; }
.grupo:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
/* "Qual?" só aparece quando a resposta é Sim */
fieldset.f > input[name$="Q"] { display: none; }
fieldset.f:has(input[value="Sim"]:checked) > input[name$="Q"] { display: block; }
.fala { background: var(--accent-soft); border-radius: 16px; padding: 12px 16px; font-size: 18px; font-weight: 700; max-width: 460px; min-height: 52px; }
.urso { width: 220px; max-width: 70%; height: auto; animation: respira 3s ease-in-out infinite; }
.urso.mini { width: 72px; max-width: none; }
.urso.pula { animation: pula .9s ease; }
.urso.balanca { animation: balanca 1s ease; }
.urso.cresce { animation: cresce 1.6s ease; }
.acoes { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.acoes .btn[aria-pressed="true"] { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.saudacao { grid-auto-flow: column; grid-template-columns: auto minmax(0, 1fr); align-items: center; width: 100%; border: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; }
@keyframes respira { 50% { transform: translateY(-5px) scale(1.02); } }
@keyframes pula { 30% { transform: translateY(-34px); } 55% { transform: translateY(0); } 75% { transform: translateY(-12px); } }
@keyframes balanca { 25% { transform: rotate(-9deg); } 75% { transform: rotate(9deg); } }
@keyframes cresce { 50% { transform: scale(1.15); } }
.person { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--border); }
.person:first-child { border-top: 0; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.search { max-width: 340px; }
.date { max-width: 170px; }
.creds { background: var(--accent-soft); border-radius: 8px; padding: 12px; font-size: 15px; display: grid; gap: 4px; overflow-wrap: anywhere; }

/* ---------- Formulário e modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 16px; z-index: 20; }
.modal-box { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: min(620px, 100%); max-height: 92vh; overflow-y: auto; padding: 16px 18px 18px; display: grid; gap: 10px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.f { display: grid; gap: 4px; min-width: 0; align-content: start; border: 0; margin: 0; padding: 0; }
.f label, .f legend { font-size: 13px; font-weight: 600; padding: 0; }
.yn { display: flex; gap: 14px; margin-bottom: 4px; }
.yn label { display: flex; gap: 5px; align-items: center; font-weight: 500; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; }
.wide { grid-column: 1 / -1; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px; background: #111827; color: #fff; padding: 9px 15px; border-radius: 9px; font-weight: 600; max-width: calc(100% - 32px); z-index: 30; }

/* ---------- Confirmação de consulta ---------- */
.confirm { display: grid; place-items: center; padding: 16px; background: var(--bg); }
.confirm-card { background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: 20px; width: 380px; max-width: 100%; display: grid; gap: 12px; }
.confirm-logo { width: 220px; height: auto; justify-self: center; }
.confirm-card form .btn { width: 100%; }

.sidebar-backdrop { display: none; }
@media (max-width: 820px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 15; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .sidebar.open + .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 14; }
  .menu-toggle { display: inline-flex; }
  .user-info { display: none; }
  .view { padding: 14px; }
  .row { grid-template-columns: 54px minmax(0, 1fr); }
  .row .act { grid-column: 2; justify-content: flex-start; }
  .login-content { flex-direction: column; justify-content: center; gap: 28px; }
  .lista-pac thead { display: none; }
  .lista-pac tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .lista-pac td { border: 0; padding: 0; }
  .lista-pac td:nth-child(2) { color: var(--muted); text-align: right; }
  .lista-pac td:nth-child(3) { color: var(--muted); font-size: 13px; }
  .lista-pac td:nth-child(3)::before { content: "Responsável: "; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } .urso, .urso.pula, .urso.balanca, .urso.cresce, .boneca, .boneca.falando, .boneca.pula, .boneca.balanca, .boneca.cresce { animation: none; } }

/* Prontuário e financeiro */
.pront { border-top: 1px solid var(--border, #e3e8ea); padding: 12px 0; }
.pront:first-of-type { border-top: 0; }
.pront .head { gap: 8px; flex-wrap: wrap; }
.pront h4 { margin: 10px 0 2px; font-size: 13px; color: var(--muted, #667); font-weight: 600; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; line-height: 1.5; }
textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--border, #d9dfe2); border-radius: 10px; resize: vertical; }
.barra { display: inline-block; width: 120px; max-width: 30vw; height: 8px; border-radius: 4px; background: var(--accent-soft); overflow: hidden; vertical-align: middle; }
.barra > span { display: block; height: 100%; background: var(--accent); }
