/* ── Base ─────────────────────────────────────────────── */
*, *::before, *::after {
    scrollbar-width: thin;
    scrollbar-color: var(--sb-thumb) transparent;
}

html {
    --sb-thumb: #c7c7c7;
}
html.dark {
    --sb-thumb: #333;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--sb-thumb); border-radius: 3px; }

/* Textarea auto-resize helper */
#questionInput {
    field-sizing: content;
}

/* ── Suggestion chips ────────────────────────────────── */
.suggestion-chip {
    text-align: left;
    font-size: 1rem;
    padding: 0.625rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid #e5e7eb;
    background: #fff;
    color: #374151;
    transition: all 0.2s;
    cursor: pointer;
}
.dark .suggestion-chip {
    border-color: #1f2937;
    background: #111827;
    color: #d1d5db;
}
.suggestion-chip:hover {
    border-color: #fb923c;
    background: #fff7ed;
}
.dark .suggestion-chip:hover {
    border-color: #f97316;
    background: rgba(67, 20, 7, 0.4);
}

/* ── Message bubbles ─────────────────────────────────── */
.msg {
    animation: slideUp 0.4s ease-out;
}

.msg-user {
    display: flex;
    justify-content: flex-end;
}

.msg-user .msg-bubble {
    background: #ea580c;
    color: #fff;
    border-radius: 1rem;
    border-bottom-right-radius: 0.375rem;
    padding: 0.625rem 1rem;
    max-width: 80%;
    font-size: 1rem;
    line-height: 1.625;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.msg-ai {
    display: flex;
    justify-content: flex-start;
    gap: 0.625rem;
}

.msg-ai .msg-avatar {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.5rem;
    background: linear-gradient(to bottom right, #f97316, #c2410c);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 0.125rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.msg-ai .msg-avatar svg {
    width: 0.875rem;
    height: 0.875rem;
    color: #fff;
}

.msg-ai .msg-bubble {
    background: #fff;
    border: 1px solid #f3f4f6;
    border-radius: 1rem;
    border-bottom-left-radius: 0.375rem;
    padding: 0.625rem 1rem;
    max-width: 80%;
    font-size: 1rem;
    line-height: 1.625;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.dark .msg-ai .msg-bubble {
    background: #111827;
    border-color: #1f2937;
}

/* ── Markdown inside AI messages ─────────────────────── */
.msg-ai .msg-bubble p {
    margin-bottom: 0.5rem;
}
.msg-ai .msg-bubble p:last-child {
    margin-bottom: 0;
}

.msg-ai .msg-bubble strong {
    font-weight: 600;
    color: #111827;
}
.dark .msg-ai .msg-bubble strong {
    color: #f3f4f6;
}

.msg-ai .msg-bubble em {
    font-style: italic;
    color: #4b5563;
}
.dark .msg-ai .msg-bubble em {
    color: #9ca3af;
}

.msg-ai .msg-bubble code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.75rem;
    background: #f3f4f6;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
}
.dark .msg-ai .msg-bubble code {
    background: #1f2937;
}

.msg-ai .msg-bubble pre {
    margin: 0.5rem 0;
    padding: 0.75rem;
    background: #f3f4f6;
    border-radius: 0.5rem;
    overflow-x: auto;
}
.dark .msg-ai .msg-bubble pre {
    background: #1f2937;
}

.msg-ai .msg-bubble pre code {
    background: transparent;
    padding: 0;
}

.msg-ai .msg-bubble ul {
    list-style-type: disc;
    list-style-position: inside;
    margin-bottom: 0.5rem;
}

.msg-ai .msg-bubble ol {
    list-style-type: decimal;
    list-style-position: inside;
    margin-bottom: 0.5rem;
}

.msg-ai .msg-bubble a {
    color: #f97316;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.msg-ai .msg-bubble a:hover {
    color: #fb923c;
}

.msg-ai .msg-bubble h1,
.msg-ai .msg-bubble h2,
.msg-ai .msg-bubble h3 {
    font-weight: 600;
    margin-top: 0.75rem;
    margin-bottom: 0.25rem;
    color: #111827;
}
.dark .msg-ai .msg-bubble h1,
.dark .msg-ai .msg-bubble h2,
.dark .msg-ai .msg-bubble h3 {
    color: #f3f4f6;
}

.msg-ai .msg-bubble blockquote {
    border-left: 2px solid #fb923c;
    padding-left: 0.75rem;
    font-style: italic;
    color: #4b5563;
    margin: 0.5rem 0;
}
.dark .msg-ai .msg-bubble blockquote {
    color: #9ca3af;
}

/* ── Typing indicator ────────────────────────────────── */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
}

.typing-indicator span {
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 50%;
    background: #9ca3af;
    animation: pulseDot 1.4s ease-in-out infinite;
}
.dark .typing-indicator span {
    background: #6b7280;
}

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

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

/* ── Error state ─────────────────────────────────────── */
.msg-error .msg-bubble {
    border-color: #fecaca !important;
    background: #fef2f2 !important;
    color: #b91c1c !important;
}
.dark .msg-error .msg-bubble {
    border-color: rgba(127, 29, 29, 0.5) !important;
    background: rgba(127, 29, 29, 0.15) !important;
    color: #f87171 !important;
}

.msg-error .msg-error-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    max-width: 80%;
}

.retry-btn {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    gap: 0.25rem;
    margin-top: 0;
    padding: 0.25rem 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid #fca5a5;
    background: #fff;
    color: #b91c1c;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.retry-btn:hover {
    background: #fee2e2;
    border-color: #f87171;
}
.dark .retry-btn {
    background: transparent;
    border-color: rgba(248, 113, 113, 0.4);
    color: #f87171;
}
.dark .retry-btn:hover {
    background: rgba(127, 29, 29, 0.25);
}

/* ── Keyframes ───────────────────────────────────────── */
@keyframes slideUp {
    0% { opacity: 0; transform: translateY(12px); }
    100% { opacity: 1; transform: translateY(0); }
}

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