/* ========================================
   Voice Chat — Styles
   ======================================== */

/* === Reset & Base === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-dark: #0b0b14;
    --bg-card: #12121f;
    --bg-card-hover: #1a1a2e;
    --bg-input: #0f0f1a;
    --border: #2a2a3e;
    --primary: #7c5cfc;
    --primary-hover: #6a4ce0;
    --primary-glow: rgba(124, 92, 252, 0.3);
    --danger: #ff4757;
    --danger-hover: #e0303f;
    --success: #2ed573;
    --text: #e8e8f0;
    --text-muted: #6b6b80;
    --text-dim: #44445a;
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font);
}

.resume-audio-btn {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}

#resumeAudioBtn[hidden] {
    display: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 0 20px var(--primary-glow);
}

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-full {
    width: 100%;
    justify-content: center;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* === Inputs === */
.input-group {
    margin-bottom: 20px;
}
.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.input-group input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 16px;
    font-family: var(--font);
    transition: border-color 0.2s;
}
.input-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.input-group small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-dim);
}

/* === Error Message === */
.error-message {
    margin-top: 12px;
    padding: 10px 14px;
    background: rgba(255, 71, 87, 0.1);
    border: 1px solid rgba(255, 71, 87, 0.3);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 14px;
    text-align: center;
}

/* ========================================
   Login Page
   ======================================== */
.page-login {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 420px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
}

.logo {
    text-align: center;
    margin-bottom: 32px;
}
.logo-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary), #a78bfa);
    border-radius: 50%;
    margin-bottom: 16px;
    color: white;
}
.logo h1 {
    font-size: 24px;
    font-weight: 700;
}
.logo .subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

/* === Auth Flow Styles === */
.auth-user-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}
.auth-user-icon {
    font-size: 24px;
    line-height: 1;
}
.auth-username-display {
    font-weight: 600;
    font-size: 16px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 13px;
    cursor: pointer;
    padding: 2px 6px;
    font-weight: 500;
}
.btn-link:hover {
    text-decoration: underline;
}
.auth-info-text {
    color: var(--success);
    font-size: 13px;
    margin-bottom: 16px;
    text-align: center;
}

/* Guest Join Section */
.guest-join-section {
    margin-bottom: 8px;
}
.guest-info-text {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 14px;
    text-align: center;
    line-height: 1.5;
}
.guest-info-text strong {
    color: var(--primary);
}
.divider-text {
    display: flex;
    align-items: center;
    margin: 16px 0;
    gap: 12px;
}
.divider-text::before,
.divider-text::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}
.divider-text span {
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.terms-box {
    margin: 16px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.terms-scroll {
    max-height: 180px;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg-input);
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.6;
}
.terms-scroll h3 {
    color: var(--text);
    font-size: 14px;
    margin-bottom: 8px;
}
.terms-scroll ol {
    padding-left: 20px;
    margin: 8px 0;
}
.terms-scroll li {
    margin-bottom: 6px;
}
.terms-scroll strong {
    color: var(--text);
}
.terms-agree-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-card-hover);
    border-top: 1px solid var(--border);
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}
.terms-agree-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

/* ========================================
   Top Bar
   ======================================== */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-left, .topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}
.topbar-left svg {
    color: var(--primary);
}
.topbar-title {
    font-size: 16px;
    font-weight: 700;
}
.user-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-muted);
}
.user-badge::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
}

/* ========================================
   Lobby Page
   ======================================== */
.lobby-main {
    max-width: 800px;
    margin: 0 auto;
    padding: 24px;
}

.lobby-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}
.lobby-header h2 {
    font-size: 20px;
}

/* Room List */
.room-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.room-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.2s;
}
.room-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--primary);
}

.room-info {
    flex: 1;
}
.room-name {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}
.room-meta {
    font-size: 13px;
    color: var(--text-muted);
    display: flex;
    gap: 16px;
}
.room-meta span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.room-users-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: 16px;
}
.user-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success);
    border: 2px solid var(--bg-card);
}
.user-dot.empty {
    background: var(--border);
}

.room-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.room-empty svg {
    margin-bottom: 16px;
    opacity: 0.3;
}

.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

/* === Lobby Tabs === */
.lobby-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    background: var(--bg-input);
    padding: 4px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.lobby-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}
.lobby-tab:hover {
    color: var(--text);
    background: var(--bg-card-hover);
}
.lobby-tab.active {
    color: var(--text);
    background: var(--primary);
}
.lobby-tab-content {
    display: none;
}
.lobby-tab-content.active {
    display: block;
}
.online-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--success);
    color: #000;
    font-size: 11px;
    font-weight: 700;
}

/* === Online Users List === */
.online-users-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.online-user-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.2s;
}
.online-user-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--primary);
}
.online-user-avatar {
    position: relative;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-input);
    border-radius: 50%;
    color: var(--text-muted);
    flex-shrink: 0;
}
.online-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success);
    border: 2px solid var(--bg-card);
}
.online-user-info {
    flex: 1;
    min-width: 0;
}
.online-user-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.online-user-status {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}
.online-user-status.available {
    color: var(--success);
}
.online-user-status.in-room {
    color: var(--primary);
}
.call-user-btn {
    flex-shrink: 0;
}

/* === Call Modal Styles === */
.call-modal {
    text-align: center;
    max-width: 340px;
}
.call-ring-animation {
    position: relative;
    width: 100px;
    height: 100px;
    margin: 0 auto 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.call-ring-circle {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--success);
    opacity: 0;
    animation: callRing 2s ease-out infinite;
}
.call-ring-circle.delay1 {
    animation-delay: 0.5s;
}
.call-ring-circle.delay2 {
    animation-delay: 1s;
}
.call-ring-animation.outgoing .call-ring-circle {
    border-color: var(--primary);
}
@keyframes callRing {
    0% { transform: scale(0.5); opacity: 0.8; }
    100% { transform: scale(1.5); opacity: 0; }
}
.call-avatar {
    position: relative;
    z-index: 1;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-input);
    border-radius: 50%;
    border: 2px solid var(--border);
    color: var(--text-muted);
}
.call-title {
    margin-bottom: 8px;
    font-size: 20px;
}
.call-from {
    color: var(--text-muted);
    margin-bottom: 8px;
    font-size: 15px;
}
.call-room-info {
    color: var(--primary);
    font-size: 13px;
    margin-bottom: 8px;
}
.call-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 24px;
}
.call-action-btn {
    min-width: 120px;
    padding: 12px 20px !important;
    font-size: 15px !important;
    border-radius: 24px !important;
}
.btn-success {
    background: var(--success);
    color: #000;
    font-weight: 600;
}
.btn-success:hover {
    background: #26c062;
}
.btn-danger {
    background: var(--danger);
    color: white;
    font-weight: 600;
}
.btn-danger:hover {
    background: var(--danger-hover);
}

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 400px;
}
.modal h3 {
    margin-bottom: 24px;
    font-size: 18px;
}
.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 8px;
}

/* ========================================
   Room Page
   ======================================== */
.room-main {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 53px);
}

.room-body {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.room-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow-y: auto;
}

/* User Grid */
.user-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    justify-content: center;
    align-items: center;
    max-width: 600px;
}

.user-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px 32px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    min-width: 140px;
    transition: all 0.3s;
    position: relative;
}

.user-tile.speaking {
    border-color: var(--success);
    box-shadow: 0 0 20px rgba(46, 213, 115, 0.2);
}

.user-tile.speaking .user-avatar {
    animation: speakPulse 1.2s ease-in-out infinite;
    box-shadow: 0 0 0 0 rgba(46, 213, 115, 0.5);
}

@keyframes speakPulse {
    0% { box-shadow: 0 0 0 0 rgba(46, 213, 115, 0.5); }
    50% { box-shadow: 0 0 0 10px rgba(46, 213, 115, 0); }
    100% { box-shadow: 0 0 0 0 rgba(46, 213, 115, 0); }
}

/* Visualizer ring — canvas sits behind the avatar */
.avatar-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.visualizer-ring {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    /* Slightly bigger than avatar */
    width: 80px;
    height: 80px;
    border: 3px solid transparent;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.user-tile.speaking .visualizer-ring {
    border-color: var(--success);
    box-shadow: 0 0 16px rgba(46, 213, 115, 0.4), inset 0 0 12px rgba(46, 213, 115, 0.15);
    animation: ringGlow 1.2s ease-in-out infinite;
}

@keyframes ringGlow {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.08); opacity: 1; }
}

.user-tile.is-me {
    border-color: var(--primary);
}

.user-tile.muted .user-avatar {
    opacity: 0.5;
}

.user-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
    color: white;
    transition: opacity 0.2s;
}

.user-tile-name {
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-tile-status {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.user-tile .muted-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    color: var(--danger);
}

/* Connection quality indicator (4 bars like WiFi/Discord) */
.quality-indicator {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 16px;
    cursor: help;
    z-index: 2;
}

.quality-indicator .quality-bar {
    width: 3px;
    border-radius: 1px;
    background: var(--text-dim);
    transition: background 0.3s, height 0.3s;
}

.quality-indicator .quality-bar:nth-child(1) { height: 4px; }
.quality-indicator .quality-bar:nth-child(2) { height: 7px; }
.quality-indicator .quality-bar:nth-child(3) { height: 10px; }
.quality-indicator .quality-bar:nth-child(4) { height: 14px; }

/* Quality levels */
.quality-excellent .quality-bar.active { background: #2ed573; }
.quality-good .quality-bar.active { background: #7bed9f; }
.quality-fair .quality-bar.active { background: #feca57; }
.quality-poor .quality-bar.active { background: #ff4757; }

/* Quality tooltip */
.quality-tooltip {
    display: none;
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    background: rgba(15, 15, 26, 0.95);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.user-tile:hover .quality-tooltip {
    display: block;
}

.qtip-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    line-height: 1.6;
}

.qtip-row span {
    color: var(--text-muted);
}

.qtip-row strong {
    color: var(--text);
    font-weight: 600;
}

/* Reconnecting state */
.user-tile.reconnecting .user-avatar {
    opacity: 0.5;
    animation: reconnectPulse 2s ease-in-out infinite;
}

.user-tile.reconnecting .user-tile-status {
    color: var(--danger);
}

@keyframes reconnectPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ============================
   Video Tiles
   ============================ */

/* Video element — hidden by default, shown when .has-video */
.user-video {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: calc(var(--radius) - 2px);
    z-index: 1;
    background: #000;
}

.user-tile.has-video {
    min-height: 200px;
    min-width: 240px;
    padding: 0;
    overflow: hidden;
}

.user-tile.has-video .user-video {
    display: block;
}

/* Hide avatar/status when video is active */
.user-tile.has-video .avatar-wrapper,
.user-tile.has-video .user-tile-name,
.user-tile.has-video .user-tile-status,
.user-tile.has-video .volume-control,
.user-tile.has-video .dm-click-hint {
    display: none;
}

/* Name overlay on video */
.video-name-overlay {
    display: none;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    z-index: 3;
    border-radius: 0 0 calc(var(--radius) - 2px) calc(var(--radius) - 2px);
}

.user-tile.has-video .video-name-overlay {
    display: block;
}

/* Keep quality indicator and muted badge above video */
.user-tile.has-video .quality-indicator,
.user-tile.has-video .quality-tooltip,
.user-tile.has-video .muted-badge {
    z-index: 4;
}

/* Video speaking border */
.user-tile.has-video.speaking {
    border-color: var(--success);
    box-shadow: 0 0 20px rgba(46, 213, 115, 0.3);
}

/* Widen grid when anyone has video */
.user-grid:has(.has-video) {
    max-width: 900px;
    gap: 16px;
}

/* Avatar color generation */
.avatar-color-0 { background: #7c5cfc; }
.avatar-color-1 { background: #ff6b6b; }
.avatar-color-2 { background: #feca57; color: #333 !important; }
.avatar-color-3 { background: #48dbfb; color: #333 !important; }
.avatar-color-4 { background: #ff9ff3; color: #333 !important; }
.avatar-color-5 { background: #2ed573; color: #333 !important; }

/* Volume control on user tiles */
.volume-control {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 0 4px;
    margin-top: 2px;
}

.vol-icon {
    flex-shrink: 0;
    color: var(--text-muted);
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    outline: none;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    cursor: pointer;
}

.volume-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    cursor: pointer;
}

/* Room Controls */
.room-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font);
    font-size: 11px;
    font-weight: 600;
    min-width: 60px;
}
.control-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--text-muted);
}
.control-btn.active {
    background: rgba(255, 71, 87, 0.1);
    border-color: var(--danger);
    color: var(--danger);
}

.control-btn-danger {
    border-color: rgba(255, 71, 87, 0.3);
    color: var(--danger);
}
.control-btn-danger:hover {
    background: rgba(255, 71, 87, 0.1);
    border-color: var(--danger);
}

/* Connection Status */
.connection-status {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-muted);
    z-index: 200;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   Toast Notifications
   ======================================== */
.toast-container {
    position: fixed;
    top: 70px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 300;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    animation: toastIn 0.3s ease-out;
    pointer-events: auto;
    max-width: 300px;
}

.toast.toast-out {
    animation: toastOut 0.3s ease-in forwards;
}

.toast-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.toast.toast-join { border-left: 3px solid var(--success); }
.toast.toast-leave { border-left: 3px solid var(--danger); }
.toast.toast-info { border-left: 3px solid var(--primary); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}

/* ========================================
   Chat Sidebar
   ======================================== */
.chat-sidebar {
    width: 320px;
    display: none;
    flex-direction: column;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    height: 100%;
}

.chat-sidebar.open {
    display: flex;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    font-weight: 700;
}

.chat-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
}
.chat-close-btn:hover {
    color: var(--text);
    background: var(--bg-input);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-msg-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.chat-msg-name {
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
}

.chat-msg.is-me .chat-msg-name {
    color: var(--success);
}

.chat-msg-time {
    font-size: 10px;
    color: var(--text-dim);
}

.chat-msg-text {
    font-size: 13px;
    color: var(--text);
    word-break: break-word;
    line-height: 1.4;
    padding: 6px 10px;
    background: var(--bg-input);
    border-radius: 6px;
    max-width: 90%;
}

.chat-msg.is-me .chat-msg-text {
    background: rgba(124, 92, 252, 0.15);
    align-self: flex-end;
}

.chat-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-size: 13px;
}

.chat-input {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    font-family: var(--font);
}
.chat-input:focus {
    outline: none;
    border-color: var(--primary);
}

.chat-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
}
.chat-send-btn:hover {
    background: var(--primary-hover);
}

/* Chat badge on control button */
.chat-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--danger);
    border-radius: 9px;
    font-size: 10px;
    font-weight: 700;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

#chatBtn {
    position: relative;
}

/* ========================================
   Push-to-Talk
   ======================================== */
.ptt-indicator {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 14px;
    background: rgba(124, 92, 252, 0.15);
    border: 1px solid var(--primary);
    border-radius: 20px;
    font-size: 12px;
    color: var(--primary);
    white-space: nowrap;
    animation: pttPulse 2s ease-in-out infinite;
}

.ptt-indicator kbd {
    display: inline-block;
    padding: 1px 6px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font);
    font-size: 11px;
    font-weight: 700;
}

@keyframes pttPulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.room-controls {
    position: relative;
}

#pttBtn.active {
    background: rgba(124, 92, 252, 0.15);
    border-color: var(--primary);
    color: var(--primary);
}

/* ========================================
   Invite Button
   ======================================== */
#inviteBtn.copied {
    border-color: var(--success);
    color: var(--success);
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 600px) {
    .login-card {
        padding: 24px;
    }
    .lobby-main {
        padding: 16px;
    }
    .lobby-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
    .room-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    .room-users-indicator {
        margin-right: 0;
    }

    /* Topbar compact */
    .topbar {
        padding: 8px 12px;
    }
    .topbar-title {
        font-size: 14px;
    }

    /* Room layout: grid tight, controls always visible */
    .room-main {
        height: calc(100vh - 45px);
        height: calc(100dvh - 45px); /* dynamic viewport for mobile */
    }
    .room-center {
        padding: 12px 8px;
        align-items: flex-start;
    }
    .user-grid {
        gap: 10px;
        max-width: 100%;
        width: 100%;
    }
    .user-tile {
        padding: 10px 12px;
        min-width: 0;
        flex: 1 1 calc(50% - 10px);
        max-width: calc(50% - 5px);
        gap: 6px;
    }
    .user-tile.has-video {
        min-height: 140px;
        min-width: 0;
    }
    .user-avatar {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    .user-tile-name {
        font-size: 12px;
        max-width: 90px;
    }
    .user-tile-status {
        font-size: 10px;
    }
    .visualizer-ring {
        width: 54px;
        height: 54px;
    }
    .volume-control {
        gap: 4px;
    }
    .volume-slider {
        height: 3px;
    }
    .volume-slider::-webkit-slider-thumb {
        width: 16px;
        height: 16px;
    }
    .volume-slider::-moz-range-thumb {
        width: 16px;
        height: 16px;
    }

    /* Controls bar: compact, wrapped into 2 rows */
    .room-controls {
        gap: 8px;
        padding: 8px 10px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
        flex-wrap: wrap;
        justify-content: center;
    }
    .control-btn {
        padding: 8px 10px;
        min-width: 56px;
        font-size: 10px;
        border-radius: var(--radius-sm);
        gap: 2px;
    }
    .control-btn svg {
        width: 20px;
        height: 20px;
    }

    /* Chat sidebar fullscreen on mobile */
    .chat-sidebar {
        position: fixed;
        top: 45px;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        z-index: 150;
        box-shadow: none;
    }

    .ptt-indicator {
        display: none !important;
    }

    /* Toast smaller on mobile */
    .toast-container {
        top: 50px;
        right: 8px;
        left: 8px;
    }
    .toast {
        max-width: 100%;
        font-size: 12px;
        padding: 8px 12px;
    }

    .muted-badge {
        top: 4px;
        right: 4px;
    }
    .muted-badge svg {
        width: 12px;
        height: 12px;
    }
}

/* ========================================
   Chat Tabs (Group / DMs)
   ======================================== */
.chat-tabs {
    display: flex;
    gap: 2px;
    flex: 1;
}
.chat-tab {
    position: relative;
    padding: 6px 14px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}
.chat-tab:hover {
    color: var(--text);
}
.chat-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.dm-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: var(--danger);
    border-radius: 8px;
    font-size: 10px;
    font-weight: 700;
    color: white;
    margin-left: 4px;
    vertical-align: middle;
}

/* ========================================
   DM User List
   ======================================== */
.dm-user-list {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    max-height: 200px;
    overflow-y: auto;
}
.dm-user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: var(--font);
    color: var(--text);
}
.dm-user-item:hover {
    background: var(--bg-input);
}
.dm-user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #a78bfa);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}
.dm-user-name {
    font-size: 13px;
    font-weight: 600;
}
.dm-user-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
}

/* ========================================
   DM Chat Header
   ======================================== */
.dm-chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: rgba(124, 92, 252, 0.05);
}
.dm-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s;
}
.dm-back-btn:hover {
    background: var(--border);
}
.dm-chat-with {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    flex: 1;
}
.dm-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #a78bfa;
    background: rgba(167, 139, 250, 0.12);
    padding: 2px 8px;
    border-radius: 10px;
}

/* ========================================
   DM Message Styling
   ======================================== */
.chat-msg.is-dm .chat-msg-text {
    background: rgba(167, 139, 250, 0.12);
    border-left: 2px solid #a78bfa;
}
.chat-msg.is-dm .chat-msg-name {
    color: #a78bfa;
}
.chat-msg-dm-tag {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    color: #a78bfa;
    margin-left: 6px;
}
.dm-click-hint {
    position: absolute;
    bottom: 6px;
    right: 6px;
    font-size: 9px;
    color: var(--text-dim);
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}
.user-tile:hover .dm-click-hint {
    opacity: 1;
}

/* ========================================
   Chat Input Toolbar (emoji, gif, image)
   ======================================== */
.chat-input-form {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    border-top: 1px solid var(--border);
}
.chat-toolbar {
    display: flex;
    gap: 2px;
    padding: 6px 12px 0 12px;
}
.chat-tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.15s, color 0.15s;
}
.chat-tool-btn:hover,
.chat-tool-btn.active {
    background: var(--bg-input);
    color: var(--primary);
}
.chat-input-row {
    display: flex;
    gap: 8px;
    padding: 6px 12px 12px 12px;
}

/* ========================================
   Emoji Picker
   ======================================== */
.emoji-picker {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    max-height: 220px;
    overflow-y: auto;
    flex-shrink: 0;
}
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    padding: 8px;
}
.emoji-item {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    width: 100%;
    aspect-ratio: 1;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.12s, transform 0.12s;
}
.emoji-item:hover {
    background: var(--bg-input);
    transform: scale(1.2);
}

/* ========================================
   GIF Picker
   ======================================== */
.gif-picker {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    max-height: 300px;
    flex-direction: column;
    flex-shrink: 0;
}
.gif-search {
    padding: 8px 12px;
    background: var(--bg-input);
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    font-family: var(--font);
    outline: none;
}
.gif-search:focus {
    background: var(--bg-body);
}
.gif-results {
    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    padding: 4px;
    align-content: start;
}
.gif-results .chat-empty {
    grid-column: 1 / -1;
    padding: 30px;
}
.gif-item {
    cursor: pointer;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 2px solid transparent;
    transition: border-color 0.15s;
}
.gif-item:hover {
    border-color: var(--primary);
}
.gif-item img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    display: block;
}

/* ========================================
   Chat Images & GIFs in Messages
   ======================================== */
.chat-msg-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.15s;
    display: block;
    margin-top: 4px;
}
.chat-msg-image:hover {
    opacity: 0.85;
}
.chat-msg-gif {
    max-width: 200px;
    max-height: 160px;
    border-radius: 8px;
    display: block;
    margin-top: 4px;
}

/* Image preview before sending */
.image-preview {
    position: relative;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
}
.image-preview img {
    max-height: 120px;
    max-width: 100%;
    border-radius: 6px;
    display: block;
}
.image-preview-cancel {
    position: absolute;
    top: 4px;
    right: 8px;
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(0,0,0,0.6);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
}

/* ========================================
   Image Lightbox
   ======================================== */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.lightbox-img {
    max-width: 95%;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255,255,255,0.15);
    color: white;
    font-size: 24px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.lightbox-close:hover {
    background: rgba(255,255,255,0.3);
}

/* ========================================
   Master Volume Control
   ======================================== */
.control-volume {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
}
.master-vol-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
.master-vol-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
}
.master-vol-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
}

/* ========================================
   Responsive: Mobile chat enhancements
   ======================================== */
@media (max-width: 600px) {
    .emoji-picker {
        max-height: 180px;
    }
    .emoji-grid {
        grid-template-columns: repeat(7, 1fr);
    }
    .emoji-item {
        font-size: 20px;
    }
    .gif-picker {
        max-height: 250px;
    }
    .gif-item img {
        height: 80px;
    }
    .chat-msg-image {
        max-width: 160px;
    }
    .chat-msg-gif {
        max-width: 160px;
    }
    .control-volume {
        order: -1;
        width: 100%;
        justify-content: center;
    }
    .master-vol-slider {
        width: 60%;
        max-width: 200px;
    }
    .chat-toolbar {
        padding: 6px 8px 0 8px;
    }
    .chat-input-row {
        padding: 6px 8px 10px 8px;
    }
    .dm-user-list {
        max-height: 160px;
    }
    /* Call modal mobile */
    .call-modal {
        max-width: 300px;
        padding: 24px;
    }
    .call-actions {
        flex-direction: column;
        gap: 10px;
    }
    .call-action-btn {
        min-width: 0;
        width: 100%;
    }
    .lobby-tabs {
        margin-bottom: 12px;
    }
    .lobby-tab {
        padding: 8px 12px;
        font-size: 13px;
    }
    .online-user-card {
        padding: 10px 12px;
        gap: 10px;
    }
}

/* ========================================
   Held Call Bar
   ======================================== */
.held-call-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, #1a1a2e, #2a1a3e);
    border-bottom: 2px solid var(--primary);
    padding: 10px 20px;
    gap: 12px;
    z-index: 100;
    animation: heldPulse 2s ease-in-out infinite;
}

@keyframes heldPulse {
    0%, 100% { border-bottom-color: var(--primary); }
    50% { border-bottom-color: var(--success); }
}

.held-call-info {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 14px;
    min-width: 0;
}

.held-call-info svg {
    flex-shrink: 0;
    stroke: var(--primary);
}

.held-call-info strong {
    color: var(--primary);
}

.held-call-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.held-btn {
    padding: 6px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.held-btn-return {
    background: var(--success);
    color: #fff;
}
.held-btn-return:hover {
    background: #26b863;
    transform: translateY(-1px);
}

.held-btn-merge {
    background: var(--primary);
    color: #fff;
}
.held-btn-merge:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.held-btn-end {
    background: var(--danger);
    color: #fff;
}
.held-btn-end:hover {
    background: var(--danger-hover);
    transform: translateY(-1px);
}

.held-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ========================================
   Missed Call Toast (Lobby)
   ======================================== */
.missed-call-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--bg-card);
    border: 1px solid var(--danger);
    border-left: 4px solid var(--danger);
    border-radius: var(--radius-sm);
    padding: 14px 20px;
    color: var(--text);
    font-size: 14px;
    z-index: 9999;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    animation: toastSlideIn 0.3s ease-out;
    transition: opacity 0.5s ease;
}

.missed-call-toast.fade-out {
    opacity: 0;
}

@keyframes toastSlideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ========================================
   Held Call Bar — Mobile
   ======================================== */
@media (max-width: 600px) {
    .held-call-bar {
        flex-direction: column;
        padding: 8px 12px;
        gap: 8px;
    }
    .held-call-actions {
        width: 100%;
        justify-content: stretch;
    }
    .held-btn {
        flex: 1;
        padding: 8px 8px;
        font-size: 12px;
        text-align: center;
    }
}
