/* AI Chat FAB & Chat Window */
#ai-chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #072f48, #0d4a6e);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(7, 47, 72, 0.4);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

#ai-chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(7, 47, 72, 0.5);
}

#ai-chat-fab:active {
    transform: scale(0.95);
}

#ai-chat-fab svg {
    width: 26px;
    height: 26px;
    fill: #fff;
}

/* Chat Window */
#ai-chat-window {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
}

#ai-chat-window.open {
    display: flex;
}

/* Header */
#ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, #072f48, #0d4a6e);
    color: #fff;
    flex-shrink: 0;
}

#ai-chat-header-title {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

#ai-chat-header-title svg {
    width: 20px;
    height: 20px;
    fill: #C0D62E;
}

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

#ai-chat-header-actions button {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: background 0.15s;
}

#ai-chat-header-actions button:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Messages Area */
#ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f7f8fa;
}

#ai-chat-messages::-webkit-scrollbar {
    width: 5px;
}

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

/* Empty state */
.ai-chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #8c95a0;
    text-align: center;
    padding: 24px;
}

.ai-chat-empty svg {
    width: 48px;
    height: 48px;
    fill: #c8cdd3;
    margin-bottom: 12px;
}

.ai-chat-empty p {
    font-size: 14px;
    margin: 0;
    line-height: 1.5;
}

/* Message Bubbles */
.ai-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.ai-msg-user {
    align-self: flex-end;
    background: #072f48;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ai-msg-assistant {
    align-self: flex-start;
    background: #fff;
    color: #1a1a1a;
    border: 1px solid #e2e5e9;
    border-bottom-left-radius: 4px;
}

.ai-msg-assistant p {
    margin: 0 0 8px 0;
}

.ai-msg-assistant p:last-child {
    margin-bottom: 0;
}

.ai-msg-assistant code {
    background: #f0f2f5;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 13px;
    font-family: 'Consolas', 'Monaco', monospace;
}

.ai-msg-assistant pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 10px 12px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 13px;
    margin: 8px 0;
}

.ai-msg-assistant pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.ai-msg-assistant strong {
    font-weight: 600;
}

.ai-msg-assistant ul, .ai-msg-assistant ol {
    margin: 4px 0;
    padding-left: 20px;
}

.ai-msg-assistant li {
    margin-bottom: 2px;
}

/* Link buttons */
.ai-link-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    margin: 6px 0;
    background: #f0f7ff;
    border: 1px solid #d0e3f7;
    border-radius: 8px;
    color: #1A73E8;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
    white-space: pre-wrap;
}

.ai-link-btn:hover {
    background: #e1effe;
    border-color: #a8c8f0;
}

.ai-link-icon-dl,
.ai-link-icon-ext {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.ai-link-icon-ext {
    width: 14px;
    height: 14px;
    opacity: 0.5;
}

.ai-msg-assistant a:not(.ai-link-btn) {
    color: #0d6efd;
    text-decoration: underline;
}

/* Typing indicator */
.ai-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid #e2e5e9;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

.ai-typing-dot {
    width: 7px;
    height: 7px;
    background: #8c95a0;
    border-radius: 50%;
    animation: ai-typing-bounce 1.4s infinite ease-in-out;
}

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

@keyframes ai-typing-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Tool indicator */
.ai-tool-indicator {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f0f7ff;
    border: 1px solid #d0e3f7;
    border-radius: 8px;
    font-size: 13px;
    color: #3a6ea5;
}

.ai-tool-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #d0e3f7;
    border-top-color: #3a6ea5;
    border-radius: 50%;
    animation: ai-spin 0.8s linear infinite;
}

@keyframes ai-spin {
    to { transform: rotate(360deg); }
}

/* Input Area */
#ai-chat-input-area {
    display: flex;
    align-items: flex-end;
    padding: 12px;
    border-top: 1px solid #e2e5e9;
    background: #fff;
    gap: 8px;
    flex-shrink: 0;
}

#ai-chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.15s;
}

#ai-chat-input:focus {
    border-color: #072f48;
}

#ai-chat-input::placeholder {
    color: #9ca3af;
}

#ai-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: #072f48;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, opacity 0.15s;
    flex-shrink: 0;
}

#ai-chat-send:hover {
    background: #0d4a6e;
}

#ai-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#ai-chat-send svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* Error message */
.ai-msg-error {
    align-self: center;
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    text-align: center;
}

/* Maximized state */
#ai-chat-window.maximized {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    transition: all 0.2s ease;
}

/* Mobile */
@media (max-width: 480px) {
    #ai-chat-window {
        bottom: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
    }

    #ai-chat-fab {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
    }
}
