.legal-modal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1051;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.legal-modal[hidden] {
    display: none;
}

body.legal-modal-open {
    overflow: hidden;
}

.legal-modal__overlay {
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

.legal-modal__dialog {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1100px;
    max-height: 100%;
    min-height: 0;
    background-color: #fff;
    border-radius: 6px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.legal-modal__header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 15px;
    padding: 12px 15px;
    color: #fff;
    background-color: rgb(163, 132, 104);
    border-bottom: 1px solid #eee;
}

.legal-modal__title {
    flex: 1 1 auto;
    margin: 0;
    font-size: 1.3em;
    font-weight: bold;
    line-height: 1.3;
    overflow-wrap: break-word;
}

.legal-modal__close {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 30px;
    line-height: 1;
    color: #fff;
    background: rgba(0, 0, 0, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.legal-modal__close:hover {
    background-color: rgb(82, 58, 17);
    border-color: #fff;
}

.legal-modal__close:active {
    transform: scale(0.92);
}

.legal-modal__close:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.legal-modal__body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 20px 15px;
    color: #333230;
    font-size: 1em;
    line-height: 1.5;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    overflow-wrap: break-word;
}

.legal-modal__body:focus-visible {
    outline: 2px solid rgb(163, 132, 104);
    outline-offset: -2px;
}

.legal-modal__body > *:first-child {
    margin-top: 0;
}

.legal-modal__body > *:last-child {
    margin-bottom: 0;
}

.legal-modal__body img {
    max-width: 100%;
    height: auto;
}

.legal-modal__body table {
    width: 100%;
    max-width: 100%;
    margin: 1em 0;
    /* Внешние документы приходят с border-collapse: collapse, из-за чего таблица
       на 1px шире контейнера и появляется горизонтальная прокрутка. */
    border-collapse: separate !important;
    border-spacing: 0;
    table-layout: fixed;
    box-sizing: border-box;
}

.legal-modal__body table th,
.legal-modal__body table td {
    padding: 8px 10px;
    border: 1px solid #ddd;
    text-align: left;
    vertical-align: top;
    box-sizing: border-box;
    overflow-wrap: break-word;
}

.legal-modal__body table th {
    background-color: #f4f1ec;
    font-weight: bold;
}

.legal-modal__footer {
    display: flex;
    flex: 0 0 auto;
    justify-content: center;
    padding: 12px 15px;
    background-color: #f4f1ec;
    border-top: 1px solid #e2ddd4;
}

.legal-modal__button {
    font-size: 1.1em;
    cursor: pointer;
}

.legal-modal__state {
    padding: 30px 10px;
    text-align: center;
}

.legal-modal__state-error {
    color: #a33;
}

.legal-modal__spinner {
    display: inline-block;
    width: 28px;
    height: 28px;
    border: 3px solid rgba(163, 132, 104, 0.3);
    border-top-color: rgb(163, 132, 104);
    border-radius: 50%;
    animation: legal-modal-spin 0.8s linear infinite;
}

@keyframes legal-modal-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 767px) {
    .legal-modal {
        padding: 0;
    }

    .legal-modal__dialog {
        max-width: 100%;
        border-radius: 0;
    }

    .legal-modal__header {
        padding: 10px 12px;
    }

    .legal-modal__title {
        font-size: 1.1em;
    }

    .legal-modal__close {
        width: 32px;
        height: 32px;
        font-size: 26px;
    }

    .legal-modal__body {
        padding: 15px 12px;
    }

    /* Внешние документы приходят с фиксированной шириной колонок — снимаем её на узких экранах. */
    .legal-modal__body table th,
    .legal-modal__body table td {
        width: auto !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .legal-modal__spinner {
        animation-duration: 2.4s;
    }

    .legal-modal__close {
        transition: none;
    }
}
