/* ================================================================
   PaletteBuilder — Notification System
   Industrial-grade toast/alert system for a colour-management
   platform. An error must NEVER look like a success — not even
   for a fraction of a second.
   ================================================================ */

:root {
  /* ---- SUCCESS (emerald) — calm, confident, earns a quick exit */
  --pb-notify-success-bg:        #ECFDF5;
  --pb-notify-success-border:    #059669;
  --pb-notify-success-icon:      #047857;
  --pb-notify-success-title:     #064E3B;
  --pb-notify-success-text:      #065F46;

  /* ---- ERROR (red) — urgent, unmissable, never fades */
  --pb-notify-error-bg:          #FEF2F2;
  --pb-notify-error-border:      #DC2626;
  --pb-notify-error-icon:        #B91C1C;
  --pb-notify-error-title:       #7F1D1D;
  --pb-notify-error-text:        #991B1B;
  --pb-notify-error-top-bar:     #B91C1C;

  /* ---- WARNING (amber) — cautionary, longer pause */
  --pb-notify-warning-bg:        #FFFBEB;
  --pb-notify-warning-border:    #D97706;
  --pb-notify-warning-icon:      #B45309;
  --pb-notify-warning-title:     #78350F;
  --pb-notify-warning-text:      #92400E;

  /* ---- INFO (sky) — soft, secondary, fades quickly */
  --pb-notify-info-bg:           #F0F9FF;
  --pb-notify-info-border:       #0284C7;
  --pb-notify-info-icon:         #0369A1;
  --pb-notify-info-title:        #0C4A6E;
  --pb-notify-info-text:         #075985;

  /* ---- Sizing / geometry */
  --pb-notify-width-desktop:     380px;
  --pb-notify-width-laptop:      340px;
  --pb-notify-top-offset:        88px;   /* below header+nav */
  --pb-notify-right-offset:      20px;
  --pb-notify-stack-gap:         10px;
  --pb-notify-border-radius:     8px;
  --pb-notify-shadow:            0 10px 15px -3px rgba(15, 23, 42, 0.12),
                                 0 4px 6px -2px rgba(15, 23, 42, 0.06);
  --pb-notify-shadow-error:      0 10px 20px -3px rgba(220, 38, 38, 0.22),
                                 0 4px 8px -2px rgba(220, 38, 38, 0.12);
  --pb-notify-z-index:           9999;
  --pb-notify-font:              -apple-system, BlinkMacSystemFont, "Segoe UI",
                                 Roboto, "Helvetica Neue", Arial, sans-serif;

  /* ---- Persistence */
  --pb-notify-duration-success:  4000ms;
  --pb-notify-duration-warning:  8000ms;
  --pb-notify-duration-info:     3000ms;
  /* ERROR has NO auto-dismiss — intentionally absent */
}

/* ---- Container (top-right on desktop, top-center on tablet) */
.pb-notify-container {
  position: fixed;
  top: var(--pb-notify-top-offset);
  right: var(--pb-notify-right-offset);
  z-index: var(--pb-notify-z-index);
  display: flex;
  flex-direction: column;
  gap: var(--pb-notify-stack-gap);
  width: var(--pb-notify-width-desktop);
  max-width: calc(100vw - 2 * var(--pb-notify-right-offset));
  pointer-events: none; /* allow clicks through gaps */
}

.pb-notify-container > .pb-notify {
  pointer-events: auto; /* but reclaim on actual notifications */
}

/* ---- Single notification card */
.pb-notify {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 4px;
  padding: 14px 14px 14px 16px;
  background: var(--pb-notify-bg, #fff);
  color: var(--pb-notify-text, #1f2937);
  border-left: 4px solid var(--pb-notify-border, #64748b);
  border-radius: var(--pb-notify-border-radius);
  box-shadow: var(--pb-notify-shadow);
  font-family: var(--pb-notify-font);
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-12px);
  transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1),
              opacity   220ms cubic-bezier(0.16, 1, 0.3, 1);
}

.pb-notify.pb-notify--in {
  opacity: 1;
  transform: translateY(0);
}

.pb-notify.pb-notify--out {
  opacity: 0;
  transform: translateX(16px) scaleY(0.96);
  transition: transform 180ms ease-in, opacity 180ms ease-in;
}

/* ---- Type accents */
.pb-notify--success {
  --pb-notify-bg:     var(--pb-notify-success-bg);
  --pb-notify-border: var(--pb-notify-success-border);
  --pb-notify-text:   var(--pb-notify-success-text);
}
.pb-notify--error {
  --pb-notify-bg:     var(--pb-notify-error-bg);
  --pb-notify-border: var(--pb-notify-error-border);
  --pb-notify-text:   var(--pb-notify-error-text);
  box-shadow: var(--pb-notify-shadow-error);
}
.pb-notify--error::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--pb-notify-error-top-bar);
}
.pb-notify--warning {
  --pb-notify-bg:     var(--pb-notify-warning-bg);
  --pb-notify-border: var(--pb-notify-warning-border);
  --pb-notify-text:   var(--pb-notify-warning-text);
}
.pb-notify--info {
  --pb-notify-bg:     var(--pb-notify-info-bg);
  --pb-notify-border: var(--pb-notify-info-border);
  --pb-notify-text:   var(--pb-notify-info-text);
}

/* ---- Icon cell */
.pb-notify__icon {
  grid-column: 1;
  grid-row: 1 / span 2;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 1px;
  color: var(--pb-notify-border);
  flex-shrink: 0;
}
.pb-notify--success .pb-notify__icon { color: var(--pb-notify-success-icon); }
.pb-notify--error   .pb-notify__icon { color: var(--pb-notify-error-icon); }
.pb-notify--warning .pb-notify__icon { color: var(--pb-notify-warning-icon); }
.pb-notify--info    .pb-notify__icon { color: var(--pb-notify-info-icon); }
.pb-notify__icon svg { width: 22px; height: 22px; display: block; }

/* ---- Color swatch (replaces icon when opts.swatch is set) */
.pb-notify__swatch {
  display: block;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

/* ---- Body */
.pb-notify__body {
  grid-column: 2;
  grid-row: 1 / span 2;
  min-width: 0; /* allow wrapping */
  align-self: center;
}
.pb-notify__title {
  display: block;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
  margin: 0 0 2px 0;
  color: inherit;
  letter-spacing: -0.005em;
}
.pb-notify--success .pb-notify__title { color: var(--pb-notify-success-title); }
.pb-notify--error   .pb-notify__title { color: var(--pb-notify-error-title); }
.pb-notify--warning .pb-notify__title { color: var(--pb-notify-warning-title); }
.pb-notify--info    .pb-notify__title { color: var(--pb-notify-info-title); }

.pb-notify__message {
  display: block;
  margin: 0;
  font-size: 13.5px;
  color: inherit;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.pb-notify__message p { margin: 0 0 4px 0; }
.pb-notify__message p:last-child { margin-bottom: 0; }

/* ---- Action button (optional, inside card) */
.pb-notify__action {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: inherit;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 4px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: background-color 120ms ease;
  font-family: inherit;
}
.pb-notify__action:hover,
.pb-notify__action:focus-visible {
  background: rgba(0, 0, 0, 0.06);
  outline: none;
}

/* ---- Dismiss button */
.pb-notify__dismiss {
  grid-column: 3;
  grid-row: 1;
  appearance: none;
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  padding: 2px 4px;
  margin: -2px -4px 0 0;
  font-size: 18px;
  line-height: 1;
  opacity: 0.55;
  border-radius: 3px;
  transition: opacity 120ms ease, background-color 120ms ease;
  align-self: start;
}
.pb-notify__dismiss:hover,
.pb-notify__dismiss:focus-visible {
  opacity: 1;
  background: rgba(0, 0, 0, 0.06);
  outline: none;
}
.pb-notify__dismiss:focus-visible {
  box-shadow: 0 0 0 2px var(--pb-notify-border);
}

/* ---- Countdown bar */
.pb-notify__countdown {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: var(--pb-notify-border);
  transform-origin: left center;
  transform: scaleX(1);
  opacity: 0.55;
  will-change: transform;
}
.pb-notify:hover .pb-notify__countdown {
  animation-play-state: paused;
}
@keyframes pb-notify-countdown {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

/* Error has no countdown bar — intentionally */
.pb-notify--error .pb-notify__countdown { display: none; }

/* ---- Error attention pulse */
@keyframes pb-notify-error-pulse {
  0%   { box-shadow: 0 0 0 0    rgba(220, 38, 38, 0.45),
                     var(--pb-notify-shadow-error); }
  70%  { box-shadow: 0 0 0 10px rgba(220, 38, 38, 0),
                     var(--pb-notify-shadow-error); }
  100% { box-shadow: 0 0 0 0    rgba(220, 38, 38, 0),
                     var(--pb-notify-shadow-error); }
}
.pb-notify--error.pb-notify--in {
  animation: pb-notify-error-pulse 640ms ease-out 0s 2;
}

/* ---- Responsive */
@media (max-width: 1280px) {
  .pb-notify-container {
    width: var(--pb-notify-width-laptop);
  }
}

@media (max-width: 768px) {
  .pb-notify-container {
    top: 12px;
    right: 16px;
    left: 16px;
    width: auto;
    max-width: none;
  }
  .pb-notify {
    font-size: 13.5px;
  }
}

/* ---- Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .pb-notify,
  .pb-notify.pb-notify--in,
  .pb-notify.pb-notify--out {
    transition: opacity 120ms linear;
    transform: none;
    animation: none;
  }
  .pb-notify__countdown {
    animation-duration: 0ms !important;
  }
}

/* ---- High-contrast fallback (Windows forced-colors) */
@media (forced-colors: active) {
  .pb-notify {
    border: 2px solid CanvasText;
    background: Canvas;
    color: CanvasText;
  }
  .pb-notify--error { border-color: Mark; }
}

/* ---- Legacy hide: the old msg() output + the old bottom-centre flash
   stay in the DOM briefly for progressive enhancement, but we hide
   them visually since PBNotify takes over. */
#notify-wrapper.pb-notify-legacy-hidden,
.msg.pb-notify-legacy-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
  padding: 0 !important;
  margin: -1px !important;
}
