/* ============================================================
   SFPD MODAL — единый компонент модальных окон
   ============================================================
   ЭТАЛОН для всех модалок сайта. Собран на базе формы поддержки.

   Подключать в base.html ПОСЛЕ sfpd-theme.css и ДО страничных css:
     <link rel="stylesheet" href="{% static 'css/sfpd-modal.css' %}">

   Покрывает три системы разметки, которые сосуществуют на сайте:
     1. .custom-modal        — своя разметка (поддержка, события, PA)
     2. .modal-content       — Bootstrap-модалки (FAQ, новости, навбар)
     3. .modal-*-custom      — старые модалки из шаблона Mercury

   ВАЖНО: фоны заданы сплошным цветом, а не через var(), потому что
   модалки рендерятся в футере/инклюдах на страницах, где тема может
   быть не подключена — раньше это давало прозрачную модалку.
   ============================================================ */

/* ============================================================
   1. ПОДЛОЖКА
   ============================================================ */
.custom-modal-overlay {
    position: fixed;
    inset: 0;
    /* выше липких шапок таблиц (position: sticky) и навбара (1080).
       Раньше при открытой модалке шапка таблицы с z-index: 2
       прорисовывалась поверх окна — казалось, что оно прозрачное. */
    z-index: 100000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(3, 9, 17, .78);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    opacity: 0;
    transition: opacity .3s ease;
}

.custom-modal-overlay.show {
    display: flex;
    opacity: 1;
}

/* ============================================================
   2. ПАНЕЛЬ
   ============================================================ */
.custom-modal,
.modal-content,
.modal-content-custom {
    position: relative;
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 26px;
    border-radius: 24px;
    background: var(--sfpd-panel);
    border: 1px solid rgba(255, 255, 255, .10);
    box-shadow: 0 30px 70px rgba(0, 0, 0, .60),
    0 10px 30px rgba(0, 0, 0, .40);
    color: rgba(255, 255, 255, .82);
    transform: translateY(-20px);
    opacity: 0;
    transition: transform .3s ease, opacity .3s ease;
}

.custom-modal-overlay.show .custom-modal {
    transform: translateY(0);
    opacity: 1;
}

/* Bootstrap сам управляет появлением — у него панель всегда видима */
.modal-content,
.modal-content-custom {
    transform: none;
    opacity: 1;
    padding: 0;
    overflow: hidden;
}

/* ============================================================
   3. ШАПКА
   ============================================================ */
.custom-modal-header,
.modal-header,
.modal-header-custom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    color: #ffffff;
    font-size: 20px;
    font-weight: 800;
}

/* у Bootstrap-модалок шапка внутри панели без внешних отступов */
.modal-header,
.modal-header-custom {
    margin-bottom: 0;
    padding: 18px 22px;
    background: var(--sfpd-panel-deep);
    border-bottom: 1px solid rgba(255, 255, 255, .10);
    border-radius: 24px 24px 0 0;
}

.modal-title {
    margin: 0;
    color: #ffffff;
    font-weight: 800;
    font-size: 20px;
    line-height: 1.3;
}

/* иконка в шапке (опционально) */
.modal-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    margin-right: 12px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--sfpd-primary-dark), var(--sfpd-teal));
    color: var(--sfpd-on-teal);
    font-size: 17px;
    box-shadow: 0 10px 22px rgba(20, 241, 217, .18);
}

/* подзаголовок под шапкой */
.modal-subtitle {
    margin: 14px 0 20px;
    color: rgba(255, 255, 255, .60);
    font-size: 14px;
    line-height: 1.6;
}

/* ============================================================
   4. ТЕЛО
   ============================================================ */
.modal-body,
.modal-body-custom {
    padding: 22px;
    background: var(--sfpd-panel);
    color: rgba(255, 255, 255, .82);
}

.modal-body-custom .icon {
    color: var(--sfpd-teal);
}

/* ============================================================
   5. КНОПКА ЗАКРЫТИЯ
   ============================================================ */
.custom-modal-close,
.modal-header .close,
.btn-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    min-width: 34px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .10);
    border-radius: 10px;
    background: rgba(255, 255, 255, .06);
    color: rgba(255, 255, 255, .70);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    opacity: 1;
    transition: background .2s ease, border-color .2s ease, color .2s ease;
}

.custom-modal-close:hover,
.modal-header .close:hover,
.btn-close:hover {
    background: rgba(239, 68, 68, .18);
    border-color: rgba(239, 68, 68, .35);
    color: var(--sfpd-danger);
    opacity: 1;
}

/* Bootstrap 5 рисует крестик фоновой картинкой — гасим и ставим свой */
.btn-close {
    background-image: none !important;
    filter: none !important;
    box-shadow: none !important;
}

.btn-close::before {
    content: "\00d7";
    font-size: 22px;
    line-height: 1;
}

/* ============================================================
   6. ФОРМЫ ВНУТРИ МОДАЛОК
   ============================================================ */
.custom-modal .form-group,
.modal-body .form-group {
    margin-bottom: 18px;
}

.custom-modal label,
.custom-modal .form-group label,
.modal-body label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    color: rgba(255, 255, 255, .85);
    font-size: 13px;
    font-weight: 700;
}

.custom-modal label i,
.modal-body label i {
    color: var(--sfpd-teal);
    font-size: 13px;
    width: 14px;
    text-align: center;
}

.custom-modal .form-control,
.custom-modal .form-input,
.custom-modal input[type="text"],
.custom-modal input[type="email"],
.custom-modal input[type="password"],
.custom-modal input[type="date"],
.custom-modal input[type="time"],
.custom-modal input[type="number"],
.custom-modal select,
.custom-modal textarea,
.modal-body .form-control,
.modal-body input[type="text"],
.modal-body select,
.modal-body textarea {
    display: block;
    width: 100%;
    min-height: 52px;
    padding: 14px 18px;
    border-radius: 14px;
    background: rgba(255, 255, 255, .05);
    border: 1px solid rgba(255, 255, 255, .12);
    color: #ffffff;
    font-size: 15px;
    line-height: 1.5;
    transition: border-color .22s ease, box-shadow .22s ease, background .22s ease;
}

.custom-modal .form-control::placeholder,
.custom-modal input::placeholder,
.custom-modal textarea::placeholder,
.modal-body input::placeholder,
.modal-body textarea::placeholder {
    color: rgba(255, 255, 255, .35);
}

.custom-modal .form-control:focus,
.custom-modal .form-input:focus,
.custom-modal input:focus,
.custom-modal select:focus,
.custom-modal textarea:focus,
.modal-body .form-control:focus,
.modal-body input:focus,
.modal-body select:focus,
.modal-body textarea:focus {
    outline: none;
    background: rgba(255, 255, 255, .07);
    border-color: rgba(20, 241, 217, .45);
    box-shadow: 0 0 0 3px rgba(20, 241, 217, .12);
}

.custom-modal textarea,
.modal-body textarea {
    height: auto;
    min-height: 130px;
    max-height: 320px;
    resize: vertical;
}

.custom-modal select option,
.modal-body select option {
    background-color: var(--sfpd-panel);
    color: rgba(255, 255, 255, .85);
}

/* автозаполнение браузера белит поля в обход background */
.custom-modal input:-webkit-autofill,
.custom-modal input:-webkit-autofill:hover,
.custom-modal input:-webkit-autofill:focus,
.modal-body input:-webkit-autofill {
    -webkit-text-fill-color: #ffffff !important;
    -webkit-box-shadow: 0 0 0 1000px rgba(255, 255, 255, .05) inset !important;
    box-shadow: 0 0 0 1000px rgba(255, 255, 255, .05) inset !important;
    caret-color: #ffffff;
    transition: background-color 5000s ease-in-out 0s;
}

.custom-modal .form-hint,
.form-hint {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: rgba(255, 255, 255, .50);
}

.custom-divider {
    height: 1px;
    margin: 16px 0;
    border: 0;
    background: rgba(255, 255, 255, .08);
}

/* ============================================================
   7. КНОПКИ ДЕЙСТВИЙ
   ============================================================ */
.modal-btn,
.custom-modal .button-block[type="submit"] {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    height: 54px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--sfpd-primary-dark), var(--sfpd-teal));
    color: var(--sfpd-on-teal);
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 12px 28px rgba(20, 241, 217, .18);
    transition: transform .2s ease, box-shadow .2s ease, filter .2s ease;
}

.modal-btn:hover,
.custom-modal .button-block[type="submit"]:hover {
    color: var(--sfpd-on-teal);
    transform: translateY(-2px);
    box-shadow: 0 16px 34px rgba(20, 241, 217, .28);
    filter: brightness(1.05);
}

.modal-btn--danger {
    background: linear-gradient(135deg, #7e1f2b, #c0334a);
    color: #ffe3e8;
    box-shadow: 0 12px 28px rgba(192, 51, 74, .20);
}

.modal-btn--ghost {
    background: rgba(255, 255, 255, .07);
    border: 1px solid rgba(255, 255, 255, .12);
    color: rgba(255, 255, 255, .85);
    box-shadow: none;
}

.modal-footer,
.modal-footer-investigation {
    display: flex;
    gap: 12px;
    padding: 18px 22px;
    background: var(--sfpd-panel-deep);
    border-top: 1px solid rgba(255, 255, 255, .08);
}

/* ============================================================
   8. BOOTSTRAP-СПЕЦИФИКА
   ============================================================ */
.modal-dialog {
    z-index: 1060;
}

.modal-dialog-custom,
.modal-dialog-centered {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 2rem);
}

.modal-backdrop.show {
    opacity: .70;
}

/* ============================================================
   9. АДАПТИВ — на мобильных модалка ведёт себя как шторка
   ============================================================ */
@media (max-width: 640px) {
    .custom-modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .custom-modal {
        max-width: 100%;
        max-height: 92vh;
        margin-top: auto;
        padding: 20px;
        border-radius: 20px 20px 0 0;
    }

    .custom-modal-header {
        font-size: 18px;
        padding-bottom: 14px;
    }

    .modal-icon {
        width: 38px;
        height: 38px;
        font-size: 15px;
    }

    .modal-header,
    .modal-header-custom {
        padding: 14px 16px;
    }

    .modal-title {
        font-size: 17px;
    }

    .modal-body,
    .modal-body-custom {
        padding: 16px;
    }
}

/* ============================================================
   10. ДОСТУПНОСТЬ
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .custom-modal-overlay,
    .custom-modal,
    .custom-modal-close,
    .modal-btn,
    .custom-modal .form-control {
        transition: none;
    }

    .modal-btn:hover {
        transform: none;
    }
}


/* ============================================================
   11. ЛИПКИЕ ЭЛЕМЕНТЫ НЕ ДОЛЖНЫ ПЕРЕКРЫВАТЬ МОДАЛКУ
   ============================================================
   Шапки таблиц зафиксированы через position: sticky и создают
   собственный слой. Держим их заведомо ниже модального окна.
   Класс .modal-open вешается на body скриптом при открытии. */
.dashboard-table thead th,
.users-table thead th,
.thead-fixed {
    z-index: 1;
}

body.modal-open .dashboard-table thead th,
body.modal-open .users-table thead th,
body.modal-open .thead-fixed {
    position: static;
    z-index: auto;
}

/* пока модалка открыта — страница под ней не скроллится */
body.modal-open {
    overflow: hidden;
}


/* ============================================================
   12. СТРАХОВКА ОТ КОНТЕКСТА НАЛОЖЕНИЯ
   ============================================================
   В style.css у .page задан opacity: 0 (страница проявляется
   скриптом). Любая opacity < 1 создаёт контекст наложения, и
   z-index модалки перестаёт работать за пределами .page —
   элементы страницы с собственным z-index рисуются поверх окна.

   Радикальное решение — переносить модалку в конец <body>
   скриптом при открытии (см. patch для supports.html).
   Ниже — CSS-страховка на случай, если перенос не сделан. */
body.modal-open .page {
    /* убираем контекст наложения, пока открыта модалка */
    opacity: 1;
    isolation: auto;
}

body.modal-open [class*="acor-"],
body.modal-open .faq-card,
body.modal-open .stat-card,
body.modal-open .chart-card,
body.modal-open .table-card,
body.modal-open .news-card {
    z-index: auto;
}
