/* --- CHAT LAYOUT GRID (Overrides default layout) --- */
.chat-layout-grid {
    display: grid;
    grid-template-columns: 80px 350px 1fr;
    /* Rail | List | Chat Main */
    height: 100dvh;
    /* Use dynamic viewport height for mobile browser bars */
    overflow: hidden;
    background: var(--bg-surface);
}

/* Hide context completely for this redesign */
.chat-context-col {
    display: none !important;
}

/* Response for Tablet */
@media (max-width: 1200px) {
    .chat-layout-grid {
        grid-template-columns: 80px 300px 1fr;
    }
}

/* --- RIGHT PANEL (CONTEXT CHAT) --- */
.c-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-subtle);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
}

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

.msg {
    padding: 12px 15px;
    border-radius: 15px;
    font-size: 0.85rem;
    line-height: 1.4;
    max-width: 90%;
}

.m-in {
    background: var(--color-gray-100);
    color: var(--text-main);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.m-out {
    background: var(--color-accent-3, #252A34);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.friends-rail {
    padding: 20px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    gap: 10px;
    overflow-x: auto;
}

.f-dot {
    width: 45px;
    height: 45px;
    border-radius: 15px;
    background: #eee;
    flex-shrink: 0;
    background-size: cover;
    border: 2px solid transparent;
    cursor: pointer;
    transition: 0.2s;
}

.f-dot:hover {
    border-color: var(--color-accent);
    transform: translateY(-3px);
}

.type-rail {
    padding: 20px;
    border-top: 1px solid var(--border-subtle);
}

.t-in {
    width: 100%;
    border: none;
    background: var(--color-gray-50);
    padding: 15px;
    border-radius: 12px;
    font-weight: 600;
    outline: none;
    transition: 0.2s;
}

.t-in:focus {
    background: #fff;
    box-shadow: var(--shadow-sm);
}

/* Response for Mobile */
@media (max-width: 1024px) {
    .chat-layout-grid {
        display: block;
        /* Switch to block to let elements claim space freely */
    }

    .nav-rail {
        display: none !important;
        /* Hide left nav on mobile chat */
    }

    .chat-list-col {
        display: flex !important;
        /* Force visibility */
        width: 100%;
        /* Relative to grid */
        height: 100dvh;
        /* Full viewport height */
        z-index: 1;
        /* Below the main chat */
        position: relative;
    }

    .chat-list-col.mobile-hidden {
        display: none !important;
    }

    .chat-main-col {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100dvh;
        transform: translateX(100%);
        transition: transform 0.35s cubic-bezier(0.25, 1, 0.5, 1);
        /* Smooth slide */
        z-index: 100;
        background: var(--bg-body);
        box-shadow: -5px 0 20px rgba(0, 0, 0, 0.1);
    }

    .chat-main-col.active {
        transform: translateX(0);
    }
}

/* =========================================
   COMPONENT: CHAT UI
   ========================================= */

/* 1. LAYOUT OVERRIDES */
/* The Chat interface needs a specific 4-col grid on desktop */
.chat-layout {
    display: grid;
    width: 100vw;
    height: 100vh;
    grid-template-columns: 100%;
    grid-template-rows: 1fr 70px;
    /* Mobile: Chat | Nav */
    background: var(--bg-body);
    overflow: hidden;
}

@media (min-width: 1024px) {
    .chat-layout {
        /* Rail | List | Chat Area | Context */
        grid-template-columns: 80px 350px 1fr 300px;
        grid-template-rows: 1fr;
    }
}

/* 2. CHAT LIST (Sidebar) */
.chat-list-col {
    background: white;
    border-right: 1px solid var(--border-subtle);
    display: none;
    /* Hidden on mobile by default unless explicitly toggled */
    flex-direction: column;
}

@media (min-width: 1024px) {
    .chat-list-col {
        display: flex;
    }
}

.cl-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.cl-search {
    background: var(--bg-surface-2);
    padding: 10px 15px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
}

.cl-items {
    flex: 1;
    overflow-y: auto;
}

.cl-item {
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    transition: 0.2s;
    border-bottom: 1px solid transparent;
}

.cl-item:hover {
    background: var(--bg-surface-2);
}

.cl-item.active {
    background: var(--bg-surface-active);
    /* Light blue tint */
    border-right: 3px solid var(--color-primary);
}

.cl-av {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    position: relative;
}

.cl-status {
    width: 12px;
    height: 12px;
    background: #00ff00;
    /* Online Green */
    border: 2px solid white;
    border-radius: 50%;
    position: absolute;
    bottom: 0;
    right: 0;
}

/* 3. CHAT AREA (Main) */
.chat-main-col {
    background: var(--bg-surface);
    display: flex;
    /* Flex to stack header, messages, input */
    flex-direction: column;
    position: relative;

    /* CRITICAL FIX: Constrain this grid item so it doesn't grow to infinity */
    min-height: 0;
    height: 100dvh;
}

.cm-header {
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    min-height: 70px;
    /* Force minimum height for touch targets */
}

.cm-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background-image: radial-gradient(#e5e7eb 1px, transparent 1px);
    background-size: 20px 20px;
    /* Subtle dot pattern */

    /* CRITICAL FIX: Allow flex child to shrink properly */
    min-height: 0;
}

/* 4. MESSAGES */
.msg-row {
    display: flex;
    gap: 10px;
    max-width: 70%;
}

.msg-row.me {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.msg-bubble {
    padding: 12px 18px;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.msg-row.them .msg-bubble {
    background: white;
    color: var(--text-main);
    border-top-left-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.msg-row.me .msg-bubble {
    background: var(--color-primary, #6366f1);
    color: white;
    border-top-right-radius: 4px;
    box-shadow: 0 4px 10px rgba(var(--color-primary-rgb, 99, 102, 241), 0.2);
}

/* 5. INPUT AREA */
.cm-input-area {
    padding: 20px;
    background: white;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 15px;
}

.chat-input {
    flex: 1;
    background: var(--bg-surface-2);
    border: none;
    padding: 12px 20px;
    border-radius: 25px;
    outline: none;
    font-size: 0.95rem;
    transition: 0.2s;
}

.chat-input:focus {
    box-shadow: 0 0 0 2px var(--color-primary-light);
    background: white;
}

.send-btn {
    width: 40px;
    height: 40px;
    background: var(--color-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: 0.2s;
}

.send-btn:hover {
    transform: scale(1.1) rotate(-10deg);
    box-shadow: var(--shadow-md);
}

/* 6. CONTEXT (Right Sidebar) */
.chat-context-col {
    background: white;
    border-left: 1px solid var(--border-subtle);
    padding: 30px;
    display: none;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

@media (min-width: 1200px) {
    .chat-context-col {
        display: flex;
    }
}

.ctx-av {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background-size: cover;
    margin-bottom: 15px;
    border: 4px solid white;
    box-shadow: var(--shadow-md);
}

/* 7. MOBILE OVERRIDES */
@media (max-width: 1024px) {
    .chat-context-col {
        display: none;
        /* Hide context on mobile/tablet */
    }

    /* On mobile, we might toggle between list and chat view.
       For now, let's assume specific classes handle visibility 
       or we just show the main chat for this demo. 
    */
}

/* =========================================
   COMPONENT: RIGHT PANEL CHAT (MODERN GLASS)
   ========================================= */

/* Container */
.rp-chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    background: #fdfdfd;
    /* Clean fallback */
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    /* Subtle background accent */
    background-image:
        radial-gradient(at 0% 0%, hsla(253, 16%, 7%, 0) 0, transparent 50%),
        radial-gradient(at 50% 0%, hsla(225, 39%, 30%, 0) 0, transparent 50%),
        radial-gradient(at 100% 0%, hsla(339, 49%, 30%, 0) 0, transparent 50%);
}

/* 1. PREMIUM TABS (Glass Segmented Control) */
.rp-tabs {
    display: flex;
    padding: 15px 20px 10px 20px;
    gap: 8px;
    position: relative;
    z-index: 2;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.rp-tab {
    flex: 1;
    text-align: center;
    padding: 10px 12px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-muted);
    transition: all 0.3s ease;
    border-radius: 10px;
    position: relative;
}

.rp-tab:hover {
    background: rgba(0, 0, 0, 0.03);
    color: var(--text-secondary);
}

.rp-tab.active {
    color: var(--color-primary);
    background: rgba(var(--color-primary-rgb), 0.1);
    font-weight: 700;
}

/* 2. CHAT FEED AREA */
.rp-feed {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    /* More breathing room */
    scroll-behavior: smooth;
    scrollbar-width: thin;
    overscroll-behavior-y: contain;
}

.rp-feed::-webkit-scrollbar {
    width: 5px;
}

.rp-feed::-webkit-scrollbar-track {
    background: transparent;
}

.rp-feed::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

.rp-feed::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.2);
}

/* 3. MESSAGES */
.rp-msg-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    animation: slideUpFade 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateY(15px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.rp-msg-row.me {
    justify-content: flex-end;
}

.rp-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    border: 2px solid white;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.rp-avatar:hover {
    transform: scale(1.1);
}

.rp-bubble {
    padding: 12px 18px;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.5;
    max-width: 85%;
    position: relative;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    word-wrap: break-word;
    letter-spacing: -0.01em;
}

.rp-msg-row.them .rp-bubble {
    background: white;
    color: var(--text-main);
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.03);
}

.rp-msg-row.me .rp-bubble {
    /* Premium Gradient */
    background: linear-gradient(135deg, var(--color-primary) 0%, #a855f7 100%);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 5px 15px rgba(var(--color-primary-rgb), 0.25);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* 4. FLOATING INPUT AREA (Glass Capsule) */
.rp-input-wrapper {
    padding: 20px;
    position: relative;
    /* Glass gradient overlap */
    background: linear-gradient(to top, rgba(255, 255, 255, 1) 40%, rgba(255, 255, 255, 0));
}

.rp-input-bar {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 30px;
    padding: 6px 6px 6px 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.03);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.rp-input-bar:focus-within {
    transform: translateY(-2px);
    box-shadow: 0 15px 35px rgba(var(--color-primary-rgb), 0.15), 0 0 0 1px rgba(var(--color-primary-rgb), 0.2);
}

.rp-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 1rem;
    outline: none;
    color: var(--text-main);
    min-height: 44px;
}

.rp-input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.rp-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary) 0%, #a855f7 100%);
    color: white;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 4px 10px rgba(var(--color-primary-rgb), 0.3);
}

.rp-send-btn:hover {
    transform: scale(1.1) rotate(-10deg);
    box-shadow: 0 8px 20px rgba(var(--color-primary-rgb), 0.4);
}

.rp-send-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    margin-left: -2px;
    /* Visual correction */
}

/* 5. FRIENDS RAIL (Clean & Modern) */
.rp-friends-rail {
    display: flex;
    align-items: center;
    height: 60px;
    padding: 0 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(5px);
}

.rp-avatar-stack {
    display: flex;
    flex-direction: row;
    /* Natural order */
    gap: 8px;
    overflow-x: auto;
    padding: 5px 0;
    scrollbar-width: none;
    /* Hide scrollbar */
}

.rp-avatar-stack::-webkit-scrollbar {
    display: none;
}

.rp-f-dot {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.2s;
    filter: grayscale(20%);
}

.rp-f-dot:hover {
    transform: translateY(-3px) scale(1.05);
    filter: grayscale(0%);
    border-color: var(--color-primary);
}

.rp-f-dot.active {
    border-color: var(--color-primary);
    filter: grayscale(0%);
    box-shadow: 0 0 0 2px rgba(var(--color-primary-rgb), 0.2);
}

/* =========================================
   COMPONENT: PERSONAL CHAT LIST & WINDOWS (REDESIGN 2.0)
   ========================================= */

/* Premium Chat Search */
.chat-search-container {
    padding: 15px 20px 20px 20px;
    /* Aligned with Global Chat padding */
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.8) 0%, rgba(255, 255, 255, 0) 100%);
    z-index: 5;
    flex-shrink: 0;
}

.chat-search-wrapper {
    position: relative;
    max-width: 100%;
}

.chat-search-input {
    width: 100%;
    padding: 12px 20px 12px 45px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: #fff;
    font-size: 14px;
    color: var(--text-primary);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    font-weight: 500;
}

.chat-search-input:focus {
    outline: none;
    background: #fff;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
    /* Stronger shadow on focus */
    transform: translateY(-2px);
}

.chat-search-icon {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 15px;
    pointer-events: none;
    transition: color 0.3s;
}

.chat-search-input:focus+.chat-search-icon {
    color: var(--primary);
}

/* Scrollable List */
#friendsList {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    /* Full width, no padding */
    scrollbar-width: thin;
    overscroll-behavior-y: contain;
    min-height: 0;
}

/* Redesigned List Item */
.chat-list-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    /* Internal padding to match header alignment */
    cursor: pointer;
    border-radius: 0;
    /* Full width flat style */
    margin: 0;
    /* No margin */
    transition: all 0.2s ease;
    background: transparent;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    /* Separator */
}

.chat-list-item:hover {
    background: #f8f9fa;
    /* Light hover background */
    box-shadow: none;
    transform: none;
}

.chat-list-item__avatar-container {
    position: relative;
    margin-right: 15px;
}

.chat-list-item__avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    /* Circular Avatar */
    object-fit: cover;
    background-color: var(--bg-surface-2);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.chat-list-item__status {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: #bdc3c7;
}

.chat-list-item__status--online {
    background: #2ecc71;
    box-shadow: 0 2px 5px rgba(46, 204, 113, 0.3);
}

.chat-list-item__content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
}

.chat-list-item__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-list-item__name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-main);
    letter-spacing: -0.3px;
}

.chat-list-item__time {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
    background: rgba(0, 0, 0, 0.03);
    padding: 2px 6px;
    border-radius: 6px;
}

.chat-list-item__preview {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.9;
}

.chat-list-item__footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-list-item__badge {
    background: var(--color-error);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0 6px;
    height: 18px;
    min-width: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 9px;
    /* Pill/Circle */
    box-shadow: 0 2px 5px rgba(231, 76, 60, 0.4);
    line-height: 1;
}

/* Chat Windows (Floating) Refined */
/* Chat Windows (Floating) - Redesign V2 (Writer/Comfort Style) */
.chat-window {
    width: 420px !important;
    height: 600px !important;
    max-height: 80vh !important;
    border-radius: 24px !important;
    /* Fully rounded, detached */
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.02) !important;
    border: none !important;
    z-index: 10000;
    margin-bottom: 20px;
    /* Detach from bottom */
    margin-right: 20px;
    /* Detach from right if needed, positioned by JS */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    font-family: 'Inter', sans-serif;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: fixed !important;
    bottom: 0 !important;
}

/* Premium Header */
/* Premium Header */
.premium-glass-header {
    height: 70px;
    /* Slightly shorter for elegance */
    padding: 0 20px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(15px);
    display: flex;
    /* Critical Fix */
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    border-radius: 24px 24px 0 0;
    /* Rounded top */
}

.chat-window__header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-window__header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Rounded square or loose circle avatar */
.chat-window__avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 2px solid transparent;
    /* Border color set via inline style */
    transition: transform 0.2s;
}

.chat-window__avatar:hover {
    transform: scale(1.05);
}

.chat-window__name {
    font-weight: 700;
    font-size: 1rem !important;
    color: var(--text-main);
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.chat-window__status-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Header Buttons (Minimalist) */
.chat-window__action-btn,
.chat-window__close-btn {
    background: transparent;
    border: none;
    color: #999;
    /* Default gray */
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.chat-window__action-btn:hover,
.chat-window__close-btn:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-main);
    transform: translateY(-1px);
}

.chat-window__close-btn:hover {
    color: var(--color-error);
    background: rgba(255, 0, 0, 0.05);
}

/* Premium Footer (Writer Mode) */
.premium-glass-footer {
    padding: 15px 20px;
    background: #fff;
    border-top: 1px solid rgba(0, 0, 0, 0.03);
    border-radius: 0 0 24px 24px;
}

.chat-window__input-wrapper {
    background: #f0f2f5;
    /* Light gray pill */
    border-radius: 30px;
    /* Full pill */
    padding: 6px 6px 6px 15px;
    /* Padding for input, less for button */
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    border: 1px solid transparent;
}

.chat-window__input-wrapper:focus-within {
    background: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border-color: var(--chat-accent-color, rgba(0, 0, 0, 0.1));
    transform: translateY(-1px);
}

.chat-window__form {
    flex: 1;
    /* Critical: Push buttons to right */
    display: flex;
}

.chat-window__input {
    font-size: 0.95rem !important;
    padding: 8px 0;
    color: var(--text-main);
    font-weight: 500;
    border: none;
    background: transparent;
    width: 100%;
}

.chat-window__input::placeholder {
    color: #999;
}

/* Dynamic Accent Support */
.chat-window__send-btn {
    background: var(--chat-accent-color, var(--color-primary));
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

.chat-window__send-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}


/* Message Area */
.chat-window__messages {
    background: #fcfcfc;
    /* Very light subtle bg */
    padding: 20px 25px;
    flex: 1;
    /* Critical: Push footer to bottom */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Message Bubbles - Softer */
.chat-window__message-bubble {
    border-radius: 18px;
    padding: 12px 18px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.02);
}

/* Responsive Override */
@media (max-width: 480px) {
    .chat-window {
        width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        margin: 0 !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
    }
}

/* Personal Chat Wrapper (Refactored from inline styles) */
.personal-chat-wrapper {
    display: none;
    /* Initial state, toggled by JS */
    flex: 1;
    overflow: hidden;
    min-height: 0;
    height: 100%;
}

/* --- REFACTORED CHAT MODULE STYLES (Global & Personal) --- */

/* Global Chat Container */
.global-chat-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-height: 0;
    height: 100%;
}

/* Common Header Styles */
.chat-module-header {
    padding: 15px 20px 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-module-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #aaa;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-admin-clear {
    background: none;
    border: none;
    color: #ff4d4d;
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
    transition: transform 0.2s;
}

.chat-admin-clear:hover {
    transform: scale(1.1);
}

.chat-live-count {
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--color-primary);
    background: rgba(var(--color-primary-rgb), 0.1);
    padding: 2px 8px;
    border-radius: 10px;
    display: none;
}

/* Online Users Rail */
.rp-online-rail {
    padding: 5px 15px 15px 15px;
    display: flex;
    gap: 12px;
    overflow-x: auto;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE */
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    margin-bottom: 5px;
    min-height: 60px;
    align-items: center;
}

.rp-online-rail::-webkit-scrollbar {
    display: none;
}

.rp-rail-item {
    flex-shrink: 0;
    cursor: pointer;
    transition: transform 0.2s;
    position: relative;
}

.rp-rail-item:hover {
    transform: scale(1.1);
}

.rp-rail-item.skeleton {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-surface-2);
}

.rp-rail-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    object-fit: cover;
}

.rp-rail-status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #31a24c;
    border: 2px solid #fff;
    border-radius: 50%;
}

/* Loading States */
.chat-loading-container {
    text-align: center;
    padding: 40px;
    color: #ccc;
}

.chat-loading-spinner {
    font-size: 24px;
    margin-bottom: 10px;
    color: var(--color-primary);
}

.chat-loading-text {
    font-size: 0.9rem;
}

/* Color Picker */
.chat-color-trigger {
    margin-left: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.chat-color-trigger:hover {
    transform: scale(1.1);
}

.chat-color-popover {
    display: none;
    position: absolute;
    bottom: 55px;
    right: 0;
    background: #fff;
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    width: 180px;
    flex-wrap: wrap;
    gap: 8px;
    z-index: 100;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

/* Personal Chat Empty State */
.personal-chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 20px;
}

.personal-chat-lock-icon {
    width: 60px;
    height: 60px;
    background: var(--bg-surface-2);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

.personal-chat-lock-icon i {
    font-size: 24px;
    opacity: 0.5;
}

.personal-chat-empty h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.personal-chat-empty p {
    font-size: 0.9rem;
    margin-bottom: 20px;
    max-width: 200px;
}

.btn-personal-login {
    border-radius: 20px;
    padding: 8px 25px;
}

/* Personal Chat Header (Instagram Style) */
.personal-chat-main-wrapper {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.personal-chat-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Center align like global header */
    margin-bottom: 10px;
    /* Match global header padding/margin */
    padding: 15px 20px 10px 20px;
    /* Exact padding from .chat-module-header */
}

.personal-chat-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #aaa;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}

.personal-chat-count {
    font-size: 0.8rem;
    /* Match apparent size */
    font-weight: 800;
    /* Match boldness */
    color: var(--text-main);
    /* Black/Dark */
    display: block;
    /* Ensure visibility */
    /* No background/pill style to match screenshot */
}