/*
 * Consent banner and cookie-settings dialog in the house identity.
 * Tokens only: load after the identity's fonts, tokens, base.css and type.css.
 * Text styling comes from the type roles on the markup (.t-h4, .t-body, .t-ui,
 * .t-small, .t-num); this file sets layout, surfaces and control states.
 * Accept and Reject are the same quiet button on purpose: neither is favoured.
 * Nothing here animates an entrance; the only motion is the button response,
 * which base.css removes under prefers-reduced-motion.
 */

/* ── Banner: first in the document, pinned to the foot, never modal ────── */

.consent-banner {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: var(--space-5) var(--space-7);
  padding: var(--space-5) var(--gutter);
  background: var(--paper-raised);
  border-top: var(--border-strong);
  max-height: 80vh;
  overflow-y: auto;
}

.consent-banner[hidden] {
  display: none;
}

.consent-banner__text {
  display: grid;
  gap: var(--space-2);
}

/* While the banner is up, the page keeps its last lines and any focused
   element clear of it. The module writes --consent-banner-height. */
html.consent-pending {
  scroll-padding-bottom: var(--consent-banner-height, 0);
}

html.consent-pending body {
  padding-bottom: var(--consent-banner-height, 0);
}

/* ── Actions: one button component, one size, for every choice ─────────── */

/* Equal columns, so every choice is the same width as well as the same style. */
.consent-actions {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: var(--space-3);
}

.consent-button {
  min-height: calc(var(--space-6) + var(--space-2));
  padding: var(--space-3) var(--space-5);
  border: var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--edge);
  background: var(--paper-raised);
  cursor: pointer;
  transition:
    transform var(--dur-quick) var(--ease),
    box-shadow var(--dur-quick) var(--ease),
    background-color var(--dur-quick) var(--ease);
}

.consent-button:hover {
  transform: translateY(-1px);
  box-shadow: var(--edge-hover);
  background: var(--paper-2);
}

.consent-button:active {
  transform: translateY(2px);
  box-shadow: none;
}

.consent-button:disabled {
  color: var(--ash);
  border: var(--border);
  box-shadow: none;
  background: var(--paper);
  cursor: not-allowed;
  transform: none;
}

.consent-button:focus-visible,
.consent-text-button:focus-visible,
.consent-check:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

/* A quiet text control for the two secondary actions in the dialog. */
.consent-text-button {
  min-height: calc(var(--space-6) + var(--space-2));
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  cursor: pointer;
}

.consent-text-button:hover {
  color: var(--accent-soft);
  text-decoration-thickness: 2px;
}

.consent-text-button:disabled {
  color: var(--ash);
  text-decoration: none;
  cursor: not-allowed;
}

/* ── Dialog: a native modal; the one place the popover shadow is allowed ── */

.consent-dialog {
  width: min(100% - 2 * var(--space-4), var(--measure));
  max-height: calc(100% - 2 * var(--space-4));
  padding: 0;
  border: var(--border-strong);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-float);
  overflow-y: auto;
}

.consent-dialog::backdrop {
  background: var(--rule-strong);
}

/* Where showModal() is missing the module opens the dialog in place. */
.consent-dialog[role='dialog'][open] {
  position: fixed;
  inset: 0;
  z-index: 20;
  margin: auto;
  height: fit-content;
}

.consent-dialog__body {
  display: grid;
  gap: var(--space-5);
  margin: 0;
  padding: var(--space-6);
}

.consent-dialog__body > h2:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.consent-dialog__foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2) var(--space-5);
  border-top: var(--border);
  padding-top: var(--space-3);
}

/* ── Category rows: a native checkbox with a visible label, no switch ──── */

.consent-categories {
  border-bottom: var(--border);
}

.consent-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: var(--space-1) var(--space-3);
  padding: var(--space-3) 0;
  border-top: var(--border);
}

.consent-check {
  width: var(--space-5);
  height: var(--space-5);
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.consent-check:disabled {
  cursor: not-allowed;
}

.consent-row__label {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-height: calc(var(--space-6) + var(--space-2));
  cursor: pointer;
}

.consent-check:disabled + .consent-row__label {
  cursor: default;
}

.consent-row__description {
  grid-column: 2;
  max-width: var(--measure-narrow);
}

/* "Always on": the identity's chip, a hairline rectangle; the label voice
   comes from the .t-overline role on the markup. */
.consent-chip {
  padding: var(--space-1) var(--space-2);
  border: var(--border);
  border-radius: var(--radius);
}

/* ── Gated embeds and their stand-in text ──────────────────────────────── */

iframe[data-consent]:not([src]) {
  display: none;
}

.consent-placeholder {
  padding: var(--space-5);
  border: var(--border);
  border-radius: var(--radius);
  background: var(--paper-2);
}

.consent-placeholder[hidden] {
  display: none;
}

/* ── Status line for screen readers ────────────────────────────────────── */

.consent-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ── Narrow: text first, then the three equal buttons in one row ───────── */

@media (max-width: 56rem) {
  .consent-banner {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
  }
}

@media (max-width: 36rem) {
  .consent-banner {
    gap: var(--space-4);
    padding-block: var(--space-4);
  }

  /* Reject and Accept share the first row in equal halves; the third action sits below. */
  .consent-actions {
    grid-auto-flow: row;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .consent-actions > :nth-child(3) {
    grid-column: 1 / -1;
  }

  .consent-button {
    padding-inline: var(--space-3);
  }

  .consent-dialog__body {
    padding: var(--space-5);
  }
}

@media print {
  .consent-banner,
  .consent-dialog {
    display: none;
  }
}
