* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    font-family: Arial, Helvetica, sans-serif;
    background: #e5ddd5;
    color: #111827;
}

/* ---------- MAIN LAYOUT ---------- */

.chat-app {
    display: grid;
    grid-template-columns: 360px 1fr;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* ---------- SIDEBAR ---------- */

.chat-sidebar {
    background: #ffffff;
    border-right: 1px solid #d1d5db;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
    overflow: hidden;
}

.chat-brand {
    flex: 0 0 auto;
    padding: 16px 18px;
    background: #075e54;
    color: #ffffff;
}

.chat-brand strong {
    display: block;
    font-size: 18px;
}

.chat-brand span {
    display: block;
    margin-top: 4px;
    font-size: 13px;
    color: #d1fae5;
}

/* ---------- STATS ---------- */

.chat-stats {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 10px;
    background: #f0f2f5;
    border-bottom: 1px solid #e5e7eb;
}

.chat-stats div {
    background: #ffffff;
    border-radius: 10px;
    padding: 8px;
    border: 1px solid #e5e7eb;
}

.chat-stats strong {
    display: block;
    font-size: 17px;
    color: #075e54;
}

.chat-stats span {
    display: block;
    margin-top: 2px;
    color: #667781;
    font-size: 12px;
}

/* ---------- FILTER ---------- */

.chat-filter {
    flex: 0 0 auto;
    padding: 10px;
    background: #f0f2f5;
    border-bottom: 1px solid #e5e7eb;
}

.chat-filter select {
    width: 100%;
    padding: 11px 12px;
    border-radius: 10px;
    border: 0;
    background: #ffffff;
    outline: none;
    font-size: 14px;
}

/* ---------- CONVERSATION LIST ---------- */

.conversation-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    background: #ffffff;
}

.conversation-list::-webkit-scrollbar {
    width: 6px;
}

.conversation-list::-webkit-scrollbar-track {
    background: transparent;
}

.conversation-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, .15);
    border-radius: 20px;
}

.conversation-item {
    width: 100%;
    border: 0;
    background: #ffffff;
    text-align: left;
    padding: 14px 16px;
    border-bottom: 1px solid #f0f2f5;
    cursor: pointer;
}

.conversation-item:hover,
.conversation-item.active {
    background: #f0f2f5;
}

.conversation-name {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-weight: 700;
}

.conversation-phone {
    margin-top: 4px;
    color: #667781;
    font-size: 13px;
}

.unread-badge {
    background: #25d366;
    color: #ffffff;
    border-radius: 999px;
    padding: 2px 7px;
    font-size: 12px;
}

/* ---------- CHAT PANEL ---------- */

.chat-panel {
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
    overflow: hidden;
    background: #efeae2;
}

.chat-header {
    flex: 0 0 auto;
    height: 64px;
    padding: 10px 18px;
    background: #f0f2f5;
    border-bottom: 1px solid #d1d5db;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 20;
}

.chat-header h1 {
    margin: 0;
    font-size: 17px;
}

.chat-header p {
    margin: 3px 0 0;
    color: #667781;
    font-size: 13px;
}

.chat-header button {
    background: #075e54;
    color: #ffffff;
    border: 0;
    border-radius: 999px;
    padding: 9px 15px;
    cursor: pointer;
    font-weight: 700;
}

/* ---------- MESSAGE AREA ---------- */

.message-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 4%;
    background: #efeae2;
}

.message-list::-webkit-scrollbar {
    width: 6px;
}

.message-list::-webkit-scrollbar-track {
    background: transparent;
}

.message-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, .15);
    border-radius: 20px;
}

.message-row {
    display: flex;
    width: 100%;
    margin-bottom: 7px;
}

.message-row.inbound {
    justify-content: flex-start;
}

.message-row.outbound {
    justify-content: flex-end;
}

/* ---------- MESSAGE BUBBLES ---------- */

.message-bubble {
    position: relative;
    max-width: 78%;
    padding: 7px 11px;
    font-size: 14px;
    line-height: 1.42;
    border-radius: 8px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
    word-break: break-word;
    white-space: normal;
}

.message-row.inbound .message-bubble {
    background: #ffffff;
    border-top-left-radius: 2px;
}

.message-row.outbound .message-bubble {
    background: #d9fdd3;
    border-top-right-radius: 2px;
}

.message-bubble > div {
    margin: 0;
    padding: 0;
    font-size: 14px;
    line-height: 1.42;
    white-space: pre-wrap;
}

.message-time {
    display: block;
    margin-top: 3px;
    text-align: right;
    font-size: 11px;
    line-height: 1;
    color: #667781;
}

/* ---------- MEDIA ---------- */

.message-bubble a {
    display: block;
    margin: 0;
    padding: 0;
    line-height: 0;
}

.chat-image-preview {
    display: block;
    max-width: 300px;
    max-height: 300px;
    border-radius: 7px;
    margin: 0 0 5px 0;
    padding: 0;
    object-fit: cover;
}

.chat-file-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border-radius: 7px;
    background: rgba(0, 0, 0, .05);
    color: #0a66c2;
    text-decoration: none;
    font-size: 13px;
    line-height: 1.2;
    margin-bottom: 5px;
}

.chat-file-link:hover {
    background: rgba(0, 0, 0, .08);
}

/* ---------- REPLY BOX ---------- */

.reply-box {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f0f2f5;
    border-top: 1px solid #d8dfe3;
    z-index: 20;
}

.reply-box textarea {
    flex: 1;
    resize: none;
    min-height: 42px;
    max-height: 120px;
    padding: 10px 12px;
    border: none;
    border-radius: 20px;
    background: #ffffff;
    outline: none;
    font-size: 14px;
    line-height: 1.35;
}

.reply-box button {
    border: none;
    padding: 10px 18px;
    border-radius: 20px;
    cursor: pointer;
    background: #00a884;
    color: #ffffff;
    font-weight: 600;
}

.reply-box button:hover {
    background: #00916f;
}

/* ---------- STATES ---------- */

.loading,
.empty-state {
    padding: 20px;
    color: #667781;
}

.loading {
    text-align: center;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: 14px;
}

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

@media (max-width: 800px) {
    .chat-app {
        grid-template-columns: 1fr;
        grid-template-rows: 42vh 58vh;
    }

    .chat-sidebar {
        height: 42vh;
    }

    .chat-panel {
        height: 58vh;
    }

    .message-list {
        padding: 10px 12px;
    }

    .message-bubble {
        max-width: 86%;
        padding: 7px 10px;
    }

    .chat-image-preview {
        max-width: 240px;
        max-height: 240px;
    }
}

/* ---------- LOGIN PAGE ---------- */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e5ddd5;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 18px 60px rgba(0,0,0,.12);
    overflow: hidden;
}

.login-brand {
    background: #075e54;
    color: #ffffff;
    padding: 24px;
}

.login-brand strong {
    display: block;
    font-size: 22px;
}

.login-brand span {
    display: block;
    margin-top: 5px;
    color: #d1fae5;
    font-size: 14px;
}

.login-form {
    padding: 24px;
}

.login-form label {
    display: block;
    margin-bottom: 16px;
    font-size: 13px;
    color: #374151;
    font-weight: 700;
}

.login-form input {
    width: 100%;
    margin-top: 7px;
    padding: 12px 13px;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    outline: none;
    font-size: 15px;
}

.login-form input:focus {
    border-color: #00a884;
}

.login-form button {
    width: 100%;
    border: 0;
    border-radius: 12px;
    padding: 13px;
    background: #00a884;
    color: #ffffff;
    font-weight: 700;
    cursor: pointer;
}

.login-form button:disabled {
    opacity: .65;
    cursor: not-allowed;
}

.login-message {
    margin: 14px 0 0;
    color: #dc2626;
    font-size: 13px;
    text-align: center;
}

.conversation-agent {
    margin-top: 4px;
    font-size: 11px;
    color: #00a884;
    font-weight: 700;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header-actions select {
    min-width: 190px;
    padding: 9px 12px;
    border: 0;
    border-radius: 999px;
    background: #ffffff;
    outline: none;
    color: #111827;
    font-size: 13px;
}

@media (max-width: 800px) {
    .chat-header-actions select {
        min-width: 130px;
        max-width: 150px;
    }
}

.chat-filter {
    display: grid;
    gap: 8px;
}

.chat-filter select {
    display: block;
}

.reply-box select {
    max-width: 170px;
    min-width: 140px;
    padding: 10px 12px;
    border: none;
    border-radius: 20px;
    background: #ffffff;
    outline: none;
    font-size: 13px;
}

@media (max-width: 800px) {
    .reply-box select {
        max-width: 120px;
        min-width: 110px;
    }
}

/* Keep last message visible above reply box */
.message-list {
    scroll-padding-bottom: 90px;
    padding-bottom: 90px;
}

.chat-location-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(0, 168, 132, .12);
    color: #075e54;
    text-decoration: none;
    font-weight: 700;
    font-size: 13px;
    line-height: 1.2;
    margin-bottom: 5px;
}

.chat-location-link:hover {
    background: rgba(0, 168, 132, .18);
}

.agent-mini-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #054d44;
    color: #ffffff;
}

.agent-mini-profile img {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    background: #ffffff;
}

.agent-mini-profile strong {
    display: block;
    font-size: 13px;
}

.agent-mini-profile span {
    display: block;
    font-size: 11px;
    color: #d1fae5;
}

.agent-mini-profile a {
    margin-left: auto;
    color: #ffffff;
    font-size: 12px;
    text-decoration: none;
    font-weight: 700;
}

.customer-panel {
    flex: 0 0 auto;
    background: #f8fafc;
    border-top: 1px solid #d8dfe3;
    padding: 10px 12px;
}

.customer-panel-header {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.customer-panel-header strong {
    font-size: 13px;
    color: #111827;
}

.customer-panel-header span {
    font-size: 11px;
    color: #667781;
}

#internalNotes {
    width: 100%;
    min-height: 70px;
    max-height: 120px;
    resize: vertical;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 9px 10px;
    font-size: 13px;
    outline: none;
}

#saveNotesBtn {
    margin-top: 7px;
    border: 0;
    border-radius: 999px;
    padding: 8px 14px;
    background: #075e54;
    color: #ffffff;
    font-weight: 700;
    cursor: pointer;
}

#notesSaveStatus {
    margin-left: 8px;
    color: #00a884;
    font-size: 12px;
}

#conversationSearch {
    width: 100%;
    padding: 11px 12px;
    border-radius: 10px;
    border: 0;
    background: #ffffff;
    outline: none;
    font-size: 14px;
}

#conversationSearch:focus {
    box-shadow: 0 0 0 2px rgba(0, 168, 132, .18);
}


.attach-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
    flex: 0 0 auto;
}

.attach-btn input {
    display: none;
}

.attach-btn:hover {
    background: #e9edef;
}


.reply-file-preview {
    max-width: 260px;
    min-width: 180px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #ffffff;
    border-radius: 12px;
    padding: 6px 8px;
    border: 1px solid #d8dfe3;
}

.reply-file-preview[hidden] {
    display: none;
}

.reply-file-preview img {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 8px;
}

.reply-file-preview strong {
    display: block;
    max-width: 145px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 12px;
}

.reply-file-preview small {
    display: block;
    color: #667781;
    font-size: 11px;
}

.reply-file-preview button {
    width: 24px;
    height: 24px;
    padding: 0;
    border-radius: 50%;
    background: #e53935;
    color: #fff;
    font-weight: 700;
}

.file-preview-icon {
    font-size: 26px;
}


.chat-file-icon {
    font-size: 22px;
    line-height: 1;
}

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

.chat-file-info strong {
    max-width: 220px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #0a66c2;
    font-size: 13px;
    line-height: 1.2;
}

.chat-file-info small {
    color: #667781;
    font-size: 11px;
    line-height: 1.2;
}


.upload-progress {
    display: none;
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 4px;
    height: 4px;
    background: #e9edef;
    border-radius: 999px;
    overflow: hidden;
}

.upload-progress-bar {
    display: block;
    width: 0%;
    height: 100%;
    background: #00a884;
    transition: width .15s ease;
}

.upload-progress-label {
    display: none;
    font-size: 10px;
    color: #00a884;
}

.reply-file-preview {
    position: relative;
    padding-bottom: 12px;
}

.reply-file-preview.is-uploading .upload-progress {
    display: block;
}

.reply-file-preview.is-uploading .upload-progress-label {
    display: block;
}


.record-audio-btn {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: #ffffff;
    cursor: pointer;
    font-size: 20px;
    flex: 0 0 auto;
}

.record-audio-btn:hover {
    background: #e9edef;
}

.record-audio-btn.recording {
    background: #e53935;
    color: #ffffff;
    animation: pulse-recording 1s infinite;
}

@keyframes pulse-recording {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.audio-preview-box {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #ffffff;
    border: 1px solid #d8dfe3;
    border-radius: 20px;
    padding: 4px 6px;
}

.audio-preview-box[hidden] {
    display: none;
}

.audio-preview-box audio {
    width: 210px;
    height: 32px;
}

.audio-preview-box button {
    width: 24px;
    height: 24px;
    padding: 0;
    border-radius: 50%;
    background: #e53935;
    color: #fff;
    font-weight: 700;
}


.reply-context-box {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 8px 14px;
    border-top: 1px solid #d8dfe3;
    background: #f0f2f5;
}

.reply-context-box[hidden] {
    display: none;
}

.reply-context-content {
    flex: 1;
    min-width: 0;
    padding: 7px 10px;
    border-left: 4px solid #00a884;
    border-radius: 5px;
    background: #ffffff;
}

.reply-context-content strong,
.reply-context-content span {
    display: block;
}

.reply-context-content strong {
    margin-bottom: 2px;
    color: #008069;
    font-size: 12px;
}

.reply-context-content span {
    overflow: hidden;
    color: #667781;
    font-size: 12px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.reply-context-box > button {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #667781;
    cursor: pointer;
    font-size: 22px;
}

.reply-context-box > button:hover {
    background: rgba(0, 0, 0, .06);
}

.quoted-message {
    display: block;
    margin: 0 0 6px;
    padding: 6px 8px;
    border-left: 4px solid #00a884;
    border-radius: 5px;
    background: rgba(0, 0, 0, .05);
}

.quoted-message strong,
.quoted-message span {
    display: block;
}

.quoted-message strong {
    margin-bottom: 2px;
    color: #008069;
    font-size: 11px;
}

.quoted-message span {
    max-width: 260px;
    overflow: hidden;
    color: #667781;
    font-size: 12px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.message-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.message-reply-btn {
    border: none;
    padding: 2px 5px;
    background: transparent;
    color: #667781;
    cursor: pointer;
    font-size: 11px;
    line-height: 1.2;
}

.message-reply-btn:hover {
    color: #008069;
    text-decoration: underline;
}


.message-list-wrapper {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    overflow: hidden;
}

.message-list-wrapper .message-list {
    flex: 1 1 auto;
    min-height: 0;
}

.scroll-to-bottom-btn {
    position: absolute;
    right: 18px;
    bottom: 18px;
    z-index: 30;
    width: 42px;
    height: 42px;
    border: 1px solid #d8dfe3;
    border-radius: 50%;
    background: #ffffff;
    color: #54656f;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
}

.scroll-to-bottom-btn[hidden] {
    display: none;
}

.scroll-to-bottom-btn:hover {
    background: #f0f2f5;
    color: #008069;
}

.scroll-to-bottom-btn span {
    position: absolute;
    top: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    background: #00a884;
}

.scroll-to-bottom-btn span[hidden] {
    display: none;
}
