/**
 * AI Chat Widget Styles
 * A floating chat widget for Ask AI functionality
 */

/* ========== CSS Variables ========== */
:root {
    --ai-chat-primary: #6366f1;
    --ai-chat-primary-hover: #4f46e5;
    --ai-chat-bg: #ffffff;
    --ai-chat-bg-secondary: #f9fafb;
    --ai-chat-text: #111827;
    --ai-chat-text-muted: #6b7280;
    --ai-chat-border: #e5e7eb;
    --ai-chat-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.15);
    --ai-chat-radius: 16px;
    --ai-chat-btn-size: 60px;
    --ai-chat-z-index: 9999;
}

[data-theme="dark"] {
    --ai-chat-primary: #818cf8;
    --ai-chat-primary-hover: #6366f1;
    --ai-chat-bg: #1f2937;
    --ai-chat-bg-secondary: #111827;
    --ai-chat-text: #f9fafb;
    --ai-chat-text-muted: #9ca3af;
    --ai-chat-border: #374151;
    --ai-chat-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.4);
}

/* ========== Widget Container ========== */
.ai-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--ai-chat-z-index);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ========== Toggle Button ========== */
.ai-chat-toggle {
    width: var(--ai-chat-btn-size);
    height: var(--ai-chat-btn-size);
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-chat-primary), #8b5cf6);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.ai-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
}

.ai-chat-toggle svg {
    width: 28px;
    height: 28px;
    color: #ffffff;
}

.ai-chat-toggle .ai-chat-icon-close {
    display: none;
}

.ai-chat-widget.open .ai-chat-toggle .ai-chat-icon-open {
    display: none;
}

.ai-chat-widget.open .ai-chat-toggle .ai-chat-icon-close {
    display: block;
}

/* ========== Chat Window ========== */
.ai-chat-window {
    position: absolute;
    bottom: calc(var(--ai-chat-btn-size) + 16px);
    right: 0;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 560px;
    max-height: calc(100vh - 140px);
    background: var(--ai-chat-bg);
    border-radius: var(--ai-chat-radius);
    box-shadow: var(--ai-chat-shadow);
    border: 1px solid var(--ai-chat-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
}

.ai-chat-widget.open .ai-chat-window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ========== Resize Handle ========== */
.ai-chat-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    z-index: 10;
    border-radius: var(--ai-chat-radius) 0 0 0;
}

.ai-chat-resize-handle::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 6px;
    width: 8px;
    height: 8px;
    border-left: 2px solid rgba(255, 255, 255, 0.6);
    border-top: 2px solid rgba(255, 255, 255, 0.6);
    opacity: 0;
    transition: opacity 0.2s;
}

.ai-chat-resize-handle:hover::before,
.ai-chat-resize-handle:active::before {
    opacity: 1;
}

/* Show resize indicator on window hover */
.ai-chat-window:hover .ai-chat-resize-handle::before {
    opacity: 0.5;
}

.ai-chat-resize-handle:hover::before {
    opacity: 1 !important;
}

/* ========== Header ========== */
.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--ai-chat-primary), #8b5cf6);
    color: #ffffff;
}

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

.ai-chat-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-avatar svg {
    width: 24px;
    height: 24px;
    color: #ffffff;
}

.ai-chat-header-text {
    display: flex;
    flex-direction: column;
}

.ai-chat-title {
    font-size: 16px;
    font-weight: 600;
}

.ai-chat-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-chat-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
}

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

.ai-chat-clear,
.ai-chat-close {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.ai-chat-clear:hover,
.ai-chat-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.ai-chat-clear svg,
.ai-chat-close svg {
    width: 18px;
    height: 18px;
    color: #ffffff;
}

.ai-chat-clear:active,
.ai-chat-close:active {
    transform: scale(0.95);
}

/* ========== Messages Container ========== */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

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

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: var(--ai-chat-border);
    border-radius: 3px;
}

/* ========== Message Bubbles ========== */
.ai-chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: messageIn 0.3s ease;
}

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

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

.ai-chat-message.ai,
.ai-chat-message.human {
    align-self: flex-start;
}

.ai-chat-message-content {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.ai-chat-message.user .ai-chat-message-content {
    background: var(--ai-chat-primary);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.ai-chat-message.ai .ai-chat-message-content,
.ai-chat-message.human .ai-chat-message-content {
    background: var(--ai-chat-bg-secondary);
    color: var(--ai-chat-text);
    border-bottom-left-radius: 4px;
}

.ai-chat-message-time {
    font-size: 11px;
    color: var(--ai-chat-text-muted);
    margin-top: 4px;
}

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

/* ========== Sources ========== */
.ai-chat-sources {
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--ai-chat-bg);
    border: 1px solid var(--ai-chat-border);
    border-radius: 8px;
    font-size: 12px;
}

.ai-chat-sources-title {
    color: var(--ai-chat-text-muted);
    margin-bottom: 4px;
}

.ai-chat-source-link {
    color: var(--ai-chat-primary);
    text-decoration: none;
    display: block;
    padding: 2px 0;
}

.ai-chat-source-link:hover {
    text-decoration: underline;
}

/* ========== Typing Indicator ========== */
.ai-chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 20px 12px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--ai-chat-text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

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

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

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-6px);
    }
}

/* ========== Input Area ========== */
.ai-chat-input-area {
    padding: 12px 16px 16px;
    border-top: 1px solid var(--ai-chat-border);
    background: var(--ai-chat-bg);
}

.ai-chat-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--ai-chat-bg-secondary);
    border: 1px solid var(--ai-chat-border);
    border-radius: 12px;
    padding: 8px 12px;
    transition: border-color 0.2s;
}

.ai-chat-form:focus-within {
    border-color: var(--ai-chat-primary);
}

.ai-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    color: var(--ai-chat-text);
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    padding: 4px 0;
}

.ai-chat-input::placeholder {
    color: var(--ai-chat-text-muted);
}

.ai-chat-input:focus {
    outline: none;
}

.ai-chat-send {
    width: 36px;
    height: 36px;
    background: var(--ai-chat-primary);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.ai-chat-send:hover {
    background: var(--ai-chat-primary-hover);
    transform: scale(1.05);
}

.ai-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.ai-chat-send svg {
    width: 18px;
    height: 18px;
    color: #ffffff;
}

.ai-chat-powered {
    text-align: center;
    margin-top: 8px;
    font-size: 11px;
    color: var(--ai-chat-text-muted);
}

/* ========== Welcome Message ========== */
.ai-chat-welcome {
    text-align: center;
    padding: 20px;
}

.ai-chat-welcome-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--ai-chat-primary), #8b5cf6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.ai-chat-welcome-icon svg {
    width: 32px;
    height: 32px;
    color: #ffffff;
}

.ai-chat-welcome-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--ai-chat-text);
    margin-bottom: 8px;
}

.ai-chat-welcome-text {
    font-size: 14px;
    color: var(--ai-chat-text-muted);
    line-height: 1.5;
}

/* ========== Mobile Responsive ========== */
@media (max-width: 480px) {
    .ai-chat-widget {
        bottom: 16px;
        right: 16px;
    }

    .ai-chat-window {
        width: calc(100vw - 32px);
        height: calc(100vh - 120px);
        bottom: calc(var(--ai-chat-btn-size) + 12px);
    }

    .ai-chat-toggle {
        width: 52px;
        height: 52px;
    }

    .ai-chat-toggle svg {
        width: 24px;
        height: 24px;
    }
}

/* ========== Markdown Support ========== */
.ai-chat-message-content p {
    margin: 0 0 8px;
}

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

.ai-chat-message-content ul,
.ai-chat-message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.ai-chat-message-content li {
    margin: 4px 0;
}

.ai-chat-message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'SF Mono', Monaco, monospace;
}

.ai-chat-message.user .ai-chat-message-content code {
    background: rgba(255, 255, 255, 0.2);
}

.ai-chat-message-content pre {
    background: rgba(0, 0, 0, 0.1);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.ai-chat-message-content pre code {
    background: transparent;
    padding: 0;
}
