/* ==========================================================================
   AnimeHub Global Download Manager (Progress Bar & Interactive Modal)
   - Desktop: Attached under top-bar (fixed top: 68px)
   - Mobile: Attached above mobile nav bar (fixed bottom: calc(65px + env(safe-area-inset-bottom)))
   - Sleek glassmorphism theme matching manga reader progress style
   ========================================================================== */

/* Плавающий мини прогресс-бар */
.ah-dl-bar-wrap {
    position: fixed;
    left: 50%;
    transform: translateX(-50%) translateY(-120%);
    width: min(720px, calc(100vw - 32px));
    height: 44px;
    background: rgba(14, 15, 20, 0.96);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: 1px solid rgba(255, 77, 109, 0.4);
    border-radius: 9999px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.65), 0 0 18px rgba(255, 77, 109, 0.25);
    z-index: 9995;
    display: flex;
    align-items: center;
    padding: 0 18px;
    gap: 12px;
    cursor: pointer;
    user-select: none;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease, bottom 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 0;
    pointer-events: none;
    box-sizing: border-box;
}

.ah-dl-bar-wrap.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Десктопное позиционирование: сверху под .top-bar (обычно высота топ-бара ~60-68px) */
@media (min-width: 769px) {
    .ah-dl-bar-wrap {
        top: 76px;
    }
    .ah-dl-bar-wrap.visible {
        transform: translateX(-50%) translateY(0);
    }
}

/* Мобильное позиционирование: снизу над мобильным таб-баром (высота ~65px) */
@media (max-width: 768px) {
    .ah-dl-bar-wrap {
        top: auto;
        bottom: calc(88px + env(safe-area-inset-bottom, 0px));
        transform: translateX(-50%) translateY(120%);
        width: calc(100vw - 24px);
        max-width: 440px;
        height: 44px;
        padding: 0 16px;
        gap: 10px;
        border-radius: 9999px;
    }
    .ah-dl-bar-wrap.visible {
        transform: translateX(-50%) translateY(0);
    }
}

.ah-dl-bar-icon {
    width: 20px;
    height: 20px;
    color: #ff4d6d;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    animation: ahDlPulse 2s infinite ease-in-out;
}

@keyframes ahDlPulse {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 2px rgba(255,77,109,0.5)); }
    50% { transform: scale(1.12); filter: drop-shadow(0 0 8px rgba(255,77,109,0.9)); }
}

.ah-dl-bar-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
}

.ah-dl-bar-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.ah-dl-bar-title {
    font-size: 12.5px;
    font-weight: 600;
    color: #f0f2f7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ah-dl-bar-stat {
    font-size: 11.5px;
    font-weight: 700;
    color: #ff4d6d;
    white-space: nowrap;
}

.ah-dl-bar-track {
    height: 5px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.ah-dl-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #ff4d6d, #ff8fa3);
    border-radius: 3px;
    width: 0%;
    transition: width 0.25s ease-out;
    box-shadow: 0 0 10px rgba(255, 77, 109, 0.7);
}

.ah-dl-bar-chevron {
    width: 14px;
    height: 14px;
    color: #8b8e98;
    flex-shrink: 0;
    transition: transform 0.2s ease, color 0.2s ease;
}

.ah-dl-bar-wrap:hover .ah-dl-bar-chevron {
    color: #fff;
    transform: translateY(-2px);
}

/* ==========================================================
 * МОДАЛЬНОЕ ОКНО ДЕТАЛЕЙ ЗАГРУЗОК
 * ========================================================== */
.ah-dl-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(8, 9, 13, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 100050 !important;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.ah-dl-modal-overlay.open {
    opacity: 1;
}

.ah-dl-modal {
    width: min(520px, 100%);
    max-height: 85vh;
    background: rgba(18, 19, 26, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7), 0 0 30px rgba(255, 77, 109, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: ahDlModalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes ahDlModalIn {
    from { transform: scale(0.92) translateY(16px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.ah-dl-m-header {
    padding: 18px 20px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ah-dl-m-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.ah-dl-m-cover-wrap {
    width: 44px;
    height: 58px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: #0f1016;
}

.ah-dl-m-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ah-dl-m-header-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.ah-dl-m-size-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    font-size: 11px;
    color: #94a3b8;
}

.ah-dl-size-tag {
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 7px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    white-space: nowrap;
}

.ah-dl-size-tag b {
    color: #ff4d6d;
    font-weight: 700;
}

.ah-dl-m-icon {
    width: 24px;
    height: 24px;
    color: #ff4d6d;
}

.ah-dl-m-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ah-dl-m-close {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #cbd5e1;
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    aspect-ratio: 1 / 1;
    border-radius: 50% !important;
    padding: 0;
    margin: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    -webkit-appearance: none !important;
    appearance: none !important;
    box-sizing: border-box;
    flex-shrink: 0;
    z-index: 10;
}

.ah-dl-m-close svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2.2;
    display: block;
    pointer-events: none;
}

.ah-dl-m-close:hover {
    background: rgba(255, 77, 109, 0.25);
    border-color: #ff4d6d;
    color: #fff;
    transform: rotate(90deg) scale(1.05);
}

/* Сводная статистика вверху модалки */
.ah-dl-m-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 14px 20px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ah-dl-stat-box {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.ah-dl-stat-label {
    font-size: 10.5px;
    color: #8b8e98;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.ah-dl-stat-val {
    font-size: 14px;
    font-weight: 700;
    color: #f0f2f7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
}

.ah-dl-stat-val.accent {
    color: #ff4d6d;
}

/* Общий прогресс-бар модалки */
.ah-dl-m-progress-section {
    padding: 12px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ah-dl-m-bar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 6px;
    color: #a0a3bd;
}

.ah-dl-m-prog-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.ah-dl-m-mb-stat {
    font-size: 11.5px;
    color: #8b8e98;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.ah-dl-item-mb {
    font-size: 11.5px;
    color: #8b8e98;
    font-weight: 600;
    margin-right: 6px;
    font-variant-numeric: tabular-nums;
}

.ah-dl-m-bar-track {
    height: 7px;
    background: #23242b;
    border-radius: 4px;
    overflow: hidden;
}

.ah-dl-m-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #ff4d6d, #ff8fa3);
    width: 0%;
    transition: width 0.25s ease;
    box-shadow: 0 0 10px rgba(255, 77, 109, 0.6);
}

/* Список скачиваемых элементов */
.ah-dl-m-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 260px;
}

.ah-dl-m-list::-webkit-scrollbar {
    width: 5px;
}
.ah-dl-m-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.ah-dl-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    transition: background 0.2s ease;
}

.ah-dl-item.current {
    background: rgba(255, 77, 109, 0.08);
    border-color: rgba(255, 77, 109, 0.3);
}

.ah-dl-item.done {
    opacity: 0.6;
}

.ah-dl-item-left {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ah-dl-item-title {
    font-size: 13px;
    font-weight: 600;
    color: #f0f2f7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ah-dl-item-subtitle {
    font-size: 11px;
    color: #8b8e98;
}

.ah-dl-item-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.ah-dl-item-status {
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.ah-dl-item.current .ah-dl-item-status {
    color: #ff4d6d;
}

.ah-dl-item.done .ah-dl-item-status {
    color: #4ade80;
}

.ah-dl-item-retry {
    background: rgba(255, 77, 109, 0.14);
    border: 1px solid rgba(255, 77, 109, 0.4);
    color: #ff4d6d;
    height: 24px;
    padding: 0 8px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 700;
    transition: all 0.2s ease;
}

.ah-dl-item-retry:hover {
    background: #ff4d6d;
    color: #ffffff;
    box-shadow: 0 0 10px rgba(255, 77, 109, 0.4);
}

.ah-dl-item-retry svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    pointer-events: none;
}

.ah-dl-item-cancel {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #94a3b8;
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    margin: 0;
    transition: all 0.2s ease;
}

.ah-dl-item-cancel:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
    color: #ef4444;
    transform: scale(1.1);
}

.ah-dl-item-cancel svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    pointer-events: none;
}

.ah-dl-m-footer {
    padding: 12px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    justify-content: flex-end;
}

.ah-dl-m-btn-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: rgba(255, 77, 109, 0.15);
    border: 1px solid rgba(255, 77, 109, 0.4);
    border-radius: 10px;
    color: #fff;
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
}

.ah-dl-m-btn-link:hover {
    background: #ff4d6d;
    box-shadow: 0 0 15px rgba(255, 77, 109, 0.4);
}
