/* ==========================================================================
   Skynet toasts — public/js/skynet-toast.js builds every one of these.

   Loaded by both headers, so it cannot assume Skynet UI's tokens exist: the
   classic pages define none. Each token is read once here with a fallback
   (the dark Skynet palette), and everything below reads the --skt-* copies.
   On a v2 page the fallbacks never apply and the toast follows the reader's
   theme in all twelve palettes.

   Motion: a toast slides a few pixels and fades. Under reduced motion it only
   fades, the timer bar is not drawn and the spinner stops turning.
   ========================================================================== */
.skt-stack {
  --skt-surface: var(--sk-surface, #1e293b);
  --skt-surface-2: var(--sk-surface-2, #273449);
  --skt-border: var(--sk-border, #334155);
  --skt-border-2: var(--sk-border-2, #475569);
  --skt-text: var(--sk-text, #f1f5f9);
  --skt-muted: var(--sk-muted, #a3b1c6);
  --skt-radius: var(--sk-radius, 12px);
  --skt-radius-sm: var(--sk-radius-sm, 8px);
  --skt-shadow: var(--sk-shadow-lg, 0 18px 40px -12px rgba(0, 0, 0, 0.55));
  --skt-primary: var(--sk-primary, #9333ea);
  --skt-on-primary: #fff;

  position: fixed;
  top: calc(var(--skv2-h, 60px) + 12px);
  right: 16px;
  z-index: 10050;
  display: flex;
  flex-direction: column-reverse; /* newest on top, nearest the bar */
  width: min(384px, calc(100vw - 32px));
  pointer-events: none;
  font-family: inherit;
  -webkit-font-smoothing: antialiased;
}
.skt-stack:empty { display: none; }

/* Per type: the accent (stripe, timer), the icon's tint and its colour. */
.skt-success { --skt-accent: var(--sk-success, #16a34a); --skt-soft: var(--sk-success-soft, rgba(22, 163, 74, 0.16)); --skt-ink: var(--sk-success-text, #4ade80); }
.skt-error   { --skt-accent: var(--sk-danger, #dc2626);  --skt-soft: var(--sk-danger-soft, rgba(220, 38, 38, 0.16));  --skt-ink: var(--sk-danger-text, #f87171); }
.skt-warning { --skt-accent: var(--sk-warning, #d97706); --skt-soft: var(--sk-warning-soft, rgba(217, 119, 6, 0.16)); --skt-ink: var(--sk-warning-text, #fbbf24); }
.skt-info    { --skt-accent: var(--sk-info, #2563eb);    --skt-soft: var(--sk-info-soft, rgba(37, 99, 235, 0.16));    --skt-ink: var(--sk-info-text, #60a5fa); }
.skt-loading { --skt-accent: var(--sk-primary, #9333ea); --skt-soft: var(--sk-primary-soft, rgba(147, 51, 234, 0.16)); --skt-ink: var(--sk-primary-text, #c084fc); }

.skt-item {
  margin-top: 8px;
  pointer-events: auto;
}
/* Leaving: the card fades out first, then the space it held closes, so the
   toasts under it slide up instead of jumping. skynet-toast.js pins the
   item's height in px before adding the class so max-height has a start. */
.skt-item.skt-leaving {
  max-height: 0 !important;
  margin-top: 0;
  overflow: hidden;
  pointer-events: none;
  transition: max-height 0.2s ease 0.06s, margin-top 0.2s ease 0.06s;
}

.skt-card {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  padding: 12px 10px 12px 16px;
  overflow: hidden;
  border: 1px solid var(--skt-border);
  border-radius: var(--skt-radius);
  background: var(--skt-surface);
  box-shadow: var(--skt-shadow);
  color: var(--skt-text);
  touch-action: pan-y;
  animation: skt-in 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
/* The type stripe. Colour is never the only signal: the icon and the title
   say the same thing. */
.skt-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--skt-accent);
}
.skt-leaving .skt-card { animation: skt-out 0.18s ease forwards; }
.skt-swiped-right .skt-card { animation: skt-out-right 0.18s ease forwards; }
.skt-swiped-left .skt-card { animation: skt-out-left 0.18s ease forwards; }
.skt-card.skt-bump { animation: skt-bump 0.28s ease; }

.skt-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--skt-soft);
  color: var(--skt-ink);
}
.skt-icon svg { display: block; }

.skt-body { min-width: 0; padding-top: 6px; }
.skt-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.skt-title {
  margin: 0;
  min-width: 0;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.35;
  color: var(--skt-text);
  overflow-wrap: anywhere;
}
.skt-count {
  flex: 0 0 auto;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--skt-surface-2);
  color: var(--skt-muted);
  font-size: 11px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
}
.skt-msg {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--skt-muted);
  overflow-wrap: anywhere;
  white-space: pre-line;
}
.skt-count[hidden], .skt-title[hidden], .skt-msg[hidden], .skt-actions[hidden] { display: none; }

.skt-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.skt-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--skt-border-2);
  border-radius: var(--skt-radius-sm);
  background: transparent;
  color: var(--skt-text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.skt-action:hover { background: var(--skt-surface-2); }
.skt-action.skt-action-primary {
  border-color: transparent;
  background: var(--skt-primary);
  color: var(--skt-on-primary);
}
.skt-action.skt-action-primary:hover { filter: brightness(1.08); background: var(--skt-primary); }

.skt-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: -6px -4px -6px 0;
  padding: 0;
  border: 0;
  border-radius: var(--skt-radius-sm);
  background: transparent;
  color: var(--skt-muted);
  cursor: pointer;
}
.skt-close:hover { background: var(--skt-surface-2); color: var(--skt-text); }
.skt-close:focus-visible,
.skt-action:focus-visible {
  outline: 2px solid var(--skt-primary);
  outline-offset: 2px;
}

/* How long is left. Paused with the clock (hover, focus, background tab). */
.skt-timer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--skt-accent);
  opacity: 0.55;
  transform-origin: left center;
  animation: skt-timer linear forwards;
}
.skt-paused .skt-timer { animation-play-state: paused; }

.skt-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 999px;
  animation: skt-spin 0.8s linear infinite;
}

@keyframes skt-in { from { opacity: 0; transform: translateX(14px) scale(0.98); } }
@keyframes skt-out { to { opacity: 0; transform: translateX(14px) scale(0.98); } }
@keyframes skt-out-right { to { opacity: 0; transform: translateX(110%); } }
@keyframes skt-out-left { to { opacity: 0; transform: translateX(-110%); } }
@keyframes skt-bump { 40% { transform: scale(1.02); } }
@keyframes skt-timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes skt-spin { to { transform: rotate(360deg); } }
@keyframes skt-fade-in { from { opacity: 0; } }
@keyframes skt-fade-out { to { opacity: 0; } }

/* Phones: along the bottom, full width, newest nearest the thumb. */
@media (max-width: 640px) {
  .skt-stack {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    width: auto;
    flex-direction: column;
  }
  .skt-card { animation-name: skt-in-up; }
  .skt-leaving .skt-card { animation-name: skt-out-down; }
  @keyframes skt-in-up { from { opacity: 0; transform: translateY(12px); } }
  @keyframes skt-out-down { to { opacity: 0; transform: translateY(12px); } }
}

/* Touch: tap targets of 44px, the size the rest of the v2 site uses. */
@media (pointer: coarse) {
  .skt-close { width: 44px; height: 44px; margin: -10px -8px -10px 0; }
  .skt-action { min-height: 40px; padding: 0 14px; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .skt-card,
  .skt-card.skt-bump { animation: skt-fade-in 0.12s linear; }
  .skt-leaving .skt-card,
  .skt-swiped-right .skt-card,
  .skt-swiped-left .skt-card { animation: skt-fade-out 0.12s linear forwards; }
  .skt-item.skt-leaving { transition: none; }
  .skt-timer { display: none; }
  .skt-spinner { animation: none; border-right-color: currentColor; opacity: 0.6; }
}

@media print {
  .skt-stack { display: none !important; }
}
