/* ==========================================================================
   MY PAYROLL — AI CHATBOT ASSISTANT
   Unified floating assistant across Level 1 (Employee), Level 2 (HR & Payroll),
   and Level 3 (Advanced Analytics).
   Zero jQuery. Scoped CSS matching mypayroll-theme.css tokens.
   ========================================================================== */

/* 1. Floating Action Trigger Button */
.ai-chatbot-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1050;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 50%, #4338ca 100%);
    color: #ffffff;
    border: none;
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.35), 0 2px 6px rgba(0, 0, 0, 0.12);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
}

.ai-chatbot-fab:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.45), 0 4px 10px rgba(0, 0, 0, 0.15);
}

.ai-chatbot-fab:active {
    transform: scale(0.96);
}

.ai-chatbot-fab .ai-fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background-color: #10b981;
    border: 2px solid #ffffff;
    border-radius: 50%;
    animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* 2. Chatbot Panel Container */
.ai-chatbot-panel {
    position: fixed;
    bottom: 92px;
    right: 24px;
    z-index: 1050;
    width: 440px;
    height: 620px;
    max-height: calc(100vh - 120px);
    max-width: calc(100vw - 32px);
    background-color: var(--bg-card, #ffffff);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 16px;
    box-shadow: 0 20px 45px -10px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.ai-chatbot-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Maximized / Expanded State */
.ai-chatbot-panel.maximized {
    width: 760px;
    height: 720px;
    max-height: calc(100vh - 80px);
}

/* Minimized State */
.ai-chatbot-panel.minimized {
    height: 56px;
    overflow: hidden;
}

.ai-chatbot-panel.minimized .ai-chat-body,
.ai-chatbot-panel.minimized .ai-chat-footer,
.ai-chatbot-panel.minimized .ai-history-drawer {
    display: none !important;
}

/* 3. Panel Header */
.ai-chat-header {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    color: #ffffff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ai-chat-header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.ai-chat-title-group h6 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-chat-title-group .ai-chat-status {
    font-size: 11px;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-chat-status-dot {
    width: 7px;
    height: 7px;
    background-color: #10b981;
    border-radius: 50%;
    display: inline-block;
}

.ai-role-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 20px;
    background-color: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
    border: 1px solid rgba(147, 197, 253, 0.3);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.ai-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-header-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}

.ai-header-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
}

/* 4. Slide-in History Drawer */
.ai-history-drawer {
    position: absolute;
    top: 56px;
    left: 0;
    width: 280px;
    bottom: 0;
    background-color: var(--bg-card, #ffffff);
    border-right: 1px solid var(--border-color, #e2e8f0);
    z-index: 20;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 6px 0 20px rgba(0, 0, 0, 0.08);
}

.ai-history-drawer.open {
    transform: translateX(0);
}

.ai-history-header {
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    background-color: var(--bg-subtle, #f8fafc);
}

.ai-history-header h6 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
}

.ai-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 12.5px;
    color: var(--text-primary, #0f172a);
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
    width: 100%;
    transition: background 0.15s;
}

.ai-history-item:hover {
    background-color: var(--bg-subtle, #f1f5f9);
}

.ai-history-item.active {
    background-color: var(--primary-light, #eff6ff);
    color: var(--primary, #2563eb);
    font-weight: 600;
}

.ai-history-item-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.ai-history-delete-btn {
    opacity: 0;
    color: #ef4444;
    background: transparent;
    border: none;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    transition: opacity 0.15s;
}

.ai-history-item:hover .ai-history-delete-btn {
    opacity: 1;
}

/* 5. Chat Messages Body */
.ai-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background-color: var(--bg-main, #f8fafc);
}

.ai-message {
    display: flex;
    gap: 10px;
    max-width: 90%;
    animation: fadeInMsg 0.2s ease-out;
}

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

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

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

.ai-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}

.ai-message-user .ai-message-avatar {
    background-color: var(--primary, #2563eb);
    color: #ffffff;
}

.ai-message-assistant .ai-message-avatar {
    background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
    color: #ffffff;
}

.ai-message-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
}

.ai-message-user .ai-message-bubble {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.ai-message-assistant .ai-message-bubble {
    background-color: var(--bg-card, #ffffff);
    color: var(--text-primary, #0f172a);
    border: 1px solid var(--border-color, #e2e8f0);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

/* Markdown styling inside bubbles */
.ai-message-bubble p {
    margin-bottom: 8px;
}

.ai-message-bubble p:last-child {
    margin-bottom: 0;
}

.ai-message-bubble ul,
.ai-message-bubble ol {
    margin: 6px 0 8px 18px;
    padding: 0;
}

.ai-message-bubble li {
    margin-bottom: 4px;
}

.ai-message-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 12px;
}

.ai-message-bubble th,
.ai-message-bubble td {
    padding: 6px 8px;
    border: 1px solid var(--border-color, #e2e8f0);
}

.ai-message-bubble th {
    background-color: var(--bg-subtle, #f1f5f9);
    font-weight: 600;
}

.ai-message-bubble blockquote {
    margin: 8px 0;
    padding: 8px 12px;
    border-left: 3px solid #f59e0b;
    background-color: #fffbeb;
    border-radius: 0 6px 6px 0;
    font-size: 12.5px;
}

/* Action Preview Interactive Card */
.ai-action-preview-card {
    margin-top: 10px;
    background-color: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-action-preview-title {
    font-size: 13px;
    font-weight: 700;
    color: #166534;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-action-preview-summary {
    font-size: 12px;
    color: #15803d;
}

.ai-action-preview-buttons {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.ai-btn-confirm {
    background-color: #16a34a;
    color: #ffffff;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.15s;
}

.ai-btn-confirm:hover {
    background-color: #15803d;
}

.ai-btn-cancel {
    background-color: #f1f5f9;
    color: #475569;
    border: 1px solid #cbd5e1;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
}

.ai-btn-cancel:hover {
    background-color: #e2e8f0;
}

/* Feedback Actions */
.ai-message-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.ai-feedback-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 12px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    transition: color 0.15s, transform 0.15s;
}

.ai-feedback-btn:hover {
    color: var(--primary, #2563eb);
    transform: scale(1.15);
}

.ai-feedback-btn.active {
    color: var(--primary, #2563eb);
}

/* Source citations pill */
.ai-citation-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 12px;
    background-color: var(--bg-subtle, #f1f5f9);
    color: var(--primary, #2563eb);
    text-decoration: none;
    margin-top: 6px;
    margin-right: 4px;
    border: 1px solid var(--border-color, #e2e8f0);
}

.ai-citation-badge:hover {
    background-color: var(--primary-light, #eff6ff);
}

/* 6. Typing Animation Indicator */
.ai-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background-color: var(--bg-card, #ffffff);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.ai-typing-dot {
    width: 6px;
    height: 6px;
    background-color: #94a3b8;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.ai-typing-dot:nth-child(1) { animation-delay: 0s; }
.ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1.2); opacity: 1; }
}

/* 7. Footer Input & Suggested Chips */
.ai-chat-footer {
    padding: 10px 14px 14px;
    background-color: var(--bg-card, #ffffff);
    border-top: 1px solid var(--border-color, #e2e8f0);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Suggested chips horizontal scroll */
.ai-suggestions-container {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
}

.ai-suggestions-container::-webkit-scrollbar {
    display: none;
}

.ai-suggestion-chip {
    white-space: nowrap;
    padding: 5px 11px;
    border-radius: 16px;
    font-size: 11.5px;
    font-weight: 500;
    background-color: var(--bg-subtle, #f1f5f9);
    color: var(--text-secondary, #475569);
    border: 1px solid var(--border-color, #e2e8f0);
    cursor: pointer;
    transition: all 0.15s ease;
}

.ai-suggestion-chip:hover {
    background-color: var(--primary-light, #eff6ff);
    color: var(--primary, #2563eb);
    border-color: var(--primary-border, #bfdbfe);
    transform: translateY(-1px);
}

/* Input Row */
.ai-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background-color: var(--bg-subtle, #f8fafc);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 12px;
    padding: 6px 8px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.ai-input-row:focus-within {
    border-color: var(--primary, #2563eb);
    box-shadow: 0 0 0 3px var(--primary-glow, rgba(37, 99, 235, 0.12));
}

.ai-chat-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.4;
    resize: none;
    max-height: 90px;
    padding: 4px 6px;
    color: var(--text-primary, #0f172a);
}

.ai-chat-input::placeholder {
    color: #94a3b8;
}

.ai-send-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background-color: var(--primary, #2563eb);
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    flex-shrink: 0;
}

.ai-send-btn:hover:not(:disabled) {
    background-color: var(--primary-hover, #1d4ed8);
}

.ai-send-btn:disabled {
    background-color: #cbd5e1;
    cursor: not-allowed;
}

/* 8. Mobile Responsiveness */
@media (max-width: 576px) {
    .ai-chatbot-panel {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        border: none;
    }

    .ai-chatbot-panel.maximized {
        width: 100vw;
        height: 100vh;
    }

    .ai-chatbot-fab {
        bottom: 16px;
        right: 16px;
    }
}
