:root {
    --bg-color: #21252b;
    --chat-bg: #282c34;
    --sidebar-bg: #21252b;
    --input-bg: #282c34;
    --text-color: #abb2bf;
    --message-in: #2c313a;
    --message-out: #2b5278;
    --accent: #5288c1;
    --hover: #2b3644;
    --room-sidebar-width: 120px;
    --user-sidebar-width: 240px;
    --header-border: #000;
    --muted-pink: #bb64a0;
    --muted-green: #7ad15d;
    --muted-purple: #828bce;
    --avatar-fallback-bg: #3d3d3d;
}

/* Светлая тема */
body.light-theme {
    --bg-color: #f0f2f5;
    --sidebar-bg: #ffffff; /* Установлено для согласованной темы сайдбара */
    --chat-bg: #ffffff;
    --input-bg: #e0e0e0; /* Более светлый фон для инпутов в светлой теме */
    --text-color: #1a1a1a;
    --message-in: #FFFACD;
    --message-out: #e0f7fa; /* Light blue for outgoing messages in light theme */
    --accent: #40A7E3;
    --hover: #f5f5f5;
    --header-border: #e0e0e0;
}


body {
    margin: 0;
    font-family: 'Roboto', sans-serif;
    background-color: var(--chat-bg);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}


/* Экран входа */
#login-screen {
    position: fixed; /* Keep it fixed to cover the entire viewport */
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--chat-bg);
    display: flex;
    flex-direction: column; /* Stack vertically: showcase, then login form */
    justify-content: flex-start; /* Align content to the top */
    align-items: center; /* Center horizontally */
    z-index: 1000;
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto; /* Allow scrolling if content is too tall */
}

.login-box {
    background: var(--sidebar-bg);
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    width: 90%;
    max-width: 320px;
}

.login-box input, .login-box select {
    padding: 10px;
    border-radius: 5px;
    border: 1px solid #333;
    background: var(--input-bg);
    color: var(--text-color);
    margin-bottom: 1rem;
    width: 100%;
    box-sizing: border-box;
}

/* Добавляем стили для Bootstrap-форм в login-box */
.login-box .form-control,
.login-box .form-select {
    color: var(--text-color);
    background-color: var(--input-bg); /* Убедимся, что фон тоже правильный */
    border: 1px solid var(--header-border); /* И рамка */
}

/* Также устанавливаем цвет плейсхолдера */
.login-box .form-control::placeholder {
    color: var(--text-color);
    opacity: 0.7; /* Можно немного приглушить плейсхолдер */
}

#recent-chats * {
    color: var(--text-color);
}


.login-box button {
    padding: 10px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    width: 100%;
}

/* Основной контейнер */
#chat-container {
    display: flex;
    height: 100vh;
    width: 100%;
}

.hidden { display: none !important; }

/* Honeypot hidden style */
.visually-hidden { /* Renamed from visual-hidden for better compatibility/standard */
    opacity: 0;
    position: absolute;
    top: 0;
    left: 0;
    height: 0;
    width: 0;
    z-index: -1;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    overflow: hidden;
    white-space: nowrap;
}



/* --- Центральная область чата --- */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--chat-bg);
    position: relative;
    min-width: 0;
}

.chat-header {
    padding: 10px 15px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--header-border);
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#theme-toggle {
    margin-left: auto; /* Подвигаем ближе к центру, чтобы не перекрывался сайдбаром */
}

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

#header-notifications {
    /* No background or specific shape for the container itself */
    /* It will just be a flex item in header-left */
    /* Removed: background-color, border-radius, width, height, display, align-items, justify-content, font-size, font-weight */
}

.chat-header .header-info {
    flex-grow: 1;
    text-align: center;
}

#current-chat-name {
    text-align: center;
}

#private-notifications {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    justify-content: center; /* This will center the items */
    margin-top: 5px; /* Add some space from the top info */
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: none; /* Для Firefox */
    -ms-overflow-style: none;  /* Для Internet Explorer и Edge */
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

.messages-area::-webkit-scrollbar {
    display: none; /* Для Chrome, Safari и Opera */
}

/* --- Message Styles (Telegram-like) --- */

.message {
    max-width: 70%;
    min-width: 100px;
    padding: 6px 10px;
    border-radius: 10px;
    position: relative;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
    margin-bottom: 2px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}

.message.incoming {
    align-self: flex-start;
    background: var(--message-in);
    color: var(--text-color);
    border-bottom-left-radius: 2px;
}

.message.outgoing {
    align-self: flex-end;
    background: var(--message-out);
    color: var(--text-color);
}

body:not(.light-theme) .message.outgoing {
    color: white;
}

.message-content {
    margin-bottom: 2px;
}

/* Timestamp & Meta */
.message-meta {
    font-size: 11px;
    text-align: right;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    gap: 4px;
    opacity: 0.7;
    float: right; /* Try to float it */
    margin-left: 8px;
    margin-top: 4px;
}

/* Avatar / Sender Name in Public Chats */
.msg-sender-info {
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
    margin-bottom: 4px;
    cursor: pointer;
}

/* Reply Quote */
.reply-quote {
    border-left: 2px solid var(--accent);
    padding-left: 6px;
    margin-bottom: 4px;
    font-size: 13px;
    background: rgba(0,0,0,0.05);
    border-radius: 2px;
}

/* Input Area */
.input-area {
    background: var(--sidebar-bg);
    padding: 10px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    border-top: 1px solid var(--header-border);
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
    z-index: 1050; /* Ensure input area is above offcanvas */
    position: relative; /* z-index only works on positioned elements */
}

#message-input {
    flex: 1;
    background: var(--bg-color); /* Cleaner look */
    border: none;
    padding: 12px;
    border-radius: 20px;
    color: var(--text-color);
    outline: none;
    resize: none;
}





.sidebar-header {
    padding: 15px;
    font-weight: bold;
    display: flex; /* Делаем flex-контейнером */
    justify-content: space-between; /* Распределяем пространство */
    align-items: center; /* Выравниваем по центру */
}





.users-list {
    overflow-y: auto; /* Enable vertical scrolling with a standard scrollbar */
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow the flex item to shrink */
    flex-grow: 1; /* Ensure it grows to fill space */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none;  /* IE and Edge */
}

#users-list::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}


.user-item {
    padding: 10px 0;
    display: flex;
    align-items: center;
    cursor: pointer;
    margin-bottom: 10px;
}

.user-item:hover {
    background: transparent;
}

.user-item.active {
    background: var(--accent);
    color: white;
}

.user-group-title {
    text-align: center;
    font-size: 32px; /* Увеличиваем до размера аватарок */
    font-weight: bold;
    padding: 8px 0;
}

/* Avatars */
.image.is-32x32 {
    width: 32px;
    height: 32px;
    display: flex; /* To center content if needed, like fallback avatar */
    justify-content: center;
    align-items: center;
    overflow: hidden; /* Hide overflowing parts if image is larger */
}

.image.is-32x32 img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Ensures the image covers the area without distortion */
}
.gender-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    font-size: 10px;
    background: var(--sidebar-bg);
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

    .status-bubble {
        background-color: #FFFACD; /* Цвет пузыря как в светлой теме, жестко задан */
        color: #000000; /* Черный текст для всех тем */
        padding: 4px 8px;
        border-radius: 12px;
        font-size: 12px;
        line-height: 1.3;
        margin-bottom: 5px;
        position: relative;
        word-wrap: break-word;
        max-width: 100%;
        width: -moz-fit-content;
        width: fit-content;
    }
    /* "Хвостик" для пузыря */
    .status-bubble::after {
        content: '';
        position: absolute;
        bottom: -4px; /* Позиция под пузырем */
        left: 15px;
        width: 0;
        height: 0;
        border: 5px solid transparent;
        border-top-color: #FFFACD; /* Same color as bubble background */
    }

    /* New User Details Container */
    .user-details {
        display: flex;
        flex-direction: column;
        overflow: hidden; /* Prevent content from breaking out */
        min-width: 0; /* Important for flex items */
        margin-left: 5px;
    }


/* --- MOBILE RESPONSIVENESS --- */

@media (max-width: 768px) {
    .message { max-width: 85%; }
    .input-area {
        gap: 4px; /* Adjust mobile input area gap */
        padding: 5px; /* Reduced padding for input area */
    }
    #message-input {
        flex-shrink: 1; /* Allow input to shrink */
        min-width: 0; /* Allow input to shrink to 0 if needed */
    }
}

/* Ensure offcanvas close button is clickable */
.offcanvas-header .btn-close {
    z-index: 9999;
    pointer-events: auto;
    opacity: 1;
}

#private-notifications {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-left: 10px;
}

.private-notification-item {
    background-color: var(--accent);
    padding: 5px 10px;
    border-radius: 15px;
    cursor: pointer;
    font-size: 12px;
    color: white;
}

.private-notification-item:hover {
    background-color: var(--hover);
}

.chat-image {
  max-width: 100%;
  border-radius: 10px;
}

#recent-chats {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    max-height: 220px; /* Limit height to ~5 items */
}

.recent-chat-item {
    cursor: pointer;
    position: relative;
    padding: 8px 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 90%;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.recent-chat-item:hover {
    background-color: transparent;
}

.recent-chat-username {
    font-size: 12px;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 30px);
}

.unread-count-number {
    color: var(--accent);
    font-weight: bold;
    margin-left: 5px;
}

.is-rounded {
    border-radius: 6px !important;
}
    
#profile-modal {
    z-index: 99999 !important;
}

/* --- Restored Button Styles --- */
#theme-toggle,
#mic-btn,
#status-btn {
    border: none !important;
    box-shadow: none !important;
    background: none !important;
    color: #888 !important;
}

#theme-toggle:focus,
#mic-btn:focus,
#status-btn:focus {
    box-shadow: none !important;
    outline: none !important;
    background: none !important;
}

#send-btn,
#left-sidebar-toggle,
#right-sidebar-toggle {
    background-color: transparent !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    color: #888 !important;
}

#send-btn:hover,
#left-sidebar-toggle:hover,
#right-sidebar-toggle:hover {
    background-color: transparent !important;
    color: var(--accent) !important;
}

#send-btn:focus,
#left-sidebar-toggle:focus,
#right-sidebar-toggle:focus {
    background-color: transparent !important;
    box-shadow: none !important;
    outline: none !important;
    color: #888 !important;
}

.offcanvas-body {
    display: flex;
    flex-direction: column;
    padding-bottom: 80px;
}

.sidebar-footer {
    margin-top: auto;
}

#profile-btn {
    background-color: #AAAAAA !important;
    border-color: #AAAAAA !important;
    color: #333 !important;
}

#profile-btn:hover {
    background-color: #929292 !important;
    border-color: #929292 !important;
}

.offcanvas-body h3 {
    color: #AAAAAA !important;
}

.room-item span {
    color: #AAAAAA !important;
}

#offcanvasUsers .offcanvas-body {
    color: #AAAAAA !important;
}
#offcanvasUsers .offcanvas-title {
    color: #AAAAAA !important;
}

#logout-btn {
    color: #AAAAAA !important;
    border-color: #AAAAAA !important;
}


/* --- New Sidebar Styles (Corrected and Consolidated) --- */

.left-sidebar {
    flex: 0 0 180px; /* Original width of offcanvas-start was 180px */
    background-color: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    transition: flex-basis 0.3s ease, width 0.3s ease;
    overflow: hidden;
    border-right: 1px solid var(--header-border); /* Border on the right */
}

.left-sidebar.collapsed {
    width: 0;
    flex-basis: 0; /* Also collapse flex-basis */
    border-right: none;
}

.left-sidebar .offcanvas-title {
    margin: 0;
}

.left-sidebar .offcanvas-header {
    padding: 10px 15px; /* Consistent padding for header */
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 15px; /* Increased gap */
    border-bottom: 1px solid var(--header-border);
    flex-shrink: 0;
    box-sizing: border-box;
}

.left-sidebar .offcanvas-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 10px 3px; /* Consistent 3px padding */
    padding-bottom: 80px; /* Restore padding for footer */
    box-sizing: border-box;
}

.right-sidebar {
    flex: 0 0 160px; /* Use flex shorthand for fixed size */
    background-color: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease; /* Transition width when collapsing */
    overflow: hidden; /* Hide content overflow */
    border-left: 1px solid var(--header-border);
}

.right-sidebar.collapsed {
    width: 0;
    flex-basis: 0; /* Also collapse flex-basis */
    border-left: none;
}

.right-sidebar .offcanvas-title {
    margin: 0; /* Remove default margin from h5 */
}

.right-sidebar .offcanvas-header {
    padding: 10px 3px; /* 3px padding for header */
    display: flex;
    justify-content: flex-start; /* Align to start */
    align-items: center;
    gap: 5px; /* Reduced gap to bring close button closer */
    border-bottom: 1px solid var(--header-border);
    flex-shrink: 0;
    box-sizing: border-box;
}

.right-sidebar .offcanvas-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Critical for flex scrolling */
    padding: 10px 3px; /* 3px padding for body content */
    box-sizing: border-box;
}

.right-sidebar .users-list {
    flex-grow: 1;
    overflow-y: auto; /* Allow this inner container to scroll */
    padding: 0; /* No padding here, use parent's padding */
}

.user-item {
    padding: 10px 0; /* No horizontal padding for user items, inherits from offcanvas-body */
    display: flex;
    align-items: center;
    cursor: pointer;
    margin-bottom: 10px;
}

.user-details {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    margin-left: 5px; /* Keep original margin */
    flex-grow: 1; /* Allow details to fill remaining space */
}

/* On mobile, revert to an overlaying sidebar to save space */
@media (max-width: 768px) {
    .right-sidebar {
        position: fixed;
        right: 0;
        top: 0;
        height: 100%;
        z-index: 1045;
        transform: translateX(100%);
        width: 160px !important; /* Fixed width when it slides in */
        transition: transform 0.3s ease-in-out;
        flex-basis: 160px; /* Match flex-basis */
    }

    .right-sidebar:not(.collapsed) {
        transform: translateX(0);
    }
    
    .right-sidebar.collapsed {
        transform: translateX(100%);
    }

    .left-sidebar {
        position: fixed;
        left: 0; /* Align to left */
        top: 0;
        height: 100%;
        z-index: 1045;
        transform: translateX(-100%); /* Collapse to left */
        width: 180px !important;
        transition: transform 0.3s ease-in-out;
        flex-basis: 180px;
    }

    .left-sidebar:not(.collapsed) {
        transform: translateX(0);
    }
    
    .left-sidebar.collapsed {
        transform: translateX(-100%);
    }
}

/* Light theme overrides for sidebar text color */

body.light-theme .offcanvas-body h3,
body.light-theme .room-item span,
body.light-theme #offcanvasUsers .offcanvas-body,
body.light-theme #offcanvasUsers .offcanvas-title {
    color: var(--text-color) !important;
}

body.light-theme .left-sidebar,
body.light-theme .right-sidebar {
    background-color: var(--sidebar-bg) !important; /* Use the defined variable */
}


/* --- Added for the black cross in light theme --- */
/* Переопределение цвета кнопки закрытия для светлой темы */
body.light-theme .btn-close {
    /* Сбрасываем фильтр, который делает иконку белой */
    filter: none;
    /* Устанавливаем стандартную видимость (можно подкорректировать) */
    opacity: 0.7;
}

body.light-theme .btn-close {
    /* Сбрасываем фильтр, который делает иконку белой */
    filter: none;
    /* Устанавливаем стандартную видимость (можно подкорректировать) */
    opacity: 0.7;
}

