/* ============================================
   PROFESSIONAL CHAT INTERFACE
   Modern, Clean Design for Customer & Vendor
   ============================================ */

:root {
    --chat-primary: #00a884;
    --chat-primary-dark: #008069;
    --chat-secondary: #f0f2f5;
    --chat-bg: #efeae2;
    --chat-sent: #d9fdd3;
    --chat-received: #ffffff;
    --chat-header: #f0f2f5;
    --chat-border: #e9edef;
    --chat-text: #111b21;
    --chat-text-secondary: #667781;
    --chat-hover: #f5f6f6;
    --chat-active: #e7f3f0;
    --sidebar-width: 380px;
    --header-height: 60px;
}

/* ============================================
   MAIN LAYOUT
   ============================================ */

body.chat-page {
    font-family: 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background-color: #d1d7db;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

.chat-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    background: white;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* ============================================
   CHAT LIST (LEFT SIDEBAR)
   ============================================ */

.chat-list {
    width: var(--sidebar-width);
    border-right: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    background: #fff;
    flex-shrink: 0;
}

.chat-list-header {
    height: var(--header-height);
    background: var(--chat-header);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--chat-border);
}

.chat-list-header h5 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--chat-text);
}

.chat-list-search {
    padding: 10px 15px;
    background: #fff;
    border-bottom: 1px solid var(--chat-border);
}

.chat-list-search input {
    width: 100%;
    padding: 10px 15px;
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.chat-list-search input:focus {
    border-color: var(--chat-primary);
}

.chat-list-items {
    overflow-y: auto;
    flex: 1;
    background: #fff;
}

.chat-list-items::-webkit-scrollbar {
    width: 6px;
}

.chat-list-items::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    cursor: pointer;
    border-bottom: 1px solid #f0f2f5;
    transition: background 0.15s ease;
    position: relative;
}

.chat-item:hover {
    background: var(--chat-hover);
}

.chat-item.active {
    background: var(--chat-active);
    border-left: 4px solid var(--chat-primary);
}

.chat-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    margin-right: 15px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--chat-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    color: var(--chat-primary);
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.chat-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.chat-name-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.chat-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--chat-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 12px;
    color: var(--chat-text-secondary);
    flex-shrink: 0;
    margin-left: 10px;
}

.chat-preview-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-preview {
    font-size: 14px;
    color: var(--chat-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chat-unread-badge {
    background: var(--chat-primary);
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 600;
    margin-left: 10px;
    flex-shrink: 0;
}

/* ============================================
   CHAT WINDOW (RIGHT PANEL)
   ============================================ */

.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    position: relative;
    overflow: hidden;
}

/* Doodle Background Pattern */
.chat-window::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><path d="M0 0h100v100H0z" fill="%23efeae2"/><path d="M20 20l5 5m10-5l5 5m10-5l5 5m10-5l5 5m10-5l5 5" stroke="%23d1d7db" stroke-width="0.5" fill="none"/></svg>');
    opacity: 0.4;
    z-index: 0;
}

.chat-header {
    height: var(--header-height);
    background: var(--chat-header);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--chat-border);
    z-index: 10;
    position: relative;
}

.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 15px;
    object-fit: cover;
    background: var(--chat-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: var(--chat-primary);
}

.chat-header-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--chat-text);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-status {
    font-size: 13px;
    color: var(--chat-text-secondary);
    margin: 0;
}

.chat-header-status.online {
    color: var(--chat-primary);
}

.chat-header-actions {
    display: flex;
    gap: 15px;
    align-items: center;
}

.chat-header-actions button {
    background: none;
    border: none;
    color: var(--chat-text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
    transition: color 0.2s;
}

.chat-header-actions button:hover {
    color: var(--chat-text);
}

/* ============================================
   MESSAGES AREA
   ============================================ */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1;
    position: relative;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* Date Divider */
.message-date-divider {
    text-align: center;
    margin: 15px 0;
    position: relative;
}

.message-date-divider span {
    background: #e1f4f3;
    color: var(--chat-text-secondary);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    display: inline-block;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Message Bubbles */
.message-bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 8px;
    word-wrap: break-word;
    position: relative;
    clear: both;
    margin-bottom: 2px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    animation: messageSlideIn 0.2s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-sent {
    background: var(--chat-sent);
    align-self: flex-end;
    margin-left: auto;
    border-radius: 8px;
}

.message-received {
    background: var(--chat-received);
    align-self: flex-start;
    margin-right: auto;
    border-radius: 8px;
}

.message-sender {
    font-size: 13px;
    font-weight: 600;
    color: var(--chat-primary);
    margin-bottom: 4px;
}

.message-text {
    font-size: 14.5px;
    line-height: 1.5;
    color: var(--chat-text);
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-image {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 5px;
    cursor: pointer;
    transition: transform 0.2s;
}

.message-image:hover {
    transform: scale(1.02);
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    margin-top: 4px;
}

.message-time {
    font-size: 11px;
    color: var(--chat-text-secondary);
}

.message-status {
    font-size: 14px;
    color: var(--chat-text-secondary);
}

.message-status.read {
    color: #53bdeb;
}

.message-status.delivered {
    color: var(--chat-text-secondary);
}

/* Reply Preview */
.message-reply-preview {
    background: rgba(0,0,0,0.05);
    border-left: 3px solid var(--chat-primary);
    padding: 6px 10px;
    margin-bottom: 6px;
    border-radius: 4px;
    font-size: 13px;
}

.message-reply-preview .reply-sender {
    font-weight: 600;
    color: var(--chat-primary);
    margin-bottom: 2px;
}

.message-reply-preview .reply-text {
    color: var(--chat-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   INPUT AREA
   ============================================ */

.chat-input-area {
    min-height: 62px;
    background: var(--chat-header);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-top: 1px solid var(--chat-border);
    z-index: 10;
    position: relative;
}

.chat-input-actions {
    display: flex;
    gap: 8px;
}

.chat-input-actions button {
    background: none;
    border: none;
    color: var(--chat-text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 5px;
    transition: color 0.2s;
}

.chat-input-actions button:hover {
    color: var(--chat-text);
}

.chat-input-wrapper {
    flex: 1;
    background: white;
    border-radius: 24px;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.chat-input-wrapper input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    color: var(--chat-text);
}

.chat-input-wrapper input::placeholder {
    color: var(--chat-text-secondary);
}

.chat-send-btn {
    background: var(--chat-primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: var(--chat-primary-dark);
}

.chat-send-btn:active {
    transform: scale(0.95);
}

.chat-send-btn i {
    font-size: 18px;
}

/* Reply Bar */
.reply-bar {
    background: #e7f3f0;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--chat-border);
}

.reply-bar-content {
    flex: 1;
}

.reply-bar-label {
    font-size: 12px;
    color: var(--chat-primary);
    font-weight: 600;
    margin-bottom: 2px;
}

.reply-bar-text {
    font-size: 14px;
    color: var(--chat-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reply-bar-close {
    background: none;
    border: none;
    color: var(--chat-text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
}

/* ============================================
   EMPTY STATE
   ============================================ */

.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--chat-bg);
    color: var(--chat-text-secondary);
    text-align: center;
    padding: 40px;
}

.chat-empty-state i {
    font-size: 80px;
    color: var(--chat-text-secondary);
    opacity: 0.3;
    margin-bottom: 20px;
}

.chat-empty-state h3 {
    font-size: 24px;
    color: var(--chat-text);
    margin-bottom: 10px;
}

.chat-empty-state p {
    font-size: 16px;
    color: var(--chat-text-secondary);
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .chat-container {
        flex-direction: column;
    }
    
    .chat-list {
        width: 100%;
        height: 100%;
    }
    
    .chat-list.hidden-mobile {
        display: none;
    }
    
    .chat-window {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 2000;
    }
    
    .chat-window.active {
        display: flex;
    }
    
    .chat-header {
        padding: 10px 15px;
    }
    
    .chat-back-btn {
        background: none;
        border: none;
        color: var(--chat-text);
        font-size: 24px;
        padding: 0;
        margin-right: 15px;
        cursor: pointer;
    }
    
    .chat-messages {
        padding: 15px 10px;
    }
    
    .message-bubble {
        max-width: 85%;
    }
    
    .chat-input-area {
        padding: 8px 10px;
    }
    
    .chat-input-wrapper {
        padding: 8px 15px;
    }
}

/* ============================================
   MESSAGE BUBBLE TEXT FIX - no word cutoff
   ============================================ */

.message-bubble {
    word-break: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    overflow: visible !important;
}

.message-bubble > div {
    word-break: break-word !important;
    overflow-wrap: break-word !important;
    white-space: pre-wrap !important;
}

/* WhatsApp-style input area stacks vertically */
.chat-input-area {
    flex-direction: column !important;
    align-items: stretch !important;
}

.chat-input-area > .d-flex {
    width: 100%;
}

/* Image preview bar in input */
#imagePreviewBar {
    width: 100%;
    box-sizing: border-box;
}

/* Ensure messages area fills available space */
.chat-messages {
    min-height: 0 !important;
    flex: 1 1 0 !important;
}


.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.slide-up {
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ============================================
   LOADING STATES
   ============================================ */

.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.chat-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--chat-secondary);
    border-top-color: var(--chat-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   TYPING INDICATOR
   ============================================ */

.typing-indicator {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background: white;
    border-radius: 18px;
    max-width: 70px;
    align-self: flex-start;
    margin-bottom: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chat-text-secondary);
    margin: 0 2px;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}
