/* Mamadysh PDF Viewer - Полностью исправленная версия */

/* Основной контейнер */
.mamadysh-pdf-viewer {
    display: flex;
    flex-direction: column;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
    background: #2a2a2a;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    font-family: Inter, system-ui, -apple-system, sans-serif;
    margin: 20px 0;
    max-width: 100%;
    height: auto !important;
    min-height: 300px;
}

/* Полноэкранный режим */
.mamadysh-pdf-viewer:fullscreen,
.mamadysh-pdf-viewer:-webkit-full-screen {
    width: 100% !important;
    height: 100% !important;
    border-radius: 0;
    border: none;
    margin: 0;
}

/* ========== ТУЛБАР ========== */
.mpdf-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: linear-gradient(to bottom, #3a3a3a, #2e2e2e);
    border-bottom: 1px solid rgba(0, 0, 0, 0.4);
    padding: 8px 12px;
    flex-wrap: wrap;
    color: #fff;
    flex-shrink: 0;
}

.mpdf-tbgrp {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.mpdf-tbgrp-center {
    flex: 1;
    justify-content: center;
    min-width: 0;
}

.mpdf-filename {
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.7);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 340px;
}

/* Кнопки */
.mpdf-btn {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
    transition: background 0.15s;
    text-decoration: none;
    padding: 0;
}

.mpdf-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.mpdf-btn:active {
    background: rgba(255, 255, 255, 0.25);
}

.mpdf-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.mpdf-download {
    font-weight: 700;
}

/* Пагинация */
.mpdf-pagebox {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 0.85rem;
}

.mpdf-page-input {
    width: 40px;
    background: transparent;
    border: none;
    color: #fff;
    text-align: center;
    font-size: 0.85rem;
    outline: none;
    -moz-appearance: textfield;
    appearance: textfield;
}

.mpdf-page-input::-webkit-outer-spin-button,
.mpdf-page-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.mpdf-page-sep {
    color: rgba(255, 255, 255, 0.4);
}

.mpdf-page-total {
    color: rgba(255, 255, 255, 0.85);
    min-width: 20px;
    text-align: left;
}

.mpdf-zoom-val {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.7);
    min-width: 46px;
    text-align: center;
    user-select: none;
}

/* ========== ОСНОВНОЙ КОНТЕЙНЕР С ПРОКРУТКАМИ ========== */
.mpdf-canvas-wrap {
    flex: 1;
    background: #525659;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    position: relative;
    scrollbar-color: #777 #2a2a2a;
    -webkit-overflow-scrolling: touch;
    
    /* По умолчанию: только вертикальная прокрутка */
    overflow-x: hidden;
    overflow-y: auto;
    
    padding: 0px;
    min-height: 0;
    height: auto !important;
}

/* Полосы прокрутки */
.mpdf-canvas-wrap::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.mpdf-canvas-wrap::-webkit-scrollbar-track {
    background: #2a2a2a;
    border-radius: 6px;
}

.mpdf-canvas-wrap::-webkit-scrollbar-thumb {
    background: #666;
    border-radius: 6px;
    border: 2px solid #2a2a2a;
}

.mpdf-canvas-wrap::-webkit-scrollbar-thumb:hover {
    background: #888;
}

/* Canvas — может выходить за пределы контейнера при зуме */
.mpdf-canvas {
    background: #fff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
    display: block;
    flex-shrink: 0;
    /* Без ограничений — размеры ставятся через JS */
    max-width: none;
}

/* ========== ЗАГРУЗКА ========== */
.mpdf-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.88rem;
    background: #525659;
    z-index: 5;
}

.mpdf-loading.hidden {
    display: none;
}

.mpdf-spinner {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    animation: mpdfspin 1s linear infinite;
}

@keyframes mpdfspin {
    to {
        transform: rotate(360deg);
    }
}

.mpdf-error {
    background: #fde8ea;
    border: 1px solid #c8222a;
    color: #9a1820;
    padding: 14px 18px;
    border-radius: 8px;
    font-size: 0.9rem;
    margin: 12px 0;
}

/* ========== МОБИЛЬНАЯ АДАПТАЦИЯ ========== */

/* Планшеты */
@media (max-width: 768px) {
    .mamadysh-pdf-viewer {
        min-height: 350px;
        margin: 12px 0;
    }
    
    .mpdf-toolbar {
        padding: 8px 10px;
        gap: 10px;
    }
    
    .mpdf-btn {
        width: 34px;
        height: 34px;
        font-size: 1rem;
    }
    
    .mpdf-filename {
        display: none;
    }
    
    .mpdf-canvas-wrap {
        padding: 0px;
        min-height: 0;
    }
}

/* Телефоны (тулбар переносится) */
@media (max-width: 600px) {
    .mamadysh-pdf-viewer {
        min-height: 0;
        height: auto !important;
    }
    
    .mpdf-toolbar {
        flex-direction: column;
        align-items: stretch;
        padding: 10px;
        gap: 10px;
    }
    
    .mpdf-tbgrp {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .mpdf-tbgrp:first-child,
    .mpdf-tbgrp:last-child {
        justify-content: center;
        margin: 0;
    }
    
    /* Крупные кнопки для пальцев */
    .mpdf-btn {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }
    
    .mpdf-pagebox {
        padding: 4px 12px;
    }
    
    .mpdf-page-input {
        width: 45px;
        font-size: 1rem;
    }
    
    .mpdf-canvas-wrap {
        padding: 0px;
        min-height: 0;
    }
}

/* Очень маленькие телефоны */
@media (max-width: 400px) {
    .mpdf-toolbar {
        padding: 8px;
        gap: 8px;
    }
    
    .mpdf-btn {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }
    
    .mpdf-page-input {
        width: 40px;
    }
    
    .mpdf-pagebox {
        padding: 3px 8px;
    }
    
    .mpdf-zoom-val {
        min-width: 40px;
    }
    
    .mpdf-canvas-wrap {
        padding: 0px;
        min-height: 0;
    }
}

/* Альбомная ориентация на телефонах */
@media (max-width: 768px) and (orientation: landscape) {
    .mamadysh-pdf-viewer {
        min-height: 300px;
    }
    
    .mpdf-toolbar {
        flex-direction: row;
        padding: 6px 8px;
    }
    
    .mpdf-btn {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }
    
    .mpdf-canvas-wrap {
        min-height: 0;
        padding: 0px;
    }
}

/* Полноэкранный режим — корректировка прокруток */
.mamadysh-pdf-viewer:fullscreen .mpdf-canvas-wrap,
.mamadysh-pdf-viewer:-webkit-full-screen .mpdf-canvas-wrap {
    width: 100%;
    height: 100% !important;
    min-height: 100% !important;
}

.mamadysh-pdf-viewer:fullscreen .mpdf-canvas,
.mamadysh-pdf-viewer:-webkit-full-screen .mpdf-canvas {
    max-width: none;
    max-height: none;
}