:root {
    --bg-dark: #0f172a;
    --bg-panel: #1e293b;
    --bg-chat: #1e293b;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #ec4899;
    --border: #334155;
    --success: #10b981;
    --danger: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

/* Layout Grid */
.app-layout {
    display: grid;
    grid-template-columns: 1fr 350px;
    height: 100vh;
    width: 100%;
}

/* Video Section */
.video-section {
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 1.5rem;
    height: 100vh;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 40px;
}

.logo {
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 99px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    font-size: 0.875rem;
    font-weight: 500;
}

.status-searching {
    color: #fbbf24;
    border-color: #fbbf24;
}

.status-connected {
    color: var(--success);
    border-color: var(--success);
}

.status-error {
    color: var(--danger);
    border-color: var(--danger);
}

/* Video Main Area */
.video-grid {
    flex: 1;
    display: flex;
    gap: 1rem;
    height: 100%;
    /* Force fill */
    min-height: 0;
    /* Prevent overflow */
}

.video-card {
    flex: 1;
    background: #000;
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    border: 2px solid var(--border);
    transition: border-color 0.3s;
}

/* Hover effect only for interactive elements, not the whole card causing jumpiness */
.video-card:hover {
    border-color: var(--primary);
}

.video-card video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-overlay {
    position: absolute;
    top: 1rem;
    left: 1rem;
    right: 1rem;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    /* Allow clicking video controls if any */
}

.video-overlay * {
    pointer-events: auto;
    /* Re-enable pointer for buttons */
}

.label {
    background: rgba(0, 0, 0, 0.6);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.875rem;
    backdrop-filter: blur(4px);
}

.placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-panel);
    color: var(--text-muted);
}

.loader {
    width: 48px;
    height: 48px;
    border: 4px solid var(--text-muted);
    border-bottom-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

.hidden {
    display: none !important;
}

/* Control Bar */
.controls-bar {
    display: flex;
    justify-content: center;
    gap: 1rem;
    height: 60px;
}

.control-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 2rem;
    border-radius: 12px;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
}

.control-btn:active {
    transform: scale(0.96);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.secondary {
    background: var(--bg-panel);
    color: var(--text-main);
    border: 1px solid var(--border);
}

.control-btn kbd {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: monospace;
}

/* Chat Sidebar */
.chat-sidebar {
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.chat-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 1rem;
    font-weight: 600;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.message {
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    max-width: 85%;
    font-size: 0.95rem;
    line-height: 1.4;
    word-wrap: break-word;
    /* Prevent overflow */
}

/* Different message types */
.msg-you {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 2px;
}

.msg-stranger {
    align-self: flex-start;
    background: var(--secondary);
    color: var(--text-main);
    border-bottom-left-radius: 2px;
}

.system-message {
    align-self: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    margin: 0.5rem 0;
}

.chat-input-area {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

#chatForm {
    display: flex;
    gap: 0.5rem;
}

#chatInput {
    flex: 1;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    padding: 0.75rem;
    border-radius: 8px;
    color: var(--text-main);
    outline: none;
}

#chatInput:focus {
    border-color: var(--primary);
}

#sendBtn {
    background: var(--secondary);
    border: none;
    color: var(--text-main);
    width: 40px;
    border-radius: 8px;
    cursor: pointer;
}

#sendBtn:hover {
    background: var(--border);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: var(--bg-panel);
    padding: 2rem;
    border-radius: 12px;
    width: 400px;
    border: 1px solid var(--border);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.form-group select {
    width: 100%;
    padding: 0.5rem;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 6px;
}

.btn.primary {
    width: 100%;
    padding: 0.75rem;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
}

/* Icon Button */
.icon-btn {
    background: rgba(0, 0, 0, 0.5);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.8);
}

/* Responsive */
/* Responsive */
@media (max-width: 900px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 350px;
        /* Video takes flex space, Chat takes 350px */
        height: 100dvh;
        /* Use dynamic viewport height for mobile browsers */
    }

    .video-section {
        padding: 0.75rem;
        gap: 0.75rem;
        height: 100%;
        overflow: hidden;
    }

    .chat-sidebar {
        height: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
    }
}

@media (max-width: 600px) {
    .app-layout {
        grid-template-rows: 45vh 1fr;
        /* Top 45% video, Bottom rest Chat */
    }

    .video-section {
        padding: 0.5rem;
        position: relative;
        /* Contain absolute children */
    }

    /* PiP Mode for Local Video on Mobile */
    .video-grid {
        position: relative;
        display: block;
        /* Remove flex, handle manually */
        height: 100%;
        /* Fill the section */
    }

    .video-card.remote {
        width: 100%;
        height: 100%;
        position: absolute;
        inset: 0;
        z-index: 1;
        border: none;
        border-radius: 8px;
        object-fit: cover;
    }

    .video-card.local {
        position: absolute;
        right: 10px;
        top: 50px;
        /* Below header area */
        width: 80px;
        /* Slightly smaller for better visibility */
        height: 106px;
        z-index: 2;
        border: 2px solid rgba(255, 255, 255, 0.2);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    }

    .video-overlay {
        padding: 0.5rem;
        z-index: 2;
    }

    .label {
        font-size: 0.7rem;
        padding: 2px 6px;
    }

    /* Controls Overlay on Video */
    .controls-bar {
        position: absolute;
        bottom: 1rem;
        /* Lift up slightly from bottom edge of video section */
        left: 0;
        right: 0;
        z-index: 10;
        /* Above videos */
        height: auto;
        padding-bottom: 0;
        pointer-events: none;
        /* Let clicks pass through empty areas */
    }

    .control-btn {
        pointer-events: auto;
        /* Re-enable clicks */
        padding: 0 1.25rem;
        height: 44px;
        /* Tappable size */
        font-size: 0.95rem;
        backdrop-filter: blur(8px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    /* Compact Security Banner */
    .security-banner {
        padding: 0.5rem;
        font-size: 0.65rem;
        line-height: 1.2;
    }

    .security-banner strong {
        font-size: 0.75rem;
        margin-bottom: 0.1rem;
        display: inline;
        margin-right: 4px;
    }

    .security-banner p {
        display: inline;
    }
}

/* Security Banner */
.security-banner {
    background-color: #450a0a;
    color: #fca5a5;
    padding: 1rem;
    border-bottom: 1px solid #7f1d1d;
    font-size: 0.75rem;
    font-weight: 700;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
}


/* Security Alert Modal */
.security-modal-content {
    border: 1px solid #ef4444;
    text-align: center;
    background: #1e293b;
    box-shadow: 0 0 40px rgba(239, 68, 68, 0.2);
}

.security-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.security-modal-content h2 {
    color: #ef4444;
    margin-bottom: 0.5rem;
}

.security-modal-content p {
    color: var(--text-main);
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.security-modal-content .sub-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.btn.danger {
    background: #ef4444;
    color: white;
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn.danger:hover {
    background: #dc2626;
}

/* Report Button */
#reportBtn {
    background: rgba(239, 68, 68, 0.8);
    /* Red-500 */
    margin-left: auto;
}

#reportBtn:hover {
    background: rgba(220, 38, 38, 1);
    /* Red-600 */
}

/* Report Modal Styles */
.report-reasons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.radio-label:hover {
    border-color: var(--primary);
}

.radio-label input[type="radio"] {
    accent-color: var(--primary);
    width: 1.2rem;
    height: 1.2rem;
}

.radio-label span {
    font-size: 0.95rem;
}