:root {
  --bg: #f5f3ee; --card: #ffffff; --txt: #1c2320; --mute: #66706b; --linha: #e4e1d9;
  --prim: #0f6e66; --prim-txt: #ffffff; --prim-c: #e2f0ee;
  --perigo: #b3261e; --perigo-c: #fbe9e7; --aviso: #8a5300; --aviso-c: #fdf0d9;
  --s2: #c2701e; --banda: rgba(15, 110, 102, .12);
  --raio: 14px; --sombra: 0 1px 2px rgba(0,0,0,.05), 0 2px 10px rgba(0,0,0,.04);
  --nav-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513; --card: #1a201d; --txt: #e8ece9; --mute: #9aa39e; --linha: #2b332f;
    --prim: #4db3a7; --prim-txt: #062421; --prim-c: #1b3330;
    --perigo: #ff8a80; --perigo-c: #3a1f1d; --aviso: #f0b55a; --aviso-c: #35291a;
    --s2: #f0a35a; --banda: rgba(77, 179, 167, .16); --sombra: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--txt);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.sem-scroll { overflow: hidden; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.02rem; margin: 2px 0 8px; }
p { margin: 6px 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.mute { color: var(--mute); }
.peq { font-size: .85rem; }
.flex { flex: 1; min-width: 0; }
.txt-fora { color: var(--perigo); }
[hidden] { display: none !important; }

/* cabeçalho */
.cab {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; background: var(--bg);
  border-bottom: 1px solid var(--linha);
}
.pessoa-btn {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; border: 0; background: none;
  padding: 4px; font-weight: 650; font-size: 1.05rem; text-align: left;
}
.pessoa-btn .pn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pessoa-btn .seta { color: var(--mute); font-size: .8rem; }
.icon-btn {
  width: 42px; height: 42px; display: grid; place-items: center; border: 0; border-radius: 50%;
  background: transparent; font-size: 1.6rem; line-height: 1;
}
.icon-btn:active { background: var(--linha); }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.main { max-width: 720px; margin: 0 auto; padding: 14px 14px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); }

/* navegação */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(6, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--linha);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--mute); font-size: .68rem; padding: 0;
}
.tab svg { width: 22px; height: 22px; }
.tab.ativo { color: var(--prim); font-weight: 650; }

/* cartões e listas */
.card { background: var(--card); border-radius: var(--raio); box-shadow: var(--sombra); padding: 14px; margin-bottom: 12px; border: 1px solid var(--linha); }
.card-h { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.card h3 + h3, .card ul + h3, .card p + h3 { margin-top: 14px; }
.topo { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 12px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.sec { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--mute); margin: 18px 4px 8px; font-weight: 650; }
.vazio { text-align: center; color: var(--mute); padding: 32px 16px; border: 1.5px dashed var(--linha); border-radius: var(--raio); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--linha); background: var(--card); font-weight: 600;
}
.btn:active { opacity: .75; }
.btn.prim { background: var(--prim); color: var(--prim-txt); border-color: var(--prim); }
.btn.perigo { color: var(--perigo); border-color: var(--perigo); background: transparent; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: .88rem; }
.btn.bloco { display: flex; width: 100%; margin-top: 10px; }
.lnk { border: 0; background: none; color: var(--prim); font-weight: 600; padding: 6px 2px; font-size: .9rem; }

.avatar {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--prim-c); color: var(--prim); font-weight: 700;
}
.avatar.sm { width: 32px; height: 32px; font-size: .8rem; }
.perfil-top { display: flex; align-items: center; gap: 12px; }
.dados { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 14px 0 4px; }
.dados dt { font-size: .78rem; color: var(--mute); }
.dados dd { margin: 0; font-weight: 600; word-break: break-word; }
.tags { list-style: none; padding: 0; margin: 0 0 4px; display: flex; flex-wrap: wrap; gap: 6px; }
.tags li { padding: 4px 10px; border-radius: 99px; background: var(--prim-c); font-size: .9rem; }
.tags.alerta li { background: var(--perigo-c); color: var(--perigo); font-weight: 600; }
.simples { list-style: none; padding: 0; margin: 0; }
.simples li { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; padding: 9px 0; border-top: 1px solid var(--linha); }
.simples li:first-child { border-top: 0; }
.simples li .mute { margin-left: auto; font-size: .88rem; }
.aviso-b {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 12px; border-radius: 12px;
  background: var(--aviso-c); color: var(--aviso); font-size: .9rem;
}
.boas-vindas p { margin: 10px 0; }

.item {
  display: flex; gap: 12px; background: var(--card); border: 1px solid var(--linha); border-radius: var(--raio);
  padding: 12px; margin-bottom: 8px; box-shadow: var(--sombra); cursor: pointer;
}
.item:active { background: var(--prim-c); }
.item-c { flex: 1; min-width: 0; }
.item-t { font-weight: 650; }
.item-s { color: var(--mute); font-size: .9rem; }
.item-r { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.item-r .lnk { margin-left: auto; }
.nota { margin: 6px 0 0; font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.data-bloco {
  flex: none; width: 52px; text-align: center; border-radius: 10px; background: var(--prim-c); color: var(--prim);
  display: flex; flex-direction: column; justify-content: center; padding: 6px 0; line-height: 1.1;
}
.data-bloco b { font-size: 1.35rem; }
.data-bloco span { font-size: .78rem; font-weight: 600; text-transform: uppercase; }
.data-bloco small { font-size: .68rem; opacity: .8; }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--linha); color: var(--txt); font-weight: 600; }
.badge.e-agendada { background: var(--prim-c); color: var(--prim); }
.badge.e-cancelada, .badge.e-faltou { background: var(--perigo-c); color: var(--perigo); }

.tarefa .caixa {
  flex: none; width: 28px; height: 28px; margin-top: 2px; border-radius: 8px; border: 2px solid var(--prim);
  background: transparent; color: var(--prim-txt); font-weight: 800; display: grid; place-items: center; padding: 0;
}
.tarefa.feita .caixa { background: var(--prim); }
.tarefa.feita .item-t { text-decoration: line-through; color: var(--mute); }
.tarefa.atraso { border-color: var(--perigo); }
.tarefa.atraso .item-s:last-child { color: var(--perigo); }

/* histórico */
.pesquisa {
  width: 100%; min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--linha); background: var(--card); margin-bottom: 10px;
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--linha); background: var(--card); border-radius: 99px; padding: 7px 14px; font-size: .9rem; white-space: nowrap;
}
.chip.ativo { background: var(--prim); border-color: var(--prim); color: var(--prim-txt); font-weight: 600; }
.ev-d { flex: none; width: 44px; font-weight: 700; color: var(--mute); font-size: .9rem; padding-top: 2px; }
.tipo { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--mute); }
.t-consultas { color: var(--prim); }
.t-medicoes { color: var(--s2); }
.ev .item-s { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* análises */
.card-h select { min-height: 36px; border-radius: 10px; border: 1px solid var(--linha); background: var(--card); padding: 0 8px; }
.graf { width: 100%; height: auto; display: block; margin-top: 6px; }
.graf .banda { fill: var(--banda); stroke: none; }
.graf .grelha { stroke: var(--linha); stroke-width: 1; }
.graf .eixo { fill: var(--mute); font-size: 10.5px; stroke: none; }
.graf .linha { fill: none; stroke: var(--prim); stroke-width: 2.2; }
.graf .linha.s2 { stroke: var(--s2); }
.graf .pt { fill: var(--card); stroke: var(--prim); stroke-width: 2.2; }
.graf .pt.s2 { stroke: var(--s2); }
.graf .pt.fora { fill: var(--perigo); stroke: var(--perigo); }
.legenda { font-size: .8rem; color: var(--mute); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.lg { display: inline-block; width: 14px; height: 4px; border-radius: 2px; background: var(--prim); }
.lg.l2 { background: var(--s2); margin-left: 8px; }
.lg.lb-banda { height: 12px; background: var(--banda); border-radius: 3px; }
.valores { list-style: none; margin: 10px 0 0; padding: 0; }
.valores li { display: grid; grid-template-columns: 92px auto 1fr; gap: 10px; align-items: baseline; padding: 9px 0; border-top: 1px solid var(--linha); cursor: pointer; }
.valores li .mute { text-align: right; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.valores small { color: var(--mute); font-weight: 400; }
.quadro-wrap { overflow-x: auto; margin: 0 -14px; padding: 0 14px; }
.quadro { border-collapse: separate; border-spacing: 0; font-size: .88rem; min-width: 100%; }
.quadro th, .quadro td { padding: 8px 10px; border-bottom: 1px solid var(--linha); white-space: nowrap; text-align: right; }
.quadro thead th { font-size: .75rem; color: var(--mute); font-weight: 600; }
.quadro tbody th, .quadro thead th:first-child {
  position: sticky; left: 0; background: var(--card); text-align: left; font-weight: 600; z-index: 1; box-shadow: 1px 0 0 var(--linha);
}
.quadro tbody th small { display: block; font-weight: 400; color: var(--mute); font-size: .72rem; }
.quadro td { cursor: pointer; font-variant-numeric: tabular-nums; }
.quadro td.fora { color: var(--perigo); font-weight: 700; }
.seta-q { color: var(--mute); font-size: .78rem; }

/* modal */
.modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.42); display: flex; align-items: flex-end; justify-content: center;
}
.folha {
  width: 100%; max-width: 620px; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--card); border-radius: 18px 18px 0 0; padding-bottom: calc(env(safe-area-inset-bottom) + 12px);
}
@media (min-width: 700px) { .modal { align-items: center; } .folha { border-radius: 18px; } }
.folha-h { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 8px 18px; background: var(--card); border-bottom: 1px solid var(--linha); }
.folha-h h2 { font-size: 1.1rem; }
.folha-c { padding: 12px 18px; }
.ecra-total .folha { max-height: 100vh; height: 100%; border-radius: 0; max-width: none; padding-top: env(safe-area-inset-top); }

.fld { display: block; margin-bottom: 12px; }
.fld > span { display: block; font-size: .85rem; color: var(--mute); margin-bottom: 4px; font-weight: 600; }
.fld input, .fld select, .fld textarea, .lb input, .lb select {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--linha);
  background: var(--bg); font-size: 16px; -webkit-appearance: none; appearance: none;
}
.fld select, .lb select {
  background-image: linear-gradient(45deg, transparent 50%, var(--mute) 50%), linear-gradient(135deg, var(--mute) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px;
}
.fld textarea { resize: vertical; }
.fld input:focus, .fld select:focus, .fld textarea:focus, .lb input:focus, .lb select:focus, .pesquisa:focus { outline: 2px solid var(--prim); outline-offset: 0; border-color: transparent; }
.chk { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; font-weight: 500; }
.chk input { width: 22px; height: 22px; accent-color: var(--prim); }
.acoes { display: flex; gap: 8px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.duas { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.lb { display: grid; grid-template-columns: 1fr 1fr 1fr 36px; gap: 6px; padding: 10px 0; border-top: 1px solid var(--linha); }
.lb select { grid-column: 1 / -1; }
.lb .x { border: 0; background: none; color: var(--mute); font-size: 1.4rem; }
.lista-p { list-style: none; padding: 0; margin: 0; }
.lp { width: 100%; display: flex; align-items: center; gap: 12px; border: 0; background: none; padding: 10px 6px; border-radius: 10px; font-weight: 600; text-align: left; }
.lp.ativo { background: var(--prim-c); }
.def { padding: 6px 0 14px; border-bottom: 1px solid var(--linha); margin-bottom: 12px; }
.def:last-child { border-bottom: 0; }

/* ficha de emergência */
.emerg h1 { font-size: 1.8rem; margin-bottom: 4px; }
.emerg .grande { font-size: 1.1rem; }
.emerg h3 { margin-top: 18px; font-size: 1rem; text-transform: uppercase; letter-spacing: .05em; color: var(--mute); }
.emerg ul { margin: 6px 0; padding-left: 20px; font-size: 1.1rem; }
.eg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.eg-b { background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.eg-b span { display: block; font-size: .78rem; color: var(--mute); }
.eg-b b { font-size: 1.15rem; word-break: break-word; }
.eg-al { list-style: none; padding: 0 !important; }
.eg-al li { background: var(--perigo-c); color: var(--perigo); font-weight: 700; padding: 8px 12px; border-radius: 10px; margin-bottom: 6px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s;
  background: var(--txt); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: .92rem; max-width: 90vw;
}
.toast.vis { opacity: 1; transform: translate(-50%, 0); }

/* impressão (ficha de emergência) */
@media print {
  .cab, .nav, .main, .toast, .folha-h, .acoes { display: none !important; }
  .modal { position: static; background: none; display: block; }
  .folha { max-height: none; height: auto; overflow: visible; box-shadow: none; }
  body { background: #fff; color: #000; }
}
