:root {
    --bg-color: #0f1115;
    --card-bg: #1e2128;
    --accent: #4a90e2;
    --accent-hover: #357abd;
    --danger: #ff4757;
    --text: #ffffff;
    --text-muted: #a0a0a0;
    --sidebar-width: 320px;
    --control-bar-height: 70px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* App Header */
.app-header {
    background-color: var(--card-bg);
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 100;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    background: linear-gradient(90deg, #fff, var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

/* App Container */
.app-container {
    display: flex;
    flex: 1;
    height: calc(100vh - var(--control-bar-height) - 60px); /* Adjust for header */
    position: relative;
}

/* Video Grid - Smart Layout */
.video-grid {
    flex: 1;
    display: flex; /* Changed from grid to flex for better centering when few items */
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    align-items: center;
    gap: 1.5rem;
    padding: 1.5rem;
    max-width: 1600px;
    margin: 0 auto;
    overflow-y: auto;
}

/* Video Cards */
.video-card {
    background-color: var(--card-bg);
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
    /* Fixed width for better centering logic */
    width: 100%;
    max-width: 480px;
    aspect-ratio: 16/9;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s;
    flex-grow: 1;
    flex-basis: 320px;
}

.video-card:hover {
    transform: scale(1.01);
}

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

/* Remote videos should generally NOT be mirrored, but let's keep consistency for now */
.remote-user video {
    transform: scaleX(1);
}

.name-tag {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    pointer-events: none;
}

/* AI Persona Specifics */
.ai-persona {
    border: 1px solid var(--accent);
    background: radial-gradient(circle at center, #1a2a3a 0%, #000 100%);
}

.ai-status {
    position: absolute;
    bottom: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.6);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
}

#aiVisualizer {
    width: 100%;
    height: 100%;
    opacity: 0.8;
}

.pulsing-dot {
    width: 8px;
    height: 8px;
    background-color: #444;
    border-radius: 50%;
    transition: background-color 0.3s;
}

/* AI Stats Overlay */
.ai-stats {
    position: absolute;
    top: 12px;
    left: 12px;
    right: auto;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    padding: 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    line-height: 1.5;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Chat Sidebar */
.chat-sidebar {
    width: var(--sidebar-width);
    background-color: var(--card-bg);
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.chat-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-msg {
    background: rgba(255, 255, 255, 0.05);
    padding: 10px 14px;
    border-radius: 12px;
    border-bottom-left-radius: 2px;
    font-size: 0.9rem;
    line-height: 1.4;
    max-width: 85%;
}

.chat-msg strong {
    display: block;
    color: var(--accent);
    font-size: 0.75rem;
    margin-bottom: 4px;
}

.chat-msg.self {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    border-radius: 12px;
    border-bottom-right-radius: 2px;
}

.chat-msg.self strong {
    color: rgba(255, 255, 255, 0.8);
}

#chat-form {
    padding: 1.5rem;
    display: flex;
    gap: 10px;
    background: rgba(0,0,0,0.2);
}

#chat-form input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.05);
    color: white;
    outline: none;
    transition: border-color 0.2s;
}

#chat-form input:focus {
    border-color: var(--accent);
}

#chat-form button {
    padding: 0 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

#chat-form button:hover {
    background: var(--accent-hover);
}

/* Floating Controls Bar */
.controls-bar {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 33, 40, 0.85);
    backdrop-filter: blur(12px);
    padding: 12px 24px;
    border-radius: 100px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 100;
}

.control-btn {
    padding: 12px 20px;
    border: none;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.control-btn.active {
    background: var(--accent);
    color: white;
}

.control-btn.danger {
    background: rgba(255, 71, 87, 0.2);
    color: var(--danger);
}

.control-btn.danger:hover {
    background: var(--danger);
    color: white;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    body {
        overflow: hidden; /* Prevent body scroll */
    }

    .app-container {
        flex-direction: row; /* Horizontal layout for scroll */
        height: calc(100vh - var(--control-bar-height) - 60px);
        width: 100vw;
        overflow-x: scroll; /* Enable horizontal scrolling */
        scroll-snap-type: x mandatory; /* Enable scroll snapping */
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }

    /* Video Section */
    .video-grid {
        flex: 0 0 100vw; /* Take full width */
        width: 100vw;
        min-width: 100vw;
        height: 100%;
        scroll-snap-align: start; /* Snap point */
        overflow-y: auto; /* Allow vertical scroll within video grid if needed */
        padding-bottom: 120px; /* Extra space for controls */
        
        /* Strict Grid for Mobile */
        display: grid;
        grid-template-columns: 1fr; /* Exactly one column */
        grid-auto-rows: auto; /* Rows size based on content */
        justify-items: center; /* Center items horizontally */
        align-content: start; /* Start packing from top */
        gap: 20px;
        padding-top: 20px;
    }

    /* Standard Video Cards (Humans) on Mobile */
    .video-card {
        width: 95%; /* Almost full width */
        max-width: 500px;
        height: auto;
        aspect-ratio: 16/9;
        margin: 0 0 20px 0; /* Changed to add margin-bottom for gap */
    }

    /* Mobile AI Floating Style (Bubbles) */
    .video-card.ai-persona {
        position: fixed; /* Float over content */
        z-index: 900;
        width: 80px;
        height: 80px;
        border-radius: 50%; /* Circle */
        right: 15px;
        box-shadow: 0 4px 10px rgba(0,0,0,0.5);
        background: #000;
        border: 2px solid var(--accent);
        padding: 0;
        max-height: none; /* Override previous restriction */
        flex-basis: auto;
        aspect-ratio: 1 / 1;
    }

    /* Specific positions for Host vs Guest bubbles */
    #ai-card-host {
        top: 80px; /* Below header */
    }

    #ai-card-guest {
        top: 170px; /* Below host bubble */
        border-color: #e24a90;
    }

    /* Adjust internals for bubble mode */
    .video-card.ai-persona canvas {
        border-radius: 50%;
        opacity: 0.8;
        width: 100%;
        height: 100%;
    }

    /* Hide text inside bubbles to keep it clean */
    .video-card.ai-persona .ai-status, 
    .video-card.ai-persona .ai-stats {
        display: none !important; 
    }
    
    /* Mobile Indicator (Button) */
    .nav-switch-btn {
        display: block !important;
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid var(--accent);
        color: var(--accent);
        padding: 6px 12px;
        border-radius: 20px;
        font-size: 0.8rem;
        font-weight: 600;
        cursor: pointer;
        position: absolute;
        right: 15px;
        transition: all 0.2s;
    }

    .nav-switch-btn:active {
        background: var(--accent);
        color: white;
    }

    /* Fixed Footer Area */
    .controls-bar {
        position: fixed; /* Strict fixing */
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        background: rgba(15, 17, 21, 0.95); /* Dark opaque background */
        backdrop-filter: blur(10px);
        padding: 15px 10px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 0; /* Full width, no radius */
        display: flex;
        gap: 12px;
        overflow-x: auto; /* Buttons scroll horizontally */
        justify-content: flex-start;
        z-index: 1000;
        transform: none; /* Reset center transform */
        box-shadow: 0 -5px 20px rgba(0,0,0,0.5);
    }
    
    /* Ensure content doesn't get hidden behind footer */
    .video-grid, .chat-sidebar {
        padding-bottom: 90px;
    }
}
/* ... Existing styles ... */

/* WAITING ROOM OVERLAY */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}

.overlay-content {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.overlay-content h2 {
    margin-top: 0;
    color: var(--accent);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    margin: 20px auto 0;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* HOST NOTIFICATIONS (TOASTS) */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 90%;
    max-width: 400px;
}

.toast {
    background: #1e2128;
    color: white;
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--accent);
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.toast-message {
    font-size: 0.9rem;
    font-weight: 500;
}

.toast-actions {
    display: flex;
    gap: 8px;
}

.toast-btn {
    padding: 6px 12px;
    border-radius: 6px;
    border: none;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.2s;
}

.toast-btn.accept {
    background: var(--accent);
    color: white;
}

.toast-btn.deny {
    background: rgba(255, 71, 87, 0.2);
    color: var(--danger);
}

.toast-btn:hover {
    filter: brightness(1.1);
}

/* AI & Podcast Controls */
.ai-controls-panel {
    padding: 1.5rem;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.ai-controls-panel h4 {
    margin: 0 0 10px 0;
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.control-select {
    width: 100%;
    padding: 10px;
    background-color: var(--card-bg) !important;
    color: var(--text) !important;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    margin-bottom: 15px;
    outline: none;
    font-size: 0.9rem;
    cursor: pointer;
    appearance: none; /* Remove default arrow to style consistently if needed, but let's keep it simple first */
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 30px;
}

.control-select option {
    background-color: var(--card-bg) !important;
    color: var(--text) !important;
}

.podcast-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.podcast-controls input {
    padding: 10px;
    background-color: var(--card-bg);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    outline: none;
}

.podcast-controls select {
    padding: 10px;
    background-color: var(--card-bg);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    outline: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    appearance: none;
}

.podcast-controls .control-btn {
    width: 100%;
    justify-content: center;
}

/* Sidebar Tabs */
.sidebar-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.tab-btn {
    flex: 1;
    padding: 12px 10px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.tab-btn:hover {
    color: var(--text);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: rgba(255, 255, 255, 0.05);
}

.tab-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    flex: 1;
    overflow: hidden;
}

/* Downloads Panel */
.downloads-panel {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.downloads-panel h3 {
    margin-top: 0;
}

.analysis-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 15px;
}

.analysis-card h4 {
    margin: 0 0 10px 0;
    color: var(--accent);
}

.analysis-card p {
    font-size: 0.85rem;
    line-height: 1.4;
    color: #e0e0e0;
}

.analysis-card ul {
    font-size: 0.85rem;
    padding-left: 20px;
    margin: 10px 0;
}

.analysis-card .download-btn {
    display: inline-block;
    margin-top: 10px;
    margin-right: 5px;
    padding: 8px 12px;
    background: var(--accent);
    color: white;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 600;
    transition: background 0.2s;
    border: none;
    cursor: pointer;
}

.analysis-card .download-btn:hover {
    background: var(--accent-hover);
}

/* Screen Share Layout (Desktop Only) */
@media (min-width: 769px) {
    .video-grid.has-screen-share {
        display: grid;
        grid-template-columns: 1fr 300px;
        grid-auto-rows: min-content;
        align-items: start;
        align-content: start;
    }
    .video-card.is-screen-sharing {
        grid-column: 1 / 2;
        grid-row: 1 / 99; /* span multiple rows so side items flow next to it */
        max-width: none;
        width: 100%;
        height: auto;
        aspect-ratio: auto;
        max-height: calc(100vh - 140px);
    }
    .video-card.is-screen-sharing video {
        object-fit: contain;
        transform: scaleX(1); /* don't mirror screen shares */
    }
    .video-grid.has-screen-share .video-card:not(.is-screen-sharing) {
        grid-column: 2 / 3;
        width: 100%;
        max-width: none;
    }
}

