/**
 * Cookie Settings dialog — wireframe section 3.
 *
 * Desktop/tablet: a centred modal with a left category rail.
 * Mobile: a full-screen sheet with a sticky Save action.
 *
 * Colours are tokens throughout. The consent BAR carries literal
 * fallbacks because it must survive its stylesheet not arriving; this
 * dialog cannot be opened without its script, and the script cannot run
 * before the page has loaded its CSS, so the same defensiveness would
 * buy nothing here.
 */

.jdev-cd[hidden] {
  display: none;
}

.jdev-cd {
  position: fixed;
  inset: 0;
  z-index: var(--z-dialog);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.jdev-cd__scrim {
  position: absolute;
  inset: 0;
  background: rgba(20, 21, 43, 0.55);
}

/* Scroll is locked on the page behind, not on the dialog: a modal that
   scrolls the document underneath loses the reader's place. */
body.jdev-cd-open {
  overflow: hidden;
}

.jdev-cd__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  max-height: min(86vh, 720px);
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.jdev-cd__panel:focus {
  /* Focused programmatically on open so the trap has an anchor. The
     ring belongs on controls the member operates, not on the region
     they were moved into. */
  outline: none;
}

/* ---- Head --------------------------------------------------------- */

.jdev-cd__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border);
}

.jdev-cd__title {
  flex: 1 1 auto;
  margin: 0;
  font-family: var(--font-heading);
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  color: var(--color-ink);
}

.jdev-cd__back,
.jdev-cd__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-neutral);
  cursor: pointer;
}

.jdev-cd__back:hover,
.jdev-cd__close:hover {
  background: var(--color-surface);
  color: var(--color-ink);
}

.jdev-cd__back:focus-visible,
.jdev-cd__close:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* The back chevron is a right-chevron rotated, and it only belongs on
   the mobile sheet — on desktop this is a dialog, not a screen. */
.jdev-cd__back {
  display: none;
  transform: rotate(180deg);
}

/* ---- Body: rail + content ----------------------------------------- */

.jdev-cd__body {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
}

.jdev-cd__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-4) var(--space-3);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
}

.jdev-cd__nav-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  font: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  color: var(--color-ink-soft);
  cursor: pointer;
}

.jdev-cd__nav-item:hover {
  background: var(--color-surface);
  color: var(--color-ink);
}

.jdev-cd__nav-item.is-active {
  background: var(--color-surface);
  color: var(--color-primary-text);
  font-weight: var(--fw-semibold);
}

.jdev-cd__nav-item:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

.jdev-cd__nav-note {
  font-size: var(--fs-xs);
  font-weight: var(--fw-regular);
  color: var(--color-neutral);
}

.jdev-cd__content {
  padding: var(--space-5) var(--space-6);
  overflow-y: auto;
  min-height: 0;
}

.jdev-cd__section-title {
  margin: 0 0 var(--space-2);
  font-family: var(--font-heading);
  font-size: var(--fs-base);
  font-weight: var(--fw-bold);
  color: var(--color-ink);
}

.jdev-cd__section-text {
  margin: 0 0 var(--space-4);
  font-size: var(--fs-sm);
  line-height: var(--lh-normal);
  color: var(--color-ink-soft);
}

/* Only the selected panel shows once the rail exists. Below 768px the
   rail is gone and every panel is stacked, so this rule simply does not
   apply there — which is why it is a class and not [hidden]. */
@media (min-width: 768px) {
  .jdev-cd__panel-section--inactive {
    display: none;
  }
}

/* ---- Category rows ------------------------------------------------- */

.jdev-cd__rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.jdev-cd__row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-white);
}

.jdev-cd__row--locked {
  background: var(--color-surface);
}

.jdev-cd__row-icon {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--color-neutral);
}

.jdev-cd__row-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
}

.jdev-cd__row-label {
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  color: var(--color-ink);
}

.jdev-cd__row-blurb {
  font-size: var(--fs-xs);
  line-height: 1.5;
  color: var(--color-neutral);
}

/* Essential: words plus a lock, never a disabled switch. A greyed-out
   toggle sitting in the off position says the opposite of the truth. */
.jdev-cd__row-always {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--color-neutral);
  white-space: nowrap;
}

.jdev-cd__row-control {
  flex-shrink: 0;
}

/* ---- Switch --------------------------------------------------------
   A real checkbox, visually hidden but still the thing that is focused,
   toggled and announced. The track and thumb are decoration painted
   from its :checked state — so the picture cannot disagree with the
   control, which is the failure mode of every div-based switch. */

.jdev-cd__switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  /* 44px tall hit area even though the track is 24px. */
  min-width: 44px;
  min-height: 44px;
  justify-content: center;
  cursor: pointer;
}

.jdev-cd__switch-input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.jdev-cd__switch-track {
  display: block;
  width: 44px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--color-neutral);
  transition: background var(--transition-fast);
}

.jdev-cd__switch-thumb {
  display: block;
  width: 18px;
  height: 18px;
  margin: 3px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}

.jdev-cd__switch-input:checked ~ .jdev-cd__switch-track {
  background: var(--color-positive);
}

.jdev-cd__switch-input:checked ~ .jdev-cd__switch-track .jdev-cd__switch-thumb {
  transform: translateX(20px);
}

.jdev-cd__switch-input:focus-visible ~ .jdev-cd__switch-track {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* §25: do not communicate state by colour alone. The thumb position is
   the second channel, and it survives both colour-blindness and forced
   colours — where the green would be repainted anyway. */
@media (forced-colors: active) {
  .jdev-cd__switch-track {
    border: 1px solid CanvasText;
  }

  .jdev-cd__switch-input:checked ~ .jdev-cd__switch-track {
    background: Highlight;
  }
}

/* ---- Category detail ----------------------------------------------- */

.jdev-cd__detail {
  margin-top: var(--space-4);
}

.jdev-cd__detail-title {
  margin: 0 0 var(--space-1);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-neutral);
}

.jdev-cd__detail-text {
  margin: 0;
  font-size: var(--fs-2xs);
  line-height: var(--lh-normal);
  color: var(--color-ink-soft);
}

.jdev-cd__detail-list {
  margin: 0;
  padding-left: var(--space-5);
  list-style: disc;
  font-size: var(--fs-2xs);
  line-height: var(--lh-normal);
  color: var(--color-ink-soft);
}

.jdev-cd__detail-list li + li {
  margin-top: var(--space-1);
}

.jdev-cd__absent {
  margin-top: var(--space-5);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.jdev-cd__absent-title {
  margin: 0 0 var(--space-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-neutral);
}

.jdev-cd__absent-text {
  margin: 0;
  font-size: var(--fs-2xs);
  line-height: var(--lh-normal);
  color: var(--color-ink-soft);
}

.jdev-cd__absent-text + .jdev-cd__absent-text {
  margin-top: var(--space-2);
}

/* ---- Status -------------------------------------------------------- */

.jdev-cd__status:empty {
  display: none;
}

.jdev-cd__status {
  margin: 0;
  padding: var(--space-3) var(--space-6);
  border-top: 1px solid var(--color-border);
  background: var(--color-positive-soft);
  color: var(--color-positive);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
}

/* ---- Foot ---------------------------------------------------------- */

.jdev-cd__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

.jdev-cd__policy {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
  color: var(--color-primary-text);
  text-decoration: none;
}

.jdev-cd__policy:hover {
  text-decoration: underline;
}

.jdev-cd__foot-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.jdev-cd__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font: inherit;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  cursor: pointer;
}

.jdev-cd__btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.jdev-cd__btn--ghost {
  background: var(--color-white);
  border-color: var(--color-border-control);
  color: var(--color-ink);
}

.jdev-cd__btn--ghost:hover {
  background: var(--color-surface);
}

.jdev-cd__btn--save {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-white);
}

.jdev-cd__btn--save:hover {
  background: var(--color-primary-deep);
  border-color: var(--color-primary-deep);
}

.jdev-cd__btn[disabled] {
  opacity: 0.6;
  cursor: wait;
}

/* ---- Tablet: rail collapses, panels stack -------------------------- */

@media (max-width: 900px) {
  .jdev-cd__body {
    grid-template-columns: 160px minmax(0, 1fr);
  }

  .jdev-cd__content {
    padding: var(--space-4) var(--space-5);
  }
}

/* ---- Mobile: full-screen sheet -------------------------------------
   The wireframe draws a sheet with a back control, a scrolling body and
   Save pinned to the bottom. The rail goes away entirely and every
   panel is shown at once, which is why each keeps its own heading. */

@media (max-width: 767px) {
  .jdev-cd {
    padding: 0;
    align-items: stretch;
  }

  .jdev-cd__panel {
    max-width: none;
    max-height: none;
    height: 100%;
    border: 0;
    border-radius: 0;
    /* Installed PWAs: clear the home indicator and the notch. */
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .jdev-cd__head {
    padding: var(--space-4);
  }

  .jdev-cd__back {
    display: inline-flex;
  }

  .jdev-cd__title {
    text-align: center;
  }

  .jdev-cd__body {
    display: block;
    overflow-y: auto;
  }

  .jdev-cd__nav {
    display: none;
  }

  .jdev-cd__content {
    padding: var(--space-4);
  }

  .jdev-cd__panel-section + .jdev-cd__panel-section {
    margin-top: var(--space-6);
    padding-top: var(--space-5);
    border-top: 1px solid var(--color-border);
  }

  /* §10: sticky Save, and do not bury it under a long page. */
  .jdev-cd__foot {
    position: sticky;
    bottom: 0;
    flex-direction: column-reverse;
    align-items: stretch;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
  }

  .jdev-cd__foot-actions {
    flex-direction: column-reverse;
    align-items: stretch;
    margin-left: 0;
  }

  .jdev-cd__btn {
    width: 100%;
    height: 48px;
  }

  .jdev-cd__policy {
    justify-content: center;
    padding-top: var(--space-1);
  }

  .jdev-cd__status {
    padding: var(--space-3) var(--space-4);
  }
}

/* Short viewports — a landscape phone, or a desktop zoomed to 200%.
   Sticking the footer there would leave almost nothing to read. */
@media (max-height: 560px) {
  .jdev-cd__foot {
    position: static;
  }
}

@media (prefers-reduced-motion: reduce) {
  .jdev-cd__switch-track,
  .jdev-cd__switch-thumb {
    transition: none;
  }
}
