/* Modal — the reusable dialog shell (components/modal.js).
 *
 * The backdrop is a blurred, dimmed page: a light tint plus
 * `backdrop-filter: blur(var(--backdrop-blur))`. When backdrop-filter is
 * unsupported the @supports block below falls back to a heavier solid dim so
 * the page behind still reads as out of focus. The panel scrolls internally;
 * on phones it becomes a near-full-screen bottom sheet, safe-area aware.
 *
 * Colour, type, spacing, radius and motion come only from tokens.css:
 * --backdrop-dim, --backdrop-solid, --backdrop-blur, --modal-surface,
 * --modal-border, --modal-radius, --modal-shadow, --modal-pad, --modal-max-w.
 * No literal colours anywhere here.
 */

dialog.modal {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  max-width: min(var(--modal-max-w), calc(100vw - var(--space-6)));
  max-height: calc(100dvh - var(--space-8));
  width: 100%;
  overflow: visible;
}

/* The page behind: dimmed first, blurred where supported. */
dialog.modal::backdrop {
  background: var(--backdrop-solid);
}

@supports (backdrop-filter: blur(2px)) {
  dialog.modal::backdrop {
    background: var(--backdrop-dim);
    backdrop-filter: blur(var(--backdrop-blur));
    -webkit-backdrop-filter: blur(var(--backdrop-blur));
  }
}

.modal-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: calc(100dvh - var(--space-8));
  background: var(--modal-surface);
  border: 1px solid var(--modal-border);
  border-radius: var(--modal-radius);
  box-shadow: var(--modal-shadow);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--modal-pad) var(--modal-pad) var(--space-3);
  flex: 0 0 auto;
}

.modal-title {
  margin: 0;
  font-size: var(--modal-title-size);
  font-weight: var(--fw-semibold);
  color: var(--ink);
}

.modal-close {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-section);
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius);
  /* 44 px hit area without a 44 px glyph. */
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--ink);
  background: var(--panel-hover);
}

.modal-close:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}

/* The body scrolls; the head and the panel chrome stay put. */
.modal-body {
  padding: 0 var(--modal-pad) var(--modal-pad);
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
  flex: 1 1 auto;
}

/* ---- phones: a near-full-screen bottom sheet, safe-area aware ---------- */

@media (max-width: 767.98px) {
  dialog.modal {
    max-width: 100%;
    width: 100%;
    margin: auto auto 0;
    max-height: calc(100dvh - var(--space-6));
  }

  .modal-panel {
    max-height: calc(100dvh - var(--space-6));
    border-radius: var(--modal-radius) var(--modal-radius) 0 0;
    border-bottom: 0;
  }

  .modal-head {
    padding-top: var(--space-4);
  }

  .modal-body {
    padding-bottom: max(var(--modal-pad), var(--safe-bottom));
  }
}
