/**
 * Stage Containers — Drag & Drop & Resize для активной встречи
 * Стили для перемещаемых контейнеров видео, текста и зрителей
 */

/* === Stage Background === */
.stage-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    background-image: url('/assets/images/theater/stage.png');
    background-size: cover;
    background-position: center;
    filter: brightness(0.75) blur(2px);
    transition: filter 0.3s ease;
}

.stage-active:hover .stage-background {
    filter: brightness(0.85) blur(1px);
}

@media (min-width: 769px) {
    .stage-background {
        background-image: url('/assets/images/theater/stage-desktop.jpg');
    }
}

/* === Draggable Container Base === */
.draggable-container {
    position: absolute;
    z-index: 10;
    background: rgba(10, 10, 20, 0.9);
    backdrop-filter: blur(15px);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    touch-action: none; /* Для interact.js */
}

.draggable-container:hover {
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.7);
    border-color: rgba(255, 255, 255, 0.2);
}

.draggable-container.dragging {
    box-shadow: 0 16px 64px rgba(99, 102, 241, 0.3);
    border-color: var(--accent-primary);
    z-index: 100;
}

.draggable-container.resizing {
    border-color: var(--accent-primary);
}

.draggable-container.pinned {
    border-color: var(--accent-secondary);
    box-shadow: 0 0 0 2px var(--accent-secondary);
}

/* === Container Header === */
.container-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: move; /* Drag handle */
    user-select: none;
}

.container-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
}

.container-controls {
    display: flex;
    gap: 4px;
}

.container-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.container-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 1);
}

.container-btn:active {
    transform: scale(0.95);
}

/* === Container Content === */
.container-content {
    position: relative;
    width: 100%;
    height: calc(100% - 40px); /* Минус header */
    overflow: hidden;
}

/* === Resize Handles === */
.resize-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--accent-primary);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 5;
}

.draggable-container:hover .resize-handle {
    opacity: 1;
}

.resize-handle--se {
    right: -6px;
    bottom: -6px;
    cursor: nwse-resize;
}

.resize-handle--ne {
    right: -6px;
    top: -6px;
    cursor: nesw-resize;
}

.resize-handle--sw {
    left: -6px;
    bottom: -6px;
    cursor: nesw-resize;
}

.resize-handle--nw {
    left: -6px;
    top: -6px;
    cursor: nwse-resize;
}

/* === Video Containers === */
.video-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

.video-container .partner-name {
    position: absolute;
    bottom: 12px;
    left: 12px;
    padding: 4px 12px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 16px;
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.9);
}

/* Self video mirror effect */
.video-container[data-container="self"] video.mirrored {
    transform: scaleX(-1);
}

/* === Text Container === */
.text-container {
    display: flex;
    flex-direction: column;
}

.text-container .container-content {
    display: flex;
    flex-direction: row;
    padding: 16px;
    height: calc(100% - 40px);
}

.text-viewport {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    margin-right: 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.text-viewport::-webkit-scrollbar {
    width: 4px;
}

.text-viewport::-webkit-scrollbar-track {
    background: transparent;
}

.text-viewport::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

.text-lines {
    width: 100%;
}

.text-line {
    padding: 8px 0;
    font-size: 1em;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.7);
    transition: color 0.3s ease, opacity 0.3s ease;
    cursor: pointer;
}

.text-line.current {
    color: rgba(255, 255, 255, 1);
    font-weight: 500;
    border-left: 3px solid var(--accent-primary);
    padding-left: 12px;
}

.text-line.past {
    opacity: 0.4;
}

.text-line.future {
    opacity: 0.6;
}

.text-line-speaker {
    font-weight: 600;
    margin-right: 8px;
}

.text-line-speaker[data-role="role1"] {
    color: #ff6b9d;
}

.text-line-speaker[data-role="role2"] {
    color: #4ecdc4;
}

.text-line-content {
    display: inline;
}

.text-line-header {
    font-weight: 700;
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9em;
    white-space: pre-line;
}

.text-line-direction {
    font-style: italic;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.875em;
}

.text-line-end {
    text-align: center;
    font-size: 1.5em;
    font-weight: 700;
    letter-spacing: 0.3em;
    color: rgba(255, 255, 255, 0.8);
    padding: 2em 0;
    border-left: none !important;
    padding-left: 0 !important;
}

.text-line-end.current {
    color: var(--accent-primary);
}

/* Navigation side panel (right) */
.text-nav-side {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    flex-shrink: 0;
}

.text-nav-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.text-nav-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.text-nav-btn:active {
    transform: scale(0.95);
}

/* Font size buttons in header */
.text-fontsize-btn {
    font-weight: 600;
    font-size: 0.7rem;
    letter-spacing: -0.5px;
    min-width: 28px;
    text-align: center;
}

/* Progress counter in header */
.container-controls .text-progress {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    margin-left: 4px;
    white-space: nowrap;
}

/* === Viewers Container === */
.viewers-container {
    height: auto !important;
}

.viewers-container .container-content {
    padding: 10px;
}

.viewers-container .resize-handle {
    display: none;
}

.broadcast-status-dot {
    width: 8px;
    height: 8px;
    background: #ff4444;
    border-radius: 50%;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }
}

/* === Layout Menu === */
.layout-menu {
    position: absolute;
    bottom: 80px;
    right: 20px;
    width: 240px;
    background: rgba(10, 10, 20, 0.95);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 16px;
    z-index: 200;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.layout-menu-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.layout-preset-btn {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
}

.layout-preset-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(4px);
}

.layout-preset-btn:active {
    transform: translateX(2px);
}

/* === Background Replacement Menu === */
.bg-menu {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    width: 260px;
    max-height: 60vh;
    overflow-y: auto;
    background: rgba(10, 10, 20, 0.95);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 16px;
    z-index: 200;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.bg-menu-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.bg-menu-section {
    font-size: 0.75rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 12px 0 6px 0;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.bg-preset-btn {
    width: 100%;
    padding: 10px 14px;
    margin-bottom: 4px;
    border: none;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    display: block;
}

.bg-preset-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(4px);
}

.bg-preset-btn:active {
    transform: translateX(2px);
}

.bg-preset-btn.bg-preset-active {
    background: rgba(99, 102, 241, 0.3);
    border: 1px solid rgba(99, 102, 241, 0.5);
}

.bg-upload-btn {
    cursor: pointer;
}

.bg-loading {
    text-align: center;
    padding: 12px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.8rem;
    animation: bg-loading-pulse 1.5s infinite;
}

@keyframes bg-loading-pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

@media (max-width: 768px) {
    .bg-menu {
        width: 220px;
        max-height: 50vh;
        padding: 12px;
    }

    .bg-preset-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
}

/* === Snap Zones Hints === */
.snap-zone-hint {
    position: absolute;
    border: 2px dashed var(--accent-primary);
    background: rgba(99, 102, 241, 0.1);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 99;
}

.snap-zone-hint.active {
    opacity: 1;
}

/* === Mobile Adaptations === */
@media (max-width: 768px) {
    .draggable-container {
        border-radius: 8px;
    }

    .container-header {
        padding: 6px 10px;
    }

    .container-title {
        font-size: 0.75rem;
    }

    .container-btn {
        width: 20px;
        height: 20px;
        font-size: 0.7rem;
    }

    .resize-handle {
        width: 16px;
        height: 16px;
    }

    /* Hide viewers container on mobile (use FAB instead) */
    .viewers-container {
        display: none;
    }

    /*
     * Mobile Stage Layout:
     * When mobile-stage-overlay is active, desktop containers are hidden via :has() selector below.
     * The mobile-stage-overlay provides its own video/text layout.
     * These styles are kept as fallback for browsers without :has() support.
     */

    /* Hide desktop containers on mobile - they're replaced by mobile-stage-overlay */
    #partner-video-container,
    #text-container,
    #self-video-container {
        display: none !important;
    }

    .text-nav-side {
        gap: 8px;
        padding: 4px 0;
    }

    .text-nav-btn {
        width: 38px;
        height: 38px;
        font-size: 1rem;
    }
}

/* === Accessibility === */
.draggable-container:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* === Animations === */
@keyframes container-appear {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.draggable-container {
    animation: container-appear 0.3s ease;
}

/* === Fullscreen Mode === */
.draggable-container.fullscreen {
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 999;
    border-radius: 0;
}

.draggable-container.fullscreen .resize-handle {
    display: none;
}

.draggable-container.fullscreen .container-header {
    background: rgba(0, 0, 0, 0.8);
}

/* ===== Mobile Stage Overlay ===== */
.mobile-stage-overlay {
    display: none;
}

@media (max-width: 768px) {
    /* Show only when active */
    .mobile-stage-overlay.active {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 200;
        background: #000;
    }

    .mobile-stage-overlay > * {
        pointer-events: auto;
    }

    /* Hide desktop containers on mobile when overlay is active */
    .stage-active:has(.mobile-stage-overlay.active) > #partner-video-container,
    .stage-active:has(.mobile-stage-overlay.active) > #self-video-container,
    .stage-active:has(.mobile-stage-overlay.active) > #text-container,
    .stage-active:has(.mobile-stage-overlay.active) > #viewers-container,
    .stage-active:has(.mobile-stage-overlay.active) > .stage-controls,
    .stage-active:has(.mobile-stage-overlay.active) > .layout-menu,
    .stage-active:has(.mobile-stage-overlay.active) > .stage-background {
        display: none !important;
    }
}

/* === Mobile Tabs === */
.mobile-tabs {
    display: flex;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.9);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 300;
}

.mobile-tab {
    flex: 1;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 2px solid transparent;
}

.mobile-tab.active {
    color: var(--accent-gold, #d4af37);
    border-bottom-color: var(--accent-gold, #d4af37);
}

/* === Mobile Tab Content === */
.mobile-tab-content {
    display: none;
    flex: 1;
    position: relative;
    overflow: hidden;
}

.mobile-tab-content.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* === Mobile Stage Tab (Layer System) === */
#mobile-tab-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    /* Ensure absolute children get proper containing block size */
    overflow: hidden;
}

/* Layer 2: Text Overlay */
.mobile-text-overlay {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 80px; /* above controls */
    height: 50vh;
    background: rgba(10, 10, 20, 0.85);
    backdrop-filter: blur(10px);
    border-radius: 16px 16px 0 0;
    display: flex;
    flex-direction: column;
    z-index: 20;
    transition: height 0.3s ease, bottom 0.3s ease;
}

.mobile-text-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.mobile-text-progress {
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
}

.mobile-text-controls {
    display: flex;
    gap: 8px;
}

.mobile-text-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 50%;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.mobile-text-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.mobile-text-content {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    font-size: 18px;
    line-height: 1.6;
    color: #e0e0e0;
}

.mobile-text-drag-handle {
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
}

.drag-indicator {
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

/* Layer 1: Controls (always on top) */
.mobile-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
    padding-bottom: env(safe-area-inset-bottom, 0);
    z-index: 30;
}

.mobile-control-btn {
    width: 56px;
    height: 56px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.mobile-control-btn:active {
    transform: scale(0.95);
}

.mobile-control-btn.muted {
    background: rgba(255, 100, 100, 0.3);
}

.mobile-control-btn--danger {
    background: #c0392b;
}

.mobile-control-btn--danger:active {
    background: #a33;
}

/* Partner Video (fullscreen background, Layer 3) */
.mobile-partner-video {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    background: #111;
}

.mobile-partner-video video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Self Video PiP */
.mobile-self-video {
    position: absolute;
    top: 60px;
    right: 12px;
    width: 80px;
    height: 110px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    z-index: 25;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.mobile-self-video video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Mirror */
}

/* Viewers Badge */
.mobile-viewers-badge {
    position: absolute;
    top: 60px;
    left: 12px;
    background: rgba(0, 0, 0, 0.7);
    padding: 6px 12px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: white;
    z-index: 25;
}

/* === Mobile Settings Tab === */
#mobile-tab-settings {
    padding: 16px;
    overflow-y: auto;
    background: #0d0d15;
}

.mobile-settings-section {
    margin-bottom: 24px;
}

.mobile-settings-section h4 {
    color: var(--accent-gold, #d4af37);
    font-size: 14px;
    font-weight: 500;
    margin: 0 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.mobile-viewers-list {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    min-height: 60px;
}

.mobile-empty-state {
    color: rgba(255, 255, 255, 0.4);
    font-size: 14px;
    text-align: center;
    padding: 16px;
}

.mobile-settings-btn {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.mobile-settings-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.mobile-settings-btn--small {
    width: auto;
    padding: 8px 16px;
}

.mobile-setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: #e0e0e0;
    font-size: 14px;
}

.mobile-toggle {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    cursor: pointer;
}

.mobile-toggle.active {
    background: var(--accent-gold, #d4af37);
    color: #000;
}

.mobile-toggle.active .toggle-label::before {
    content: '✓ ';
}

.mobile-fontsize-controls {
    display: flex;
    gap: 8px;
}

.mobile-fontsize-btn {
    width: 40px;
    height: 32px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 14px;
    cursor: pointer;
}

.mobile-fontsize-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.mobile-range {
    width: 120px;
    accent-color: var(--accent-gold, #d4af37);
}
