/* =========================
   Модальные окна - исправления
========================= */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.95);
    z-index: 9999;
    overflow: auto;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    background: var(--card-bg);
    border-radius: 20px;
    padding: 0;
    max-width: 90%;
    max-height: 90%;
    overflow: hidden;
    border: 1px solid var(--border-color);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.modal.show .modal-content {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

/* Кнопка закрытия */
.modal .close {
    position: absolute;
    top: 20px;
    right: 20px;
    color: white;
    font-size: 24px;
    font-weight: normal;
    cursor: pointer;
    z-index: 1001;
    background: rgba(0, 0, 0, 0.6);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    line-height: 1;
}

.modal .close:hover {
    background: rgba(239, 68, 68, 0.8);
    transform: scale(1.1);
}

/* =========================
   Модалка с изображением
========================= */
#image-modal .modal-content {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    max-width: 95vw;
    max-height: 95vh;
    width: auto;
}

#image-modal .modal-content {
    transform: translate(-50%, -50%) scale(0.95);
}

#image-modal.show .modal-content {
    transform: translate(-50%, -50%) scale(1);
}

#modal-img {
    display: block;
    max-width: 100%;
    max-height: 85vh;
    margin: 0 auto;
    border-radius: 8px;
}

/* =========================
   Модалка с текстом
========================= */
#text-modal .modal-content {
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding: 0;
}

#text-modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    border-bottom: 2px solid var(--border-color);
    background: var(--card-bg);
    position: relative;
    flex-wrap: wrap;
    gap: 15px;
}

#text-modal .modal-header h3 {
    margin: 0;
    font-size: 1.5rem;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    flex: 1;
}

.modal-header-buttons {
    display: flex;
    gap: 10px;
    order: 2;
    width: 100%;
    justify-content: flex-end;
    margin-top: 10px;
}

.btn-copy-text, .btn-save-text {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    min-width: 120px;
    justify-content: center;
}

.btn-copy-text {
    background: var(--gradient);
    color: white;
}

.btn-save-text {
    background: var(--success);
    color: white;
}

.btn-copy-text:hover, .btn-save-text:hover {
    opacity: 0.9;
    transform: translateY(-2px);
}

/* Текстовое поле */
#modal-textarea {
    flex: 1;
    min-height: 300px;
    margin: 20px;
    padding: 20px;
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    outline: none;
}

#modal-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

/* Адаптивность для модалок */
@media (max-width: 768px) {
    .modal .close {
        top: 15px;
        right: 15px;
        width: 36px;
        height: 36px;
        font-size: 20px;
    }

    #text-modal .modal-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 15px 20px;
    }

    .modal-header-buttons {
        order: 2;
        width: 100%;
        justify-content: space-between;
        margin-top: 10px;
    }

    .btn-copy-text, .btn-save-text {
        flex: 1;
        min-width: 0;
        padding: 10px;
    }

    #modal-textarea {
        margin: 15px;
        padding: 15px;
        min-height: 250px;
    }
}

@media (max-width: 480px) {
    .modal-content {
        width: 95%;
        max-width: 95%;
    }

    .modal-header-buttons {
        flex-direction: column;
        gap: 8px;
    }

    .btn-copy-text, .btn-save-text {
        width: 100%;
    }
}