/* Mama Heads — estilos (mobile-first) */
:root {
  --teal: #087083;
  --teal-dark: #064f5d;
  --teal-soft: #e3f0f1;
  --sage: #89ad8d;
  --sage-soft: #eef5ee;
  --coral: #ff9b7a;
  --coral-dark: #f4794f;
  --coral-soft: #fff0e9;
  --bg: #f5f7f5;
  --card: #ffffff;
  --text: #223433;
  --muted: #6b807e;
  --line: #e2eae7;
  --green: #16a34a;
  --yellow: #ca8a04;
  --orange: #ea580c;
  --red: #dc2626;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(15, 40, 38, 0.06), 0 4px 14px rgba(15, 40, 38, 0.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 76px;
  -webkit-tap-highlight-color: transparent;
}

/* header + nav */
header {
  background: linear-gradient(120deg, var(--teal-dark), var(--teal) 70%, #0d8aa6);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}
header .logo-img {
  width: 46px;
  height: 46px;
  object-fit: contain;
  background: transparent;
  box-shadow: none;
  filter: brightness(0) invert(1) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.18));
}
header > div { min-width: 0; }
header h1 { font-size: 21px; margin: 0; font-weight: 800; letter-spacing: 0.3px; }
header .tag { font-size: 11.5px; opacity: 0.9; display: block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

[hidden] { display: none !important; }

nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: center;
  z-index: 40;
  box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.05);
}
.nav-btn {
  flex: 1 1 0;
  max-width: 220px;
  border: 0;
  background: none;
  padding: 9px 4px 10px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s;
}
.nav-btn .ico { display: block; font-size: 20px; margin-bottom: 2px; }
.nav-btn.active { color: var(--teal); font-weight: 700; }

main { max-width: 860px; margin: 0 auto; padding: 16px; }
.view { display: none; animation: fadein 0.25s ease; }
.view.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

h2 { font-size: 19px; margin: 6px 0 14px; }
.card-title { font-size: 14px; margin: 0 0 10px; color: var(--teal-dark); }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 11px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

/* botoes */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 11px;
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { border-color: var(--teal); color: var(--teal); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--teal-dark); color: #fff; }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }
.btn-big { width: 100%; padding: 13px; font-size: 15.5px; }
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); color: var(--red); background: #fef2f2; }
.btn-danger-solid { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn.on { background: #fee2e2; border-color: var(--red); color: var(--red); }
.row-btns { display: flex; gap: 8px; margin-top: 12px; }
.row-btns .btn-grow { flex: 1; min-width: 0; white-space: nowrap; }
.row-btns .btn-icon { flex: 0 0 auto; padding: 10px 12px; }

/* chips de severidade */
.chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.sev-0 { background: #dcfce7; color: var(--green); }
.sev-1 { background: #fef9c3; color: var(--yellow); }
.sev-2 { background: #ffedd5; color: var(--orange); }
.sev-3 { background: #fee2e2; color: var(--red); }
.chip-empty { background: #eef2f6; color: var(--muted); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
  font-size: 14px;
  line-height: 1.6;
}

/* dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-ico { font-size: 18px; display: block; margin-bottom: 2px; }
.stat b { font-size: 27px; color: var(--teal); display: block; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--muted); }
.stat-warn b { color: var(--orange); }
.recent-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 11px 6px; border-bottom: 1px solid var(--line); cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s;
}
.recent-item > div:first-child { flex: 1; min-width: 0; }
.recent-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-item:hover { background: var(--teal-soft); }
.recent-item:last-child { border-bottom: 0; }
.recent-metrics { display: flex; gap: 8px; align-items: center; font-size: 12.5px; white-space: nowrap; flex-shrink: 0; }

/* pacientes */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input { flex: 1; }
input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #99d5e2; border-color: var(--teal); }
.patient-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.patient-card { transition: box-shadow 0.15s; }
.patient-card:hover { box-shadow: 0 3px 14px rgba(14, 116, 144, 0.14); }

/* modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none; align-items: center; justify-content: center;
  z-index: 50; padding: 16px;
}
.modal.open { display: flex; }
.modal-box {
  background: #fff; border-radius: var(--radius);
  padding: 20px; width: 100%; max-width: 420px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.25);
  animation: pop 0.18s ease;
}
@keyframes pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
.modal-sm { max-width: 340px; }
.confirm-text { margin: 0 0 6px; font-size: 15px; line-height: 1.5; }
.modal-box h3 { margin: 0 0 14px; }
.form-row { margin-bottom: 10px; }
.form-row label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* medicao */
#m-steps { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.step {
  font-size: 12px; padding: 5px 11px;
  border-radius: 999px; background: #eef2f6; color: var(--muted);
  transition: all 0.2s;
}
.step.active { background: var(--teal); color: #fff; font-weight: 600; }
.step.done { background: #dcfce7; color: var(--green); }
.measure-top { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.measure-top select { flex: 2; min-width: 180px; }
.measure-top input[type="date"] { flex: 1; min-width: 130px; }
.photo-btns { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.photo-btns .btn { flex: 1; text-align: center; min-width: 140px; }
.file-hidden { display: none; }

#m-canvas-wrap { position: relative; }
#m-canvas {
  width: 100%;
  display: block;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #eef3f6;
  cursor: crosshair;
  box-shadow: var(--shadow);
}
.canvas-tools { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.canvas-tools .btn { flex: 1; min-width: 120px; }
#calib-row { display: none; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
#calib-row input { max-width: 110px; }

#m-results { margin-top: 12px; }
.results-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric { text-align: center; padding: 10px 8px; border-radius: 11px; background: #f8fafc; border: 1px solid var(--line); }
.metric b { display: block; font-size: 25px; }
.metric .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.metric .chip { margin-top: 4px; }
.muted-box { opacity: 0.45; pointer-events: none; }

.hint {
  font-size: 13px; color: var(--text);
  background: #f0f7fa; border: 1px dashed #b7d6e0;
  border-radius: 11px; padding: 10px 14px; margin: 10px 0;
  line-height: 1.55;
}
.hint summary { cursor: pointer; font-weight: 600; color: var(--teal-dark); }
.hint ol { margin: 8px 0 4px; padding-left: 20px; }
.hint li { margin-bottom: 5px; }
.tip-note { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; }

.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
#m-edit-banner {
  display: none;
  background: #fff7ed; border: 1px solid #fdba74; color: #9a3412;
  border-radius: 10px; padding: 9px 12px; font-size: 13px; margin-bottom: 10px;
}

/* captura guiada */
.modal-dark { background: rgba(2, 6, 12, 0.92); }
.capture-box { width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 10px; }
.cap-video-wrap {
  position: relative; border-radius: 16px; overflow: hidden;
  background: #000; aspect-ratio: 3/4;
}
#cap-video { width: 100%; height: 100%; object-fit: cover; }
.cap-overlay { position: absolute; inset: 0; pointer-events: none; }
.cap-sil {
  position: absolute; left: 50%; top: 50%;
  width: 62%; height: 74%;
  transform: translate(-50%, -50%);
  border: 3px dashed rgba(255, 255, 255, 0.85);
  border-radius: 50% 50% 46% 46% / 55% 55% 42% 42%;
  box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.25);
}
.cap-sil::after {
  content: "▲ nariz";
  position: absolute; top: -26px; left: 50%; transform: translateX(-50%);
  color: #fff; font-size: 12px; white-space: nowrap;
}
/* grade de tercos da captura guiada (referencia de enquadramento) */
.cap-grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(to right, transparent calc(33.333% - 1px), rgba(255,255,255,.34) calc(33.333% - 1px), rgba(255,255,255,.34) calc(33.333% + 1px), transparent calc(33.333% + 1px)),
    linear-gradient(to right, transparent calc(66.666% - 1px), rgba(255,255,255,.34) calc(66.666% - 1px), rgba(255,255,255,.34) calc(66.666% + 1px), transparent calc(66.666% + 1px)),
    linear-gradient(to bottom, transparent calc(33.333% - 1px), rgba(255,255,255,.34) calc(33.333% - 1px), rgba(255,255,255,.34) calc(33.333% + 1px), transparent calc(33.333% + 1px)),
    linear-gradient(to bottom, transparent calc(66.666% - 1px), rgba(255,255,255,.34) calc(66.666% - 1px), rgba(255,255,255,.34) calc(66.666% + 1px), transparent calc(66.666% + 1px));
}

.cap-cross {
  position: absolute; left: 50%; top: 50%; width: 18px; height: 18px;
  transform: translate(-50%, -50%);
}
.cap-cross::before, .cap-cross::after {
  content: ""; position: absolute; background: rgba(255, 255, 255, 0.9);
}
.cap-cross::before { left: 8px; top: 0; width: 2px; height: 18px; }
.cap-cross::after { top: 8px; left: 0; height: 2px; width: 18px; }
#cap-level {
  position: absolute; top: 10px; right: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.cap-ring {
  width: 84px; height: 84px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8);
  background: rgba(0, 0, 0, 0.25);
  position: relative;
}
.cap-ring::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 26px; height: 26px; border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 1.5px dashed rgba(255, 255, 255, 0.7);
}
#cap-bubble {
  position: absolute; left: 50%; top: 50%; margin: -9px 0 0 -9px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fbbf24;
  transition: transform 0.1s linear, background 0.2s;
}
#cap-bubble.ok { background: #4ade80; }
.cap-status {
  font-size: 11px; color: #fff; background: rgba(0, 0, 0, 0.45);
  padding: 3px 9px; border-radius: 999px;
}
.cap-status.ok { background: rgba(22, 163, 74, 0.85); }
.cap-tip { color: #cbd5e1; text-align: center; font-size: 13px; margin: 0; }
.cap-actions { display: flex; align-items: center; justify-content: space-between; }
.cap-actions .btn { background: transparent; color: #fff; border-color: #475569; width: 86px; }
.cap-shutter {
  width: 68px; height: 68px; border-radius: 50%;
  border: 4px solid #fff; background: rgba(255, 255, 255, 0.25);
  cursor: pointer; transition: transform 0.1s;
}
.cap-shutter:active { transform: scale(0.92); background: rgba(255, 255, 255, 0.5); }

/* historico */
.h-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
@media (max-width: 560px) {
  .h-title { flex: 1 0 100%; }          /* status ganha a largura toda no celular */
  .h-actions { width: 100%; }
  .h-actions .btn-primary { flex: 1; }
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-size: 12px; padding: 8px 6px; border-bottom: 2px solid var(--line); }
td { padding: 9px 5px; border-bottom: 1px solid var(--line); vertical-align: top; }
td .chip { font-size: 11px; padding: 2px 8px; }
tr:last-child td { border-bottom: 0; }
canvas.chart { width: 100%; display: block; }

/* toasts */
#toasts { position: fixed; top: 12px; left: 0; right: 0; z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: #134e4a; color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 14px;
  opacity: 0; transform: translateY(-8px); transition: all 0.3s;
  max-width: 92%;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.toast.show { opacity: 1; transform: none; }
.toast-err { background: #b91c1c; }

@media (min-width: 700px) {
  .results-grid { grid-template-columns: repeat(4, 1fr); }
  .canvas-tools .btn { flex: 0 1 auto; }
}

/* login */
.login-wrap { max-width: 400px; margin: 24px auto 0; display: flex; flex-direction: column; gap: 8px; }
.login-logo { width: min(290px, 82vw); height: auto; margin: 0 auto; display: block; }
.welcome-logo { width: 96px; height: 96px; margin: 8px auto 0; object-fit: contain; background: transparent; box-shadow: none; }
.login-card { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.btn-link { border: 0; background: none; color: var(--teal); font-size: 14px; padding: 10px 0 2px; cursor: pointer; }
.btn-link:hover { text-decoration: underline; }

/* usuario no header */
.user-box { display: flex; align-items: center; gap: 10px; }
.user-info { text-align: right; line-height: 1.15; }
.user-info b { font-size: 14px; display: block; }
.user-role { font-size: 11px; opacity: 0.85; }
.btn-header { background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.35); color: #fff; padding: 7px 11px; font-size: 13px; }
.btn-header:hover { background: rgba(255,255,255,0.25); color: #fff; }

/* tags de vinculo */
.tag-doctor { display: inline-block; margin-top: 4px; font-size: 11.5px; color: var(--teal-dark);
  background: var(--teal-soft); border-radius: 999px; padding: 2px 9px; }
.tag-own { background: #fdf4ff; color: #86198f; }

/* anotacoes */
.note-add { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 12px; }
.note-add textarea { flex: 1; }
.note-item { border-top: 1px solid var(--line); padding: 10px 2px; }
.note-item:first-of-type { border-top: 0; }
.note-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.note-body { font-size: 14px; margin-top: 4px; white-space: pre-wrap; }

/* responsaveis */
.guardian-item { display: flex; justify-content: space-between; align-items: center;
  padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.guardian-item:last-child { border-bottom: 0; }
.guardian-add { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.guardian-add input { flex: 1; min-width: 150px; }
.confirm-text { white-space: pre-wrap; }

/* abas dos filhos (perfil responsavel) */
.nav-child .child-avatar {
  display: block; width: 30px; height: 30px; margin: 0 auto 3px;
  border-radius: 50%; color: #fff; font-weight: 700; font-size: 15px;
  line-height: 30px; text-align: center;
  background: #94a3b8;
}
.nav-child.active .child-avatar { outline: 2.5px solid var(--teal); outline-offset: 1.5px; }
.child-avatar.sex-M, .child-avatar-big.sex-M { background: #38bdf8; }
.child-avatar.sex-F, .child-avatar-big.sex-F { background: #f472b6; }
.nav-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-add .ico { color: var(--teal); }

/* hero da crianca */
.h-title { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.h-actions { display: flex; gap: 8px; align-items: center; }
.child-avatar-big {
  width: 54px; height: 54px; border-radius: 50%; flex-shrink: 0;
  color: #fff; font-weight: 800; font-size: 26px;
  line-height: 54px; text-align: center;
  background: #94a3b8;
  box-shadow: var(--shadow);
}
.hero-status {
  margin-top: 5px; font-size: 13.5px; color: var(--teal-dark);
  background: var(--teal-soft); border-radius: 10px; padding: 6px 10px;
  display: inline-block; line-height: 1.45;
}
.hero-status.warn { background: #fff7ed; color: #9a3412; }
.hero-status.alert { background: #fef2f2; color: #b91c1c; }

/* medicao multiangulo */
.section-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--teal-dark); font-weight: 700; margin-bottom: 8px; }
.hc-row { display: flex; gap: 10px; align-items: stretch; }
.hc-row input { max-width: 110px; }
.hc-result { flex: 1; display: flex; align-items: center; padding: 8px 12px;
  background: #f8fafc; border: 1px solid var(--line); border-radius: 11px; font-size: 13.5px; }
.hc-result b { font-size: 16px; }
.aux-photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.aux-slot { display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 12px 6px; border: 1.5px dashed var(--line); border-radius: 11px;
  cursor: pointer; font-size: 12px; color: var(--muted); background: #fbfdfe;
  min-height: 82px; text-align: center; background-size: cover; background-position: center; }
.aux-slot:hover { border-color: var(--teal); }
.aux-slot.filled { border-style: solid; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.6); }
.aux-slot.filled .aux-ico { display: none; }
.aux-ico { font-size: 22px; }
/* thumbs no historico */
.aux-thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.aux-thumb { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); cursor: pointer; }
.aux-thumb-lbl { font-size: 10px; color: var(--muted); text-align: center; }

/* ---- UX: os pais têm as MESMAS opções de medição do médico ----
   (o app é feito para os pais medirem). Mantemos só a linguagem amigável
   e a conveniência do nome do filho; nenhuma ferramenta é escondida. */
.measure-child {
  flex: 2; min-width: 180px; display: flex; align-items: center;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px;
  background: #f8fafc; font-weight: 600; color: var(--teal-dark);
}
/* leitura ao vivo logo abaixo do canvas (feedback perto da ação) */
.m-live {
  display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px;
  background: #f0f7fa; border: 1px solid var(--line); border-radius: 11px;
  padding: 8px 12px; align-items: center;
}
.m-live-item { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.m-live-item b { font-size: 17px; color: var(--text); }
.term-clin { color: var(--muted); font-weight: 400; font-size: 0.85em; }
body.measure-simple .term-clin { display: none; }
.screening-note {
  font-size: 12.5px; color: #7c5b12; background: #fefce8; border: 1px solid #fde68a;
  border-radius: 10px; padding: 8px 11px; margin: 12px 0 10px; line-height: 1.45;
}
/* aux photos como botões (câmera/galeria via chooser) */
.aux-slot { position: relative; }
.aux-slot:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
/* toque mínimo 44px e foco visível global */
.btn, .nav-btn { min-height: 40px; }
:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
/* chips com texto um pouco mais escuro (contraste AA) */
.sev-0 { color: #15803d; }
.sev-1 { color: #a16207; }

/* ---- fluxo da medição: só mostrar o ajuste depois de escolher a foto ---- */
#view-measure:not(.has-photo) #m-canvas-wrap,
#view-measure:not(.has-photo) .canvas-tools,
#view-measure:not(.has-photo) #calib-row,
#view-measure:not(.has-photo) .legend,
#view-measure:not(.has-photo) #m-adjust-hint,
#view-measure:not(.has-photo) #m-live,
#view-measure:not(.has-photo) #m-results { display: none !important; }
#view-measure.has-photo #m-start-hint { display: none; }
.start-hint {
  text-align: center; color: var(--teal-dark); font-weight: 600;
  font-size: 14.5px; margin: 6px 0 8px;
}
/* botões de foto maiores enquanto não há foto (ação principal clara) */
#view-measure:not(.has-photo) .photo-btns { gap: 10px; }
#view-measure:not(.has-photo) .photo-btns .btn { padding: 15px 14px; font-size: 15.5px; }
/* quando já há foto, os botões viram “trocar foto”, discretos */
#view-measure.has-photo .photo-btns .btn { padding: 8px 12px; font-size: 13.5px; opacity: 0.9; }

/* ---- linguagem simples para os pais ---- */
.simple-only { display: none; }
body.measure-simple .simple-only { display: block; }
.adjust-hint {
  font-size: 13px; color: var(--teal-dark); background: #eef7fa;
  border: 1px solid #bfe3ec; border-radius: 10px; padding: 8px 12px; margin: 8px 0 0; line-height: 1.5;
}
.m-summary {
  font-size: 15px; font-weight: 600; border-radius: 11px;
  padding: 11px 14px; margin: 0 0 12px; line-height: 1.45;
}
.sev-bg-0 { background: #dcfce7; color: #15803d; }
.sev-bg-1 { background: #fef9c3; color: #854d0e; }
.sev-bg-2 { background: #ffedd5; color: #9a3412; }
.sev-bg-3 { background: #fee2e2; color: #b91c1c; }

/* histórico simplificado para pais: esconde a coluna clínica de perímetro */
body.hist-simple .hist-table .th-pc { display: none; }

/* ---- botão fechar (X) nos modais + fechar clicando fora/Esc ---- */
.modal-box { position: relative; }
.modal-x {
  position: absolute; top: 10px; right: 10px;
  width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: #eef2f6; color: #475569;
  font-size: 15px; line-height: 32px; text-align: center; cursor: pointer;
  transition: background 0.15s;
}
.modal-x:hover { background: #e2e8f0; color: var(--text); }
.modal-box h3 { padding-right: 34px; }
.confirm-text { padding-right: 30px; }

/* ============================================================
   DESIGN POLISH & ANIMAÇÕES
   ============================================================ */
:root {
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.06), 0 10px 26px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 14px 36px rgba(14, 116, 144, 0.18);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.4, 0.5, 1);
}

/* fundo com leve profundidade */
body { background: radial-gradient(1200px 600px at 50% -10%, #eaf5f8 0%, var(--bg) 60%); }

/* transição de telas */
.view.active { animation: viewIn 0.34s var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* entrada escalonada de cards/stats */
.view.active .card,
.view.active .stat,
.view.active .patient-card,
.view.active .m-live,
.view.active #m-results { animation: cardUp 0.42s var(--ease) both; }
.view.active .card:nth-child(2) { animation-delay: 0.05s; }
.view.active .card:nth-child(3) { animation-delay: 0.10s; }
.view.active .card:nth-child(4) { animation-delay: 0.15s; }
.view.active .patient-card:nth-child(2) { animation-delay: 0.05s; }
.view.active .patient-card:nth-child(3) { animation-delay: 0.10s; }
.view.active .patient-card:nth-child(4) { animation-delay: 0.15s; }
.view.active .patient-card:nth-child(5) { animation-delay: 0.20s; }
@keyframes cardUp { from { opacity: 0; transform: translateY(14px) scale(0.99); } to { opacity: 1; transform: none; } }

/* cards mais macios + brilho no hover */
.card { border-radius: 16px; box-shadow: var(--shadow); transition: box-shadow 0.25s var(--ease), transform 0.25s var(--ease); }
.stat { border-radius: 16px; transition: transform 0.2s var(--spring), box-shadow 0.2s var(--ease); }
.stat:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.stat b { transition: transform 0.2s var(--spring); }
.stat:hover b { transform: scale(1.06); }

/* botões: elevação e clique com mola */
.btn { transition: transform 0.12s var(--spring), box-shadow 0.2s var(--ease), background 0.15s, border-color 0.15s, color 0.15s; }
.btn:active { transform: scale(0.95); }
.btn-primary { box-shadow: 0 4px 14px rgba(14, 116, 144, 0.28); }
.btn-primary:hover { box-shadow: 0 6px 20px rgba(14, 116, 144, 0.36); transform: translateY(-1px); }
.btn-primary:active { transform: scale(0.96); }
.btn-big { border-radius: 13px; }

/* navegação inferior: indicador ativo com mola */
.nav-btn { position: relative; transition: color 0.2s var(--ease); }
.nav-btn .ico { display: block; transition: transform 0.25s var(--spring); }
.nav-btn.active .ico { transform: translateY(-2px) scale(1.14); }
.nav-btn.active::after {
  content: ""; position: absolute; top: 4px; left: 50%; width: 30px; height: 30px;
  transform: translateX(-50%); border-radius: 50%;
  background: radial-gradient(circle, rgba(14,116,144,0.14), transparent 70%);
  animation: popDot 0.3s var(--spring);
}
@keyframes popDot { from { transform: translateX(-50%) scale(0.4); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
.child-avatar { transition: transform 0.25s var(--spring), outline-color 0.2s; }
.nav-child.active .child-avatar { transform: scale(1.1); }

/* chips: aparecem com micro-escala */
.chip { transition: background 0.2s, color 0.2s; animation: chipIn 0.25s var(--spring); }
@keyframes chipIn { from { transform: scale(0.85); opacity: 0.6; } to { transform: scale(1); opacity: 1; } }
.sev-3 { animation: chipIn 0.25s var(--spring), pulseAlert 2s ease-in-out 0.3s 2; }
@keyframes pulseAlert { 0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,0); } 50% { box-shadow: 0 0 0 5px rgba(220,38,38,0.12); } }

/* passos da medição */
.step { transition: background 0.25s var(--ease), color 0.25s, transform 0.2s var(--spring); }
.step.active { transform: scale(1.05); }
.step.done::before { content: "✓ "; }

/* resultado da medição surge de baixo */
#view-measure.has-photo #m-results { animation: cardUp 0.4s var(--ease) both; }
.m-live { border-radius: 12px; animation: cardUp 0.35s var(--ease) both; }
.metric { transition: transform 0.2s var(--spring), box-shadow 0.2s var(--ease); }
.metric:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.metric b { transition: color 0.25s; }

/* resumo (frase) para os pais entra suave */
.m-summary { animation: cardUp 0.4s var(--ease) both; }

/* modais: fundo com blur + caixa com mola */
.modal { backdrop-filter: blur(3px); animation: fadeBg 0.2s var(--ease); }
@keyframes fadeBg { from { opacity: 0; } to { opacity: 1; } }
.modal-box, .capture-box { animation: modalPop 0.28s var(--spring); }
@keyframes modalPop { from { opacity: 0; transform: translateY(16px) scale(0.94); } to { opacity: 1; transform: none; } }
.modal-x { transition: background 0.15s, transform 0.15s var(--spring); }
.modal-x:active { transform: scale(0.88); }

/* toasts com mola */
.toast { border-radius: 14px; transition: opacity 0.35s var(--ease), transform 0.35s var(--spring); }

/* hero da criança: avatar flutua de leve */
.child-avatar-big { animation: float 4s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.hero-status { animation: cardUp 0.4s var(--ease) both; }

/* skeleton shimmer para carregamento */
.skeleton {
  border-radius: 12px; height: 74px; margin-bottom: 12px;
  background: linear-gradient(100deg, #eef3f6 30%, #f7fafc 50%, #eef3f6 70%);
  background-size: 200% 100%; animation: shimmer 1.2s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* estados vazios mais amigáveis */
.empty { animation: viewIn 0.4s var(--ease); }

/* logo do header com leve brilho ao tocar */
header .logo-img { transition: transform 0.3s var(--spring); }
header .logo-img:active { transform: rotate(-8deg) scale(0.92); }

/* recent items deslizam ao passar */
.recent-item { transition: background 0.18s var(--ease), transform 0.18s var(--ease); }
.recent-item:hover { transform: translateX(3px); }

/* respeita quem prefere menos movimento */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .child-avatar-big { animation: none; }
}

/* ============================================================
   AJUSTES MOBILE
   ============================================================ */
/* grade de resultados nunca estoura a largura */
.results-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.metric { min-width: 0; overflow: hidden; }
.metric b { overflow-wrap: anywhere; }
.metric .chip { white-space: normal; max-width: 100%; line-height: 1.25; }
.m-live { flex-wrap: wrap; }
.m-live-item { min-width: 0; flex-wrap: wrap; }
.chip { white-space: normal; }

/* histórico: tabela (médico) rola só dentro do card; lista (pais) padrão */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.meas-list { display: none; }
body.hist-simple .table-scroll { display: none; }
body.hist-simple .meas-list { display: block; }

/* cartão de medição (pais) */
.meas-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: #fbfdfe; }
.meas-card:last-child { margin-bottom: 0; }
.meas-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.meas-when b { font-size: 14.5px; }
.meas-metrics { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; font-size: 13.5px; }
.meas-actions { display: flex; gap: 8px; margin-top: 10px; }
.meas-actions .btn { flex: 1; }

/* telas estreitas: reduz gaps e fontes de textos densos */
@media (max-width: 400px) {
  main { padding: 14px 12px; }
  h2 { font-size: 18px; }
  .results-grid { gap: 8px; }
  .metric { padding: 9px 6px; }
  .metric b { font-size: 22px; }
  .metric .lbl { font-size: 10px; }
  .measure-top { gap: 6px; }
  .measure-top select, .measure-child { min-width: 140px; }
  .photo-btns .btn { min-width: 0; }
  .canvas-tools .btn { min-width: 0; font-size: 13px; padding: 9px 8px; }
  .aux-photos { gap: 6px; }
  .aux-slot { min-height: 74px; font-size: 11px; }
  header h1 { font-size: 19px; }
  .user-info b { font-size: 13px; }
  .btn-header { padding: 6px 9px; font-size: 12px; }
  .stat b { font-size: 23px; }
  .modal-box { padding: 16px; }
}
/* telas muito estreitas: header enxuto */
@media (max-width: 340px) {
  header .tag { display: none; }
  .photo-btns { gap: 6px; }
}

/* ============================================================
   TABELA CLÍNICA → CARTÕES EMPILHADOS NO CELULAR
   (evita quebra de linha feia; cada campo em sua própria linha)
   ============================================================ */
@media (max-width: 620px) {
  .hist-table thead { display: none; }
  .hist-table, .hist-table tbody, .hist-table tr, .hist-table td { display: block; width: 100%; }
  .hist-table { border-collapse: separate; }
  .hist-table tr {
    border: 1px solid var(--line); border-radius: 12px;
    padding: 8px 12px; margin-bottom: 10px; background: #fbfdfe;
  }
  .hist-table tr:last-child td { border-bottom: 0; }
  .hist-table td {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 12px; padding: 7px 0; border-bottom: 1px solid #eef2f6;
  }
  .hist-table td::before {
    content: attr(data-label);
    color: var(--muted); font-size: 12px; font-weight: 600;
    text-align: left; flex: 0 0 auto; padding-top: 1px;
  }
  .hist-table td .td-v {
    flex: 1 1 auto; min-width: 0;
    display: flex; flex-direction: column; align-items: flex-end;
    text-align: right; gap: 1px; overflow-wrap: anywhere;
  }
  .hist-table td:last-child { border-bottom: 0; }
  .hist-table .td-actions { justify-content: flex-end; padding-top: 10px; }
  .hist-table .td-actions::before { content: ""; }
  .hist-table .td-actions .btn { flex: 1; }
  .table-scroll { overflow-x: visible; }             /* não precisa rolar */
}

/* itens recentes (início) empilham sem cortar em telas estreitas */
@media (max-width: 420px) {
  .recent-item { flex-wrap: wrap; }
  .recent-metrics { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .guardian-item { flex-wrap: wrap; }
  .guardian-item .btn { margin-top: 6px; }
}

/* subtexto das células (classe/percentil abaixo do número) */
.hist-table .td-sub { display: block; font-size: 11px; color: var(--muted); line-height: 1.3; }

/* ============================================================
   IDENTIDADE MAMA HEADS (teal profundo + verde sálvia)
   ============================================================ */
body {
  background:
    radial-gradient(900px 500px at 100% -5%, var(--coral-soft) 0%, transparent 55%),
    radial-gradient(1100px 620px at 0% 0%, var(--teal-soft) 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

/* header mais suave, alinhado ao logo */
header { background: linear-gradient(125deg, var(--teal-dark) 0%, var(--teal) 68%, var(--sage) 140%); }
header .logo-img { background: transparent; box-shadow: none; }

/* acentos coral (calor) usados com parcimônia */
.btn-link { color: var(--coral-dark); }
.nav-add .ico { color: var(--coral-dark); }
.nav-btn.nav-add.active { color: var(--coral-dark); }
.nav-btn.active::after { background: radial-gradient(circle, rgba(255,155,122,0.20), transparent 70%); }
.tag-own { background: var(--coral-soft); color: var(--coral-dark); }
a, .link { color: var(--coral-dark); }

/* cartões e superfícies um pouco mais quentes */
.card, .stat, .metric, .meas-card, .aux-slot, .hc-result { background: #ffffff; }
.metric, .hc-result { background: #fbfcfb; }

/* botão primário com leve profundidade da marca */
.btn-primary { background: linear-gradient(180deg, #098196, var(--teal)); border-color: var(--teal); box-shadow: 0 6px 18px rgba(8, 112, 131, 0.24); }
.btn-primary:hover { background: linear-gradient(180deg, var(--teal), var(--teal-dark)); }

/* login: assinatura completa da marca em destaque */
.login-logo { width: min(290px, 82vw); height: auto; border-radius: 0; box-shadow: none; }
#login-title { margin-top: -8px; letter-spacing: 0.2px; }

/* chip "dentro do esperado" ganha leve toque de marca no hero */
.hero-status { background: var(--teal-soft); color: var(--teal-dark); border: 1px solid #cfe9e6; }

/* stat "em atenção" combina com coral quando aplicável já usa laranja — mantemos */
.stat-warn b { color: var(--coral-dark); }

/* passo ativo e detalhes de foco na cor da marca */
.step.active { background: var(--teal); }
:focus-visible { outline-color: var(--teal); }

/* títulos um pouco mais fortes */
h2 { letter-spacing: -0.2px; }
.card-title { letter-spacing: 0.1px; }

/* ---- Travar foto: fixa a imagem para ajustar só os pontos ---- */
#m-lock.on, #f-lock.on { background: rgba(14, 138, 138, 0.92); border-color: var(--teal); color: #fff; }
.photo-locked { outline: 2px solid var(--teal); outline-offset: -2px; border-radius: 12px; }

/* ---- Vista frontal (assimetria das orelhas) ---- */
.frontal-block { margin-top: 14px; border-top: 1px dashed #cbd5e1; padding-top: 10px; }
.frontal-block > summary { cursor: pointer; list-style: none; display: flex; align-items: center; }
.frontal-block > summary::-webkit-details-marker { display: none; }
.frontal-block > summary::before { content: "▸"; margin-right: 6px; color: var(--teal); transition: transform .15s; }
.frontal-block[open] > summary::before { transform: rotate(90deg); }
#f-canvas-wrap { position: relative; margin-top: 8px; }
#f-canvas { width: 100%; display: block; background: #eef3f6; border-radius: 12px; touch-action: none; box-shadow: var(--shadow); }

/* login: divisor "ou" + botão de criar conta em destaque coral */
.login-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 12px 0 2px; color: var(--muted); font-size: 12.5px;
}
.login-divider::before, .login-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}
.btn-signup {
  background: var(--coral-soft);
  border: 1.5px solid var(--coral);
  color: var(--coral-dark);
  font-weight: 600;
  border-radius: 13px;
}
.btn-signup:hover {
  background: linear-gradient(180deg, var(--coral), var(--coral-dark));
  border-color: var(--coral-dark);
  color: #fff;
  box-shadow: 0 6px 18px rgba(244, 121, 79, 0.30);
  transform: translateY(-1px);
}
.btn-signup:active { transform: scale(0.96); }
.login-signup-options { display: grid; gap: 8px; }
.login-card [hidden] { display: none !important; }
.btn-doctor-signup {
  background: var(--teal-soft);
  border-color: var(--teal);
  color: var(--teal-dark);
}
.btn-doctor-signup:hover {
  background: linear-gradient(180deg, var(--teal), var(--teal-dark));
  border-color: var(--teal-dark);
  box-shadow: 0 6px 18px rgba(5, 82, 100, 0.24);
}
.btn-login-back {
  background: #f8fafc;
  border: 1px solid var(--line);
  color: var(--teal-dark);
}
.btn-login-back:hover { background: var(--teal-soft); border-color: var(--teal); }

/* trava da foto: botao flutuante dentro do quadro (mais facil de alcancar) */
.btn-lock {
  position: absolute; top: 8px; right: 8px; z-index: 6;
  flex: none; min-height: 0; width: auto;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 12.5px; font-weight: 600; padding: 6px 11px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.18);
}
.btn-lock:hover { border-color: var(--teal); color: var(--teal); }
#m-lock.on:hover, #f-lock.on:hover { background: var(--teal-dark); border-color: var(--teal-dark); color: #fff; }

/* botao voltar das telas internas */
.btn-back {
  display: inline-flex; align-items: center; gap: 4px;
  margin-bottom: 10px; padding: 7px 13px 7px 10px;
  border-radius: 999px; font-size: 13.5px; font-weight: 600;
  color: var(--teal-dark); background: var(--card);
}
.btn-back:hover { border-color: var(--teal); color: var(--teal); }

/* celular: botoes abaixo da foto em grade 2 colunas, sem texto cortado */
@media (max-width: 520px) {
  .canvas-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .canvas-tools .btn {
    min-width: 0; width: 100%;
    font-size: 13.5px; padding: 12px 8px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
}

/* voltar: respeita o atributo hidden (a regra .btn-back sobrescreveria o UA) */
.btn-back[hidden] { display: none; }

/* novo paciente na medicao: some para responsaveis (cadastram pela aba propria) */
body.measure-simple #m-new-patient { display: none; }

/* perfil no topo: o bloco do usuario e clicavel */
button.user-info {
  background: none; border: 0; padding: 4px 6px; margin: 0;
  font: inherit; color: inherit; text-align: right; cursor: pointer;
  display: flex; flex-direction: column; align-items: flex-end;
  border-radius: 9px;
}
button.user-info:hover { background: rgba(255, 255, 255, 0.14); }

/* entrega do acesso da familia (credenciais copiaveis) */
.cred-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--teal-soft); border: 1px solid #cfe9e6;
  border-radius: 11px; padding: 9px 10px; margin-bottom: 8px;
}
.cred-label { font-size: 12px; color: var(--muted); flex: 0 0 auto; min-width: 108px; }
.cred-value {
  flex: 1; min-width: 0; font-size: 14.5px; font-weight: 600;
  color: var(--teal-dark); overflow-wrap: anywhere; user-select: all;
  background: none; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.access-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.access-actions .btn-grow { flex: 1; min-width: 130px; white-space: normal; line-height: 1.3; }


/* ===== Termos de Uso / Privacidade / consentimento LGPD ===== */
.modal-doc { max-width: 560px; }
#terms-modal { z-index: 60; }   /* leitor de documentos por cima do portao de consentimento */
.modal-block { backdrop-filter: blur(5px); background: rgba(15, 23, 42, 0.62); }
.doc-body {
  max-height: 46vh; overflow-y: auto; padding-right: 6px;
  font-size: 13.5px; line-height: 1.55; color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  background: #fbfdfd;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.doc-body-sm { max-height: 34vh; font-size: 13px; }
.doc-body h4 { margin: 14px 0 4px; font-size: 13.5px; color: var(--teal-dark); }
.doc-body h4:first-child { margin-top: 0; }
.doc-body p { margin: 0 0 8px; }
.doc-body ul { margin: 0 0 8px; padding-left: 18px; }
.doc-body li { margin-bottom: 5px; }
.doc-body a { color: var(--teal-dark); }
.doc-meta { font-size: 11.5px; color: var(--muted); margin-bottom: 10px !important; }
.consent-line {
  display: flex; gap: 10px; align-items: flex-start;
  font-size: 12.8px; line-height: 1.45; color: var(--text);
  margin: 12px 0 4px; cursor: pointer;
}
.consent-line input[type="checkbox"] {
  width: 20px; height: 20px; min-width: 20px; margin: 1px 0 0; accent-color: var(--teal);
}
.consent-line a { color: var(--teal-dark); }
.consent-strong {
  background: var(--teal-soft); border: 1px solid #bfe3e0;
  border-radius: 12px; padding: 10px 12px; margin: 12px 0 2px;
}
.legal-links { text-align: center; font-size: 12px; color: var(--muted); margin: 14px 0 0; }
.legal-links a { color: var(--teal-dark); text-decoration: none; }
.legal-links a:hover { text-decoration: underline; }

/* bloco de privacidade dentro do perfil */
.privacy-block { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.privacy-block > summary {
  cursor: pointer; font-weight: 600; color: var(--teal-dark); font-size: 13.5px;
  list-style: none;
}
.privacy-block > summary::-webkit-details-marker { display: none; }
.privacy-block > summary::before { content: "▸"; margin-right: 6px; transition: transform .15s; display: inline-block; }
.privacy-block[open] > summary::before { transform: rotate(90deg); }
.privacy-block a { color: var(--teal-dark); }
.danger-zone {
  margin-top: 14px; border: 1px solid #fecaca; background: #fef2f2;
  border-radius: 12px; padding: 12px;
}
.danger-zone .form-row { margin-bottom: 8px; }
