/* ============================================
   Alert — inline notification banner.

   Lightweight inline surface for notice/warning/success/critical
   context. Sits between snackbar (modal-ish backend-error tunnel)
   and a plain message: the host drops it inline in a chat thread,
   a settings pane, or any content surface.

   Severity is communicated by the icon glyph and copy ONLY — every
   variant uses the same neutral surface and ink. `--md-sys-color-error*`
   is forbidden in components (POLICIES.md rule 3a); status pastels
   are not part of this design system.

   Grid:
     icon · body · action-slot · close
   The icon column and close column are auto-sized; the body fills.
   ============================================ */

.alert {
  /* Component-local vars — neutral surface, border, and ink for every
     severity (matches the rest of the design system). Severity carries
     hue ONLY on the icon and its chip — this is the targeted exception
     to the "no hue for severity" rule, scoped tightly so the alert
     reads as chrome with a glanceable severity marker, not a loud
     full-banner tint. Defaults are info; .alert--{severity} swaps the
     icon vars. */
  --alert-bg: var(--md-sys-color-surface-container-high);
  --alert-border: var(--md-sys-color-outline-variant);
  --alert-ink: var(--md-sys-color-on-surface);
  --alert-ink-soft: var(--md-sys-color-on-surface-variant);
  --alert-icon-ink: var(--xm-alert-info-ink);
  --alert-icon-chip: var(--xm-alert-info-chip);

  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
  background: var(--alert-bg);
  border: 1px solid var(--alert-border);
  border-radius: var(--md-sys-shape-corner-medium);
  color: var(--alert-ink);
  font-family: var(--md-sys-typescale-body-medium-font);
  animation: alert-in var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard) both;
}
.alert--static { animation: none; }

@keyframes alert-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Severity modifiers — swap ONLY the icon's ink and chip. Surface,
   border, and body text stay neutral. */
.alert--info {
  --alert-icon-ink: var(--xm-alert-info-ink);
  --alert-icon-chip: var(--xm-alert-info-chip);
}
.alert--success {
  --alert-icon-ink: var(--xm-alert-success-ink);
  --alert-icon-chip: var(--xm-alert-success-chip);
}
.alert--warning {
  --alert-icon-ink: var(--xm-alert-warning-ink);
  --alert-icon-chip: var(--xm-alert-warning-chip);
}
.alert--critical {
  --alert-icon-ink: var(--xm-alert-critical-ink);
  --alert-icon-chip: var(--xm-alert-critical-chip);
}

/* ── Prominent / banner modifier (Story 4.6) ───────────────────────────
   A high-importance, persistent layout. Changes PROMINENCE / LAYOUT ONLY:
   wider full-width feel, larger padding, a left severity accent rail, and a
   larger icon chip — while the body surface stays NEUTRAL and the per-severity
   hue stays scoped to the icon chip + ink + the rail (the same --alert-icon-*
   mechanism, the sole sanctioned severity-hue exception). No new severity
   hues, no --md-sys-color-error*, no full-banner tint. The contract (severity
   model, slots, events) is unchanged. */
.alert--prominent {
  padding: var(--s-5) var(--s-5) var(--s-5) var(--s-6);
  border-radius: var(--md-sys-shape-corner-large);
  /* The left severity rail — a hairline-respecting accent band drawn from the
     per-severity chip, scoped to the edge so the body reads neutral. 3px is a
     decorative rail, not a border (borders stay hairline; 2px is focus/drag). */
  border-left: 3px solid var(--alert-icon-chip);
  column-gap: var(--s-4);
}
.alert--prominent .alert__icon {
  width: 40px;
  height: 40px;
  align-self: start;
}
.alert--prominent .alert__heading {
  font-size: var(--md-sys-typescale-body-large-size);
}
.alert--prominent .alert__text {
  font-size: var(--md-sys-typescale-body-medium-size);
}
/* In the banner layout the action drops below the body so the message has the
   full row width — a persistent banner reads as a block, not a one-liner. */
.alert--prominent .alert__action {
  grid-column: 2 / 3;
  grid-row: 2;
  justify-content: flex-start;
  margin-top: var(--s-1);
}

.alert__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--md-sys-shape-corner-small);
  /* Per-severity tint chip behind the glyph — the ONLY hued region in
     the alert. Sits on top of the neutral alert surface. */
  background: color-mix(in oklab, var(--alert-icon-chip) 38%, transparent);
  color: var(--alert-icon-ink);
  flex-shrink: 0;
}

.alert__body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-0-5);
}
.alert__heading {
  font-size: var(--md-sys-typescale-body-medium-size);
  font-weight: 600;
  color: var(--alert-ink);
  /* Heading wraps when narrow rather than truncating — alerts are read,
     not glanced at like snackbars. */
  text-wrap: pretty;
}
.alert__text {
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: 1.45;
  color: var(--alert-ink-soft);
  text-wrap: pretty;
}
.alert__text.is-empty { display: none; }
.alert__heading.is-empty { display: none; }

.alert__action {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.alert__action.is-empty { display: none; }

.alert__close {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--alert-ink-soft);
  width: 28px;
  height: 28px;
  border-radius: var(--md-sys-shape-corner-small);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard),
    color var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
  flex-shrink: 0;
}
.alert__close:hover {
  background: color-mix(in oklab, var(--alert-ink) 10%, transparent);
  color: var(--alert-ink);
}
.alert__close:focus-visible {
  outline: none;
  box-shadow: var(--xm-state-focus-ring);
}

/* Compact: when the row gets narrow, drop the action below the body
   so nothing wraps awkwardly. The dismiss stays inline. The 520px literal
   mirrors --xm-breakpoint-sm (styles/_layout.css) — @media can't read the
   token (docs/adr/0001), so the literal is the source-of-truth's echo. */
@media (max-width: 520px) {
  .alert {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    row-gap: var(--s-2);
  }
  .alert__action {
    grid-column: 2 / -1;
    justify-content: flex-end;
  }
}
