/* Minimalist X icon for sidebar close */
.sidebar-close-x {
    display: block;
    position: relative;
    width: 28px;
    height: 28px;
}

.sidebar-close-x::before,
.sidebar-close-x::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 18px;
    height: 2.2px;
    background: #222;
    border-radius: 2px;
    transform-origin: center;
    transition: background 0.2s;
}

.sidebar-close-x::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.sidebar-close-x::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

.sidebar-close-btn:hover .sidebar-close-x::before,
.sidebar-close-btn:hover .sidebar-close-x::after {
    background: #374151;
}

/* Sidebar close (X) button for mobile */

.sidebar-close-btn {
    display: none;
    position: absolute;
    top: 14px;
    right: 16px;
    z-index: 10;
    background: transparent;
    border: none;
    color: #374151;
    font-size: 26px;
    padding: 4px 8px;
    border-radius: 50%;
    box-shadow: none;
    cursor: pointer;
    transition: background 0.2s;
}

.sidebar-close-btn:active,
.sidebar-close-btn:hover {
    background: transparent;
}

@media (max-width: 768px) {
    .sidebar-close-btn {
        display: block;
    }
}

/* Chat Room Variables */
:root {
    --chat-primary: #374151;
    --chat-primary-gradient: linear-gradient(135deg, #374151 0%, #4b5563 100%);
    --chat-bg: #F7F4ED;
    --chat-sidebar-bg: #F7F4ED;
    --chat-border: #e2e8f0;
    --chat-text-dark: #2d3748;
    --chat-text-muted: #718096;
    --chat-user-msg-bg: #374151;
    --chat-user-msg-text: #ffffff;
    --chat-other-msg-bg: #edf2f7;
    --chat-other-msg-text: #2d3748;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.02);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.04);
}

/* =============================================
   FULL-VIEWPORT CHAT PAGE LAYOUT
   ============================================= */

/* Lock the entire page — no external scrolling */
html.chat-page,
body.chat-page-body {
    height: 100% !important;
    overflow: hidden !important;
}

/* Hide standard footer on chat page */
body.chat-page-body footer {
    display: none !important;
}

/* Main fills from below navbar to bottom of viewport */
.chat-page-main {
    background-color: var(--chat-bg);
    padding: 0;
    /* measured from top of page; navbar is ~72px */
    position: fixed;
    top: 72px;
    /* matches .header-mid height */
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
}

/* Full-height bootstrap helpers inside main */
.chat-page-main .container-fluid,
.chat-page-main .row,
.chat-page-main [class*="col-"] {
    height: 100%;
}

/* Chat Container Card — fills available space */
.chat-container {
    background: #F7F4ED;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
    height: 100%;
    max-height: none;
    display: flex;
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

/* Sidebar (Rooms) */
.chat-sidebar {
    width: 300px;
    background: var(--chat-sidebar-bg);
    border-right: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    z-index: 2;
}

.sidebar-header {
    padding: 25px;
}

.sidebar-header h3 {
    font-size: 22px;
    font-weight: 800;
    margin: 0;
    color: var(--chat-text-dark);
    letter-spacing: -0.5px;
}

.room-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 15px;
}

.room-item {
    padding: 12px 15px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    border-radius: 12px;
    margin-bottom: 8px;
    border: 1px solid transparent;
}

.room-item:hover {
    background-color: #f7fafc;
}

.room-item.active {
    background: #efeee8;
    border-color: rgba(252, 63, 0, 0.1);
    box-shadow: 0 4px 12px rgba(252, 63, 0, 0.08);
}

.room-item .room-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background-size: cover;
    background-position: center;
    margin-right: 15px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s;
}

.room-item:hover .room-icon {
    transform: scale(1.05);
}

.room-info {
    flex: 1;
    min-width: 0;
}

.room-info h4 {
    font-size: 15px;
    font-weight: 700;
    margin: 0 0 4px 0;
    color: var(--chat-text-dark);
}

.room-item.active .room-info h4 {
    color: var(--chat-primary);
}

.room-info p {
    font-size: 13px;
    color: var(--chat-text-muted);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    position: relative;
}

/* Chat Header */
.chat-header {
    padding: 20px 30px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.header-title-group h3 {
    font-size: 18px;
    font-weight: 800;
    margin: 0;
    color: var(--chat-text-dark);
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.room-desc-header {
    font-size: 13px;
    color: var(--chat-text-muted);
    margin: 0;
    font-weight: 500;
}

.online-status {
    font-size: 12px;
    color: #48bb78;
    font-weight: 700;
    display: flex;
    align-items: center;
    background: rgba(72, 187, 120, 0.1);
    padding: 6px 12px;
    border-radius: 20px;
    white-space: nowrap;
}

.online-status::before {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    background-color: #48bb78;
    border-radius: 50%;
    margin-right: 6px;
    box-shadow: 0 0 0 2px rgba(72, 187, 120, 0.2);
}

/* Messages Area */
.chat-messages {
    flex: 1;
    padding: 100px 30px 30px 30px;
    /* Increased top padding matching new header height */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background-image: radial-gradient(#cbd5e0 1px, transparent 1px);
    background-size: 30px 30px;
    background-position: 0 0, 15px 15px;
    overflow-anchor: none;
    /* Prevents browser scroll anchoring jumps */
    scroll-behavior: auto;
    /* Ensure manual scrolling is instant/stable */
}

/* Message Styles */
.message {
    display: flex;
    align-items: flex-start;
    /* Aligned to top for professional look */
    max-width: 80%;
    animation: slideUp 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background-size: cover;
    margin-right: 12px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    border: 2px solid #fff;
}

.message.self .message-avatar {
    margin-right: 0;
    margin-left: 12px;
    display: none;
}

.message-content-wrapper {
    display: flex;
    flex-direction: column;
}

.message-sender {
    font-size: 12px;
    font-weight: 600;
    color: var(--chat-text-muted);
    margin-bottom: 6px;
    margin-left: 12px;
}

.message.self .message-sender {
    display: none;
}

.message-bubble {
    padding: 12px 18px;
    border-radius: 18px;
    border-top-left-radius: 4px;
    /* Beak at top left to match top-aligned avatar */
    background: var(--chat-other-msg-bg);
    color: var(--chat-other-msg-text);
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    font-size: 15px;
    line-height: 1.5;
}

.message.self .message-bubble {
    background: var(--chat-primary-gradient);
    color: var(--chat-user-msg-text);
    border-top-left-radius: 18px;
    border-top-right-radius: 4px;
    /* User messages point top right */
    box-shadow: 0 4px 15px rgba(252, 63, 0, 0.25);
}

.message-time {
    font-size: 11px;
    color: #a0aec0;
    margin-top: 6px;
    text-align: right;
    font-weight: 500;
}

/* Input Area */
.chat-input-area {
    padding: 20px 30px;
    background: #fff;
    border-top: 1px solid var(--chat-border);
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: #f7fafc;
    border-radius: 16px;
    padding: 8px 8px 8px 20px;
    border: 1px solid transparent;
    /* Prepare for focus */
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.input-wrapper:focus-within {
    background: #fff;
    border-color: #e2e8f0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.btn-emoji {
    border: none;
    background: none;
    color: #a0aec0;
    font-size: 20px;
    cursor: pointer;
    transition: color 0.2s;
    padding: 0;
    margin-right: 12px;
}

.btn-emoji:hover {
    color: #718096;
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 0;
    max-height: 120px;
    resize: none;
    outline: none;
    font-family: inherit;
    font-size: 15px;
    color: var(--chat-text-dark);
}

#message-input::placeholder {
    color: #cbd5e0;
}

.btn-send {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--chat-primary-gradient);
    border: none;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: 12px;
    box-shadow: 0 4px 12px rgba(252, 63, 0, 0.2);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-send:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(252, 63, 0, 0.3);
}

.btn-send:active {
    transform: translateY(0);
}

/* Animations */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

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

/* =============================================
   MOBILE RESPONSIVE (≤ 768px)
   ============================================= */
@media (max-width: 768px) {

    /* 1. Hide horizontal nav-scroll row on chat page:
          it overlaps the chat content and isn't needed here.
          This reduces true mobile header height to ~55px
          (50px .mobile-nav-wrapper + 5px top padding on .header-bottom). */
    body.chat-page-body .mobile-nav-links-wrapper {
        display: none !important;
    }

    /* 2. Chat main: position from top of real header height */
    .chat-page-main {
        top: 55px;
        padding: 0;
    }

    /* 3. Chat container fills all available space */
    .chat-container {
        height: 100%;
        max-height: none;
        border-radius: 0;
        border: none;
    }

    /* 4. Sidebar: full-width fixed overlay that slides in from the left */
    .chat-sidebar {
        position: fixed;
        top: 55px;
        left: 0;
        width: 100%;
        height: calc(100% - 55px);
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
        z-index: 200;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

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

    /* 5. Dark scrim backdrop behind sidebar */
    .chat-sidebar-backdrop {
        display: none;
        position: fixed;
        top: 55px;
        left: 0;
        width: 100%;
        height: calc(100% - 55px);
        background: rgba(0, 0, 0, 0.45);
        z-index: 199;
        cursor: pointer;
    }

    .chat-sidebar-backdrop.active {
        display: block;
    }

    /* 6. Chat main fills full width on mobile */
    .chat-main {
        width: 100%;
        min-width: 0;
    }

    /* 7. Hamburger toggle: always visible */
    .mobile-menu-toggle {
        display: inline-block !important;
        margin-right: 10px;
        font-size: 20px;
        color: var(--chat-text-dark);
        cursor: pointer;
        flex-shrink: 0;
    }

    /* 8. Chat header bar */
    .chat-header {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        padding: 12px 16px;
    }

    .header-title-group h3 {
        font-size: 16px;
    }

    .room-desc-header {
        font-size: 12px;
    }

    /* 9. Messages area */
    .chat-messages {
        padding: 68px 12px 16px 12px;
        gap: 14px;
    }

    /* 10. Message bubbles */
    .message {
        max-width: 88%;
    }

    .message-bubble {
        font-size: 14px;
        padding: 10px 14px;
    }

    /* 11. Input area — honour iOS safe-area for home-indicator bar */
    .chat-input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .input-wrapper {
        padding: 6px 6px 6px 14px;
        border-radius: 14px;
    }

    #message-input {
        font-size: 15px;
        padding: 8px 0;
    }

    .btn-send {
        width: 40px;
        height: 40px;
        border-radius: 10px;
    }

    /* 12. Sidebar aesthetics on mobile */
    .sidebar-header {
        padding: 20px 20px 10px 20px;
    }

    .sidebar-header h3 {
        font-size: 18px;
    }

    .room-list {
        padding: 8px 12px;
    }

    .room-item {
        padding: 14px 12px;
    }
}

/* =============================================
   LOGIN PROMPT OVERLAY
   ============================================= */
#login-prompt-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    border-radius: 0 0 20px 0;
}

.login-prompt {
    text-align: center;
    padding: 20px;
}

.login-prompt i {
    font-size: 32px;
    color: #a0aec0;
    margin-bottom: 12px;
    display: block;
}

.login-prompt p {
    font-size: 14px;
    color: var(--chat-text-muted);
    margin-bottom: 16px;
}

.btn-login-prompt,
.btn-register-prompt {
    display: inline-block;
    padding: 10px 24px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    margin: 0 6px;
    transition: all 0.2s ease;
}

.btn-login-prompt {
    background: var(--chat-primary-gradient);
    color: #fff;
    box-shadow: 0 4px 12px rgba(252, 63, 0, 0.2);
}

.btn-login-prompt:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(252, 63, 0, 0.3);
    color: #fff;
}

.btn-register-prompt {
    background: #f7fafc;
    color: var(--chat-text-dark);
    border: 1px solid #e2e8f0;
}

.btn-register-prompt:hover {
    background: #edf2f7;
    color: var(--chat-text-dark);
}

/* =============================================
   COOLDOWN INDICATOR
   ============================================= */
#cooldown-indicator {
    text-align: center;
    font-size: 12px;
    color: var(--chat-primary);
    padding: 6px 0 0;
    font-weight: 600;
    animation: fadeIn 0.2s ease;
}

.btn-send.cooldown {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* =============================================
   TOAST NOTIFICATIONS
   ============================================= */
.chat-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    z-index: 99999;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    max-width: 90vw;
    text-align: center;
}

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

.chat-toast.warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fbbf24;
}

.chat-toast.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #f87171;
}

.chat-toast.info {
    background: #dbeafe;
    color: #1e3a5f;
    border: 1px solid #60a5fa;
}

/* =============================================
   LOADING STATE
   ============================================= */
.chat-loading,
.chat-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--chat-text-muted);
    gap: 16px;
}

.chat-loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e2e8f0;
    border-top-color: var(--chat-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.chat-error i {
    font-size: 36px;
    color: #f56565;
}

.chat-error p {
    font-size: 14px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* =============================================
   MESSAGE ANIMATE IN
   ============================================= */
.msg-animate {
    animation: slideUp 0.3s ease-out;
}

/* System message style */
.system-message .message-bubble {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
    font-style: italic;
    font-size: 14px;
}

.system-message .message-sender {
    color: #16a34a;
    font-weight: 700;
}

/* =============================================
   AUTH OVERLAY (Login Prompt on Input Area)
   ============================================= */
.chat-auth-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    border-radius: 0 0 20px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
}

.chat-auth-prompt {
    text-align: center;
    padding: 30px;
    max-width: 300px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.6);
    animation: fadeIn 0.4s ease-out;
}

.chat-auth-prompt i {
    font-size: 2.5rem;
    color: var(--chat-primary);
    margin-bottom: 20px;
    display: inline-block;
    background: rgba(55, 65, 81, 0.05);
    width: 80px;
    height: 80px;
    line-height: 80px;
    border-radius: 50%;
}

.chat-auth-prompt p {
    font-size: 16px;
    font-weight: 800;
    color: var(--chat-text-dark);
    margin: 0 0 24px 0;
    line-height: 1.6;
}

.chat-auth-prompt .btn-primary {
    display: inline-block;
    padding: 14px 36px;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 800;
    text-decoration: none;
    background: var(--chat-primary-gradient);
    color: #fff;
    box-shadow: 0 8px 20px rgba(55, 65, 81, 0.2);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 0.3px;
}

.chat-auth-prompt .btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 24px rgba(55, 65, 81, 0.3);
    color: #fff;
}