/* Tokens compartilhados vêm de tokens.css (carregado antes deste arquivo).
   Aqui ficam só os tokens locais da calculadora e o estilo dos componentes. */

:root {
  /* Locais do app: variam por tema mas não fazem parte do sistema compartilhado. */
  --card-bg: var(--surface);
  --card-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 14px 40px -20px var(--accent-glow),
    0 10px 30px -22px rgba(0, 0, 0, 0.75);
  --result-bg: var(--surface-2);
  --result-border: rgba(249, 115, 22, 0.30);
  --item-bg: var(--surface);
  /* #ff4f4f sobre #09090b dá 6,1:1 */
  --danger: #ff4f4f;
  --danger-bg: rgba(255, 79, 79, 0.10);
}

:root[data-theme="light"] {
  --card-bg: #ffffff;
  --card-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.08);
  --result-bg: #fafafa;
  --result-border: rgba(249, 115, 22, 0.35);
  --item-bg: #ffffff;
  /* #ff4f4f sobre #fafafa dá 3,1:1 e reprova AA — red-700 dá 6,2:1 */
  --danger: #b91c1c;
  --danger-bg: rgba(185, 28, 28, 0.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  position: relative;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 55% 45% at 85% 10%, var(--accent-glow) 0%, transparent 60%),
    radial-gradient(ellipse 40% 35% at 5% 90%, var(--accent-glow) 0%, transparent 55%);
  pointer-events: none;
}

.wrap {
  width: 100%;
  max-width: 420px;
  position: relative;
}

/* —— Cabeçalho —— */

/* Barra propria acima do titulo: os controles nao disputam largura com o h1.
   "Taxa Metabolica" em Syne 800 mede 13,27x o font-size — ao lado do botao
   sobravam 356px e o titulo quebrava em tres linhas em vez das duas do design. */
.page-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

/* Volta para o portal (§4 da spec). Link, nao botao, e na mesma aba: o hub
   abre os apps com target=_blank e fica na aba de tras, entao abrir mais uma
   aba e justamente o que criou o beco sem saida. URL absoluta porque os tres
   deploys sao separados — nenhum caminho relativo chega la. */
.btn-back {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--step--1);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

/* --accent-text, nao --accent: no tema claro o hover precisa escurecer (§2.1). */
.btn-back:hover {
  color: var(--accent-text);
  border-color: var(--border-hover);
}

header {
  margin-bottom: 1.8rem;
  padding: 0 0.25rem;
}

.label-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-text);
  background: var(--accent-tint);
  border-radius: 100px;
  padding: 0.3rem 0.8rem;
  margin-bottom: 1rem;
}

.label-tag::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}

/* Maximo em --step-3, nao --step-4: "Taxa Metabolica" mede 13,27x o font-size
   em Syne 800, e a 2.9rem precisaria de 615px numa coluna de 420px. A 30px pede
   398px dos 412px disponiveis, e a rampa de 6.5vw mantem a quebra do design
   ("Taxa Metabolica" / "Basal") ate 320px de viewport. Ao mexer aqui, meca. */
h1 {
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 6.5vw, var(--step-3));
  font-weight: 800;
  line-height: 1.1;
  color: var(--text);
  letter-spacing: -0.02em;
}

h1 span { color: var(--accent-text); }

.subtitle {
  font-size: var(--step--1);
  color: var(--text-dim);
  margin-top: 0.5rem;
  font-weight: 600;
}

/* —— Botão de tema —— */

.theme-toggle {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.theme-toggle:hover {
  color: var(--accent-text);
  border-color: var(--border-hover);
}

.theme-toggle svg {
  width: 1.15rem;
  height: 1.15rem;
}

/* Só um dos dois ícones aparece — o que representa o tema para o qual o clique leva. */
.theme-toggle .icon-moon { display: none; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: block; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: none; }

/* —— Cartão —— */

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.6rem;
  box-shadow: var(--card-shadow);
}

/* Dois grupos usam este segmentado: a fórmula e o sexo. */
.seg-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.375rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 0.3125rem;
}

.seg-toggle button {
  min-height: 44px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-body);
  /* --step--1, não --step-0: "Harris-Benedict" não cabe em meia coluna de 420px
     a 15px sem quebrar em duas linhas. */
  font-size: var(--step--1);
  font-weight: 700;
  padding: 0.6rem 0.4rem;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: color 0.22s ease, background-color 0.22s ease, box-shadow 0.22s ease;
}

/* --on-accent, não #fff: branco sobre #f97316 dá 2,8:1 e reprova AA. */
.seg-toggle button.active {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 2px 12px var(--accent-glow);
}

.seg-toggle button:not(.active):hover {
  color: var(--text);
  background: var(--border);
}

.field { margin-bottom: 1.1rem; }

/* Respiro extra entre o bloco de escolhas (fórmula + sexo) e os campos numéricos. */
.field-gap { margin-bottom: 1.6rem; }

/* Mesma aparência do <label> dos campos, para elementos que não rotulam um input
   único (um grupo de botões só pode ser rotulado por aria-labelledby). */
.field-label {
  display: block;
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 0.45rem;
}

/* —— "Qual delas escolher?" —— */

.formula-help {
  margin-top: 0.6rem;
}

.formula-help summary {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 32px;
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--accent-text);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.formula-help summary::-webkit-details-marker { display: none; }

.formula-help summary::before {
  content: "▸";
  font-size: 0.9em;
  transition: transform 0.2s ease;
}

.formula-help[open] summary::before { transform: rotate(90deg); }

.formula-help-body {
  margin-top: 0.4rem;
  padding: 0.85rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: var(--step--1);
  color: var(--text-dim);
  line-height: 1.6;
}

.formula-help-body p + p { margin-top: 0.7rem; }

.formula-help-body strong { color: var(--text); font-weight: 700; }

.formula-help-note {
  padding-top: 0.7rem;
  border-top: 1px solid var(--border);
}

label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 0.45rem;
}

.input-row {
  display: flex;
  align-items: stretch;
  min-height: 46px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input[type="number"] {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--step-1);
  font-weight: 600;
  padding: 0.7rem 0.9rem;
  outline: none;
  width: 100%;
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }

/* --text-dim, não --text-faint: o faint reprova AA em quase toda superfície
   (3,5:1 sobre --surface-2 no escuro) e só serve para não-texto ou >=24px (§2.3). */
.unit {
  display: flex;
  align-items: center;
  padding: 0 0.9rem;
  font-size: var(--step--1);
  font-weight: 700;
  color: var(--text-dim);
  border-left: 1px solid var(--border);
  white-space: nowrap;
}

.btn-calc {
  width: 100%;
  min-height: 48px;
  background: var(--accent);
  border: none;
  color: var(--on-accent);
  font-family: var(--font-body);
  font-size: var(--step-0);
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 0.95rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-top: 0.5rem;
  transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-calc:hover {
  background: var(--accent-soft);
  box-shadow: 0 6px 28px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-calc:active { transform: scale(0.98); }

/* —— Resultado —— */

.result-box {
  margin-top: 1.4rem;
  background: var(--result-bg);
  border: 1px solid var(--result-border);
  border-radius: var(--radius);
  padding: 1.4rem;
  display: none;
  animation: fadeUp 0.3s ease forwards;
}

.result-box.show { display: block; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.3rem;
}

.result-label {
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--text-dim);
}

.result-badge {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent-text);
  background: var(--accent-tint);
  border-radius: 100px;
  padding: 0.25rem 0.625rem;
  white-space: nowrap;
}

.result-value {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 12vw, 2.875rem);
  font-weight: 800;
  color: var(--accent-text);
  line-height: 1;
  letter-spacing: -0.02em;
}

.result-unit {
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-top: 0.85rem;
}

.btn-copy {
  min-height: 44px;
  font-family: var(--font-body);
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--text);
  background: var(--item-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.btn-copy:hover {
  color: var(--accent-text);
  border-color: var(--border-hover);
}

.copy-feedback {
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--text-dim);
  min-height: 1.2em;
}

.formula-row {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  background: var(--item-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: var(--step--1);
  color: var(--text-dim);
  line-height: 1.9;
}

.formula-row strong { color: var(--accent-text); font-weight: 700; }

.activity-section {
  margin-top: 1.2rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border);
}

.activity-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-text);
  margin-bottom: 0.7rem;
}

.activity-grid {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.activity-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.8rem;
  background: var(--item-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  transition: border-color 0.15s, background-color 0.15s;
}

.activity-item:hover {
  border-color: var(--border-hover);
}

.act-name {
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--text-dim);
}

/* Número em --text, não em laranja: o único acento do bloco é a TMB grande. */
.act-val {
  font-family: var(--font-display);
  font-size: var(--step--1);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.error {
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--danger);
  margin-top: 0.5rem;
  display: none;
  background: var(--danger-bg);
  border-radius: var(--radius-xs);
  padding: 0.4rem 0.7rem;
}

footer {
  margin-top: 1.25rem;
  font-size: var(--step--1);
  color: var(--text-dim);
  text-align: center;
  font-weight: 600;
  line-height: 1.6;
}

.footer-author {
  display: block;
  margin-top: 0.35rem;
  font-weight: 400;
}

/* Foco padronizado com os outros apps do sistema. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .btn-calc:hover,
  .btn-calc:active {
    transform: none;
  }
}
