/* ============================================================
   Cookie Banner — Tutela Debitori
   Conforme Garante Provv. 231/2021 + Google Consent Mode v2
   ============================================================ */

:root {
  --cb-navy-1: #0A1326;
  --cb-navy-2: #142042;
  --cb-navy-3: #1F2D52;
  --cb-gold-1: #FFD86B;
  --cb-gold-2: #F5C84B;
  --cb-gold-3: #D9A93B;
  --cb-gold-4: #B8862A;
  --cb-gold-soft: rgba(245, 200, 75, 0.12);
  --cb-gold-ghost: rgba(245, 200, 75, 0.06);
  --cb-white: #FFFFFF;
  --cb-bg-soft: #F4F6FB;
  --cb-text: #0A1326;
  --cb-text-body: #2A3450;
  --cb-text-muted: #56638A;
  --cb-border: rgba(20, 32, 66, 0.1);
  --cb-error: #C72929;
  --cb-success: #1E8A50;
  --cb-focus: #1A57FF;
  --cb-font-system-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --cb-font-display: var(--cb-font-system-sans);
  --cb-font-body: var(--cb-font-system-sans);
  --cb-shadow-deep: 0 40px 100px rgba(10, 19, 38, 0.5);
  --cb-shadow-glow: 0 14px 36px rgba(245, 200, 75, 0.4);
  --cb-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ============================================================
   BACKDROP + BANNER
   ============================================================ */
.cb-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 19, 38, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 2147483600;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  animation: cb-fadein .3s ease;
}
.cb-backdrop.cb-open { display: flex; }
.cb-backdrop.cb-no-block {
  background: transparent;
  pointer-events: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.cb-backdrop.cb-no-block .cb-banner { pointer-events: auto; }
@keyframes cb-fadein { from { opacity: 0; } to { opacity: 1; } }

.cb-banner {
  background: var(--cb-white);
  width: 100%;
  max-width: 620px;
  max-height: calc(100vh - 32px);
  border-radius: 24px;
  box-shadow: var(--cb-shadow-deep);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: cb-slideup .5s var(--cb-ease);
  position: relative;
  font-family: var(--cb-font-body);
  color: var(--cb-text-body);
  font-size: 15px;
  line-height: 1.55;
}
@keyframes cb-slideup {
  from { transform: translateY(60px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@media (min-width: 640px) {
  .cb-backdrop { align-items: center; }
}

/* ============================================================
   HEADER
   ============================================================ */
.cb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 28px;
  border-bottom: 1px solid var(--cb-border);
  background: linear-gradient(180deg, var(--cb-bg-soft) 0%, var(--cb-white) 100%);
}
.cb-logo {
  display: inline-flex;
  align-items: center;
}
.cb-logo-img {
  height: 44px;
  width: auto;
  display: block;
}
@media (max-width: 520px) {
  .cb-logo-img { height: 38px; }
}

.cb-close {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(20, 32, 66, 0.06);
  color: var(--cb-navy-2);
  display: grid; place-items: center;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: background .2s ease, transform .2s ease;
}
.cb-close:hover, .cb-close:focus-visible {
  background: var(--cb-navy-1);
  color: var(--cb-white);
  transform: rotate(90deg);
}
.cb-close svg { width: 18px; height: 18px; }

/* ============================================================
   TABS (stile Cookiebot — 3 colonne underline)
   ============================================================ */
.cb-tabs {
  display: flex;
  padding: 0 28px;
  border-bottom: 1px solid var(--cb-border);
  gap: 0;
}
.cb-tab {
  flex: 1;
  padding: 18px 12px;
  border: none;
  background: transparent;
  font-family: var(--cb-font-body);
  font-weight: 700;
  font-size: 14px;
  color: var(--cb-text-muted);
  cursor: pointer;
  text-align: center;
  position: relative;
  transition: color .25s var(--cb-ease);
}
.cb-tab::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 3px;
  background: linear-gradient(90deg, var(--cb-gold-2), var(--cb-gold-3));
  border-radius: 3px 3px 0 0;
  transform: scaleX(0);
  transform-origin: center;
  transition: transform .3s var(--cb-ease);
}
.cb-tab:hover { color: var(--cb-navy-1); }
.cb-tab[aria-selected="true"] {
  color: var(--cb-gold-4);
}
.cb-tab[aria-selected="true"]::after { transform: scaleX(1); }
@media (max-width: 520px) {
  .cb-tab { font-size: 12px; padding: 14px 6px; letter-spacing: 0; }
}

/* ============================================================
   PANES
   ============================================================ */
.cb-pane {
  padding: 24px 28px 8px;
  overflow-y: auto;
  flex: 1;
}
.cb-pane[hidden] { display: none; }

.cb-pane h2 {
  font-family: var(--cb-font-display);
  font-size: clamp(1.2rem, 2.5vw, 1.5rem);
  color: var(--cb-navy-1);
  margin: 0 0 10px;
  line-height: 1.1;
  text-transform: uppercase;
  letter-spacing: -0.015em;
}
.cb-pane h2 .gold {
  background: linear-gradient(135deg, var(--cb-gold-3) 0%, var(--cb-gold-4) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.cb-pane p { margin: 0 0 14px; color: var(--cb-text-body); }
.cb-pane a {
  color: var(--cb-navy-1);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 600;
}
.cb-pane a:hover, .cb-pane a:focus-visible { color: var(--cb-gold-4); }

/* ============================================================
   DETAILS PANE — CATEGORIES + TOGGLES (Cookiebot-like)
   ============================================================ */
.cb-category {
  border-bottom: 1px solid var(--cb-border);
  padding: 18px 0;
}
.cb-category:last-child { border-bottom: none; }
.cb-category-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.cb-category-title {
  font-family: var(--cb-font-body);
  font-weight: 700;
  font-size: 15px;
  color: var(--cb-navy-1);
  margin: 0;
  letter-spacing: -0.005em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.cb-category-count {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 22px;
  padding: 0 7px;
  background: var(--cb-bg-soft);
  border: 1px solid var(--cb-border);
  color: var(--cb-text-muted);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.cb-category-desc {
  font-size: 13.5px;
  color: var(--cb-text-body);
  margin: 12px 0 0;
  line-height: 1.55;
}

/* Toggle switch */
.cb-toggle {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}
.cb-toggle input {
  position: absolute;
  opacity: 0;
  width: 100%; height: 100%;
  margin: 0;
  cursor: pointer;
}
.cb-toggle-slider {
  position: absolute;
  inset: 0;
  background: #C2CADC;
  border-radius: 999px;
  transition: background .25s var(--cb-ease);
}
.cb-toggle-slider::before {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  background: var(--cb-white);
  border-radius: 50%;
  transition: transform .25s var(--cb-ease);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.cb-toggle input:checked + .cb-toggle-slider {
  background: linear-gradient(135deg, var(--cb-gold-2) 0%, var(--cb-gold-3) 100%);
}
.cb-toggle input:checked + .cb-toggle-slider::before {
  transform: translateX(20px);
}
.cb-toggle input:disabled + .cb-toggle-slider {
  background: var(--cb-success);
  cursor: not-allowed;
  opacity: 0.85;
}
.cb-toggle input:focus-visible + .cb-toggle-slider {
  outline: 3px solid var(--cb-focus);
  outline-offset: 3px;
}

/* ============================================================
   ACTIONS (footer bottoni — Cookiebot-style)
   ============================================================ */
.cb-actions {
  display: flex;
  gap: 12px;
  padding: 18px 28px 22px;
  border-top: 1px solid var(--cb-border);
  background: var(--cb-white);
  justify-content: flex-end;
  flex-wrap: wrap;
}
.cb-actions [hidden] { display: none !important; }
.cb-actions .cb-btn { flex: 1 1 0; min-width: 140px; max-width: 280px; }
@media (max-width: 520px) {
  .cb-actions { flex-direction: column; padding: 16px 20px; }
  .cb-actions .cb-btn { max-width: none; }
}

.cb-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  border-radius: 12px;
  border: 2px solid transparent;
  font-family: var(--cb-font-body);
  font-weight: 800;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: transform .2s var(--cb-ease), box-shadow .2s var(--cb-ease), background .2s ease;
  line-height: 1;
  text-align: center;
  min-height: 48px;
  overflow: hidden;
}
.cb-btn-primary {
  background: linear-gradient(135deg, var(--cb-gold-1) 0%, var(--cb-gold-3) 100%);
  color: var(--cb-navy-1);
  box-shadow: var(--cb-shadow-glow);
}
.cb-btn-primary:hover, .cb-btn-primary:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 20px 50px rgba(245, 200, 75, 0.55);
}
.cb-btn-secondary {
  background: var(--cb-white);
  color: var(--cb-navy-1);
  border: 2px solid var(--cb-gold-2);
}
.cb-btn-secondary:hover, .cb-btn-secondary:focus-visible {
  background: var(--cb-gold-soft);
  border-color: var(--cb-gold-3);
  transform: translateY(-2px);
}
.cb-btn-ghost {
  background: var(--cb-white);
  color: var(--cb-navy-1);
  border: 2px solid var(--cb-border);
}
.cb-btn-ghost:hover, .cb-btn-ghost:focus-visible {
  border-color: var(--cb-navy-1);
  background: var(--cb-bg-soft);
}
.cb-btn-reject {
  background: transparent;
  color: var(--cb-text-muted);
  border: 2px solid var(--cb-border);
  font-weight: 700;
}
.cb-btn-reject:hover, .cb-btn-reject:focus-visible {
  color: var(--cb-navy-1);
  border-color: var(--cb-navy-1);
  background: var(--cb-bg-soft);
}

/* Footer links rimossi: i link a Cookie Policy + Privacy Policy sono ora dentro le tab Consenso e Informazioni */

/* ============================================================
   WIDGET (persistente bottom-left)
   ============================================================ */
.cb-widget {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 2147483500;
  display: none;
}
.cb-widget.cb-visible { display: block; }

.cb-widget-trigger {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--cb-white);
  border: 2px solid var(--cb-gold-2);
  cursor: pointer;
  display: grid; place-items: center;
  box-shadow: 0 12px 32px rgba(10, 19, 38, 0.3), 0 0 0 0 rgba(245, 200, 75, 0.4);
  transition: transform .25s var(--cb-ease), box-shadow .3s ease;
  font-family: var(--cb-font-body);
  position: relative;
  padding: 0;
  overflow: hidden;
}
.cb-widget-trigger:hover, .cb-widget-trigger:focus-visible {
  transform: scale(1.08);
  box-shadow: 0 16px 40px rgba(10, 19, 38, 0.4), 0 0 0 6px rgba(245, 200, 75, 0.22);
}
.cb-widget-mark {
  width: 40px;
  height: 40px;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.cb-widget-popup {
  position: absolute;
  bottom: 70px; left: 0;
  background: var(--cb-white);
  border-radius: 18px;
  width: 320px;
  max-width: calc(100vw - 40px);
  padding: 20px;
  box-shadow: var(--cb-shadow-deep);
  display: none;
  animation: cb-widget-pop .35s var(--cb-ease);
  border: 1px solid var(--cb-border);
}
.cb-widget-popup.cb-open { display: block; }
@keyframes cb-widget-pop {
  from { transform: translateY(10px) scale(0.97); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.cb-widget-popup h3 {
  margin: 0 0 8px;
  font-family: var(--cb-font-display);
  font-size: 1rem;
  color: var(--cb-navy-1);
  text-transform: uppercase;
}
.cb-widget-popup p {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--cb-text-body);
  line-height: 1.5;
}
.cb-widget-popup .cb-status-list {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
}
.cb-widget-popup .cb-status-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  color: var(--cb-text-body);
}
.cb-widget-popup .cb-status-list .cb-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}
.cb-widget-popup .cb-status-list .cb-dot-on { background: var(--cb-success); }
.cb-widget-popup .cb-status-list .cb-dot-off { background: #C2CADC; }
.cb-widget-popup .cb-status-list .cb-status-val {
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.cb-widget-popup .cb-status-list .cb-status-val.on { color: var(--cb-success); }
.cb-widget-popup .cb-status-list .cb-status-val.off { color: var(--cb-text-muted); }

.cb-widget-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cb-widget-actions .cb-btn {
  padding: 12px 16px;
  font-size: 12px;
  min-height: 44px;
}

/* ============================================================
   FOCUS VISIBLE GLOBALE
   ============================================================ */
.cb-banner :focus-visible,
.cb-widget :focus-visible {
  outline: 3px solid var(--cb-focus);
  outline-offset: 3px;
}

/* ============================================================
   SCREEN READER ONLY
   ============================================================ */
.cb-sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .cb-backdrop, .cb-banner, .cb-widget-popup {
    animation: none !important;
  }
  .cb-banner *, .cb-widget * { transition-duration: 0.01ms !important; }
}

/* ============================================================
   HIGH CONTRAST
   ============================================================ */
@media (prefers-contrast: more) {
  :root {
    --cb-text-body: #000000;
    --cb-text-muted: #1A2540;
    --cb-border: rgba(20, 32, 66, 0.5);
  }
  .cb-btn-ghost { border-width: 3px; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 520px) {
  .cb-header { padding: 18px 20px; }
  .cb-tabs { margin: 12px 20px 0; }
  .cb-pane { padding: 20px 20px 8px; }
  .cb-actions { padding: 16px 20px 20px; }
  .cb-footer-links { padding: 0 20px 16px; }
  .cb-actions { grid-template-columns: 1fr; }
  /* Mobile: widget spinto sotto il bordo visibile (bottom: -20px) */
  .cb-widget { bottom: -20px; left: 6px; }
  .cb-widget-trigger { width: 48px; height: 48px; }
  .cb-widget-mark { width: 28px; height: 28px; }
  .cb-widget-popup { bottom: 38px; left: 8px; }
}
