/* ════════════════ Componentes do design system (LP + style guide) ════════════════
   Depende de tokens.css. Toda animação aqui usa os tokens de movimento e some com
   prefers-reduced-motion (regra global em tokens.css). */

/* ───────── Botões ─────────
   Tamanhos P/M/G = 40/48/56 px de altura (toque ≥ 48 px no celular: P só ganha 48 em telas de toque).
   Estados: normal → hover (sobe 1px + brilho) → pressionado (afunda, escala 0,98) → foco (anel) → desabilitado → carregando. */
.btn {
  --btn-h: 3rem;
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--btn-h); padding: 0 1.375rem;
  border-radius: var(--radius); border: 1px solid transparent;
  font: inherit; font-weight: 500; font-size: 1rem; line-height: 1; white-space: nowrap;
  text-decoration: none; cursor: pointer; isolation: isolate; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}
.btn-sm { --btn-h: 2.5rem; padding: 0 1rem; font-size: 0.9375rem; }
.btn-lg { --btn-h: 3.5rem; padding: 0 1.75rem; font-size: 1.0625rem; }
@media (pointer: coarse) { .btn-sm { --btn-h: 3rem; } }
.btn svg { width: 1.125rem; height: 1.125rem; flex: none; transition: transform var(--dur-base) var(--ease-out); }
.btn:hover svg.arrow { transform: translateX(3px); }
.btn:active { transform: translateY(0) scale(0.98); transition-duration: var(--dur-instant); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring)); }

.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); box-shadow: var(--shadow-glow); }
.btn-primary:hover { background: hsl(var(--primary-hover)); transform: translateY(-1px);
  box-shadow: 0 0 0 1px hsl(var(--primary) / 0.45), 0 12px 32px -10px hsl(var(--primary) / 0.7); }
/* Brilho que atravessa o botão primário no hover (uma passada, não fica piscando). */
.btn-primary::after {
  content: ''; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(110deg, transparent 30%, hsl(var(--primary-foreground) / 0.22) 50%, transparent 70%);
  transform: translateX(-120%);
}
.btn-primary:hover::after { transform: translateX(120%); transition: transform 700ms var(--ease-out); }
.btn-primary:focus-visible { box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring)), var(--shadow-glow); }

.btn-secondary { background: hsl(var(--primary-soft)); color: hsl(var(--primary-soft-foreground)); }
.btn-secondary:hover { background: hsl(var(--primary) / 0.18); transform: translateY(-1px); }
.btn-ghost { color: hsl(var(--foreground)); border-color: hsl(var(--border-strong)); background: transparent; }
.btn-ghost:hover { background: hsl(var(--surface-sunken)); border-color: hsl(var(--foreground) / 0.3); }
.btn-text { color: hsl(var(--primary-soft-foreground)); background: transparent; padding: 0 0.75rem; }
.btn-text:hover { background: hsl(var(--primary) / 0.08); }
.btn-danger { color: hsl(var(--danger)); border-color: hsl(var(--danger) / 0.4); background: transparent; }
.btn-danger:hover { background: hsl(var(--danger) / 0.08); }

.btn:disabled, .btn[aria-disabled='true'] {
  cursor: not-allowed; opacity: 0.45; transform: none; box-shadow: none;
}
.btn:disabled::after { display: none; }
.btn[aria-busy='true'] { color: transparent; pointer-events: none; }
.btn[aria-busy='true']::before {
  content: ''; position: absolute; inset: 0; margin: auto; width: 1.125rem; height: 1.125rem;
  border-radius: 999px; border: 2px solid currentColor; border-right-color: transparent;
  color: hsl(var(--primary-foreground)); animation: spin 700ms linear infinite;
}
.btn-ghost[aria-busy='true']::before { color: hsl(var(--foreground)); }

/* Botão de ícone (48×48) + troca de tema com sol/lua que giram ao trocar */
.icon-btn {
  display: inline-grid; place-items: center; width: 3rem; height: 3rem; flex: none;
  border-radius: var(--radius); border: 1px solid hsl(var(--border)); background: hsl(var(--surface));
  color: hsl(var(--foreground)); cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.icon-btn:hover { border-color: hsl(var(--border-strong)); background: hsl(var(--surface-raised)); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 1.25rem; height: 1.25rem; grid-area: 1 / 1; }
.theme-toggle svg { transition: transform var(--dur-slow) var(--ease-spring), opacity var(--dur-base) var(--ease-out); }
.theme-toggle .icon-sun { opacity: 0; transform: rotate(-90deg) scale(0.5); }
.theme-toggle .icon-moon { opacity: 1; transform: none; }
.dark .theme-toggle .icon-sun { opacity: 1; transform: none; }
.dark .theme-toggle .icon-moon { opacity: 0; transform: rotate(90deg) scale(0.5); }

/* ───────── Cartões ───────── */
.card {
  background: hsl(var(--surface)); border: 1px solid hsl(var(--border)); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}
.card-interactive { transition: transform var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out); }
.card-interactive:hover { transform: translateY(-3px); border-color: hsl(var(--primary) / 0.35); box-shadow: var(--shadow-pop); }

/* ───────── Selos ───────── */
.badge {
  display: inline-flex; align-items: center; gap: 0.375rem;
  font-size: 0.75rem; font-weight: 500; line-height: 1; padding: 0.375rem 0.625rem; border-radius: var(--radius-pill);
  background: hsl(var(--surface-sunken)); color: hsl(var(--muted-foreground));
}
.badge-ok { background: hsl(var(--primary-soft)); color: hsl(var(--primary-soft-foreground)); }
.badge-warn { background: hsl(var(--amber-soft)); color: hsl(var(--amber)); }
.badge-info { background: hsl(var(--cyan-soft)); color: hsl(var(--cyan)); }
.badge-danger { background: hsl(var(--danger-soft)); color: hsl(var(--danger)); }
.badge .live { width: 0.5rem; height: 0.5rem; border-radius: 999px; background: currentColor; animation: pulse-ring 1.8s var(--ease-out) infinite; }

/* ───────── Campos ─────────
   Rótulo acima, ajuda abaixo, erro inline logo abaixo do campo (com um "tremidinho" único). */
.field { display: grid; gap: 0.375rem; }
.field label { font-size: 0.9375rem; font-weight: 500; }
.field label small { font-weight: 400; color: hsl(var(--muted-foreground)); }
.input {
  width: 100%; min-height: 3rem; padding: 0 0.875rem;
  font: inherit; font-size: 1rem; color: hsl(var(--foreground));
  background: hsl(var(--surface-sunken)); border: 1px solid hsl(var(--border-strong)); border-radius: var(--radius);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-base) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.input::placeholder { color: hsl(var(--subtle-foreground)); }
.input:hover { border-color: hsl(var(--foreground) / 0.35); }
.input:focus { outline: none; border-color: hsl(var(--ring)); box-shadow: 0 0 0 4px hsl(var(--ring) / 0.18); background: hsl(var(--surface)); }
.input:disabled { opacity: 0.5; cursor: not-allowed; }
.field .help { font-size: 0.8125rem; color: hsl(var(--muted-foreground)); }
.field .error { font-size: 0.8125rem; color: hsl(var(--danger)); display: none; align-items: center; gap: 0.375rem; }
.field.has-error .input { border-color: hsl(var(--danger)); animation: shake 320ms var(--ease-out); }
.field.has-error .input:focus { box-shadow: 0 0 0 4px hsl(var(--danger) / 0.16); }
.field.has-error .error { display: flex; animation: rise var(--dur-base) var(--ease-out); }
.field.has-error .help { display: none; }
.field.is-valid .input { border-color: hsl(var(--success)); }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ───────── Caixa de seleção, opção e interruptor ─────────
   Controle + rótulo inteiros são clicáveis (min 48 px). Caixa e opção à esquerda; interruptor à direita. */
.choice { position: relative; display: flex; align-items: center; gap: 0.75rem; min-height: 3rem; cursor: pointer; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice .box, .choice .radio {
  width: 1.375rem; height: 1.375rem; flex: none; display: grid; place-items: center;
  border: 1.5px solid hsl(var(--border-strong)); background: hsl(var(--surface-sunken));
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), transform var(--dur-instant) var(--ease-out);
}
.choice .box { border-radius: 0.375rem; }
.choice .radio { border-radius: 999px; }
.choice:hover .box, .choice:hover .radio { border-color: hsl(var(--primary) / 0.6); }
.choice:active .box, .choice:active .radio { transform: scale(0.9); }
.choice .box svg { width: 0.875rem; height: 0.875rem; color: hsl(var(--primary-foreground)); }
.choice .box path { stroke-dasharray: 22; stroke-dashoffset: 22; transition: stroke-dashoffset var(--dur-base) var(--ease-out) 40ms; }
.choice input:checked + .box { background: hsl(var(--primary)); border-color: hsl(var(--primary)); }
.choice input:checked + .box path { stroke-dashoffset: 0; }
.choice input:indeterminate + .box { background: hsl(var(--primary)); border-color: hsl(var(--primary)); }
.choice input:indeterminate + .box::after { content: ''; width: 0.625rem; height: 2px; border-radius: 2px; background: hsl(var(--primary-foreground)); }
.choice input:indeterminate + .box svg { display: none; }
.choice .radio::after { content: ''; width: 0.5rem; height: 0.5rem; border-radius: 999px; background: hsl(var(--primary-foreground)); transform: scale(0); transition: transform var(--dur-base) var(--ease-spring); }
.choice input:checked + .radio { background: hsl(var(--primary)); border-color: hsl(var(--primary)); }
.choice input:checked + .radio::after { transform: scale(1); }
.choice input:focus-visible + .box, .choice input:focus-visible + .radio, .choice input:focus-visible + .switch {
  outline: 2px solid hsl(var(--ring)); outline-offset: 3px;
}
.choice input:disabled ~ * { opacity: 0.45; cursor: not-allowed; }

.choice.toggle { justify-content: space-between; }
.switch {
  position: relative; width: 2.75rem; height: 1.625rem; flex: none; border-radius: 999px;
  background: hsl(var(--border-strong)); transition: background-color var(--dur-base) var(--ease-out);
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 1.25rem; height: 1.25rem; border-radius: 999px;
  background: hsl(var(--surface-raised)); box-shadow: 0 1px 3px hsl(var(--shadow-color) / 0.3);
  transition: transform var(--dur-base) var(--ease-spring), width var(--dur-fast) var(--ease-out);
}
.choice:active .switch::after { width: 1.5rem; }
.choice input:checked + .switch { background: hsl(var(--primary)); }
.choice input:checked + .switch::after { transform: translateX(1.125rem); }
.choice:active input:checked + .switch::after { transform: translateX(0.875rem); }

/* ───────── Controle deslizante ───────── */
.range { -webkit-appearance: none; appearance: none; width: 100%; height: 3rem; background: transparent; cursor: pointer; }
.range::-webkit-slider-runnable-track { height: 6px; border-radius: 999px;
  background: linear-gradient(hsl(var(--primary)), hsl(var(--primary))) 0 / var(--fill, 50%) 100% no-repeat, hsl(var(--border-strong)); }
.range::-moz-range-track { height: 6px; border-radius: 999px; background: hsl(var(--border-strong)); }
.range::-moz-range-progress { height: 6px; border-radius: 999px; background: hsl(var(--primary)); }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 1.375rem; height: 1.375rem; margin-top: -8px; border-radius: 999px;
  background: hsl(var(--surface-raised)); border: 2px solid hsl(var(--primary)); transition: transform var(--dur-fast) var(--ease-spring); }
.range::-moz-range-thumb { width: 1.125rem; height: 1.125rem; border-radius: 999px; background: hsl(var(--surface-raised)); border: 2px solid hsl(var(--primary)); }
.range:active::-webkit-slider-thumb { transform: scale(1.2); }
.range:focus-visible { outline: none; }
.range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px hsl(var(--ring) / 0.3); }

/* ───────── Sanfona (perguntas) ───────── */
.accordion { display: grid; gap: 0.75rem; }
.accordion details { background: hsl(var(--surface)); border: 1px solid hsl(var(--border)); border-radius: var(--radius-lg);
  transition: border-color var(--dur-base) var(--ease-out); }
.accordion details[open] { border-color: hsl(var(--border-strong)); }
.accordion summary {
  list-style: none; cursor: pointer; min-height: 3.5rem; padding: 1rem 3rem 1rem 1.25rem; position: relative;
  font-weight: 500; border-radius: var(--radius-lg); transition: color var(--dur-fast) var(--ease-out);
}
.accordion summary:hover { color: hsl(var(--primary-soft-foreground)); }
.accordion summary::-webkit-details-marker { display: none; }
.accordion summary::after {
  content: ''; position: absolute; right: 1.25rem; top: 50%; width: 0.625rem; height: 0.625rem; margin-top: -0.4rem;
  border-right: 1.5px solid hsl(var(--muted-foreground)); border-bottom: 1.5px solid hsl(var(--muted-foreground));
  transform: rotate(45deg); transition: transform var(--dur-base) var(--ease-out), margin var(--dur-base) var(--ease-out);
}
.accordion details[open] summary::after { transform: rotate(-135deg); margin-top: -0.1rem; }
.accordion details > :not(summary) { padding: 0 1.25rem 1.25rem; color: hsl(var(--muted-foreground)); }
.accordion details[open] > :not(summary) { animation: rise var(--dur-base) var(--ease-out); }

/* ───────── Aviso (toast) ───────── */
.toast-region { position: fixed; z-index: 60; left: 1rem; right: 1rem; bottom: 1rem; display: grid; gap: 0.5rem; justify-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 0.625rem; max-width: 26rem; width: 100%;
  padding: 0.875rem 1rem; border-radius: var(--radius); background: hsl(var(--surface-raised)); border: 1px solid hsl(var(--border-strong));
  box-shadow: var(--shadow-pop); font-size: 0.9375rem; animation: toast-in 320ms var(--ease-spring);
}
.toast svg { width: 1.125rem; height: 1.125rem; color: hsl(var(--primary)); flex: none; }
.toast.leaving { animation: toast-out 220ms var(--ease-in-out) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(0.98); } }

/* ───────── Carregando ───────── */
.skeleton { border-radius: var(--radius-sm); min-height: 0.875rem;
  background: linear-gradient(90deg, hsl(var(--surface-sunken)) 25%, hsl(var(--border)) 50%, hsl(var(--surface-sunken)) 75%) 0 0 / 200% 100%;
  animation: shimmer 1.6s linear infinite; }
