:root {
    --bg-dark: #07090e;
    --bg-surface: #0f172a;
    --bg-card: #131d33;
    --bg-card-hover: #1e293b;
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-active: rgba(16, 185, 129, 0.4);

    --primary: #10b981;
    --primary-glow: rgba(16, 185, 129, 0.35);
    --cyan: #06b6d4;
    --danger: #ef4444;
    --danger-glow: rgba(239, 68, 68, 0.35);
    --warning: #f59e0b;

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-family);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ========================================================= */
/* Header Bar                                                */
/* ========================================================= */
.call-header {
    height: 52px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 20;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    font-size: 14px;
    letter-spacing: 0.5px;
    color: #fff;
}

.brand-badge i {
    color: var(--primary);
    font-size: 16px;
}

.room-badge {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-subtle);
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    color: var(--cyan);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.header-center {
    display: flex;
    align-items: center;
    gap: 8px;
}

.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.25);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 800;
    color: var(--primary);
}

.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 8px var(--primary);
    animation: livePulse 2s infinite ease-in-out;
}

@keyframes livePulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.4); opacity: 0.4; }
}

.call-timer {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 700;
    font-size: 13px;
    color: var(--text-muted);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-btn-ghost {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn-ghost:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-color: var(--border-subtle);
}

/* ========================================================= */
/* Call Stage & Video Grid                                   */
/* ========================================================= */
.call-stage {
    flex: 1;
    position: relative;
    padding: 12px;
    overflow: hidden;
    display: flex;
}

.grid-container {
    width: 100%;
    height: 100%;
    display: grid;
    gap: 12px;
    transition: all 0.3s ease;
}

/* Dynamic Grid Classes */
.grid-container.grid-1 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

.grid-container.grid-2 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
}

.grid-container.grid-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.grid-container.grid-6 {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

.grid-container.grid-multi {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    grid-auto-rows: 1fr;
}

/* User Card */
.user-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.user-card.is-speaking {
    border-color: var(--primary);
    box-shadow: 0 0 16px var(--primary-glow);
}

.user-video-wrap {
    width: 100%;
    height: 100%;
    position: relative;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

#local-user-card video {
    transform: scaleX(-1); /* Mirror local webcam */
}

/* Avatar Placeholder (when video is off or audio-only) */
.user-avatar-wrap {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 2;
}

.user-card.video-off .user-avatar-wrap {
    display: flex;
}

.user-card.video-off video {
    display: none;
}

.user-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10b981 0%, #06b6d4 100%);
    color: #fff;
    font-size: 24px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    letter-spacing: 1px;
}

.user-card.is-speaking .user-avatar {
    box-shadow: 0 0 0 4px var(--primary-glow), 0 4px 20px var(--primary);
    animation: avatarPulse 1.5s infinite;
}

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

.user-avatar-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-main);
}

/* Card Badges */
.card-overlay-badge {
    position: absolute;
    z-index: 5;
}

.card-overlay-badge.top-right {
    top: 10px;
    right: 10px;
    display: flex;
    gap: 6px;
}

.card-overlay-badge.bottom-left {
    bottom: 10px;
    left: 10px;
}

.peer-name-badge {
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-subtle);
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
}

.media-badge {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid var(--border-subtle);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: var(--primary);
}

.media-badge.muted {
    background: rgba(239, 68, 68, 0.85);
    color: #fff;
    border-color: rgba(239, 68, 68, 0.5);
}

/* ========================================================= */
/* Controls Bar (Dock at Bottom)                             */
/* ========================================================= */
.call-dock-wrap {
    height: 76px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    z-index: 20;
    flex-shrink: 0;
}

.dock-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dock-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-subtle);
    color: var(--text-main);
    border-radius: 12px;
    width: 58px;
    height: 52px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 10px;
    font-weight: 700;
}

.dock-btn i {
    font-size: 17px;
}

.dock-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.dock-btn.off {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.4);
    color: var(--danger);
}

.dock-btn.active {
    background: rgba(6, 182, 212, 0.2);
    border-color: var(--cyan);
    color: var(--cyan);
}

.dock-btn.danger {
    background: var(--danger);
    border-color: transparent;
    color: #fff;
    width: 68px;
    box-shadow: 0 4px 14px var(--danger-glow);
}

.dock-btn.danger:hover {
    background: #dc2626;
    transform: translateY(-2px);
}

.badge-counter {
    position: absolute;
    top: 4px;
    right: 8px;
    background: var(--cyan);
    color: #000;
    font-size: 9px;
    font-weight: 900;
    border-radius: 8px;
    padding: 1px 5px;
    display: none;
}

/* ========================================================= */
/* Collapsible Chat Drawer                                   */
/* ========================================================= */
.chat-drawer {
    width: 320px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 52px;
    bottom: 76px;
    right: -320px;
    transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 15;
}

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

.chat-drawer-header {
    height: 48px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    font-size: 13px;
    font-weight: 800;
}

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

.chat-msg {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.4;
    word-break: break-word;
}

.chat-msg.mine {
    background: rgba(16, 185, 129, 0.18);
    border: 1px solid rgba(16, 185, 129, 0.3);
    align-self: flex-end;
}

.chat-msg.theirs {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    align-self: flex-start;
}

.msg-header {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 2px;
    font-size: 10px;
    color: var(--text-dim);
}

.msg-sender {
    font-weight: 800;
    color: var(--cyan);
}

.chat-input-bar {
    padding: 10px 12px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    gap: 8px;
    background: rgba(0, 0, 0, 0.2);
}

.chat-input-bar input {
    flex: 1;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-subtle);
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
    outline: none;
}

.chat-input-bar input:focus {
    border-color: var(--primary);
}

.chat-input-bar button {
    background: var(--primary);
    border: none;
    color: #000;
    font-weight: 800;
    padding: 0 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
}

/* ========================================================= */
/* Toast Notifications                                       */
/* ========================================================= */
.call-toast {
    position: fixed;
    top: 64px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid var(--border-subtle);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transition: all 0.25s ease;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.call-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.call-toast.error {
    border-color: var(--danger);
    color: #fca5a5;
}

.call-toast.error i {
    color: var(--danger);
}

/* ========================================================= */
/* Responsive Tweaks for Popups (width < 600px)              */
/* ========================================================= */
@media (max-width: 600px) {
    .call-dock-wrap {
        height: 68px;
    }
    .dock-btn {
        width: 48px;
        height: 48px;
        font-size: 9px;
    }
    .dock-btn.danger {
        width: 54px;
    }
    .chat-drawer {
        width: 100%;
        right: -100%;
    }
}
