<script lang="ts">
  import { toasts, dismissToast } from '$lib/toast';
</script>

<div class="toast-stack" aria-live="polite" aria-atomic="false">
  {#each $toasts as t (t.id)}
    <div class="toast lvl-{t.level}" role="status">
      <span class="msg">{t.message}</span>
      <button class="close" type="button" aria-label="dismiss" onclick={() => dismissToast(t.id)}
        >×</button
      >
    </div>
  {/each}
</div>

<style>
  .toast-stack {
    position: fixed;
    bottom: 18px;
    right: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
    pointer-events: none;
  }
  .toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 260px;
    max-width: 420px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--fg);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    font-size: 13px;
  }
  .toast.lvl-error {
    border-color: color-mix(in srgb, var(--err) 55%, transparent);
    background: color-mix(in srgb, var(--err) 12%, var(--bg-card));
  }
  .toast.lvl-warn {
    border-color: color-mix(in srgb, var(--warn) 55%, transparent);
  }
  .toast.lvl-success {
    border-color: color-mix(in srgb, var(--ok) 55%, transparent);
  }
  .msg {
    flex: 1;
    word-break: break-word;
  }
  .close {
    background: none;
    border: none;
    color: var(--fg-dim);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
  }
  .close:hover {
    color: var(--fg);
  }
</style>
