/* =====================================================
   RandomChat - Clean & Modern Style
   ===================================================== */

:root {
    --bg-dark: #000;
    --bg-panel: #1a1a1a;
    --text-active: #fff;
    --text-muted: #888;
    --accent-blue: #007bff;
    --accent-green: #28a745;
    --accent-red: #dc3545;
    --border-color: #333;
    --radius: 8px;
    --nav-height: 60px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-dark);
    color: var(--text-active);
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 10px;
}

/* Header */
.header {
    height: var(--nav-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--bg-panel);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    margin-bottom: 10px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1.2rem;
}

.logo svg {
    width: 24px;
    height: 24px;
    color: var(--accent-blue);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: 0.2s;
}

.icon-btn:hover {
    color: var(--text-active);
    background: rgba(255, 255, 255, 0.1);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: hidden;
}

/* Video Grid - Left/Right Split */
.video-grid {
    flex: 2;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    min-height: 0;
    /* Important for flex child scroll/resize */
}

.video-card {
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.video-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
    background: #000;
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    /* Mirror effect */
}


.partner-info {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-items: flex-end;
    z-index: 15;
}

.info-badge {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.info-badge.name {
    font-weight: 700;
    font-size: 13px;
    background: var(--accent-blue);
    border: none;
}

.video-label {
    position: absolute;
    bottom: 10px;
    left: 10px;
    top: auto;
    background: rgba(0, 0, 0, 0.6);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    z-index: 10;
    pointer-events: none;
}

.video-overlay {
    position: absolute;
    inset: 0;
    background: #111;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

.video-overlay.hidden {
    display: none;
}


.media-status-indicators {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    pointer-events: none;
    z-index: 12;
}

.status-icon {
    width: 60px;
    height: 60px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    padding: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    opacity: 0.8;
    backdrop-filter: blur(4px);
}

.status-icon.hidden {
    display: none;
}

.status-icon svg {
    width: 100%;
    height: 100%;
    stroke-width: 2px;
}


.status-content {
    text-align: center;
    color: var(--text-muted);
}

/* Main Controls (Start/Next/Stop) */
.media-controls-overlay {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 20;
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 16px;
    border-radius: 30px;
    backdrop-filter: blur(4px);
}

.overlay-btn {
    background: none;
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.2s;
}

.overlay-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.overlay-btn.muted {
    background: var(--accent-red);
    /* Red background when disabled */
    color: #fff;
}

.overlay-btn.muted:hover {
    background: #cc0000;
    /* Darker red on hover */
}

.overlay-btn svg {
    width: 20px;
    height: 20px;
}



.hidden {
    display: none;
}

/* Bottom Section: Chat & Action Buttons */
.bottom-section {
    flex: 1;
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 10px;
    min-height: 200px;
    max-height: 300px;
}

.chat-box {
    background: var(--bg-panel);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-message {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
}

.chat-message.sent {
    align-self: flex-end;
    background: var(--accent-blue);
    color: #fff;
    border-bottom-right-radius: 2px;
}

.chat-message.received {
    align-self: flex-start;
    background: #333;
    color: #fff;
    border-bottom-left-radius: 2px;
}

.chat-message.system {
    align-self: center;
    background: none;
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
    padding: 4px;
}

.chat-input-area {
    padding: 10px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    background: var(--bg-panel);
}

.chat-input-area input {
    flex: 1;
    background: #000;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 0 15px;
    color: #fff;
    outline: none;
    height: 40px;
}

.chat-input-area button {
    width: 40px;
    height: 40px;
    background: var(--accent-blue);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
}

.chat-input-area button:hover:not(:disabled) {
    transform: scale(1.1) rotate(-10deg);
    background: var(--accent-hover);
}

.chat-input-area button:disabled {
    background: #333;
    cursor: not-allowed;
    opacity: 0.5;
}

.chat-input-area button svg {
    width: 20px;
    height: 20px;
    margin-left: -2px;
    /* Center optical alignment for paper plane */
    margin-top: 2px;
}

/* Main Controls (Start/Next/Stop) */
.main-controls {
    padding: 15px;
    display: flex;
    flex-direction: column;
    /* Vertical Layout for Desktop */
    gap: 12px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-panel);
}

.ctl-btn {
    height: 50px;
    border: none;
    border-radius: 8px;
    /* Rounded corners */
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.1s, background 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    /* Full width container */
}

.ctl-btn svg {
    width: 24px;
    height: 24px;
}

.ctl-btn.start {
    background: var(--accent-green);
    color: #fff;
    flex: 1;
    /* Take full width */
}

.active-controls {
    /* Removed */
}

.ctl-btn.next {
    background: var(--accent-blue);
    color: #fff;
    flex: 2;
    /* Next button wider if visible alongside Stop */
}

.ctl-btn.stop {
    background: #333;
    color: #fff;
    flex: 1;
}

.ctl-btn.start:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #0056b3;
}

.ctl-btn.next:disabled {
    background: #555;
    color: #888;
    box-shadow: none;
    cursor: not-allowed;
}

.ctl-btn.stop:hover:not(:disabled) {
    background: var(--accent-red);
    color: #fff;
}

.ctl-btn.stop:disabled {
    border-color: #555;
    color: #555;
    cursor: not-allowed;
}

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: 0.3s;
}

.modal.visible {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: var(--bg-panel);
    border-radius: 12px;
    padding: 20px;
    width: 90%;
    max-width: 400px;
    border: 1px solid var(--border-color);
    color: #fff;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.close-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
}

.form-group {
    margin-bottom: 15px;
}


.form-row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

.form-group.half {
    flex: 1;
    margin-bottom: 0;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-muted);
    font-size: 14px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    background: #000;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: #fff;
    outline: none;
}

.save-btn {
    width: 100%;
    padding: 12px;
    background: var(--accent-green);
    border: none;
    border-radius: 6px;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
}

/* Loading */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
}

.loading-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    body {
        height: 100vh;
        height: 100dvh;
        /* Dynamic Viewport Height for mobile browsers */
        overflow: hidden;
    }

    .app-container {
        padding: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .header {
        height: 50px;
        border-radius: 0;
        margin-bottom: 0;
        border: none;
        border-bottom: 1px solid var(--border-color);
        padding: 0 15px;
    }

    .main-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 0;
        overflow: hidden;
    }

    /* Split Video Layout for Mobile */
    .video-grid {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        gap: 2px;
        padding: 0;
        background: #000;
        overflow: hidden;
    }

    .video-card {
        flex: 1;
        /* Force equal height (50:50) */
        width: 100%;
        height: auto;
        /* Let flex dictate height */
        border-radius: 0;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #111;
        position: relative;
        overflow: hidden;
    }

    .video-wrapper {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Zoom to fill */
    .video-wrapper video {
        width: 100%;
        height: 100%;
        object-fit: cover;
        background: #000;
    }

    /* Compact Info Badges on Mobile */
    .partner-info {
        top: 10px;
        right: 10px;
        gap: 3px;
        align-items: flex-end;
    }

    .info-badge {
        padding: 3px 8px;
        font-size: 10px;
        border-radius: 8px;
        backdrop-filter: blur(2px);
    }

    .info-badge.name {
        font-size: 12px;
        margin-bottom: 2px;
    }

    .video-label {
        bottom: 10px;
        left: 10px;
        padding: 2px 8px;
        font-size: 10px;
    }

    /* Compact Status Icons */
    .status-icon {
        width: 50px;
        height: 50px;
        padding: 12px;
    }

    /* Overlay Controls on Mobile */
    .media-controls-overlay {
        bottom: 15px;
        padding: 6px 14px;
        gap: 12px;
    }

    .overlay-btn {
        width: 36px;
        height: 36px;
    }

    .overlay-btn svg {
        width: 18px;
        height: 18px;
    }

    /* Bottom Section (Chat & Controls) */
    .bottom-section {
        flex: none;
        height: auto;
        min-height: auto;
        display: flex;
        flex-direction: column;
        background: var(--bg-panel);
        border-top: 1px solid var(--border-color);
    }

    /* Fixed height chat on mobile */
    .chat-box {
        border: none;
        border-radius: 0;
        background: transparent;
        height: 140px;
        display: flex;
        flex-direction: column;
    }

    .chat-messages {
        padding: 10px;
        font-size: 13px;
        flex: 1;
        min-height: 0;
    }

    .chat-input-area {
        padding: 8px 10px;
        background: transparent;
    }

    .chat-input-area input {
        height: 38px;
        font-size: 14px;
    }

    .chat-input-area button {
        width: 38px;
        height: 38px;
    }

    /* Main Controls (Start/Next/Stop) */
    .main-controls {
        flex: none;
        padding: 12px;
        display: flex;
        gap: 12px;
        background: #000;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        align-items: center;
        justify-content: space-between;
    }

    .ctl-btn {
        height: 52px;
        border-radius: 12px;
        display: flex;
        /* Ensure flex for centering icon */
        align-items: center;
        justify-content: center;
        margin: 0;
        /* Reset margins */
    }

    /* Hide Text on Mobile */
    .btn-text {
        display: none;
    }

    .ctl-btn svg {
        width: 28px;
        height: 28px;
    }

    /* Remove wrapper style */
    .active-controls {
        display: none;
    }

    .ctl-btn.stop {
        flex: 1;
        background: #333;
        order: 1;
    }

    .ctl-btn.next {
        flex: 2;
        order: 2;
        margin-left: 0;
    }

    .ctl-btn.start {
        width: 100%;
        flex: 1;
    }

    .ctl-btn:active {
        transform: scale(0.96);
    }
}

/* Landscape Mode Mobile Fix */
@media (max-width: 768px) and (orientation: landscape) {
    .video-grid {
        flex-direction: row;
    }

    .chat-box {
        display: none;
        /* Hide chat in landscape to prioritize video */
    }

    .bottom-section {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, 0.8);
    }

    .main-controls {
        background: transparent;
        padding: 5px;
    }

    .ctl-btn {
        height: 40px;
    }
}