/* ═══════════════ MODAL ═══════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-modal);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow-y: auto;
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-body);
    width: 100%;
    max-width: 800px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    max-height: 90vh;
    max-height: 90dvh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px var(--shadow-color);
    box-sizing: border-box;
    overflow: hidden;
}

.modal-sm { max-width: 400px; }

.modal > form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    width: 100%;
    margin: 0;
    padding: 0;
}

.modal-header {
    padding: 24px 32px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
    min-width: 0;
}
.modal-header h2 {
    font-size: 26px;
    overflow-wrap: break-word;
    word-break: break-word;
    min-width: 0;
}
.modal-close {
    background: transparent;
    color: var(--text-muted);
    font-size: 32px;
    padding: 0;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}
.modal-close:hover { color: var(--text-main); }

.modal-body {
    padding: 32px 40px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1 1 auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.modal-footer {
    padding: 20px 40px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 16px;
    justify-content: flex-end;
    flex-shrink: 0;
    flex-wrap: wrap;
    background: var(--bg-body);
}

.modal-footer--split {
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.modal-footer-actions {
    display: flex;
    gap: 16px;
    margin-left: auto;
    flex-wrap: wrap;
}

/* ═══════════════ LIGHTBOX ═══════════════ */
.admin-lightbox {
    position: fixed;
    inset: 0;
    background: var(--modal-backdrop);
    backdrop-filter: blur(10px);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 40px;
    cursor: zoom-out;
}
.admin-lightbox.active { display: flex; }
.admin-lightbox img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

/* ═══════════════ WYSIWYG ═══════════════ */
.wysiwyg-wrapper {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    width: 100%;
    box-sizing: border-box;
}
.wysiwyg-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    background: var(--bg-input);
    padding: 8px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.wysiwyg-toolbar button {
    background: transparent;
    color: var(--text-main);
    border: 1px solid transparent;
    padding: 7px 13px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: 0.2s;
    font-family: var(--font-body);
}
.wysiwyg-toolbar button:hover {
    background: var(--skeleton-highlight);
    border-color: var(--border);
}

.wysiwyg-editor {
    min-height: 250px;
    overflow-y: visible;
    padding: 16px;
    background: var(--bg-input);
    color: var(--text-main);
    outline: none;
    line-height: 1.65;
    font-size: 15px;
    width: 100%;
    box-sizing: border-box;
}
.wysiwyg-editor h3 {
    margin-bottom: 8px;
    margin-top: 16px;
    color: var(--text-main);
    font-family: var(--font-heading);
    font-size: 21px;
}
.wysiwyg-editor ul { padding-left: 20px; margin-bottom: 8px; list-style-type: disc; }
.wysiwyg-editor li { margin-bottom: 4px; }
.wysiwyg-editor p { margin-bottom: 8px; }
.wysiwyg-editor a { color: var(--accent); text-decoration: underline; }

@media (max-width: 768px) {
    /* ─── Модалка по центру экрана ─── */
    .modal-overlay {
        padding: 16px;
        align-items: center;
        justify-content: center;
    }

    .modal {
        max-width: 100%;
        max-height: calc(100dvh - 32px);
        border-radius: var(--radius-lg);
        width: 100%;
        box-sizing: border-box;
    }
    .modal-sm {
        max-width: 100%;
    }

    .modal-header {
        padding: 16px 20px;
        gap: 12px;
    }
    .modal-header h2 { font-size: 21px; }

    .modal-body {
        padding: 20px 16px;
    }

    .modal-footer {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
        flex-direction: column-reverse;
        gap: 8px;
    }
    .modal-footer button { width: 100%; padding: 16px; }

    .modal-footer--split {
        flex-direction: column-reverse;
        align-items: stretch;
        gap: 8px;
    }
    .modal-footer-actions {
        flex-direction: column-reverse;
        margin-left: 0;
        gap: 8px;
        width: 100%;
    }
    .modal-footer--split > button,
    .modal-footer-actions button {
        width: 100%;
        padding: 16px;
    }

    .wysiwyg-editor {
        min-height: 200px;
    }

    .modal > form .settings-card {
        padding: 16px;
    }
}

/* ═══════════════ CONTACT FIELDS EDITOR ═══════════════ */
#contacts-fields-editor { margin-top: 4px; }

.contact-field-row {
    display: grid;
    grid-template-columns: minmax(140px, 1fr) minmax(180px, 1.4fr) minmax(160px, 1.2fr) 40px;
    gap: 8px;
    align-items: center;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 10px;
}
.contact-field-row .form-control {
    padding: 10px 14px;
    font-size: 14px;
    height: 42px;
    border-radius: 10px;
}
.contact-field-remove {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(var(--accent-rgb), 0.1);
    color: var(--accent);
    border: 1px solid rgba(var(--accent-rgb), 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    padding: 0;
}
.contact-field-remove:hover {
    background: var(--accent);
    color: var(--white-on-accent);
    border-color: var(--accent);
}

@media (max-width: 768px) {
    .contact-field-row { grid-template-columns: 1fr 40px; }
    .contact-field-row [data-field="label"]  { grid-column: 1 / -1; }
    .contact-field-row [data-field="value"]  { grid-column: 1 / 2; }
    .contact-field-row [data-field="link"]   { grid-column: 1 / 2; }
    .contact-field-remove {
        grid-column: 2 / 3;
        grid-row: 2 / 4;
        align-self: center;
    }
}