/* ==========================================================================
   Alert — inline messages. Flat; neutral until it gets a color.

   <div class="alert alert-amber" role="status">
     <i class="mi mi-triangle-alert alert-icon"></i>
     <div class="alert-content">
       <div class="alert-title">Trial ends in 3 days</div>
       <p>Add a payment method to keep your workspace.</p>
       <div class="alert-actions">…buttons…</div>
     </div>
     <button class="btn-close" aria-label="Dismiss"></button>
   </div>

   Strengths: .alert-subtle · .alert-soft · (default) · .alert-solid · .alert-vivid · .alert-deep · .alert-outline
   .alert-sm · .alert-banner
   Plain text works too: <div class="alert">Saved. <button class="btn-close"></button></div>
   Close: moey.js closes it when its .btn-close is clicked (.alert-instant skips the fade)
   ========================================================================== */

.alert {
  --mo-alert-padding-x: 1rem;
  --mo-alert-padding-y: .875rem;
  --mo-alert-gap: .75rem;
  --mo-alert-font-size: .875rem;
  --mo-alert-icon-size: 1.125rem;
  --mo-alert-color: var(--mo-fg-body);                                   /* neutral until it gets a color */
  --mo-alert-bg: color-mix(in oklab, var(--mo-fg-body) 6%, transparent);
  --mo-alert-border: var(--mo-border-color);
  --mo-alert-icon-color: var(--mo-fg-2);
  --mo-alert-radius: var(--mo-radius-card);
  position: relative;
  display: block;
  padding: var(--mo-alert-padding-y) var(--mo-alert-padding-x);
  font-size: var(--mo-alert-font-size);
  line-height: 1.5;
  color: var(--mo-alert-color);
  background-color: var(--mo-alert-bg);
  border: var(--mo-surface-border-width) solid var(--mo-alert-border);
  border-radius: var(--mo-alert-radius);
}

/* Flex layout only with Moey's structure (icon / content / actions).
   Plain text and links placed directly inside flow normally. */
.alert:has(> .alert-icon, > .alert-content) {
  display: flex;
  align-items: flex-start;
  gap: var(--mo-alert-gap);
}

/* Icon lines up with the first line of text */
.alert-icon {
  flex-shrink: 0;
  margin-top: calc((var(--mo-alert-font-size) * 1.5 - var(--mo-alert-icon-size)) / 2);
  font-size: var(--mo-alert-icon-size);
  line-height: 1;
  color: var(--mo-alert-icon-color);
}
.alert-icon.mi { vertical-align: 0; }

.alert-content { flex: 1; min-width: 0; }
.alert-content > :last-child,
.alert > p:last-child { margin-bottom: 0; }
.alert p { margin: 0 0 .25rem; }
.alert ul, .alert ol { margin: .25rem 0; padding-inline-start: 1.25rem; }

.alert-title {
  margin: 0 0 .125rem;
  font-size: inherit;
  font-weight: var(--mo-font-weight-semibold);
  line-height: inherit;
}
/* A title on its own (no text under it) needs no gap */
.alert-title:last-child { margin-bottom: 0; }

.alert hr { margin: .75rem 0; border-color: color-mix(in oklab, currentcolor 20%, transparent); }

.alert-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .75rem;
}

/* Links read as part of the message */
.alert a:not([class*="btn"]) {
  font-weight: var(--mo-font-weight-semibold);
  color: inherit;
  text-decoration: underline;
  text-decoration-color: color-mix(in oklab, currentcolor 45%, transparent);
}
.alert a:not([class*="btn"]):hover { text-decoration-color: currentcolor; }

/* Fade out on dismiss: add .hiding, remove the element after the transition */
@media (prefers-reduced-motion: no-preference) {
  .alert:not(.alert-instant) { transition: opacity .15s linear, translate .15s var(--mo-ease); }
}
.alert.hiding { opacity: 0; translate: 0 -.25rem; pointer-events: none; }

/* Close button: top-right, aligned with the first line, pulled into the padding */
.alert > .btn-close {
  --mo-close-size: 1.75rem;
  --mo-close-icon: .875rem;
  margin-block: calc((var(--mo-alert-font-size) * 1.5 - var(--mo-close-size)) / 2);
  margin-inline: auto calc(var(--mo-alert-padding-x) * -.5);
}

/* Plain-text alert (no .alert-content): the close button pins itself top-right
   and the text makes room for it — no extra class needed. */
.alert:not(:has(> .alert-content)):has(> .btn-close) { padding-inline-end: calc(var(--mo-alert-padding-x) + 2rem); }
.alert:not(:has(> .alert-content)) > .btn-close {
  position: absolute;
  top: calc(var(--mo-alert-padding-y) + (var(--mo-alert-font-size) * 1.5 - var(--mo-close-size)) / 2);
  inset-inline-end: calc(var(--mo-alert-padding-x) * .5);
  margin: 0;
}

/* Colors & strengths ---------------------------------------------------------
   <div class="alert alert-amber"> (the soft default fill) · + .alert-subtle … .alert-deep */
:is(/*@colors alert*/), .alert:where(/*@themes*/) {
  --mo-alert-color: var(--mo-theme-fill-text);
  --mo-alert-bg: var(--mo-theme-fill);
  --mo-alert-border: var(--mo-theme-border);
  --mo-alert-icon-color: currentcolor;
}
/* Same as colored cards: accents inside a strong alert use its text color */
:is(/*@colors alert*/):not(.alert-outline),
.alert:where(/*@themes*/):not(.alert-outline) {
  --mo-accent: var(--mo-alert-color);
  --mo-accent-contrast: var(--mo-alert-bg);
  --mo-track: color-mix(in oklab, var(--mo-alert-color) 22%, transparent);
  --mo-check-mark: var(--mo-alert-mark, var(--mo-theme-fill-mark));   /* .alert-solid / -vivid / -deep set their own */
  --mo-check-dash: var(--mo-alert-dash, var(--mo-theme-fill-dash));
}
.alert-subtle, .alert-soft { --mo-alert-mark: var(--mo-check-on-text); --mo-alert-dash: var(--mo-dash-on-text); }
.alert-solid { --mo-alert-mark: var(--mo-theme-solid-mark); --mo-alert-dash: var(--mo-theme-solid-dash); }
.alert-vivid { --mo-alert-mark: var(--mo-theme-vivid-mark); --mo-alert-dash: var(--mo-theme-vivid-dash); }
.alert-deep  { --mo-alert-mark: var(--mo-theme-deep-mark);  --mo-alert-dash: var(--mo-theme-deep-dash); }
.alert-subtle { --mo-alert-color: var(--mo-theme-subtle-text); --mo-alert-bg: var(--mo-theme-subtle); --mo-alert-icon-color: var(--mo-theme-fg); }
.alert-soft   { --mo-alert-color: var(--mo-theme-soft-text);   --mo-alert-bg: var(--mo-theme-soft);   --mo-alert-icon-color: var(--mo-theme-fg); }
.alert-solid  { --mo-alert-color: var(--mo-theme-solid-text);  --mo-alert-bg: var(--mo-theme-solid);  --mo-alert-icon-color: currentcolor; }
.alert-vivid  { --mo-alert-color: var(--mo-theme-vivid-text);  --mo-alert-bg: var(--mo-theme-vivid);  --mo-alert-icon-color: currentcolor; }
.alert-deep   { --mo-alert-color: var(--mo-theme-deep-text);   --mo-alert-bg: var(--mo-theme-deep);   --mo-alert-icon-color: currentcolor; }
/* Outline — a border, no fill; body-colored text */
.alert-outline {
  --mo-alert-color: var(--mo-fg-body);
  --mo-alert-bg: transparent;
  --mo-alert-icon-color: var(--mo-theme-fg);
  border-width: var(--mo-border-width);
}
.alert-outline .alert-title { color: var(--mo-theme-fg-emphasis); }

/* Sizes & shapes ------------------------------------------------------------- */
.alert-sm {
  --mo-alert-padding-x: .75rem;
  --mo-alert-padding-y: .5rem;
  --mo-alert-gap: .5rem;
  --mo-alert-font-size: .8125rem;
  --mo-alert-icon-size: 1rem;
}
/* Full-width bar (top of a page or app): square corners, content centered */
.alert-banner {
  --mo-alert-radius: 0;
  align-items: center;
  justify-content: center;
}
.alert-banner > .alert-content { flex: 0 1 auto; }
.alert-banner > .alert-icon { margin-top: 0; }
.alert-banner > .btn-close { position: absolute; inset-inline-end: var(--mo-alert-padding-x); margin: 0; }

/* Inline code inside an alert takes the alert's text color (readable on every strength) */
.alert :not(pre) > code { color: inherit; background-color: color-mix(in oklab, currentColor 12%, transparent); }
