@layer components {

  /* Native <dialog> fed by the layout's "modal" turbo-frame (ApplicationHelper#modal_frame). */
  .modal {
    width: min(560px, calc(100vw - 32px));
    padding: 0;
    color: var(--color-ink);
    background: var(--color-surface);
    border: 1px solid var(--color-edge);
    border-radius: 10px;

    &::backdrop {
      background: color-mix(in oklch, var(--black) 55%, transparent);
    }
  }

  /* The dialog's form (simple_form_for … html: { class: "modal__body" }). */
  .modal__body {
    display: grid;
    gap: 12px;
    padding: 14px 16px 16px;
  }

  .modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-line);
  }

  .modal__title {
    font-size: 15px;
    font-weight: 600;
  }

  .modal__close {
    font-size: 16px;
    line-height: 1;
    background: transparent;
    border: 0;
  }

  .modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
  }

  /* Narrow skin for the shared confirmation dialog (layouts/_confirm, confirm.js). */
  .modal--confirm {
    width: min(380px, calc(100vw - 32px));
    padding: 18px 18px 14px;

    & .modal__actions button {
      min-width: 6em;
      padding: 6px 12px;
      font-size: 13px;
    }
  }

  .modal__message {
    margin: 0 0 16px;
    font-size: 14px;
    line-height: 1.45;
  }

  /* Fields set once and rarely touched (the house's heat loss inputs), folded away. */
  .modal__more {
    display: grid;
    gap: 14px;

    & summary {
      font-size: 12px;
      color: var(--color-ink-muted);
      cursor: pointer;
    }

    &[open] summary {
      margin-bottom: 0;
    }
  }

  /* Two fields side by side, their label, input, error and hint rows shared (subgrid), so the inputs line
     up whatever wraps above or below them. */
  .modal__pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(4, auto);
    column-gap: 12px;

    &>.input {
      grid-row: span 4;
      grid-template-rows: subgrid;
      row-gap: 4px;
    }
  }

  /* A part of a settings modal below its form (houses/_share). */
  .modal__section {
    display: grid;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--color-line);
  }

  .modal__section-title {
    font-size: 13px;
    font-weight: 600;
  }

  /* Linked projects (houses/_links): the original and the ones over its building, this one in bold. */
  .modal__links {
    display: grid;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;

    & small {
      margin-left: 6px;
      color: var(--color-ink-muted);
    }
  }

  /* The read-only link: the address to copy, then what can be done with it. */
  .share {
    display: flex;
    gap: 6px;
  }

  /* The link's language: as the viewer's browser has it, or one named in the link. */
  .share__lang {
    flex: none;
    max-width: 9em;
    padding: 4px 6px;
    font: inherit;
    font-size: 12px;
    color: var(--color-ink);
    background: var(--color-surface-sunken);
    border: 1px solid var(--color-line);
    border-radius: 4px;
  }

  .share__url {
    flex: 1;
    min-width: 0;
    padding: 4px 8px;
    font: 12px ui-monospace, monospace;
    color: var(--color-ink);
    background: var(--color-surface-sunken);
    border: 1px solid var(--color-line);
    border-radius: 4px;
  }

  .share__actions {
    display: flex;
    gap: 6px;
  }

  .modal__danger {
    padding: 10px 16px 14px;
    border-top: 1px solid var(--color-line);

    & button {
      color: var(--color-danger-ink);
    }
  }
}
