/* ============================================================================
   AI Chat Widget Styles
   ============================================================================ */

/* Floating Action Button */
.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    z-index: 1090;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.chat-fab.hidden {
    display: none;
}

/* Chat Panel */
.chat-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 420px;
    height: 600px;
    max-height: calc(100vh - 48px);
    background: var(--card-bg, #fff);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    z-index: 1090;
    overflow: hidden;
    border: 1px solid var(--border-color, #e5e7eb);
    animation: chatSlideUp 0.25s ease-out;
}

.chat-panel.hidden {
    display: none;
}

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

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--primary-color);
    color: #fff;
    flex-shrink: 0;
}

.chat-header-title {
    flex: 1;
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-actions {
    display: flex;
    gap: 4px;
}

.chat-header-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    font-size: 16px;
    line-height: 1;
    transition: background 0.15s ease;
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* Chat Body */
.chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.chat-body::-webkit-scrollbar-thumb {
    background: var(--gray-300, #d1d5db);
    border-radius: 3px;
}

/* Welcome Screen */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 24px;
}

.chat-welcome-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.7;
}

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

.chat-welcome-text {
    font-size: 13px;
    color: var(--text-muted, #6b7280);
    margin-bottom: 24px;
    line-height: 1.5;
}

.chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.chat-suggestion-btn {
    padding: 10px 16px;
    background: var(--gray-50, #f9fafb);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
    font-size: 13px;
    color: var(--text-dark, #333);
    transition: background 0.15s ease, border-color 0.15s ease;
    line-height: 1.4;
}

.chat-suggestion-btn:hover {
    background: var(--gray-100, #f3f4f6);
    border-color: var(--primary-color);
}

/* Message Bubbles */
.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: chatFadeIn 0.2s ease-out;
}

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

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

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

.chat-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.6;
    word-break: break-word;
}

.chat-message.human .chat-bubble {
    background: var(--primary-color);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message.ai .chat-bubble {
    background: var(--gray-100, #f3f4f6);
    color: var(--text-dark, #333);
    border-bottom-left-radius: 4px;
}

/* Markdown rendering in AI messages */
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3 {
    margin: 8px 0 4px 0;
    font-size: 14px;
    font-weight: 600;
}

.chat-bubble p {
    margin: 4px 0;
}

.chat-bubble ul, .chat-bubble ol {
    margin: 4px 0;
    padding-left: 20px;
}

.chat-bubble li {
    margin: 2px 0;
}

.chat-bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
}

.chat-message.human .chat-bubble code {
    background: rgba(255, 255, 255, 0.2);
}

.chat-bubble pre {
    background: var(--gray-800, #1f2937);
    color: #e5e7eb;
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 6px 0;
    font-size: 12px;
}

.chat-bubble pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.chat-bubble table {
    border-collapse: collapse;
    margin: 6px 0;
    font-size: 12px;
    width: 100%;
}

.chat-bubble th, .chat-bubble td {
    border: 1px solid var(--border-color, #e5e7eb);
    padding: 4px 8px;
    text-align: left;
}

.chat-bubble th {
    background: var(--gray-50, #f9fafb);
    font-weight: 600;
}

.chat-bubble strong {
    font-weight: 600;
}

/* SQL Queries collapsible */
.chat-sql-details {
    margin-top: 6px;
    font-size: 12px;
}

.chat-sql-details summary {
    cursor: pointer;
    color: var(--text-muted, #6b7280);
    font-size: 11px;
    user-select: none;
}

.chat-sql-details summary:hover {
    color: var(--primary-color);
}

.chat-sql-details pre {
    margin-top: 4px;
    font-size: 11px;
    max-height: 150px;
    overflow-y: auto;
}

/* Typing cursor */
.chat-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--primary-color);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: chatCursorBlink 0.6s step-end infinite;
}

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

/* Bubble typing state — ensure cursor stays visible after content */
.chat-bubble-typing {
    min-height: 20px;
}

/* Thinking animation */
.chat-thinking {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background: var(--gray-100, #f3f4f6);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    font-size: 12px;
    color: var(--text-muted, #6b7280);
}

.chat-thinking-dots {
    display: flex;
    gap: 3px;
}

.chat-thinking-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted, #6b7280);
    animation: chatDotPulse 1.2s infinite;
}

.chat-thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes chatDotPulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* Tool execution indicator */
.chat-tool-indicator {
    font-size: 11px;
    color: var(--text-muted, #6b7280);
    padding: 4px 14px;
    align-self: flex-start;
    font-style: italic;
}

/* Input Area */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color, #e5e7eb);
    background: var(--card-bg, #fff);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 13px;
    font-family: inherit;
    line-height: 1.5;
    max-height: 100px;
    min-height: 38px;
    background: var(--input-bg, #fff);
    color: var(--text-dark, #333);
    outline: none;
    transition: border-color 0.15s ease;
}

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

.chat-input::placeholder {
    color: var(--text-muted, #6b7280);
}

.chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--primary-color);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s ease;
    font-size: 16px;
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-send-btn:hover:not(:disabled) {
    opacity: 0.9;
}

/* Conversation List */
.chat-conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-conv-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-dark, #333);
    transition: background 0.15s ease;
    gap: 8px;
}

.chat-conv-item:hover {
    background: var(--gray-100, #f3f4f6);
}

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

.chat-conv-item-date {
    font-size: 11px;
    color: var(--text-muted, #6b7280);
    flex-shrink: 0;
}

.chat-conv-item-delete {
    background: none;
    border: none;
    color: var(--text-muted, #6b7280);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 14px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s ease;
    flex-shrink: 0;
}

.chat-conv-item:hover .chat-conv-item-delete {
    opacity: 1;
}

.chat-conv-item-delete:hover {
    color: var(--danger, #dc3545);
}

.chat-conv-empty {
    text-align: center;
    color: var(--text-muted, #6b7280);
    padding: 32px 16px;
    font-size: 13px;
}

/* Settings Panel */
.chat-settings {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    height: 100%;
}

.chat-settings-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-settings-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dark, #333);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-settings-select {
    padding: 8px 10px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    font-size: 13px;
    background: var(--input-bg, #fff);
    color: var(--text-dark, #333);
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s ease;
}

.chat-settings-select:focus {
    border-color: var(--primary-color);
}

.chat-settings-textarea {
    padding: 8px 10px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    background: var(--input-bg, #fff);
    color: var(--text-dark, #333);
    resize: vertical;
    min-height: 60px;
    max-height: 120px;
    outline: none;
    transition: border-color 0.15s ease;
}

.chat-settings-textarea:focus {
    border-color: var(--primary-color);
}

.chat-settings-textarea::placeholder {
    color: var(--text-muted, #6b7280);
}

.chat-settings-actions {
    display: flex;
    gap: 8px;
}

.chat-settings-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    background: var(--gray-50, #f9fafb);
    color: var(--text-dark, #333);
    transition: background 0.15s ease, border-color 0.15s ease;
}

.chat-settings-btn:hover {
    background: var(--gray-100, #f3f4f6);
}

.chat-settings-btn-primary {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.chat-settings-btn-primary:hover {
    opacity: 0.9;
    background: var(--primary-color);
}

.chat-settings-btn-danger {
    color: var(--danger, #dc3545);
    border-color: var(--danger, #dc3545);
    background: transparent;
}

.chat-settings-btn-danger:hover {
    background: var(--danger, #dc3545);
    color: #fff;
}

.chat-settings-divider {
    border-top: 1px solid var(--border-color, #e5e7eb);
    margin: 4px 0;
}

/* Responsive */
@media (max-width: 480px) {
    .chat-panel {
        width: calc(100vw - 16px);
        height: calc(100vh - 16px);
        bottom: 8px;
        right: 8px;
        border-radius: 12px;
    }
}
