/* ============================================================
   HAGÁ — Micro-interactions v2.0
   Importar POR ÚLTIMO: colors_and_type.css → components.css → este.
   ------------------------------------------------------------
   Todas as classes são utilitárias e opt-in (prefixo .mi-).
   Tudo respeita prefers-reduced-motion (bloco no final).
   Onde JS é necessário (count-up, indicador deslizante),
   o hook e o snippet estão documentados na seção.
   ============================================================ */

/* ============================================================
   §1 BOTÕES — .mi-btn (+ .is-loading)
   Hover: elevação; Active: pressão; Loading: spinner + "Aguarde…"
   Uso: <button class="btn btn-primary mi-btn">…</button>
        JS: btn.classList.add('is-loading') e trocar o texto.
   ============================================================ */
.mi-btn {
  transition: transform .15s ease-out, box-shadow .15s ease-out,
              background .15s ease-out, filter .15s ease-out;
}
.mi-btn:hover  { transform: translateY(-1px); }
.mi-btn:active { transform: translateY(0) scale(.98); transition-duration: .08s; }

.mi-btn.is-loading { pointer-events: none; opacity: .85; }
.mi-btn.is-loading::before {
  content: ""; width: 15px; height: 15px; flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: mi-spin .7s linear infinite;
}
@keyframes mi-spin { to { transform: rotate(360deg); } }

/* ============================================================
   §2 CARDS CLICÁVEIS — .mi-card-click
   Hover: borda destaque + lift + sombra; Active: volta ao lugar.
   ============================================================ */
.mi-card-click {
  cursor: pointer;
  transition: transform .18s var(--ease-out), box-shadow .18s var(--ease-out),
              border-color .18s var(--ease-out);
}
.mi-card-click:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.mi-card-click:active { transform: translateY(0); box-shadow: var(--shadow-md); transition-duration: .08s; }

/* ============================================================
   §3 INPUTS — .mi-input / .mi-shake
   Focus: ring animado; Erro: shake (3 oscilações, 300ms).
   JS: input.classList.add('mi-shake') e remover em animationend.
   ============================================================ */
.mi-input { transition: border-color .15s var(--ease-out), box-shadow .25s var(--ease-out), background .15s; }
.mi-input:focus { outline: 0; border-color: var(--primary); box-shadow: var(--ring); }

.mi-shake { animation: mi-shake .3s var(--ease-in-out); }
@keyframes mi-shake {
  0%, 100% { transform: translateX(0); }
  16%      { transform: translateX(-6px); }
  33%      { transform: translateX(5px); }
  50%      { transform: translateX(-4px); }
  66%      { transform: translateX(3px); }
  83%      { transform: translateX(-2px); }
}

/* ============================================================
   §4 TOGGLE + CHECKBOX
   Toggle: <label class="mi-toggle"><input type="checkbox"><i></i></label>
   Checkbox: <label class="mi-checkbox"><input type="checkbox">
     <svg viewBox="0 0 24 24"><polyline points="20 6 9 17 4 12"/></svg></label>
   ============================================================ */
.mi-toggle { position: relative; display: inline-flex; width: 50px; height: 30px; cursor: pointer; }
.mi-toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.mi-toggle > i {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--track-bg);
  transition: background .25s var(--ease-out), box-shadow .25s var(--ease-out);
}
.mi-toggle > i::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(23,18,46,.25);
  transition: transform .3s var(--ease-spring);   /* spring easing */
}
.mi-toggle input:checked + i { background: var(--primary); box-shadow: var(--shadow-glow-soft); }
.mi-toggle input:checked + i::after { transform: translateX(20px); }
.mi-toggle input:focus-visible + i { box-shadow: var(--ring); }

.mi-checkbox { position: relative; display: inline-flex; width: 24px; height: 24px; cursor: pointer; }
.mi-checkbox input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.mi-checkbox svg {
  width: 24px; height: 24px; border-radius: var(--radius-xs);
  background: var(--surface-2); box-shadow: inset 0 0 0 1.5px var(--border-strong);
  fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 24; stroke-dashoffset: 24;   /* checkmark "desenhado" */
  padding: 3px; box-sizing: border-box;
  transition: background .2s var(--ease-out), box-shadow .2s,
              stroke-dashoffset .3s var(--ease-out) .05s;
}
.mi-checkbox input:checked + svg {
  background: var(--primary); box-shadow: var(--shadow-glow-soft);
  stroke-dashoffset: 0;
}
.mi-checkbox input:focus-visible + svg { box-shadow: var(--ring); }

/* ============================================================
   §5 BARRA DE XP — .mi-xp-gain (+ count-up via JS)
   Preenchimento já anima via .xpbar (width, 800ms ease-out).
   Ao ganhar XP: adicionar .mi-xp-gain à .xpbar → shimmer percorre
   a barra 2×; remover em animationend.
   Count-up (número de 0 → valor), hook [data-countup]:
     const el = document.querySelector('[data-countup]');
     const alvo = +el.dataset.countup, t0 = performance.now();
     (function tick(t){ const p = Math.min((t-t0)/800, 1);
       el.textContent = Math.round(alvo*(1-Math.pow(1-p,3))).toLocaleString('pt-BR');
       if (p<1) requestAnimationFrame(tick); })(t0);
   ============================================================ */
.mi-xp-gain > i::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: linear-gradient(105deg, transparent 30%, rgba(255,255,255,.55) 50%, transparent 70%);
  background-size: 220% 100%;
  animation: mi-shimmer 1.1s ease-in-out 2;
}
@keyframes mi-shimmer {
  0%   { background-position: 180% 0; }
  100% { background-position: -80% 0; }
}
.mi-countup { font-variant-numeric: tabular-nums; }

/* ============================================================
   §6 STREAK (fogo) — .mi-streak-ativo / .mi-streak-bump
   Pulse contínuo quando ativo; bounce quando incrementa (JS add
   .mi-streak-bump, remover em animationend).
   ============================================================ */
.mi-streak-ativo { animation: mi-streak-pulse 2.4s var(--ease-in-out) infinite; }
@keyframes mi-streak-pulse {
  0%, 100% { transform: scale(1);    filter: drop-shadow(0 0 4px rgba(255,112,67,.35)); }
  50%      { transform: scale(1.06); filter: drop-shadow(0 0 12px rgba(255,112,67,.6)); }
}
.mi-streak-bump { animation: mi-streak-bounce .55s var(--ease-spring); }
@keyframes mi-streak-bounce {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.35) rotate(-6deg); }
  65%  { transform: scale(.94) rotate(3deg); }
  100% { transform: scale(1); }
}

/* ============================================================
   §7 BADGES — .mi-badge-unlock / .mi-stagger
   Desbloqueio: pop (0 → 1.1 → 1) + glow violeta pulsante 2s.
   Grid: filhos entram com stagger de 40ms (até 12 itens).
   ============================================================ */
.mi-badge-unlock {
  animation: mi-pop .45s var(--ease-spring) both,
             mi-glow-pulse 2s var(--ease-out) .45s;
}
@keyframes mi-pop {
  0%   { transform: scale(0);   opacity: 0; }
  70%  { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes mi-glow-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(123,127,232,0); }
  20%  { box-shadow: var(--glow-primary); }
  50%  { box-shadow: 0 0 0 2px rgba(123,127,232,.1), 0 0 20px rgba(123,127,232,.3); }
  75%  { box-shadow: var(--glow-primary); }
  100% { box-shadow: 0 0 0 0 rgba(123,127,232,0); }
}
.mi-stagger > * { opacity: 0; animation: mi-rise .4s var(--ease-out) forwards; }
.mi-stagger > *:nth-child(1)  { animation-delay: 0ms; }
.mi-stagger > *:nth-child(2)  { animation-delay: 40ms; }
.mi-stagger > *:nth-child(3)  { animation-delay: 80ms; }
.mi-stagger > *:nth-child(4)  { animation-delay: 120ms; }
.mi-stagger > *:nth-child(5)  { animation-delay: 160ms; }
.mi-stagger > *:nth-child(6)  { animation-delay: 200ms; }
.mi-stagger > *:nth-child(7)  { animation-delay: 240ms; }
.mi-stagger > *:nth-child(8)  { animation-delay: 280ms; }
.mi-stagger > *:nth-child(9)  { animation-delay: 320ms; }
.mi-stagger > *:nth-child(10) { animation-delay: 360ms; }
.mi-stagger > *:nth-child(11) { animation-delay: 400ms; }
.mi-stagger > *:nth-child(12) { animation-delay: 440ms; }
@keyframes mi-rise {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   §8 PASSAGENS LIDAS
   .card-passagem.lida já aplica risco + fade 0.75 (components.css).
   Para o checkmark desenhado use .mi-checkbox dentro do card,
   ou .mi-check-draw num svg avulso:
   <svg class="mi-check-draw" viewBox="0 0 24 24">
     <polyline points="20 6 9 17 4 12"/></svg>
   ============================================================ */
.mi-check-draw {
  fill: none; stroke: var(--success); stroke-width: 2.5;
  stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 24; stroke-dashoffset: 24;
}
.lida .mi-check-draw, .mi-check-draw.is-checked {
  animation: mi-draw .35s var(--ease-out) forwards;
}
@keyframes mi-draw { to { stroke-dashoffset: 0; } }

/* ============================================================
   §9 TOAST — animações extras de saída
   Entrada já vem de .toast/.toast.visivel (components.css):
   slide-up+fade no mobile, slide-left no desktop.
   Saída: adicionar .saindo antes de remover do DOM (250ms).
   ============================================================ */
.toast.saindo { opacity: 0; transform: translateX(-50%) translateY(4px) scale(.95); }
@media (min-width: 769px) {
  .toast.saindo { transform: translateX(0) translateY(4px) scale(.95); }
}

/* ============================================================
   §10 MODAIS — .mi-modal-overlay / .mi-modal-box (+ .saindo)
   Entrada: overlay fade + caixa scale(.96→1), 200ms.
   Saída: reverso, 150ms (adicionar .saindo, remover após 150ms).
   ============================================================ */
.mi-modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--scrim);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  animation: mi-fade .2s var(--ease-out) both;
}
.mi-modal-box {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  animation: mi-modal-in .2s var(--ease-out) both;
}
@keyframes mi-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes mi-modal-in {
  from { opacity: 0; transform: scale(.96) translateY(6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.mi-modal-overlay.saindo { animation: mi-fade .15s var(--ease-out) reverse both; }
.mi-modal-overlay.saindo .mi-modal-box { animation: mi-modal-in .15s var(--ease-out) reverse both; }

/* ============================================================
   §11 NAVEGAÇÃO — indicador que desliza entre itens
   Indicadores por item (::before) já animam via components.css.
   Para o deslize CONTÍNUO entre itens, use um elemento único
   .mi-nav-pill posicionado pelo JS (nav.js):
     const pill = nav.querySelector('.mi-nav-pill');
     const alvo = nav.querySelector('.ativo');
     pill.style.transform = `translateY(${alvo.offsetTop}px)`;  // sidebar
     // bottom-nav: translateX(${alvo.offsetLeft + alvo.offsetWidth/2}px)
   ============================================================ */
.mi-nav-pill {
  position: absolute; left: 0; width: 3px; height: 22px;
  border-radius: 3px; background: var(--primary);
  box-shadow: 0 0 8px rgba(123,127,232,.6);
  transition: transform .3s var(--ease-spring);
  pointer-events: none;
}
.bottom-nav .mi-nav-pill {
  top: 0; left: 0; width: 28px; height: 3px;
  border-radius: 0 0 3px 3px;
}

/* ============================================================
   §12 TRANSIÇÃO DE PÁGINA — .mi-page-enter
   Aplicar no <main> a cada troca de rota: fade + translateY(8px).
   ============================================================ */
.mi-page-enter { animation: mi-page-enter .25s var(--ease-out) both; }
@keyframes mi-page-enter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   §13 SKELETON — já refinado em components.css
   (gradiente surface-2 → surface-hover, 1.8s ease-in-out)
   ============================================================ */

/* ============================================================
   ACESSIBILIDADE — prefers-reduced-motion
   Desativa transforms e animações; estados finais preservados.
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .mi-btn, .mi-card-click, .mi-input, .mi-toggle > i, .mi-toggle > i::after,
  .mi-checkbox svg, .mi-nav-pill, .toast, .xpbar > i, .progress > i,
  .sidebar-xp-fill, .card, .card-passagem, .chip-select, .btn {
    transition: none !important;
  }
  .mi-shake, .mi-streak-ativo, .mi-streak-bump, .mi-badge-unlock,
  .mi-stagger > *, .mi-page-enter, .mi-xp-gain > i::before,
  .mi-modal-overlay, .mi-modal-box, .skeleton, .mi-btn.is-loading::before,
  .mi-check-draw {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
  .mi-stagger > * { opacity: 1; }
  .mi-btn:hover, .mi-btn:active, .mi-card-click:hover, .mi-card-click:active {
    transform: none;
  }
}
