/* ==========================================================================
   chiirp-toast
   ==========================================================================
   The toast is the same colour as the app frame, with a square right edge
   pinned to the accent gutter, so it reads as the rail swelling inward rather
   than a card dropped on top. Everything is driven from the existing theme
   tokens — this file introduces no new colours.

   Paired with src/static/js/toast/. See that folder's README.md.
   ========================================================================== */

:root {
  /* The shell IS the frame. In dark mode the frame is --accent-dark, which is
     what makes the collapsed state read as a literal black island.
     Every token is read with a fallback: this package also loads on the signup
     page, which is standalone and never pulls main.css, so it cannot assume the
     app's token set exists. Defaults are main.css's own values. */
  --ct-frame: hsl(var(--accent-component, 193 70% 39%));
  --ct-on-frame: #fff;

  /* Status colour lives in the chip, not the shell, so the shell stays fused
     to the frame. --success-component is set to the accent in this codebase, so
     success is pinned to the green the app already uses for live / ok /
     checked states (agents.css) rather than inheriting the brand teal. */
  --ct-success: hsl(142 71% 40%);
  --ct-info: hsl(217 91% 55%);
  --ct-warning: hsl(var(--warning-component, 43 96% 56%));
  --ct-error: hsl(var(--destructive-component, 0 84% 60%));

  --ct-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ct-ease-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ct-ease-in: cubic-bezier(0.4, 0, 1, 1);
}

.dark {
  --ct-frame: hsl(var(--accent-dark, 193 25% 12%));
  --ct-success: hsl(142 66% 46%);
}

/* ── stage ───────────────────────────────────────────────────────────────
   Parked by JS so its local x = 720 lands on the frame's outer edge.
   overflow:visible lets the rail run past the stage instead of ending in a
   filter fade — a seam there would give the whole trick away. */
.ct-stage {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 720px;
  height: 520px;
  z-index: 10000;
  pointer-events: none;
  display: none;
}
.ct-stage.ct-on { display: block; }
.ct-svg { position: absolute; inset: 0; overflow: visible; }
.ct-shape { fill: var(--ct-frame); }

/* ── card: the unfiltered layer the copy rides on ────────────────────────
   It cannot live inside the SVG (the metaball would eat the text), so it is a
   positioned div the engine keeps in step with the shape underneath. */
.ct-card {
  position: absolute;
  display: flex;
  align-items: stretch;
  color: var(--ct-on-frame);
  opacity: 0;
  pointer-events: none;
  transform-origin: right center;
  will-change: transform;
  font-family: 'Inter', -apple-system, 'SF Pro Text', system-ui, sans-serif;
  /* The card is sized by the engine, frame by frame, to match the shape drawn
     under it. Hover lifts the line clamp instantly — the copy is at its full
     height on the first frame — while the shell eases open over ~190ms, so
     without this the text hangs outside the shape for the whole opening. It
     clips instead, and the copy is revealed as the shell grows to meet it. */
  overflow: hidden;
}
.ct-card.ct-interactive { pointer-events: auto; cursor: pointer; }

.ct-body {
  display: flex;
  align-items: center;
  gap: 11px;
  /* flex:none is load-bearing when measuring — inside a sized parent the body
     shrinks to fit before it can be measured, and long copy collapses to one
     word per line. */
  flex: none;
  padding: 0 20px 0 13px;
  width: max-content;
  max-width: 392px;
}
.ct-card.ct-fixed { }
.ct-card.ct-fixed .ct-body {
  flex: 1;
  min-width: 0;
  width: auto;
  max-width: none;
}
/* Copy that overruns is clamped to a line; hovering expands that one shell and
   freezes its clock so it cannot expire while you are reading. */
/* One line by default: a status line reads at a glance and a stack of them
   stays uniform. */
.ct-card.ct-fixed .ct-msg {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* ...but not when the message is the whole point. An error is the one kind of
   toast the reader has to be able to act on, so it wraps up front instead of
   making them hover to find out what went wrong. Capped with -webkit-line-clamp
   so a runaway backend string cannot grow the shell without bound; the rest is
   still reachable on hover. */
.ct-card.ct-fixed.ct-multiline .ct-msg {
  white-space: normal;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: var(--ct-lines, 3);
  line-clamp: var(--ct-lines, 3);
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Hover lifts the clamp. Both selectors below are needed: the second has to
   carry .ct-fixed.ct-multiline as well, because the clamp rule above is four
   classes deep and a three-class override loses to it — the shell would grow on
   hover while the text stayed clipped, which is worse than not expanding at
   all (dead space AND unreadable). */
.ct-card.ct-expanded .ct-msg {
  white-space: normal;
  -webkit-line-clamp: unset;
  line-clamp: unset;
  display: block;
}
.ct-card.ct-fixed.ct-multiline.ct-expanded .ct-msg {
  -webkit-line-clamp: unset;
  line-clamp: unset;
  display: block;
  overflow: visible;
}

/* ── chip + countdown ring ───────────────────────────────────────────────
   The timer is a ring around the icon rather than a bar under the copy. It is
   driven per frame from the same clock as the shell, so it cannot drift out of
   sync and hovering pauses it for free. */
.ct-chip-wrap {
  position: relative;
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
}
.ct-ring {
  position: absolute;
  inset: 0;
  width: 34px;
  height: 34px;
  transform: rotate(-90deg);
  overflow: visible;
}
.ct-ring circle { fill: none; stroke-width: 2.5; }
.ct-ring-track { stroke: rgba(255, 255, 255, 0.24); }
.ct-ring-fill { stroke: #fff; stroke-linecap: round; }

.ct-chip {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--ct-info);
  color: #fff;
}
.ct-chip svg { width: 14px; height: 14px; }
.ct-chip.ct-spin svg { animation: ct-spin 1s linear infinite; }
@keyframes ct-spin { to { transform: rotate(360deg); } }

.ct-card[data-type="success"] .ct-chip { background: var(--ct-success); }
.ct-card[data-type="info"]    .ct-chip { background: var(--ct-info); }
.ct-card[data-type="warning"] .ct-chip { background: var(--ct-warning); color: #231a00; }
.ct-card[data-type="error"]   .ct-chip { background: var(--ct-error); }

/* ── copy ────────────────────────────────────────────────────────────────*/
.ct-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  transition: opacity 0.18s var(--ct-ease-in);
}
.ct-title { display: flex; align-items: center; }
.ct-name {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ct-msg { font-size: 12px; font-weight: 500; opacity: 0.82; line-height: 1.42; }
.ct-count {
  display: inline-grid;
  place-items: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin-left: 6px;
  border-radius: 100px;
  background: rgba(255, 255, 255, 0.26);
  font-size: 9.5px;
  font-weight: 800;
  flex: none;
}

/* ── dismiss ─────────────────────────────────────────────────────────────*/
.ct-dismiss {
  flex: none;
  align-self: stretch;
  width: 38px;
  padding: 0;
  border: none;
  border-left: 1px solid rgba(255, 255, 255, 0.22);
  background: transparent;
  color: inherit;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.16s var(--ct-ease-out), opacity 0.16s var(--ct-ease-in);
}
.ct-dismiss:hover { background: rgba(255, 255, 255, 0.17); }
.ct-dismiss:active { background: rgba(255, 255, 255, 0.26); }
.ct-dismiss:focus-visible { outline: 2px solid #fff; outline-offset: -4px; }
.ct-dismiss svg { width: 17px; height: 17px; transition: transform 0.22s var(--ct-spring); }
.ct-dismiss:hover svg { transform: translateX(4px); }

/* ── live activity ───────────────────────────────────────────────────────*/
.ct-track {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.2);
}
.ct-bar {
  height: 100%;
  background: #fff;
  opacity: 0.9;
  border-radius: 0 2px 2px 0;
  transition: width 0.22s linear;
}
/* counters must not jitter as they tick */
.ct-msg { font-variant-numeric: tabular-nums; }

/* ── screen readers ──────────────────────────────────────────────────────
   The stage is aria-hidden, so the words reach assistive tech here instead. */
.ct-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .ct-chip.ct-spin svg { animation: none; }
  .ct-dismiss svg,
  .ct-text { transition: none; }
}
