/* Dark mode CSS variable design tokens */
:root {
    --bg-primary: #0b0d19;
    --bg-secondary: #161a30;
    --glass-bg: rgba(22, 26, 48, 0.6);
    --glass-border: rgba(255, 255, 255, 0.08);
    --text-primary: #f3f4f6;
    --text-muted: #9ca3af;
    --accent-blue: #0ea5e9;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --accent-yellow: #f59e0b;
    --accent-gradient: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
    --font-family: 'Plus Jakarta Sans', 'Inter', system-ui, -apple-system, sans-serif;
    --shadow-md: 0 4px 20px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 30px -3px rgba(0, 0, 0, 0.5);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: radial-gradient(circle at top right, #1e1b4b, var(--bg-primary) 60%);
    color: var(--text-primary);
    font-family: var(--font-family);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* App Header styling */
header {
    background: rgba(11, 13, 25, 0.7);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--glass-border);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.025em;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.username-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 9999px;
    padding: 0.4rem 1.2rem;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 600;
    outline: none;
    transition: var(--transition);
    max-width: 160px;
    text-align: center;
}

.username-input:focus {
    border-color: var(--accent-blue);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.2);
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    padding: 0.4rem 0.8rem;
    border-radius: 9999px;
    font-size: 0.85rem;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--accent-yellow);
}

.status-dot.connecting {
    background-color: var(--accent-yellow);
    box-shadow: 0 0 8px var(--accent-yellow);
    animation: pulse 1.5s infinite alternate;
}

.status-dot.connected {
    background-color: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green);
}

.status-dot.disconnected {
    background-color: var(--accent-red);
    box-shadow: 0 0 8px var(--accent-red);
}

@keyframes pulse {
    0% { transform: scale(0.8); opacity: 0.5; }
    100% { transform: scale(1.2); opacity: 1; }
}

/* Main Dashboard layout */
main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1.5rem;
    padding: 1.5rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

@media (max-width: 1024px) {
    main {
        grid-template-columns: 1fr;
    }
}

/* Video Section (Left side) */
.media-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.video-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    min-height: 450px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1rem;
    position: relative;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(12px);
}

.video-wrapper {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    border: 1px solid rgba(255, 255, 255, 0.05);
    aspect-ratio: 16/9;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.video-wrapper:hover {
    transform: translateY(-2px);
    border-color: var(--accent-blue);
    box-shadow: 0 8px 25px rgba(14, 165, 233, 0.2);
}

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

.video-label {
    position: absolute;
    bottom: 0.75rem;
    left: 0.75rem;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Grid Empty State Placeholder */
.grid-placeholder {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
}

.grid-placeholder svg {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    color: var(--text-muted);
    opacity: 0.5;
}

.grid-placeholder p {
    font-size: 0.95rem;
}

/* Control Bar underneath video grid */
.controls-bar {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(12px);
}

.control-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    cursor: pointer;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

.control-btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    box-shadow: 0 0 12px rgba(14, 165, 233, 0.4);
}

.control-btn.active:hover {
    background: #0284c7;
}

.control-btn.muted {
    background: var(--accent-red);
    border-color: var(--accent-red);
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
}

.control-btn.muted:hover {
    background: #dc2626;
}

/* Chat & Users Pane (Right side) */
.sidebar-pane {
    display: flex;
    flex-direction: column;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    overflow: hidden;
    height: calc(100vh - 100px);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(12px);
}

.pane-section {
    display: flex;
    flex-direction: column;
}

.users-section {
    max-height: 200px;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(11, 13, 25, 0.2);
}

.chat-section {
    flex: 1;
    overflow: hidden;
}

.section-header {
    padding: 0.8rem 1.25rem;
    background: rgba(11, 13, 25, 0.4);
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.section-header h2 {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.users-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 1.25rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-content: flex-start;
}

/* User Badge styling */
.user-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 0.3rem 0.65rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    transition: var(--transition);
}

.user-badge:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-blue);
}

.user-badge.local {
    background: rgba(14, 165, 233, 0.1);
    border-color: rgba(14, 165, 233, 0.3);
    color: var(--accent-blue);
}

.user-badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-green);
}

/* Message Box style */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Custom Scrollbars */
.chat-messages::-webkit-scrollbar,
.video-grid::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-track,
.video-grid::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb,
.video-grid::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 9999px;
}
.chat-messages::-webkit-scrollbar-thumb:hover,
.video-grid::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-bubble {
    max-width: 85%;
    padding: 0.6rem 0.9rem;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.4;
    word-break: break-word;
}

.chat-bubble.remote {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-bottom-left-radius: 4px;
}

.chat-bubble.local {
    align-self: flex-end;
    background: var(--accent-gradient);
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.bubble-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.chat-bubble.local .bubble-meta {
    color: rgba(255, 255, 255, 0.7);
    text-align: right;
}

.system-message {
    align-self: center;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.2);
    color: var(--accent-yellow);
    font-size: 0.8rem;
    padding: 0.3rem 0.75rem;
    border-radius: 9999px;
    max-width: 90%;
    text-align: center;
    margin: 0.25rem 0;
}

.system-message.error {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
    color: var(--accent-red);
}

/* Chat Input form */
.chat-input-area {
    padding: 1rem;
    border-top: 1px solid var(--glass-border);
    background: rgba(11, 13, 25, 0.4);
}

.chat-form {
    display: flex;
    gap: 0.5rem;
}

.chat-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 9999px;
    padding: 0.6rem 1.2rem;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.88rem;
    outline: none;
    transition: var(--transition);
}

.chat-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.2);
    background: rgba(0, 0, 0, 0.3);
}

.chat-send-btn {
    background: var(--accent-blue);
    border: none;
    color: #fff;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.chat-send-btn:hover {
    background: #0284c7;
    transform: scale(1.05);
}

.chat-send-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.private-chat-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(14, 165, 233, 0.1);
    border: 1px solid rgba(14, 165, 233, 0.2);
    color: var(--accent-blue);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
}

.cancel-private-btn {
    background: none;
    border: none;
    color: var(--accent-blue);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0 0.2rem;
    transition: var(--transition);
}

.cancel-private-btn:hover {
    color: var(--accent-red);
    transform: scale(1.1);
}
