/* ==========================================
   ПЛАВАЮЩИЙ МИНИ-ПЛЕЕР (Picture-in-Picture)
   ========================================== */
.ah-floating-pip {
    position: fixed;
    width: 380px;
    height: 235px;
    min-width: 260px;
    min-height: 160px;
    max-width: 900px;
    max-height: 600px;
    background: rgba(18, 19, 24, 0.96);
    border: 1px solid rgba(255, 77, 109, 0.5);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.8), 0 0 20px rgba(255, 77, 109, 0.25);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: ahPipSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
    user-select: none;
    touch-action: none;
}

/* Плавная анимация изменения размера при клике на кнопки пресетов или двойном тапе */
.ah-floating-pip.is-animating-size {
    transition: width 0.32s cubic-bezier(0.2, 0.9, 0.3, 1),
                height 0.32s cubic-bezier(0.2, 0.9, 0.3, 1),
                left 0.32s cubic-bezier(0.2, 0.9, 0.3, 1),
                top 0.32s cubic-bezier(0.2, 0.9, 0.3, 1),
                box-shadow 0.25s ease !important;
}

/* Плавное затухание при закрытии мини-плеера */
.ah-floating-pip.is-closing {
    opacity: 0 !important;
    transform: scale(0.86) translateY(12px) !important;
    transition: opacity 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
    pointer-events: none !important;
}

/* Режим перетаскивания окна по экрану (Windows-style) */
.ah-floating-pip.is-dragging {
    transition: none !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    border-color: #ff4d6d !important;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.95), 0 0 32px rgba(255, 77, 109, 0.45) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    will-change: left, top !important;
}
.ah-floating-pip.is-dragging .ah-pip-header {
    cursor: grabbing !important;
}

/* Режим ручного изменения размера за угол */
.ah-floating-pip.is-resizing {
    transition: none !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    border-color: #ff4d6d;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.9), 0 0 25px rgba(255, 77, 109, 0.4);
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    will-change: width, height !important;
}

.ah-floating-pip.hidden {
    display: none !important;
}

@keyframes ahPipSlideIn {
    from {
        transform: scale(0.92);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Угловая ручка изменения размера (Bottom-Right) */
.ah-pip-resize {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    z-index: 10;
    cursor: nwse-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.35);
    transition: color 0.15s, background 0.15s;
    border-radius: 8px 0 14px 0;
    background: rgba(0, 0, 0, 0.4);
}
.ah-pip-resize svg {
    width: 12px;
    height: 12px;
}
.ah-pip-resize:hover {
    color: #ff4d6d;
    background: rgba(255, 77, 109, 0.35);
}

/* Шапка окна для перетаскивания (Header / Titlebar) */
.ah-pip-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 10px 7px 12px;
    background: rgba(10, 11, 14, 0.94);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}
.ah-pip-header:active {
    cursor: grabbing;
}

.ah-pip-title {
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    flex: 1;
    margin-right: 8px;
}

.ah-pip-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.ah-pip-btn {
    background: transparent;
    border: none;
    color: #8b8e98;
    cursor: pointer;
    padding: 5px;
    border-radius: 6px;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ah-pip-btn svg {
    width: 14px;
    height: 14px;
    pointer-events: none;
}
.ah-pip-btn:hover {
    color: #ff4d6d;
    background: rgba(255, 255, 255, 0.08);
}

.ah-pip-body {
    flex: 1;
    position: relative;
    background: #000;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.ah-pip-body video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    background: #000;
}
.ah-pip-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    background: rgba(0, 0, 0, 0.45);
    transition: opacity 0.2s;
    cursor: pointer;
}
.ah-floating-pip:hover .ah-pip-overlay {
    opacity: 1;
}
.ah-pip-play-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 77, 109, 0.95);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 16px rgba(255, 77, 109, 0.6);
    transition: transform 0.2s;
    cursor: pointer;
}
.ah-pip-play-btn svg {
    width: 22px;
    height: 22px;
    display: block;
    fill: currentColor;
    pointer-events: none;
}
.ah-pip-play-btn .ic-pip-play {
    margin-left: 2px;
}
.ah-pip-play-btn:hover {
    transform: scale(1.1);
}
.ah-pip-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(255, 255, 255, 0.15);
    overflow: hidden;
}
.ah-pip-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #ff4d6d, #ff8fa3);
    transition: width 0.25s linear;
}

@media (max-width: 768px) {
    #ah-pip-size-btn,
    #ah-pip-resize {
        display: none !important;
    }

    .ah-floating-pip {
        min-width: 180px;
        min-height: 110px;
        max-width: calc(100vw - 16px);
        max-height: calc(100vh - 120px);
        box-shadow: 0 16px 40px rgba(0, 0, 0, 0.9), 0 0 16px rgba(255, 77, 109, 0.25) !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: #111217 !important;
    }

    /* Верхняя панель управления с кнопкой закрытия всегда активна и видна */
    .ah-floating-pip .ah-pip-header {
        display: flex !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        height: 38px !important;
        padding: 0 8px 0 12px !important;
        background: rgba(12, 13, 17, 0.96) !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
        z-index: 20 !important;
        touch-action: none !important;
    }

    .ah-floating-pip .ah-pip-title {
        font-size: 11.5px !important;
        color: #fff !important;
        font-weight: 600 !important;
    }

    .ah-floating-pip .ah-pip-actions {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
    }

    .ah-floating-pip #ah-pip-close,
    .ah-floating-pip #ah-pip-expand {
        width: 32px !important;
        height: 32px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: rgba(255, 255, 255, 0.08) !important;
        border-radius: 8px !important;
        color: #f0f2f8 !important;
        cursor: pointer !important;
        padding: 0 !important;
        border: none !important;
    }

    .ah-floating-pip #ah-pip-close svg,
    .ah-floating-pip #ah-pip-expand svg {
        width: 16px !important;
        height: 16px !important;
        stroke: currentColor !important;
        stroke-width: 2.2 !important;
    }

    .ah-floating-pip #ah-pip-close:active {
        background: rgba(255, 77, 109, 0.35) !important;
        color: #ff4d6d !important;
    }

    .ah-floating-pip .ah-pip-overlay {
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    .ah-floating-pip.controls-visible .ah-pip-overlay {
        opacity: 1;
        pointer-events: auto;
        background: rgba(0, 0, 0, 0.45);
    }
}
