/**
 * Trinocex Cookie & Consent — frontend CMP styles.
 * Light, clean, accessible. Auto dark-mode via prefers-color-scheme.
 * Only the brand accent is injected from settings; everything else adapts.
 */
#trinocex-cookie-consent-root {
  /* Light tokens (default). */
  --tcc-bg: #ffffff;
  --tcc-elev: #f7f8fa;
  --tcc-fg: #15202b;
  --tcc-muted: #5a6573;
  --tcc-border: #e3e7ec;
  --tcc-border-strong: #c9d0d8;
  --tcc-accent: var(--trinocex-primary, #1f4e79);
  --tcc-accent-hover: var(--trinocex-primary-dark, #163a5a);
  --tcc-accent-contrast: #ffffff;
  --tcc-radius: 16px;
  --tcc-radius-sm: 10px;
  --tcc-shadow: 0 12px 40px -8px rgba(16, 35, 55, 0.28), 0 2px 8px rgba(16, 35, 55, 0.08);
  --tcc-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  position: relative;
  z-index: 2147483600;
  font-family: var(--tcc-font);
  -webkit-font-smoothing: antialiased;
}

/* The hidden attribute must always win over component display rules
   (e.g. the panel uses display:flex) — otherwise the banner/panel never hide. */
#trinocex-cookie-consent-root [hidden] { display: none !important; }

/* Dark tokens: explicit, or automatic when mode = auto. */
#trinocex-cookie-consent-root[data-color-mode="dark"],
#trinocex-cookie-consent-root[data-color-mode="auto"] {
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  #trinocex-cookie-consent-root[data-color-mode="auto"] {
    --tcc-bg: #1b2530;
    --tcc-elev: #232f3c;
    --tcc-fg: #eef3f8;
    --tcc-muted: #a7b4c2;
    --tcc-border: #33414f;
    --tcc-border-strong: #45556500;
    --tcc-shadow: 0 14px 44px -8px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4);
  }
}
#trinocex-cookie-consent-root[data-color-mode="dark"] {
  --tcc-bg: #1b2530;
  --tcc-elev: #232f3c;
  --tcc-fg: #eef3f8;
  --tcc-muted: #a7b4c2;
  --tcc-border: #33414f;
  --tcc-border-strong: #455565;
  --tcc-shadow: 0 14px 44px -8px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* ---------- Banner ---------- */
.trinocex-cookie-banner {
  position: fixed;
  left: 20px;
  right: 20px;
  bottom: 20px;
  max-width: 480px;
  margin: 0 auto;
  background: var(--tcc-bg);
  color: var(--tcc-fg);
  border: 1px solid var(--tcc-border);
  border-radius: var(--tcc-radius);
  box-shadow: var(--tcc-shadow);
  padding: 22px 22px 20px;
  z-index: 2147483601;
  animation: tccSlideUp 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

#trinocex-cookie-consent-root[data-banner-width="ancho"] .trinocex-cookie-banner { max-width: 760px; }
#trinocex-cookie-consent-root[data-banner-width="compacto"] .trinocex-cookie-banner { max-width: 400px; }

.trinocex-cmp-icon {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: color-mix(in srgb, var(--tcc-accent) 14%, transparent);
  color: var(--tcc-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.trinocex-cmp-icon svg { width: 21px; height: 21px; }

.trinocex-cookie-banner h2 {
  margin: 0 0 7px;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--tcc-fg);
}

.trinocex-cookie-banner p {
  margin: 0 0 4px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--tcc-muted);
}

.trinocex-cmp-policy-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 13px;
  color: var(--tcc-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- Buttons ---------- */
.trinocex-cookie-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.trinocex-btn {
  flex: 1 1 0;
  min-width: 120px;
  appearance: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  padding: 12px 16px;
  border-radius: var(--tcc-radius-sm);
  border: 1.5px solid transparent;
  transition: transform 0.12s ease, background-color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.trinocex-btn:hover { transform: translateY(-1px); }
.trinocex-btn:active { transform: translateY(0); }

/* Reject and Accept are deliberately EQUAL prominence (AEPD / GDPR). */
.trinocex-btn-accept {
  background: var(--tcc-accent);
  color: var(--tcc-accent-contrast);
  border-color: var(--tcc-accent);
}
.trinocex-btn-accept:hover { background: var(--tcc-accent-hover); border-color: var(--tcc-accent-hover); }

.trinocex-btn-reject {
  background: var(--tcc-elev);
  color: var(--tcc-fg);
  border-color: var(--tcc-border-strong);
}
.trinocex-btn-reject:hover { border-color: var(--tcc-fg); }

/* Tertiary (configure / customise) — clearly a control but not a primary CTA. */
.trinocex-btn-ghost {
  flex: 1 1 100%;
  background: transparent;
  color: var(--tcc-muted);
  border-color: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 8px;
  font-weight: 600;
  margin-top: 2px;
}
.trinocex-btn-ghost:hover { color: var(--tcc-accent); transform: none; }

/* ---------- Preferences panel ---------- */
.trinocex-cookie-panel {
  position: fixed;
  /* Anchored to the floating manage button's corner (default: bottom-right),
     so it visually grows out of that button. */
  right: 16px;
  bottom: 68px;
  left: auto;
  top: auto;
  width: min(var(--tcc-panel-w, 460px), calc(100vw - 24px));
  max-height: min(80vh, 720px);
  /* Flex column: header + footer never move, only the body scrolls. */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--tcc-bg);
  color: var(--tcc-fg);
  border: 1px solid var(--tcc-border);
  border-radius: var(--tcc-radius);
  box-shadow: var(--tcc-shadow);
  z-index: 2147483602;
  transform-origin: bottom right;
  animation: tccGrow 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

#trinocex-cookie-consent-root[data-panel-width="compacto"] .trinocex-cookie-panel { --tcc-panel-w: 380px; }
#trinocex-cookie-consent-root[data-panel-width="normal"] .trinocex-cookie-panel { --tcc-panel-w: 460px; }
#trinocex-cookie-consent-root[data-panel-width="ancho"] .trinocex-cookie-panel { --tcc-panel-w: 560px; }

/* Follow the floating button position so the panel is born from it. */
#trinocex-cookie-consent-root[data-manage-position="bottom_left"] .trinocex-cookie-panel {
  left: 16px; right: auto; bottom: 68px; top: auto; transform-origin: bottom left;
}
#trinocex-cookie-consent-root[data-manage-position="top_right"] .trinocex-cookie-panel {
  right: 16px; left: auto; top: 68px; bottom: auto; transform-origin: top right;
}
#trinocex-cookie-consent-root[data-manage-position="top_left"] .trinocex-cookie-panel {
  left: 16px; right: auto; top: 68px; bottom: auto; transform-origin: top left;
}

.trinocex-cookie-panel-header {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--tcc-border);
  background: var(--tcc-bg);
  border-radius: var(--tcc-radius) var(--tcc-radius) 0 0;
}
.trinocex-cookie-panel-header h3 { margin: 0; font-size: 16px; font-weight: 700; color: var(--tcc-fg); }

.trinocex-cmp-close {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--tcc-muted);
  font-size: 22px;
  line-height: 1;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.trinocex-cmp-close:hover { background: var(--tcc-elev); color: var(--tcc-fg); }

.trinocex-cmp-panel-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 22px 4px;
}
.trinocex-cmp-panel-intro { font-size: 13px; color: var(--tcc-muted); line-height: 1.55; margin: 12px 0 6px; }

.trinocex-cookie-categories { display: flex; flex-direction: column; gap: 12px; margin: 14px 0; }

.trinocex-cmp-cat {
  border: 1px solid var(--tcc-border);
  border-radius: var(--tcc-radius-sm);
  padding: 14px 16px;
  background: var(--tcc-elev);
}
.trinocex-cmp-cat-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}
.trinocex-cmp-cat-name { font-size: 14px; font-weight: 700; color: var(--tcc-fg); margin: 0; }
.trinocex-cmp-cat-desc { font-size: 12.5px; color: var(--tcc-muted); line-height: 1.5; margin: 5px 0 0; }

/* Toggle switch */
.trinocex-switch { position: relative; flex: 0 0 auto; width: 42px; height: 24px; }
.trinocex-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.trinocex-switch-track {
  position: absolute;
  inset: 0;
  background: var(--tcc-border-strong);
  border-radius: 999px;
  transition: background-color 0.2s ease;
  pointer-events: none;
}
.trinocex-switch-track::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.trinocex-switch input:checked + .trinocex-switch-track { background: var(--tcc-accent); }
.trinocex-switch input:checked + .trinocex-switch-track::before { transform: translateX(18px); }
.trinocex-switch input:disabled + .trinocex-switch-track { opacity: 0.55; }
.trinocex-switch input:focus-visible + .trinocex-switch-track { outline: 2px solid var(--tcc-accent); outline-offset: 2px; }

/* Expandable cookie details */
.trinocex-cmp-cookies { margin-top: 10px; }
.trinocex-cmp-cookies > summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--tcc-accent);
  list-style: revert;
}
.trinocex-cmp-cookies table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12px; }
.trinocex-cmp-cookies th, .trinocex-cmp-cookies td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid var(--tcc-border);
  color: var(--tcc-muted);
}
.trinocex-cmp-cookies th { color: var(--tcc-fg); font-weight: 600; }

.trinocex-cmp-panel-footer {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 14px 22px 18px;
  flex-wrap: wrap;
  border-top: 1px solid var(--tcc-border);
  background: var(--tcc-bg);
  border-radius: 0 0 var(--tcc-radius) var(--tcc-radius);
}
.trinocex-cmp-panel-footer .trinocex-btn { flex: 1 1 auto; min-width: 110px; }

/* ---------- Floating manage button ---------- */
.trinocex-cookie-manage-link {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 2147483599;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--tcc-bg);
  color: var(--tcc-fg);
  border: 1px solid var(--tcc-border);
  border-radius: 999px;
  padding: 9px 14px;
  font-family: var(--tcc-font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(16, 35, 55, 0.14);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.trinocex-cookie-manage-link:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(16, 35, 55, 0.2); }
.trinocex-cookie-manage-link svg { width: 16px; height: 16px; color: var(--tcc-accent); }
#trinocex-cookie-consent-root[data-manage-position="bottom_left"] .trinocex-cookie-manage-link { left: 16px; right: auto; }
#trinocex-cookie-consent-root[data-manage-position="top_right"] .trinocex-cookie-manage-link { top: 16px; bottom: auto; right: 16px; }
#trinocex-cookie-consent-root[data-manage-position="top_left"] .trinocex-cookie-manage-link { top: 16px; bottom: auto; left: 16px; right: auto; }

/* ---------- Banner positions ---------- */
#trinocex-cookie-consent-root[data-banner-position="bottom_left"] .trinocex-cookie-banner { left: 20px; right: auto; margin: 0; }
#trinocex-cookie-consent-root[data-banner-position="bottom_right"] .trinocex-cookie-banner { right: 20px; left: auto; margin: 0; }
#trinocex-cookie-consent-root[data-banner-position="top_center"] .trinocex-cookie-banner { top: 20px; bottom: auto; }
#trinocex-cookie-consent-root[data-banner-position="top_left"] .trinocex-cookie-banner { top: 20px; bottom: auto; left: 20px; right: auto; margin: 0; }
#trinocex-cookie-consent-root[data-banner-position="top_right"] .trinocex-cookie-banner { top: 20px; bottom: auto; right: 20px; left: auto; margin: 0; }

/* ---------- Focus ---------- */
.trinocex-btn:focus-visible,
.trinocex-cmp-close:focus-visible,
.trinocex-cookie-manage-link:focus-visible,
.trinocex-cmp-policy-link:focus-visible {
  outline: 2px solid var(--tcc-accent);
  outline-offset: 2px;
}

.screen-reader-text {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}

/* ---------- Animations ---------- */
@keyframes tccSlideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes tccGrow { from { opacity: 0; transform: scale(0.82) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }

@media (prefers-reduced-motion: reduce) {
  .trinocex-cookie-banner, .trinocex-cookie-panel { animation: none; }
  .trinocex-btn, .trinocex-cookie-manage-link, .trinocex-switch-track::before { transition: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 540px) {
  .trinocex-cookie-banner { left: 12px; right: 12px; bottom: 12px; max-width: none; padding: 18px; }
  .trinocex-cookie-actions { gap: 8px; }
  .trinocex-btn-accept, .trinocex-btn-reject { flex: 1 1 calc(50% - 4px); }
  .trinocex-cmp-panel-footer .trinocex-btn { flex: 1 1 100%; }

  /* Popover becomes a full-width bottom sheet on phones. */
  #trinocex-cookie-consent-root .trinocex-cookie-panel,
  #trinocex-cookie-consent-root[data-manage-position="bottom_left"] .trinocex-cookie-panel,
  #trinocex-cookie-consent-root[data-manage-position="top_right"] .trinocex-cookie-panel,
  #trinocex-cookie-consent-root[data-manage-position="top_left"] .trinocex-cookie-panel {
    left: 10px; right: 10px; bottom: 10px; top: auto; width: auto; max-height: 82vh; transform-origin: bottom center;
  }
}
