/*
 * Dialogs (README "Dialogs", D-08, S-07, A-10, A-19): native <dialog> opened with showModal().
 * Scrim neutral-900 62% into bg; panel 480–640px, radius 32px, padding 30px, --shadow-lg; title
 * 24px/700; close button is a 38px circle on surface (44px on phones). On phones the panel becomes a bottom sheet,
 * or a full screen view with .dialog--fullscreen-mobile (M-03 signature).
 */
@layer components {
  .dialog {
    width: 560px;
    max-width: calc(100vw - 32px);
    max-height: calc(100dvh - 32px);
    padding: 0;
    overflow: visible;
    border: 0;
    background: transparent;
    color: var(--color-text);
  }
  .dialog--sm { width: 480px; }
  .dialog--lg { width: 620px; }
  .dialog--xl { width: 640px; }

  .dialog::backdrop { background: var(--scrim); }

  .dialog[open] { animation: dialog-in var(--motion-base) var(--ease-standard); }
  .dialog[open]::backdrop { animation: backdrop-in var(--motion-base) var(--ease-standard); }

  .dialog__panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-height: calc(100dvh - 32px);
    padding: 30px;
    overflow-y: auto;
    border-radius: var(--radius-dialog);
    background: var(--color-bg);
    box-shadow: var(--shadow-lg);
  }
  .dialog--compact .dialog__panel { gap: 18px; }

  .dialog__head {
    display: flex;
    align-items: flex-start;
    gap: 16px;
  }
  .dialog__heading { flex: 1; display: flex; flex-direction: column; gap: 6px; }
  .dialog__title {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.2;
  }
  .dialog__desc { font-size: 14px; line-height: 1.55; color: var(--color-neutral-800); text-wrap: pretty; }

  .dialog__close {
    width: 38px;
    height: 38px;
    flex: none;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 18px;
  }
  .dialog__close:hover { background: var(--color-neutral-300); }

  .dialog__body {
    display: flex;
    flex-direction: column;
    gap: 20px;
    font-size: 14.5px;
  }

  /* The buttons sit one panel gap (20px) under the last block (A-03, A-04, A-05 · add); a footer
     with a foot-note gets 4px more (A-10, A-19). */
  .dialog__foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
  }
  .dialog__foot:has(.dialog__foot-note) { padding-top: 4px; }
  .dialog__foot-note {
    flex: 1;
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--color-neutral-700);
  }

  /* "You are signing" summary box (D-08) */
  .signing-target {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-radius: 20px;
    background: var(--color-blue-soft);
    color: var(--color-blue-deep);
  }
  .signing-target .icon { font-size: 22px; }
  .signing-target__text { display: flex; flex-direction: column; gap: 2px; }
  .signing-target__label { font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
  .signing-target__title { font-size: 16px; font-weight: 700; color: var(--color-text); }
  .signing-target__meta { font-size: 13px; font-weight: 600; }

  /* No scale: the signature pad measures its canvas when the dialog opens. */
  @keyframes dialog-in {
    from { opacity: 0; transform: translateY(8px); }
  }
  @keyframes backdrop-in {
    from { opacity: 0; }
  }
  @keyframes dialog-sheet-in {
    from { opacity: 0; transform: translateY(24px); }
  }

  @media (prefers-reduced-motion: reduce) {
    .dialog[open],
    .dialog[open]::backdrop { animation: none; }
  }

  @media (max-width: 767px) {
    .dialog,
    .dialog--sm,
    .dialog--lg,
    .dialog--xl {
      width: 100vw;
      max-width: 100vw;
      margin: auto 0 0;
    }
    /* A bottom sheet rises from the bottom edge. */
    .dialog[open] { animation-name: dialog-sheet-in; }
    .dialog__panel {
      padding: 22px 18px max(26px, env(safe-area-inset-bottom));
      border-radius: var(--radius-card) var(--radius-card) 0 0;
    }
    .dialog__close { width: 44px; height: 44px; } /* phone hit target */
    .dialog__title { font-size: 22px; }
    .signing-target { padding: 12px 14px; border-radius: 18px; }
    .signing-target > .icon { display: none; }
    .signing-target__title { font-size: 15px; }
    .dialog__foot { flex-wrap: wrap; }
    .dialog__foot-note { flex-basis: 100%; text-align: center; }
    .dialog__foot .btn { flex: 1; }

    .dialog--fullscreen-mobile {
      height: 100dvh;
      max-height: 100dvh;
      margin: 0;
    }
    .dialog--fullscreen-mobile .dialog__panel {
      height: 100%;
      max-height: 100dvh;
      border-radius: 0;
      box-shadow: none;
      padding-top: max(6px, env(safe-area-inset-top)); /* M-03: the × row starts like the header row */
      padding-bottom: max(30px, env(safe-area-inset-bottom)); /* M-03: 30px under "Sign & Acknowledge" */
    }
    .dialog--fullscreen-mobile .dialog__panel { gap: 14px; }
    .dialog--fullscreen-mobile .dialog__head { flex-direction: column; gap: 14px; }
    .dialog--fullscreen-mobile .dialog__close { order: -1; font-size: 19px; }
    .dialog--fullscreen-mobile .dialog__title { font-size: 26px; letter-spacing: -0.02em; line-height: 1.08; }
    /* M-03: the signature pad takes the remaining height; the × button is the way out. */
    .dialog--fullscreen-mobile .dialog__panel > form,
    .dialog--fullscreen-mobile .signature { flex: 1; display: flex; flex-direction: column; }
    .dialog--fullscreen-mobile .signature { gap: 14px; }
    .dialog--fullscreen-mobile .signature-pad { flex: 1; min-height: 300px; }
    .dialog--fullscreen-mobile .signature__foot .btn--secondary { display: none; }
  }
}
