/* ========================================
   CONSENT MANAGER
   Generic, reusable cookie/consent UI.

   All visual values are driven by --cm-* CSS custom properties with
   NEUTRAL defaults, so an embedding website can theme the component
   purely through CSS (colors, fonts, radius, spacing, icons, z-index)
   without ever touching consentmgr.js.

   A website selects a theme via the generic configuration
   (ConsentManagerConfig.theme = "dsr"), which adds a "cm-theme-<name>"
   class to the banner/modal/floating button. The DSR-specific theme
   lives in a clearly separated section at the BOTTOM of this file.
   ======================================== */

/* ----------------------------------------
   Design tokens (neutral defaults)
   ---------------------------------------- */

.cm-banner,
.cm-modal,
.cm-fab {
  --cm-font-family: inherit;
  --cm-radius: 12px;
  --cm-border: #e6e6e6;
  --cm-backdrop: rgba(0, 0, 0, 0.55);
  --cm-focus: #1a73e8;

  --cm-banner-bg: #ffffff;
  --cm-banner-color: #222222;
  --cm-banner-link-color: #555555;

  --cm-surface-bg: #ffffff;
  --cm-surface-color: #222222;
  --cm-muted-color: #555555;

  --cm-primary: #1a1a1a;
  --cm-primary-hover: #000000;
  --cm-on-primary: #ffffff;

  --cm-secondary-bg: #ededed;
  --cm-secondary-hover: #e0e0e0;
  --cm-secondary-color: #1a1a1a;

  --cm-toggle-on: #1a1a1a;
  --cm-toggle-off: #c7ccd1;

  --cm-fab-bg: #ffffff;
  --cm-fab-color: #333333;
  --cm-fab-opacity: 0.65;
  --cm-fab-opacity-hover: 1;
  --cm-fab-right: 20px;
  --cm-fab-bottom: 20px;

  --cm-z-banner: 11000;
  --cm-z-fab: 11500;
  --cm-z-modal: 12000;
}

.cm-banner,
.cm-banner *,
.cm-modal,
.cm-modal *,
.cm-fab,
.cm-fab * {
  box-sizing: border-box;
}

/* ----------------------------------------
   Shared icon sizing (SVG scales with font-size)
   ---------------------------------------- */

.cm-icon svg {
  width: 1em;
  height: 1em;
  display: block;
}

/* ----------------------------------------
   Banner (bottom-of-screen overlay)
   ---------------------------------------- */

.cm-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--cm-z-banner);
  background: var(--cm-banner-bg);
  color: var(--cm-banner-color);
  font-family: var(--cm-font-family);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
  transform: translateY(110%);
  transition: transform 0.35s ease;
}

.cm-banner.cm-banner--visible {
  transform: translateY(0);
}

.cm-banner__inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 24px;
}

.cm-banner__icon {
  flex: 0 0 auto;
  font-size: 34px;
  line-height: 0;
  color: var(--cm-banner-color);
  opacity: 0.9;
}

.cm-banner__text {
  flex: 1 1 320px;
  font-size: 14px;
  line-height: 1.55;
}

.cm-banner__text p {
  margin: 0 0 8px;
}

.cm-banner__text p:last-child {
  margin-bottom: 0;
}

.cm-banner__text a {
  color: var(--cm-banner-link-color);
}

.cm-banner__actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

/* ----------------------------------------
   Buttons
   ---------------------------------------- */

.cm-btn {
  border: 0;
  border-radius: 8px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, color 0.2s ease;
}

/* Primary: the prominent action (Accept all / Save) */
.cm-btn--primary {
  background: var(--cm-primary);
  color: var(--cm-on-primary);
  padding: 12px 26px;
  font-size: 15px;
}

.cm-btn--primary:hover {
  background: var(--cm-primary-hover);
  transform: translateY(-1px);
}

/* Secondary: Custom settings */
.cm-btn--secondary {
  background: var(--cm-secondary-bg);
  color: var(--cm-secondary-color);
}

.cm-btn--secondary:hover {
  background: var(--cm-secondary-hover);
  transform: translateY(-1px);
}

/* Link: unobtrusive inline text-style action (Decline all) */
.cm-btn--link {
  background: transparent;
  color: var(--cm-banner-link-color);
  padding: 11px 8px;
  font-weight: 500;
  text-decoration: underline;
}

.cm-btn--link:hover {
  text-decoration: none;
}

.cm-btn:focus-visible,
.cm-modal__close:focus-visible,
.cm-fab:focus-visible,
.cm-switch input:focus-visible + .cm-switch__track {
  outline: 3px solid var(--cm-focus);
  outline-offset: 3px;
}

/* ----------------------------------------
   Modal (custom settings dialog)
   ---------------------------------------- */

.cm-modal {
  position: fixed;
  inset: 0;
  z-index: var(--cm-z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--cm-backdrop);
  font-family: var(--cm-font-family);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.cm-modal.cm-modal--visible {
  opacity: 1;
  visibility: visible;
}

.cm-modal__dialog {
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--cm-surface-bg);
  color: var(--cm-surface-color);
  border-radius: var(--cm-radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  transform: translateY(16px) scale(0.98);
  transition: transform 0.25s ease;
}

.cm-modal--visible .cm-modal__dialog {
  transform: translateY(0) scale(1);
}

.cm-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--cm-border);
}

.cm-modal__title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--cm-surface-color);
}

.cm-modal__header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cm-modal__icon {
  font-size: 30px;
  line-height: 0;
  color: var(--cm-primary);
}

.cm-modal__close {
  border: 0;
  background: transparent;
  color: var(--cm-muted-color);
  font-size: 26px;
  line-height: 1;
  padding: 2px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.cm-modal__close:hover {
  color: var(--cm-surface-color);
}

.cm-modal__body {
  padding: 8px 24px 4px;
  overflow-y: auto;
}

.cm-modal__intro {
  font-size: 14px;
  line-height: 1.55;
  margin: 12px 0 4px;
}

/* ----------------------------------------
   Options (consent categories) - toggle on the LEFT
   ---------------------------------------- */

.cm-option {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 0;
  border-top: 1px solid var(--cm-border);
}

.cm-option:first-of-type {
  border-top: 0;
}

.cm-option__text {
  flex: 1 1 auto;
  min-width: 0;
}

.cm-option__title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--cm-surface-color);
}

.cm-option__badge {
  margin-left: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--cm-muted-color);
}

.cm-option__desc {
  margin: 6px 0 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--cm-muted-color);
}

/* Toggle switch */
.cm-switch {
  position: relative;
  flex-shrink: 0;
  margin-top: 2px;
  display: inline-flex;
  align-items: center;
}

.cm-switch input {
  position: absolute;
  top: 0;
  left: 0;
  width: 46px;
  height: 26px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.cm-switch__track {
  display: inline-block;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: var(--cm-toggle-off);
  transition: background 0.2s ease;
  position: relative;
}

.cm-switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease;
}

.cm-switch input:checked + .cm-switch__track {
  background: var(--cm-toggle-on);
}

.cm-switch input:checked + .cm-switch__track::after {
  transform: translateX(20px);
}

.cm-switch input:disabled {
  cursor: not-allowed;
}

.cm-switch input:disabled + .cm-switch__track {
  opacity: 0.55;
}

/* ----------------------------------------
   Modal footer (single primary action)
   ---------------------------------------- */

.cm-modal__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 16px 24px 22px;
  border-top: 1px solid var(--cm-border);
}

/* ----------------------------------------
   Floating re-open button (cookie FAB)
   ---------------------------------------- */

.cm-fab {
  position: fixed;
  right: var(--cm-fab-right);
  bottom: var(--cm-fab-bottom);
  z-index: var(--cm-z-fab);
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: var(--cm-fab-bg);
  color: var(--cm-fab-color);
  font-family: var(--cm-font-family);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  opacity: 0;
  visibility: hidden;
  transform: scale(0.9);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
}

.cm-fab.cm-fab--visible {
  opacity: var(--cm-fab-opacity);
  visibility: visible;
  transform: scale(1);
}

.cm-fab:hover,
.cm-fab:focus-visible {
  opacity: var(--cm-fab-opacity-hover);
}

.cm-fab__icon {
  font-size: 26px;
  line-height: 0;
}

/* ----------------------------------------
   Responsive
   ---------------------------------------- */

@media (max-width: 720px) {
  .cm-banner__inner {
    padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0px));
    flex-direction: column;
    align-items: stretch;
  }

  .cm-banner__icon {
    align-self: flex-start;
  }

  /* In the column layout flex-basis becomes a height, so reset it to the
     content height, otherwise it leaves a tall empty gap before the buttons. */
  .cm-banner__text {
    flex: 0 0 auto;
  }

  .cm-banner__actions {
    justify-content: center;
  }

  .cm-btn--primary,
  .cm-btn--secondary {
    flex: 1 1 auto;
  }

  .cm-modal {
    padding: 0;
    align-items: flex-end;
  }

  .cm-modal__dialog {
    max-width: 100%;
    max-height: 92vh;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  .cm-modal__footer .cm-btn {
    flex: 1 1 auto;
  }
}

/* ----------------------------------------
   Reduced motion
   ---------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .cm-banner,
  .cm-modal,
  .cm-modal__dialog,
  .cm-btn,
  .cm-fab,
  .cm-switch__track,
  .cm-switch__track::after {
    transition: none;
  }
}

/* ========================================
   DSR24 THEME  (website-specific overrides)
   ----------------------------------------
   NOT part of the generic defaults. Activated only when
   ConsentManagerConfig.theme === "dsr" (adds the "cm-theme-dsr" class).
   Another website can ignore this block entirely and instead override
   the --cm-* variables above with its own colors/fonts.
   ======================================== */

.cm-theme-dsr {
  --cm-font-family: Arial, sans-serif;
  --cm-focus: #f1d90d;

  --cm-banner-bg: #19599c;
  --cm-banner-color: #ffffff;
  --cm-banner-link-color: #e9f1fa;

  --cm-primary: #19599c;
  --cm-primary-hover: #14477c;
  --cm-on-primary: #ffffff;

  --cm-toggle-on: #3aa757;

  --cm-fab-bg: #19599c;
  --cm-fab-color: #ffffff;
  /* Stack above the existing accessibility widget (bottom-right). */
  --cm-fab-bottom: 84px;
}

/* On the blue DSR banner the default dark buttons would have poor
   contrast, so the banner buttons are re-skinned for the blue surface. */
.cm-theme-dsr.cm-banner .cm-btn--primary {
  background: #ffffff;
  color: #19599c;
}

.cm-theme-dsr.cm-banner .cm-btn--primary:hover {
  background: #eef4fa;
}

.cm-theme-dsr.cm-banner .cm-btn--secondary {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.cm-theme-dsr.cm-banner .cm-btn--secondary:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* On mobile the site's accessibility widget shifts to right:12px / 48px
   (see accessibility-widget.css). Match it so the two stacked buttons stay
   vertically aligned. Desktop already matches (right:20px / 52px). */
@media (max-width: 480px) {
  .cm-theme-dsr.cm-fab {
    right: 12px;
    width: 48px;
    height: 48px;
  }
}
