/* The cookie consent (app/views/layouts/_cookie_consent.html.erb): the banner of a visitor who has not decided yet and
   the dialog of the settings. Linked EXPLICITLY in layouts/_head, so it reaches both layouts, like toast.css. Both lie
   outside any .kl wrapper: the colours, typefaces and radii come from tokens.css, which declares them on .kl__consent
   too, and the buttons are kl.css's .kl__btn (plain classes, linked in both layouts as well). Every element sets its
   own margins: above a React application the application's resets reach this markup too. Only the z-index is this
   sheet's own — a token of the mechanism, not of the brand. */
:root {
  /* above the public navbar over the SPAs (1001) and the applications' layers; below the toasts (1200) */
  --consent-z: 1100;
}

.kl__consent {
  font-family: var(--font-sans);
  font-weight: 400;
  line-height: 1.55;
  color: var(--ink);
}

.kl__consent *,
.kl__consent *::before,
.kl__consent *::after {
  box-sizing: border-box;
}

.kl__consent :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ——— Banner ——— */

/* Shown only while the engine marks the document „pending” (app/javascript/consent.js): never for a visitor who has
   decided, never without JavaScript. Fixed, so it moves nothing on the page. */
.kl__consent-banner {
  display: none;
}

html[data-consent="pending"] .kl__consent-banner {
  display: block;
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 16px;
  z-index: var(--consent-z);
}

.kl__consent-banner-in {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 20px 24px;
  background: rgb(255 255 255 / .94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid color-mix(in srgb, var(--accent) 14%, transparent);
  border-radius: var(--radius-card);
  box-shadow: 0 24px 48px -24px color-mix(in srgb, var(--accent) 55%, transparent);
}

.kl__consent-title {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--ink);
}

.kl__consent-lead {
  margin: 0;
  font-size: .875rem;
  color: var(--ink-soft);
}

.kl__consent-actions {
  flex: none;
  display: flex;
  gap: 10px;
}

/* The link and the button inside the banner's text: the garnet text link of the site (kl.css .kl__link). */
.kl__consent-link,
.kl__consent-inline {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent-pale);
  text-underline-offset: 3px;
  transition: color .18s ease, text-decoration-color .18s ease;
}

.kl__consent-inline {
  display: inline;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
}

.kl__consent-link:hover,
.kl__consent-inline:hover {
  color: var(--accent-dark);
  text-decoration-color: currentColor;
}

/* ——— Settings dialog ——— */

/* A modal <dialog> in the top layer: centred explicitly (a reset of an application may zero the UA's margin). */
.kl__consent-dialog {
  position: fixed;
  inset: 0;
  width: min(560px, calc(100vw - 32px));
  height: fit-content;
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 28px;
  overflow-y: auto;
  border: 0;
  border-radius: var(--radius-card);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 30px 60px -30px color-mix(in srgb, var(--accent) 60%, transparent);
}

.kl__consent-dialog::backdrop {
  background: rgb(27 20 36 / .45);
}

html:has(.kl__consent-dialog[open]) {
  overflow: hidden;
}

.kl__consent-dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.kl__consent-dialog-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.375rem;
  font-weight: 400;
  line-height: 1.25;
  color: var(--ink);
}

.kl__consent-close {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: -4px -6px 0 0;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--accent) 18%, transparent);
  border-radius: 50%;
  background: var(--paper);
  font: inherit;
  font-size: 1.375rem;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
}

.kl__consent-close:hover {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.kl__consent-intro {
  margin: 10px 0 18px;
  font-size: .9rem;
  color: var(--ink-soft);
}

.kl__consent-categories {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--border);
}

.kl__consent-category {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin: 0;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.kl__consent-category-name {
  display: block;
  margin: 0;
  font-weight: 500;
  color: var(--ink);
}

label.kl__consent-category-name {
  cursor: pointer;
}

.kl__consent-category-description {
  margin: 4px 0 0;
  font-size: .84rem;
  color: var(--muted);
}

.kl__consent-always {
  flex: none;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--success);
  white-space: nowrap;
}

/* A switch (role="switch" on a native checkbox, so the keyboard and screen readers get it for free): a garnet track
   while on. */
.kl__consent-switch {
  appearance: none;
  flex: none;
  position: relative;
  width: 44px;
  height: 26px;
  margin: 2px 0 0;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--muted) 45%, var(--white));
  cursor: pointer;
  transition: background .15s ease;
}

.kl__consent-switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 3px rgb(27 20 36 / .3);
  transition: transform .15s ease;
}

.kl__consent-switch:checked {
  background: var(--accent);
}

.kl__consent-switch:checked::before {
  transform: translateX(18px);
}

.kl__consent-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

/* The footer's „Ustawienia cookies” opens the dialog through the engine: without it (no JavaScript) it has nothing to
   open. */
html:not([data-consent]) [data-consent-settings] {
  display: none;
}

/* Phone: the banner spans the width above the bottom edge, its text above two equal buttons; the dialog's buttons
   stack. */
@media (max-width: 768px) {
  html[data-consent="pending"] .kl__consent-banner {
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
  }

  .kl__consent-banner-in {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding: 16px 18px;
  }

  .kl__consent-lead {
    font-size: .8125rem;
  }

  .kl__consent-actions .kl__btn {
    flex: 1 1 0;
  }

  .kl__consent-dialog {
    padding: 22px 18px;
  }

  .kl__consent-dialog-actions {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kl__consent-switch,
  .kl__consent-switch::before {
    transition: none;
  }
}
