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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background: #1a1a1a;
    color: #ffffff;
    overflow: hidden;
    height: 100vh;
}

/* ===============================================
   CRITICAL: Screen Display Management
   =============================================== */

/* Hide everything by default */
#join-screen,
#video-screen {
    display: none !important;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
}

/* Only show active screen */
#join-screen.active {
    display: flex !important;
}

#video-screen.active {
    display: flex !important;
    flex-direction: column;
}

/* ===============================================
   BEAUTIFUL JOIN SCREEN - BLUE THEME
   =============================================== */

#join-screen {
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #3b82f6 100%);
    position: relative;
    overflow: hidden;
}

/* Animated background pattern */
#join-screen::before {
    content: '';
    position: absolute;
    width: 200%;
    height: 200%;
    background: 
        radial-gradient(circle at 20% 50%, rgba(59, 130, 246, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(37, 99, 235, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, rgba(30, 58, 138, 0.3) 0%, transparent 50%);
    animation: moveBackground 20s ease-in-out infinite;
}

@keyframes moveBackground {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(-50px, -50px); }
}

.join-wrapper {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 40px 20px;
}

.join-content {
    width: 100%;
    max-width: 480px;
    animation: fadeInUp 0.6s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Logo Section */
.join-logo {
    text-align: center;
    margin-bottom: 48px;
}

.join-logo svg {
    margin-bottom: 20px;
    filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.3));
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

.join-logo h1 {
    font-size: 42px;
    font-weight: 800;
    color: white;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    letter-spacing: -1px;
    margin: 0;
}

/* Meeting Info Card */
.meeting-info {
    margin-bottom: 32px;
    animation: slideDown 0.5s ease;
}

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

.meeting-info.hidden {
    display: none;
}

.info-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.info-icon {
    font-size: 36px;
    flex-shrink: 0;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.info-text {
    flex: 1;
}

.info-label {
    font-size: 14px;
    color: #64748b;
    font-weight: 600;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-value {
    font-size: 24px;
    color: #1e293b;
    font-weight: 800;
    letter-spacing: 2px;
    font-family: 'Courier New', monospace;
}

/* Main Form Card */
.join-form-card {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    margin-bottom: 24px;
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.form-group {
    margin-bottom: 24px;
}

.form-group:last-of-type {
    margin-bottom: 32px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #334155;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input {
    width: 100%;
    padding: 16px 18px;
    font-size: 16px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    background: #f8fafc;
    color: #1e293b;
    transition: all 0.3s ease;
    font-weight: 500;
}

.form-group input:focus {
    outline: none;
    border-color: #3b82f6;
    background: white;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
    transform: translateY(-1px);
}

.form-group input::placeholder {
    color: #94a3b8;
    font-weight: 400;
}

.btn-primary {
    width: 100%;
    padding: 18px;
    background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

#join-btn-icon {
    font-size: 24px;
    animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

.btn-primary:disabled #join-btn-icon {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Join Hint */
.join-hint {
    margin-top: 20px;
    padding: 12px 16px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.hint-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.hint-text {
    font-size: 13px;
    color: #475569;
    line-height: 1.5;
}

/* Security Badge */
.security-badge {
    text-align: center;
    color: rgba(255, 255, 255, 0.95);
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

.security-badge .badge-icon {
    font-size: 18px;
    animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ===============================================
   VIDEO SCREEN (HIDDEN BY DEFAULT)
   =============================================== */

#video-screen {
    background: #1a1a1a;
}

/* Top Bar */
.top-bar {
    background: #2D8CFF;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
    z-index: 100;
    flex-wrap: wrap;
}

.meeting-info-top {
    display: flex;
    align-items: center;
    gap: 20px;
}

.meeting-id-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.2);
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
}

.meeting-timer {
    background: rgba(255, 255, 255, 0.2);
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

.meeting-link-section {
    flex: 1;
    display: flex;
    gap: 12px;
    min-width: 300px;
}

#meeting-link {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 14px;
    font-weight: 500;
}

#meeting-link::selection {
    background: rgba(255, 255, 255, 0.3);
}

.btn-copy-link {
    padding: 10px 20px;
    background: white;
    color: #2D8CFF;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-copy-link:hover {
    background: #f0f0f0;
    transform: translateY(-1px);
}

.btn-copy-link.copied {
    background: #34A853;
    color: white;
}

/* Owner Controls */
.owner-controls {
    display: flex;
    gap: 8px;
}

.owner-controls.hidden {
    display: none !important;
}

.btn-owner-control {
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
}

.btn-owner-control:hover {
    background: rgba(255, 255, 255, 0.3);
}

.btn-owner-control.danger {
    background: rgba(234, 67, 53, 0.9);
}

.btn-owner-control.danger:hover {
    background: #EA4335;
}

.btn-owner-control.locked {
    background: rgba(255, 193, 7, 0.9);
}

/* Video Container */
#video-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#videos-grid {
    width: 100%;
    height: 100%;
    display: grid;
    gap: 8px;
    padding: 8px;
    grid-auto-rows: 1fr;
}

#videos-grid[data-count="1"] { grid-template-columns: 1fr; }
#videos-grid[data-count="2"] { grid-template-columns: repeat(2, 1fr); }
#videos-grid[data-count="3"],
#videos-grid[data-count="4"] { grid-template-columns: repeat(2, 1fr); }
#videos-grid[data-count="5"],
#videos-grid[data-count="6"] { grid-template-columns: repeat(3, 1fr); }
#videos-grid[data-count="7"],
#videos-grid[data-count="8"],
#videos-grid[data-count="9"] { grid-template-columns: repeat(3, 1fr); }

.video-tile {
    position: relative;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    min-height: 200px;
}

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

.video-tile-overlay {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: rgba(0, 0, 0, 0.7);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.video-tile-overlay.muted::before {
    content: '🔇';
    font-size: 14px;
}

/* Meeting Ended Overlay */
.meeting-ended-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.meeting-ended-overlay:not(.hidden) {
    display: flex;
}

.ended-content {
    text-align: center;
    padding: 40px;
    max-width: 500px;
}

.ended-icon {
    font-size: 80px;
    margin-bottom: 20px;
}

.ended-content h2 {
    font-size: 32px;
    margin-bottom: 12px;
    color: white;
}

.ended-content p {
    font-size: 18px;
    color: #94a3b8;
    margin-bottom: 32px;
}

.btn-return {
    padding: 16px 32px;
    background: #2D8CFF;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-return:hover {
    background: #1a73e8;
    transform: translateY(-2px);
}

/* Chat Sidebar */
.chat-sidebar {
    position: fixed;
    right: -400px;
    top: 0;
    width: 360px;
    height: 100vh;
    background: #262626;
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
    z-index: 200;
}

.chat-sidebar.open {
    right: 0;
}

.chat-header {
    padding: 20px;
    border-bottom: 1px solid #3a3a3a;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.btn-close-chat {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #ffffff;
    font-size: 28px;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
}

.btn-close-chat:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-message {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.chat-sender {
    font-weight: 600;
    color: #2D8CFF;
}

.chat-time {
    color: #999;
    font-size: 12px;
}

.chat-text {
    background: #3a3a3a;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.chat-message.own .chat-sender {
    color: #34A853;
}

.chat-input-container {
    padding: 16px;
    border-top: 1px solid #3a3a3a;
    display: flex;
    gap: 8px;
}

#chat-input {
    flex: 1;
    padding: 12px;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    background: #1a1a1a;
    color: white;
    font-size: 14px;
}

#chat-input:focus {
    outline: none;
    border-color: #2D8CFF;
}

.btn-send {
    padding: 12px 20px;
    background: #2D8CFF;
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-send:hover {
    background: #1a73e8;
}

/* Control Bar */
.control-bar {
    background: #1f1f1f;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #2d2d2d;
}

.control-group {
    display: flex;
    gap: 8px;
}

.control-group.center {
    flex: 1;
    justify-content: center;
}

.control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

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

.control-btn .icon {
    font-size: 24px;
}

.control-btn .label {
    font-size: 12px;
    font-weight: 500;
}

.control-btn.active {
    background: rgba(234, 67, 53, 0.2);
    color: #EA4335;
}

.control-btn.danger {
    color: #EA4335;
}

.control-btn.danger:hover {
    background: rgba(234, 67, 53, 0.2);
}

.badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #EA4335;
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

.badge.hidden {
    display: none !important;
}

.hidden {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    .join-content {
        max-width: 100%;
        padding: 0 16px;
    }

    .join-form-card {
        padding: 32px 24px;
        border-radius: 16px;
    }

    .join-logo h1 {
        font-size: 32px;
    }

    .join-logo svg {
        width: 50px;
        height: 50px;
    }

    .info-card {
        padding: 20px;
        gap: 16px;
    }

    .info-icon {
        font-size: 28px;
    }

    .info-value {
        font-size: 20px;
    }

    .form-group input {
        padding: 14px 16px;
        font-size: 15px;
    }

    .btn-primary {
        padding: 16px;
        font-size: 16px;
    }

    #join-btn-icon {
        font-size: 20px;
    }

    .security-badge {
        font-size: 13px;
        padding: 10px;
    }

    .top-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 12px 16px;
    }

    .meeting-link-section {
        min-width: auto;
        width: 100%;
    }

    .owner-controls {
        justify-content: center;
    }

    .chat-sidebar {
        width: 100%;
        right: -100%;
    }

    .control-bar {
        padding: 12px 8px;
    }

    .control-btn {
        padding: 8px 12px;
    }

    .control-btn .label {
        display: none;
    }
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #3a3a3a;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #4a4a4a;
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message {
    animation: slideIn 0.2s ease;
}
