.ref-modal,
.config-modal,
.pessoa-list__modal {
    position: fixed;
    z-index: var(--ref-layer-modal);
    inset: 0;
    display: none;
    place-items: center;
    padding: 20px;
}

.ref-modal.is-open,
.config-modal.is-open,
.pessoa-list__modal.is-open {
    display: grid;
}

.ref-modal__backdrop,
.config-modal__backdrop,
.pessoa-list__modal-backdrop {
    width: 100%;
    height: 100%;
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(12, 29, 26, .56);
    backdrop-filter: blur(2px);
}

.ref-modal__dialog,
.config-modal__dialog,
.pessoa-list__modal-dialog {
    width: min(700px, 100%);
    max-height: calc(100vh - 40px);
    max-height: calc(100dvh - 40px);
    min-width: 0;
    position: relative;
    z-index: 1;
    display: flex;
    overflow: hidden;
    flex-direction: column;
    border: 1px solid var(--ref-border);
    border-radius: var(--ref-radius-lg);
    color: var(--ref-text);
    background: var(--ref-surface);
    box-shadow: var(--ref-shadow-modal);
}

.config-modal__dialog--wide,
.ref-modal__dialog--wide,
.pessoa-list__modal-dialog {
    width: min(900px, 100%);
}

.config-modal__dialog > form,
.ref-modal__dialog > form {
    min-height: 0;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
}

.ref-modal__header,
.ref-modal__footer,
.config-modal__header,
.config-modal__footer,
.pessoa-list__modal-header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: var(--ref-space-4);
    padding: 17px 20px;
}

.ref-modal__header,
.config-modal__header,
.pessoa-list__modal-header {
    border-bottom: 1px solid var(--ref-border);
}

.ref-modal__header h2,
.config-modal__header h2,
.pessoa-list__modal-header h2 {
    margin: 0;
    color: var(--ref-text);
    font-size: 18px;
}

.ref-modal__header p,
.config-modal__header p,
.pessoa-list__modal-header p {
    margin: 4px 0 0;
    color: var(--ref-text-muted);
    font-size: 13px;
    line-height: 1.4;
}

.ref-modal__body {
    padding: var(--ref-space-5);
}

.ref-modal__body,
.config-form,
.config-details,
.pessoa-list__modal-body {
    min-height: 0;
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.config-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    padding: 20px;
}

.config-field--wide {
    grid-column: 1 / -1;
}

.config-details {
    padding: 20px;
}

.ref-modal__footer,
.config-modal__footer {
    justify-content: flex-end;
    border-top: 1px solid var(--ref-border);
    background: var(--ref-surface-muted);
}

.ref-modal__close,
.config-modal__close {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--ref-border);
    border-radius: var(--ref-radius-sm);
    color: var(--ref-text-muted);
    background: var(--ref-surface);
    cursor: pointer;
}

.ref-modal__close:focus-visible,
.ref-modal__close:hover,
.config-modal__close:focus-visible,
.config-modal__close:hover {
    outline: 0;
    border-color: var(--ref-primary);
    background: var(--ref-primary-soft);
    box-shadow: 0 0 0 3px var(--ref-focus);
}

body.ref-modal-open,
body.config-modal-open,
body.pessoa-list-modal-open {
    overflow: hidden;
}

.ref-window-form .modal-content,
.modal-content:has(.ref-window-form) {
    overflow: hidden;
    border: 1px solid var(--ref-border);
    border-radius: var(--ref-radius-lg);
    background: var(--ref-surface);
    box-shadow: var(--ref-shadow-modal);
}

@media (max-width: 680px) {
    .ref-modal,
    .config-modal,
    .pessoa-list__modal {
        padding: 8px;
    }

    .ref-modal__dialog,
    .config-modal__dialog,
    .pessoa-list__modal-dialog {
        max-height: calc(100vh - 16px);
        max-height: calc(100dvh - 16px);
    }

    .config-form {
        grid-template-columns: 1fr;
        padding: 16px;
    }

    .config-field--wide {
        grid-column: auto;
    }

    .ref-modal__header,
    .ref-modal__body,
    .ref-modal__footer,
    .config-modal__header,
    .config-modal__footer {
        padding: 14px 16px;
    }

    .ref-modal__footer,
    .config-modal__footer {
        flex-wrap: wrap;
    }
}
