/* AiChat Widget Styles */
.aichat-container {
    position: fixed;
    bottom: 100px;
    right: 24px;
    z-index: 10000;
    font-family: var(--aichat-font-family);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    --aichat-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    --aichat-bg: #ffffff;
    --aichat-fg: #111827;
    --aichat-muted: #6b7280;
    --aichat-border: #e5e7eb;
    --aichat-accent: #2563eb;
    --aichat-user-bg: #2563eb;
    --aichat-user-fg: #ffffff;
    --aichat-assistant-bg: #f3f4f6;
    --aichat-assistant-fg: #1f2937;
    --aichat-header-bg: #ffffff;
    --aichat-header-text: #111827;
    --aichat-header-icon: #111827;
    --aichat-header-bg-image: none;
    --aichat-header-bg-size: cover;
    --aichat-chat-bg: #ffffff;
    --aichat-footer-bg: #ffffff;
    --aichat-suggestion-bg: #ffffff;
    --aichat-suggestion-text: #111827;
    --aichat-suggestion-border: #e5e7eb;
    --aichat-suggestion-hover-bg: #ffffff;
    --aichat-suggestion-hover-text: #2563eb;
    --aichat-suggestion-hover-border: #2563eb;
    --aichat-send-bg: #2563eb;
    --aichat-send-fg: #ffffff;
    --aichat-send-hover-bg: #2563eb;
    --aichat-send-hover-fg: #ffffff;
    --aichat-send-hover-filter: brightness(1.1);
    --aichat-trigger-bg: #ffffff;
    --aichat-trigger-icon: #111827;
    --aichat-tooltip-bg: #1f2937;
    --aichat-tooltip-text: #ffffff;
    --aichat-tooltip-arrow: #1f2937;
    --aichat-shadow-color: rgba(0, 0, 0, 0.15);
    --aichat-shadow-color-hover: rgba(0, 0, 0, 0.2);
    --aichat-body-text: #111827;
    --aichat-link-color: #2563eb;
    --aichat-code-bg: rgba(0, 0, 0, 0.05);
    --aichat-code-text: #111827;
    --aichat-code-block-bg: rgba(0, 0, 0, 0.06);
    --aichat-blockquote-bg: rgba(0, 0, 0, 0.02);
    --aichat-blockquote-border: #e5e7eb;
    --aichat-input-bg: #f9fafb;
    --aichat-input-text: #111827;
    --aichat-input-placeholder: #6b7280;
    --aichat-input-border: #e5e7eb;
    --aichat-input-focus-border: #2563eb;
    --aichat-input-focus-ring: rgba(37, 99, 235, 0.1);
}

/* Trigger Button */
.aichat-trigger {
    background: var(--aichat-trigger-bg);
    color: var(--aichat-fg);
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--aichat-shadow-color);
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s;
    position: relative;
    padding: 0;
}

.aichat-trigger:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px var(--aichat-shadow-color-hover);
}

.aichat-trigger:active {
    transform: scale(0.95);
}

.aichat-icon {
    color: var(--aichat-trigger-icon, var(--aichat-fg));
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.aichat-icon svg {
    width: 48px !important;
    height: 48px !important;
    display: block;
    color: var(--aichat-trigger-icon, var(--aichat-fg));
    fill: currentColor;
    stroke: currentColor;
    flex-shrink: 0;
}

.aichat-icon img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: 4px;
}

/* Tooltip */
.aichat-tooltip {
    position: absolute;
    right: 100%;
    margin-right: 16px;
    background: var(--aichat-tooltip-bg);
    color: var(--aichat-tooltip-text);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transform: translateX(10px);
    transition: all 0.2s ease;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.aichat-tooltip::after {
    content: '';
    position: absolute;
    top: 50%;
    right: -4px;
    transform: translateY(-50%);
    border-width: 4px;
    border-style: solid;
    border-color: transparent transparent transparent var(--aichat-tooltip-arrow);
}

.aichat-trigger:hover .aichat-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

/* Hide trigger while chat is open */
.aichat-container.aichat-open .aichat-trigger {
    display: none;
}

/* Chat Widget Window */
.aichat-widget {
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--aichat-bg);
    border-radius: 12px;
    box-shadow: 0 12px 28px var(--aichat-shadow-color);
    display: none;
    /* Hidden by default */
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--aichat-border);
    animation: aichat-slide-up 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    color: var(--aichat-body-text);
}

.aichat-widget.aichat-visible {
    display: flex;
}

@keyframes aichat-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.aichat-header {
    padding: 16px 20px;
    background: var(--aichat-header-bg, white);
    background-image: var(--aichat-header-bg-image, none);
    background-size: var(--aichat-header-bg-size, cover);
    background-position: center;
    background-repeat: no-repeat;
    border-bottom: 1px solid var(--aichat-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.aichat-title {
    font-weight: 600;
    font-size: 16px;
    color: var(--aichat-header-text, var(--aichat-fg));
    display: var(--aichat-header-title-display, block);
    margin-right: 8px;
}

.aichat-close {
    background: transparent;
    border: none;
    color: var(--aichat-header-icon, var(--aichat-muted));
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.aichat-close:hover {
    background: var(--aichat-header-close-hover-bg, var(--aichat-assistant-bg));
    color: var(--aichat-header-close-hover, var(--aichat-header-icon, var(--aichat-fg)));
}

/* Chat Body */
.aichat-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--aichat-chat-bg);
    scroll-behavior: smooth;
}

/* Messages */
.aichat-message {
    max-width: 85%;
    display: flex;
    flex-direction: column;
}

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

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

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

.aichat-message--user .aichat-message-content {
    background: var(--aichat-user-bg);
    color: var(--aichat-user-fg);
    border-bottom-right-radius: 2px;
}

.aichat-message--assistant .aichat-message-content {
    background: var(--aichat-assistant-bg);
    color: var(--aichat-assistant-fg);
    border-bottom-left-radius: 2px;
}

/* Formatted content styles */
.aichat-message-content p {
    margin: 0 0 8px 0;
}

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

.aichat-message-content ul,
.aichat-message-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

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

.aichat-message-content strong {
    font-weight: 600;
    color: var(--aichat-fg);
}

.aichat-message-content em {
    font-style: italic;
}

.aichat-message-content code {
    background: var(--aichat-code-bg);
    color: var(--aichat-code-text);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}

.aichat-message-content pre {
    background: var(--aichat-code-block-bg);
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}

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

.aichat-message-content blockquote {
    margin: 8px 0;
    padding: 8px 12px;
    border-left: 3px solid var(--aichat-blockquote-border);
    color: var(--aichat-muted);
    background: var(--aichat-blockquote-bg);
}

.aichat-message-content hr {
    border: none;
    border-top: 1px solid var(--aichat-border);
    margin: 10px 0;
}

.aichat-message-content a {
    color: var(--aichat-link-color);
    text-decoration: underline;
}

/* Suggestions */
.aichat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px 20px;
    flex-shrink: 0;
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden;
}

.aichat-suggestions:empty {
    display: none;
}

.aichat-suggestions-label {
    font-size: 13px;
    color: var(--aichat-muted);
    margin-bottom: 4px;
}

.aichat-suggestions-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 4px;
}

.aichat-suggestion-chip {
    border: 1px solid var(--aichat-suggestion-border);
    background: var(--aichat-suggestion-bg);
    color: var(--aichat-suggestion-text);
    border-radius: 16px;
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
}

.aichat-suggestion-chip:hover {
    border-color: var(--aichat-suggestion-hover-border);
    background: var(--aichat-suggestion-hover-bg);
    color: var(--aichat-suggestion-hover-text);
}

/* Suggestions scrollbar */
.aichat-suggestions::-webkit-scrollbar {
    width: 6px;
}

.aichat-suggestions::-webkit-scrollbar-track {
    background: transparent;
}

.aichat-suggestions::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

.aichat-suggestions::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.2);
}

/* Input Area */
.aichat-input {
    padding: 16px;
    border-top: 1px solid var(--aichat-border);
    display: flex;
    gap: 10px;
    background: var(--aichat-footer-bg);
    flex-shrink: 0;
}

.aichat-text {
    flex: 1;
    border: 1px solid var(--aichat-input-border);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--aichat-input-bg);
    color: var(--aichat-input-text);
}

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

.aichat-text:focus {
    background: white;
    border-color: var(--aichat-input-focus-border);
    box-shadow: 0 0 0 2px var(--aichat-input-focus-ring);
}

.aichat-send {
    background: var(--aichat-send-bg);
    color: var(--aichat-send-fg);
    border: none;
    border-radius: 20px;
    padding: 0 20px;
    font-weight: 500;
    cursor: pointer;
    font-size: 14px;
    transition: filter 0.2s, background 0.2s, color 0.2s;
}

.aichat-send:hover {
    background: var(--aichat-send-hover-bg);
    color: var(--aichat-send-hover-fg);
    filter: var(--aichat-send-hover-filter);
}

/* Scrollbar Styling */
.aichat-body::-webkit-scrollbar {
    width: 6px;
}

.aichat-body::-webkit-scrollbar-track {
    background: transparent;
}

.aichat-body::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

.aichat-body::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.2);
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
    .aichat-widget {
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
        right: 16px;
        bottom: 90px;
    }

    .aichat-container {
        right: 16px;
        bottom: 16px;
    }
}
