/* Chat Widget Styles */

.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 3000;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* When scroll-to-top button is visible, shift left to avoid overlap */
.chat-widget.with-scroll-btn {
    right: 90px; /* 46px button + ~14px gap on each side */
}

/* Chat Button */
.chat-button {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary-color, #00205b), var(--primary-light, #3b82f6));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.3);
    transition: all 0.3s ease;
    position: relative;
}

.chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(37, 99, 235, 0.4);
}

.chat-button i {
    color: white;
    font-size: 1.5rem;
    transition: all 0.3s ease;
}

.chat-button.active i {
    transform: rotate(180deg);
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--danger-color, #ef4444);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Chat Window */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 500px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.8) translateY(20px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border-color, #e5e7eb);
    /* resize: both; */
    min-width: 300px;
    min-height: 400px;
    max-width: 600px;
    max-height: 80vh;
}

.chat-window.show {
    display: flex;
    transform: scale(1) translateY(0);
    opacity: 1;
}

.chat-window.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    border-radius: 0;
    z-index: 99999;
    background: white;
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, var(--primary-color, #00205b), var(--primary-light, #3b82f6));
    color: white;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.chat-avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.chat-title h6 {
    margin: 0;
    font-weight: 600;
    color: white;
    font-size: 1.5rem;
}

.online-status {
    color: rgba(255, 255, 255, 0.8);
    font-size: 1.25rem;
}

.chat-controls {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    padding: 0.25rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: #f8fafc;
}

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

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

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

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

.message {
    display: flex;
    gap: 0.75rem;
    max-width: 85%;
    animation: messageSlideIn 0.3s ease;
    align-items: flex-start;
}

.message.user-message {
    margin-left: auto;
    flex-direction: row-reverse;
}

.message-avatar {
    flex-shrink: 0;
}

/* Center assistant/bot avatar vertically relative to bubble */
.assistant-message .message-avatar,
.bot-message .message-avatar { align-self: center; }

.message-avatar img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.user-message .message-content {
    align-items: flex-end;
}

.message-bubble {
    background: white;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border-color, #e5e7eb);
    word-wrap: break-word;
    line-height: 1.4;
    color: var(--text-color, #0f172a);
    font-size: 1.25rem;
}

.user-message .message-bubble {
    background: linear-gradient(135deg, var(--primary-color, #00205b), var(--primary-light, #3b82f6));
    color: white;
    border: none;
}

.message-time {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-light, #64748b);
    padding: 0 0.5rem;
}

.user-message .message-time {
    color: rgba(255, 255, 255, 0.9);
}

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

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1rem;
    margin-bottom: 1rem;
}

.typing-dots {
    background: white;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border-color, #e5e7eb);
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-light, #64748b);
    border-radius: 50%;
    animation: typingDot 1.4s infinite ease-in-out;
}

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

@keyframes typingDot {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Chat Input */
.chat-input {
    padding: 1rem;
    background: white;
    border-top: 1px solid var(--border-color, #e5e7eb);
    flex-shrink: 0;
}

.chat-input .input-group {
    background: var(--light-bg, #f8fafc);
    border-radius: 12px;
    border: 1px solid var(--border-color, #e5e7eb);
    overflow: hidden;
    transition: all 0.2s ease;
    display: flex;
    align-items: stretch;
    gap: 0;
    white-space: nowrap;
    flex-wrap: nowrap;
    flex-direction: row;
}

.chat-input .input-group:focus-within {
    border-color: var(--primary-color, #00205b);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chat-input .form-control {
    border: none;
    background: transparent;
    padding: 0.9rem 1.1rem;
    font-size: 1.25rem;
    flex: 1 1 auto;
    width: 0;
}

.chat-input .form-control::placeholder {
    font-size: 1rem;
    color: var(--text-light, #64748b);
}

.chat-input .form-control:focus {
    box-shadow: none;
    background: transparent;
}

.chat-input .btn {
    border: none;
    background: var(--primary-color, #00205b);
    color: white;
    padding: 0.75rem 1rem;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: auto !important;
    white-space: nowrap;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.chat-input .btn:hover {
    background: var(--primary-dark, #1e40af);
}

.chat-input .btn:disabled {
    background: var(--text-light, #9ca3af);
    cursor: not-allowed;
}

/* Resize Handle */
.resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    background: linear-gradient(-45deg, transparent 30%, var(--border-color, #e5e7eb) 30%, var(--border-color, #e5e7eb) 40%, transparent 40%, transparent 60%, var(--border-color, #e5e7eb) 60%, var(--border-color, #e5e7eb) 70%, transparent 70%);
    cursor: nw-resize;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

/* .resize-handle:hover { opacity: 1; } */

/* Responsive Design */
@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 40px);
        right: 0;
left: initial;
        max-width: none;
    }
    .chat-widget {
        right: 15px;
        bottom: 15px;
    }
    .chat-button { width: 55px; height: 55px; }
    .chat-button i { font-size: 1.3rem; }
}

/* Fullscreen Styles */
.chat-window.fullscreen .chat-header {
    padding: 1.5rem 2rem;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    min-height: 80px;
    display: flex;
    align-items: center;
}

.chat-window.fullscreen .chat-controls {
    margin-left: auto;
    display: flex;
    gap: 1rem;
}

.chat-window.fullscreen .btn-icon {
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.chat-window.fullscreen .btn-icon:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.chat-window.fullscreen .chat-messages { padding: 2rem; font-size: 1.5rem; padding-top: 1rem; }
.chat-window.fullscreen .chat-input { padding: 1.5rem 2rem; position: sticky; bottom: 0; background: white; box-shadow: 0 -2px 8px rgba(0,0,0,0.1); }
.chat-window.fullscreen .message-bubble { padding: 1rem 1.5rem; font-size: 1.5rem; }
.chat-window.fullscreen .message-time { font-size: 1.5rem; }
.chat-window.fullscreen .chat-input .form-control { font-size: 1.5rem; }
.chat-window.fullscreen .resize-handle { display: none; }

/* Fallback fullscreen exit button */
.chat-fullscreen-exit {
    display: none;
    position: absolute;
    bottom: 16px;
    left: 16px;
    z-index: 1001;
}
.chat-fullscreen-exit.show { display: flex; }

/* Ensure header and controls keep contrast within widget */
.chat-widget .chat-header {
    background: linear-gradient(135deg, var(--primary-color, #00205b), var(--primary-light, #3b82f6)) !important;
    color: #fff !important;
}
.chat-widget .chat-controls .btn-icon,
.chat-widget .chat-header .btn-icon,
.chat-widget .chat-title h6,
.chat-widget .online-status { color: #fff !important; }
.chat-widget .btn-icon:hover { color: #fff !important; }

/* Fullscreen overlay and hints */
.fullscreen-overlay { position: fixed; top:0; left:0; right:0; bottom:0; background: rgba(0,0,0,0.8); z-index: 99998; opacity:0; pointer-events:none; transition: opacity 0.3s ease; }
.fullscreen-overlay.show { opacity:1; pointer-events:auto; }
.fullscreen-hint { position: absolute; top:20px; right:20px; background: rgba(0,0,0,0.8); color:white; padding:0.75rem 1rem; border-radius:8px; font-size:0.875rem; z-index:100000; animation: fadeInOut 4s ease-in-out; pointer-events:none; }

.navbar{ z-index: 2000; }
@keyframes fadeInOut { 0%, 100% { opacity: 0; } 10%, 90% { opacity: 1; } }

/* Mobile fullscreen improvements */
@media (max-width: 768px) {
    .chat-window.fullscreen .chat-header { padding: 1rem; min-height: 70px; }
    .chat-window.fullscreen .btn-icon { width: 48px; height: 48px; font-size: 1.3rem; }
    .chat-window.fullscreen .chat-controls { gap: 0.75rem; }
    .fullscreen-hint { top: 10px; right: 10px; left: 10px; text-align: center; font-size: 0.8rem; }
}

/* Animation for fullscreen toggle */
.chat-window.entering-fullscreen { animation: expandToFullscreen 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.chat-window.exiting-fullscreen { animation: contractFromFullscreen 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
@keyframes expandToFullscreen { from { transform: scale(1); border-radius: 16px; } to { transform: scale(1); border-radius: 0; } }
@keyframes contractFromFullscreen { from { transform: scale(1); border-radius: 0; } to { transform: scale(1); border-radius: 16px; } }
