/* Paleta oficial da Prefeitura de Barroso, tirada do brasão:
   anil #2C2C76 · azul #02AFF3 · amarelo #FECB29 · verde #01A75B          */
:root {
  --anil: #2C2C76;
  --anil-escuro: #1E1F55;
  --anil-claro: #eceefb;
  --azul: #02AFF3;
  --azul-fraco: #e2f6ff;
  --amarelo: #FECB29;
  --amarelo-fraco: #fff6d8;
  --amarelo-texto: #8a6100;
  --verde: #01A75B;
  --verde-fraco: #e0f7ec;
  --vermelho: #d92d20;
  --vermelho-fraco: #fee4e2;

  --fundo: #f5f6fa;
  --card: #ffffff;
  --texto: #171a33;
  --suave: #6b7192;
  --borda: #e4e7f2;

  --sombra: 0 1px 2px rgba(28, 32, 74, .05), 0 6px 18px rgba(28, 32, 74, .07);
  --sombra-alta: 0 12px 34px rgba(28, 32, 74, .16);
  --raio: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--fundo); color: var(--texto);
  font-size: 16px; line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

/* ---------- cabeçalho ---------- */
header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 11px;
  padding: calc(11px + env(safe-area-inset-top)) 14px 13px;
  background: linear-gradient(135deg, var(--anil) 0%, var(--anil-escuro) 62%, #101138 100%);
  color: #fff;
  box-shadow: 0 2px 14px rgba(28, 32, 74, .22);
}
header .brasao {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  background: #fff center/82% no-repeat url('/brasao-mini.png');
  box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
}
header h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: -.2px; }
header small { font-size: 11.5px; opacity: .82; display: block; letter-spacing: .1px; }
header > div { flex: 1; min-width: 0; }
header h1, header small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icone {
  background: rgba(255, 255, 255, .15); color: #fff; border: 0;
  width: 36px; height: 36px; border-radius: 11px; font-size: 19px; cursor: pointer;
  display: grid; place-items: center; flex: none;
  transition: background .15s;
}
.icone:active { background: rgba(255, 255, 255, .3); }

/* ---------- estrutura ---------- */
main { padding: 16px 14px 100px; max-width: 820px; margin: 0 auto; }
h2 {
  font-size: 12.5px; margin: 24px 0 9px; color: var(--suave); font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px;
}
h2:first-child { margin-top: 2px; }

.cartao {
  background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio);
  padding: 15px; margin-bottom: 10px; box-shadow: var(--sombra);
  transition: transform .12s, box-shadow .12s;
}
.cartao.clicavel { cursor: pointer; }
.cartao.clicavel:active { transform: scale(.99); box-shadow: var(--sombra-alta); }
.linha { display: flex; align-items: center; gap: 10px; }
.linha .cresce { flex: 1; min-width: 0; }
.nome { font-weight: 650; font-size: 16px; letter-spacing: -.2px; }
.meta { color: var(--suave); font-size: 13px; }
.vazio { text-align: center; color: var(--suave); padding: 44px 20px; }

/* ---------- etiquetas ---------- */
.tag {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap; letter-spacing: .2px;
}
.tag.pendente { background: var(--amarelo-fraco); color: var(--amarelo-texto); }
.tag.pronta   { background: var(--azul-fraco);    color: #0369a1; }
.tag.entregue { background: var(--verde-fraco);   color: #05784a; }
.tag.recusado { background: var(--vermelho-fraco); color: var(--vermelho); }
.tag.urgente  { background: var(--vermelho); color: #fff; }
.tag.neutra   { background: var(--anil-claro); color: var(--anil); }

/* ---------- formulários ---------- */
label { display: block; font-size: 12.5px; color: var(--suave); margin: 12px 0 5px; font-weight: 650; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 12px 13px;
  border: 1.5px solid var(--borda); border-radius: 12px; background: #fff; color: var(--texto);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--azul); box-shadow: 0 0 0 3.5px rgba(2, 175, 243, .18);
}
textarea { min-height: 76px; resize: vertical; }

button.b {
  font: inherit; font-weight: 650; font-size: 15px; border: 0; border-radius: 13px;
  padding: 14px 16px; cursor: pointer; width: 100%;
  background: linear-gradient(135deg, var(--anil), var(--anil-escuro)); color: #fff;
  box-shadow: 0 4px 12px rgba(44, 44, 118, .26);
  transition: transform .1s, box-shadow .1s;
}
button.b:active { transform: translateY(1px); box-shadow: 0 2px 6px rgba(44, 44, 118, .26); }
button.b.secundario {
  background: #fff; color: var(--anil); border: 1.5px solid var(--anil-claro); box-shadow: var(--sombra);
}
button.b.azul { background: linear-gradient(135deg, var(--azul), #0286c9); box-shadow: 0 4px 12px rgba(2, 175, 243, .3); }
button.b.perigo { background: var(--vermelho); box-shadow: 0 4px 12px rgba(217, 45, 32, .25); }
button.b.pequeno { width: auto; padding: 10px 15px; font-size: 14px; border-radius: 11px; }
button.b:disabled { opacity: .45; cursor: not-allowed; }
.botoes { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 14px; }
.botoes button.b { flex: 1; min-width: 145px; }

/* ---------- itens marcáveis ---------- */
.item {
  display: flex; gap: 12px; align-items: flex-start; padding: 13px;
  border: 1.5px solid var(--borda); border-radius: 13px; margin-bottom: 8px; background: #fff;
  transition: border-color .12s, background .12s;
}
.item.marcado { border-color: var(--azul); background: var(--azul-fraco); }
.item input[type=checkbox] { width: 22px; height: 22px; flex: none; margin-top: 2px; accent-color: var(--anil); }
.item .cresce { min-width: 0; }
.item .apagar { background: none; border: 0; color: var(--vermelho); font-size: 18px; cursor: pointer; padding: 0 4px; }

/* ---------- menu inferior ---------- */
nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: rgba(255, 255, 255, .94); backdrop-filter: blur(12px);
  border-top: 1px solid var(--borda);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 16px rgba(28, 32, 74, .06);
}
nav a {
  flex: 1; text-align: center; padding: 9px 4px 10px; text-decoration: none;
  color: var(--suave); font-size: 11px; font-weight: 650; position: relative;
}
nav a span { display: block; font-size: 19px; line-height: 1.3; filter: grayscale(.6); opacity: .75; }
nav a.ativo { color: var(--anil); }
nav a.ativo span { filter: none; opacity: 1; }
nav a.ativo::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 30px; height: 3px; border-radius: 0 0 3px 3px; background: var(--azul);
}

/* ---------- barra de seleção (médico) ---------- */
.barra-selecao {
  position: fixed; left: 8px; right: 8px; bottom: 66px; z-index: 25;
  background: linear-gradient(135deg, var(--anil), var(--anil-escuro)); color: #fff;
  padding: 11px 12px; border-radius: 15px;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  box-shadow: var(--sombra-alta);
}
.barra-selecao b { margin-right: auto; font-size: 13.5px; }
.barra-selecao button {
  font: inherit; font-size: 13px; font-weight: 650; border: 0; border-radius: 10px;
  padding: 9px 12px; background: rgba(255, 255, 255, .16); color: #fff; cursor: pointer;
}
.barra-selecao button.destaque { background: var(--amarelo); color: #4a3600; }

/* ---------- números do painel ---------- */
.numeros { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 10px; }
.numero {
  background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio);
  padding: 15px; box-shadow: var(--sombra); position: relative; overflow: hidden;
}
.numero::after {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--anil);
}
.numero b { display: block; font-size: 32px; line-height: 1.05; font-weight: 700; letter-spacing: -1px; }
.numero small { color: var(--suave); font-size: 12.5px; }
.numero.pendente b { color: var(--amarelo-texto); }
.numero.pendente::after { background: var(--amarelo); }
.numero.pronta b { color: #0369a1; }
.numero.pronta::after { background: var(--azul); }
.numero.entregue b { color: #05784a; }
.numero.entregue::after { background: var(--verde); }

/* ---------- login ---------- */
.login-fundo {
  position: fixed; inset: 0; overflow-y: auto;
  background:
    radial-gradient(1100px 520px at 50% -8%, rgba(2, 175, 243, .38), transparent 62%),
    linear-gradient(160deg, var(--anil) 0%, var(--anil-escuro) 55%, #0d0e2e 100%);
}
.login { max-width: 400px; margin: 0 auto; padding: 8vh 20px 40px; }
.login .marca { text-align: center; margin-bottom: 22px; }
.login .marca img {
  width: 168px; max-width: 62%; background: #fff; padding: 16px 20px;
  border-radius: 20px; box-shadow: var(--sombra-alta);
}
.login .marca h1 { font-size: 21px; margin: 20px 0 4px; color: #fff; font-weight: 650; letter-spacing: -.3px; }
.login .marca p { color: rgba(255, 255, 255, .72); margin: 0; font-size: 13.5px; }
.login form {
  background: #fff; border-radius: 20px; padding: 18px 18px 20px; box-shadow: var(--sombra-alta);
}
.login .rodape-marca {
  text-align: center; color: rgba(255, 255, 255, .55); font-size: 11.5px; margin-top: 20px; line-height: 1.6;
}

/* ---------- aviso flutuante ---------- */
.aviso {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 60;
  background: var(--texto); color: #fff; padding: 12px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 600; max-width: 90vw; box-shadow: var(--sombra-alta);
}
.aviso.erro { background: var(--vermelho); }

.busca { position: relative; margin-bottom: 12px; }
.busca input { padding-left: 40px; }
.busca::before { content: "🔎"; position: absolute; left: 13px; top: 12px; font-size: 15px; opacity: .6; }

/* ---------- seletor do bulário (folha que sobe) ---------- */
.fundo-escuro {
  position: fixed; inset: 0; z-index: 40; background: rgba(23, 26, 51, .5);
  display: flex; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(2px);
}
.folha {
  background: var(--fundo); width: 100%; max-width: 820px; max-height: 92vh;
  border-radius: 22px 22px 0 0; display: flex; flex-direction: column; overflow: hidden;
  animation: sobe .18s cubic-bezier(.2, .8, .3, 1);
}
@keyframes sobe { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
.folha > header { position: static; padding: 13px 14px; }
.folha > header h3 { font-size: 16px; margin: 0; flex: 1; font-weight: 650; }
.folha .corpo { overflow-y: auto; padding: 13px 14px calc(16px + env(safe-area-inset-bottom)); }
.folha .rodape {
  padding: 11px 14px calc(13px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--borda); background: #fff;
}

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 14px; padding: 9px 14px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--borda); background: #fff; color: var(--texto); text-align: left;
  transition: border-color .12s, background .12s;
}
.chip.ativo { border-color: var(--azul); background: var(--azul-fraco); color: #0369a1; font-weight: 650; }
.chip.mais { border-style: dashed; color: var(--suave); }

.resultado {
  background: #fff; border: 1px solid var(--borda); border-radius: 13px;
  padding: 12px 14px; margin-bottom: 7px; cursor: pointer; box-shadow: var(--sombra);
}
.resultado:active { background: var(--azul-fraco); }
.resultado .nome { font-size: 15px; }
.resultado .meta { font-size: 12.5px; }
.resultado .classe {
  float: right; font-size: 10.5px; font-weight: 700; color: var(--anil); background: var(--anil-claro);
  padding: 3px 9px; border-radius: 999px; margin-left: 8px; text-transform: uppercase; letter-spacing: .3px;
}

/* ---------- aviso de pedido preso sem internet ---------- */
.pendentes {
  position: fixed; left: 10px; right: 10px; bottom: 74px; z-index: 30;
  background: var(--amarelo); color: #4a3600; font-size: 13.5px; font-weight: 650;
  padding: 11px 14px; border-radius: 13px; text-align: center; cursor: pointer;
  box-shadow: var(--sombra-alta);
}

/* ================= otimizações para celular ================= */
/* busca fica grudada no topo: com 500 pacientes, rolar e não perder o campo */
.busca.fixa {
  position: sticky; top: calc(58px + env(safe-area-inset-top)); z-index: 15;
  margin: -16px -14px 12px; padding: 10px 14px;
  background: rgba(245, 246, 250, .94); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--borda);
}
.busca.fixa::before { top: 22px; left: 27px; }
.busca .limpar {
  position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
  border: 0; background: var(--borda); color: var(--suave); cursor: pointer;
  width: 26px; height: 26px; border-radius: 50%; font-size: 15px; line-height: 1;
}

/* alvo de toque nunca menor que o dedo */
button, .chip, .resultado, .cartao.clicavel, nav a { min-height: 44px; }
.item input[type=checkbox], .linha > input[type=checkbox] { min-width: 24px; min-height: 24px; }

/* cartão de paciente em lista longa: mais compacto, sem perder o nome */
.lista-densa .cartao { padding: 12px 13px; margin-bottom: 7px; border-radius: 13px; }
.lista-densa .nome { font-size: 15.5px; line-height: 1.25; }
.lista-densa .meta { font-size: 12.5px; }

.alerta {
  background: var(--amarelo-fraco); color: var(--amarelo-texto);
  border: 1px solid #f2dc9a; border-radius: 12px; padding: 10px 12px;
  font-size: 13px; margin-bottom: 12px; line-height: 1.5;
}
.resultado.falta { border-color: #f2dc9a; background: #fffdf5; }
.falta-aviso { color: var(--amarelo-texto); font-weight: 650; }

/* telas pequenas (iPhone SE e afins) */
@media (max-width: 380px) {
  body { font-size: 15px; }
  main { padding: 14px 11px 96px; }
  header h1 { font-size: 15.5px; }
  header .brasao { width: 34px; height: 34px; }
  .numeros { grid-template-columns: 1fr 1fr; gap: 8px; }
  .numero { padding: 12px; }
  .numero b { font-size: 26px; }
  .botoes button.b { min-width: 100%; }
  nav a { font-size: 10px; }
}

/* telas grandes: aproveita a largura em vez de esticar o texto */
@media (min-width: 720px) {
  .numeros { grid-template-columns: repeat(4, 1fr); }
  main.duas-colunas #lista { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  main.duas-colunas #lista .cartao { margin-bottom: 0; }
}

/* respeita quem desliga animação no sistema */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* rolagem elástica sem "puxar" a página inteira no iOS */
.folha .corpo { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

/* ---------- repeticao precoce e medicacao controlada ---------- */
.item.repete { border-color: #f2c94c; background: #fffdf3; }
.item.repete-grave { border-color: var(--vermelho); background: #fff5f4; }
.repete-aviso { color: var(--vermelho); font-weight: 650; }
.alerta.grave { background: var(--vermelho-fraco); color: var(--vermelho); border-color: #f5b5b0; }
.tag.controle { font-size: 10px; padding: 2px 7px; vertical-align: middle; margin-left: 5px; }
.tag.controle.azul { background: #dbeafe; color: #1d4ed8; }
.tag.controle.amarela { background: var(--amarelo-fraco); color: var(--amarelo-texto); }
.tag.controle.branca { background: #eef1f6; color: #475069; }

/* ---------- faixa do modo "ver como o agente" ---------- */
.faixa-vercomo {
  position: fixed; left: 0; right: 0; top: 0; z-index: 40;
  background: var(--azul); color: #fff; font-size: 12.5px; font-weight: 650;
  padding: 7px 12px; text-align: center; cursor: pointer;
  padding-top: calc(7px + env(safe-area-inset-top));
}
body.com-faixa { padding-top: 30px; }
body.com-faixa header { top: 30px; }

/* ---------- tutorial do primeiro acesso ---------- */
.tutorial-fundo {
  position: fixed; inset: 0; z-index: 70;
  background: linear-gradient(160deg, var(--anil) 0%, var(--anil-escuro) 55%, #0d0e2e 100%);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top));
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
.tutorial {
  background: #fff; border-radius: 22px; width: 100%; max-width: 420px;
  max-height: 100%; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: var(--sombra-alta); animation: sobe .2s ease-out;
}
.tut-topo { display: flex; align-items: center; padding: 14px 16px 0; }
.tut-passo { font-size: 12px; font-weight: 700; color: var(--suave); letter-spacing: .5px; }
.tut-pular {
  margin-left: auto; border: 0; background: none; color: var(--suave);
  font: inherit; font-size: 13px; cursor: pointer; text-decoration: underline;
}
.tut-corpo { padding: 8px 22px 4px; overflow-y: auto; text-align: center; }
.tut-emoji { font-size: 52px; line-height: 1.2; margin-bottom: 6px; }
.tut-titulo { font-size: 20px; margin: 0 0 10px; letter-spacing: -.4px; color: var(--texto);
              text-transform: none; font-weight: 700; }
.tut-texto { font-size: 15px; line-height: 1.6; color: #414867; margin: 0 0 6px; }
.tut-texto b { color: var(--anil); }
.tut-pontos { display: flex; gap: 6px; justify-content: center; padding: 14px 0 4px; }
.tut-pontos span { width: 7px; height: 7px; border-radius: 50%; background: var(--borda); }
.tut-pontos span.aceso { background: var(--azul); width: 20px; border-radius: 4px; }
.tut-botoes { display: flex; gap: 9px; padding: 10px 18px 18px; }
.tut-botoes button.b { flex: 1; }
@media (max-height: 680px) {
  .tut-emoji { font-size: 40px; }
  .tut-titulo { font-size: 18px; }
  .tut-texto { font-size: 14px; }
}

/* link discreto para conhecer o app antes de entrar */
.tut-link {
  display: block; width: 100%; margin-top: 14px; background: none; border: 0;
  color: rgba(255, 255, 255, .8); font: inherit; font-size: 13.5px; font-weight: 650;
  text-decoration: underline; cursor: pointer; padding: 8px;
}

/* ---------- montador de posologia e dose da bula ---------- */
.dose-bula {
  background: var(--anil-claro); color: var(--anil); border-radius: 11px;
  padding: 10px 12px; font-size: 13px; line-height: 1.5; margin-bottom: 14px;
}
.montador {
  border: 1.5px dashed var(--borda); border-radius: 13px; padding: 11px 12px; margin-top: 10px;
  background: #fff;
}
.mont-titulo { font-size: 11.5px; font-weight: 700; color: var(--suave);
               text-transform: uppercase; letter-spacing: .6px; margin-bottom: 9px; }
.mont-linha { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 9px; }
.mont-linha:last-child { margin-bottom: 0; }
.mont-linha > span { font-size: 12px; color: var(--suave); width: 52px; flex: none;
                     padding-top: 9px; font-weight: 650; }
.chip.mini { font-size: 13px; padding: 7px 11px; min-height: 36px; }

/* ---------- busca + novo paciente grudados no topo ---------- */
.topo-lista {
  position: sticky; top: calc(58px + env(safe-area-inset-top)); z-index: 15;
  display: flex; gap: 8px; align-items: center;
  margin: -16px -14px 12px; padding: 10px 14px;
  background: rgba(245, 246, 250, .94); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--borda);
}
.topo-lista .busca { flex: 1; margin-bottom: 0; }
.topo-lista .busca::before { top: 13px; }
.topo-lista .busca .limpar { right: 8px; }
.b.novo-paciente {
  width: auto; flex: none; padding: 12px 15px; font-size: 14.5px; border-radius: 12px;
  white-space: nowrap;
}
body.com-faixa .topo-lista { top: calc(88px + env(safe-area-inset-top)); }
@media (max-width: 380px) {
  .b.novo-paciente { padding: 12px; font-size: 14px; }
}
.mont-dica { text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--azul); }
.doses { border: 1.5px solid var(--borda); border-radius: 12px; padding: 10px 11px; margin-bottom: 14px; background: #fff; }
.divisor-base {
  font-size: 11px; font-weight: 700; color: var(--suave); text-transform: uppercase;
  letter-spacing: .6px; margin: 16px 0 8px; padding-top: 12px; border-top: 1px dashed var(--borda);
}
.resultado.da-base { background: #fbfcfe; }
