*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    background: #111b21;
    color: #e9edef;
    height: 100vh;
    overflow: hidden;
}

/* ── Login ──────────────────────────────────────────────── */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    background: #202c33;
    padding: 40px 36px;
    border-radius: 12px;
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.login-container h1 {
    font-size: 22px;
    font-weight: 400;
}

.login-error {
    color: #f15c6d;
    font-size: 13px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.login-form input {
    background: #2a3942;
    border: none;
    border-radius: 8px;
    padding: 12px 16px;
    color: #e9edef;
    font-size: 14px;
    outline: none;
    width: 100%;
}

.login-form input::placeholder { color: #8696a0; }
.login-form input:focus { box-shadow: 0 0 0 2px #00a884; }

.login-form button {
    background: #00a884;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 4px;
    transition: background 0.15s;
    font-family: inherit;
}

.login-form button:hover { background: #06cf9c; }

/* ── App layout ─────────────────────────────────────────── */

#app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Left panel ─────────────────────────────────────────── */

#chatContainer {
    width: 30%;
    min-width: 280px;
    max-width: 420px;
    background: #111b21;
    border-right: 1px solid #2a3942;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

#SearchContainer {
    padding: 8px 12px;
    border-bottom: 1px solid #2a3942;
    flex-shrink: 0;
}

.search-bar {
    background: #202c33;
    border-radius: 8px;
    padding: 8px 14px;
    margin-bottom: 8px;
}

.search-bar input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: #e9edef;
    font-size: 14px;
    font-family: inherit;
}

.search-bar input::placeholder { color: #8696a0; }

.filter-tabs {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tab {
    background: none;
    border: none;
    color: #8696a0;
    font-size: 13px;
    padding: 4px 14px;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.tab.active {
    background: rgba(0, 168, 132, 0.15);
    color: #00a884;
}

.tab:hover:not(.active) { color: #e9edef; }

.tab-refresh {
    margin-left: auto;
    background: none;
    border: none;
    color: #8696a0;
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 50%;
    transition: color 0.15s;
}

.tab-refresh:hover { color: #e9edef; }

/* Chat list */

#ChatList {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

#ChatList::-webkit-scrollbar          { width: 5px; }
#ChatList::-webkit-scrollbar-track    { background: transparent; }
#ChatList::-webkit-scrollbar-thumb    { background: #374248; border-radius: 3px; }

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid rgba(42, 57, 66, 0.5);
    transition: background 0.1s;
}

.chat-item:hover    { background: #202c33; }
.chat-item.selected { background: #2a3942; }

.avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: #2a3942;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    color: #8696a0;
    flex-shrink: 0;
    text-transform: uppercase;
}

.chat-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.chat-phone {
    font-size: 15px;
    color: #e9edef;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-preview {
    font-size: 13px;
    color: #8696a0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 11px;
    color: #8696a0;
    flex-shrink: 0;
    align-self: flex-start;
    margin-top: 2px;
}

.error-item {
    padding: 20px 16px;
    color: #8696a0;
    font-size: 13px;
    text-align: center;
}

/* ── Right panel ────────────────────────────────────────── */

#ChatDisplayer {
    flex: 1;
    background: #0b141a;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Empty state */

#emptyState {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 16px;
    color: #8696a0;
    border-top: 3px solid #00a884;
}

#emptyState h2 {
    font-size: 28px;
    font-weight: 300;
    color: #e9edef;
}

#emptyState p { font-size: 14px; }

/* Chat view */

#chatView {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.hidden { display: none !important; }

/* Header */

#chatHeader {
    background: #202c33;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.back-btn {
    display: none;
    background: none;
    border: none;
    color: #aebac1;
    cursor: pointer;
    padding: 4px;
    align-items: center;
    border-radius: 50%;
    transition: color 0.15s;
}

.back-btn:hover { color: #e9edef; }

#chatHeader .avatar {
    width: 40px;
    height: 40px;
    font-size: 16px;
}

.chat-header-info { flex: 1; }

#headerPhone {
    font-size: 15px;
    font-weight: 500;
    color: #e9edef;
}

.logout-link {
    color: #8696a0;
    text-decoration: none;
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 6px;
    transition: color 0.15s;
}

.logout-link:hover { color: #e9edef; }

/* Message area */

#messageArea {
    flex: 1;
    overflow-y: auto;
    padding: 16px 8%;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

#messageArea::-webkit-scrollbar       { width: 5px; }
#messageArea::-webkit-scrollbar-track { background: transparent; }
#messageArea::-webkit-scrollbar-thumb { background: #374248; border-radius: 3px; }

/* Date separator */

.date-separator {
    align-self: center;
    background: #182229;
    color: #8696a0;
    font-size: 12px;
    padding: 5px 14px;
    border-radius: 8px;
    margin: 10px 0;
}

/* Bubbles */

.bubble {
    max-width: 65%;
    padding: 6px 10px 4px;
    border-radius: 8px;
    margin-bottom: 1px;
    word-wrap: break-word;
}

.bubble-in {
    background: #202c33;
    align-self: flex-start;
    border-top-left-radius: 2px;
}

.bubble-out {
    background: #005c4b;
    align-self: flex-end;
    border-top-right-radius: 2px;
}

.bubble-text {
    display: block;
    font-size: 14px;
    color: #e9edef;
    line-height: 1.4;
    white-space: pre-wrap;
}

.bubble-time {
    display: block;
    font-size: 11px;
    color: rgba(233, 237, 239, 0.55);
    text-align: right;
    margin-top: 2px;
}

/* ── Mobile (<768px) ────────────────────────────────────── */

@media (max-width: 768px) {
    #chatContainer {
        position: absolute;
        inset: 0;
        width: 100%;
        max-width: 100%;
        z-index: 1;
    }

    #ChatDisplayer {
        position: absolute;
        inset: 0;
        z-index: 0;
    }

    #app.chat-open #chatContainer  { display: none; }
    #app.chat-open #ChatDisplayer  { z-index: 2; }

    .back-btn { display: flex; }

    #messageArea { padding: 12px 4%; }

    .bubble { max-width: 85%; }
}
