/**
 * Cookie consent banner + settings dialog (2026-10-10) — markup in
 * src/partials/cookie-consent.php, behaviour in assets/js/cookie-consent.js.
 *
 * Buttons share .cookie-consent__btn (label + growing underline). EXCEPTION
 * (2026-10-10, owner's decision after being told the legal risk — see
 * DOKUMENTACJA_MIGRACJA.md §16): on the first-layer banner only,
 * "Akceptuj wszystkie" is a filled primary pill (.cookie-consent__btn--pill).
 * EDPB 03/2022 treats visually favouring "accept" over "reject" as a risky
 * pattern; "Odrzuć wszystkie" therefore stays on the same first layer, same
 * size class and fully legible. The settings dialog keeps identical buttons.
 * Visual language follows the site: frosted white surface (like the
 * navbar's glass fallback), Lato, --color-primary, the .btn-underline
 * "label + 2px underline that grows on hover" button.
 *
 * Layering: the banner sits above the navbar (10), card-stack dots (9) and
 * progress bar (11) but below the mobile menu overlay (1000). The settings
 * panel is a native <dialog> opened with showModal(), i.e. the browser's
 * top layer — above everything, with built-in focus trap and Esc.
 */

.cookie-consent {
  position: fixed;
  z-index: 900;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  max-height: calc(100svh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 20px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
  box-shadow:
    0 0 2px 1px rgba(0, 0, 0, 0.06) inset,
    0 4px 16px rgba(17, 17, 26, 0.10),
    0 8px 32px rgba(17, 17, 26, 0.10);
  font-family: var(--font-family-base);
  color: var(--color-text);
  animation: cookie-consent-in 0.3s ease-out;
}

@media (min-width: 992px) {
  .cookie-consent {
    left: 24px;
    right: auto;
    bottom: 24px;
    width: min(560px, calc(100vw - 48px));
    padding: 24px 28px 14px;
  }
}

/* Compact mobile banner (2026-10-10, owner request): it covered ~50% of a
   360×640 screen — smaller title, tighter spacing, short text (markup). */
@media (max-width: 991.98px) {
  .cookie-consent {
    padding: 14px 16px 6px;
  }

  .cookie-consent .cookie-consent__title {
    margin-bottom: 4px;
    font-size: 16px;
  }

  .cookie-consent .cookie-consent__text {
    font-size: 13.5px;
    line-height: 1.45;
  }

  .cookie-consent .cookie-consent__actions {
    margin-top: 10px;
    gap: 2px 20px;
  }

  .cookie-consent .cookie-consent__btn--pill {
    padding: 8px 20px;
  }
}

@keyframes cookie-consent-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}

.cookie-consent__title,
.cookie-settings__title {
  margin: 0 0 8px;
  font-family: var(--font-family-heading);
  font-weight: var(--fw-bold);
  font-size: 18px;
  line-height: 1.3;
  color: var(--color-black);
}

.cookie-consent__text,
.cookie-settings__intro,
.cookie-settings__desc,
.cookie-settings__provider {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
}

.cookie-consent a,
.cookie-settings a {
  color: var(--color-primary);
  text-decoration: underline;
}

.cookie-consent__actions,
.cookie-settings__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 20px;
  margin-top: 8px;
}

/* Action button — one style for every choice (see legal note above). */
.cookie-consent__btn,
.cookie-consent__link {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-height: 44px;
  padding: 8px 0;
  border: none;
  background: none;
  font-family: var(--font-family-base);
  font-weight: var(--fw-bold);
  font-size: 15px;
  line-height: 1.2;
  color: var(--color-primary);
  cursor: pointer;
}

.cookie-consent__btn::after,
.cookie-consent__link::after {
  content: '';
  display: block;
  width: 40%;
  height: 2px;
  margin-top: 6px;
  background-color: var(--color-primary);
  transition: width 0.25s ease;
}

.cookie-consent__btn:hover::after,
.cookie-consent__btn:focus-visible::after,
.cookie-consent__link:hover::after,
.cookie-consent__link:focus-visible::after {
  width: 100%;
}

/* Banner-only filled pill for "Akceptuj wszystkie" (see the header note). */
.cookie-consent__btn--pill {
  flex-direction: row;
  align-items: center;
  padding: 10px 24px;
  border-radius: 999px;
  background-color: var(--color-primary);
  color: var(--color-white);
  transition: background-color 0.2s ease;
}

.cookie-consent__btn--pill::after {
  content: none;
}

.cookie-consent__btn--pill:hover {
  background-color: #33412f; /* --color-primary, ~20% darker */
}

.cookie-consent :focus-visible,
.cookie-settings :focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ---- Settings dialog ---------------------------------------------------- */

.cookie-settings {
  width: min(640px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: none;
  border-radius: 14px;
  background: var(--color-white);
  color: var(--color-text);
  font-family: var(--font-family-base);
  box-shadow: 0 8px 40px rgba(17, 17, 26, 0.25);
  overscroll-behavior: contain;
}

.cookie-settings::backdrop {
  background: rgba(22, 22, 22, 0.45);
}

.cookie-settings__form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 20px 12px;
}

@media (min-width: 992px) {
  .cookie-settings__form {
    padding: 28px 32px 16px;
  }
}

.cookie-settings__header,
.cookie-settings__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.cookie-settings__title {
  margin: 0;
}

.cookie-settings__close {
  flex: none;
  width: 44px;
  height: 44px;
  margin: -8px -10px -8px 0;
  border: none;
  background: none;
  font-size: 30px;
  line-height: 1;
  color: var(--color-primary);
  cursor: pointer;
}

/* Each category is a soft card (2026-10-10 "user friendly" pass): name +
   service tag, on/off with a written state, one-sentence summary, what we
   do / don't learn (✓ / ✕), technical details collapsed in <details>. */
.cookie-settings__category {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-radius: 12px;
  background: var(--color-bg);
}

.cookie-settings__row {
  align-items: flex-start;
}

.cookie-settings__name {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding-top: 10px;
  font-family: var(--font-family-heading);
  font-weight: var(--fw-bold);
  font-size: 16px;
  line-height: 1.3;
  color: var(--color-black);
}

.cookie-settings__service {
  align-self: flex-start;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-white);
  font-weight: var(--fw-bold);
  font-size: 12px;
  line-height: 1.5;
  color: var(--color-secondary);
}

.cookie-settings__always {
  flex: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: var(--fw-bold);
  color: var(--color-primary);
}

.cookie-settings__facts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cookie-settings__fact {
  position: relative;
  padding-left: 26px;
  font-size: 14px;
  line-height: 1.45;
}

.cookie-settings__fact::before {
  position: absolute;
  left: 0;
  top: 1px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: var(--fw-bold);
  line-height: 18px;
  text-align: center;
}

.cookie-settings__fact--yes::before {
  content: '\2713'; /* ✓ */
  background: var(--color-primary);
  color: var(--color-white);
}

.cookie-settings__fact--no::before {
  content: '\2715'; /* ✕ */
  background: var(--color-white);
  color: var(--color-secondary);
  box-shadow: 0 0 0 1px var(--color-secondary) inset;
}

.cookie-settings__details > summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  font-size: 13px;
  font-weight: var(--fw-bold);
  color: var(--color-primary);
  cursor: pointer;
  list-style: none;
}

.cookie-settings__details > summary::-webkit-details-marker {
  display: none;
}

.cookie-settings__details > summary::after {
  content: '';
  width: 7px;
  height: 7px;
  margin-top: -3px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
}

.cookie-settings__details[open] > summary::after {
  margin-top: 3px;
  transform: rotate(-135deg);
}

.cookie-settings__details[open] > summary {
  margin-bottom: 6px;
}

.cookie-settings__details .cookie-table th,
.cookie-settings__details .cookie-table td {
  border-bottom-color: rgba(121, 133, 118, 0.25);
}

.cookie-settings__provider {
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--color-secondary);
}

/* Toggle switch — a real checkbox (role="switch"), visually restyled. */
.cookie-switch {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
}

/* Written state next to the switch ("Włączone"/"Wyłączone") — the colour
   change alone isn't enough for everyone. Screen readers get the state
   from role="switch" itself, so this text is aria-hidden. */
.cookie-switch__state {
  min-width: 72px;
  font-size: 13px;
  font-weight: var(--fw-bold);
  color: var(--color-secondary);
}

.cookie-switch__on,
.cookie-switch__input:checked ~ .cookie-switch__state .cookie-switch__off {
  display: none;
}

.cookie-switch__input:checked ~ .cookie-switch__state .cookie-switch__on {
  display: inline;
  color: var(--color-primary);
}

.cookie-switch__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1; /* the invisible real checkbox takes every click/tap */
}

.cookie-switch__track {
  pointer-events: none;
  position: relative;
  box-sizing: border-box;
  width: 44px;
  height: 24px;
  border-radius: 12px;
  /* Off = empty outline + grey knob, on = filled + white knob: the two
     states must be unmistakable, since optional categories start OFF. */
  border: 2px solid var(--color-secondary);
  background: var(--color-white);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.cookie-switch__track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-secondary);
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.cookie-switch__input:checked + .cookie-switch__track {
  border-color: var(--color-primary);
  background: var(--color-primary);
}

.cookie-switch__input:checked + .cookie-switch__track::after {
  background: var(--color-white);
  transform: translateX(20px);
}

.cookie-switch__input:focus-visible + .cookie-switch__track {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
}

/* ---- Cookie list table (dialog + privacy policy) ------------------------- */

.cookie-table__wrap {
  overflow-x: auto;
}

.cookie-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-family-base);
  font-size: 13px;
  line-height: 1.4;
}

.cookie-table th,
.cookie-table td {
  padding: 6px 8px 6px 0;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--color-border);
}

.cookie-table th {
  font-weight: var(--fw-bold);
  color: var(--color-secondary);
}

.cookie-table code {
  font-size: 12px;
  color: var(--color-black);
  white-space: nowrap;
}

/* ---- "Ustawienia cookies" re-open links (footer, privacy policy) --------- */

.site-footer__cookie-link {
  padding: 0;
  border: none;
  background: none;
  font-family: var(--font-family-base);
  font-weight: var(--fw-medium);
  font-size: 20px;
  color: var(--color-white);
  cursor: pointer;
}

.site-footer__legal {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 32px;
}

/* Mobile footer: same look as the "Polityka prywatności" link next to it
   (components.css .site-footer__bottom--mobile a). */
.site-footer__bottom--mobile .site-footer__cookie-link {
  font-size: 13px;
  opacity: 0.6;
  text-align: left;
}

@media (prefers-reduced-motion: reduce) {
  .cookie-consent { animation: none; }
  .cookie-consent__btn::after,
  .cookie-consent__link::after,
  .cookie-switch__track,
  .cookie-switch__track::after { transition: none; }
}

/* Keep the pill shape when focused from the keyboard (the shared
   `.cookie-consent :focus-visible` rule above sets a 2px radius). */
.cookie-consent .cookie-consent__btn--pill:focus-visible {
  border-radius: 999px;
  outline-offset: 3px;
}
