/* ===== УЛУЧШЕННЫЕ МОДАЛЬНЫЕ ОКНА ===== */

.modal_div {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;           /* Ограничение высоты */
    display: flex;
    flex-direction: column;      /* Чтобы header и footer не сжимались */
    background: linear-gradient(145deg, #2a1e15, #1f150e);
    border: 2px solid #b8860b;
    border-radius: 24px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.8), 0 0 0 1px #d4af37 inset;
    z-index: 10000;
    color: #fff;
    overflow: hidden;            /* Скрываем лишнее, прокрутка будет внутри modal-body */
}

.modal_div.show {
    display: flex;
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    pointer-events: auto;
}

.modal-header {
    flex-shrink: 0;              /* Запрещаем сжиматься */
    padding: 20px 25px 10px;
    border-bottom: 2px solid #b8860b;
    background: rgba(0,0,0,0.3);
}

.modal-header h3 {
    margin: 0;
    color: #ffd966;
    font-size: 26px;
    font-weight: 700;
    text-align: left;
    border-bottom: none;
    padding-bottom: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-header h3::before {
    content: '📜';
    font-size: 28px;
    filter: drop-shadow(0 0 5px gold);
}

.modal-body {
    position: relative;
    overflow: visible;           /* разрешаем панелям выходить за границы */
    flex: 1 1 auto;
    padding: 20px 25px;
    max-height: calc(90vh - 130px);
    display: flex;
    flex-direction: column;
}

.modal-body .modal-scrollable {
    overflow-y: auto;             /* прокрутка только для этого блока */
    flex: 1;
    padding-right: 5px;           /* небольшой отступ для скроллбара */
}

/* Стилизация скроллбара для WebKit (Chrome, Safari) */
.modal-body::-webkit-scrollbar {
    width: 8px;
}
.modal-body::-webkit-scrollbar-track {
    background: #2b1e0e;
}
.modal-body::-webkit-scrollbar-thumb {
    background: #b8860b;
    border-radius: 4px;
}

.modal-footer {
    flex-shrink: 0;
    padding: 15px 25px 20px;
    background: rgba(0,0,0,0.3);
    border-top: 2px solid #8b5a2b;
}

/* Кнопки внутри модалок */
.modal-scrollable button{
    min-width: 29%;
    margin: 0 2%;
}
.modal-button-primary,
.modal-button-secondary {
    padding: 12px 30px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 40px;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.modal-button-primary {
    background: linear-gradient(145deg, #b8860b, #8b5a2b);
    color: #1f140c;
    box-shadow: 0 4px 0 #5a3e2b;
}

.modal-button-primary:hover {
    background: linear-gradient(145deg, #8b5a2b, #b8860b);
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #5a3e2b, 0 0 15px gold;
}

.modal-button-secondary {
    background: linear-gradient(145deg, #3f2e22, #2b1e0e);
    border: 2px solid #b8860b;
    color: #ffd966;
}

.modal-button-secondary:hover {
    background: #b8860b;
    color: #1f140c;
    border-color: #ffd700;
}

/* Поля ввода */
.modal-body input[type="text"],
.modal-body input[type="number"],
.modal-body input[type="email"],
.modal-body input[type="password"],
.modal-body textarea,
.modal-body select {
    width: 100%;
    background: #3f2e22;
    border: 2px solid #8b5a2b;
    border-radius: 12px;
    padding: 12px 16px;
    color: #fff;
    font-size: 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
    margin-bottom: 15px;
}

.modal-body input:focus,
.modal-body textarea:focus,
.modal-body select:focus {
    border-color: #ffd700;
    box-shadow: 0 0 0 3px rgba(255,215,0,0.2);
    outline: none;
}

.modal-body select {
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='%23ffd966'><path d='M7 10l5 5 5-5z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 15px center;
    padding-right: 40px;
}

.modal-body label {
    display: block;
    color: #ffd966;
    font-weight: 600;
    margin-bottom: 5px;
    font-size: 15px;
}

.modal-body .form-group {
    margin-bottom: 20px;
}

/* Чекбоксы в стиле переключателей */
.modal-body .checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #f0e6d2;
    cursor: pointer;
    margin-bottom: 10px;
}

.modal-body .checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: #b8860b;
}

/* Поисковые результаты внутри модалок */
.modal-body .search-results {
    position: absolute;
    background: #2a1e15;
    border: 2px solid #b8860b;
    border-radius: 10px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 10001;
    width: calc(100% - 50px);
    box-shadow: 0 5px 20px #000;
}

.modal-body .search-result-item {
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 1px solid #3f2e22;
    color: #fff;
    transition: background 0.2s;
}

.modal-body .search-result-item:hover {
    background: #b8860b;
    color: #1f140c;
}

/* Адаптация для мобильных */
@media (max-width: 768px) {
    .modal_div {
        width: 95%;
        max-width: none;
        border-radius: 20px;
    }

    .modal-header h3 {
        font-size: 22px;
    }

    .modal-body {
        padding: 20px;
    }

    .modal-footer {
        flex-direction: column;
        padding: 15px 20px;
    }

    .modal-button-primary,
    .modal-button-secondary {
        width: 100%;
        margin: 5px 0;
    }

    .modal-body input,
    .modal-body textarea,
    .modal-body select {
        font-size: 16px; /* предотвращает масштабирование на iOS */
    }
}

/* Кнопка закрытия */
.modal_close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 36px;
    height: 36px;
    background: rgba(0,0,0,0.5);
    border: 2px solid #b8860b;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
}

.modal_close:hover {
    background: #b8860b;
}

.closeButton {
    width: 20px;
    height: 20px;
    position: relative;
}

.closeButton span {
    position: absolute;
    width: 100%;
    height: 2px;
    background-color: #ffd966;
    top: 50%;
    left: 0;
}

.closeButton span:nth-child(1) {
    transform: rotate(45deg);
}

.closeButton span:nth-child(2) {
    transform: rotate(-45deg);
}

.modal_close:hover .closeButton span {
    background-color: #1f140c;
}

/* Оверлей */
#overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 9999;
    display: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

#overlay.show {
    opacity: 1;
    pointer-events: auto;;
    display: block;
}