/*
 * Shared modal dialog.
 *
 * The element is only a frame: it holds no surface of its own, so the card
 * inside keeps its radius and its shadow against the backdrop. Sizing lives on
 * the dialog because the browser centres it, and the card fills what it is given.
 */
.fs-dialog {
  position: fixed;
  inset: 50% auto auto 50%;
  width: min(680px, calc(100vw - (2 * var(--fs-space-4))));
  max-width: none;
  max-height: calc(100vh - (2 * var(--fs-space-5)));
  margin: 0;
  padding: 0;
  overflow: visible;
  color: var(--fs-color-text);
  background: transparent;
  border: 0;
  transform: translate(-50%, -50%);
}

.fs-dialog::backdrop {
  background: color-mix(in srgb, var(--fs-palette-44) 48%, transparent);
}

/*
 * The card scrolls, not the dialog: the header names what is being asked and the
 * footer holds the answer, so neither may scroll out of reach of a long form.
 */
.fs-dialog__card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  max-height: calc(100vh - (2 * var(--fs-space-5)));
  overflow: hidden;
  background: var(--fs-color-surface);
  border: 1px solid var(--fs-color-border);
  border-radius: var(--fs-radius-lg);
  box-shadow: var(--fs-shadow-md);
}

.fs-dialog__header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--fs-space-3);
  padding: var(--fs-space-4) var(--fs-space-5);
  background: var(--fs-color-surface-subtle);
  border-bottom: 1px solid var(--fs-color-border-subtle);
}

/* No icon, no empty column: the heading takes the track the glyph would have had. */
.fs-dialog__header:not(:has(.fs-dialog__icon)) {
  grid-template-columns: minmax(0, 1fr) auto;
}

.fs-dialog__icon {
  position: relative;
  width: 44px;
  height: 44px;
  background: var(--fs-color-primary-subtle);
  border: 1px solid var(--fs-color-primary-line);
  border-radius: var(--fs-radius-md);
}

.fs-dialog__icon::after {
  position: absolute;
  inset: 0;
  content: "";
  background: var(--fs-color-primary-text);
  mask-image: var(--fs-dialog-icon, none);
  mask-position: center;
  mask-repeat: no-repeat;
  mask-size: 24px 24px;
  -webkit-mask-image: var(--fs-dialog-icon, none);
  -webkit-mask-position: center;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-size: 24px 24px;
}

.fs-dialog__heading h2,
.fs-dialog__heading p {
  margin: 0;
}

.fs-dialog__heading h2 {
  font-size: var(--fs-text-xl);
  font-weight: 700;
}

.fs-dialog__heading p {
  margin-top: var(--fs-space-1);
  color: var(--fs-color-text-secondary);
  font-size: var(--fs-text-sm);
}

.fs-dialog__body {
  display: grid;
  align-content: start;
  gap: var(--fs-space-5);
  padding: var(--fs-space-5);
  overflow: auto;
}

.fs-dialog__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--fs-space-2);
  padding: var(--fs-space-4) var(--fs-space-5);
  background: var(--fs-color-surface-subtle);
  border-top: 1px solid var(--fs-color-border-subtle);
}

/*
 * On a phone the dialog is a sheet: it arrives from the edge the thumb is on and
 * keeps its full width, so the answer is not asked for in a small box in the air.
 */
@media (max-width: 520px) {
  .fs-dialog {
    inset: auto auto 0 0;
    width: 100vw;
    max-height: 92vh;
    transform: none;
  }

  .fs-dialog__card {
    max-height: 92vh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: var(--fs-radius-lg) var(--fs-radius-lg) 0 0;
  }

  .fs-dialog__header,
  .fs-dialog__actions,
  .fs-dialog__body {
    padding: var(--fs-space-4);
  }
}
