/* ============================================================================
   MODAL — shared compound (single source of truth).
   A scrim-backed dialog surface: head (title + close) / body / footer, with
   entrance + exit motion driven by --mo-* tokens on the scrim. Self-contained
   on the CSS architecture (own @layer tokens / theme / components); import
   AFTER colors_and_type.css. Behaviour lives in _modal.js (focus trap, scrim,
   restart-safe motion); schema in _modal.config.js (window.FP_COMPOUNDS.modal).

   Used as an OVERLAY (Modal.open) — a fixed .modal-layer holds one .modal-scrim
   per open dialog — OR INLINE (.modal-scrim--inline) for showcases / embedding
   the surface in normal flow (the DS card thumbnail uses this).
   ============================================================================ */

@layer tokens {
  :root {
    /* Motion (read at play time on the scrim; governor-scaled, Inspector-tunable). */
    --mo-dur: 260ms;      /* @kind other */
    --mo-ease: cubic-bezier(0.16, 1, 0.3, 1);   /* @kind other */
    --mo-scrim-dur: 200ms;   /* @kind other */
    --mo-rise: 16px;      /* dialog enters from this far below its resting spot */
    --mo-scale: 0.97;     /* @kind other */

    /* Surface (literals that differ by theme → token + theme override). */
    --modal-scrim-bg: rgba(12, 24, 56, 0.44);
    --modal-shadow: 0 24px 60px -12px rgba(12, 24, 56, 0.32), 0 8px 20px -6px rgba(12, 24, 56, 0.18);
    --modal-bd: var(--color-border-default);
  }
}

@layer theme {
  [data-theme="dark"] {
    --modal-scrim-bg: rgba(2, 6, 18, 0.62);
    --modal-shadow: 0 24px 64px -12px rgba(0, 0, 0, 0.6), 0 8px 22px -6px rgba(0, 0, 0, 0.45);
    --modal-bd: var(--color-border-strong, var(--color-border-default));
  }
}

@layer components {
  /* The fixed stack the controller appends overlay scrims into. */
  .modal-layer {
    position: fixed;
    inset: 0;
    z-index: 1200;
    pointer-events: none;
  }
  .modal-layer:empty { display: none; }

  /* ── Scrim ───────────────────────────────────────────────────────────── */
  .modal-scrim {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: clamp(16px, 4vw, 48px);
    background: var(--modal-scrim-bg);
    -webkit-backdrop-filter: saturate(1) blur(1.5px);
    backdrop-filter: saturate(1) blur(1.5px);
    pointer-events: auto;
    opacity: 0;
    transition: opacity var(--mo-scrim-dur) ease-out;
    overflow-y: auto;
  }
  .modal-scrim.is-open { opacity: 1; }

  /* Inline showcase variant — sits in normal flow, no fixed positioning. */
  .modal-scrim--inline {
    position: relative;
    inset: auto;
    min-height: 0;
    border-radius: var(--radius-overlay, var(--radius-lg));
    opacity: 1;
    overflow: visible;
    background: transparent;            /* the host frames the dim; don't double it */
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    padding: 0;
  }

  /* ── Dialog surface ──────────────────────────────────────────────────── */
  .modal {
    width: 100%;
    max-width: 520px;            /* --md default; size modifiers below */
    max-height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--color-bg-surface);
    color: var(--color-fg-default);
    border: var(--bw-panel, 1px) solid var(--modal-bd);
    border-radius: var(--radius-overlay, var(--radius-lg));
    box-shadow: var(--modal-shadow);
    /* Entrance resting state (visible) — the controller animates FROM hidden so
       reduced-motion / print / no-JS show the dialog, not a blank box. */
    opacity: 1;
    transform: none;
    overflow: hidden;
  }
  .modal--sm { max-width: 420px; }
  .modal--md { max-width: 520px; }
  .modal--lg { max-width: 720px; }
  .modal--xl { max-width: 920px; }

  /* The controller stamps these while the scrim is mid-open / mid-close. The
     :not(.modal-scrim--inline) guard keeps the inline showcase surface visible
     (it never gets .is-open). */
  .modal-scrim:not(.is-open):not(.modal-scrim--inline) .modal {
    opacity: 0;
    transform: translateY(var(--mo-rise)) scale(var(--mo-scale));
  }
  .modal {
    transition: opacity var(--mo-dur) var(--mo-ease),
                transform var(--mo-dur) var(--mo-ease);
  }
  .modal-scrim--inline .modal { transition: none; opacity: 1; transform: none; }

  /* ── Head ────────────────────────────────────────────────────────────── */
  .modal__head {
    flex: none;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 20px 22px 14px;
  }
  .modal__head--bordered { border-bottom: var(--bw-line, 1px) solid var(--color-border-subtle, var(--color-border-default)); }
  .modal__titles { flex: 1; min-width: 0; }
  .modal__eyebrow {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-fg-tertiary);
    margin-bottom: 4px;
  }
  .modal__title {
    margin: 0;
    font-size: 19px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--color-fg-default);
    letter-spacing: -0.01em;
  }
  .modal__sub {
    margin: 6px 0 0;
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--color-fg-secondary);
  }

  /* Close button — matches the toast close hit-target vocabulary. */
  .modal__close {
    all: unset;
    cursor: pointer;
    user-select: none; -webkit-user-select: none;
    flex: none;
    position: relative;
    width: 30px; height: 30px;
    border-radius: 999px;
    display: inline-grid; place-items: center;
    color: var(--color-fg-tertiary);
    transition: background-color 120ms ease, color 120ms ease,
                box-shadow 220ms cubic-bezier(0.16, 1, 0.3, 1);
  }
  .modal__close i { font-size: 20px; line-height: 1; display: block; margin-top: -1px; }
  .modal__close:hover,
  .modal__close[data-state~="hover"] { background: var(--gov-color-neutral-100); color: var(--color-fg-default); }
  .modal__close:active,
  .modal__close[data-state~="pressed"] { background: var(--gov-color-neutral-200); }
  .modal__close:focus-visible,
  .modal__close[data-state~="focus"] { outline: none; box-shadow: var(--shadow-focus); }
  /* Touch: enlarge the TAP target to ≥44px without growing the visible 30px
     button — an invisible centred overlay, coarse-pointer only (mouse / pen keep
     the tight target, so the layout is untouched there). Shared vocabulary with
     the toast close. */
  @media (pointer: coarse) {
    .modal__close::after { content: ""; position: absolute; top: 50%; left: 50%;
      transform: translate(-50%, -50%); width: 100%; height: 100%;
      min-width: 44px; min-height: 44px; }
  }

  /* ── Body ────────────────────────────────────────────────────────────── */
  .modal__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 6px 22px 20px;
    font-size: 14px;
    line-height: 1.55;
    color: var(--color-fg-default);
  }
  .modal__body > :first-child { margin-top: 0; }
  .modal__body > :last-child { margin-bottom: 0; }

  /* ── Footer ──────────────────────────────────────────────────────────── */
  .modal__foot {
    flex: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 22px 18px;
    background: var(--modal-foot-bg, transparent);
  }
  /* Separator above the actions is OPT-IN (user round 7: no line by default —
     the padding already separates). Carries the old default rule; the Theme
     Lab bwLine "none" scope targets this class. */
  .modal__foot--bordered { border-top: var(--bw-line, 1px) solid var(--color-border-subtle, var(--color-border-default)); }
  .modal__foot--split { justify-content: space-between; }
  .modal__foot .btn { white-space: nowrap; }
  .modal__foot-note { font-size: 12px; color: var(--color-fg-tertiary); margin-right: auto; }
}
