/* Feedback layer: toasts, confirmations, busy buttons, progress, loaders,
   alerts, removals. Motion is short and purposeful; all of it is disabled by
   prefers-reduced-motion. Tokens come from app.css. */

/* ---------- Top loading bar ---------- */
.top-loader { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 300; pointer-events: none;
  background: var(--brand); transform-origin: left; transform: scaleX(0); opacity: 0; }
.top-loader.active { opacity: 1; animation: loader-run 2.4s cubic-bezier(.1, .7, .2, 1) forwards; }
.top-loader.done { animation: none; transform: scaleX(1); opacity: 0; transition: transform .2s ease, opacity .3s ease .15s; }
@keyframes loader-run { from { transform: scaleX(0); } to { transform: scaleX(.86); } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 72px; display: flex; flex-direction: column; gap: 8px; z-index: 250; width: min(380px, calc(100vw - 32px)); }
.toast { position: relative; overflow: hidden; display: grid; grid-template-columns: auto 1fr auto auto; align-items: start; gap: 10px;
  padding: 11px 12px 12px; border-radius: 8px; background: var(--surface); color: var(--text); border: 1px solid var(--line);
  box-shadow: var(--pop); font-size: 13.5px; animation: toast-in .24s cubic-bezier(.2, .9, .3, 1.2); }
.toast-leave { animation: toast-out .2s ease forwards; }
.toast-ico { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; margin-top: 1px; }
.toast-ico svg { width: 14px; height: 14px; }
.toast-success .toast-ico { background: var(--ok-soft); color: var(--ok); }
.toast-error .toast-ico { background: var(--err-soft); color: var(--err); }
.toast-warning .toast-ico { background: var(--warn-soft); color: var(--warn); }
.toast-info .toast-ico { background: var(--info-soft); color: var(--info); }
.toast-body { display: grid; gap: 1px; min-width: 0; }
.toast-body b { font-weight: 600; }
.toast-body span { color: var(--muted); }
.toast-body b + span { font-size: 13px; }
.toast-body:not(:has(b)) span { color: var(--text); }
.toast-action { border: 0; background: none; color: var(--brand); font-weight: 600; cursor: pointer; padding: 1px 4px; border-radius: 4px; }
.toast-action:hover { background: var(--brand-soft); }
.toast-close { border: 0; background: none; color: var(--faint); cursor: pointer; padding: 2px; border-radius: 4px; display: grid; }
.toast-close:hover { color: var(--text); background: var(--surface-2); }
.toast-close svg { width: 14px; height: 14px; }
.toast-timer { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; transform-origin: left; background: currentColor; opacity: .25;
  animation: toast-timer linear forwards; }
.toast-success .toast-timer { color: var(--ok); }
.toast-error .toast-timer { color: var(--err); }
.toast-warning .toast-timer { color: var(--warn); }
.toast-info .toast-timer { color: var(--info); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
@keyframes toast-timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ---------- Confirmation ---------- */
.confirm-backdrop { position: fixed; inset: 0; z-index: 280; background: var(--overlay); display: grid; place-items: center; padding: 20px;
  animation: fade-in .15s ease; }
.confirm-backdrop.leaving { animation: fade-out .15s ease forwards; }
.confirm { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--pop);
  padding: 22px; display: grid; gap: 10px; animation: pop-in .2s cubic-bezier(.2, .9, .3, 1.2); }
.confirm h2 { font-size: 17px; font-weight: 600; }
.confirm p { margin: 0; color: var(--muted); }
.confirm .field { margin: 6px 0 0; }
.confirm .field span { font-size: 13px; color: var(--muted); }
.confirm-ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--info-soft); color: var(--info); }
.confirm-ico.danger { background: var(--err-soft); color: var(--err); }
.confirm-ico svg { width: 20px; height: 20px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--err) 88%, black); }
.btn-danger:disabled { opacity: .45; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(.97); } }

/* ---------- Busy buttons ---------- */
.btn.is-busy { cursor: progress; justify-content: center; }
.btn.is-done { justify-content: center; color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: var(--ok-soft); }
.btn.primary.is-done { color: #fff; background: var(--ok); border-color: var(--ok); }
.btn.is-error { animation: shake .4s ease; }
.btn.is-busy .spin, .spin.dark { border-color: color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor; }
.draw-check { width: 15px; height: 15px; flex: none; }
.draw-check path { stroke-dasharray: 22; stroke-dashoffset: 22; animation: draw .35s ease forwards .05s; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes shake { 0%, 100% { transform: none; } 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }

/* Large success mark */
.success-mark { width: 44px; height: 44px; flex: none; }
.success-mark circle { stroke: var(--ok); stroke-width: 3; stroke-dasharray: 145; stroke-dashoffset: 145; animation: draw .5s ease forwards; }
.success-mark path { stroke: var(--ok); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw .3s ease forwards .45s; }
.result-ok { display: flex; gap: 14px; align-items: center; padding: 14px; margin-bottom: 12px; border-radius: 8px; background: var(--ok-soft); animation: pop-in .25s ease; }
.result-ok b { display: block; color: var(--ok); }
.result-ok span { color: var(--muted); font-size: 13px; }
.shake-in { animation: shake .4s ease; }

/* ---------- Insert / remove ---------- */
.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 30% { background-color: var(--brand-soft); box-shadow: 0 0 0 2px var(--brand-soft); } 100% { background-color: transparent; box-shadow: 0 0 0 0 transparent; } }
.card.flash, .app-card.flash { animation: flash-card 1.6s ease; }
@keyframes flash-card { 0%, 30% { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); } 100% { border-color: var(--line); box-shadow: none; } }
.leaving { opacity: 0; transform: translateX(10px); overflow: hidden; transition: opacity .2s ease, transform .2s ease, height .25s ease .1s, padding .25s ease .1s, margin .25s ease .1s; }
.app-card.leaving { transform: scale(.96); }
tr.leaving td { padding-top: 0; padding-bottom: 0; transition: padding .25s ease .1s; }

/* ---------- Task tray ---------- */
.task-tray { position: fixed; left: 252px; bottom: 16px; z-index: 240; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 32px)); }
.task { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--pop); padding: 12px 14px; animation: toast-in .25s ease; }
.task.leaving { opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; }
.task-head { display: flex; align-items: center; gap: 10px; }
.task-head b { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-pct { font: 500 12px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.task-done .task-pct { color: var(--ok); }
.task-failed .task-pct { color: var(--err); }
.task-state { width: 16px; height: 16px; display: grid; place-items: center; color: var(--ok); }
.task-state.err { color: var(--err); }
.task-state svg { width: 16px; height: 16px; }
.progress { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; margin: 10px 0 8px; }
.progress > i { display: block; height: 100%; background: var(--brand); transform-origin: left; transform: scaleX(0); transition: transform .5s cubic-bezier(.3, .8, .3, 1); position: relative; }
.task:not(.task-done):not(.task-failed) .progress > i::after { content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .45), transparent); animation: sheen 1.2s linear infinite; }
.task-done .progress > i { background: var(--ok); }
.task-failed .progress > i { background: var(--err); }
@keyframes sheen { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.task-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; font-size: 12.5px; color: var(--faint); }
.task-steps li { display: flex; align-items: center; gap: 8px; }
.task-steps li::before { content: ""; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid var(--line-strong); flex: none; }
.task-steps li.now { color: var(--text); }
.task-steps li.now::before { border-color: var(--brand); border-top-color: transparent; animation: rot .7s linear infinite; }
.task-steps li.ok { color: var(--muted); }
.task-steps li.ok::before { background: var(--ok); border-color: var(--ok); }
.task-steps li.failed { color: var(--err); }
.task-steps li.failed::before { background: var(--err); border-color: var(--err); }

/* ---------- Alerts ---------- */
.alert { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 12px; padding: 11px 12px 11px 14px; margin-bottom: 14px;
  border-radius: 8px; border: 1px solid; font-size: 13.5px; animation: pop-in .25s ease; }
.alert.leaving { margin-bottom: 0; padding-top: 0; padding-bottom: 0; border-width: 0; }
.alert-body { display: flex; flex-wrap: wrap; gap: 2px 8px; min-width: 0; }
.alert-body b { font-weight: 600; }
.alert-body span { color: var(--muted); }
.alert-ico svg { width: 17px; height: 17px; }
.alert-info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 22%, transparent); }
.alert-info .alert-ico { color: var(--info); }
.alert-success { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 22%, transparent); }
.alert-success .alert-ico { color: var(--ok); }
.alert-warning { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert-warning .alert-ico { color: var(--warn); }
.alert-error { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 25%, transparent); }
.alert-error .alert-ico { color: var(--err); }
.alert .btn { background: var(--surface); }
.alert-close { border: 0; background: none; color: var(--faint); cursor: pointer; padding: 3px; border-radius: 4px; display: grid; }
.alert-close:hover { color: var(--text); }
.alert-close svg { width: 14px; height: 14px; }

/* ---------- Skeletons ---------- */
.skeleton { display: grid; gap: 10px; padding: 4px 0; }
.sk-line { display: block; height: 12px; border-radius: 4px;
  background: linear-gradient(90deg, var(--surface-2) 25%, color-mix(in srgb, var(--surface-2) 55%, var(--surface)) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.3s ease infinite; }
.sk-line.short { width: 60%; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ---------- Forms ---------- */
.input.invalid { border-color: var(--err); box-shadow: 0 0 0 3px var(--err-soft); }
.shake { animation: shake .4s ease; }
.field-error { color: var(--err); font-size: 12.5px; display: flex; gap: 6px; align-items: center; animation: pop-in .2s ease; }
.field-error::before { content: "!"; width: 14px; height: 14px; border-radius: 50%; background: var(--err); color: #fff; font: 700 10px var(--sans); display: grid; place-items: center; }
.row .field-error { flex-basis: 100%; }

/* ---------- Assistant typing ---------- */
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: none; } 40% { opacity: 1; transform: translateY(-2px); } }

/* Deploying app card */
.app-card.deploying { border-style: dashed; }
.badge.tone-deploy { background: var(--brand-soft); color: var(--brand); }
.badge.tone-deploy .dot { background: var(--brand); animation: pulse 1.2s ease infinite; }
@keyframes pulse { 50% { opacity: .3; } }

@media (max-width: 860px) { .task-tray { left: 16px; bottom: 72px; } .toasts { bottom: 72px; right: 16px; } }
@media (prefers-reduced-motion: reduce) {
  .top-loader.active { animation: none; transform: scaleX(.86); }
  .toast, .confirm, .confirm-backdrop, .alert, .task, .flash, .card.flash, .shake, .btn.is-error, .sk-line, .typing i, .task-steps li.now::before, .progress > i::after { animation: none !important; }
  .draw-check path, .success-mark circle, .success-mark path { animation: none; stroke-dashoffset: 0; }
  .leaving, .progress > i { transition: none; }
}
