/* SW shell widgets — toast, cookie consent, feedback launcher and guided tour (Shepherd)
   for pages on the SW design system. Tokens only; load after /design-system/styles.css
   and sw-extended.css (design system). JS: sw-toast.js, sw-cookie-consent.js, feedback.js, tour.js. */

/* ── Toast ──────────────────────────────────────────────── */
.sw-toasts {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-toast);
  display: grid;
  gap: var(--space-2);
  width: min(24rem, calc(100vw - 2rem));
  pointer-events: none;
}
.sw-toasts > * { pointer-events: auto; }
.sw-toast { width: 100%; transition: opacity var(--duration-base) ease, transform var(--duration-base) ease; }
.sw-toast.is-leaving { opacity: 0; transform: translateX(1rem); }
.sw-toast__body { flex: 1 1 auto; min-width: 0; }
.sw-toast__title + .sw-toast__description { margin-top: var(--space-0-5); }
.sw-toast__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.sw-toast__close {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 1.75rem;
  height: 1.75rem;
  margin: calc(var(--space-1) * -1) calc(var(--space-1) * -1) 0 var(--space-1);
  border-radius: var(--radius-sm);
}
.sw-toast__close:hover { background: var(--surface-muted); color: var(--text-primary); }
.sw-toast__close:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.sw-toast--success .sw-toast__icon { background: var(--success-soft); color: var(--success); }
.sw-toast--warning .sw-toast__icon { background: var(--warning-soft); color: var(--warning); }
.sw-toast--info .sw-toast__icon,
.sw-toast--primary .sw-toast__icon { background: var(--accent-soft); color: var(--accent-text); }

@media (max-width: 1024px) {
  .sw-toasts { top: calc(var(--sw-mobile-bar-h, 0rem) + var(--space-2)); right: var(--space-3); left: var(--space-3); width: auto; }
}

/* ── Cookie consent ─────────────────────────────────────── */
.sw-cookie {
  position: fixed;
  bottom: var(--space-4);
  left: calc(var(--sw-sidebar-w, 0px) + var(--space-4));
  right: 5.5rem; /* leaves room for the feedback launcher */
  margin-inline: auto; /* centred in the free space (left and right are both set) */
  z-index: calc(var(--z-toast) - 1);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-5);
  max-width: 56rem;
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-panel);
  background: var(--surface-solid);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  opacity: 0;
  transform: translateY(1rem);
  transition: opacity var(--duration-medium) ease, transform var(--duration-medium) ease, border-color var(--duration-base) ease;
}
body.sw-sidebar-collapsed .sw-cookie { left: calc(var(--sw-sidebar-w-collapsed, 0px) + var(--space-4)); }
.sw-cookie.visible { opacity: 1; transform: none; }
.sw-cookie.hiding { opacity: 0; transform: translateY(1rem); }
.sw-cookie.highlight { border-color: var(--accent-solid); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus-ring) 30%, transparent), var(--shadow-lg); }
.sw-cookie__icon { display: grid; place-items: center; flex: 0 0 auto; width: 2.5rem; height: 2.5rem; border-radius: var(--radius-control); background: var(--accent-fill); color: var(--accent-text); }
.sw-cookie__icon .sw-icon { width: var(--icon-md); height: var(--icon-md); }
.sw-cookie__text { flex: 1 1 22rem; min-width: 0; }
.sw-cookie__title { margin: 0; font-family: var(--font-heading); font-size: var(--text-base); font-weight: var(--heading-weight); }
.sw-cookie__description { margin: var(--space-1) 0 0; color: var(--text-secondary); line-height: 1.5; }
.sw-cookie__description a { color: var(--text-link); }
.sw-cookie__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.sw-dialog__body:has(.sw-cookie-category) { gap: 0; padding-block: var(--space-2); }
.sw-cookie-category { padding: var(--space-2) 0; }
.sw-cookie-category + .sw-cookie-category { border-top: 1px solid var(--border-soft); }
.sw-cookie-category__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-height: var(--hit-min); }
.sw-cookie-category__title { font-weight: 600; }
.sw-cookie-category__description { margin: var(--space-1) 0 0; color: var(--text-secondary); font-size: var(--text-sm); line-height: 1.5; }

.sw-cookie-required {
  position: fixed;
  bottom: var(--space-4);
  right: 5.5rem;
  z-index: var(--z-toast);
  width: min(24rem, calc(100vw - 2rem));
}

@media (max-width: 576px) {
  .sw-cookie__icon { display: none; }
}

@media (max-width: 1024px) {
  .sw-cookie, body.sw-sidebar-collapsed .sw-cookie { left: var(--space-3); right: var(--space-3); bottom: var(--space-3); }
  .sw-cookie__actions .sw-btn { flex: 1 1 auto; min-height: var(--hit-min); }
  .sw-cookie-required { right: var(--space-3); left: var(--space-3); width: auto; }
}

/* ── Feedback launcher ──────────────────────────────────── */
.c-feedback-button {
  --feedback-size: var(--hit-min);
  position: fixed;
  right: max(var(--space-5), env(safe-area-inset-right));
  bottom: max(var(--space-5), calc(env(safe-area-inset-bottom) + var(--space-4)));
  z-index: var(--z-overlay);
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  width: var(--feedback-size);
  height: var(--feedback-size);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  background: var(--surface-raised);
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
  transition: width var(--duration-medium) var(--ease-standard), border-color var(--duration-base) ease;
}
.c-feedback-button__icon { display: grid; place-items: center; flex: 0 0 var(--feedback-size); width: var(--feedback-size); color: var(--accent-text); }
.c-feedback-button__icon .sw-icon { width: var(--icon-md); height: var(--icon-md); }
.c-feedback-button__label {
  max-width: 0;
  padding-left: 0;
  overflow: hidden;
  font-size: var(--text-xs);
  font-weight: 650;
  opacity: 0;
  transition: max-width var(--duration-medium) var(--ease-standard), opacity var(--duration-base) ease, padding var(--duration-medium) ease;
}
.c-feedback-button:hover,
.c-feedback-button:focus-visible { width: 10rem; border-color: var(--border-strong); }
.c-feedback-button:hover .c-feedback-button__label,
.c-feedback-button:focus-visible .c-feedback-button__label { max-width: 7.5rem; padding-left: var(--space-3); opacity: 1; }
.c-feedback-button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.c-feedback-button:disabled { cursor: wait; opacity: .7; }
.c-feedback-notice {
  position: fixed;
  right: var(--space-5);
  bottom: calc(var(--hit-min) + var(--space-8));
  z-index: var(--z-overlay);
  max-width: min(24rem, calc(100vw - 2.5rem));
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border: 1px solid color-mix(in srgb, var(--danger) 50%, transparent);
  border-radius: var(--radius-control);
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  font-weight: 600;
}
.u-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; }
@media (max-width: 576px) {
  .c-feedback-button { right: max(var(--space-3), env(safe-area-inset-right)); bottom: max(var(--space-4), calc(env(safe-area-inset-bottom) + var(--space-3))); }
}

/* ── Guided tour (Shepherd.js) ──────────────────────────── */
/* Shepherd's own CSS comes from the CDN and loads after this file: every rule is prefixed with
   .shepherd-element so it wins regardless of order (otherwise the popup stays white in dark mode). */
.shepherd-element.shepherd-theme-autoclipper {
  max-width: 24rem;
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-panel);
  background: var(--surface-solid);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-body);
}
.shepherd-element.shepherd-theme-autoclipper .shepherd-content { background: transparent; padding: 0; }
.shepherd-element.shepherd-theme-autoclipper .shepherd-header,
.shepherd-element.shepherd-theme-autoclipper.shepherd-has-title .shepherd-content .shepherd-header {
  padding: var(--space-4) var(--space-5) 0;
  background: transparent;
  border-radius: 0;
  color: var(--text-primary);
}
.shepherd-element.shepherd-theme-autoclipper .shepherd-title { margin: 0; color: var(--text-primary); font-family: var(--font-heading); font-size: var(--text-base); font-weight: var(--heading-weight); line-height: 1.3; }
.shepherd-element.shepherd-theme-autoclipper .shepherd-cancel-icon { color: var(--text-subtle); font-size: var(--text-xl); }
.shepherd-element.shepherd-theme-autoclipper .shepherd-cancel-icon:hover { color: var(--text-primary); }
.shepherd-element.shepherd-theme-autoclipper .shepherd-text { margin: 0; padding: var(--space-2) var(--space-5) var(--space-4); color: var(--text-secondary); font-size: var(--text-sm); line-height: 1.6; }
.shepherd-element.shepherd-theme-autoclipper .shepherd-footer { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border-soft); background: var(--surface-soft); }
.shepherd-element.shepherd-theme-autoclipper .shepherd-button {
  min-height: var(--control-h-sm);
  padding: 0 var(--space-4);
  border: 1px solid var(--accent-solid);
  border-radius: var(--radius-button);
  background: var(--accent-solid);
  color: var(--text-on-accent);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--button-weight);
  cursor: pointer;
  transition: background-color var(--duration-fast) ease;
}
.shepherd-element.shepherd-theme-autoclipper .shepherd-button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.shepherd-element.shepherd-theme-autoclipper .shepherd-button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.shepherd-element.shepherd-theme-autoclipper .shepherd-button-secondary { background: transparent; border-color: var(--border-default); color: var(--text-primary); }
.shepherd-element.shepherd-theme-autoclipper .shepherd-button-secondary:hover { background: var(--accent-fill); border-color: var(--border-strong); }
.shepherd-element.shepherd-theme-autoclipper[data-popper-placement^="bottom"] > .shepherd-arrow:before,
.shepherd-element.shepherd-theme-autoclipper.shepherd-has-title[data-popper-placement^="bottom"] > .shepherd-arrow:before { background: var(--surface-solid); }
.shepherd-element.shepherd-theme-autoclipper .shepherd-arrow:before { background: var(--surface-solid); }
.shepherd-modal-overlay-container { background: var(--scrim); opacity: 1; z-index: calc(var(--z-toast) + 10) !important; }
.shepherd-element { z-index: calc(var(--z-toast) + 20) !important; }

@media (max-width: 768px) {
  .shepherd-element.shepherd-theme-autoclipper { max-width: 90%; margin: 0 5%; }
  .shepherd-element.shepherd-theme-autoclipper .shepherd-footer { flex-direction: column; }
  .shepherd-element.shepherd-theme-autoclipper .shepherd-button { width: 100%; min-height: var(--hit-min); }
}

@media (prefers-reduced-motion: reduce) {
  .sw-toast, .sw-cookie, .c-feedback-button, .c-feedback-button__label { transition: none; }
}

/* Native select popups: the control is transparent, so the option list needs its own
   surface and text colour or it shows light text on the browser's white default. */
select option, select optgroup { background-color: var(--surface-card); color: var(--text-primary); }
