/**
 * Cookie notice + cookie settings dialog (Harbor, Batch 5B; compliance audit
 * 2026-11-18 CON-1/CON-2/CON-5/A11Y-1). Only strictly necessary storage is
 * used, so the banner is a notice ("Got it" + "Details"). When the optional
 * analytics beacon is built in, "Allow analytics" and "Essential only" are
 * two equal-size choices, nothing pre-ticked; settings stay reachable from
 * the footer at any time.
 *
 * Load order: this sheet loads after ds/shell.css (base.njk) and owns every
 * cookie rule; the older Aurora/shell cookie rules were removed in Phase 5B.
 * The `body #cookieConsent` / `body #cookieSettingsModal` prefixes stay so the
 * banner keeps beating the generic ds `.btn*` / `.modal*` re-skins.
 *
 * Phones (<768): bottom sheet. Signed-in app pages: it sits on top of the tab
 * bar (`bottom` below). The AccessCore button floats in the bottom
 * inline-start corner, so the last row of the sheet keeps that corner free.
 * 768+: a floating card in the bottom inline-end corner (AccessCore lives in
 * the rail/sidebar zone or the inline-start corner).
 */

/* ---------------------------------------------------------------------------
   Banner
   --------------------------------------------------------------------------- */
.cookie-consent {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: var(--af-z-consent); /* above the tab bar, below AccessCore */
}

body #cookieConsent {
  inset-inline: 0;
  margin: 0;
  padding: var(--af-sp-4) var(--af-sp-4) calc(var(--af-sp-4) + var(--af-safe-bottom));
  background: var(--af-surface-elev);
  color: var(--af-ink);
  border: 1px solid var(--af-border);
  border-block-end: 0;
  border-radius: var(--af-r-xl) var(--af-r-xl) 0 0;
  box-shadow: var(--af-shadow-3);
  font-family: var(--af-font-body);
  max-height: calc(100dvh - var(--af-appbar-h) - var(--af-safe-top) - var(--af-sp-4));
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: afCookieIn var(--af-dur-slow) var(--af-ease) both;
}
/* JS shows it with style.display = 'flex'. */
body #cookieConsent[style*="flex"] { display: block !important; }
/* State switches (GPC note, analytics offer, Got it) use [hidden]; the
   .btn rules below set display, so hidden must win explicitly. */
body #cookieConsent [hidden],
body #cookieSettingsModal [hidden] { display: none !important; }

/* A11Y-1 / WCAG 2.4.11 (same approach as the tab bar, ds/shell.css): while
   the banner is shown, cookie-consent.js sets --af-consent-clear to the
   distance from the viewport bottom to the banner's top edge (tab bar
   included when it sits on it). Root scroll padding keeps a focused control
   scrolled clear of it; the page padding lets the last controls (footer)
   scroll above it. Selectors match the shell rules' specificity and win on
   order (this sheet loads after ds/shell.css). nav.js has a focusin
   fallback for browsers that ignore scroll-padding on focus. */
html[data-cookie-banner],
html[data-shell][data-cookie-banner]:has(> body) {
  scroll-padding-block-end: calc(var(--af-consent-clear, 0px) + var(--af-sp-2));
}
html[data-cookie-banner] body,
html[data-shell][data-cookie-banner] body[data-authenticated] {
  padding-block-end: var(--af-consent-clear, 0px);
}

@keyframes afCookieIn {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  body #cookieConsent { animation: none; }
}

body #cookieConsent .cookie-consent-content {
  display: flex;
  flex-direction: column;
  gap: var(--af-sp-3);
  max-width: none;
  margin: 0;
  text-align: start;
}
body #cookieConsent .cookie-consent-text { flex: none; min-width: 0; }
body #cookieConsent .cookie-consent-title {
  margin: 0 0 var(--af-sp-1);
  font-family: var(--af-font-display);
  font-size: var(--af-fs-lg);
  font-weight: 600;
  line-height: 1.3;
  color: var(--af-ink);
}
body #cookieConsent .cookie-consent-desc {
  margin: 0;
  font-size: var(--af-fs-sm);
  line-height: 1.5;
  color: var(--af-ink-soft);
}
body #cookieConsent .cookie-learn-more {
  color: var(--af-primary-text);
  font-size: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}
body #cookieConsent .cookie-learn-more:hover { color: var(--af-ink); }
body #cookieConsent .cookie-learn-more:focus-visible { outline: 2px solid var(--af-focus); outline-offset: 2px; border-radius: var(--af-r-xs); }
/* GPC / DNT honoured: a quiet note under the text (banner and dialog). */
body #cookieConsent .cookie-consent-signal,
body #cookieSettingsModal .cookie-consent-signal {
  margin: var(--af-sp-2) 0 0;
  padding: var(--af-sp-2) var(--af-sp-3);
  border-radius: var(--af-r-md);
  background: var(--af-primary-soft);
  color: var(--af-ink);
  font-size: var(--af-fs-sm);
  line-height: 1.5;
}
body #cookieSettingsModal .cookie-consent-signal { margin: 0 0 var(--af-sp-4); }

/* Allow analytics + Essential only (only when the optional beacon exists):
   same size, same row (equal prominence). Otherwise one "Got it" across the
   row. Details: a quieter choice on its own row at the inline end, clear of
   the AccessCore corner. Always visible, 320px included. */
body #cookieConsent .cookie-consent-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--af-sp-2);
  width: 100%;
  flex: none;
}
body #cookieConsent .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--af-control-h);
  padding: var(--af-sp-2) var(--af-sp-3);
  border-radius: var(--af-r-md);
  font-family: inherit;
  font-size: var(--af-fs-md);
  font-weight: 600;
  line-height: 1.2;
  white-space: normal;
  text-align: center;
  cursor: pointer;
  box-shadow: none;
  transition: background var(--af-dur-fast) var(--af-ease), border-color var(--af-dur-fast) var(--af-ease);
}
body #cookieConsent .btn:focus-visible { outline: 2px solid var(--af-focus); outline-offset: 2px; }
body #cookieConsent .btn-primary { background: var(--af-primary); color: var(--af-on-primary); border: 1px solid var(--af-primary); }
body #cookieConsent .btn-primary:hover { background: var(--af-primary-hover); border-color: var(--af-primary-hover); }
body #cookieConsent .btn-secondary { background: var(--af-surface); color: var(--af-primary-text); border: 1px solid var(--af-primary); }
body #cookieConsent .btn-secondary:hover { background: var(--af-primary-soft); }
body #cookieConsent .cookie-ack { grid-column: 1 / -1; }
body #cookieConsent .cookie-customize {
  grid-column: 1 / -1;
  justify-self: end;
  width: auto;
  min-height: var(--af-target-min);
  margin-inline-start: calc(var(--af-ac-size) + var(--af-sp-4));
  padding-inline: var(--af-sp-3);
  background: transparent;
  color: var(--af-primary-text);
  border: 1px solid transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
}
body #cookieConsent .cookie-customize:hover { background: var(--af-primary-soft); }

/* Phones: the customize row above keeps the AccessCore corner free. */
@media (max-width: 767.98px) {
  /* Signed-in app pages: the sheet sits on the tab bar, no safe-area gap. */
  html[data-shell="app"] body[data-authenticated="true"] .cookie-consent { bottom: calc(var(--af-tabbar-h) + var(--af-safe-bottom)); }
  html[data-shell="app"] body[data-authenticated="true"] #cookieConsent {
    padding-block-end: var(--af-sp-3);
    max-height: calc(100dvh - var(--af-appbar-h) - var(--af-safe-top) - var(--af-tabbar-h) - var(--af-safe-bottom) - var(--af-sp-4));
  }
}

/* 768+: floating card at the bottom inline-end corner. */
@media (min-width: 768px) {
  body #cookieConsent {
    inset-inline-start: auto;
    inset-inline-end: var(--af-sp-5);
    bottom: var(--af-sp-5);
    width: min(440px, calc(100vw - 2 * var(--af-sp-5)));
    padding: var(--af-sp-5);
    border: 1px solid var(--af-border);
    border-radius: var(--af-r-xl);
  }
  body #cookieConsent .btn { font-size: var(--af-fs-sm); min-height: var(--af-target-min); }
}

/* Landscape phones (short viewports, e.g. 667x375, 844x390): the portrait
   sheet / 440px card covered half the screen or more (Q1-04). Compact bar
   across the bottom: title and text run inline beside one row of the three
   equal choices; the inline-start corner stays free for the AccessCore
   button. Nothing is hidden or truncated. */
@media (orientation: landscape) and (max-height: 500px) {
  body #cookieConsent {
    inset-inline: 0;
    width: auto;
    padding: var(--af-sp-2) var(--af-sp-4) calc(var(--af-sp-2) + var(--af-safe-bottom));
    padding-inline-start: calc(var(--af-ac-size) + 16px + var(--af-sp-3));
    border-inline: 0;
    border-radius: var(--af-r-lg) var(--af-r-lg) 0 0;
  }
  body #cookieConsent .cookie-consent-content { flex-direction: row; align-items: center; gap: var(--af-sp-3); }
  body #cookieConsent .cookie-consent-text { flex: 1 1 auto; }
  body #cookieConsent .cookie-consent-title { display: inline; margin: 0; margin-inline-end: var(--af-sp-1); font-size: var(--af-fs-sm); }
  body #cookieConsent .cookie-consent-desc { display: inline; font-size: var(--af-fs-xs); line-height: 1.45; }
  body #cookieConsent .cookie-consent-actions { display: flex; width: auto; gap: var(--af-sp-2); }
  body #cookieConsent .btn { width: auto; min-height: var(--af-target-min); padding-inline: var(--af-sp-3); font-size: var(--af-fs-sm); white-space: nowrap; }
  body #cookieConsent .cookie-customize { margin-inline-start: 0; }
}
/* 768+ landscape has no tab bar: undo the floating card's bottom offset
   (below 768 `.cookie-consent` keeps sitting on the tab bar when signed in). */
@media (orientation: landscape) and (max-height: 500px) and (min-width: 768px) {
  body #cookieConsent { bottom: 0; }
}

/* ---------------------------------------------------------------------------
   Settings dialog (ds .modal gives the sheet / centred dialog frame)
   --------------------------------------------------------------------------- */
.cookie-settings-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
body #cookieSettingsModal { background: var(--af-scrim); z-index: var(--af-z-consent); }
body #cookieSettingsModal .modal-content {
  display: flex;
  flex-direction: column;
  width: min(560px, calc(100vw - 2 * var(--af-sp-4)));
  max-width: 560px;
  padding: 0;
  overflow: hidden;
  background: var(--af-surface-elev);
  color: var(--af-ink);
}
body #cookieSettingsModal .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--af-sp-2);
  flex: none;
  padding: var(--af-sp-2) var(--af-sp-2) var(--af-sp-2) var(--af-sp-5);
  padding-inline: var(--af-sp-5) var(--af-sp-2);
  border-block-end: 1px solid var(--af-border);
  background: var(--af-surface-elev);
}
body #cookieSettingsModal .modal-header h2 {
  margin: 0;
  font-family: var(--af-font-display);
  font-size: var(--af-fs-xl);
  font-weight: 600;
  color: var(--af-ink);
}
body #cookieSettingsModal .modal-close { color: var(--af-ink-soft); }
body #cookieSettingsModal .modal-close:focus-visible { outline: 2px solid var(--af-focus); outline-offset: -2px; }
body #cookieSettingsModal .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--af-sp-4) var(--af-sp-5);
}
body #cookieSettingsModal .cookie-settings-intro {
  margin: 0 0 var(--af-sp-4);
  font-size: var(--af-fs-sm);
  line-height: 1.5;
  color: var(--af-ink-soft);
}

/* One category: a row (title + switch, the whole row is the label) and a
   description under it. */
body #cookieSettingsModal .cookie-category {
  margin: 0;
  padding: var(--af-sp-2) 0 var(--af-sp-4);
  background: none;
  border: 0;
  border-block-end: 1px solid var(--af-border);
  border-radius: 0;
}
body #cookieSettingsModal .cookie-category:last-child { border-block-end: 0; padding-block-end: 0; }
body #cookieSettingsModal .cookie-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--af-sp-3);
  min-height: var(--af-target-min);
  margin: 0;
  cursor: pointer;
  font-size: inherit;
  font-weight: inherit;
}
body #cookieSettingsModal .cookie-category-header:has(input:disabled) { cursor: default; }
body #cookieSettingsModal .cookie-category-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--af-sp-2);
  flex: 1 1 auto;
  min-width: 0;
}
body #cookieSettingsModal .cookie-category-title {
  margin: 0;
  font-family: inherit;
  line-height: 1.4;
  font-size: var(--af-fs-md);
  font-weight: 600;
  color: var(--af-ink);
}
body #cookieSettingsModal .cookie-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 var(--af-sp-2);
  border-radius: var(--af-r-pill);
  font-size: var(--af-fs-xs);
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}
body #cookieSettingsModal .cookie-badge.required { background: var(--af-primary-soft); color: var(--af-primary-text); }
body #cookieSettingsModal .cookie-category-desc {
  margin: var(--af-sp-1) 0 0;
  padding: 0;
  padding-inline-end: calc(52px + var(--af-sp-3));
  font-size: var(--af-fs-sm);
  line-height: 1.5;
  color: var(--af-ink-soft);
}

/* Switch: 52x44 hit area (the whole row is clickable too), 44x24 track. */
body #cookieSettingsModal .cookie-toggle {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 52px;
  height: var(--af-target-min);
}
body #cookieSettingsModal .cookie-toggle input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: inherit;
  z-index: 1;
}
body #cookieSettingsModal .cookie-toggle-slider {
  position: relative;
  inset: auto;
  display: block;
  width: 44px;
  height: 24px;
  border-radius: var(--af-r-pill);
  background: var(--af-border-strong);
  opacity: 1;
  transition: background var(--af-dur-fast) var(--af-ease);
}
body #cookieSettingsModal .cookie-toggle-slider::before {
  content: "";
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  right: auto;
  left: auto;
  bottom: auto;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--af-stone-0);
  box-shadow: var(--af-shadow-1);
  transform: none;
  transition: inset-inline-start var(--af-dur-fast) var(--af-ease);
}
[dir="rtl"] body #cookieSettingsModal .cookie-toggle-slider::before { right: 3px; }
[dir="ltr"] body #cookieSettingsModal .cookie-toggle-slider::before { left: 3px; }
body #cookieSettingsModal .cookie-toggle input:checked + .cookie-toggle-slider { background: var(--af-primary); }
[dir="rtl"] body #cookieSettingsModal .cookie-toggle input:checked + .cookie-toggle-slider::before { right: 23px; transform: none; }
[dir="ltr"] body #cookieSettingsModal .cookie-toggle input:checked + .cookie-toggle-slider::before { left: 23px; transform: none; }
body #cookieSettingsModal .cookie-toggle input:disabled + .cookie-toggle-slider { background: var(--af-primary); opacity: .55; cursor: default; }
body #cookieSettingsModal .cookie-toggle input:focus-visible + .cookie-toggle-slider { outline: 2px solid var(--af-focus); outline-offset: 3px; box-shadow: none; }
@media (prefers-reduced-motion: reduce) {
  body #cookieSettingsModal .cookie-toggle-slider, body #cookieSettingsModal .cookie-toggle-slider::before { transition: none; }
}

body #cookieSettingsModal .modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--af-sp-3);
  flex: none;
  padding: var(--af-sp-3) var(--af-sp-5);
  border-block-start: 1px solid var(--af-border);
  background: var(--af-surface-elev);
}
body #cookieSettingsModal .modal-footer .btn {
  min-height: var(--af-control-h);
  padding: 0 var(--af-sp-5);
  border-radius: var(--af-r-md);
  font-size: var(--af-fs-md);
  font-weight: 600;
}
body #cookieSettingsModal .modal-footer .btn-primary { background: var(--af-primary); color: var(--af-on-primary); border: 1px solid var(--af-primary); }
body #cookieSettingsModal .modal-footer .btn-primary:hover { background: var(--af-primary-hover); }

@media (max-width: 767.98px) {
  body #cookieSettingsModal .modal-content {
    width: 100%;
    max-height: calc(100dvh - var(--af-safe-top) - 24px);
    overflow: hidden;
  }
  body #cookieSettingsModal .modal-header { padding-inline-start: var(--af-sp-4); }
  body #cookieSettingsModal .modal-body { padding-inline: var(--af-sp-4); }
  /* AccessCore sits in the bottom inline-start corner while a sheet is open. */
  body #cookieSettingsModal .modal-footer {
    padding: var(--af-sp-3) var(--af-sp-4) calc(var(--af-sp-3) + var(--af-safe-bottom));
    padding-inline-start: calc(var(--af-ac-size) + 16px + var(--af-sp-4));
  }
  body #cookieSettingsModal .modal-footer .btn { flex: 1 1 auto; }
}
