/* --------------------------------------------------------------------------
   CORE SYSTEM & RESET (Fixed 100dvh Zero-Scroll Rules)
   -------------------------------------------------------------------------- */
:root {
    --header-height: 52px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden; /* Strictly prevent whole-page scrolling */
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: #020617; /* Slate 950 */
}

/* Outer Shell Viewport */
.app-viewport {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
    position: relative;
}

/* Header */
.app-header {
    height: var(--header-height);
    min-height: var(--header-height);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(51, 65, 85, 0.4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 40;
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: all 0.25s ease;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.status-idle {
    background-color: rgba(51, 65, 85, 0.6);
    color: #94a3b8;
}
.status-idle .status-dot { background-color: #64748b; }

.status-searching {
    background-color: rgba(234, 179, 8, 0.15);
    color: #facc15;
    border: 1px solid rgba(234, 179, 8, 0.3);
}
.status-searching .status-dot {
    background-color: #facc15;
    box-shadow: 0 0 8px #facc15;
    animation: pulse 1.5s infinite;
}

.status-connecting {
    background-color: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}
.status-connecting .status-dot {
    background-color: #60a5fa;
    box-shadow: 0 0 8px #60a5fa;
    animation: pulse 1.5s infinite;
}

.status-connected {
    background-color: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}
.status-connected .status-dot {
    background-color: #34d399;
    box-shadow: 0 0 8px #34d399;
}

/* Main Container Area */
.app-main {
    flex: 1 1 0%;
    min-height: 0; /* Critical for inner scrolling boundaries */
    display: flex;
    position: relative;
    overflow: hidden;
}

/* --------------------------------------------------------------------------
   LOBBY / MATCHMAKING STYLES
   -------------------------------------------------------------------------- */
.lobby-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: radial-gradient(circle at center, rgba(30, 41, 59, 0.6) 0%, rgba(2, 6, 23, 0.95) 100%);
}

.lobby-card {
    width: 100%;
    max-width: 380px;
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(51, 65, 85, 0.6);
    border-radius: 20px;
    padding: 1.25rem;
    box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.preview-box {
    width: 100%;
    aspect-ratio: 16 / 10;
    border-radius: 14px;
    background: #020617;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(51, 65, 85, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-box video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Mirror camera */
}

.preview-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    text-align: center;
}

.preview-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.6);
    color: #94a3b8;
    backdrop-filter: blur(6px);
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, #4f46e5, #3b82f6);
    color: #ffffff;
    font-weight: 600;
    font-size: 0.875rem;
    padding: 0.75rem 1.25rem;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 16px -4px rgba(79, 70, 229, 0.4);
    transition: all 0.2s ease;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 20px -4px rgba(79, 70, 229, 0.6);
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-secondary {
    background: rgba(51, 65, 85, 0.6);
    color: #cbd5e1;
    font-size: 0.8125rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 10px;
    border: 1px solid rgba(71, 85, 105, 0.6);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: rgba(71, 85, 105, 0.8);
    color: white;
}

.radar-spinner {
    width: 42px;
    height: 42px;
    border: 3px solid rgba(99, 102, 241, 0.2);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* --------------------------------------------------------------------------
   CALL & CHAT SCREEN (Responsive Desktop & Mobile)
   -------------------------------------------------------------------------- */
.call-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

@media (min-width: 768px) {
    .call-container {
        flex-direction: row;
    }
}

/* Video Stage */
.video-stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    background: #000000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.video-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #020617;
}

.remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remote-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #090d16;
}

/* Picture in Picture (Local Video) */
.pip-video-wrapper {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 110px;
    aspect-ratio: 9 / 14;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    background: #0f172a;
    z-index: 20;
}

@media (min-width: 768px) {
    .pip-video-wrapper {
        width: 140px;
        top: 1.25rem;
        right: 1.25rem;
    }
}

.local-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

.pip-label {
    position: absolute;
    bottom: 4px;
    left: 4px;
    font-size: 9px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: #e2e8f0;
}

/* Floating Controls Bar */
.call-controls-bar {
    position: absolute;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0.6rem;
    border-radius: 9999px;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    z-index: 30;
}

.control-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: rgba(51, 65, 85, 0.6);
    color: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.control-btn:hover {
    background: rgba(71, 85, 105, 0.8);
    transform: scale(1.05);
}

.control-btn-danger {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: #ef4444;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
    transition: all 0.2s;
}

.control-btn-danger:hover {
    background: #dc2626;
    transform: scale(1.05);
}

/* --------------------------------------------------------------------------
   CHAT SIDEBAR & INTERNAL SCROLLING
   -------------------------------------------------------------------------- */
.chat-sidebar {
    width: 100%;
    height: 42%; /* Mobile split */
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #090e1a;
    border-top: 1px solid rgba(51, 65, 85, 0.4);
    position: relative;
    z-index: 10;
}

@media (min-width: 768px) {
    .chat-sidebar {
        width: 340px;
        min-width: 340px;
        height: 100%;
        border-top: none;
        border-left: 1px solid rgba(51, 65, 85, 0.4);
    }
}

.chat-header {
    height: 40px;
    min-height: 40px;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(15, 23, 42, 0.6);
    border-bottom: 1px solid rgba(51, 65, 85, 0.3);
}

/* Scrollable message stack */
.chat-messages {
    flex: 1 1 0%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overscroll-behavior: contain;
}

/* Custom Scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 4px;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(51, 65, 85, 0.6);
    border-radius: 4px;
}

.sys-message {
    text-align: center;
    font-size: 11px;
    color: #64748b;
    margin: 0.25rem 0;
}

/* Chat Bubbles */
.message-bubble {
    max-width: 82%;
    padding: 0.55rem 0.85rem;
    border-radius: 14px;
    font-size: 0.8125rem;
    line-height: 1.35;
    word-break: break-word;
    animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.message-sent {
    align-self: flex-end;
    background: #3b82f6;
    color: #ffffff;
    border-bottom-right-radius: 3px;
}

.message-received {
    align-self: flex-start;
    background: #1e293b;
    color: #e2e8f0;
    border: 1px solid rgba(51, 65, 85, 0.5);
    border-bottom-left-radius: 3px;
}

/* Chat Input Bar */
.chat-input-bar {
    height: 52px;
    min-height: 52px;
    padding: 0.45rem 0.65rem;
    background: rgba(15, 23, 42, 0.8);
    border-top: 1px solid rgba(51, 65, 85, 0.3);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-input {
    flex: 1;
    height: 38px;
    background: #0f172a;
    border: 1px solid rgba(51, 65, 85, 0.6);
    border-radius: 10px;
    padding: 0 0.75rem;
    font-size: 0.8125rem;
    color: #ffffff;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: #3b82f6;
}

.chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: none;
    background: #3b82f6;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: #2563eb;
}

/* --------------------------------------------------------------------------
   ANIMATIONS
   -------------------------------------------------------------------------- */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.9); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}