/*
 * consent.css - styles for the cookie banner, the "Choose cookies" dialog and the status line.
 *
 * Every colour, font, radius and spacing value comes from the site's design tokens (CSS custom
 * properties) with a fallback, because the visual design is still being chosen. All class names
 * start with "cc-". The banner is fixed to the bottom of the screen and the dialog sits in the
 * browser's top layer, so neither moves the page behind them (no layout shift, no cookie wall).
 */

/* The hidden attribute must always win over the display rules below. */
.cc-root [hidden] {
  display: none !important;
}

.cc-root {
  font-family: var(--font-body, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
  color: var(--color-ink, #0F1D3A);
  line-height: 1.5;
}

/* ---------------------------------------------------------------------------------------
 * Shared pieces
 * --------------------------------------------------------------------------------------- */
.cc-title {
  margin: 0 0 var(--space-2, 8px);
  font-family: var(--font-heading, inherit);
  font-size: var(--text-lg, 1.125rem);
  font-weight: 700;
  color: var(--color-ink, #0F1D3A);
}

.cc-text {
  margin: 0 0 var(--space-2, 8px);
  font-size: var(--text-sm, 0.9375rem);
  color: var(--color-ink-muted, #3D4A63);
}

.cc-note {
  padding: var(--space-2, 8px) var(--space-3, 12px);
  border-left: 3px solid var(--color-accent, #2F5BEA);
  background: var(--color-surface-alt, #F2F5FA);
  border-radius: var(--radius-sm, 6px);
}

.cc-link {
  color: var(--color-link, #1F4ED8);
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

.cc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2, 8px);
}

/* All choice buttons share one style: "Accept all" and "Reject all" have the same size,
   weight and colour, as the Garante guidelines ask. Do not give one of them its own style. */
.cc-btn {
  flex: 1 1 auto;
  min-height: 44px;
  min-width: 44px;
  margin: 0;
  padding: var(--space-2, 8px) var(--space-4, 16px);
  font: inherit;
  font-size: var(--text-sm, 0.9375rem);
  font-weight: 600;
  line-height: 1.2;
  color: var(--color-on-ink, #FFFFFF);
  background: var(--color-ink, #0F1D3A);
  border: 2px solid var(--color-ink, #0F1D3A);
  border-radius: var(--radius, 10px);
  cursor: pointer;
}

.cc-btn:hover {
  background: var(--color-ink-hover, #22345C);
  border-color: var(--color-ink-hover, #22345C);
}

.cc-btn:focus-visible,
.cc-close:focus-visible,
.cc-link:focus-visible,
.cc-switch:focus-visible {
  outline: 3px solid var(--color-focus, #2F5BEA);
  outline-offset: 2px;
}

.cc-close {
  position: absolute;
  top: var(--space-2, 8px);
  right: var(--space-2, 8px);
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--color-ink, #0F1D3A);
  background: transparent;
  border: 0;
  border-radius: var(--radius, 10px);
  cursor: pointer;
}

.cc-close:hover {
  background: var(--color-surface-alt, #F2F5FA);
}

.cc-sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------------------------------
 * Banner: a bar at the bottom of the screen, never a wall. The page stays usable behind it.
 * --------------------------------------------------------------------------------------- */
.cc-banner {
  position: fixed;
  z-index: var(--z-consent, 1000);
  left: var(--space-4, 16px);
  right: var(--space-4, 16px);
  bottom: var(--space-4, 16px);
  box-sizing: border-box;
  max-width: 1040px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  margin: 0 auto;
  overflow-y: auto;
  padding: var(--space-5, 20px) calc(44px + var(--space-4, 16px)) var(--space-5, 20px) var(--space-5, 20px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4, 16px);
  background: var(--color-surface, #FFFFFF);
  border: 1px solid var(--color-line, #D5DAE3);
  border-radius: var(--radius-lg, 16px);
  box-shadow: var(--shadow-lg, 0 12px 40px rgba(15, 29, 58, 0.18));
}

.cc-banner__body {
  flex: 1 1 420px;
  min-width: 0;
}

.cc-banner .cc-actions {
  flex: 1 1 280px;
}

/* ---------------------------------------------------------------------------------------
 * Dialog ("Choose cookies"). Native <dialog> opened with showModal(); the --fallback class
 * covers old browsers without it.
 * --------------------------------------------------------------------------------------- */
.cc-dialog {
  box-sizing: border-box;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  overflow-y: auto;
  color: var(--color-ink, #0F1D3A);
  background: var(--color-surface, #FFFFFF);
  border: 1px solid var(--color-line, #D5DAE3);
  border-radius: var(--radius-lg, 16px);
  box-shadow: var(--shadow-lg, 0 12px 40px rgba(15, 29, 58, 0.18));
}

/* Browsers without <dialog> support would otherwise show the closed dialog inline. */
.cc-dialog:not([open]) {
  display: none;
}

.cc-dialog::backdrop {
  background: rgba(15, 29, 58, 0.55);
}

.cc-dialog--fallback {
  position: fixed;
  z-index: var(--z-consent-dialog, 1001);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 100vmax rgba(15, 29, 58, 0.55);
}

.cc-dialog__inner {
  position: relative;
  padding: var(--space-6, 24px);
}

.cc-dialog__title {
  margin: 0 calc(44px + var(--space-2, 8px)) var(--space-3, 12px) 0;
  font-family: var(--font-heading, inherit);
  font-size: var(--text-xl, 1.375rem);
  font-weight: 700;
  line-height: 1.25;
  color: var(--color-ink, #0F1D3A);
}

/* The title receives focus only so that screen readers start reading at the top of the
   dialog; it is not a control, so it shows no focus ring. */
.cc-dialog__title:focus {
  outline: none;
}

.cc-cats {
  margin: var(--space-4, 16px) 0;
  padding: 0;
  list-style: none;
}

.cc-cat {
  padding: var(--space-3, 12px) 0;
  border-top: 1px solid var(--color-line, #D5DAE3);
}

.cc-cat:last-child {
  border-bottom: 1px solid var(--color-line, #D5DAE3);
}

.cc-cat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3, 12px);
  min-height: 44px;
}

label.cc-cat__head {
  cursor: pointer;
}

.cc-cat__name {
  font-weight: 700;
}

.cc-cat__always {
  font-size: var(--text-sm, 0.9375rem);
  font-weight: 600;
  color: var(--color-ok, #136B4A);
}

.cc-cat__desc {
  margin: var(--space-1, 4px) 0 0;
  font-size: var(--text-sm, 0.9375rem);
  color: var(--color-ink-muted, #3D4A63);
}

/* A native checkbox, enlarged. Kept native on purpose: it works with every keyboard and
   screen reader without extra code. */
.cc-switch {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  margin: 10px;
  accent-color: var(--color-accent, #2F5BEA);
  cursor: pointer;
}

/* ---------------------------------------------------------------------------------------
 * Status line after a withdrawal ("reload to finish").
 * --------------------------------------------------------------------------------------- */
.cc-status__panel {
  position: fixed;
  z-index: var(--z-consent, 1000);
  left: var(--space-4, 16px);
  right: var(--space-4, 16px);
  bottom: var(--space-4, 16px);
  box-sizing: border-box;
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-4, 16px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3, 12px);
  background: var(--color-surface, #FFFFFF);
  border: 1px solid var(--color-line, #D5DAE3);
  border-radius: var(--radius-lg, 16px);
  box-shadow: var(--shadow-lg, 0 12px 40px rgba(15, 29, 58, 0.18));
}

.cc-status__panel .cc-text {
  flex: 1 1 280px;
  margin: 0;
}

.cc-status__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2, 8px);
}

/* ---------------------------------------------------------------------------------------
 * Small screens: buttons stack full width; the banner keeps a 16 px side gutter.
 * --------------------------------------------------------------------------------------- */
@media (max-width: 600px) {
  .cc-banner {
    left: var(--space-4, 16px);
    right: var(--space-4, 16px);
    bottom: var(--space-4, 16px);
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    padding: var(--space-4, 16px);
    padding-top: calc(44px + var(--space-2, 8px));
  }

  .cc-banner .cc-actions,
  .cc-dialog .cc-actions {
    flex-direction: column;
  }

  .cc-btn {
    width: 100%;
  }

  .cc-dialog__inner {
    padding: var(--space-4, 16px);
  }
}

/* A gentle entrance only for visitors who have not asked for reduced motion. */
@media (prefers-reduced-motion: no-preference) {
  .cc-banner:not([hidden]),
  .cc-status__panel:not([hidden]) {
    animation: cc-rise 0.25s ease-out;
  }

  @keyframes cc-rise {
    from {
      opacity: 0;
      transform: translateY(12px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
}

/* Windows high-contrast and forced-colours modes: keep borders visible. */
@media (forced-colors: active) {
  .cc-banner,
  .cc-dialog,
  .cc-status__panel,
  .cc-btn {
    border: 1px solid CanvasText;
  }
}

@media print {
  .cc-root {
    display: none !important;
  }
}

/* While the banner is open, a focused element scrolls clear of it instead of hiding under it (review A-04). */
html:has(.cc-banner:not([hidden])) {
  scroll-padding-bottom: 40vh;
}
