:root {
    --bg-primary: #191919;
    --bg-secondary: #1e1e1e;
    --bg-tertiary: #242424;
    --bg-hover: #2d2d2d;
    --bg-input: #2a2a2a;
    --text-primary: #ffffff;
    --text-secondary: #a6a6a6;
    --text-tertiary: #5e5e5e;
    --accent: #ff4654;
    --accent-hover: #ff5e6a;
    --accent-glow: rgba(255, 70, 84, 0.15);
    --success: #65e9a0;
    --danger: #ff4654;
    --danger-hover: #e0323f;
    --border: #2d2d2d;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --sidebar-width: 260px;
    --transition: 150ms ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Views ---------- */

.view {
    display: none;
    width: 100%;
    height: 100vh;
}

.view:not(.hidden) {
    display: flex;
}

/* ---------- Auth / Connect Shared ---------- */

.auth-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at 20% 50%, var(--accent-glow), transparent 50%),
        radial-gradient(ellipse at 80% 50%, rgba(88, 101, 242, 0.08), transparent 50%),
        var(--bg-primary);
}

.auth-card {
    width: 100%;
    max-width: 440px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-xl);
    padding: 40px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.logo-icon {
    margin-bottom: 12px;
}

.auth-header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

.auth-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    padding: 4px;
    margin-bottom: 24px;
}

.auth-tab {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition);
}

.auth-tab:hover {
    color: var(--text-primary);
}

.auth-tab.active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.auth-form label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-top: 10px;
}

.auth-form label:first-child {
    margin-top: 0;
}

.auth-form input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    outline: none;
    transition: border-color var(--transition);
}

.auth-form input::placeholder {
    color: var(--text-tertiary);
}

.auth-form input:focus {
    border-color: var(--accent);
}

.auth-error {
    color: var(--danger);
    font-size: 13px;
    min-height: 20px;
    margin-top: 4px;
}

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
    margin-top: 8px;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-text {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    margin-top: 16px;
    padding: 8px;
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: color var(--transition);
}

.btn-text:hover {
    color: var(--text-secondary);
}

/* ---------- App Layout ---------- */

.app-layout {
    display: flex;
    width: 100%;
    height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 2px;
}

.server-address {
    font-size: 12px;
    color: var(--text-tertiary);
    font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
}

.channel-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.channel-list::-webkit-scrollbar {
    width: 4px;
}

.channel-list::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 2px;
}

.channel-section-header {
    padding: 8px 8px 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
}

.channel-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    background: none;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
}

.channel-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.channel-item.active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.channel-item.active .channel-icon {
    color: var(--accent);
}

.channel-icon {
    flex-shrink: 0;
    color: var(--text-tertiary);
    transition: color var(--transition);
}

.channel-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.channel-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.channel-users-list {
    padding: 2px 0 6px 20px;
}

.channel-user-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 10px;
    font-size: 13px;
    color: var(--text-secondary);
    border-left: 2px solid var(--border);
}

.mini-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

/* ---------- User Panel ---------- */

.user-panel {
    display: flex;
    align-items: center;
    padding: 12px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    gap: 8px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ---------- Main Content ---------- */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    min-width: 0;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-tertiary);
    padding: 20px;
    text-align: center;
}

.empty-state h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 14px;
    max-width: 300px;
}

/* ---------- Channel View ---------- */

.channel-view {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.channel-view.hidden {
    display: none;
}

.channel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.channel-header h2 {
    font-size: 16px;
    font-weight: 700;
}

/* ---------- Video Grid ---------- */

.video-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    padding: 20px;
    overflow-y: auto;
    align-content: start;
}

.video-grid::-webkit-scrollbar {
    width: 6px;
}

.video-grid::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 3px;
}

.video-tile {
    position: relative;
    aspect-ratio: 16 / 10;
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 2px solid transparent;
    transition: border-color var(--transition);
}

.video-tile.speaking {
    border-color: var(--success);
    box-shadow: 0 0 12px rgba(101, 233, 160, 0.2);
}

.video-tile.self {
    border-color: var(--border);
}

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

.video-tile video.hidden {
    display: none;
}

.video-tile video.self-video {
    transform: scaleX(-1);
}

.tile-avatar-wrap {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
}

.tile-avatar-wrap.hidden {
    display: none;
}

.tile-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    color: #fff;
}

.tile-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
}

.tile-name {
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.tile-mute {
    display: flex;
    align-items: center;
    background: rgba(255, 70, 84, 0.85);
    border-radius: 50%;
    padding: 3px;
}

/* ---------- Controls Bar ---------- */

.controls-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.control-btn {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-hover);
    border: none;
    border-radius: 50%;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition);
}

.control-btn:hover {
    background: #3a3a3a;
}

.control-btn.active {
    background: var(--danger);
    color: #fff;
}

.control-btn.active:hover {
    background: var(--danger-hover);
}

.control-btn.danger {
    background: var(--danger);
    color: #fff;
}

.control-btn.danger:hover {
    background: var(--danger-hover);
}

/* ---------- Connection Banner ---------- */

.connection-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
}

.connection-banner.hidden {
    display: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
    .sidebar {
        width: 220px;
        min-width: 220px;
    }

    .video-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        padding: 12px;
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        position: absolute;
        z-index: 10;
        height: 100vh;
    }

    .auth-card {
        margin: 16px;
        padding: 24px;
    }
}

/* ---------- Animations ---------- */

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

.video-tile {
    animation: fadeIn 200ms ease;
}
