:root {
  --brand: #0f766e;
  --brand-dark: #115e59;
  --brand-soft: #e6f4f1;
  --bg: #f5f7f8;
  --card: #ffffff;
  --text: #1c2526;
  --muted: #64748b;
  --line: #e2e8f0;
  --ok: #15803d; --ok-bg: #dcfce7;
  --warn: #a16207; --warn-bg: #fef9c3;
  --err: #b91c1c; --err-bg: #fee2e2;
  --info: #1d4ed8; --info-bg: #dbeafe;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); }
h1 { font-size: 1.6rem; margin: .2em 0 .6em; }
h2 { font-size: 1.15rem; margin: 0 0 .8em; }
h3 { font-size: 1rem; margin: 1.4em 0 .6em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, Consolas, monospace; letter-spacing: 1px; text-transform: uppercase; }
[hidden] { display: none !important; }

/* ---------- Topo do painel ---------- */
.topbar { display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.logo-dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: linear-gradient(135deg, #14b8a6, var(--brand)); }
.logo-dot.big { width: 44px; height: 44px; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--text); }
.topbar nav a:hover, .topbar nav a.active { background: var(--brand-soft); color: var(--brand-dark); }
.topbar .user { display: flex; gap: 12px; align-items: center; font-size: .9rem; color: var(--muted); }

.container { max-width: 1180px; margin: 0 auto; padding: 24px 16px 60px; }

/* ---------- Cards e layout ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow); overflow-x: auto; }
.card.highlight { border-color: #fbbf24; box-shadow: 0 0 0 3px #fef3c7; }
.card.narrow { max-width: 520px; margin: 20px auto; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h1, .card-head h2 { margin: 0; }
.cols { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.span2 { grid-column: span 2; }
details.card summary { cursor: pointer; }
details.card[open] summary { margin-bottom: 16px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.8rem; color: var(--brand); }
.stat span { color: var(--muted); font-size: .9rem; }
.stat.alert { border-color: #f59e0b; background: #fffbeb; }

/* ---------- Formulários ---------- */
label { display: block; font-size: .88rem; font-weight: 600; color: #334155; margin-bottom: 12px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 11px; border: 1px solid #cbd5e1; border-radius: 8px; font: inherit; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #99f6e4; border-color: var(--brand); }
textarea { resize: vertical; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: auto; margin: 0; }
.weekdays { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 8px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input, .toolbar select { width: auto; margin: 0; }
.toolbar input[name="busca"] { flex: 1; min-width: 220px; }
form.inline { display: inline; }

.btn { display: inline-block; padding: 9px 16px; border-radius: 8px; border: 1px solid #cbd5e1; background: #fff; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: #f1f5f9; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--err); border-color: #fecaca; }
.btn.danger:hover { background: var(--err-bg); }
.btn.small { padding: 5px 10px; font-size: .82rem; }
.btn.big { padding: 14px 26px; font-size: 1.05rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
button.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* ---------- Tabelas ---------- */
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tr.urgent td { background: #fff5f5; }
td.actions { white-space: nowrap; }
td.actions > * { margin: 0 4px 4px 0; }
.status-form select { display: inline-block; width: auto; padding: 4px 8px; margin: 0; font-size: .82rem; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 700; background: #f1f5f9; color: var(--muted); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.info { background: var(--info-bg); color: var(--info); }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.flash.ok { background: var(--ok-bg); color: #14532d; }
.flash.err { background: var(--err-bg); color: #7f1d1d; }
.flash.warn { background: var(--warn-bg); color: #713f12; }
.notice { background: var(--brand-soft); border-left: 4px solid var(--brand); padding: 10px 14px; border-radius: 6px; }
.secret { background: #0f172a; color: #e2e8f0; padding: 16px; border-radius: 10px; margin: 12px 0; line-height: 2; }
.secret code { color: #5eead4; font-size: 1.1rem; }
.tabs a { margin-right: 14px; text-decoration: none; padding-bottom: 4px; }
.tabs a.active { border-bottom: 2px solid var(--brand); font-weight: 700; }
.logo-preview { max-width: 220px; max-height: 120px; display: block; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.list { padding-left: 18px; }

.dl { display: grid; grid-template-columns: 220px 1fr; gap: 6px 16px; margin: 0; }
.dl dt { font-weight: 600; color: var(--muted); font-size: .88rem; }
.dl dd { margin: 0; white-space: pre-wrap; }
.dl.cols3 { grid-template-columns: repeat(3, 110px 1fr); }
.record { border-top: 1px solid var(--line); padding: 14px 0; }
.record-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; }

/* ---------- Login / páginas simples ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #ecfdf5, #f0f9ff); }
.card.auth { width: 100%; max-width: 400px; }
.card.auth.wide { max-width: 480px; }
.card.auth .btn.primary { width: 100%; margin: 6px 0 14px; }

/* ---------- Páginas do paciente (consulta / avaliação) ---------- */
.patient-head { display: flex; gap: 12px; align-items: center; padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.patient-head img { max-height: 48px; max-width: 120px; object-fit: contain; }
.card.auth .dl { grid-template-columns: 120px 1fr; margin-bottom: 16px; }
.patient-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0 12px; }
.patient-actions .btn { width: auto; margin: 0; }
.stars { border: 0; padding: 0; margin: 8px 0 16px; display: flex; flex-direction: row-reverse; justify-content: flex-end; gap: 4px; }
.stars input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.stars label { font-size: 2.4rem; color: #cbd5e1; cursor: pointer; margin: 0; line-height: 1; }
.stars input:checked ~ label, .stars label:hover, .stars label:hover ~ label { color: #f59e0b; }
.stars input:focus-visible + label { outline: 2px solid var(--brand); border-radius: 4px; }
img.qr { display: block; width: 220px; height: 220px; margin: 12px 0; border: 1px solid var(--line); border-radius: 8px; }

/* ---------- Site institucional ---------- */
.site-top { display: flex; justify-content: space-between; align-items: center; padding: 16px 32px; max-width: 1200px; margin: 0 auto; flex-wrap: wrap; gap: 12px; }
.site-brand { font-weight: 800; font-size: 1.15rem; display: flex; gap: 8px; align-items: center; }
.site-top nav { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.site-top nav a:not(.btn) { color: var(--text); text-decoration: none; }
.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 48px; align-items: center; max-width: 1200px; margin: 0 auto; padding: 48px 32px 72px; }
.hero h1 { font-size: 2.6rem; line-height: 1.15; margin-bottom: .4em; }
.hero p { font-size: 1.15rem; color: #475569; margin-bottom: 28px; }
.hero-card { background: #fff; border-radius: 20px; padding: 24px; box-shadow: 0 20px 50px rgba(15, 118, 110, .15); display: flex; flex-direction: column; gap: 10px; }
.features { max-width: 1200px; margin: 0 auto; padding: 40px 32px; }
.features h2 { font-size: 1.8rem; text-align: center; margin-bottom: 32px; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.feature { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 22px; }
.feature h3 { margin-top: 0; }
.feature p { color: #475569; margin: 0; }
.cta { text-align: center; padding: 64px 32px; background: linear-gradient(135deg, var(--brand), #0e7490); color: #fff; }
.cta h2 { font-size: 1.9rem; }
.cta .btn.primary { background: #fff; color: var(--brand-dark); }
.cta .muted { color: #ccfbf1; }
.site-foot { text-align: center; padding: 24px; color: var(--muted); }

/* ---------- Chat ---------- */
.bubble { max-width: 82%; padding: 10px 14px; border-radius: 16px; line-height: 1.45; word-wrap: break-word; }
.bubble.bot { background: #f1f5f9; align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.me { background: var(--brand); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.sys { background: var(--ok-bg); color: #14532d; align-self: center; font-size: .9rem; text-align: center; max-width: 95%; }
.bubble.typing { display: flex; gap: 4px; }
.bubble.typing span { width: 8px; height: 8px; background: #94a3b8; border-radius: 50%; animation: blink 1.2s infinite; }
.bubble.typing span:nth-child(2) { animation-delay: .2s; }
.bubble.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

body.bare .chat-page { max-width: 760px; margin: 0 auto; height: 100vh; height: 100dvh; display: flex; flex-direction: column; background: #fff; box-shadow: 0 0 40px rgba(0, 0, 0, .06); }
.chat-head { display: flex; gap: 14px; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.chat-head img { max-height: 48px; max-width: 120px; object-fit: contain; }
.chat-status { font-size: .8rem; color: #15803d; display: flex; align-items: center; gap: 5px; }
.chat-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #22c55e; }
.chat-status.typing { color: var(--brand); font-style: italic; }
.chat-status.typing::before { animation: blink 1.2s infinite; }
.chat-box { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.consent { align-self: stretch; font-size: .92rem; margin: 8px 0; }
.consent .emergency { background: var(--err-bg); color: #7f1d1d; padding: 8px 12px; border-radius: 8px; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-input textarea { margin: 0; resize: none; max-height: 140px; }
.chat-foot { text-align: center; margin: 0; padding: 6px 12px 10px; }

/* ---------- Responsivo ---------- */
@media (max-width: 860px) {
  .cols, .hero { grid-template-columns: 1fr; }
  .hero h1 { font-size: 2rem; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .dl, .dl.cols3 { grid-template-columns: 1fr; }
  .site-top, .hero, .features { padding-left: 16px; padding-right: 16px; }
  .topbar { padding: 10px 16px; gap: 10px; }
}

@media print {
  .topbar, .btn, form { display: none !important; }
  .card { box-shadow: none; border: 0; }
}
