/* ==================== GOOGLE FONT IMPORT ==================== */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Khmer:wght@100;200;300;400;500;600;700;800;900&display=swap');

/* ==================== CSS VARIABLES - BLUE THEME ==================== */
:root {
    --primary: #1a73e8;
    --primary-light: #4285f4;
    --primary-dark: #1557b0;
    --primary-gradient-start: #1a73e8;
    --primary-gradient-end: #0d47a1;
    --success: #0d9488;
    --danger: #dc2626;
    --warning: #f59e0b;
    --dark: #0f172a;
    --gray-dark: #1e293b;
    --gray: #64748b;
    --gray-light: #e2e8f0;
    --gray-lighter: #f1f5f9;
    --border-radius: 8px;
    --border-radius-lg: 16px;
    --border-radius-xl: 50px;
    --shadow: 0 10px 40px rgba(26, 115, 232, 0.15);
    --shadow-lg: 0 20px 60px rgba(26, 115, 232, 0.25);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==================== BASE STYLES ==================== */
* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box;
    font-family: 'Noto Sans Khmer', 'Khmer', 'Khmer OS', 'Khmer OS Siemreap', 'Moul', 'Khmer UI', 'System Khmer', sans-serif;
}

body { 
    background: var(--dark);
    color: white;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ==================== UTILITY CLASSES ==================== */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-10 { gap: 10px; }
.gap-15 { gap: 15px; }
.text-center { text-align: center; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

/* ==================== ANIMATIONS ==================== */
@keyframes spin { 
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
@keyframes fadeInOut {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
}
@keyframes slideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
@keyframes slideIn {
    from { transform: translateY(-30px) scale(0.95); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* ==================== LOGIN SCREEN ==================== */
#login-container {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-gradient-start) 0%, var(--primary-gradient-end) 100%);
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}
#login-container::before {
    content: '';
    position: absolute;
    width: 500px;
    height: 500px;
    background: rgba(255,255,255,0.05);
    border-radius: 50%;
    top: -200px;
    right: -200px;
}
#login-container::after {
    content: '';
    position: absolute;
    width: 300px;
    height: 300px;
    background: rgba(255,255,255,0.03);
    border-radius: 50%;
    bottom: -100px;
    left: -100px;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    position: relative;
    z-index: 1;
}

.logo { text-align: center; margin-bottom: 30px; }
.logo h1 {
    color: var(--primary);
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.logo p {
    color: var(--gray);
    font-size: 14px;
    margin-top: 5px;
    -webkit-text-fill-color: var(--gray);
}

/* Form Elements */
.form-group { margin-bottom: 20px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--gray-dark);
    font-weight: 500;
    font-size: 14px;
}
.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--gray-light);
    border-radius: var(--border-radius);
    font-size: 16px;
    transition: var(--transition);
    background: var(--gray-lighter);
}
.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(26,115,232,0.1);
}
.form-group input.error { 
    border-color: var(--danger);
    box-shadow: 0 0 0 4px rgba(220,38,38,0.1);
}

/* Room ID Display */
.room-id-display {
    background: var(--gray-lighter);
    border: 2px solid var(--gray-light);
    border-radius: var(--border-radius);
    padding: 14px;
    font-size: 20px;
    text-align: center;
    color: var(--primary);
    margin-bottom: 10px;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
    letter-spacing: 1px;
}
.room-id-display:hover {
    background: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(26,115,232,0.1);
    transform: translateY(-2px);
}
.room-id-label {
    font-size: 12px;
    color: var(--gray);
    margin-bottom: 5px;
    text-align: center;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Buttons */
button {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}
button::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}
button:hover::after {
    width: 300px;
    height: 300px;
}
button:hover { 
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(26,115,232,0.3);
}
button:active { transform: translateY(0px); }
button:disabled { 
    background: var(--gray); 
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.button-group {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}
.button-group button { flex: 1; }
.secondary-btn { background: var(--gray); }
.secondary-btn:hover { 
    background: var(--gray-dark);
    box-shadow: 0 4px 20px rgba(100,116,139,0.3);
}

.error-message {
    color: var(--danger);
    text-align: center;
    margin-top: 12px;
    font-size: 14px;
    min-height: 20px;
    font-weight: 500;
}

/* Device Selector */
#device-selector {
    margin: 15px 0;
    padding: 16px;
    background: var(--gray-lighter);
    border-radius: var(--border-radius);
}
#device-selector h4 {
    color: var(--gray-dark);
    font-size: 13px;
    margin-bottom: 4px;
    font-weight: 600;
}
#device-selector select {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--gray-light);
    border-radius: var(--border-radius);
    margin: 4px 0 12px;
    font-size: 14px;
    background: white;
    color: var(--gray-dark);
    transition: var(--transition);
    cursor: pointer;
}
#device-selector select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(26,115,232,0.1);
}

/* ==================== WAITING ROOM ==================== */
#waiting-room {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}
.waiting-card {
    background: white;
    padding: 40px;
    border-radius: var(--border-radius-lg);
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow-lg);
}
.waiting-title {
    font-size: 24px;
    color: var(--primary);
    margin-bottom: 20px;
    font-weight: 700;
}
.waiting-message {
    margin: 20px 0;
    color: var(--gray);
    line-height: 1.6;
}
.waiting-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--gray-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

/* Participant List */
.participant-list {
    background: var(--gray-lighter);
    border-radius: var(--border-radius);
    padding: 15px;
    margin: 20px 0;
    max-height: 200px;
    overflow-y: auto;
}
.participant-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--gray-light);
}
.participant-item:last-child { border-bottom: none; }
.participant-name { font-weight: 500; color: var(--gray-dark); }
.participant-badge {
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 600;
}
.badge-host { background: var(--primary); color: white; }
.badge-waiting { background: var(--warning); color: white; }

.approve-btn {
    background: var(--success);
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    margin-left: 5px;
    font-weight: 600;
    transition: var(--transition);
}
.approve-btn:hover { background: #0f766e; transform: scale(1.05); }
.deny-btn {
    background: var(--danger);
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: var(--transition);
}
.deny-btn:hover { background: #b91c1c; transform: scale(1.05); }

/* ==================== VIDEO CONTAINER ==================== */
#video-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 12px;
    padding: 12px 12px 80px;
    min-height: 100vh;
    background: var(--dark);
    transition: background-color 0.2s ease;
}
#video-container.fullscreen-mode {
    display: block;
    position: relative;
    background: #000;
    padding: 0;
}

/* Video Wrapper */
.video-wrapper {
    position: relative;
    background: var(--dark);
    border-radius: 12px;
    overflow: hidden;
    aspect-ratio: 16/9;
    transition: var(--transition);
    cursor: pointer;
    border: 2px solid transparent;
}
.video-wrapper:hover { border-color: rgba(26,115,232,0.3); }
.video-wrapper.selected { 
    border-color: var(--primary);
    box-shadow: 0 0 30px rgba(26,115,232,0.2);
}
.video-wrapper video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

/* Fullscreen Mode */
#video-container.fullscreen-mode .video-wrapper {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    border-radius: 0;
    border-color: transparent;
}
#video-container.fullscreen-mode .video-wrapper:not(.focused) {
    position: fixed;
    width: 240px;
    height: 135px;
    bottom: 100px;
    right: 20px;
    top: auto;
    left: auto;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.6);
    z-index: 1001;
    border: 2px solid var(--primary);
}
#video-container.fullscreen-mode .video-wrapper:not(.focused):hover {
    transform: scale(1.05);
    z-index: 1002;
}
#video-container.fullscreen-mode .video-wrapper.focused { z-index: 1000; }
#video-container.fullscreen-mode .video-wrapper.focused video { object-fit: contain; }

/* Video Labels */
.video-label {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    z-index: 5;
    pointer-events: none;
    border: 1px solid rgba(255,255,255,0.1);
}
.host-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--warning);
    color: black;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    z-index: 6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.connection-type {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 10px;
    font-family: monospace;
    z-index: 42;
    border: 1px solid rgba(255,255,255,0.15);
    font-weight: 600;
    letter-spacing: 0.5px;
}
.connection-type.stun { color: #34d399; border-color: rgba(52,211,153,0.3); }
.connection-type.turn { color: #fbbf24; border-color: rgba(251,191,36,0.3); }
.connection-type.local { color: #60a5fa; border-color: rgba(96,165,250,0.3); }

/* Minimize Button */
.minimize-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: rgba(0,0,0,0.7);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 50%;
    color: white;
    font-size: 16px;
    cursor: pointer;
    z-index: 1010;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    opacity: 0;
}
.video-wrapper:hover .minimize-btn { opacity: 1; }
.minimize-btn:hover { background: rgba(220,38,38,0.9); transform: scale(1.1); }
.video-wrapper.minimized { display: none !important; }

/* Play Button */
.play-button {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    padding: 14px 28px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    box-shadow: 0 4px 20px rgba(26,115,232,0.4);
    transition: var(--transition);
}
.play-button:hover { 
    background: var(--primary-dark);
    transform: translate(-50%, -50%) scale(1.05);
}

/* ==================== CONTROLS ==================== */
#controls {
    position: fixed;
    bottom: max(24px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    padding: 12px 20px;
    background: rgba(15,23,42,0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: var(--border-radius-xl);
    z-index: 2000;
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}
.control-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.08);
    color: white;
    cursor: pointer;
    transition: var(--transition);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.control-btn:hover { 
    background: rgba(255,255,255,0.18);
    transform: scale(1.05);
}
.control-btn:active { transform: scale(0.95); }
.control-btn.danger { background: var(--danger); }
.control-btn.danger:hover { background: #b91c1c; }
.control-btn.active { background: var(--success); }
.control-btn.active:hover { background: #0f766e; }
.control-btn.recording {
    background: var(--danger);
    animation: pulse 1s infinite;
}

.control-btn.chat-off {
    background: rgba(255,255,255,0.08);
    color: white;
}

.control-btn.muted,
.control-btn.video-off {
    background: rgba(255,255,255,0.08);
    color: #ef4444;
    position: relative;
}
.control-btn.muted::after,
.control-btn.video-off::after {
    content: '✕';
    position: absolute;
    font-size: 14px;
    color: #ef4444;
    /* Center the cross symbol in the button */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* Remove the background circle if you want just the cross */
    background: transparent;
    width: auto;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    /* Optional: add slight shadow for visibility */
    text-shadow: 0 0 8px rgba(239, 68, 68, 0.3);
}

/* Context menu styles */
.context-menu-item {
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #1e293b;
    font-size: 14px;
    transition: background 0.2s;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: 'Noto Sans Khmer', sans-serif;
}
.context-menu-item:hover {
    background: #f1f5f9;
}
.context-menu-item.active {
    background: #e8f0fe;
    color: #1a73e8;
}
.context-menu-divider {
    height: 1px;
    background: #e2e8f0;
    margin: 4px 12px;
}

/* ==================== CHAT ==================== */
#chat-container {
    position: fixed;
    right: 20px;
    bottom: 100px;
    width: 340px;
    height: 440px;
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    z-index: 2000;
    overflow: hidden;
    border: 1px solid var(--gray-light);
}
#chat-container.visible { display: flex; }

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--gray-lighter);
}
.chat-message {
    margin-bottom: 12px;
    padding: 12px 16px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    border: 1px solid var(--gray-light);
	color: #1e293b;
}
.chat-message .sender {
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
    font-size: 13px;
}
.chat-message .sender span {
    font-weight: 400;
    color: var(--gray);
}

.chat-message > div:last-child {
    color: #1e293b;
    word-wrap: break-word;
}

.chat-input-area {
    display: flex;
    padding: 12px 16px;
    border-top: 1px solid var(--gray-light);
    gap: 10px;
    background: white;
}
.chat-input-area input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid var(--gray-light);
    border-radius: var(--border-radius);
    font-size: 14px;
    transition: var(--transition);
}
.chat-input-area input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(26,115,232,0.1);
}
.chat-input-area button {
    width: auto;
    padding: 10px 20px;
    border-radius: var(--border-radius);
    font-size: 14px;
}

/* ==================== STATUS INDICATORS ==================== */
#connection-status {
    position: fixed;
    top: 20px;
    left: 20px;
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
#connection-status.connected { background: rgba(13,148,136,0.9); color: white; }
#connection-status.disconnected { background: rgba(220,38,38,0.9); color: white; }
#connection-status.connecting { background: rgba(245,158,11,0.9); color: white; }

.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

/* ==================== ROOM INFO ==================== */
#room-info {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(15,23,42,0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: white;
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 2000;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.08);
    font-weight: 500;
    transition: var(--transition);
}
#room-info:hover {
    background: rgba(15,23,42,0.95);
    transform: translateY(-2px);
}

#invite-link {
    position: fixed;
    top: 62px;
    right: 20px;
    background: rgba(15,23,42,0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: white;
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 12px;
    z-index: 2000;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.08);
    transition: var(--transition);
    font-weight: 500;
}
#invite-link:hover { 
    background: rgba(15,23,42,0.95);
    transform: translateY(-2px);
}

/* ==================== FULLSCREEN HINTS ==================== */
.fullscreen-exit-hint {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(15,23,42,0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: white;
    padding: 16px 32px;
    border-radius: var(--border-radius-xl);
    font-size: 16px;
    z-index: 10000;
    animation: fadeInOut 2s ease-in-out;
    pointer-events: none;
    white-space: nowrap;
    font-weight: 500;
    border: 1px solid rgba(255,255,255,0.1);
}

/* ==================== MOBILE STYLES ==================== */
@media (max-width: 768px) {
    #video-container { 
        padding-top: 12px;
        padding-bottom: 100px;
        gap: 8px;
        padding-left: 8px;
        padding-right: 8px;
    }
    
    #connection-status { 
        top: 12px; 
        left: 12px;
        font-size: 12px;
        padding: 6px 14px;
    }
    #room-info { 
        top: 12px; 
        right: 12px;
        font-size: 12px;
        padding: 6px 14px;
    }
    #invite-link { 
        top: 58px; 
        right: 12px;
        font-size: 11px;
        padding: 6px 14px;
    }
    
    #video-container.fullscreen-mode .video-wrapper:not(.focused) {
        width: 120px;
        height: 68px;
        bottom: 80px;
        right: 12px;
    }
    
    .control-btn {
        width: 48px;
        height: 48px;
        font-size: 18px;
    }
    #controls {
        gap: 8px;
        padding: 8px 16px;
        bottom: max(16px, env(safe-area-inset-bottom));
    }
    
    #chat-container {
        width: calc(100% - 32px);
        height: 60vh;
        right: 16px;
        bottom: 100px;
    }
    
    .login-box { padding: 28px 20px; }
    
    .fullscreen-exit-hint {
        font-size: 14px;
        padding: 12px 20px;
        white-space: normal;
        text-align: center;
        max-width: 80%;
    }
}

/* ==================== IOS SAFE AREAS ==================== */
@supports (padding: max(0px)) {
    #video-container.fullscreen-mode {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
}

/* ==================== SCROLLBAR STYLING ==================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); border-radius: 10px; }
::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary-dark); }

/* ==================== SELECTION COLOR ==================== */
::selection { background: var(--primary); color: white; }