:root {
    --bg-color: #111b21;
    --sidebar-bg: #111b21;
    /* Usually sidebar header is #202c33, list is #111b21 */
    --header-bg: #202c33;
    --item-bg: #111b21;
    --item-hover: #202c33;
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --brand-color: #00a884;
    --incoming-bubble: #202c33;
    --outgoing-bubble: #005c4b;
    --system-red: #ef5350;
    --border-color: #222d34;
    --input-bg: #2a3942;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    height: 100%;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    background-color: var(--bg-color);
}

/* --- Sidebar --- */
#sidebar {
    flex: 0 0 30%;
    /* Fixed width, don't grow or shrink */
    width: 30%;
    min-width: 300px;
    max-width: 450px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    background-color: var(--sidebar-bg);
    z-index: 10;
}

.sidebar-header {
    height: 60px;
    background-color: var(--header-bg);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.app-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.search-bar-container {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--sidebar-bg);
}

.search-bar {
    background-color: var(--header-bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    padding: 6px 12px;
    height: 35px;
}

.search-icon {
    color: var(--text-secondary);
    margin-right: 12px;
    display: flex;
}

.search-bar input {
    background: none;
    border: none;
    color: var(--text-primary);
    width: 100%;
    outline: none;
    font-size: 0.9rem;
}

.search-bar input::placeholder {
    color: var(--text-secondary);
}

.session-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.session-item {
    display: flex;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s;
}

.session-item:hover,
.session-item.active {
    background-color: var(--item-hover);
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: #607d8b;
    /* Fallback avatar color */
    margin-right: 12px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.avatar svg {
    width: 100%;
    height: 100%;
    fill: #dfe5e7;
}

.session-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    /* For text truncation */
}

.session-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}

.session-phone {
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 500;
}

.session-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.session-preview {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.last-msg {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 70%;
}

.session-timer {
    font-size: 0.75rem;
    color: var(--brand-color);
    font-weight: 500;
}

.session-timer.closed {
    color: var(--system-red);
}

/* --- Main Chat --- */
#main-chat {
    flex: 1;
    min-width: 0;
    /* Prevent flex overflow issues */
    display: flex;
    flex-direction: column;
    background-image: url('bg-pattern.png');
    /* Local background image */
    background-repeat: repeat;
    background-size: 500px;
    /* Adjust size to make pattern visible but not too large */
    background-color: #0b141a;
    /* Fallback */
    position: relative;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    text-align: center;
    background-color: var(--border-color);
    /* Slightly lighter than bg */
    border-bottom: 6px solid var(--brand-color);
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.chat-container.hidden {
    display: none;
}

.chat-header {
    height: 60px;
    background-color: var(--header-bg);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    border-left: 1px solid var(--border-color);
    flex-shrink: 0;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    margin-right: 12px;
    border-radius: 50%;
    overflow: hidden;
}

.chat-info {
    display: flex;
    flex-direction: column;
}

#chat-title {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
}

#chat-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 5%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message-bubble {
    max-width: 90%;
    padding: 6px 7px 8px 9px;
    border-radius: 7.5px;
    position: relative;
    font-size: 0.9rem;
    line-height: 1.4;
    word-wrap: break-word;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.message-bubble.incoming {
    align-self: flex-start;
    background-color: var(--incoming-bubble);
    border-top-left-radius: 0;
}

.message-bubble.outgoing {
    align-self: flex-end;
    background-color: var(--outgoing-bubble);
    border-top-right-radius: 0;
}

.msg-content {
    color: var(--text-primary);
    margin-bottom: 4px;
}

.msg-time {
    float: right;
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.6);
    margin-left: 8px;
    margin-top: 4px;
}

.chat-input-area {
    background-color: var(--header-bg);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.input-wrapper {
    flex: 1;
    background-color: var(--input-bg);
    border-radius: 8px;
    padding: 9px 12px;
    margin-right: 10px;
}

#message-input {
    width: 100%;
    background: none;
    border: none;
    color: var(--text-primary);
    outline: none;
    font-size: 0.95rem;
}

#message-input:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.send-btn {
    background-color: var(--brand-color);
    color: white;
    padding: 10px;
    border-radius: 50%;
    transition: transform 0.1s;
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn:disabled {
    background-color: var(--input-bg);
    color: var(--text-secondary);
    cursor: not-allowed;
}

/* --- Mobile Responsiveness --- */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    #sidebar {
        width: 100%;
        max-width: none;
        border-right: none;
        height: 100dvh;
        padding-bottom: 20px;
    }

    .session-list {
        padding-bottom: 80px;
    }

    #main-chat {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 20;
        transform: translateX(100%);
        transition: transform 0.3s ease-in-out;
    }

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

    .mobile-only {
        display: flex;
        margin-right: 10px;
    }

    .empty-state {
        display: none;
    }

    .chat-container.hidden {
        display: flex;
    }
}

/* --- Header Password Input --- */
#header-password-input {
    width: 40px;
    background-color: transparent;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-primary);
    text-align: center;
    font-size: 1rem;
    margin-right: 5px;
    outline: none;
    padding: 2px;
}

#header-password-input:focus {
    border-bottom-color: var(--brand-color);
}

#header-login-btn {
    background-color: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-primary);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.8rem;
    cursor: pointer;
}

#header-login-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Utility */
.hidden {
    display: none !important;
}