/* Aviso e preferencias de cookies (public/cookies.js).
   Adaptado do padrao da Moretto: prefixo kc-, tokens de cor do Base.astro. */

:root {
  --kc-primaria: var(--color-primary, #482828);
  --kc-primaria-clara: var(--color-primary-light, #705050);
  --kc-fundo: var(--color-bg, #f5f0ed);
  --kc-texto: #5a4040;
  --kc-borda: #e6dcd6;
  --kc-foco: #482828;
  --kc-trilho: #8f7a7a;    /* interruptor desligado: 3,9:1 sobre branco */
}

/* ---------- icone do cookie ---------- */
.kc-cookie { width: 100%; height: 100%; overflow: visible; }
.kc-cookie__massa { fill: #e3b98f; stroke: #a8794f; stroke-width: 1.5; }
.kc-cookie__gota { fill: #482828; }
.kc-cookie__farelo { fill: #cf9f74; }

/* ---------- aviso ---------- */
.kc-aviso {
  position: fixed;
  z-index: 10000;
  left: max(20px, env(safe-area-inset-left, 0px));
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  width: min(440px, calc(100vw - 40px));
  /* nunca maior que a tela (zoom 400 %, celular deitado): rola por dentro */
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 4px 16px;
  padding: 22px 22px 18px;
  border: 1px solid var(--kc-borda);
  border-radius: 20px;
  background: #fff;
  color: var(--kc-texto);
  font: 400 15px/1.55 system-ui, -apple-system, sans-serif;
  box-shadow: 0 24px 60px rgba(72, 40, 40, 0.22), 0 2px 6px rgba(72, 40, 40, 0.06);
  opacity: 0;
  transform: translateY(24px) scale(0.98);
  transition: opacity 320ms ease, transform 420ms cubic-bezier(.22, 1, .36, 1);
}
/* fio bordo no topo, como assinatura da marca */
.kc-aviso::before {
  content: "";
  position: absolute;
  inset: 0 22px auto;
  height: 4px;
  border-radius: 0 0 4px 4px;
  background: linear-gradient(90deg, var(--kc-primaria), var(--kc-primaria-clara));
}
.kc-aviso.is-visivel { opacity: 1; transform: none; }
.kc-aviso.is-saindo { opacity: 0; transform: translateY(16px); }
.kc-aviso__icone { width: 58px; height: 58px; margin-top: 2px; }
.kc-aviso.is-visivel .kc-cookie { animation: kc-balanco 1.4s cubic-bezier(.36, .07, .19, .97) 450ms both; transform-origin: 50% 60%; }
.kc-aviso.is-visivel .kc-cookie__farelo { animation: kc-farelo 1.2s ease-out 700ms both; }
@keyframes kc-balanco {
  0% { transform: rotate(0); } 18% { transform: rotate(-12deg); } 36% { transform: rotate(9deg); }
  54% { transform: rotate(-5deg); } 72% { transform: rotate(2deg); } 100% { transform: rotate(0); }
}
@keyframes kc-farelo { from { transform: translate(-6px, -8px); opacity: 0; } to { transform: none; opacity: 1; } }
.kc-aviso__texto h2 { margin: 2px 0 4px; color: var(--kc-primaria); font: 600 19px/1.25 system-ui, -apple-system, sans-serif; letter-spacing: 0.01em; }
.kc-aviso__texto p { margin: 0; }
.kc-aviso__curto { display: none; }
.kc-aviso a, .kc-prefs a { color: var(--kc-primaria); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.kc-aviso__botoes {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}
.kc-aviso__botoes .kc-link { grid-column: 1 / -1; justify-self: center; }

/* ---------- botoes ---------- */
.kc-btn {
  min-height: 46px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1.5px solid var(--kc-primaria);
  font: 600 15px/1 system-ui, -apple-system, sans-serif;
  cursor: pointer;
  transition: background-color 180ms, color 180ms, transform 120ms;
}
/* Recusar e Aceitar usam a mesma classe: mesmo peso visual (orientacao da ANPD) */
.kc-btn--pri { background: var(--kc-primaria); color: #fff; }
.kc-btn--pri:is(:hover, :focus-visible) { background: var(--kc-primaria-clara); border-color: var(--kc-primaria-clara); }
.kc-btn--sec { background: #fff; color: var(--kc-primaria); }
.kc-btn--sec:is(:hover, :focus-visible) { background: var(--kc-fundo); }
.kc-btn:active { transform: scale(0.98); }
.kc-link {
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  background: none;
  color: var(--kc-texto);
  font: 600 14px/1 system-ui, -apple-system, sans-serif;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}
.kc-link:hover { color: var(--kc-primaria); }
:is(.kc-btn, .kc-link, .kc-fechar, .kc-chave input, .kc-aviso a, .kc-prefs a):focus-visible { outline: 3px solid var(--kc-foco); outline-offset: 3px; }
/* conteudo principal recebe o foco (tabindex=-1) depois da escolha: sem anel em volta da pagina */
.kc-foco-alvo:focus { outline: none; }

/* ---------- preferencias ---------- */
.kc-prefs {
  width: min(600px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: #fff;
  color: var(--kc-texto);
  font: 400 15px/1.55 system-ui, -apple-system, sans-serif;
  box-shadow: 0 30px 80px rgba(72, 40, 40, 0.35);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.kc-prefs::backdrop { background: rgba(72, 40, 40, 0.45); backdrop-filter: blur(3px); }
.kc-prefs[open] { animation: kc-entra 360ms cubic-bezier(.22, 1, .36, 1); }
@keyframes kc-entra { from { opacity: 0; transform: translateY(18px) scale(0.98); } to { opacity: 1; transform: none; } }
.kc-prefs__caixa { margin: 0; }
.kc-prefs__topo {
  position: relative;
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 14px;
  align-items: start;
  padding: 26px 64px 20px 24px;
  background: var(--kc-fundo);
  border-bottom: 1px solid var(--kc-borda);
}
.kc-prefs__topo > .kc-cookie { width: 52px; height: 52px; }
.kc-prefs__topo h2 { margin: 0 0 4px; color: var(--kc-primaria); font: 600 22px/1.2 system-ui, -apple-system, sans-serif; }
.kc-prefs__topo p { margin: 0; font-size: 14.5px; }
.kc-fechar {
  position: absolute; top: 12px; right: 12px;
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--kc-primaria);
  font-size: 26px; line-height: 1; cursor: pointer;
}
.kc-fechar:hover { background: #fff; }
.kc-cats { list-style: none; margin: 0; padding: 8px 24px; }
.kc-cat { display: flex; align-items: center; gap: 18px; padding: 18px 0; border-bottom: 1px solid var(--kc-borda); }
.kc-cat:last-child { border-bottom: 0; }
.kc-cat__txt { flex: 1; min-width: 0; }
.kc-cat h3 { margin: 0 0 2px; color: var(--kc-primaria); font: 600 16.5px/1.3 system-ui, -apple-system, sans-serif; }
.kc-cat p { margin: 0; font-size: 14px; }
.kc-chave { position: relative; display: grid; justify-items: center; gap: 4px; flex: none; cursor: pointer; }
.kc-chave input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.kc-chave__trilho {
  position: relative;
  width: 52px; height: 30px;
  border-radius: 999px;
  background: var(--kc-trilho);
  transition: background-color 200ms;
}
.kc-chave__bola {
  position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 220ms cubic-bezier(.22, 1, .36, 1);
}
.kc-chave input:checked + .kc-chave__trilho { background: var(--kc-primaria); }
.kc-chave input:checked + .kc-chave__trilho .kc-chave__bola { transform: translateX(22px); }
.kc-chave input:focus-visible + .kc-chave__trilho { outline: 3px solid var(--kc-foco); outline-offset: 3px; }
.kc-chave.is-fixa { cursor: default; }
.kc-chave.is-fixa .kc-chave__trilho { background: #a88f8f; }
.kc-chave__rot { color: var(--kc-texto); font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.kc-chave__rot:empty { display: none; }
.kc-prefs__links { margin: 0; padding: 4px 24px 0; font-size: 14px; }
.kc-prefs__botoes {
  position: sticky; bottom: 0;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  padding: 18px 24px 24px;
  background: #fff;
  border-top: 1px solid var(--kc-borda);
}

/* ---------- confirmacao ---------- */
.kc-toast {
  position: fixed; z-index: 10001;
  left: 50%; bottom: max(24px, env(safe-area-inset-bottom, 0px));
  margin: 0; padding: 12px 20px;
  border-radius: 999px;
  background: var(--kc-primaria); color: #fff;
  font: 500 14.5px/1.3 system-ui, -apple-system, sans-serif;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 250ms, transform 300ms cubic-bezier(.22, 1, .36, 1);
}
.kc-toast.is-visivel { opacity: 1; transform: translate(-50%, 0); }

/* ---------- celular: folha na base da tela ---------- */
@media (max-width: 600px) {
  .kc-aviso {
    left: 0; right: 0; bottom: 0;
    width: auto;
    grid-template-columns: 48px 1fr;
    padding: 20px max(18px, env(safe-area-inset-left, 0px)) calc(16px + env(safe-area-inset-bottom, 0px));
    border-radius: 22px 22px 0 0;
    border-bottom: 0;
    max-height: calc(100dvh - 16px);
  }
  .kc-aviso__icone { width: 46px; height: 46px; }
  .kc-aviso__texto h2 { font-size: 18px; }
  .kc-aviso__texto p { font-size: 14.5px; }
  .kc-prefs { border-radius: 20px; }
  /* topo sem icone e Recusar/Aceitar lado a lado: sobra espaco para as categorias */
  .kc-prefs__topo { grid-template-columns: 1fr; padding: 18px 60px 14px 20px; }
  .kc-prefs__topo > .kc-cookie { display: none; }
  .kc-prefs__topo h2 { font-size: 20px; }
  .kc-cats { padding: 4px 20px; }
  .kc-prefs__links { padding: 4px 20px 0; }
  .kc-prefs__botoes { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 14px 16px 16px; }
  .kc-prefs__botoes [data-kc="salvar"] { grid-column: 1 / -1; order: 1; }
  html body .kc-prefs button.kc-btn { min-width: 0; min-height: 44px; padding: 4px 8px; font-size: 14px; line-height: 1.15; white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  .kc-aviso, .kc-toast, .kc-btn, .kc-chave__trilho, .kc-chave__bola { transition: none; }
  .kc-aviso.is-visivel .kc-cookie, .kc-aviso.is-visivel .kc-cookie__farelo, .kc-prefs[open] { animation: none; }
}

/* ---------- telas baixas (< 700 px de altura): aviso compacto ----------
   Sem icone, titulo menor, texto curto. */
@media (max-height: 699px) {
  .kc-aviso { grid-template-columns: 1fr; gap: 2px; padding: 16px 18px 12px; }
  .kc-aviso__icone { display: none; }
  .kc-aviso__texto h2 { margin: 0 0 2px; font-size: 17px; }
  .kc-aviso__texto p { font-size: 14px; line-height: 1.45; }
  .kc-aviso__longo { display: none; }
  .kc-aviso__curto { display: inline; }
  .kc-aviso__botoes { gap: 8px; margin-top: 10px; }
  html body .kc-aviso button.kc-btn { min-height: 44px; padding: 0 12px; font-size: 14.5px; }
  html body .kc-aviso button.kc-link { min-height: 36px; }
}
/* tres botoes numa linha quando couber */
@media (max-height: 699px) and (min-width: 420px) {
  .kc-aviso__botoes { grid-template-columns: 1fr 1fr auto; }
  .kc-aviso__botoes .kc-link { grid-column: auto; }
  html body .kc-aviso button.kc-link { min-height: 44px; }
}
/* celular deitado / zoom alto (<= 500 px de altura): ainda mais justo */
@media (max-height: 500px) {
  .kc-aviso { padding: 12px 16px 10px; }
  .kc-aviso__botoes { margin-top: 8px; }
}
@media (max-height: 500px) and (min-width: 601px) {
  /* cartao largo e baixo no canto esquerdo, longe do botao do WhatsApp (a direita) */
  .kc-aviso {
    left: max(12px, env(safe-area-inset-left, 0px));
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    width: min(560px, calc(100vw - 100px));
    max-height: calc(100dvh - 16px);
  }
  .kc-aviso::before { inset: 0 16px auto; }
}
/* celular deitado / zoom 400 %: os botoes empilhados nao cabem fixos na base da janela; rolam com o resto */
@media (max-height: 500px) and (max-width: 600px) {
  .kc-prefs__botoes { position: static; }
}
