/* FitPal cookie consent: the glass bottom sheet built by analytics.js.
   It exists only when a tracking ID is configured. Non-blocking: no backdrop, the page stays usable.
   Layer 1 (data-layer="main"): accept / customise / continue without accepting.
   Layer 2 (data-layer="prefs"): per-category switches. Tokens only.
   Hooks for pages with their own fixed bottom bar: while the sheet is up, <html> has .consent-open and
   --consent-h (its height, set by analytics.js); --consent-gap below is its distance from the bottom. */

:root { --consent-gap: max(12px, env(safe-area-inset-bottom)); }

/* Contract guard: hidden consent controls stay hidden whatever display a page gives them. */
[data-consent-open][hidden],
[data-consent-status][hidden],
.consent[hidden],
.consent__panel[hidden] { display: none !important; }

.consent {
  --consent-pad: 1.25rem;
  position: fixed;
  z-index: calc(var(--z-overlay) + 5);
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: var(--consent-gap);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow: hidden;
  isolation: isolate;
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: var(--surface);
  background: var(--grad-surface), color-mix(in srgb, var(--surface) 95%, transparent);   /* legible even where blur is unavailable */
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  backdrop-filter: blur(24px) saturate(160%);
  box-shadow: var(--shadow-2), 0 0 0 1px color-mix(in srgb, var(--bg) 60%, transparent);
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1.55;
  opacity: 0;
  transform: translate3d(0, 28px, 0) scale(0.985);
  transform-origin: 50% 100%;
  transition:
    opacity var(--dur-3) var(--ease-out),
    transform var(--dur-3) var(--ease-out);
}
.consent:not(.is-visible) { pointer-events: none; }   /* no stray taps while it fades out */
.consent.is-visible { opacity: 1; transform: none; }

/* Touch screens: out of the way while the visitor types in a field (keyboard up), back on blur */
.consent.is-visible.is-aside {
  opacity: 0;
  transform: translate3d(0, 28px, 0) scale(0.985);
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity var(--dur-2) ease,
    transform var(--dur-2) ease,
    visibility 0s linear var(--dur-2);
}

/* Top sheen + ambient violet depth */
.consent::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line-3) 30%, var(--line-3) 70%, transparent);
  pointer-events: none;
}
.consent__glow {
  position: absolute;
  z-index: -1;
  top: -55%;
  left: -25%;
  width: 90%;
  height: 120%;
  background: var(--glow-violet);
  opacity: 0.32;
  pointer-events: none;
}

.consent__panel {
  position: relative;
  padding: var(--consent-pad);
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: consent-panel-in var(--dur-3) var(--ease-out);
}
@keyframes consent-panel-in {
  from { opacity: 0; transform: translate3d(0, 6px, 0); }
  to { opacity: 1; transform: none; }
}

/* ---------- Layer 1 ---------- */
.consent__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.875rem;
}
.consent__eyebrow { flex: none; }

/* "Continua senza accettare": deliberately quiet, still a full 44px target */
.consent__reject {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin: -12px -8px -12px 0;
  padding: 0 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text-3);
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.3;
  text-align: right;
  text-decoration: underline;
  text-decoration-color: var(--line-3);
  text-underline-offset: 3px;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--dur-2) ease, text-decoration-color var(--dur-2) ease;
}
.consent__reject:hover { color: var(--text-2); text-decoration-color: currentColor; }

.consent__title {
  color: var(--text);
  font-size: 1.0625rem;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.018em;
}
.consent__title:focus { outline: none; }
.consent__title:focus-visible { outline: 2px solid var(--volt); outline-offset: 4px; }

.consent__text {
  margin-top: 0.375rem;
  color: var(--text-2);
  font-size: 0.875rem;
  line-height: 1.55;
}
.consent__text a {
  color: var(--text);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: var(--line-3);
  text-underline-offset: 3px;
  transition: text-decoration-color var(--dur-2) ease;
}
.consent__text a:hover { text-decoration-color: var(--volt); }
.consent__dot { color: var(--text-4); }

.consent__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.125rem;
}
.consent__accept { --btn-h: 50px; flex: 1 1 auto; }

/* "Personalizza": a text link with a button's hit area */
.consent__link {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 0.875rem;
  border: 0;
  border-radius: var(--r-pill);
  background: none;
  color: var(--text-2);
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: var(--line-3);
  text-underline-offset: 4px;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--dur-2) ease, background-color var(--dur-2) ease;
}
.consent__link:hover { color: var(--text); background: color-mix(in srgb, var(--text) 5%, transparent); }

/* ---------- Layer 2 ---------- */
.consent__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: -0.5rem -0.625rem 0 0;
}
.consent__close {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: none;
  color: var(--text-2);
  transition: background-color var(--dur-2) ease, color var(--dur-2) ease, border-color var(--dur-2) ease;
}
.consent__close svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.consent__close:hover { color: var(--text); background: color-mix(in srgb, var(--text) 6%, transparent); border-color: var(--line); }

.consent .consent__cats {   /* beats base.css ul[role=list] { margin: 0 } */
  display: grid;
  gap: 0.5rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}
.consent-cat {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.875rem 0.875rem 0.875rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--text) 2.5%, transparent);
  transition: border-color var(--dur-2) ease, background-color var(--dur-2) ease;
}
.consent-cat:has(.consent-switch__input:checked) {
  border-color: color-mix(in srgb, var(--volt) 30%, transparent);
  background: var(--volt-tint);
}
.consent-cat__body {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: 0.125rem;
  cursor: pointer;
}
/* Locked row: "Always on" sits on the name line, the description gets the full width */
.consent-cat--locked {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 1rem;
  row-gap: 0.125rem;
  align-items: center;
}
.consent-cat--locked .consent-cat__body { display: contents; cursor: default; }
.consent-cat--locked .consent-cat__name { grid-column: 1; grid-row: 1; }
.consent-cat--locked .consent-cat__desc { grid-column: 1 / -1; grid-row: 2; }
.consent-cat--locked .consent-cat__always { grid-column: 2; grid-row: 1; }
.consent-cat__name { color: var(--text); font-size: 0.9375rem; font-weight: 600; letter-spacing: -0.01em; }
.consent-cat__desc { color: var(--text-3); font-size: 0.8125rem; line-height: 1.45; }
.consent-cat__tools,
.consent-cat__always {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: var(--tracking-mono);
  text-transform: uppercase;
  color: var(--text-3);
}
.consent-cat__tools { margin-top: 0.375rem; }
.consent-cat__always {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--text-2);
}
.consent-cat__always svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* Switch: a real checkbox (role="switch") laid over a drawn track */
.consent-switch {
  position: relative;
  flex: none;
  display: inline-grid;
  width: 48px;
  height: 28px;
}
.consent-switch__input {
  position: absolute;
  inset: -8px;
  z-index: 1;
  width: calc(100% + 16px);
  height: calc(100% + 16px);
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.consent-switch__track {
  position: relative;
  width: 100%;
  height: 100%;
  border: 1px solid var(--line-3);
  border-radius: var(--r-pill);
  background: var(--surface-3);
  transition: background-color var(--dur-2) ease, border-color var(--dur-2) ease, box-shadow var(--dur-3) var(--ease-out);
}
.consent-switch__track::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-2);
  box-shadow: 0 2px 6px color-mix(in srgb, var(--bg) 70%, transparent);
  transition: transform var(--dur-2) var(--ease-out), background-color var(--dur-2) ease;
}
.consent-switch__input:hover + .consent-switch__track { border-color: var(--text-3); }
.consent-switch__input:checked + .consent-switch__track {
  border-color: var(--volt);
  background: var(--volt);
  box-shadow: 0 0 18px -4px var(--volt-glow);
}
.consent-switch__input:checked + .consent-switch__track::before {
  transform: translateX(20px);
  background: var(--volt-ink);
}
.consent-switch__input:focus-visible + .consent-switch__track {
  outline: 2px solid var(--volt);
  outline-offset: 3px;
}

/* Layer 2 actions stay pinned to the bottom of the sheet when the list has to scroll (small phones) */
.consent__panel[data-consent-panel='prefs'] { padding-bottom: 0; }
.consent__actions--prefs {
  position: sticky;
  bottom: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  margin: 0.25rem calc(-1 * var(--consent-pad)) 0;
  padding: 0.75rem var(--consent-pad) var(--consent-pad);
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 0%, transparent), var(--surface) 0.875rem);
}
.consent__actions--prefs .btn { --btn-h: 50px; width: 100%; }

/* ---------- Larger screens: a floating card bottom-right, clear of hero copy and CTAs ---------- */
@media (min-width: 768px) {
  :root { --consent-gap: max(24px, env(safe-area-inset-bottom)); }
  .consent {
    --consent-pad: 1.5rem;
    left: auto;
    right: max(24px, env(safe-area-inset-right));
    width: 440px;
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
  }
  .consent__actions--prefs { grid-template-columns: 1fr 1fr; }
}

/* Quiz page, wide screens: the corner card would cover the right end of the 640px question column (the
   option marks, the inline Continue). From 1360px it fits in the right gutter instead, up to the usual
   440px: 24px from the edge and 24px clear of the column (16px at 1360-1375, so the card keeps 320px).
   In the narrower card Accept takes the row and the link wraps under it when both do not fit, and the
   preference buttons stack. */
@media (min-width: 1360px) and (min-height: 541px) {
  .page-quiz:not(:has(.qz[data-phase='result'])) .consent {
    width: min(440px, calc((100vw - 640px) / 2 - 24px - clamp(16px, (100vw - 1360px) / 2 + 16px, 24px)));
  }
  .page-quiz:not(:has(.qz[data-phase='result'])) .consent__actions { flex-wrap: wrap; justify-content: center; }
  .page-quiz:not(:has(.qz[data-phase='result'])) .consent__actions--prefs { grid-template-columns: 1fr; }
}
/* Quiz result (two columns from 768px): bottom right, the card sat on the sticky next-step card and its
   WhatsApp button. Bottom left it covers only the profile column, which scrolls clear of it (quiz.css). */
@media (min-width: 768px) and (min-height: 541px) {
  .page-quiz:has(.qz[data-phase='result']) .consent { left: max(24px, env(safe-area-inset-left)); right: auto; }
}

/* Short, wide viewports (phones in landscape): a full-width strip, copy left and actions right,
   so the sheet never climbs over the header */
@media (min-width: 768px) and (max-height: 540px) {
  :root { --consent-gap: max(12px, env(safe-area-inset-bottom)); }
  .consent {
    --consent-pad: 1.125rem;
    left: max(16px, env(safe-area-inset-left));
    right: max(16px, env(safe-area-inset-right));
    width: auto;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
  }
  .consent__panel[data-consent-panel='main'] {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 2rem;
    align-items: center;
  }
  .consent__panel[data-consent-panel='main'] > .consent__top { grid-column: 1 / -1; margin-bottom: 0.5rem; }
  .consent__panel[data-consent-panel='main'] > .consent__title,
  .consent__panel[data-consent-panel='main'] > .consent__text { grid-column: 1; }
  .consent__panel[data-consent-panel='main'] > .consent__actions {
    grid-column: 2;
    grid-row: 2 / span 2;
    flex-direction: column;
    align-items: stretch;
    margin-top: 0;
  }
  .consent .consent__cats { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 0.75rem; }
  .consent-cat { align-items: flex-start; }
  .consent__actions--prefs { grid-template-columns: repeat(2, minmax(0, 15rem)); justify-content: end; }
  .consent-cat--locked { align-content: start; }
}

/* Short phones (360×740, iPhone SE): a tighter sheet leaves more of the page, and of a docked button, in view */
@media (max-width: 767px) and (max-height: 760px) {
  .consent { --consent-pad: 1rem; }
  .consent__top { margin-bottom: 0.5rem; }
  .consent__title { font-size: 1rem; }
  .consent__text { font-size: 0.8125rem; line-height: 1.5; }
  .consent__panel[data-consent-panel='main'] > .consent__actions { margin-top: 0.875rem; }
  .consent__accept { --btn-h: 46px; }
  .consent__link { min-height: 46px; }
}

/* Very small phones: keep the sheet compact */
@media (max-width: 374px) {
  :root { --consent-gap: max(8px, env(safe-area-inset-bottom)); }
  .consent { --consent-pad: 1rem; left: 8px; right: 8px; }
  .consent__link { padding: 0 0.625rem; }
}

@media (prefers-reduced-motion: reduce) {
  .consent,
  .consent.is-visible { transform: none; }
  .consent__panel { animation: none; }
}

@media print {
  .consent { display: none !important; }
}
