/* ==========================================================================
   Component — Toasts, Modals & Tooltips
   ========================================================================== */

/* --- Toasts -------------------------------------------------------------- */
.wu-toasts {
  position: fixed;
  right: var(--wu-space-5);
  bottom: var(--wu-space-5);
  z-index: var(--wu-z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--wu-space-2);
  width: min(360px, calc(100vw - 2rem));
  pointer-events: none;
}

.wu-toast {
  display: flex;
  align-items: flex-start;
  gap: var(--wu-space-3);
  padding: var(--wu-space-3) var(--wu-space-4);
  border-radius: var(--wu-radius);
  background: var(--wu-surface);
  border: 1px solid var(--wu-border);
  border-inline-start: 4px solid var(--wu-info);
  box-shadow: var(--wu-shadow);
  font-size: var(--wu-fs-sm);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--wu-duration) var(--wu-ease),
              transform var(--wu-duration) var(--wu-ease-out);
}
.wu-toast.is-visible { opacity: 1; transform: translateY(0); }

.wu-toast-icon { flex: 0 0 auto; color: var(--wu-info); }
.wu-toast-icon svg { width: 20px; height: 20px; }

.wu-toast-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.wu-toast-body strong { color: var(--wu-heading); }

.wu-toast-close {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border: 0;
  background: none;
  color: var(--wu-text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.wu-toast-close:hover { color: var(--wu-heading); }

.wu-toast-success { border-inline-start-color: var(--wu-success); }
.wu-toast-success .wu-toast-icon { color: var(--wu-success); }
.wu-toast-error   { border-inline-start-color: var(--wu-danger); }
.wu-toast-error   .wu-toast-icon { color: var(--wu-danger); }
.wu-toast-warning { border-inline-start-color: var(--wu-warning); }
.wu-toast-warning .wu-toast-icon { color: var(--wu-warning); }

@media (max-width: 575.98px) {
  .wu-toasts { left: var(--wu-space-4); right: var(--wu-space-4); width: auto; bottom: var(--wu-space-4); }
}

/* --- Modal (the template's own; see WayUgo.ui.modals) -------------------- */
.wu-modal {
  position: fixed;
  inset: 0;
  z-index: var(--wu-z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--wu-space-4);
  background: var(--wu-overlay);
  opacity: 0;
  visibility: hidden;
  /* visibility is a discrete property: transitioning it leaves the element
     hidden for the first half of the animation, and focus() on a hidden
     element is silently dropped - which is how a modal opens with focus still
     on the page behind it. Delay it on the way out, flip it at once on the
     way in. Same trap the promo popup and the cookie bar hit. */
  transition: opacity var(--wu-duration) var(--wu-ease),
              visibility 0s linear var(--wu-duration);
}
.wu-modal.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--wu-duration) var(--wu-ease), visibility 0s;
}

.wu-modal-dialog {
  width: min(560px, 100%);
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  background: var(--wu-surface);
  /* Square: overlays follow the editorial shape language, not the soft
     card one. Controls inside them keep their own radii. */
  border-radius: 0;
  box-shadow: var(--wu-shadow-lg);
  transform: translateY(16px) scale(.98);
  transition: transform var(--wu-duration) var(--wu-ease-out);
}
.wu-modal.is-open .wu-modal-dialog { transform: none; }
.wu-modal-lg .wu-modal-dialog { width: min(880px, 100%); }

.wu-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--wu-space-3);
  padding: var(--wu-space-4) var(--wu-space-5);
  border-bottom: 1px solid var(--wu-border);
}
.wu-modal-head h3 { margin: 0; }
.wu-modal-body { padding: var(--wu-space-5); }
.wu-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--wu-space-3);
  padding: var(--wu-space-4) var(--wu-space-5);
  border-top: 1px solid var(--wu-border);
}
.wu-modal-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--wu-surface-alt);
  color: var(--wu-text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.wu-modal-close:hover { color: var(--wu-heading); }

/* --- Tooltip ------------------------------------------------------------- */
.wu-tooltip { position: relative; }
.wu-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  z-index: var(--wu-z-dropdown);
  padding: 0.4rem 0.7rem;
  border-radius: var(--wu-radius-sm);
  background: var(--wu-ink);
  color: #fff;
  font-size: var(--wu-fs-xs);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--wu-duration-sm) var(--wu-ease),
              transform var(--wu-duration-sm) var(--wu-ease),
              visibility var(--wu-duration-sm);
}
.wu-tooltip:hover::after,
.wu-tooltip:focus-visible::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* --- Color scheme switcher (demo control; remove for production) --------- */
.wu-scheme-switcher {
  position: fixed;
  top: 50%;
  right: 0;
  z-index: var(--wu-z-sticky);
  /* The whole switcher parks off-screen and slides in, so the toggle — which
     hangs off its left edge — ends up flush against the viewport edge. Moving
     only the panel would leave the toggle stranded a panel-width inland. */
  transform: translate(100%, -50%);
  transition: transform var(--wu-duration) var(--wu-ease-out);
}
.wu-scheme-switcher.is-open { transform: translate(0, -50%); }

.wu-scheme-toggle {
  position: absolute;
  top: 50%;
  right: 100%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--wu-radius) 0 0 var(--wu-radius);
  background: var(--wu-primary);
  color: var(--wu-on-primary);
  cursor: pointer;
  box-shadow: var(--wu-shadow-sm);
  /* Not transform: that is the translateY(-50%) doing the vertical centring,
     and animating it would slide the button on every hover. */
  transition: background-color var(--wu-duration-sm) var(--wu-ease),
              box-shadow var(--wu-duration-sm) var(--wu-ease);
}
.wu-scheme-toggle svg { width: 20px; height: 20px; }

.wu-scheme-panel {
  width: 190px;
  padding: var(--wu-space-4);
  background: var(--wu-surface);
  border: 1px solid var(--wu-border);
  border-inline-end: 0;
  border-radius: var(--wu-radius) 0 0 var(--wu-radius);
  box-shadow: var(--wu-shadow);
}
/* Was an h4; it is a group label now, so the selector follows the class
   rather than the tag. Same size, same spacing. */
.wu-scheme-title {
  margin: 0 0 var(--wu-space-3);
  font-size: var(--wu-fs-xs);
  font-weight: var(--wu-fw-semibold);
  color: var(--wu-heading);
}

.wu-scheme-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--wu-space-2); }
.wu-scheme-swatch {
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 0 0 2px var(--wu-surface);
  transition: border-color var(--wu-duration-sm) var(--wu-ease),
              box-shadow var(--wu-duration-sm) var(--wu-ease);
}
.wu-scheme-swatch.is-active { border-color: var(--wu-heading); }

@media print {
  .wu-scheme-switcher, .wu-toasts { display: none !important; }
}

/* ==========================================================================
   Cookie consent bar
   Sits above everything except a modal. Three states: the bar, the expanded
   category panel, and gone. Nothing is set until the visitor chooses, which
   is the whole point of the component.
   ========================================================================== */
.wu-cookie-bar {
  position: fixed;
  left: var(--wu-space-4);
  right: var(--wu-space-4);
  bottom: var(--wu-space-4);
  z-index: calc(var(--wu-z-modal) - 1);
  max-width: 1080px;
  margin-inline: auto;
  padding: var(--wu-space-5);
  border: 1px solid var(--wu-border);
  border-radius: var(--wu-radius-lg);
  background: var(--wu-surface);
  box-shadow: var(--wu-shadow-lg);

  /* Off-screen until opened, and out of the tab order while it is: a hidden
     bar that still catches Tab is the classic consent-banner bug. */
  visibility: hidden;
  opacity: 0;
  transform: translateY(1rem);

  /* visibility is a discrete property: transitioning it leaves the element
     hidden for the first half of the animation, which silently swallows any
     focus() call in that window. Delay it on the way out instead, and flip it
     at once on the way in. */
  transition: opacity var(--wu-duration) var(--wu-ease),
              transform var(--wu-duration) var(--wu-ease),
              visibility 0s linear var(--wu-duration);
}
.wu-cookie-bar.is-open {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition: opacity var(--wu-duration) var(--wu-ease),
              transform var(--wu-duration) var(--wu-ease),
              visibility 0s;
}

.wu-cookie-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--wu-space-5);
}
.wu-cookie-text { flex: 1 1 320px; min-width: 0; }
.wu-cookie-text h3 { font-size: var(--wu-fs-base); margin-bottom: var(--wu-space-1); }
.wu-cookie-text p { margin: 0; font-size: var(--wu-fs-sm); color: var(--wu-text-muted); }

.wu-cookie-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--wu-space-2);
  flex: 0 0 auto;
}

/* The category panel opens in place — a second dialog for "let me choose"
   is one dismissal too many. */
.wu-cookie-options {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--wu-duration) var(--wu-ease);
}
.wu-cookie-bar.is-expanded .wu-cookie-options { grid-template-rows: 1fr; }
.wu-cookie-options > div { overflow: hidden; }

.wu-cookie-option {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--wu-space-4);
  padding: var(--wu-space-4) 0;
  border-top: 1px solid var(--wu-border);
}
.wu-cookie-option strong { display: block; font-size: var(--wu-fs-sm); color: var(--wu-heading); }
.wu-cookie-option span { font-size: var(--wu-fs-xs); color: var(--wu-text-muted); }

@media (max-width: 767.98px) {
  .wu-cookie-bar { left: var(--wu-space-3); right: var(--wu-space-3); bottom: var(--wu-space-3); padding: var(--wu-space-4); }
  .wu-cookie-actions { width: 100%; }
  .wu-cookie-actions .wu-btn { flex: 1 1 auto; }
}

/* ==========================================================================
   Promo popup
   A real dialog: focus goes in, Escape and the backdrop close it, and the
   page behind it cannot be tabbed into.
   ========================================================================== */
.wu-popup-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--wu-z-modal);
  display: grid;
  place-items: center;
  padding: var(--wu-space-4);
  background: rgba(9, 14, 22, .6);
  backdrop-filter: blur(3px);

  visibility: hidden;
  opacity: 0;
  /* Same discrete-property trap as the cookie bar, and here it matters more:
     the dialog moves focus into itself the moment it opens. */
  transition: opacity var(--wu-duration) var(--wu-ease),
              visibility 0s linear var(--wu-duration);
}
.wu-popup-backdrop.is-open {
  visibility: visible;
  opacity: 1;
  transition: opacity var(--wu-duration) var(--wu-ease), visibility 0s;
}

.wu-popup {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  width: min(760px, 100%);
  max-height: calc(100vh - 2rem);
  overflow: auto;
  border-radius: var(--wu-radius-lg);
  background: var(--wu-surface);
  box-shadow: var(--wu-shadow-lg);

  transform: scale(.96);
  transition: transform var(--wu-duration) var(--wu-ease);
}
.wu-popup-backdrop.is-open .wu-popup { transform: none; }

.wu-popup-media { position: relative; background: var(--wu-surface-sunken); min-height: 260px; }
.wu-popup-media img { width: 100%; height: 100%; object-fit: cover; }
.wu-popup-badge {
  position: absolute;
  top: var(--wu-space-4);
  left: var(--wu-space-4);
  padding: 0.3rem 0.7rem;
  border-radius: var(--wu-radius);
  background: var(--wu-danger);
  color: #fff;
  font-size: var(--wu-fs-xs);
  font-weight: var(--wu-fw-bold);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.wu-popup-body { padding: var(--wu-space-6); display: flex; flex-direction: column; justify-content: center; }
.wu-popup-body h2 { font-size: var(--wu-fs-xl); margin-bottom: var(--wu-space-2); }
.wu-popup-body p { color: var(--wu-text-muted); font-size: var(--wu-fs-sm); }

.wu-popup-code {
  display: inline-flex;
  align-items: center;
  gap: var(--wu-space-2);
  align-self: flex-start;
  margin: var(--wu-space-4) 0;
  padding: var(--wu-space-3) var(--wu-space-4);
  border: 1px dashed var(--wu-primary);
  border-radius: var(--wu-radius);
  background: color-mix(in srgb, var(--wu-primary) 8%, transparent);
  font-weight: var(--wu-fw-bold);
  letter-spacing: .1em;
  color: var(--wu-heading);
}

.wu-popup-close {
  position: absolute;
  top: var(--wu-space-3);
  right: var(--wu-space-3);
  z-index: 2;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--wu-surface);
  color: var(--wu-text-muted);
  cursor: pointer;
  box-shadow: var(--wu-shadow-sm);
}
.wu-popup-close:hover { color: var(--wu-heading); }
.wu-popup-close svg { width: 18px; height: 18px; }

.wu-popup-dismiss {
  margin-top: var(--wu-space-3);
  font-size: var(--wu-fs-xs);
  color: var(--wu-text-muted);
}

@media (max-width: 767.98px) {
  .wu-popup { grid-template-columns: minmax(0, 1fr); }
  .wu-popup-media { min-height: 180px; }
  .wu-popup-body { padding: var(--wu-space-5); }
}

@media print {
  .wu-cookie-bar, .wu-popup-backdrop { display: none !important; }
}
