/* AI Chatbot Floating Widget */

/* Floating Button */
.chatbot-toggle {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4e73df 0%, #224abe 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.3s ease;
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(78, 115, 223, 0.4);
}

.chatbot-toggle:active {
    transform: scale(0.95);
}

.chatbot-toggle .fa-robot {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Chat Window */
.chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 400px;
    height: 550px;
    min-width: 300px;
    min-height: 300px;
    max-width: 90vw;
    max-height: 90vh;
    resize: both;
    background-color: var(--bg-card);
    border: 1px solid var(--primary-color);
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    z-index: 999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
    animation: slideUp 0.3s ease-out;
}

/* Minimized State — !important needed to override inline height set by resize handle */
.chatbot-window.minimized {
    height: auto !important;
    min-height: 0 !important;
    resize: none;
}

.chatbot-window.minimized .chatbot-messages,
.chatbot-window.minimized .chatbot-input-container {
    display: none;
}

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

/* Chat Header */
.chatbot-header {
    background: linear-gradient(135deg, #4e73df 0%, #224abe 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #4e73df;
    position: relative; /* For drag handle positioning */
}

.chatbot-header-title {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chatbot-header-buttons {
    display: flex;
    gap: 4px;
    align-items: center;
}

.chatbot-setup-guide,
.chatbot-minimize,
.chatbot-close {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.chatbot-setup-guide:hover,
.chatbot-minimize:hover,
.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chatbot-setup-guide {
    font-size: 14px;
}

.chatbot-minimize {
    font-size: 16px; /* Slightly smaller minus icon */
}

.chatbot-close {
    font-size: 20px;
}

/* Messages Area */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: var(--bg-primary);
}

.chatbot-message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: fadeIn 0.3s ease-out;
}

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

.chatbot-message.user {
    align-self: flex-end;
}

.chatbot-message.assistant {
    align-self: flex-start;
}

.chatbot-message-content {
    padding: 12px 16px;
    border-radius: 12px;
    word-wrap: break-word;
    line-height: 1.5;
}

.chatbot-message.user .chatbot-message-content {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.chatbot-message.assistant .chatbot-message-content {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.chatbot-message-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    padding: 0 4px;
}

.chatbot-message.user .chatbot-message-time {
    text-align: right;
}

/* Typing Indicator */
.chatbot-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: fit-content;
}

.chatbot-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: typing 1.4s infinite;
}

.chatbot-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.7; }
    30% { transform: translateY(-10px); opacity: 1; }
}

/* Input Area */
.chatbot-input-container {
    padding: 16px;
    background-color: var(--bg-card);
    border-top: 1px solid var(--border-color);
}

.chatbot-input-wrapper {
    display: flex;
    gap: 4px;
    align-items: center;
}

.chatbot-input {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--input-text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.chatbot-input:focus {
    border-color: var(--primary-color);
}

.chatbot-input::placeholder {
    color: var(--text-secondary);
}

.chatbot-send {
    padding: 10px 14px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.chatbot-send:hover {
    background: var(--navbar-bg);
}

.chatbot-send:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
}

/* Context Badge */
.chatbot-context {
    font-size: 11px;
    color: var(--text-secondary);
    padding: 4px 12px;
    background: var(--bg-secondary);
    border-radius: 4px;
    margin-bottom: 8px;
    display: inline-block;
}

/* Scrollbar Styling */
.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--navbar-bg);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .chatbot-window {
        width: calc(100vw - 20px);
        right: 10px;
        bottom: 90px;
        height: 450px;
    }

    .chatbot-toggle {
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
}

/* Welcome Message */
.chatbot-welcome {
    text-align: center;
    color: var(--text-secondary);
    padding: 20px;
    font-size: 14px;
}

.chatbot-welcome-icon {
    font-size: 48px;
    color: var(--primary-color);
    margin-bottom: 12px;
}

.chatbot-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.chatbot-suggestion {
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    font-size: 13px;
    transition: all 0.2s;
}

.chatbot-suggestion:hover {
    background: var(--bg-card);
    border-color: var(--primary-color);
}

/* ============================================
   DRAGGABLE FUNCTIONALITY (PC/TABLET ONLY)
   ============================================ */

/* Only enable dragging on larger screens */
@media (min-width: 769px) {
    .chatbot-window.draggable .chatbot-header {
        cursor: grab;
        user-select: none;
    }

    .chatbot-window.dragging {
        cursor: grabbing;
        opacity: 0.9;
        transform: scale(1.02);
        box-shadow: 0 15px 35px rgba(0,0,0,0.3);
        z-index: 10000;
        transition: none; /* Disable transitions while dragging */
    }

    .chatbot-window.dragging .chatbot-header {
        cursor: grabbing;
    }

    /* Add drag handle visual indicator */
    .chatbot-header::before {
        content: "⋮⋮";
        position: absolute;
        left: 8px;
        top: 50%;
        transform: translateY(-50%);
        color: var(--text-secondary);
        font-size: 12px;
        opacity: 0.6;
        letter-spacing: 1px;
        pointer-events: none;
    }

    .chatbot-header:hover::before {
        opacity: 1;
        color: var(--primary-color);
    }
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .chatbot-header::before {
        display: none !important;
    }

    /* Adjust button sizes for mobile */
    .chatbot-setup-guide,
    .chatbot-minimize,
    .chatbot-close {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }

    /* Ensure minimized state works on mobile */
    .chatbot-window.minimized {
        height: auto;
    }
}

/* ============================================
   FILE ATTACHMENT STYLES
   ============================================ */

/* Attach (paperclip) button */
.chatbot-attach {
    padding: 8px 10px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chatbot-attach:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

/* File preview strip (above input) */
.chatbot-file-preview {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin: 0 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-primary);
}

.chatbot-file-preview.active {
    display: flex;
}

.chatbot-file-preview .file-thumb {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
}

.chatbot-file-preview .file-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 16px;
    flex-shrink: 0;
    background: var(--bg-primary);
}

.chatbot-file-preview .file-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.chatbot-file-preview .file-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chatbot-file-preview .file-size {
    color: var(--text-secondary);
    font-size: 11px;
}

.chatbot-file-preview .file-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
    border-radius: 4px;
    flex-shrink: 0;
}

.chatbot-file-preview .file-remove:hover {
    color: #dc3545;
    background: rgba(220, 53, 69, 0.1);
}

/* Large file warning */
.chatbot-file-preview .file-large-note {
    display: none;
    font-size: 10px;
    color: #e0a800;
}

.chatbot-file-preview.large-file .file-large-note {
    display: block;
}

/* File type icon colors */
.chatbot-file-preview .fa-file-pdf { color: #dc3545; }
.chatbot-file-preview .fa-file-csv { color: #28a745; }
.chatbot-file-preview .fa-file-excel { color: #28a745; }
.chatbot-file-preview .fa-file-alt { color: #6c757d; }

/* Drag overlay */
.chatbot-drag-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(78, 115, 223, 0.15);
    border: 2px dashed var(--primary-color);
    border-radius: 12px;
    z-index: 10;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary-color);
    pointer-events: none;
}

.chatbot-drag-overlay.active {
    display: flex;
}

/* File badge in user message bubbles */
.chatbot-file-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    opacity: 0.85;
    margin-bottom: 4px;
}

.chatbot-file-badge i {
    font-size: 12px;
}

/* ============================================
   VOICE INPUT STYLES
   ============================================ */

/* Mic button — matches paperclip styling */
.chatbot-mic {
    padding: 8px 10px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    flex-shrink: 0;
    touch-action: manipulation;  /* Prevent double-tap zoom, ensure fast taps */
    -webkit-tap-highlight-color: transparent;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;  /* Stay above pulsing box-shadow */
}

.chatbot-mic:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

/* Recording state */
.chatbot-mic.recording {
    color: #fff;
    background: #dc3545;
    border-color: #dc3545;
    animation: pulse-recording 1.5s infinite;
}

@keyframes pulse-recording {
    0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4); }
    70% { box-shadow: 0 0 0 8px rgba(220, 53, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}
