:root {
    --sidebar-width-tablet: 220px;
    --sidebar-width-desktop: 250px;
    --send-icon-size: 25px;
    --background-color: rgba(0,0,0,0);
    --sidebar-color: #090e18;
    --profile-color: #544F7E;
    --div-color: #030509;
    --word-color: #cbd5e1;
    --chat-color: #020617;
    --border-color: #544F7E;
    --hover-color: #313236;
    --msg-other-color: #252f5c;
    --msg-me-color: #6571a3;
}

/* --- CẤU TRÌNH CHUNG --- */
* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    font-family: Inter, Arial, sans-serif;
}

body {
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--background-color);
    overflow: hidden;

}

.main-container {
    height: 80vh;
    width: 100%;
    position: relative;
    max-width: 1200px;
    display: flex;
    align-items: stretch;
    overflow: hidden;
    box-shadow: 0px 0px 25px #9e8faf92;
    border-radius: 25px;
}

/* --- SIDEBAR (THANH MENU) --- */
.sidebar {
    display: flex; 
    flex-direction: column;
    background-color: var(--sidebar-color);
    border-right: 1px solid var(--border-color);
    color: var(--word-color);
    width: var(--sidebar-width-desktop);
    flex-shrink: 0;
    overflow-y: auto;
    transition: 0.3s ease;
}

/* PHẦN BỔ SUNG: Logic thu gọn Sidebar cho PC */
.sidebar.collapsed {
    width: 0;
    opacity: 0;
    border: none;
    overflow: hidden;
}

.profile, .public-room, .user-online, .roomchat-list {
    background: var(--div-color);
    padding: 30px;
    border-top: 1px solid var(--border-color);
}

.profile { background: linear-gradient(to right, var(--profile-color),var(--msg-me-color)); }


.public-room{ background: linear-gradient(to bottom, var(--chat-color), var(--div-color));}

.public-room:hover { background-color: var(--hover-color); cursor: pointer; }


/* --- ONLINE LIST --- */
.user-online{
    padding: 0;
}

.online-header {
    display: flex;
    justify-content: space-between;
    padding: 30px;
    background: linear-gradient(to bottom, var(--chat-color), var(--div-color));
}

.online-body {
    padding: 30px 38px 30px 30px;;
    background-color: var(--div-color);
    border-top: solid 1px var(--border-color);
    transition: max-height 0.3s ease;
}

.search-bar{
    display: flex;
    background-color: var(--hover-color);
    align-items: center;
    justify-items: flex-end;
}

.search-bar input{
    flex: 1;
    border: none;
    outline: none;
    font-size: 12px;
    padding: 5px;
}

.search-bar i{
    padding: 5px;
    background-color: var(--hover-color);
}

.search-bar i:hover{
    cursor: pointer;
    background-color: var(--border-color);
}


.online-body.hidden { display: none; }

#online-list { list-style: none; }
#online-list li {
    background: var(--border-color);
    margin: 10px 0;
    padding: 10px;
    border-radius: 15px;
    cursor: pointer;
}

#online-list li:hover{
    background-color: var(--hover-color);
}

/* Lịch sử trò chuyện */
.roomchat-list{
    padding: 0;
}

.roomchat-header{
    text-align: center;
    padding: 10px;
    background: linear-gradient(to bottom, var(--chat-color), var(--div-color));
}

.roomchat-body{
    padding: 0px 38px 30px 30px;
}

#roomchat .chat-user {
  padding: 10x;
  cursor: pointer;
  list-style: none;
  background-color: #544F7E;
  border-radius: 15px;
  margin: 10px 0;
}

#roomchat .chat-user:hover {
  background: var(--hover-color);
  border-radius: 15px;
}


/* --- CHAT SECTION --- */
.chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--chat-color);
    min-width: 0; /* Đảm bảo khung chat co giãn khi ẩn sidebar */
}

.chat-header {
    padding: 16px;
    background: linear-gradient(to bottom, var(--div-color), var(--chat-color));
    color: #e5e7eb;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-toggle i{
    padding: 5px;
    border-radius: 25%;
}

.sidebar-toggle i:hover{
    background-color: var(--hover-color);
}

/* --- BOX TIN NHẮN (CĂN TRÁI PHẢI) --- */
.chat-box {
    flex: 1;
    padding: 20px 8px 20px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    scrollbar-gutter: stable;

}

.msg-me, .msg-other {
    max-width: 70%;
    padding: 15px;
    border-radius: 20px;
    margin: 8px 0;
    color: var(--word-color);
    word-wrap: break-word;
}

.msg-me {
    align-self: flex-end;
    background-color: var(--msg-me-color);
    border-bottom-right-radius: 2px;
}

.msg-other {
    align-self: flex-start;
    background-color: var(--msg-other-color);
    border-bottom-left-radius: 2px;
}

.username-msg {
    display: block;
    font-size: 11px;
    color: #edc170;
    margin-bottom: 5px;
}

/* THÔNG BÁO USER ĐN */
.msg-system{
    display: flex;
    justify-content: center;
    margin-top: 3px;
}

.msg-system span{
    padding: 5px;
    border-radius: 25px;
    background: var(--hover-color);
    font-size: 11px;
    color: var(--word-color);
}

/* --- INPUT --- */
.chat-input {
    padding: 15px;
    background: var(--chat-color);
    border-top: 1px solid var(--border-color);
}

.chat-input-body { display: flex; gap: 10px; }
.chat-input input {
    flex: 1;
    color: white !important; 
    background-color: #1e293b;
    border-radius: 20px;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    outline: none;
}

/* PHẦN BỔ SUNG: Placeholder cho dễ nhìn */
.chat-input input::placeholder {
    color: #64748b;
}

.chat-input button {
    background: transparent;
    border: none;
    color: var(--word-color);
    font-size: var(--send-icon-size);
    cursor: pointer;
}

.chat-input button:hover{
    color: var(--msg-me-color);
}

/* --- RESPONSIVE MOBILE --- */
@media (max-width: 768px) {
    .sidebar {
        display: none; 
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 1000;
        width: 85vw;          
        max-width: 280px;    
        min-width: 240px;
    }

    .sidebar.active {
        display: flex; 
    }

    .sidebar-toggle {
        display: block;
        color: white;
        font-size: 20px;
        cursor: pointer;
    }
    .sidebar.collapsed {
        width: 80%;
        opacity: 1;
        display: none;
    }
} 

@media (min-width: 769px) and (max-width: 1023px) {     /*TABLET*/
    .main-container {
        flex-direction: row; 
      }

    .sidebar {
       width: var(--sidebar-width-tablet);
       max-height: 100%;
       display: flex;
      }

    .chat-section {
        flex: 1;
        display: flex;
        flex-direction: column;
      }}

@media (min-width: 1024px){             /*DESKTOP*/
    .main-container {
        flex-direction: row; 
        max-width: 800px;
      }

    .sidebar {
        width: var(--sidebar-width-desktop);
        max-height: 100%;
        display: flex;
      }

    .chat-section {
        flex: 1;
        display: flex;
        flex-direction: column;
      } 

    .msg-other, .msg-me{
        max-width: 200px;
    } 
}

/* Hiển thị nút toggle mặc định trên PC để bấm ẩn menu */
.sidebar-toggle { 
    display: block; 
    cursor: pointer;
    color: white;
    font-size: 20px;
}

/*SCROLLBAR*/
body{
    scrollbar-color: #444 transparent;
}

.chat-user {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;
}

.unread-badge {
    background-color: #ff4d4d;
    color: white;
    font-size: 11px;
    font-weight: bold;
    min-width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
