/* ============================================================================
 * COMPONENT — Alert
 * ----------------------------------------------------------------------------
 * Renderer: shared/components/alert.php
 *
 * A message about the page or the action just taken. Title on top, detail
 * underneath, dismiss at the trailing edge.
 *
 * Two looks, same markup:
 *
 *   .alert           tinted — the surface itself carries the status colour.
 *                    Louder, for the one message a screen is about.
 *   .alert--plain    neutral card, solid colour only in the icon badge.
 *                    Quieter, for a stack of messages or a toast, where four
 *                    tinted blocks in a row become noise.
 *
 * Colour never carries the meaning alone: every variant has its own icon too,
 * so the message still reads in greyscale and for a colour-blind reader.
 * ========================================================================== */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid transparent;
  border-radius: var(--r-xl);
  font-size: var(--fs-base);
  line-height: var(--lh-snug);
}

.alert + .alert,
.alert + .card,
.card + .alert { margin-block-start: var(--sp-3); }

/* The flash message sits above the page's own content, so it owns the space
   below it rather than relying on whatever comes next to add a margin. */
.alert.flash { margin-block-end: var(--sp-4); }

/* --------------------------------------------------------------------------
 * Parts
 * ----------------------------------------------------------------------- */

.alert__icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  inline-size: 26px;
  block-size: 26px;
  margin-block-start: 1px;
}

.alert__icon .icon {
  inline-size: 22px;
  block-size: 22px;
}

.alert__body {
  flex: 1 1 auto;
  min-inline-size: 0;
  padding-block: 2px;
}

.alert__title {
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
}

/* The detail line sits a step back from the title so the two are read in the
   right order at a glance. */
.alert__text {
  margin-block-start: 2px;
  font-size: var(--fs-sm);
  opacity: 0.85;
}

/* A single-line alert: no title, so the message is the title. */
.alert__body > .alert__text:only-child {
  margin-block-start: 0;
  font-size: var(--fs-base);
  opacity: 1;
}

.alert__close {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  inline-size: 28px;
  block-size: 28px;
  margin-block-start: 1px;
  margin-inline-end: calc(var(--sp-1) * -1);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: inherit;
  opacity: 0.5;
  cursor: pointer;
  transition: opacity var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease);
}

.alert__close:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.06);
}

/* --------------------------------------------------------------------------
 * Tinted (default)
 * --------------------------------------------------------------------------
 * The title takes the status colour and the body stays near-black: colouring
 * both makes the detail line hard to read, especially for amber.
 * ----------------------------------------------------------------------- */

.alert--info    { background: var(--info-soft);    border-color: var(--info); }
.alert--success { background: var(--success-soft); border-color: var(--success); }
.alert--warning { background: var(--warning-soft); border-color: var(--warning); }
.alert--danger  { background: var(--danger-soft);  border-color: var(--danger); }

.alert--info    .alert__icon, .alert--info    .alert__title { color: var(--info); }
.alert--success .alert__icon, .alert--success .alert__title { color: var(--success); }
.alert--warning .alert__icon, .alert--warning .alert__title { color: var(--warning); }
.alert--danger  .alert__icon, .alert--danger  .alert__title { color: var(--danger); }

.alert--info    .alert__text,
.alert--success .alert__text,
.alert--warning .alert__text,
.alert--danger  .alert__text { color: var(--ink); }

/* --------------------------------------------------------------------------
 * Plain — neutral card, solid icon badge
 * ----------------------------------------------------------------------- */

.alert--plain {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--sh-2);
}

.alert--plain .alert__title { color: var(--ink); }
.alert--plain .alert__text  { color: var(--ink-muted); }

/* Filled disc with the glyph knocked out in white. The existing stroke icons
   are reused as-is — there is no second, solid icon set to keep in step. */
.alert--plain .alert__icon {
  inline-size: 28px;
  block-size: 28px;
  border-radius: var(--r-full);
  color: var(--n-0);
}

.alert--plain .alert__icon .icon {
  inline-size: 17px;
  block-size: 17px;
  stroke-width: 2.6;
}

.alert--plain.alert--info    .alert__icon { background: var(--info); }
.alert--plain.alert--success .alert__icon { background: var(--success); }
.alert--plain.alert--warning .alert__icon { background: var(--warning); }
.alert--plain.alert--danger  .alert__icon { background: var(--danger); }

/* The disc already supplies the contrast; a border under it would double it. */
.alert--plain .alert__icon .icon { color: var(--n-0); }

/* --------------------------------------------------------------------------
 * Dark theme
 * --------------------------------------------------------------------------
 * A plain alert sitting on the page background disappears into it once the
 * canvas is dark, so it lifts to the raised surface; and the close button's
 * hover wash has to invert or it just darkens an already dark card.
 *
 * Two blocks, kept identical — same reason as tokens.css: a media query and a
 * plain selector cannot share one declaration list.
 * ----------------------------------------------------------------------- */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .alert--plain {
    background: var(--surface-raised);
  }
  :root:not([data-theme="light"]) .alert__close:hover {
    background: rgba(255, 255, 255, 0.08);
  }
}

/* KEEP IDENTICAL TO THE BLOCK ABOVE. */
:root[data-theme="dark"] .alert--plain {
  background: var(--surface-raised);
}
:root[data-theme="dark"] .alert__close:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* A flash on its way out — see autoDismissFlash() in ui.js. */
.alert.flash.is-leaving {
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity var(--dur-slow) var(--ease),
              transform var(--dur-slow) var(--ease);
}

@media (prefers-reduced-motion: reduce) {
  .alert.flash.is-leaving { transition: none; }
}
