/**
 * BH.Toast CSS — matches design tokens from styles.css.
 * Import via: <link rel="stylesheet" href="/components/toast.css" />
 *
 * Stack: bottom-right. 4 types (success/error/info/warning).
 * Progress bar animates width from 100% → 0% over duration.
 * Dismiss: click ✕ or auto after timeout.
 *
 * Respect prefers-reduced-motion: no animations.
 */

/* ── Toast stack container ────────────────────────────────────────────────── */
#toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse; /* newest on top visually */
  gap: 8px;
  pointer-events: none;
}

#toast-stack .bh-toast {
  pointer-events: auto;
}

/* ── Screen-reader only utility ───────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ── Toast card ────────────────────────────────────────────────────────────── */
.bh-toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 320px;
  max-width: calc(100vw - 40px);
  background: var(--surface, #1a1a18);
  border: 1px solid var(--border-strong, rgba(255, 255, 255, 0.13));
  border-radius: var(--radius-md, 14px);
  box-shadow: var(--shadow-md, 0 10px 28px rgba(0, 0, 0, 0.32));
  padding: 12px 14px 16px;
  position: relative;
  overflow: hidden;
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-primary, #f7f6f2);
  animation: bh-toast-in var(--dur-slow, 280ms) var(--anim-spring, cubic-bezier(0.22, 1, 0.36, 1)) both;
}

@keyframes bh-toast-in {
  from {
    opacity: 0;
    transform: translateX(24px) scale(0.95);
  }
  60% {
    transform: translateX(-3px) scale(1.01);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

/* ── Icon ─────────────────────────────────────────────────────────────────── */
.bh-toast__icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bh-toast--success .bh-toast__icon { color: var(--success, #84a37d); }
.bh-toast--error   .bh-toast__icon { color: var(--danger, #e07a7a); }
.bh-toast--info    .bh-toast__icon { color: var(--info, #7aa2c4); }
.bh-toast--warning .bh-toast__icon { color: var(--warning, #d4a35c); }

/* ── Body ─────────────────────────────────────────────────────────────────── */
.bh-toast__body {
  flex: 1;
  min-width: 0;
}

.bh-toast__title {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary, #f7f6f2);
  line-height: 1.3;
}

.bh-toast__msg {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-secondary, #a8a59c);
  line-height: 1.45;
}

.bh-toast__body:empty { display: none; }

/* ── Close button ─────────────────────────────────────────────────────────── */
.bh-toast__close {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-tertiary, #78766f);
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  transition: background var(--dur-micro, 110ms), color var(--dur-micro, 110ms);
  font-family: var(--font-sans, system-ui, sans-serif);
}

.bh-toast__close:hover {
  background: var(--surface-hover, #2b2b28);
  color: var(--text-primary, #f7f6f2);
}

.bh-toast__close:focus-visible {
  outline: 2px solid var(--accent, #d97757);
  outline-offset: 2px;
}

/* ── Progress bar ─────────────────────────────────────────────────────────── */
.bh-toast__progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--border-dim, rgba(255, 255, 255, 0.045));
  overflow: hidden;
}

.bh-toast__progress-bar {
  height: 100%;
  width: 100%;
  transform-origin: left;
  transform: scaleX(0);
  transition: none;
}

.bh-toast--success .bh-toast__progress-bar { background: var(--success, #84a37d); }
.bh-toast--error   .bh-toast__progress-bar { background: var(--danger, #e07a7a); }
.bh-toast--info    .bh-toast__progress-bar { background: var(--info, #7aa2c4); }
.bh-toast--warning .bh-toast__progress-bar { background: var(--warning, #d4a35c); }

/* Activated by JS: starts the drain animation */
.bh-toast__progress-bar--active {
  transform: scaleX(1);
  transform-origin: left;
  transition: transform linear;
  /* duration set inline by JS (matches opts.duration) */
}

/* ── Type color accents on border ─────────────────────────────────────────── */
.bh-toast--success { border-left: 3px solid var(--success, #84a37d); }
.bh-toast--error   { border-left: 3px solid var(--danger, #e07a7a); }
.bh-toast--info    { border-left: 3px solid var(--info, #7aa2c4); }
.bh-toast--warning { border-left: 3px solid var(--warning, #d4a35c); }

/* ── Leave animation ──────────────────────────────────────────────────────── */
.bh-toast--leaving {
  animation: bh-toast-out 240ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1)) forwards !important;
}

@keyframes bh-toast-out {
  to {
    opacity: 0;
    transform: translateX(12px);
  }
}

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #toast-stack {
    bottom: 12px;
    right: 12px;
    left: 12px;
  }
  .bh-toast {
    width: auto;
  }
}

/* ── Respect reduced motion ───────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .bh-toast {
    animation: none;
  }
  .bh-toast--leaving {
    animation: none;
  }
  .bh-toast__progress-bar--active {
    transition: none;
  }
}
