body { 
    font-family: sans-serif; 
    padding: 20px; 
    background: #eee; 
    overflow-x: hidden;
}

/* Login Box */
#auth-box {
    position: absolute;
    top: 50%;
    left: 50%;
    background: white;
    padding: 20px;
    width: 300px;
    border-radius: 8px;
    border: 1px solid #ccc;
    transform: translate(-50%, -50%);
}

#auth-box input {
    width: 90%;
    padding: 8px;
    margin-bottom: 10px;
    border-radius: 5px;
    border: 1px solid #ccc;
}

#auth-box button {
    width: 45%;
    padding: 8px;
    margin-right: 5px;
    cursor: pointer;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
}

#auth-box button:hover {
    background: #0056b3;
}

/* Chat Container */
#chat-container {
    display: none;
}

/* Controls Layout */
#controls {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 12px;
    margin-top: 10px;
    width: 100%;
    padding: 5px 0;
}

#controls-left {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    flex-shrink: 0;
}

#user-input {
    width: 140px;
    padding: 8px;
    border-radius: 5px;
    border: 1px solid #ccc;
}

#logout-btn {
    width: 157px;
    height: 30px;
    margin-top: 10px;
    background: #444;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;

    font-size: 14px;
    font-weight: 600;
}

#logout-btn:hover {
    background: #666;
}

#controls-right {
    display: flex;
    flex-direction: column;
    flex: 1;
}

#msg-wrapper {
    position: relative;
    width: 100%;
    margin-bottom: 1px;
}

#msg-input {
    width: 100%;
    box-sizing: border-box;

    resize: none;
    overflow-y: auto;

    max-height: 150px;
    min-height: 40px;

    line-height: 1.4;
    padding: 8px;
    font-size: 14px;

    white-space: pre-wrap;
    word-wrap: break-word;

    border: 1px solid #ccc;
    border-radius: 5px;
    background: white;
}

#charCount {
    position: absolute;
    bottom: -18px;
    left: 4px;
    font-size: 12px;
    color: #666;
}

#send-btn {
    align-self: flex-end;
    padding: 4px 15px;
    border-radius: 5px;
    margin-top: 6px;
    background: #007bff;
    color: white;
    border: none;
    cursor: pointer;
}

#send-btn:hover {
    background: #0056b3;
}

/* Sidebar */
#menu-btn {
    font-size: 24px;
    cursor: pointer;
    background: #007bff;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 5px;
    margin-bottom: 10px;
}

#menu-btn:hover {
    background: #0056b3;
}

#sidebar {
    position: fixed;
    top: 0;
    left: -360px;
    width: 260px;
    height: 100%;
    background: white;
    border-right: 1px solid #ccc;
    padding: 20px;
    transition: left 0.3s ease;
    z-index: 999;
    overflow-y: auto;
}

#sidebar.open {
    left: 0;
}

#close-sidebar {
    background: #ff4444;
    color: white;
    border: none;
    padding: 6px 10px;
    border-radius: 5px;
    cursor: pointer;
    margin-bottom: 15px;
}

#close-sidebar:hover {
    background: #cc0000;
}

.sidebar-section-title {
    font-weight: bold;
    margin-top: 15px;
    margin-bottom: 5px;
}

.chat-item {
    padding: 8px;
    border-radius: 5px;
    border: 1px solid #ddd;
    margin-bottom: 6px;
    cursor: pointer;
    background: #f9f9f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item:hover {
    background: #e6e6e6;
}

/* Chat Window */
#chat-window { 
    height: 300px; 
    background: white; 
    border: 1px solid #bbb; 
    overflow-y: scroll; 
    padding: 10px; 
    margin-bottom: 10px; 
    border-radius: 5px; 
}

/* THREAD UI — tightened + cleaner ------------------------------- */

.msg-group {
    position: relative;
    margin-bottom: 4px;
}

/* PRIMARY MESSAGE — no indent, no lines */
.msg-group.first {
    padding-left: 0 !important;
    margin-top: 25px; 
}
.msg-group.first::before,
.msg-group.first::after {
    display: none !important;
}

/* THREADED MESSAGES — indent + vertical line */
.msg-group:not(.first) {
    padding-left: 22px;
}

.msg-group:not(.first)::before {
    content: "";
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #ccc;
    border-radius: 2px;
}

/* LAST MESSAGE — arc connector */
.msg-group.last::after {
    content: "";
    position: absolute;
    left: 8px;
    top: 12px;
    width: 12px;
    height: 12px;

    border-left: 2px solid #ccc;
    border-bottom: 2px solid #ccc;

    border-radius: 0 0 0 6px; 
}

/* MESSAGE BLOCK — classic look, but tighter */
.msg { 
    margin-bottom: 2px; 
    border-bottom: 1px solid #f0f0f0; 
    padding-bottom: 3px; 
    word-wrap: break-word;
}

/* Header: username + time on one line */
.msg-header {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 13px;
}

.msg-username {
    font-size: 15px;
    font-weight: bold;
}

.msg-time {
    font-size: 8px;
    color: #888;
}

/* Body text */
.msg-body {
    margin-top: 2px;
    white-space: pre-wrap;
}

/* Admin Panel */
#admin-panel {
    display: none;
    background: #222;
    color: white;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

#admin-panel button {
    background: #ff4444;
    margin-right: 10px;
}

#admin-panel button:hover {
    background: #cc0000;
}