/**
 * Ask Taikun - Shared Chat Styling
 * Used by: catalog-browser.html, well-360.html, index.html
 * 
 * Provides consistent ChatGPT/Claude-style chat interface across all pages.
 */

/* ===== TYPING INDICATOR ANIMATION ===== */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}
.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--tblr-primary);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0s; }
@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ===== AI RESPONSE STYLING ===== */
.ai-response {
    font-size: 14px;
    line-height: 1.6;
    color: var(--tblr-body-color);
    /* Prevent horizontal overflow in flex containers */
    min-width: 0;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    overflow-x: hidden;
}
/* Ensure the flex parent also constrains width */
.ai-response .markdown,
.ai-response > div:first-child,
.ai-response > p {
    min-width: 0;
    overflow-wrap: break-word;
    word-wrap: break-word;
}
.ai-response h3 { font-size: 18px; font-weight: 600; }
.ai-response h4 { font-size: 15px; font-weight: 600; }
.ai-response h5 { font-size: 13px; font-weight: 600; }
.ai-response h6 { font-size: 11px; font-weight: 500; }
.ai-response p { margin-bottom: 0.5rem; }
.ai-response ul, .ai-response ol { margin-bottom: 0.75rem; }
.ai-response li { margin-bottom: 0.25rem; }
.ai-response .alert { font-size: 13px; }
.ai-response hr { border-color: var(--tblr-border-color); opacity: 0.5; }
.ai-response blockquote {
    border-left: 3px solid var(--tblr-primary);
    color: var(--tblr-secondary-color);
    margin-left: 0;
    padding: 0.5rem 0 0.5rem 1rem;
}
.ai-response .table-responsive {
    border: 1px solid var(--tblr-border-color);
    border-radius: var(--tblr-border-radius);
}
.ai-response .table { margin-bottom: 0; }

/* ===== STREAMING STATUS INDICATOR ===== */
.ask-taikun-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--tblr-muted);
    animation: fadeIn 0.3s ease;
}
.ask-taikun-status .spinner-border {
    width: 14px;
    height: 14px;
    border-width: 2px;
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Dark mode support */
[data-bs-theme="dark"] .ai-response code {
    background: var(--tblr-bg-surface-secondary);
}

/* ===== CHAT CONTAINER ===== */
.ask-taikun-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.ask-taikun-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: var(--tblr-bg-surface);
}

.ask-taikun-input-area {
    border-top: 1px solid var(--tblr-border-color);
    padding: 0.75rem 1rem;
    background: var(--tblr-card-bg);
}

/* ===== USER MESSAGE BUBBLE ===== */
/* Uses Tabler primary background - solid color per Tabler conventions */
.ask-taikun-user-message {
    max-width: 70%;
    background: var(--tblr-primary);
    border-radius: var(--tblr-border-radius-lg);
    padding: 12px 16px;
    color: #fff;
}

.ask-taikun-user-message .message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 8px;
}

/* ===== AI MESSAGE BUBBLE ===== */
.ask-taikun-ai-message {
    max-width: 85%;
}

.ask-taikun-ai-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--tblr-primary-lt);
    color: var(--tblr-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ===== FLOATING PANEL STYLES ===== */
/* Uses Tabler z-index and shadow patterns */
.ask-taikun-floating-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 400px;
    max-width: calc(100vw - 40px);
    z-index: var(--tblr-zindex-modal);
    box-shadow: var(--tblr-box-shadow-lg);
    border-radius: var(--tblr-border-radius-lg);
    overflow: hidden;
}

.ask-taikun-floating-fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    z-index: var(--tblr-zindex-modal);
    box-shadow: var(--tblr-box-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== EXAMPLE BUTTONS ===== */
.ask-taikun-examples .btn {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== CODE BLOCKS IN RESPONSES ===== */
/* Uses Tabler dark/code colors for consistency */
.ai-response pre {
    background: var(--tblr-dark);
    color: var(--tblr-gray-200);
    padding: 12px 16px;
    border-radius: var(--tblr-border-radius);
    font-size: 12px;
    overflow-x: auto;
    margin-bottom: 12px;
}

.ai-response code {
    background: var(--tblr-azure-lt);
    color: var(--tblr-azure);
    padding: 2px 6px;
    border-radius: var(--tblr-border-radius-sm);
    font-size: 12px;
}

/* ===== WELCOME MESSAGE ===== */
.ask-taikun-welcome {
    text-align: center;
    padding: 2rem;
    color: var(--tblr-muted);
}

.ask-taikun-welcome i {
    font-size: 48px;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* ===== MESSAGE ACTION BUTTONS ===== */
.ask-taikun-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.d-flex:hover .ask-taikun-actions {
    opacity: 1;
}

.ask-taikun-actions .btn {
    padding: 4px 8px;
    font-size: 12px;
}

.ask-taikun-actions .btn:hover {
    background: var(--tblr-primary-lt);
}

/* ===== RECORDING INDICATOR ===== */
.recording {
    animation: pulse-recording 1.5s infinite;
}

@keyframes pulse-recording {
    0%, 100% { 
        box-shadow: 0 0 0 0 rgba(var(--tblr-danger-rgb), 0.4);
    }
    50% { 
        box-shadow: 0 0 0 8px rgba(var(--tblr-danger-rgb), 0);
    }
}

.recording i {
    animation: blink 0.5s infinite;
}

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

/* ===== FILE ATTACHMENTS ===== */
.ask-taikun-attachments {
    padding: 8px 0;
}

.ask-taikun-attachments .badge {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ask-taikun-attachments .btn-close {
    padding: 0;
    margin-left: 6px;
    font-size: 8px;
}

/* ===== INPUT TOOLBAR ===== */
.ask-taikun-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ask-taikun-toolbar .btn {
    padding: 8px;
    border-radius: 50%;
}

.ask-taikun-toolbar .btn:hover {
    background: var(--tblr-primary-lt);
}

/* ===== MESSAGE ACTION BUTTONS (Copy, Read Aloud) ===== */
/* Always visible, not just on hover - like ChatGPT/Claude */
.ask-taikun-actions {
    display: flex !important;
    gap: 4px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.ask-taikun-actions:hover {
    opacity: 1;
}

.ask-taikun-actions .btn {
    padding: 4px 8px;
    font-size: 14px;
    border-radius: 6px;
    color: var(--tblr-muted);
}

.ask-taikun-actions .btn:hover {
    background: var(--tblr-bg-surface-secondary);
    color: var(--tblr-body-color);
}

.ask-taikun-actions .btn i {
    font-size: 16px;
}

/* Success state for copy */
.ask-taikun-actions .btn.text-success {
    color: var(--tblr-success) !important;
}

/* ===== COPY THREAD BUTTON ===== */
.ask-taikun-copy-thread {
    position: absolute;
    top: 8px;
    right: 8px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.ask-taikun-copy-thread:hover {
    opacity: 1;
}

/* ===== ANIMATE SPIN (for loading icons) ===== */
.animate-spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ===== PR-2.2 · a11y: rem type (resizes with user pref), tap targets, mobile sheet ===== */
.ai-response { font-size: .875rem; }
.ai-response h3 { font-size: 1.125rem; }
.ai-response h4 { font-size: .9375rem; }
.ai-response h5 { font-size: .8125rem; }
.ai-response h6 { font-size: .75rem; }            /* lift the 11px floor */
.ask-taikun-status { font-size: .8125rem; }
/* icon-only action buttons meet the 24x24 min target (WCAG 2.5.8) */
.ask-taikun-actions .btn, .ask-taikun-toolbar .btn {
    min-width: 2rem; min-height: 2rem;
    display: inline-flex; align-items: center; justify-content: center;
}
.ask-taikun-attachments .btn-close { width: 1.5rem; height: 1.5rem; font-size: .625rem; }
/* flagship chat becomes a full-height sheet on phones (was a fixed 400px panel) */
@media (max-width: 575.98px) {
    .ask-taikun-floating-panel { inset: 0; width: 100vw; max-width: none; height: 100dvh; border-radius: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .typing-indicator span, .recording, .recording i, .animate-spin { animation: none !important; }
}
