/**
 * Complete Simple Modern Chat CSS
 * Version 3.0.0 - With fixed height, translation support, and all fixes
 */
@media(min-width:650px){
.simple-modern-chat-container {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-width: 400px;
    height: 400px; /* FIXED HEIGHT - Better default for desktop */
    margin: 0 auto;
    border: 1px solid #e1e5e9;
}
}

.simple-modern-chat-container {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-width: 400px;
    height: 400px; /* FIXED HEIGHT - Better default for desktop */
    margin: 0 auto;
    border: 1px solid #e1e5e9;
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.vendor-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.vendor-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    color: white;
}

.vendor-info {
    flex: 1;
}

.vendor-info h4 {
    font-size: 10px;
    font-weight: 600;
    margin: 0 0 4px 0;
}

.vendor-store-name {
    font-size: 9px;
    font-weight: 300;
    opacity: 0.85;
    margin: 0 0 4px 0;
    line-height: 0.5;
}

.vendor-status {
    font-size: 9px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    flex-shrink: 0;
    transition: background 0.3s ease;
}

.status-dot.online {
    background: #10b981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.chat-actions {
    display: flex;
    gap: 8px;
}

.minimize-btn,
.close-btn,
.end-conversation-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
}

.minimize-btn:hover,
.close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.end-conversation-btn:hover {
    background: rgba(239, 68, 68, 0.8);
    transform: scale(1.1);
}

/* Messages Area - FIXED HEIGHT */
.messages-area {
    flex: 1;
    min-height: 0; /* Important for flex-based scrolling */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: linear-gradient(to bottom, #f8fafc, #e2e8f0);
}

.messages-container {
    flex: 1;
    min-height: 0; /* Important for flex-based scrolling */
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.welcome-message {
    background: white;
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.welcome-message p {
    margin: 0;
    color: #374151;
    font-size: 14px;
}

.message {
    display: flex;
    max-width: 80%;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.received {
    align-self: flex-start;
}

.message.system {
    align-self: center;
    max-width: 90%;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

.message.received .message-bubble {
    background: #ffffff;
    color: #1f2937;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.08);
    border: 1px solid #e5e7eb;
}

.message.sent .message-bubble {
    /* Warm indigo → vivid brand: high contrast, clearly readable */
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.30);
    /* Ensure text never disappears on any display */
    -webkit-font-smoothing: antialiased;
}

.message.system .message-bubble {
    background: #f3f4f6;
    color: #6b7280;
    text-align: center;
    font-size: 13px;
    font-style: italic;
    border-radius: 12px;
    padding: 8px 16px;
}

.message-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
    align-self: flex-end;
}

.message.sending .message-bubble {
    opacity: 0.7;
}

.message.failed .message-bubble {
    opacity: 0.5;
    border: 1px solid #ef4444;
}

.attachment-link {
    color: inherit;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.05);
}

.message.sent .attachment-link {
    background: rgba(255, 255, 255, 0.2);
}

.attachment-link:hover {
    text-decoration: underline;
}

/* Typing Indicator */
.typing-indicator {
    padding: 8px 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    flex-shrink: 0;
}

.typing-indicator span:not(.typing-text) {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

.typing-text {
    font-size: 12px;
    color: #64748b;
    font-style: italic;
}

/* ── Input Area — Modern Clean Layout ─────────────────────────── */
.input-area {
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    padding: 12px 16px;
    flex-shrink: 0;
    /* Ensure input area stays above scroll content on iOS */
    position: relative;
    z-index: 2;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f3f4f6;
    border: 1.5px solid #e5e7eb;
    border-radius: 24px;
    padding: 6px 6px 6px 14px;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
    min-height: 48px;
}

.input-wrapper:focus-within {
    border-color: #6366f1;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.attachment-btn {
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
    transition: background 0.2s ease;
    flex-shrink: 0;
    align-self: flex-end;
    margin-bottom: 4px;
    opacity: 0.65;
}

.attachment-btn:hover {
    background: rgba(99, 102, 241, 0.10);
    opacity: 1;
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    line-height: 1.5;
    outline: none;
    padding: 8px 0;
    font-family: inherit;
    color: #111827;
    /* Allow the textarea to expand up to ~4 lines */
    max-height: 96px;
    overflow-y: auto;
    resize: none;
    scrollbar-width: thin;
}

#message-input::placeholder {
    color: #9ca3af;
}

/* Send button — circular icon button, no text pill */
.send-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-end;
    transition: background 0.18s ease, transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.35);
}

.send-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #4f46e5, #3730a3);
    transform: scale(1.06);
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.45);
}

.send-btn:active:not(:disabled) {
    transform: scale(0.96);
}

.send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    background: #9ca3af;
}

/* Hide text labels, only show SVG icon */
.send-btn .send-text,
.send-btn .send-loading { display: none !important; }

.send-btn svg {
    width: 16px;
    height: 16px;
    display: block;
    fill: #ffffff;
    stroke: none;
}

/* Fallback arrow icon via pseudo-element if no SVG injected */
.send-btn:not(:has(svg))::after {
    content: '➤';
    font-size: 14px;
    color: #fff;
    line-height: 1;
}

.send-btn.loading .send-text {
    display: none;
}

.send-btn.loading .send-loading {
    display: inline !important;
}

/* Conversation Ended State */
.conversation-ended-banner {
    background: #fef2f2;
    color: #dc2626;
    padding: 12px 20px;
    text-align: center;
    font-size: 14px;
    border-bottom: 1px solid #fecaca;
    font-weight: 500;
    flex-shrink: 0;
}

.conversation-ended .messages-area {
    opacity: 0.7;
}

.conversation-ended .input-area {
    opacity: 0.5;
    pointer-events: none;
}

/* Restart Conversation Area */
.restart-conversation-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e5e7eb;
    text-align: center;
    flex-shrink: 0;
}

.restart-conversation-btn {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 22px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    width: 100%;
    transition: all 0.2s ease;
    font-family: inherit;
}

.restart-conversation-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    background: linear-gradient(135deg, #059669, #047857);
}

.restart-conversation-btn:active {
    transform: translateY(0);
}

/* Hide restart button when conversation is active */
.simple-modern-chat-container:not(.conversation-ended) .restart-conversation-area {
    display: none;
}

/* Error States */
.chat-error,
.chat-login-required,
.chat-disabled {
    padding: 20px;
    text-align: center;
    border-radius: 8px;
    margin: 20px 0;
}

.chat-error,
.chat-disabled {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.chat-login-required {
    background: #f3f4f6;
    color: #1f2937;
    border: 1px solid #d1d5db;
}

.chat-login-required a {
    color: #4f46e5;
    text-decoration: none;
    font-weight: 600;
}

.chat-login-required a:hover {
    text-decoration: underline;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .simple-modern-chat-container {
        max-width: 100%;
        height: 60vh; /* Exactly half viewport height on mobile */
        max-height: 60vh; /* Ensure it doesn't exceed half screen */
        min-height: 400px; /* Minimum usable height for small screens */
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    .chat-header {
        padding: 8px 16px;
    }
    
    .vendor-avatar {
        width: 36px;
        height: 36px;
    }
    
    .vendor-info h4 {
        font-size: 15px;
    }
    
    .vendor-store-name {
        font-size: 10px;
    }
    
    .vendor-status {
        font-size: 9px;
    }
    
    .messages-container {
        padding: 16px;
    }
    
    .input-area {
        padding: 12px 16px;
    }
    
    .message-bubble {
        font-size: 13px;
        padding: 10px 14px;
    }
    
    .end-conversation-btn {
        width: 20px;
        height: 20px;
    }
    
    .conversation-ended-banner {
        font-size: 13px;
        padding: 10px 16px;
    }
    
    .restart-conversation-area {
        padding: 12px 16px;
    }
    
    .restart-conversation-btn {
        padding: 10px 20px;
        font-size: 13px;
    }
}

/* Tablet Responsive */
@media (min-width: 481px) and (max-width: 768px) {
    .simple-modern-chat-container {
        max-width: 500px;
        height: 650px;
    }
}

/* Large Desktop */
@media (min-width: 1200px) {
    .simple-modern-chat-container {
        max-width: 450px;
        height: 700px;
    }
}

/* Print Styles */
@media print {
    .simple-modern-chat-container {
        height: auto;
        box-shadow: none;
    }
    
    .input-area,
    .restart-conversation-area,
    .chat-actions,
    .typing-indicator {
        display: none;
    }
    
    .messages-container {
        overflow: visible;
        height: auto;
    }
}