/**
 * Consent manager styles.
 *
 * Every value is a CSS custom property on `.cmp-root`, so a site restyles the
 * CMP by overriding variables rather than editing this file or fighting
 * specificity. Defaults match dsgarden.pt (#6aaf08 brand green, Roboto).
 *
 * Selectors are single-class and namespaced `cmp-`, keeping specificity flat
 * (0,1,0) so a host stylesheet can override without !important. This matters
 * here: the CMP loads into pages carrying Bootstrap, which styles bare
 * `button` and `.btn` aggressively.
 */

.cmp-root {
  /* Brand. Accent is darker than the site's #6aaf08 because it sits behind
     white button text, where the lighter green falls below WCAG AA (2.71:1). */
  --cmp-accent: #4a7a00;
  --cmp-accent-hover: #3d6600;
  --cmp-accent-contrast: #ffffff;

  /* Surfaces */
  --cmp-bg: #ffffff;
  --cmp-bg-raised: #f7f7f7;
  --cmp-text: #272727;
  --cmp-text-muted: #6b6b6b;
  --cmp-border: #e2e2e2;

  /* Secondary control (Reject) — must read as equal in weight to Accept */
  --cmp-secondary-bg: #ffffff;
  --cmp-secondary-text: #272727;
  --cmp-secondary-border: #c6c6c6;
  --cmp-secondary-hover-bg: #f0f0f0;

  --cmp-overlay: rgba(39, 39, 39, 0.5);

  /* Shape */
  --cmp-radius: 10px;
  --cmp-radius-sm: 6px;
  --cmp-shadow: 0 4px 24px rgba(0, 0, 0, 0.16);
  --cmp-gap: 16px;

  /* Type: inherit the host's stack by default so the CMP does not import fonts */
  --cmp-font: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --cmp-font-size: 15px;
  --cmp-font-size-sm: 13.5px;
  --cmp-line-height: 1.55;

  --cmp-z: 2147483000; /* below max, leaving room for a host's own top layer */
}

/* Dark theme: applied by the library, or by the host toggling the attribute. */
.cmp-root[data-cmp-theme='dark'] {
  --cmp-bg: #1e1e1e;
  --cmp-bg-raised: #272727;
  --cmp-text: #f2f2f2;
  --cmp-text-muted: #a8a8a8;
  --cmp-border: #3a3a3a;
  --cmp-secondary-bg: #2e2e2e;
  --cmp-secondary-text: #f2f2f2;
  --cmp-secondary-border: #4a4a4a;
  --cmp-secondary-hover-bg: #3a3a3a;
  --cmp-overlay: rgba(0, 0, 0, 0.65);
  --cmp-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

/* `theme: 'auto'` follows the OS, unless the host has pinned an explicit theme. */
@media (prefers-color-scheme: dark) {
  .cmp-root[data-cmp-theme='auto'] {
    --cmp-bg: #1e1e1e;
    --cmp-bg-raised: #272727;
    --cmp-text: #f2f2f2;
    --cmp-text-muted: #a8a8a8;
    --cmp-border: #3a3a3a;
    --cmp-secondary-bg: #2e2e2e;
    --cmp-secondary-text: #f2f2f2;
    --cmp-secondary-border: #4a4a4a;
    --cmp-secondary-hover-bg: #3a3a3a;
    --cmp-overlay: rgba(0, 0, 0, 0.65);
    --cmp-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  }
}

/* ==========================================================================
   Banner
   ========================================================================== */

.cmp-banner {
  position: fixed;
  inset: auto 0 0 0;
  z-index: var(--cmp-z);
  box-sizing: border-box;
  padding: 20px;
  background: var(--cmp-bg);
  color: var(--cmp-text);
  border-top: 1px solid var(--cmp-border);
  box-shadow: var(--cmp-shadow);
  font-family: var(--cmp-font);
  font-size: var(--cmp-font-size);
  line-height: var(--cmp-line-height);
  /* `both` pins the end state: without a fill mode a dropped frame can leave
     the banner mid-transform, and a half-rendered consent prompt is not a
     prompt the user can act on. */
  animation: cmp-slide-up 0.25s ease-out both;
}

@keyframes cmp-slide-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.cmp-banner__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--cmp-gap);
  max-width: 1170px; /* matches the site's .container */
  margin: 0 auto;
}

.cmp-banner__body {
  flex: 1 1 auto;
  min-width: 0;
}

.cmp-banner__title {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 700;
  color: var(--cmp-text);
}

.cmp-banner__text {
  margin: 0;
  color: var(--cmp-text-muted);
  font-size: var(--cmp-font-size-sm);
}

.cmp-banner__actions {
  display: flex;
  flex: 0 0 auto;
  gap: 10px;
  align-items: center;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.cmp-btn {
  box-sizing: border-box;
  padding: 11px 20px;
  border-radius: var(--cmp-radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: var(--cmp-font-size-sm);
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  /* Neutralise Bootstrap's `.btn` inheritance from the host page. */
  text-transform: none;
  letter-spacing: normal;
  text-decoration: none;
}

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

.cmp-btn--primary {
  background: var(--cmp-accent);
  color: var(--cmp-accent-contrast);
  border-color: var(--cmp-accent);
}

.cmp-btn--primary:hover {
  background: var(--cmp-accent-hover);
  border-color: var(--cmp-accent-hover);
}

/*
 * Reject must be as easy to find and press as Accept. Equal padding, weight,
 * and font size; only the fill differs. A greyed-out or text-link Reject is a
 * dark pattern and is what EDPB guidance and multiple DPA rulings penalise.
 */
.cmp-btn--secondary {
  background: var(--cmp-secondary-bg);
  color: var(--cmp-secondary-text);
  border-color: var(--cmp-secondary-border);
}

.cmp-btn--secondary:hover {
  background: var(--cmp-secondary-hover-bg);
}

/* Tertiary ("Customise") is genuinely lower priority — it opens a dialog
   rather than expressing a choice, so a lighter treatment is not a dark
   pattern. It stays keyboard-reachable and meets contrast. */
.cmp-btn--tertiary {
  background: transparent;
  color: var(--cmp-text);
  border-color: transparent;
  text-decoration: underline;
  padding-inline: 8px;
}

.cmp-btn--tertiary:hover {
  color: var(--cmp-accent);
}

/* ==========================================================================
   Modal
   ========================================================================== */

.cmp-overlay {
  position: fixed;
  inset: 0;
  z-index: calc(var(--cmp-z) + 1);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--cmp-overlay);
  animation: cmp-fade-in 0.15s ease-out both;
}

@keyframes cmp-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.cmp-modal {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  background: var(--cmp-bg);
  color: var(--cmp-text);
  border-radius: var(--cmp-radius);
  box-shadow: var(--cmp-shadow);
  font-family: var(--cmp-font);
  font-size: var(--cmp-font-size);
  line-height: var(--cmp-line-height);
}

.cmp-modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--cmp-border);
}

.cmp-modal__title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
}

.cmp-modal__intro {
  margin: 6px 0 0;
  font-size: var(--cmp-font-size-sm);
  color: var(--cmp-text-muted);
}

.cmp-modal__close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--cmp-radius-sm);
  color: var(--cmp-text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.cmp-modal__close:hover {
  background: var(--cmp-bg-raised);
  color: var(--cmp-text);
}

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

.cmp-modal__body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 4px 20px;
  /* Momentum scrolling on iOS inside the constrained max-height. */
  -webkit-overflow-scrolling: touch;
}

.cmp-modal__footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--cmp-border);
}

/* ==========================================================================
   Category rows
   ========================================================================== */

.cmp-category {
  padding: 16px 0;
  border-bottom: 1px solid var(--cmp-border);
}

.cmp-category:last-child {
  border-bottom: none;
}

.cmp-category__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* Host sites style bare h2/h3 globally (dsgarden.pt sets a Lora serif on
   headings). Restate the family so the dialog stays typographically self-
   consistent instead of inheriting the page's heading font. */
.cmp-category__title,
.cmp-modal__title,
.cmp-banner__title {
  font-family: var(--cmp-font);
}

.cmp-category__title {
  margin: 0;
  font-size: var(--cmp-font-size);
  font-weight: 600;
}

.cmp-category__desc {
  margin: 6px 0 0;
  font-size: var(--cmp-font-size-sm);
  color: var(--cmp-text-muted);
}

.cmp-category__locked {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--cmp-accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ==========================================================================
   Toggle

   A real <button> with aria-pressed, not a checkbox: it needs no label
   association, announces its state natively, and cannot be reset by a
   surrounding form.
   ========================================================================== */

.cmp-toggle {
  flex: 0 0 auto;
  position: relative;
  width: 46px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 13px;
  background: #c6c6c6;
  cursor: pointer;
  transition: background-color 0.18s ease;
}

.cmp-toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.18s ease;
}

.cmp-toggle[aria-pressed='true'] {
  background: var(--cmp-accent);
}

.cmp-toggle[aria-pressed='true']::after {
  transform: translateX(20px);
}

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

.cmp-toggle[disabled] {
  cursor: not-allowed;
  opacity: 0.55;
}

/* ==========================================================================
   Links
   ========================================================================== */

.cmp-links {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
}

.cmp-link {
  color: var(--cmp-accent);
  font-size: var(--cmp-font-size-sm);
  text-decoration: underline;
}

.cmp-link:hover {
  color: var(--cmp-accent-hover);
}

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

/* ==========================================================================
   Floating reopen button
   ========================================================================== */

.cmp-fab {
  position: fixed;
  bottom: 18px;
  left: 18px;
  z-index: calc(var(--cmp-z) - 1);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--cmp-bg);
  color: var(--cmp-text-muted);
  border: 1px solid var(--cmp-border);
  border-radius: 50%;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

/* Bottom-left: the site's own controls and most chat widgets sit bottom-right. */
.cmp-fab:hover {
  color: var(--cmp-accent);
  border-color: var(--cmp-accent);
}

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

.cmp-fab svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
  pointer-events: none;
}

/* ==========================================================================
   Utilities
   ========================================================================== */

.cmp-hidden {
  display: none !important;
}

/* Visible only to screen readers — used for the live region announcing saves. */
.cmp-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Prevent background scroll while the modal is open. */
.cmp-scroll-lock {
  overflow: hidden !important;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 767px) {
  .cmp-banner {
    padding: 16px;
  }

  .cmp-banner__inner {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .cmp-banner__actions {
    flex-wrap: wrap;
  }

  /*
   * Accept and Reject share the row equally on mobile. Giving Accept the full
   * width and stacking Reject beneath would make refusal the harder action —
   * the layout equivalent of the dark pattern the colour choices avoid.
   */
  .cmp-banner__actions .cmp-btn--primary,
  .cmp-banner__actions .cmp-btn--secondary {
    flex: 1 1 0;
    min-width: 130px;
  }

  .cmp-banner__actions .cmp-btn--tertiary {
    flex: 1 0 100%;
    order: 3;
    text-align: center;
  }

  .cmp-modal {
    max-height: 90vh;
  }

  .cmp-modal__footer .cmp-btn {
    flex: 1 1 0;
    min-width: 120px;
  }

  .cmp-fab {
    bottom: 14px;
    left: 14px;
  }
}

/* ==========================================================================
   Accessibility preferences
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .cmp-banner,
  .cmp-overlay,
  .cmp-toggle,
  .cmp-toggle::after,
  .cmp-btn {
    animation: none !important;
    transition: none !important;
  }
}

@media (prefers-contrast: more) {
  .cmp-root {
    --cmp-border: #767676;
    --cmp-text-muted: #4a4a4a;
    --cmp-secondary-border: #767676;
  }
}

/* Consent UI is not part of the document — never print it. */
@media print {
  .cmp-banner,
  .cmp-overlay,
  .cmp-fab {
    display: none !important;
  }
}
