/* ======================= HIDDEN =======================
   A regra do navegador é `[hidden] { display: none }` — especificidade de uma
   classe só, e vinda do user-agent, que PERDE de qualquer regra de autor com a
   mesma especificidade. Ou seja: `.field { display: block }` e `.seg { display:
   flex }` anulavam o atributo, e todo `node.hidden = true` do app virava
   decoração no elemento que tivesse classe com display.

   Isto vale para o app inteiro, não só para a tela que trouxe o problema à
   tona: `.field`, `.seg` e `.tr-items` já dependiam de `hidden` e não
   escondiam nada. As regras `.view[hidden]` e `#tabbar[hidden]` em layout.css
   existiam justamente para contornar isto caso a caso. */
[hidden] {
  display: none !important;
}

/* ======================= CARD ======================= */
.card {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 22px;
  box-shadow: var(--sh-lg);
  padding: 14px;
  margin-top: 14px; /* espaço pro avatar sobreposto */
}
/* bloco de conteúdo comum (não estica) */
.panel {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--sh-lg);
  padding: 14px;
}
.panel + .panel {
  margin-top: 12px;
}
.panel-title {
  margin: 0 0 10px;
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
}

/* ======================= BOTÕES ======================= */
.btn {
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  border-radius: 12px;
  padding: 11px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.btn:active {
  background: var(--field);
}
.btn-primary {
  border: 0;
  background: var(--blue);
  color: var(--on-accent);
}
.btn-primary:active {
  filter: brightness(0.94);
  background: var(--blue);
}
.btn-accent {
  border: 0;
  background: var(--accent);
  color: var(--on-warm);
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
}
.btn-danger {
  color: var(--danger);
}
.btn-danger:active {
  background: var(--tint-danger);
}
.btn-block {
  width: 100%;
}
.btn-sm {
  font-size: 13px;
  padding: 8px 11px;
  border-radius: 10px;
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.icon-btn {
  background: transparent;
  border: 0;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 19px;
  line-height: 1;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.icon-btn:active {
  background: var(--field);
}

/* ======================= CAMPOS ======================= */
/* font-size 16px é obrigatório: com user-scalable=no o iOS ainda dá zoom abaixo disso */
.input,
.select {
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
  height: 46px;
  font-size: 16px;
  color: var(--ink);
}
.input:disabled {
  background: var(--field);
  color: var(--muted);
}
.input.err {
  border-color: var(--danger);
}
textarea.input {
  height: auto;
  min-height: 70px;
  padding: 10px 12px;
  line-height: 1.45;
  resize: vertical;
}
.field {
  display: block;
  margin-bottom: 10px;
}
.field-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 5px 2px;
}
.field-row {
  display: flex;
  gap: 10px;
}
.field-row > .field {
  flex: 1 1 0;
  min-width: 0;
}
.field-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 4px 2px 0;
  line-height: 1.4;
}
/* campo que é RESULTADO, não entrada: mesmo espaço de um .field com slider,
   mas sem controle nenhum — é o carboidrato quando ele vira a sobra da conta */
.field.readout {
  background: var(--field);
  border-radius: 12px;
  padding: 9px 12px;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 8px;
}
.field.readout .field-label {
  flex: 1 1 100%;
  margin: 0;
}
.field.readout b {
  font-size: 15px;
  color: var(--ink);
}
.ro-tag {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  margin-left: auto;
}
.field-warn {
  font-size: 12.5px;
  color: var(--tint-warn-ink);
  background: var(--tint-warn);
  border: 1px solid var(--tint-warn-line);
  border-radius: 10px;
  padding: 8px 10px;
  margin: 8px 0 0;
  line-height: 1.4;
}

/* grupo segmentado (sexo, fórmula, abas internas) */
.seg {
  display: flex;
  background: var(--field);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}
.seg-btn {
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 9px;
  padding: 9px 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seg-btn.active {
  background: var(--card-2);
  color: var(--ink);
  box-shadow: var(--sh-sm);
}

/* Opções da folha de exportar em PDF.
   Repete o visual do .rest-toggle em vez de reusar a classe de propósito: o
   bloco CONTA TRAVADA de css/layout.css esconde todo .rest-toggle, e aí a
   conta travada — que PODE exportar — abriria a folha sem opção nenhuma. */
.pdf-opts {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 4px 0 12px;
}
.pdf-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.pdf-opt input {
  width: 18px;
  height: 18px;
  accent-color: var(--blue-solid);
}

/* chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.chip {
  border: 1px solid var(--line);
  background: var(--card-2);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.chip.active {
  background: var(--tint-blue);
  border-color: var(--tint-blue-line);
  color: var(--blue-solid);
}
.tag {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  background: var(--field);
  color: var(--muted);
}
.tag-edit {
  background: var(--tint-warn);
  color: var(--tint-warn-ink);
}
.tag-custom {
  background: var(--tint-ok);
  color: var(--tint-ok-ink);
}

/* range */
input[type="range"] {
  width: 100%;
  accent-color: var(--blue-solid);
  height: 28px;
}

/* ======================= BARRAS E MEDIDORES ======================= */
.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--field);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--blue-solid);
  transition: width 0.25s ease;
}
.bar-fill.over {
  background: var(--danger);
}
.bar-sm {
  height: 5px;
}
/* barra empilhada de macros */
.bar-stack {
  display: flex;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--field);
}
.bar-stack > span {
  display: block;
  height: 100%;
}

/* linha de estatísticas (TMB / gasto / meta) */
.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.stat {
  min-width: 0;
  background: var(--field);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
}
.stat b {
  display: block;
  font-family: "Baloo 2", sans-serif;
  font-size: 20px;
  line-height: 1.15;
  color: var(--ink);
}
.stat span {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.stat-hi {
  background: var(--tint-blue);
}
.stat-hi b {
  color: var(--blue-solid);
}

/* ======================= MENU / POPOVER ======================= */
.menu {
  position: absolute;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  min-width: 200px;
  box-shadow: var(--sh-lg);
  display: none;
  z-index: 70;
}
.menu.show {
  display: block;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 11px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--ink);
}
.menu button.danger {
  color: var(--danger);
}
.menu button:active {
  background: var(--field);
}

/* ======================= MODAL / GATE ======================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  /* mesma razão do .sheet-backdrop: sem altura dinâmica o mobile centraliza
     contra a viewport grande e o card sobe demais */
  height: 100dvh;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-t) + 22px) calc(var(--safe-r) + 22px)
    calc(var(--safe-b) + 22px) calc(var(--safe-l) + 22px);
  background: var(--scrim-strong);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal-backdrop.hidden {
  display: none;
}
/* Web: imagem completa (contain), ancorada embaixo pra a plaquinha ficar
   onde o card está. O card fica ancorado embaixo. */
#gate {
  background: #0d1117 url("../login-bg.jpg") center bottom / contain no-repeat;
  align-items: flex-end;
  justify-content: center;
  padding: 0 18px calc(var(--safe-b) + 6dvh) 18px;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
/* Celular: arte vertical (login-bg-cel.jpg) na largura cheia — preenche a tela. */
@media (max-width: 820px) {
  #gate {
    background-image: url("../login-bg-cel.jpg");
    background-position: center center;
    background-size: cover;
    padding-bottom: calc(var(--safe-b) + 10dvh);
  }
  #gate .modal {
    max-width: 300px;
  }
  #gate .modal .gate-input,
  #gate .modal .gate-go {
    height: 46px;
    font-size: 14px;
  }
}
/* Web: sobe um pouco o card (margem inferior maior). */
@media (min-width: 821px) {
  #gate {
    padding-bottom: calc(var(--safe-b) + 13dvh);
  }
}
.modal {
  width: 100%;
  max-width: 320px;
  margin: 0;
  background: var(--card-2);
  border-radius: 18px;
  padding: 18px 16px;
  box-shadow: var(--sh-xl);
  animation: rise 0.3s ease both;
}
.modal .gate-input {
  width: 100%;
  margin-bottom: 10px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  height: 50px;
  font-size: 16px;
  color: var(--ink);
}
.modal .gate-go {
  width: 100%;
  border: 0;
  cursor: pointer;
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 15px;
  color: var(--on-warm);
  background: var(--accent);
  border-radius: 12px;
  height: 50px;
}
.modal .err {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  min-height: 16px;
  margin: 10px 2px 0;
  line-height: 1.4;
}
.gate-alt {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--blue-solid);
  padding: 8px 4px;
  text-decoration: underline;
}
.gate-go[disabled] {
  opacity: 0.6;
  cursor: default;
}

/* ======================= BOTTOM SHEET ======================= */
/* CENTRALIZADO, não colado embaixo.
   Antes era um bottom sheet ancorado por `inset: 0` + `align-items: flex-end`.
   No mobile o bottom do `inset: 0` resolve contra a viewport GRANDE (atrás da
   barra de URL), então o rodapé do popup caía fora da área visível. Centralizar
   com altura dinâmica e padding de folga tira a dependência da borda inferior
   de vez: sobrando espaço ou não, o popup fica inteiro dentro da tela. */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  height: 100dvh;
  z-index: 90;
  background: var(--scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 14px)
    calc(var(--safe-b) + 16px) calc(var(--safe-l) + 14px);
}
.sheet {
  width: 100%;
  max-width: var(--maxw);
  /* 100% do backdrop, que já desconta safe areas e padding — o popup nunca
     encosta na borda nem é cortado */
  max-height: 100%;
  background: var(--card-2);
  border-radius: 20px;
  box-shadow: var(--sh-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: sheet-up 0.22s ease both;
}
.sheet-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h3 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 17px;
}
.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px;
}
.sheet-foot {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
}
.sheet-foot > .btn {
  flex: 1 1 0;
}
/* Bloco rotulado dentro de uma folha. Nasceu na folha de troca da dieta e já
   serve a de substitutos, então mora aqui junto do resto da primitiva. */
.sheet-sec {
  margin-top: 14px;
}
.sheet-sec-title {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.acc-email {
  margin: 0 0 4px;
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
  word-break: break-all;
}

/* ======================= ESTADOS / FEEDBACK ======================= */
.empty {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  padding: 26px 16px;
}
.empty .empty-ic {
  display: block;
  font-size: 34px;
  margin-bottom: 8px;
}
.muted {
  color: var(--muted);
}

/* Pastilha de variação — "+16%", "+41", "igual". Usada pela progressão de
   carga e pela folha de troca da dieta, daí morar aqui e não numa das duas.
   O par tint/ink existe justamente para ela ter contraste nos dois temas:
   pintar só a letra com --ok/--warn deixaria o texto fraco no escuro. */
.delta-chip {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--muted);
}
.delta-chip.up {
  background: var(--tint-ok);
  color: var(--tint-ok-ink);
}
.delta-chip.flat {
  background: var(--tint-warn);
  color: var(--tint-warn-ink);
}
.delta-chip.down {
  background: var(--tint-danger);
  color: var(--tint-danger-ink);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#toaster {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--safe-b) + var(--tabbar-h) + 14px);
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: min(92vw, 420px);
}
.toast {
  background: var(--toast-bg);
  color: var(--on-accent);
  font-size: 13.5px;
  font-weight: 500;
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: var(--sh-lg);
  animation: rise 0.2s ease both;
  text-align: center;
}
.toast.err {
  background: var(--toast-err);
}

/* chip de status de sincronização */
.sync-chip {
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--tint-warn);
  color: var(--tint-warn-ink);
  white-space: nowrap;
}
.sync-chip[hidden] {
  display: none;
}

/* ======================= REORDENAR ARRASTANDO =======================
   Segurar um item por ~1/4 de segundo o "levanta"; aí ele acompanha o dedo.
   O contêiner ganha [data-sortable] via js/ui/sortable.js. */
[data-sortable] > [data-key] {
  /* segurar no iOS abriria o menu de copiar/selecionar em cima do arraste */
  -webkit-touch-callout: none;
}
[data-sortable].sorting {
  user-select: none;
  -webkit-user-select: none;
  cursor: grabbing;
}
[data-sortable] > .sort-drag {
  position: relative;
  z-index: 30;
  /* o item da dieta é transparente dentro do card da refeição; no ar ele
     precisa de fundo próprio pra não deixar ver o que passa por baixo */
  background: var(--card-2);
  border-radius: 12px;
  box-shadow: var(--sh-lg);
  border-bottom-color: transparent;
}
@media (prefers-reduced-motion: reduce) {
  [data-sortable] > [data-key] {
    transition: none !important;
  }
}

/* ======================= LISTA DE CONTAS =======================
   No sheet "Minha conta", visível só para treinador. */
.conta-lista {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0;
}
.conta-linha {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 11px;
  border-radius: 12px;
  background: var(--field);
}
.conta-linha.ativa {
  outline: 2px solid var(--blue-solid);
}
.conta-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.conta-main b {
  font-size: 14px;
}
.conta-sub {
  font-size: 11.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conta-acoes {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
}
