/* OpenWebUI-inspired Clean Dark Theme */
:root {
    /* Gray scale - OpenWebUI style */
    --gray-50: oklch(0.98 0 0);
    --gray-100: oklch(0.94 0 0);
    --gray-200: oklch(0.92 0 0);
    --gray-300: oklch(0.85 0 0);
    --gray-400: oklch(0.77 0 0);
    --gray-500: oklch(0.69 0 0);
    --gray-600: oklch(0.51 0 0);
    --gray-700: oklch(0.42 0 0);
    --gray-800: oklch(0.32 0 0);
    --gray-850: oklch(0.27 0 0);
    --gray-900: oklch(0.2 0 0);
    --gray-950: oklch(0.16 0 0);
    
    /* Primary accent - subtle blue */
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-light: rgba(59, 130, 246, 0.1);
    
    /* Semantic colors */
    --success: #22c55e;
    --error: #ef4444;
    --warning: #f59e0b;
    
    /* Layout */
    --sidebar-width: 280px;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', ui-sans-serif, system-ui, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-900);
    color: var(--gray-100);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--gray-700);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray-600);
}

/* Selection */
::selection {
    background: var(--accent-light);
    color: white;
}

/* App Layout */
.app {
    display: flex;
    height: 100vh;
    height: 100dvh;
    max-width: 1600px;
    margin: 0 auto;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-950);
    border-right: 1px solid var(--gray-800);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--gray-800);
}

.sidebar-header h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-100);
    margin-bottom: 4px;
}

.subtitle {
    font-size: 13px;
    color: var(--gray-500);
}

.experts-list {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}

/* Expert Cards */
.expert-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: transparent;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background var(--transition-fast);
    text-align: left;
    width: 100%;
    color: var(--gray-300);
    font-family: inherit;
    font-size: 14px;
}

.expert-card:hover {
    background: var(--gray-800);
}

.expert-card.active {
    background: var(--gray-800);
    color: var(--gray-100);
}

.expert-icon {
    width: 36px;
    height: 36px;
    background: var(--gray-800);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.expert-card.active .expert-icon {
    background: var(--accent);
}

.expert-info h3 {
    font-size: 14px;
    font-weight: 500;
    color: inherit;
    margin-bottom: 2px;
}

.expert-info p {
    font-size: 12px;
    color: var(--gray-500);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-800);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.api-status {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--gray-400);
}

.logout-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--gray-500);
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.logout-btn:hover {
    background: var(--gray-800);
    color: var(--text-primary);
}

.status-dot {
    width: 32px;
    height: 32px;
    background: var(--success);
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-900);
    background-size: cover;
    background-position: center;
}

/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--gray-900);
}

/* Chat Header */
.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--gray-800);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.current-expert {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.expert-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-100);
}

.expert-badge {
    font-size: 10px;
    padding: 4px 10px;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 20px;
    font-weight: 500;
}

.clear-btn {
    font-size: 13px;
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--gray-700);
    border-radius: 8px;
    color: var(--gray-400);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
}

.clear-btn:hover {
    background: var(--gray-800);
    border-color: var(--gray-600);
    color: var(--gray-200);
}

/* Messages Area */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome-message {
    max-width: 480px;
    margin: auto;
    text-align: center;
    padding: 48px 24px;
}

.welcome-message h2 {
    font-size: 24px;
    font-weight: 600;
    color: var(--gray-100);
    margin-bottom: 0;
}

.welcome-message p {
    color: var(--gray-400);
    line-height: 1.7;
    font-size: 15px;
}

/* Message Bubbles */
.message {
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    padding: 16px 20px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.7;
}

.message.user {
    background: var(--gray-800);
    margin-left: auto;
}

.message.assistant {
    background: var(--gray-850);
    border: 1px solid var(--gray-800);
}

.message-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--gray-700);
}

.message-actions button {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--gray-800);
    border: 1px solid var(--gray-700);
    border-radius: 6px;
    color: var(--gray-400);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.message-actions button:hover {
    background: var(--gray-700);
    color: var(--gray-200);
}

.message-actions button svg {
    width: 14px;
    height: 14px;
}

.message.user .message-actions {
    justify-content: flex-end;
}

.message.assistant .message-actions {
    justify-content: flex-start;
}

.message-header {
    font-size: 12px;
    font-weight: 500;
    color: var(--gray-500);
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Typing indicator - visible typing dots in header */
.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 0 6px;
    align-items: center;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: var(--accent);
    border-radius: 50%;
    animation: typingBounce 1.2s infinite ease-in-out;
}

.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 typingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

.message-header .streaming-dots {
    padding: 0;
    gap: 3px;
}

.message-header .streaming-dots span {
    width: 5px;
    height: 5px;
    background: var(--gray-500);
}

.message-header .thinking-toggle-btn {
    display: none;
}

.message-header .thinking-toggle-btn.active {
    color: var(--accent);
    background: var(--accent-light);
    border-color: var(--accent);
}

.message-content {
    color: var(--gray-200);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.streaming .streaming-content {
    white-space: normal;
}

.message.streaming .streaming-content.markdown-body p {
    margin: 8px 0;
}

.message.streaming .streaming-content.markdown-body p:first-child {
    margin-top: 0;
}

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

/* Thinking Section */
.thinking-section {
    margin-bottom: 0;
}

.thinking-section .thinking-content {
    font-size: 10px;
    color: var(--gray-500);
    font-style: italic;
    line-height: 1.4;
    opacity: 0.7;
}
    display: none;
}

.thinking-section .thinking-content {
    font-size: 10px;
    color: var(--gray-500);
    font-style: italic;
    line-height: 1.4;
    opacity: 0.7;
}

/* Markdown Styling */
.message-content.markdown-body {
    font-size: 15px;
    line-height: 1.7;
}

.message-content.markdown-body h1,
.message-content.markdown-body h2,
.message-content.markdown-body h3 {
    font-weight: 600;
    margin: 16px 0 8px 0;
    color: var(--gray-100);
}

.message-content.markdown-body h1 { font-size: 1.4em; }
.message-content.markdown-body h2 { font-size: 1.2em; }
.message-content.markdown-body h3 { font-size: 1.1em; }

.message-content.markdown-body p {
    margin: 8px 0;
}

.message-content.markdown-body p:first-child {
    margin-top: 0;
}

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

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

.message-content.markdown-body code {
    background: var(--gray-800);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: ui-monospace, 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.9em;
}

.message-content.markdown-body pre {
    background: var(--gray-950);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid var(--gray-800);
}

.message-content.markdown-body pre code {
    background: none;
    padding: 0;
    font-size: 13px;
}

.message-content.markdown-body blockquote {
    border-left: 3px solid var(--gray-700);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--gray-400);
    font-style: italic;
}

.message-content.markdown-body a {
    color: var(--accent);
    text-decoration: none;
}

.message-content.markdown-body a:hover {
    text-decoration: underline;
}

.message-content.markdown-body strong {
    font-weight: 600;
}

/* Streaming dots animation */
.streaming-dots {
    display: inline-flex;
    gap: 4px;
    padding: 8px 0;
}

.streaming-dots.inline {
    padding: 0;
    gap: 3px;
    vertical-align: middle;
}

.streaming-dots.inline span {
    width: 6px;
    height: 6px;
}

.streaming-dots span {
    width: 8px;
    height: 8px;
    background: var(--gray-500);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.streaming-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.streaming-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Area */
.input-area {
    padding: 20px 24px;
    padding-bottom: calc(20px + var(--safe-area-bottom));
    border-top: 1px solid var(--gray-800);
    display: flex;
    gap: 12px;
    background: var(--gray-900);
}

.input-area textarea {
    flex: 1;
    background: var(--gray-850);
    border: 1px solid var(--gray-800);
    border-radius: 12px;
    padding: 14px 16px;
    color: var(--gray-100);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color var(--transition-fast);
    line-height: 1.5;
    -webkit-appearance: none;
    appearance: none;
}

.input-area textarea::-webkit-resizer {
    display: none;
}

.input-area textarea::-webkit-scrollbar {
    display: none;
}

.input-area textarea:focus {
    border-color: var(--gray-600);
}

.input-area textarea::placeholder {
    color: var(--gray-500);
}

.send-btn {
    width: 48px;
    height: 48px;
    background: var(--gray-800);
    border: none;
    border-radius: 12px;
    color: var(--gray-300);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--gray-700);
    color: var(--gray-100);
}

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

/* Mobile */
@media (max-width: 768px) {
    .app {
        flex-direction: column;
        height: 100dvh;
        height: -webkit-fill-available;
        overflow: hidden;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        max-width: 300px;
        height: 100dvh;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar-overlay.visible {
        display: block;
    }

    .chat-container {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .chat-header {
        padding: 16px;
        flex-shrink: 0;
    }

    .messages {
        flex: 1;
        min-height: 0;
        padding: 16px;
        overflow-y: auto;
    }

    .input-area {
        padding: 16px;
        flex-shrink: 0;
        background: var(--gray-900);
    }

    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: var(--gray-800);
        border: none;
        border-radius: 10px;
        color: var(--gray-300);
        cursor: pointer;
        margin-right: 12px;
        flex-shrink: 0;
    }

    .mobile-menu-btn:active {
        background: var(--gray-700);
    }

    .welcome-message {
        padding: 32px 16px;
    }

    .welcome-message h2 {
        font-size: 20px;
    }

    .message {
        padding: 12px 16px;
        border-radius: 10px;
    }

    .expert-badge {
        display: none;
    }

    .clear-btn {
        padding: 8px 12px;
        font-size: 12px;
    }
}

@media (min-width: 769px) {
    .mobile-menu-btn {
        display: none;
    }

    .sidebar-overlay {
        display: none !important;
    }
}

/* Touch targets */
@media (pointer: coarse) {
    .expert-card {
        min-height: 56px;
    }

    .clear-btn {
        min-height: 44px;
    }

    .send-btn {
        width: 52px;
        height: 52px;
    }
}

/* Focus states */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Visually hidden */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
