/* =====================================================================
   Ki Sabor · Design system · BASE E COMPONENTES
   Prefixo k- para conviver com o CSS antigo do painel (estilo.css).
   Depende de tokens.css.
   ===================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: 8.5rem; }
body.k {
  margin: 0;
  min-height: 100dvh;
  background: var(--fundo);
  color: var(--texto);
  font: var(--peso-normal) var(--t-md) / var(--altura-linha) var(--fonte-texto);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur-3) ease, color var(--dur-3) ease;
}
/* Resets com :where() para não ganhar de nenhum componente (especificidade zero) */
:where(.k) :where(h1, h2, h3, h4) {
  margin: 0;
  font-family: var(--fonte-display);
  font-weight: var(--peso-extra);
  line-height: var(--altura-titulo);
  letter-spacing: -0.01em;
  text-wrap: balance;
}
:where(.k) :where(p) { margin: 0; }
:where(.k) :where(img) { max-width: 100%; display: block; }
:where(.k) :where(a) { color: inherit; }
:where(.k) :where(button, input, select, textarea) { font: inherit; color: inherit; }
:where(.k) :where(button) { cursor: pointer; }
.k :focus { outline: none; }
.k :focus-visible {
  outline: 3px solid var(--foco);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--foco-halo);
  border-radius: var(--r-sm);
}
.k-sr {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.k-pular {
  position: absolute; left: var(--e-3); top: -4rem; z-index: 100;
  background: var(--primaria); color: var(--sobre-primaria); padding: var(--e-2) var(--e-4);
  border-radius: var(--r-pilula); font-weight: var(--peso-forte); text-decoration: none;
}
.k-pular:focus { top: var(--e-3); }
.k-num { font-variant-numeric: tabular-nums; }
.k-display { font-family: var(--fonte-display); font-weight: var(--peso-extra); }
.k-mudo { color: var(--texto-2); font-size: var(--t-sm); }

/* ---------- Botões ---------- */
.k-btn {
  --btn-fundo: var(--primaria);
  --btn-texto: var(--sobre-primaria);
  --btn-sombra: var(--sombra-adesivo);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--e-2);
  min-height: 48px; padding: 0 var(--e-5);
  border: 0; border-radius: var(--r-pilula);
  background: var(--btn-fundo); color: var(--btn-texto);
  font-family: var(--fonte-display); font-size: var(--t-lg); font-weight: var(--peso-extra); line-height: 1;
  text-decoration: none; white-space: nowrap;
  box-shadow: var(--btn-sombra);
  transition: transform var(--dur-1) var(--ease-saida), box-shadow var(--dur-1) var(--ease-saida),
              background-color var(--dur-2) ease, opacity var(--dur-2) ease;
  user-select: none;
}
.k-btn:hover { background: var(--primaria-hover); }
.k-btn:active { transform: translateY(2px) scale(0.985); box-shadow: var(--sombra-adesivo-pressionado); }
.k-btn[disabled], .k-btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }
.k-btn--escuro { --btn-fundo: var(--ks-grafite-800); --btn-texto: var(--ks-amarelo-500); --btn-sombra: 0 3px 0 var(--ks-grafite-950); }
.k-btn--escuro:hover { background: var(--ks-grafite-700); }
.k-btn--contorno { --btn-fundo: transparent; --btn-texto: var(--texto); --btn-sombra: inset 0 0 0 2px var(--linha-forte); }
.k-btn--contorno:hover { background: var(--superficie-2); }
.k-btn--contorno:active { box-shadow: inset 0 0 0 2px var(--texto); }
.k-btn--verde { --btn-fundo: var(--ks-verde-500); --btn-texto: #fff; --btn-sombra: 0 3px 0 #0f5a2c; }
.k-btn--verde:hover { background: #146f37; }
.k-btn--bloco { display: flex; width: 100%; }
.k-btn--g { min-height: 56px; font-size: var(--t-xl); padding: 0 var(--e-6); }
.k-btn--p { min-height: 40px; font-size: var(--t-md); padding: 0 var(--e-4); }
.k-btn svg { flex: 0 0 auto; width: 22px; height: 22px; }
.k-btn .k-btn__valor { margin-left: auto; font-variant-numeric: tabular-nums; }

/* Botão redondo de ícone */
.k-ic {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 50%;
  background: var(--superficie-2); color: var(--texto);
  transition: transform var(--dur-1) var(--ease-saida), background-color var(--dur-2) ease;
}
.k-ic:hover { background: var(--superficie-3); }
.k-ic:active { transform: scale(0.9); }
.k-ic svg { width: 22px; height: 22px; }
.k-ic--marca { background: rgb(255 255 255 / 0.1); color: var(--marca-texto); }
.k-ic--marca:hover { background: rgb(255 255 255 / 0.18); }

/* Carregando dentro do botão */
.k-giro {
  width: 1.1em; height: 1.1em; border-radius: 50%;
  border: 3px solid currentColor; border-right-color: transparent;
  animation: k-giro 0.7s linear infinite;
}
@keyframes k-giro { to { transform: rotate(1turn); } }

/* ---------- Chips (categorias, filtros) ---------- */
.k-chip {
  display: inline-flex; align-items: center; gap: var(--e-1);
  min-height: 40px; padding: 0 var(--e-4);
  border: 0; border-radius: var(--r-pilula);
  background: var(--superficie); color: var(--texto);
  box-shadow: inset 0 0 0 1.5px var(--linha);
  font-weight: var(--peso-medio); font-size: var(--t-sm); white-space: nowrap; text-decoration: none;
  transition: background-color var(--dur-2) ease, color var(--dur-2) ease, box-shadow var(--dur-2) ease, transform var(--dur-1) ease;
}
.k-chip:active { transform: scale(0.96); }
.k-chip[aria-current="true"], .k-chip.is-on {
  background: var(--ks-grafite-800); color: var(--ks-amarelo-500); box-shadow: none;
}

/* ---------- Selos ---------- */
.k-selo {
  display: inline-flex; align-items: center; gap: 0.35em;
  padding: 0.2em 0.65em; border-radius: var(--r-pilula);
  font-size: var(--t-xs); font-weight: var(--peso-forte); line-height: 1.35;
  background: var(--superficie-2); color: var(--texto);
}
.k-selo--ok { background: var(--ok-fundo); color: var(--ok); }
.k-selo--esgotado { background: var(--ks-grafite-800); color: #fff; }
.k-selo--aviso { background: var(--aviso-fundo); color: var(--aviso); }
.k-selo--acento { background: var(--acento-forte); color: var(--sobre-acento); }
.k-selo--amarelo { background: var(--ks-amarelo-500); color: var(--ks-grafite-900); }
.k-selo--info { background: var(--info-fundo); color: var(--info); }
.k-ponto { width: 0.55em; height: 0.55em; border-radius: 50%; background: currentColor; }
.k-ponto--vivo { position: relative; }
.k-ponto--vivo::after {   /* onda só com transform/opacity: roda na GPU, sem repintar a página */
  content: ""; position: absolute; inset: 0; border-radius: 50%; background: currentColor;
  animation: k-pulso-ponto 1.6s var(--ease-saida) infinite;
}
@keyframes k-pulso-ponto { from { transform: scale(1); opacity: 0.6; } to { transform: scale(2.8); opacity: 0; } }

/* ---------- Cartões ---------- */
.k-cartao {
  background: var(--superficie);
  border-radius: var(--r-lg);
  box-shadow: var(--sombra-1);
  padding: var(--e-4);
}
.k-cartao + .k-cartao { margin-top: var(--e-3); }
.k-cartao__titulo { font-size: var(--t-lg); margin-bottom: var(--e-3); }

/* ---------- Campos ---------- */
.k-campo { display: block; margin-top: var(--e-4); }
.k-campo:first-child { margin-top: 0; }
.k-campo__rotulo { display: block; font-weight: var(--peso-forte); font-size: var(--t-sm); margin-bottom: var(--e-2); }
.k-campo__ajuda { display: block; color: var(--texto-2); font-size: var(--t-xs); margin-top: var(--e-1); }
.k-entrada {
  display: block; width: 100%; min-height: 50px;
  padding: var(--e-3) var(--e-4);
  border: 1.5px solid var(--linha-forte); border-radius: var(--r-md);
  background: var(--superficie); color: var(--texto); font-size: var(--t-md);
  transition: border-color var(--dur-2) ease, box-shadow var(--dur-2) ease;
  appearance: none;
}
.k-entrada::placeholder { color: var(--texto-3); }
.k-entrada:hover { border-color: var(--texto-3); }
.k-entrada:focus-visible, .k-entrada:focus {
  outline: none; border-color: var(--texto);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ks-amarelo-500) 70%, transparent);
  border-radius: var(--r-md);
}
.k-entrada[aria-invalid="true"] { border-color: var(--perigo); }
select.k-entrada {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b6264' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.9rem center; background-size: 18px; padding-right: 2.6rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; /* Safari: opção longa (bairro) não vaza da caixa */
}
textarea.k-entrada { min-height: 84px; resize: vertical; }

/* ---------- Opções em cartão (rádio) ---------- */
.k-opcoes { display: grid; gap: var(--e-2); }
.k-opcoes--2 { grid-template-columns: 1fr 1fr; }
.k-opcao {
  position: relative; display: flex; align-items: center; gap: var(--e-3);
  min-height: 60px; padding: var(--e-3) var(--e-4);
  border-radius: var(--r-md); background: var(--superficie);
  box-shadow: inset 0 0 0 1.5px var(--linha-forte);
  cursor: pointer; font-weight: var(--peso-medio);
  transition: box-shadow var(--dur-2) ease, background-color var(--dur-2) ease, transform var(--dur-1) ease;
}
.k-opcao:active { transform: scale(0.985); }
.k-opcao input { position: absolute; opacity: 0; pointer-events: none; }
.k-opcao__ic {
  flex: 0 0 auto; display: grid; place-items: center; width: 40px; height: 40px;
  border-radius: 12px; background: var(--superficie-2); color: var(--texto);
  transition: background-color var(--dur-2) ease, color var(--dur-2) ease;
}
.k-opcao__ic svg { width: 22px; height: 22px; }
.k-opcao__txt { flex: 1; min-width: 0; line-height: 1.25; }
.k-opcao__txt small { display: block; font-weight: var(--peso-normal); color: var(--texto-2); font-size: var(--t-xs); margin-top: 2px; }
.k-opcao__marca {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%;
  box-shadow: inset 0 0 0 2px var(--linha-forte); transition: box-shadow var(--dur-2) var(--ease-mola);
}
.k-opcao:has(input:checked) { box-shadow: inset 0 0 0 2.5px var(--texto); background: color-mix(in srgb, var(--ks-amarelo-500) 9%, var(--superficie)); }
.k-opcao:has(input:checked) .k-opcao__ic { background: var(--ks-amarelo-500); color: var(--ks-grafite-900); }
.k-opcao:has(input:checked) .k-opcao__marca { box-shadow: inset 0 0 0 7px var(--texto); }
.k-opcao:has(input:focus-visible) { outline: 3px solid var(--foco); outline-offset: 2px; }

/* ---------- Seletor segmentado ---------- */
.k-seg {
  position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 4px; border-radius: var(--r-pilula); background: var(--superficie-2);
}
.k-seg button {
  position: relative; z-index: 1; min-height: 44px; padding: 0 var(--e-4);
  border: 0; border-radius: var(--r-pilula); background: transparent; color: var(--texto-2);
  font-weight: var(--peso-forte); font-size: var(--t-sm); white-space: nowrap;
  transition: color var(--dur-2) ease;
}
.k-seg button[aria-pressed="true"] { color: var(--ks-grafite-900); }
.k-seg__bolha {
  position: absolute; z-index: 0; top: 4px; bottom: 4px; left: 4px;
  border-radius: var(--r-pilula); background: var(--ks-amarelo-500); box-shadow: var(--sombra-1);
  transition: transform var(--dur-3) var(--ease-mola), width var(--dur-3) var(--ease-saida);
}

/* ---------- Contador de quantidade ---------- */
.k-qtd {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px; border-radius: var(--r-pilula); background: var(--superficie-2);
}
.k-qtd button {
  position: relative; display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 50%; background: var(--superficie); color: var(--texto);
  box-shadow: var(--sombra-1);
  transition: transform var(--dur-1) var(--ease-saida), background-color var(--dur-2) ease;
}
.k-qtd button:active { transform: scale(0.86); }
.k-qtd button[disabled] { opacity: 0.4; box-shadow: none; }
.k-qtd button svg { width: 18px; height: 18px; }
.k-qtd__n {
  min-width: 2.6ch; text-align: center;
  font-family: var(--fonte-display); font-weight: var(--peso-extra); font-size: var(--t-lg);
  font-variant-numeric: tabular-nums;
}
.k-qtd--p button { width: 38px; height: 38px; }
/* Área de toque de 44 px mesmo no contador pequeno (celular de 375 px): o círculo fica menor, o alvo não. */
.k-qtd--p button::after { content: ""; position: absolute; inset: -3px; border-radius: 50%; }
.k-qtd--p .k-qtd__n { font-size: var(--t-md); }
.k-mais10 {
  min-height: 40px; padding: 0 var(--e-3); border: 0; border-radius: var(--r-pilula);
  background: var(--ks-grafite-800); color: var(--ks-amarelo-500);
  font-family: var(--fonte-display); font-weight: var(--peso-extra); font-size: var(--t-md);
  transition: transform var(--dur-1) var(--ease-mola);
}
.k-mais10:active { transform: scale(0.9); }
:root[data-tema="escuro"] .k-mais10 { background: var(--ks-amarelo-500); color: var(--ks-grafite-900); }
@media (prefers-color-scheme: dark) { :root:not([data-tema="claro"]) .k-mais10 { background: var(--ks-amarelo-500); color: var(--ks-grafite-900); } }

/* Número que "salta" quando muda */
.k-salto { animation: k-salto var(--dur-3) var(--ease-mola); }
@keyframes k-salto { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }

/* ---------- Alertas ---------- */
.k-alerta {
  display: flex; gap: var(--e-3); align-items: flex-start;
  padding: var(--e-3) var(--e-4); border-radius: var(--r-md);
  background: var(--aviso-fundo); color: var(--aviso); font-size: var(--t-sm); font-weight: var(--peso-medio);
}
.k-alerta svg { flex: 0 0 auto; width: 20px; height: 20px; margin-top: 1px; }
.k-alerta--erro { background: var(--perigo-fundo); color: var(--perigo); }
.k-alerta--info { background: var(--info-fundo); color: var(--info); }
.k-alerta--ok { background: var(--ok-fundo); color: var(--ok); }
.k-alerta[hidden] { display: none; }
.k-tremor { animation: k-tremor 0.4s var(--ease-saida); }
@keyframes k-tremor { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- Gaveta / folha (bottom sheet no celular, painel lateral no desktop) ---------- */
.k-scrim {
  position: fixed; inset: 0; z-index: var(--z-scrim);
  background: var(--scrim); opacity: 0; transition: opacity var(--dur-3) ease;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.k-scrim.is-aberto { opacity: 1; }
.k-folha {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-gaveta);
  display: flex; flex-direction: column;
  max-height: 92dvh; background: var(--fundo);
  border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: var(--sombra-3);
  transform: translateY(105%); transition: transform var(--dur-3) var(--ease-saida);
  overscroll-behavior: contain;
}
.k-folha.is-aberto { transform: none; }
.k-folha__puxador { width: 44px; height: 5px; border-radius: 5px; background: var(--linha-forte); margin: var(--e-2) auto 0; flex: 0 0 auto; }
.k-folha__cab { display: flex; align-items: center; gap: var(--e-3); padding: var(--e-3) var(--e-4); flex: 0 0 auto; }
.k-folha__cab h2 { flex: 1; font-size: var(--t-xl); }
.k-folha__corpo { flex: 1 1 auto; overflow-y: auto; padding: 0 var(--e-4) var(--e-4); -webkit-overflow-scrolling: touch; }
.k-folha__pe {
  flex: 0 0 auto; padding: var(--e-3) var(--e-4) calc(var(--e-3) + env(safe-area-inset-bottom));
  background: var(--superficie); border-top: 1px solid var(--linha);
}
@media (min-width: 48rem) {
  .k-folha--lado {
    left: auto; top: 0; width: min(28rem, 100vw); max-height: none;
    border-radius: var(--r-xl) 0 0 var(--r-xl); transform: translateX(105%);
  }
  .k-folha--lado .k-folha__puxador { display: none; }
  .k-folha--centro {
    left: 50%; right: auto; top: 50%; bottom: auto; width: min(44rem, 94vw); max-height: 88dvh;
    border-radius: var(--r-xl); transform: translate(-50%, -46%) scale(0.96); opacity: 0;
    transition: transform var(--dur-3) var(--ease-saida), opacity var(--dur-2) ease;
  }
  .k-folha--centro.is-aberto { transform: translate(-50%, -50%); opacity: 1; }
  .k-folha--centro .k-folha__puxador { display: none; }
}

/* ---------- Toast ---------- */
.k-toast {
  position: fixed; left: 50%; top: calc(var(--e-4) + env(safe-area-inset-top)); z-index: var(--z-toast);
  display: flex; align-items: center; gap: var(--e-2);
  max-width: calc(100vw - 2rem); padding: var(--e-3) var(--e-4);
  border-radius: var(--r-pilula); background: var(--ks-grafite-800); color: #fff;
  font-weight: var(--peso-forte); font-size: var(--t-sm); box-shadow: var(--sombra-2);
  transform: translate(-50%, -20px); opacity: 0; pointer-events: none;
  transition: transform var(--dur-3) var(--ease-mola), opacity var(--dur-2) ease;
}
.k-toast.is-aberto { transform: translate(-50%, 0); opacity: 1; }
.k-toast svg { width: 18px; height: 18px; color: var(--ks-amarelo-500); }

/* ---------- Skeleton ---------- */
.k-skel {
  border-radius: var(--r-sm);
  background: linear-gradient(100deg, var(--skel-a) 30%, var(--skel-b) 50%, var(--skel-a) 70%) 0 0 / 300% 100%;
  animation: k-brilho 1.3s linear infinite;
}
@keyframes k-brilho { from { background-position: 100% 0; } to { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .k-skel { animation: none; } }

/* ---------- Mascote (gota do logo) ---------- */
.k-gota { display: block; width: 96px; height: auto; overflow: visible; }
.k-gota .vida { transform-box: fill-box; transform-origin: 50% 100%; animation: k-respira var(--resp-d, 3.6s) ease-in-out var(--resp-a, 0s) infinite; will-change: transform; }
.k-gota--dormindo .vida { animation-duration: calc(var(--resp-d, 3.6s) * 1.3); }
/* Olhar: a íris anda um pouco (JS põe o transform). Transição curta que retoma de onde está. */
.k-gota .iris { transition: transform .22s var(--ease-saida); }
/* Pálpebra: fica acima do olho (aberto) e desce sobre ele na piscada; dormindo fica fechada. */
.k-gota .palpebra { transform-box: fill-box; transform: translateY(-101%); animation: k-piscar var(--pisca-d, 6s) infinite var(--pisca-a, -2s); }
.k-gota--dupla .palpebra { animation-name: k-piscar-dupla; }
.k-gota--dormindo .palpebra { transform: translateY(0); animation: none; }
.k-gota--pula { animation: k-pula 1.8s var(--ease-saida) infinite; transform-origin: 50% 100%; }
/* Respiração: escala sutil com origem na base da gota. */
@keyframes k-respira { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.015, 1.03); } }
/* Piscada rara: a pálpebra fecha em ~100 ms (ease-in: é o movimento de ida) e abre em ~170 ms (ease-out); o resto do ciclo fica de olhos abertos. */
@keyframes k-piscar {
  0%, 93.4% { transform: translateY(-101%); animation-timing-function: cubic-bezier(.5, 0, .9, .6); }
  95% { transform: translateY(0); animation-timing-function: cubic-bezier(.1, .5, .3, 1); }
  97.8%, 100% { transform: translateY(-101%); }
}
@keyframes k-piscar-dupla {
  0%, 86.4% { transform: translateY(-101%); animation-timing-function: cubic-bezier(.5, 0, .9, .6); }
  88% { transform: translateY(0); animation-timing-function: cubic-bezier(.1, .5, .3, 1); }
  90%, 92.6% { transform: translateY(-101%); animation-timing-function: cubic-bezier(.5, 0, .9, .6); }
  94.2% { transform: translateY(0); animation-timing-function: cubic-bezier(.1, .5, .3, 1); }
  97%, 100% { transform: translateY(-101%); }
}
@keyframes k-pula {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  30% { transform: translateY(-10px) scale(0.96, 1.04); }
  55% { transform: translateY(0) scale(1.05, 0.95); }
  70% { transform: translateY(0) scale(1, 1); }
}
@media (prefers-reduced-motion: reduce) { .k-gota .vida, .k-gota--pula { animation: none; will-change: auto; } .k-gota .palpebra { animation: none; } .k-gota .iris { transition: none; transform: none !important; } }

/* ---------- Movimento reduzido: garante que nada fique preso no meio ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
