/* ==================== МОДАЛЬНОЕ ОКНО ЛИСТИНГА ПРОГРАММЫ ==================== */

.listing-modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10060;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    padding: 20px;
    overflow: hidden;              /* 🎯 окно не должно вызывать скролл страницы */
}

.listing-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

body.light-theme .listing-modal-overlay {
    background-color: rgba(255, 255, 255, 0.85);
}

/* ===== Модальное окно: ширина по содержимому ===== */
.listing-modal {
    width: fit-content;              /* 🎯 ширина по содержимому */
    /* 🎯 max-width убран — окно растёт под самую длинную строку */
    height: 90vh;
    max-height: 860px;
    background-color: #0a0a0a;
    border: 1px solid #333;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
    transform: translateY(30px) scale(0.96);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
    background-color 0.5s ease,
    border-color 0.5s ease;
}

.listing-modal-overlay.active .listing-modal {
    transform: translateY(0) scale(1);
}

body.light-theme .listing-modal {
    background-color: #ffffff;
    border: 1px solid #ddd;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

/* ===== Заголовок ===== */
.listing-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 22px;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
    transition: border-color 0.5s ease;
}

body.light-theme .listing-modal-header {
    border-bottom: 1px solid #ddd;
}

.listing-modal-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: #FFFFFF;
    margin: 0;
    transition: color 0.5s ease;
    white-space: nowrap;
}

body.light-theme .listing-modal-title {
    color: #000000;
}

.listing-modal-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background-color: rgba(255, 255, 255, 0.08);
    color: #FFFFFF;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin-left: 16px;
}

.listing-modal-close:hover {
    background-color: rgba(255, 255, 255, 0.18);
    transform: scale(1.08);
}

.listing-modal-close svg {
    width: 20px;
    height: 20px;
}

body.light-theme .listing-modal-close {
    background-color: rgba(0, 0, 0, 0.05);
    color: #000000;
}

body.light-theme .listing-modal-close:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

/* ===== Тело ===== */
.listing-modal-body {
    flex: 1;
    min-height: 0;
    min-width: 0;
    padding: 18px 22px;
    overflow: hidden;
    display: flex;
}

/* ===== Содержимое <pre>: ширина по самой длинной строке ===== */
.listing-modal-content {
    flex: 0 1 auto;
    margin: 0;
    padding: 18px 22px;
    background-color: #050505;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    color: #D4D4D4;
    font-family: 'Source Code Pro', 'Consolas', 'Monaco', monospace;
    font-size: 1rem;
    line-height: 1.5;
    white-space: pre;
    /* 🎯 Только вертикальный скролл — по горизонтали окно само расширяется */
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
    user-select: text;
    cursor: text;

    width: max-content;          /* ширина по содержимому */
    max-width: none;             /* 🎯 не ограничиваем — окно само растянется */
    min-width: 0;
}

body.light-theme .listing-modal-content {
    background-color: #f5f5f5;
    border: 1px solid rgba(0, 0, 0, 0.06);
    color: #1a1a1a;
}

.listing-modal-content::-webkit-scrollbar {
    width: 10px;
    height: 0;                    /* 🎯 горизонтальный скроллбар скрыт */
}

.listing-modal-content::-webkit-scrollbar-track {
    background: #111;
}

.listing-modal-content::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 5px;
    border: 2px solid #111;
}

body.light-theme .listing-modal-content::-webkit-scrollbar-track {
    background: #f0f0f0;
}

body.light-theme .listing-modal-content::-webkit-scrollbar-thumb {
    background: #ccc;
    border: 2px solid #f0f0f0;
}

/* ===== Подвал ===== */
.listing-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 22px;
    border-top: 1px solid #333;
    background-color: #0a0a0a;
    flex-shrink: 0;
    transition: background-color 0.5s ease, border-color 0.5s ease;
}

body.light-theme .listing-modal-footer {
    background-color: #fafafa;
    border-top: 1px solid #ddd;
}

.listing-modal-btn {
    padding: 10px 22px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    min-width: 110px;
    white-space: nowrap;
}

.listing-modal-btn:active {
    transform: scale(0.97);
}

.listing-modal-btn.copy {
    background-color: rgba(183, 255, 105, 0.15);
    border-color: rgba(183, 255, 105, 0.35);
    color: #B7FF69;
}

.listing-modal-btn.copy:hover:not(:disabled) {
    background-color: rgba(183, 255, 105, 0.25);
    border-color: rgba(183, 255, 105, 0.55);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(183, 255, 105, 0.15);
}

.listing-modal-btn.copy:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.listing-modal-btn.close {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.15);
    color: #FFFFFF;
}

.listing-modal-btn.close:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

body.light-theme .listing-modal-btn.copy {
    background-color: rgba(72, 0, 150, 0.08);
    border-color: rgba(72, 0, 150, 0.25);
    color: #480096;
}

body.light-theme .listing-modal-btn.copy:hover:not(:disabled) {
    background-color: rgba(72, 0, 150, 0.15);
    border-color: rgba(72, 0, 150, 0.45);
    box-shadow: 0 6px 20px rgba(72, 0, 150, 0.12);
}

body.light-theme .listing-modal-btn.close {
    background-color: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.1);
    color: #000000;
}

body.light-theme .listing-modal-btn.close:hover {
    background-color: rgba(0, 0, 0, 0.08);
    border-color: rgba(0, 0, 0, 0.2);
}

/* ===== Мобильная адаптация ===== */
@media (max-width: 575px) {
    .listing-modal-overlay {
        padding: 0;
        align-items: stretch;
        justify-content: stretch;
    }

    .listing-modal {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
        transform: translateY(100%);
    }

    .listing-modal-overlay.active .listing-modal {
        transform: translateY(0);
    }

    .listing-modal-header {
        padding: 12px 16px;
    }

    .listing-modal-title {
        font-size: 1.15rem;
    }

    .listing-modal-body {
        padding: 12px 14px;
    }

    .listing-modal-content {
        font-size: 0.85rem;
        padding: 12px 14px;
        /* На мобильных окно фиксированной ширины — возвращаем горизонтальный скролл */
        width: 100%;
        overflow-x: auto;
    }

    .listing-modal-footer {
        padding: 12px 16px;
        gap: 8px;
    }

    .listing-modal-btn {
        flex: 1;
        padding: 10px 14px;
        font-size: 0.9rem;
        min-width: 0;
    }
}

/* ===== Поддержка safe area ===== */
@supports (padding: max(0px)) {
    @media (max-width: 575px) {
        .listing-modal-header {
            padding-top: max(12px, env(safe-area-inset-top));
        }
        .listing-modal-footer {
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }
    }
}
