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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: #333;
    overflow: hidden;
}

/* Status bar */
.status-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #e53e3e;
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 3000;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}

.status-bar.warning {
    background: #f59e0b;
}

.status-bar.info {
    background: #3b82f6;
}

.status-bar.success {
    background: #10b981;
}

.status-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 0.5rem;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.status-close:hover {
    opacity: 1;
}

/* Adjust app when status bar is visible */
body.has-status-bar #app {
    padding-top: 60px;
}

#app {
    height: 100vh;
    position: relative;
}

.screen {
    display: none !important;
    height: 100vh;
}

.screen.active {
    display: block !important;
}

#call-screen.active {
    display: flex !important;
}

/* Lobby Styles */
#lobby {
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

#lobby.active {
    display: flex !important;
}

.container {
    background: white;
    padding: 3rem;
    border-radius: 1rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    text-align: center;
    max-width: 400px;
    width: 100%;
}

.container h1 {
    margin-bottom: 2rem;
    color: #333;
}

#join-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#join-form input {
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: 0.5rem;
    font-size: 1rem;
}

#join-form button {
    padding: 0.75rem;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.3s;
}

#join-form button:hover {
    background: #5a67d8;
}

/* Call Screen Styles */
#call-screen {
    display: flex;
    flex-direction: column;
    background: #1a1a1a;
    height: 100vh;
}

.video-grid {
    flex: 1;
    display: grid;
    gap: 0.5rem;
    padding: 1rem;
    overflow-y: auto;
    min-height: 400px;
}

/* Dynamic grid layouts based on video count */
.video-grid[data-count="1"] {
    grid-template-columns: 1fr;
}

.video-grid[data-count="2"] {
    grid-template-columns: repeat(2, 1fr);
}

.video-grid[data-count="3"],
.video-grid[data-count="4"] {
    grid-template-columns: repeat(2, 1fr);
}

.video-grid[data-count="5"],
.video-grid[data-count="6"] {
    grid-template-columns: repeat(3, 1fr);
}

.video-grid[data-count="7"],
.video-grid[data-count="8"],
.video-grid[data-count="9"] {
    grid-template-columns: repeat(3, 1fr);
}

.video-grid[data-count="10"],
.video-grid[data-count="11"],
.video-grid[data-count="12"] {
    grid-template-columns: repeat(4, 1fr);
}

/* For more than 12, use auto-fit */
.video-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

/* Featured video (main speaker) */
.video-container.featured {
    grid-column: span 2;
    grid-row: span 2;
}

/* Adjust featured sizing for smaller grids */
.video-grid[data-count="2"] .video-container.featured,
.video-grid[data-count="3"] .video-container.featured,
.video-grid[data-count="4"] .video-container.featured {
    grid-column: span 1;
    grid-row: span 1;
}

.video-container {
    position: relative;
    background: #000;
    border-radius: 0.5rem;
    overflow: hidden;
    aspect-ratio: 16/9;
}

/* Adjust video container size based on count */
.video-grid[data-count="1"] .video-container {
    max-width: 800px;
    margin: 0 auto;
}

.video-grid[data-count="2"] .video-container,
.video-grid[data-count="3"] .video-container,
.video-grid[data-count="4"] .video-container {
    min-height: 250px;
}

.video-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}


.video-label {
    position: absolute;
    bottom: 0.5rem;
    left: 0.5rem;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    backdrop-filter: blur(4px);
    max-width: 80%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Smaller labels for crowded grids */
.video-grid[data-count="5"] .video-label,
.video-grid[data-count="6"] .video-label,
.video-grid[data-count="7"] .video-label,
.video-grid[data-count="8"] .video-label,
.video-grid[data-count="9"] .video-label {
    font-size: 0.7rem;
    padding: 0.2rem 0.4rem;
}

/* Even smaller for very crowded grids */
.video-grid[data-count="10"] .video-label,
.video-grid[data-count="11"] .video-label,
.video-grid[data-count="12"] .video-label {
    font-size: 0.65rem;
    padding: 0.15rem 0.3rem;
}

/* Additional camera indicator */
.video-container[id*="camera-"] .video-label {
    background: rgba(102, 126, 234, 0.8);
}

.video-container[id*="camera-"] {
    border: 2px solid #667eea;
}

/* Remove camera button */
.remove-camera-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(229, 62, 62, 0.8);
    color: white;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.video-container:hover .remove-camera-btn {
    opacity: 1;
}

.remove-camera-btn:hover {
    background: rgba(197, 48, 48, 0.9);
    transform: scale(1.1);
}

/* Ensure remove button is visible on touch devices */
@media (hover: none) {
    .remove-camera-btn {
        opacity: 1;
    }
}

/* Hover effects */
.video-container:hover .video-label {
    background: rgba(0,0,0,0.9);
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    .video-grid[data-count="10"],
    .video-grid[data-count="11"],
    .video-grid[data-count="12"] {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 900px) {
    .video-grid[data-count="7"],
    .video-grid[data-count="8"],
    .video-grid[data-count="9"] {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .video-grid[data-count="5"],
    .video-grid[data-count="6"] {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .video-grid {
        gap: 0.25rem;
        padding: 0.5rem;
    }
}

/* Controls */
.controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    background: rgba(0,0,0,0.8);
    position: relative;
}

.control-btn {
    padding: 0.75rem 1.5rem;
    background: #333;
    color: white;
    border: none;
    border-radius: 2rem;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.3s;
}

.control-btn:hover {
    background: #555;
}

.control-btn.end-call {
    background: #e53e3e;
}

.control-btn.end-call:hover {
    background: #c53030;
}

/* End call confirmation */
.end-call-confirm {
    position: absolute;
    bottom: 100%;
    right: 0;
    background: white;
    border-radius: 0.5rem;
    padding: 1rem;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.2);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: slideUp 0.2s ease-out;
    z-index: 1000;
}

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

.end-call-confirm span {
    color: #333;
    font-weight: 500;
    margin-right: 0.5rem;
}

.confirm-btn, .cancel-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.confirm-btn {
    background: #e53e3e;
    color: white;
}

.confirm-btn:hover {
    background: #c53030;
}

.cancel-btn {
    background: #e0e0e0;
    color: #333;
}

.cancel-btn:hover {
    background: #ccc;
}

/* Chat */
.chat-container {
    position: fixed;
    right: 1rem;
    bottom: 5rem;
    width: 300px;
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    transition: all 0.3s ease-out;
    z-index: 100;
}

.chat-container.hidden {
    transform: translateX(320px);
    opacity: 0;
}

/* View modes */
.video-grid.compact-view .video-container[id*="camera-"] {
    display: none;
}

.video-grid.focus-view .video-container:not(.focused) {
    width: 150px;
    height: 100px;
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 10;
}

.video-grid.focus-view .video-container.focused {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
}

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

.chat-header h3 {
    font-size: 1rem;
}

.toggle-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
}

.chat-body {
    height: 300px;
    display: flex;
    flex-direction: column;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.message {
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background: #f0f2f5;
    border-radius: 0.25rem;
}

.message .sender {
    font-weight: bold;
    color: #667eea;
}

#chat-form {
    display: flex;
    padding: 1rem;
    border-top: 1px solid #e0e0e0;
}

#chat-input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #e0e0e0;
    border-radius: 0.25rem;
    margin-right: 0.5rem;
}

#chat-form button {
    padding: 0.5rem 1rem;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
}

.message-time {
    font-size: 0.75rem;
    color: #999;
    margin-left: 0.5rem;
}

.system-message {
    font-style: italic;
    color: #666;
    text-align: center;
    margin: 0.5rem 0;
}

/* Loading state */
button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Tooltips */
button[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    white-space: nowrap;
    pointer-events: none;
}

/* Device selection dialog */
.device-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.device-dialog {
    background: white;
    border-radius: 0.5rem;
    padding: 1.5rem;
    min-width: 300px;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.device-dialog h3 {
    margin-bottom: 1rem;
    color: #333;
}

.device-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.device-item {
    padding: 0.75rem;
    background: #f0f2f5;
    border: 2px solid transparent;
    border-radius: 0.5rem;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
    width: 100%;
    font-size: 1rem;
    font-family: inherit;
}

.device-item:hover {
    background: #e0e2e5;
    border-color: #667eea;
}

.device-item:active {
    background: #d0d2d5;
    transform: scale(0.98);
}