/* ==========================================================================
   Cookie bar + pannello preferenze (modulo Legal). Solo variabili del design system.
   Layout: .cc-layout-bar (barra in basso), .cc-layout-box (riquadro in basso a sinistra),
           .cc-layout-modal (finestra centrale con sfondo)
   ========================================================================== */
.cookie-consent[hidden], .cc-modal[hidden], .cc-floating[hidden] { display: none !important; }
body.cc-lock { overflow: hidden; }

.cc-banner {
  position: fixed; z-index: 1100;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  font-size: .92rem; line-height: 1.5;
  animation: ccUp .38s cubic-bezier(.2, .9, .3, 1.1) both;
}
.cc-banner:focus { outline: none; }
.cc-banner-body { display: flex; gap: .9rem; align-items: flex-start; min-width: 0; }
.cc-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; background: var(--primary-soft); color: var(--primary); }
.cc-banner-text { min-width: 0; }
.cc-title { font-size: 1.02rem; margin: 0 0 .25rem; padding-right: 2rem; }
.cc-text { margin: 0; color: var(--text-muted); }
.cc-text a { font-weight: 600; text-decoration: underline; }
.cc-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.cc-btn { min-width: 130px; justify-content: center; }
.cc-close {
  position: absolute; top: .6rem; right: .6rem; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; border: 1px solid transparent; background: transparent; color: var(--text-muted); cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.cc-close:hover { background: var(--surface-3); color: var(--text); }
.cc-close:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* Barra in basso */
.cc-layout-bar .cc-banner {
  left: 1rem; right: 1rem; bottom: 1rem; margin: 0 auto; max-width: 1200px;
  border-radius: var(--radius-lg); padding: 1.1rem 3.25rem 1.1rem 1.25rem;
  display: flex; align-items: center; gap: 1.25rem;
}
.cc-layout-bar .cc-banner-body { flex: 1; }
.cc-layout-bar .cc-actions { flex-shrink: 0; }

/* Riquadro in basso a sinistra */
.cc-layout-box .cc-banner {
  left: 1rem; bottom: 1rem; width: min(420px, calc(100vw - 2rem));
  border-radius: var(--radius-lg); padding: 1.25rem;
}
.cc-layout-box .cc-actions { margin-top: 1rem; }
.cc-layout-box .cc-actions .cc-btn { flex: 1 1 auto; min-width: 0; }
.cc-layout-box .cc-btn-customize { order: 3; flex-basis: 100%; }

/* Finestra centrale */
.cc-backdrop, .cc-modal-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 23, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: ccFade .25s ease-out both; }
.cc-backdrop { z-index: 1099; }
.cc-layout-modal .cc-banner {
  left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(540px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); overflow-y: auto;
  border-radius: var(--radius-lg); padding: 1.75rem 1.5rem 1.5rem;
  animation: ccPop .32s cubic-bezier(.2, .9, .3, 1.2) both;
}
.cc-layout-modal .cc-banner-body { flex-direction: column; align-items: center; text-align: center; }
.cc-layout-modal .cc-title { padding: 0; font-size: 1.2rem; }
.cc-layout-modal .cc-actions { margin-top: 1.25rem; justify-content: center; }
.cc-layout-modal .cc-actions .cc-btn { flex: 1 1 140px; }
.cc-layout-modal .cc-btn-customize { order: 3; flex-basis: 100%; }

/* Uscita */
.cookie-consent.cc-leaving .cc-banner { animation: ccDown .25s ease-in both; }
.cookie-consent.cc-leaving.cc-layout-modal .cc-banner { animation: ccPopOut .2s ease-in both; }
.cookie-consent.cc-leaving .cc-backdrop { animation: ccFadeOut .25s ease-in both; }

/* Pannello preferenze */
.cc-modal { position: fixed; inset: 0; z-index: 1200; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.cc-modal-backdrop { z-index: 0; }
.cc-dialog {
  position: relative; z-index: 1; width: min(600px, 100%); max-height: calc(100vh - 2rem); display: flex; flex-direction: column;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: ccPop .28s cubic-bezier(.2, .9, .3, 1.2) both;
}
.cc-dialog:focus { outline: none; }
.cc-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem 1rem 1.5rem; border-bottom: 1px solid var(--border); }
.cc-dialog-head h2 { margin: 0; font-size: 1.1rem; display: flex; align-items: center; gap: .5rem; }
.cc-dialog-head h2 .icon { color: var(--primary); }
.cc-close-static { position: static; }
.cc-dialog-body { padding: 1.1rem 1.5rem; overflow-y: auto; }
.cc-prefs-intro { color: var(--text-muted); font-size: .9rem; }
.cc-cats { border: 1px solid var(--border); border-radius: var(--radius); padding: 0 1rem; background: var(--surface-2); }
.cc-cat .badge { margin-left: .35rem; vertical-align: middle; }
.cc-cat input:disabled + .switch-ui { opacity: .6; cursor: not-allowed; }
.cc-dialog-foot { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; padding: 1rem 1.5rem; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.cc-dialog-foot .cc-btn { flex: 1 1 140px; }
.cc-modal.cc-leaving .cc-dialog { animation: ccPopOut .18s ease-in both; }
.cc-modal.cc-leaving .cc-modal-backdrop { animation: ccFadeOut .2s ease-in both; }

/* Pulsante flottante */
.cc-floating {
  position: fixed; left: 1rem; bottom: 1rem; z-index: 900; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: var(--surface); color: var(--primary); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
  animation: ccFade .3s ease-out both;
}
.cc-floating:hover { transform: translateY(-2px) rotate(-8deg); box-shadow: var(--shadow-lg); }
.cc-floating:focus-visible { outline: none; box-shadow: var(--focus-ring); }

@keyframes ccUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
@keyframes ccDown { to { opacity: 0; transform: translateY(24px); } }
@keyframes ccPop { from { opacity: 0; transform: translate(-50%, -46%) scale(.96); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes ccPopOut { to { opacity: 0; transform: translate(-50%, -48%) scale(.97); } }
@keyframes ccFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ccFadeOut { to { opacity: 0; } }
/* il dialogo preferenze non usa translate(-50%) */
.cc-dialog { animation-name: ccDialogIn; }
.cc-modal.cc-leaving .cc-dialog { animation-name: ccDialogOut; }
@keyframes ccDialogIn { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes ccDialogOut { to { opacity: 0; transform: translateY(8px) scale(.98); } }

@media (max-width: 860px) {
  .cc-layout-bar .cc-banner { flex-direction: column; align-items: stretch; padding: 1.1rem 1.1rem 1rem; left: .5rem; right: .5rem; bottom: .5rem; }
  .cc-layout-bar .cc-actions .cc-btn { flex: 1 1 auto; min-width: 0; }
  .cc-layout-bar .cc-btn-customize { order: 3; flex-basis: 100%; }
}
@media (max-width: 520px) {
  .cc-banner { font-size: .88rem; }
  .cc-icon { display: none; }
  .cc-layout-box .cc-banner { left: .5rem; bottom: .5rem; width: calc(100vw - 1rem); }
  .cc-dialog-foot .cc-btn { flex-basis: 100%; }
}
@media print {
  .cookie-consent, .cc-modal, .cc-floating { display: none !important; }
}
