/* ============================================
   Dash Chat Application - Core Component Styles
   Reusable styles for chat components across all layouts
   Version: 2.0 - Modular architecture
   ============================================ */

/* === ROOT & THEME VARIABLES === */
:root {
    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    /* Main backgrounds - Dark navy theme */
    --bg-main: #0f1117;
    --bg-sidebar: #16171f;
    --bg-header: #1a1b26;
    --bg-input: #1f2937;
    --bg-message-ai: transparent;
    --bg-message-user: #383838;

    /* Glassmorphism */
    --bg-glass: rgba(255, 255, 255, 0.05);
    --bg-glass-dark: rgba(31, 41, 55, 0.8);
    --border-glass: rgba(255, 255, 255, 0.1);

    /* Accent colors - Purple to Blue gradient */
    --accent-purple: #8b5cf6;
    --accent-purple-light: #a78bfa;
    --accent-blue: #3b82f6;
    --accent-blue-light: #60a5fa;
    --accent-gradient: linear-gradient(135deg, #8b5cf6, #6366f1, #3b82f6);

    /* Original colors */
    --border-color: #3a3a3a;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-muted: #808080;

    /* Chat input colors */
    --input-container-bg: #2a2a2a;
    --input-container-border: rgba(255, 255, 255, 0.1);
    --input-text: #e0e0e0;
    --input-placeholder: #9ca3af;
    --send-btn-bg: #4b9cd3;

    /* Border radius */
    --border-radius-xl: 24px;
    --border-radius-lg: 16px;
    --border-radius-md: 12px;
    --border-radius-sm: 8px;
    --border-radius-pill: 50px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
    --shadow-glow-purple: 0 4px 20px rgba(139, 92, 246, 0.4);
    --shadow-glow-blue: 0 4px 20px rgba(59, 130, 246, 0.4);
}

/* === GLOBAL RESETS === */
* {
    box-sizing: border-box;
}

/* Global font fallback for non-Ant components */
body, html {
    font-family: var(--font-family);
}

/* Critical fix for message bubbles - override any conflicting styles */
.message-bubble {
    writing-mode: horizontal-tb !important;
    text-orientation: mixed !important;
}

/* === GLASSMORPHISM UTILITY CLASSES === */
.glass-container {
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    border-radius: var(--border-radius-xl);
}

.glass-container-dark {
    background: var(--bg-glass-dark);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
}

/* Gradient glow effects */
.gradient-glow-left {
    position: relative;
    border-left: 3px solid transparent;
    border-image: linear-gradient(to bottom, var(--accent-purple), var(--accent-blue)) 1;
}

.gradient-glow-all {
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.3), 0 0 40px rgba(59, 130, 246, 0.2);
}

/* === MESSAGE COMPONENTS === */
.messages-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 0;
}

/* Message wrapper - controls alignment */
.message-wrapper {
    display: flex;
    /* No margin-bottom needed - gap in .messages-list handles spacing */
}

/* User message alignment */
.message-user {
    justify-content: flex-end;
    margin-left: auto;
    width: 100%;
}

/* AI message alignment */
.message-assistant {
    justify-content: flex-start;
    max-width: 100%;
}

/* === MESSAGE BUBBLES === */
.message-bubble {
    position: relative;
    padding: 12px 16px;
    max-width: 100%;
    word-wrap: break-word;
    line-height: 1.6;
    font-size: 14px;
    transition: all 0.2s ease;
}

/* User message bubble */
.message-user .message-bubble {
    background: var(--bg-message-user) !important;
    color: white !important;
    border-radius: 18px !important;
    border: none !important;
    box-shadow: var(--shadow-sm);
    min-width: 60px !important;
    max-width: 70% !important;
    width: auto !important;
    display: inline-block !important;
    word-break: normal !important;
    word-wrap: break-word !important;
    white-space: pre-wrap !important;
    overflow-wrap: break-word !important;
    hyphens: none !important;
    margin-left: auto;
}

/* AI message plain text (no bubble) */
.message-assistant.message-text {
    color: var(--text-primary) !important;
    padding: 12px 16px;
    word-break: break-word;
    white-space: pre-wrap;
    line-height: 1.6;
    font-size: 14px;
}

/* Remove AntdCard default styling */
.message-bubble .ant-card {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

.message-bubble .ant-card-body {
    padding: 0 !important;
    background: transparent !important;
}

/* Hover effects (only for user messages with bubbles) */
.message-user .message-bubble:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

/* === MESSAGE AVATAR === */
.message-avatar {
    flex-shrink: 0;
    margin-right: 8px;
    margin-top: 2px;
}

.message-avatar .ant-avatar {
    background-color: var(--bg-message-user) !important;
}

/* === EMPTY STATE === */
.chat-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px 20px;
}

.chat-empty .ant-empty {
    color: var(--text-muted) !important;
}

.chat-empty .ant-empty-description {
    color: var(--text-muted) !important;
}

/* === LOADING / TYPING INDICATOR === */
/* Hide typing indicator when not in use */
#typing-indicator-display.typing-hidden {
    display: none !important;
}

/* Show typing indicator when active */
#typing-indicator-display.typing-visible {
    display: flex !important;
    visibility: visible !important;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    width: fit-content;
    margin: 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-10px);
    }
}

/* === STREAMING MESSAGE STYLES === */
/* Hide streaming display completely when not in use */
#sse-streaming-display.streaming-hidden {
    display: none !important;
}

/* Show streaming display when active */
#sse-streaming-display.streaming-active {
    display: flex !important;
    visibility: visible !important;
}

/* Intermediate state: stream done but keep layout space to prevent scroll jump */
#sse-streaming-display.streaming-done {
    display: flex !important;
    visibility: hidden !important;
    /* Maintains layout space until final message renders */
}

.streaming-text {
    color: var(--text-primary) !important;
    padding: 12px 16px;
    word-break: normal !important;
    word-wrap: break-word !important;
    white-space: pre-wrap !important;
    overflow-wrap: break-word !important;
    font-size: 14px !important;
    line-height: 1.6 !important;
}

/* Streaming cursor animation */
.streaming-cursor {
    animation: blink-cursor 1s step-start infinite;
    margin-left: 2px;
    color: var(--text-primary);
    font-weight: bold;
}

@keyframes blink-cursor {
    50% {
        opacity: 0;
    }
}

/* === MARKDOWN MESSAGE STYLES === */
/* Base typography - match existing plain text */
.markdown-message-content {
    color: var(--text-primary) !important;
    font-family: var(--font-family) !important;
    font-size: 14px !important;
    line-height: 1.6 !important;
    padding: 12px 16px;
    word-break: break-word;
    white-space: normal;
    width: 100%;  /* Force full width */
    max-width: 100%;
    background: transparent !important;
    box-sizing: border-box;  /* Include padding in width calculation */
}

/* Override FefferyMarkdown default container styles */
.markdown-message-content > div {
    background: transparent !important;
    color: var(--text-primary) !important;
    display: block;  /* Ensure full width for nested elements */
    width: 100%;  /* Force full width */
    box-sizing: border-box;
}

/* Markdown headings */
.markdown-message-content h1,
.markdown-message-content h2,
.markdown-message-content h3,
.markdown-message-content h4,
.markdown-message-content h5,
.markdown-message-content h6 {
    color: var(--text-primary) !important;
    font-family: var(--font-family) !important;
    margin-top: 16px;
    margin-bottom: 8px;
}

.markdown-message-content h1 { font-size: 24px; font-weight: 600; }
.markdown-message-content h2 { font-size: 20px; font-weight: 600; }
.markdown-message-content h3 { font-size: 18px; font-weight: 600; }
.markdown-message-content h4 { font-size: 16px; font-weight: 600; }
.markdown-message-content h5 { font-size: 14px; font-weight: 600; }
.markdown-message-content h6 { font-size: 13px; font-weight: 600; }

/* Markdown paragraphs */
.markdown-message-content p {
    margin-top: 0;
    margin-bottom: 8px;
    color: var(--text-primary) !important;
}

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

/* Markdown code blocks */
.markdown-message-content pre {
    background: #1f2937 !important;
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    max-width: 100%;
    margin: 12px 0;
}

.markdown-message-content pre code {
    background: transparent !important;
    padding: 0 !important;
    font-family: Monaco, "Courier New", Consolas, monospace;
    font-size: 13px;
    line-height: 1.5;
}

/* Inline code */
.markdown-message-content code {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: Monaco, "Courier New", Consolas, monospace;
}

/* Markdown lists */
.markdown-message-content ul,
.markdown-message-content ol {
    margin-top: 0;
    margin-bottom: 8px;
    margin-left: 20px;
    padding-left: 0;
}

.markdown-message-content li {
    margin-bottom: 2px;
    line-height: 1.5;
}

.markdown-message-content li:last-child {
    margin-bottom: 0;
}

/* Markdown links */
.markdown-message-content a {
    color: #60a5fa;
    text-decoration: underline;
    transition: color 0.2s ease;
}

.markdown-message-content a:hover {
    color: #93c5fd;
}

/* Markdown blockquotes */
.markdown-message-content blockquote {
    border-left: 3px solid var(--accent-blue);
    padding-left: 12px;
    margin-left: 0;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

/* Markdown tables */
.markdown-message-content table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 12px;
}

.markdown-message-content th,
.markdown-message-content td {
    border: 1px solid var(--border-color);
    padding: 8px;
    text-align: left;
}

.markdown-message-content th {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
}

/* === MESSAGE ACTIONS === */
.message-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.message-wrapper:hover .message-actions {
    opacity: 1;
}

.message-action-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
}

.message-action-btn:hover {
    background: var(--bg-input);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

/* === SCROLL BUTTON === */
/* Scroll-down button wrapper with fixed positioning */
#scroll-button-wrapper {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

/* Show button when visible (controlled by clientside callback) */
#scroll-button-wrapper.scroll-btn-visible {
    opacity: 1;
    pointer-events: auto;
}

/* Hover effect for scroll button */
#scroll-down-button:hover {
    background-color: #383838 !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4) !important;
}

/* === UTILITY CLASSES === */
.hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* === FIX FOR ANTD CARD WITHIN MESSAGES === */
.message-bubble .ant-card-bordered {
    border: none !important;
}

/* === RESPONSIVE MESSAGE ADJUSTMENTS === */
@media (max-width: 768px) {
    .message-assistant {
        max-width: 100%;
    }

    .message-user .message-bubble {
        max-width: 80% !important;
    }
}

/* ============================================
   Tool Call Accordion (HTML <details> element)
   Slim, compact ChatGPT-style design with visual grouping
   ============================================ */

/* Main details container - slim styling */
.markdown-message-content details {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    margin: 10px 0;
    padding: 0;
    overflow: hidden;
    transition: border-color 0.2s ease;
    width: 100%;  /* Full width from the start */
    display: block;  /* Force block-level layout */
    box-sizing: border-box;  /* Include border in width calculation */
}

.markdown-message-content details:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

.markdown-message-content details[open] {
    border-color: rgba(255, 255, 255, 0.15);
}

/* Visual grouping - consecutive accordions connected */
.markdown-message-content details + details {
    margin-top: 0;
    border-top: none;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.markdown-message-content details:has(+ details) {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    margin-bottom: 0;
}

/* Summary (clickable header) - compact padding */
.markdown-message-content details summary {
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 400;
    font-size: 13px;
    color: #b0b0b0;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 8px;
    list-style: none;
    transition: background-color 0.2s ease;
    line-height: 1.4;
}

.markdown-message-content details summary:hover {
    background: rgba(255, 255, 255, 0.03);
}

.markdown-message-content details[open] summary {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* Remove default disclosure triangle */
.markdown-message-content details summary::-webkit-details-marker {
    display: none;
}

/* Icon on LEFT side - Font Awesome magnifying glass for search/query indication */
.markdown-message-content details summary::before {
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    content: '\f002 ';  /* fa-magnifying-glass (search icon) */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Web search - globe icon */
.markdown-message-content details[data-tool="websearch"] summary::before {
    content: '\f0ac ';  /* fa-globe */
}

/* Web fetch - download icon */
.markdown-message-content details[data-tool="webfetch"] summary::before {
    content: '\f019 ';  /* fa-download */
}

/* Chevron arrow on RIGHT side (Font Awesome icons for professional look) */
.markdown-message-content details summary::after {
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    content: '\f078';  /* fa-chevron-down - collapsed state */
    display: inline-block;
    font-size: 12px;
    margin-left: auto;  /* Push to right */
    color: #888;
    flex-shrink: 0;
}

.markdown-message-content details[open] summary::after {
    content: '\f077';  /* fa-chevron-up - expanded state */
}

/* Content area - compact padding */
.markdown-message-content details > :not(summary) {
    padding: 12px 14px;
}

/* SQL code block inside details - compact styling */
.markdown-message-content details pre {
    margin: 0;
    border-radius: 6px;
    font-size: 12px;
}

.markdown-message-content details .hljs {
    background: #1a1a1a !important;
    padding: 10px !important;
}
