/* ===================================
   FINAL PERFECT CHAT WIDGET STYLES
   =================================== */

.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Poppins', sans-serif;
}

/* Chat Toggle Button */
.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.chat-toggle-btn .material-icons-sharp {
    font-size: 28px;
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #f44336;
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}

.chat-badge.hidden {
    display: none;
}

/* Chat Window - FIXED HEIGHT */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 550px; /* FIXED HEIGHT */
    max-height: calc(100vh - 120px); /* Never taller than viewport */
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
    transform-origin: bottom right;
}

.chat-window.hidden {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
}

.chat-window:not(.hidden) {
    opacity: 1;
    transform: scale(1);
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 1rem 1.2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.chat-header p {
    margin: 0.3rem 0 0 0;
    font-size: 0.85rem;
    opacity: 0.9;
}

.chat-header-info {
    flex: 1;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.2rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4CAF50;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chat-title {
    font-size: 1rem;
    font-weight: 600;
}

.chat-subtitle {
    font-size: 0.8rem;
    opacity: 0.9;
}

.chat-header-actions {
    display: flex;
    gap: 0.5rem;
}

.chat-close-btn,
.chat-end-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    flex-shrink: 0;
}

.chat-close-btn:hover,
.chat-end-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Pre-Chat Form */
.pre-chat-form {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.pre-chat-content {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.form-intro {
    margin-bottom: 1.5rem;
    text-align: center;
}

.form-intro h4 {
    margin: 0 0 0.5rem 0;
    color: #333;
    font-size: 1.2rem;
}

.form-intro p {
    margin: 0;
    color: #666;
    font-size: 0.9rem;
    line-height: 1.4;
}

.form-group {
    margin-bottom: 1.2rem;
}

.form-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: #333;
    margin-bottom: 0.4rem;
}

.form-group label .material-icons-sharp {
    font-size: 1.1rem;
    color: #667eea;
}

.form-group input {
    width: 100%;
    padding: 0.7rem 1rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: 'Poppins', sans-serif;
    transition: 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.start-chat-btn {
    width: 100%;
    padding: 0.9rem;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: 0.2s;
    margin-top: 0.5rem;
}

.start-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

/* Main Chat */
.main-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.main-chat.hidden {
    display: none;
}

/* Chat Messages - SCROLLABLE */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #f5f5f5;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* Welcome Message - CRISP */
.chat-welcome-msg {
    text-align: center;
    padding: 2rem 1rem 1rem 1rem;
}

.welcome-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem auto;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.welcome-avatar .material-icons-sharp {
    font-size: 2rem;
    color: white;
}

.chat-welcome-msg h4 {
    margin: 0 0 0.5rem 0;
    color: #333;
    font-size: 1.1rem;
}

.chat-welcome-msg p {
    margin: 0;
    color: #666;
    font-size: 0.9rem;
}

/* Message Bubbles */
.chat-message {
    margin-bottom: 1rem;
    display: flex;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    justify-content: flex-end;
}

.chat-message.admin {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 75%;
    padding: 0.75rem 1rem;
    border-radius: 16px;
    word-wrap: break-word;
    white-space: pre-wrap; /* PRESERVE LINE BREAKS */
}

.chat-message.user .message-bubble {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.admin .message-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 0.3rem;
}

.chat-message.user .message-time {
    text-align: right;
}

.chat-message.admin .message-time {
    text-align: left;
}

/* Typing Indicator */
.typing-indicator {
    padding: 0.75rem 1rem;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.typing-indicator.hidden {
    display: none;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

.typing-text {
    font-size: 0.8rem;
    color: #666;
    margin-left: 0.5rem;
}

/* Chat Input - TEXTAREA */
.chat-input-container {
    display: flex;
    padding: 1rem;
    background: white;
    border-top: 1px solid #e0e0e0;
    gap: 0.75rem;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
    font-family: 'Poppins', sans-serif;
    outline: none;
    transition: 0.2s;
    resize: none;
    max-height: 120px;
    min-height: 40px;
    overflow-y: auto;
}

.chat-input:focus {
    border-color: #667eea;
}

.chat-send-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .chat-window {
        width: calc(100vw - 40px);
        height: calc(100vh - 160px);
    }
}

@media (max-width: 480px) {
    .chat-widget {
        bottom: 10px;
        right: 10px;
    }
    
    .chat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 80px);
        bottom: 70px;
    }
    
    .chat-toggle-btn {
        width: 50px;
        height: 50px;
    }
}

/* Dark Mode */
body.dark-mode .chat-window {
    background: var(--card-bg);
}

body.dark-mode .chat-messages {
    background: var(--bg);
}

body.dark-mode .chat-message.admin .message-bubble {
    background: var(--card-bg);
    color: var(--text);
}

body.dark-mode .chat-input-container {
    background: var(--card-bg);
    border-top-color: var(--border);
}

body.dark-mode .chat-input {
    background: var(--bg);
    color: var(--text);
    border-color: var(--border);
}

body.dark-mode .form-group input {
    background: var(--bg);
    color: var(--text);
    border-color: var(--border);
}

body.dark-mode .form-intro h4,
body.dark-mode .form-group label,
body.dark-mode .chat-welcome-msg h4 {
    color: var(--text);
}

body.dark-mode .form-intro p,
body.dark-mode .chat-welcome-msg p {
    color: var(--text-muted);
}
















.chat-attach-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    color: #667eea;
    display: flex;
    align-items: center;
    transition: background 0.2s;
}
.chat-attach-btn:hover { background: #f0f0f0; }

/* Timestamp BELOW the bubble */
.chat-message { display: flex; flex-direction: column; margin-bottom: 1rem; }
.chat-message.admin { align-items: flex-end; }
.chat-message.user  { align-items: flex-start; }
.message-time { font-size: 0.72rem; color: #aaa; margin-top: 3px; }