/* ============================================================
   COOKIE BANNER — PBI #38 F1.7 (paridade #377)
   Estilos isolados consumindo tokens.css (klosi-core).
   Modo claro e escuro automáticos via [data-theme].
   Métricas e estados espelham design/prototipos/app/cookie-banner.html
   (contrato em docs/design/contratos-visuais/cookie-banner.md).
   ============================================================ */

/* Host fixed wrapper — banner posicionado no rodapé do viewport. */
.kc-host {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
}
.kc-host > * { pointer-events: auto; }

/* ── Banner ──────────────────────────────────────────────── */
.kc-banner {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-secondary);
  box-shadow: 0 -12px 32px -8px rgba(15, 17, 24, .10), 0 -2px 8px rgba(15, 17, 24, .04);
  padding: 16px 20px;
  z-index: 60;
  animation: kc-slide-up 240ms var(--ease-out) both;
}
[data-theme="dark"] .kc-banner {
  box-shadow: 0 -16px 32px -8px rgba(0, 0, 0, .50), 0 -2px 8px rgba(0, 0, 0, .30);
}

@keyframes kc-slide-up {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.kc-banner__close {
  position: absolute;
  top: 10px; right: 10px;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border: 0;
  background: transparent;
  color: var(--text-tertiary);
  border-radius: 6px;
  cursor: pointer;
}
.kc-banner__close:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.kc-banner__close:focus-visible { outline: 2px solid var(--brand-primary); outline-offset: 2px; }
.kc-banner__close[disabled] { opacity: .55; cursor: not-allowed; }

.kc-banner__inner {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
}

.kc-banner__msg {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding-right: 24px;
}
.kc-banner__icon {
  width: 36px; height: 36px;
  border-radius: var(--r-md);
  background: var(--brand-soft);
  color: var(--brand-fg);
  display: grid; place-items: center;
  border: 1px solid var(--brand-soft-2);
  flex-shrink: 0;
}
.kc-banner__title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 2px;
  letter-spacing: -.005em;
}
.kc-banner__desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
  max-width: 64ch;
}
.kc-banner__desc a {
  color: var(--brand-fg);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

.kc-banner__actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* Re-consent ribbon — política de cookies atualizada (CA01). */
.kc-recon {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--info-fg);
  background: var(--info-bg);
  border: 1px solid var(--info-bd);
  border-radius: var(--r-pill);
  padding: 3px 9px;
  margin-bottom: 6px;
  font-family: var(--font-display);
}
.kc-recon svg { width: 11px; height: 11px; }

/* Buttons (banner-local; espelham DS sem depender de KButton) */
.kc-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  border: 0;
  font: inherit;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  padding: 0 16px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur), border-color var(--dur), color var(--dur);
}
.kc-btn:focus-visible { outline: 2px solid var(--brand-primary); outline-offset: 2px; }
.kc-btn--primary {
  background: var(--brand-primary);
  color: var(--text-on-brand);
}
.kc-btn--primary:hover { background: var(--brand-primary-hover); }
.kc-btn--secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-primary);
}
.kc-btn--secondary:hover { background: var(--bg-secondary); }
.kc-btn--ghost {
  background: transparent;
  color: var(--brand-fg);
  border: 1px solid transparent;
}
.kc-btn--ghost:hover { background: var(--brand-soft); }
.kc-btn--sm { height: 34px; font-size: 12.5px; padding: 0 12px; border-radius: 7px; }
.kc-btn[disabled] { opacity: .55; cursor: not-allowed; }

.kc-btn .spin {
  width: 14px; height: 14px;
  border-radius: 999px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: kc-spin .8s linear infinite;
}
@keyframes kc-spin { to { transform: rotate(360deg); } }

/* ── Drawer ──────────────────────────────────────────────── */
.kc-drawer-mask {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(2px);
  z-index: 70;
  animation: kc-fade 200ms var(--ease-out) both;
  display: flex;
  justify-content: flex-end;
}
@keyframes kc-fade { from { opacity: 0; } to { opacity: 1; } }

.kc-drawer {
  position: relative;
  top: 0; right: 0; bottom: 0;
  width: 480px; max-width: 100%;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-secondary);
  box-shadow: -24px 0 64px -16px rgba(15, 17, 24, .20);
  display: flex; flex-direction: column;
  animation: kc-slide-r 280ms var(--ease-out) both;
}
[data-theme="dark"] .kc-drawer { box-shadow: -24px 0 64px -16px rgba(0, 0, 0, .60); }
@keyframes kc-slide-r {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

/* Grab indicator — visível só no bottom-sheet mobile. */
.kc-drawer__grab { display: none; }

/* Mobile: bottom-sheet em vez de drawer lateral */
@media (max-width: 768px) {
  .kc-drawer-mask { align-items: flex-end; }
  .kc-drawer {
    width: 100%;
    height: auto;
    max-height: 85vh;
    border-left: 0;
    border-top-left-radius: 18px;
    border-top-right-radius: 18px;
    box-shadow: 0 -24px 64px -16px rgba(15, 17, 24, .30);
    animation: kc-slide-up-sheet 280ms var(--ease-out) both;
  }
  @keyframes kc-slide-up-sheet {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }
  .kc-drawer__grab {
    display: block;
    width: 40px; height: 4px;
    background: var(--border-primary);
    border-radius: 999px;
    margin: 8px auto 0;
    flex-shrink: 0;
  }
  .kc-drawer__foot .kc-btn { height: 34px; font-size: 12.5px; padding: 0 12px; border-radius: 7px; }
  .kc-drawer__foot .kc-btn--primary { flex: 1; }
}

.kc-drawer__head {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border-secondary);
  position: relative;
}
.kc-drawer__head h2 {
  font-family: var(--font-display);
  font-size: 18px; font-weight: 600;
  letter-spacing: -.01em;
  margin: 0 0 4px;
  padding-right: 32px;
  color: var(--text-primary);
}
.kc-drawer__head h2:focus { outline: none; }
.kc-drawer__head p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
}
.kc-drawer__close {
  position: absolute;
  top: 14px; right: 14px;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 0;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border-radius: 999px;
  cursor: pointer;
}
.kc-drawer__close:hover { color: var(--text-primary); background: var(--bg-primary); }
.kc-drawer__close:focus-visible { outline: 2px solid var(--brand-primary); outline-offset: 2px; }

.kc-drawer__body {
  padding: 18px 20px;
  display: flex; flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  flex: 1;
}

.kc-cat {
  border: 1px solid var(--border-secondary);
  background: var(--bg-primary);
  border-radius: var(--r-md);
  padding: 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: start;
}
.kc-cat__icon {
  width: 36px; height: 36px;
  border-radius: var(--r-md);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.kc-cat__icon--locked { background: var(--success-bg); color: var(--success-strong); border: 1px solid var(--success-bd); }
.kc-cat__icon--analytics { background: var(--brand-soft); color: var(--brand-fg); border: 1px solid var(--brand-soft-2); }
.kc-cat__icon--marketing { background: var(--coral-50); color: var(--coral-600); border: 1px solid var(--coral-100); }
[data-theme="dark"] .kc-cat__icon--marketing { background: rgba(249, 112, 102, .14); border-color: rgba(249, 112, 102, .30); color: var(--coral-400); }
.kc-cat__icon--perso { background: var(--amber-50); color: var(--amber-800); border: 1px solid var(--amber-100); }
[data-theme="dark"] .kc-cat__icon--perso { background: rgba(255, 181, 71, .14); border-color: rgba(255, 181, 71, .30); color: var(--amber-400); }

.kc-cat__body { min-width: 0; }
.kc-cat__title {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-display);
  font-size: 14.5px; font-weight: 600;
  letter-spacing: -.005em;
  margin: 0 0 2px;
  color: var(--text-primary);
}
.kc-cat__badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  background: var(--success-bg);
  color: var(--success-fg);
  padding: 2px 7px;
  border-radius: 999px;
}
.kc-cat__desc {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0 0 8px;
}

/* Lista de cookies da categoria Necessários (CA05). */
.kc-cat__cookies {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 11px;
  color: var(--text-tertiary);
  display: grid;
  gap: 2px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-secondary);
}
.kc-cat__cookies code {
  font: inherit;
  color: var(--brand-fg);
}

/* Switch (role="switch") — botão acessível, 38x22 como no protótipo. */
.kc-switch {
  --w: 38px; --h: 22px;
  position: relative;
  border: 0;
  width: var(--w);
  height: var(--h);
  background: var(--gray-200);
  border-radius: 999px;
  cursor: pointer;
  margin-top: 4px;
  flex-shrink: 0;
  padding: 0;
  transition: background var(--dur);
}
[data-theme="dark"] .kc-switch { background: var(--gray-700); }
.kc-switch__knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 999px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
  transition: transform var(--dur);
}
.kc-switch[data-checked="true"] { background: var(--brand-primary); }
.kc-switch[data-checked="true"] .kc-switch__knob { transform: translateX(16px); }
.kc-switch[data-disabled="true"] {
  background: var(--success-strong);
  cursor: not-allowed;
  opacity: .9;
}
.kc-switch[data-disabled="true"] .kc-switch__knob { transform: translateX(16px); }
.kc-switch:focus-visible { outline: 2px solid var(--brand-primary); outline-offset: 2px; }

.kc-drawer__foot {
  border-top: 1px solid var(--border-secondary);
  padding: 14px 20px;
  display: flex; align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-secondary);
}

/* ── Toast ──────────────────────────────────────────────── */
.kc-toast {
  position: fixed;
  bottom: 20px; right: 20px;
  background: var(--gray-900);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  padding: 12px 16px;
  border-radius: var(--r-md);
  display: inline-flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 80;
  animation: kc-toast-in 200ms var(--ease-out) both;
}
[data-theme="dark"] .kc-toast { background: var(--gray-50); color: var(--gray-900); }
.kc-toast__icon {
  width: 22px; height: 22px;
  background: var(--green-600);
  color: #fff;
  border-radius: 999px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
@keyframes kc-toast-in {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ── Erro inline ─────────────────────────────────────────── */
.kc-error {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--danger-bg);
  border: 1px solid var(--danger-bd);
  color: var(--danger-fg);
  padding: 8px 12px;
  border-radius: var(--r-md);
  font-size: 12.5px;
  margin-right: 12px;
}
.kc-error svg { color: var(--danger-strong); flex-shrink: 0; }
.kc-error button {
  font: inherit;
  font-weight: 600;
  background: none;
  border: 0;
  color: var(--danger-strong);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}

/* ── Mobile banner overrides ────────────────────────────── */
/* Breakpoint 768px como o protótipo (sec-desc "Em < 768px") — mesma faixa
   do bottom-sheet do drawer, sem o híbrido 721-768 (D15). */
@media (max-width: 768px) {
  .kc-banner { padding: 14px 14px 14px; }
  .kc-banner__inner {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .kc-banner__msg { padding-right: 28px; }
  .kc-banner__actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    width: 100%;
  }
  /* Ordem visual mobile do protótipo: Aceitar todos → Apenas essenciais →
     Configurar (erro inline acima de tudo). DOM segue a ordem desktop. */
  .kc-banner__actions .kc-error { order: 0; margin-right: 0; }
  .kc-banner__actions .kc-btn--primary { order: 1; }
  .kc-banner__actions .kc-btn--secondary { order: 2; }
  .kc-banner__actions .kc-btn--ghost { order: 3; }
  .kc-btn { width: 100%; height: 44px; font-size: 13.5px; }
  .kc-banner__desc { font-size: 12.5px; }
  .kc-banner__title { font-size: 14.5px; }
}
