/* Chatbot tab styles - extracted, pruned, partial Tailwind; tokens + stable sidebar sizing. */

/* Design tokens (mirror tailwind.config.js semantic colors) */
#chatbot-container {
    --chat-ink: #0F172A;
    --chat-accent: #0F766E;
    --chat-accent-hover: #115E59;
    --chat-highlight: #F0FDFA;
    --chat-highlight-ink: #134E4A;
    --chat-mute: #64748B;
    --chat-surface: #F3F1EB;
    --chat-canvas: #EBE8E1;
    --chat-panel: #FFFFFF;
    --chat-line: #E4E1D9;
    --chat-brand-soft: #EEECE6;
    --chat-danger: #DC2626;
}

/* Smooth transitions for sidebar collapse */
#chat-sidebar {
    resize: none; /* Disable native resize to use custom handle */
}

/* Desktop sidebar collapse styles */
@media (min-width: 768px) {
    #chat-sidebar.sidebar-expanded {
        width: var(--sidebar-width, 24rem); /* Default 24rem (384px), was 16rem */
        min-width: 18rem; /* Minimum width */
        max-width: 40rem; /* Maximum width */
    }
    
    #chat-sidebar.sidebar-collapsed {
        width: 0;
        min-width: 0;
        border-right-width: 0;
        overflow: hidden;
    }
}

/* Ensure mobile behavior isn't affected */
@media (max-width: 767px) {
    #chat-sidebar.sidebar-collapsed {
        width: 16rem; /* w-64 - keep mobile width fixed */
        min-width: 16rem;
        border-right-width: 4px;
    }
}

/* Resize handle styles */
.resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: transparent;
    cursor: col-resize;
    z-index: 10;
    transition: background-color 0.2s ease;
}

.resize-handle:hover {
    background: #e5e7eb;
}

.resize-handle:active {
    background: #CBD5E1;
}

/* Visual indicator on hover */
.resize-handle::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 30px;
    background: #d1d5db;
    border-radius: 1px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.resize-handle:hover::after {
    opacity: 1;
}

/* Chat title wrapping styles - use higher specificity to override Tailwind */
#chat-sidebar .chat-item .chat-title {
    /* Force wrapping and override any Tailwind truncate classes */
    white-space: normal !important;
    text-overflow: clip !important;
    overflow: visible !important;
    line-height: 1.4 !important;
    max-height: none !important; /* Allow unlimited height instead of limiting to 2 lines */
    display: block !important;
    word-wrap: break-word !important;
    word-break: break-word !important;
    hyphens: auto;
    -webkit-hyphens: auto;
    -moz-hyphens: auto;
    min-height: 1.4em; /* Ensure at least one line height */
    margin-bottom: 0.25rem;
    padding-right: 0.5rem;
}

/* Better chat item layout for improved title visibility */
#chat-sidebar .chat-item {
    transition: background-color 0.15s ease;
    min-height: 0 !important;
}

/* Ensure the title container uses available space */
#chat-sidebar .chat-item .flex-1.min-w-0 {
    overflow: visible !important;
    min-width: 0 !important;
    flex: 1 1 0% !important;
}

/* Make sidebar content more responsive to width changes */
@media (min-width: 768px) {
    #chat-sidebar {
        /* Ensure content reflows when sidebar width changes */
        contain: layout style;
    }
    
    /* Optimize for wider sidebars - increased specificity */
    #chat-sidebar.sidebar-expanded .chat-item {
        padding: 0.5rem 0.625rem !important;
        min-height: 0 !important;
    }
    
    #chat-sidebar.sidebar-expanded .chat-item .chat-title {
        font-size: 0.925rem !important; /* Slightly larger text when there's more space */
        line-height: 1.35 !important;
        margin-bottom: 0.375rem !important;
    }
}

/* Responsive chat alignment system */
#chat-history {
    /* Extra bottom space so the last line is not hidden behind the floating scroll control */
    padding-bottom: max(5rem, calc(env(safe-area-inset-bottom, 0px) + 4rem));
    /*
     * Asymmetric gutters: outer = left of assistant / right of user (usually tighter);
     * inner = toward the middle (user left, assistant right).
     */
    --chat-gutter-inner: clamp(0.5rem, 2vw, 2rem);
    --chat-gutter-outer: clamp(0.125rem, 1.25vw, 0.875rem);
    --chat-message-max-width: min(110ch, calc(100% - var(--chat-gutter-outer) - var(--chat-gutter-inner)));
    /* Keep tool/process panel aligned with assistant bubbles */
    --chat-process-max-width: var(--chat-message-max-width);
    /*
     * Message overlap: assistant and user columns each extend past center so the
     * horizontal overlap in the middle equals (overlap-ratio × inner row width).
     * Wider overlap gives both sides room for full answers while keeping alignment.
     */
    --overlap-ratio: 0.94;
    --chat-inner-span: calc(100% - var(--chat-gutter-outer) - var(--chat-gutter-inner));
    /*
     * Use max(readability cap, overlap reach). A plain min(cap, overlap) always
     * picked the smaller ch cap on desktop, so overlap never appeared for any chat.
     */
    --chat-bubble-overlap-width: min(
        100%,
        max(
            var(--chat-message-max-width),
            calc(var(--chat-inner-span) * (0.5 + var(--overlap-ratio) * 0.5))
        )
    );
}

@media (min-width: 768px) and (max-width: 1023px) {
    #chat-history {
        --overlap-ratio: 0.8;
    }
}

#chat-history .chat-row {
    display: flex;
    width: 100%;
    min-width: 0;
}

#chat-history .chat-row-user {
    justify-content: flex-end;
    padding-left: var(--chat-gutter-inner);
    padding-right: var(--chat-gutter-outer);
}

#chat-history .chat-row-assistant {
    justify-content: flex-start;
    padding-left: var(--chat-gutter-outer);
    padding-right: var(--chat-gutter-inner);
}

#chat-history .chat-row-center {
    justify-content: center;
    padding-left: var(--chat-gutter-inner);
    padding-right: var(--chat-gutter-inner);
}

#chat-history .chat-bubble-shell,
#chat-history .chat-process-shell {
    flex: 0 1 auto;
    width: min(100%, var(--chat-bubble-overlap-width));
    max-width: min(100%, var(--chat-bubble-overlap-width));
    min-width: 0;
}

/* Desktop: modest inner channel; outer edges (assistant left / user right) stay tighter until very wide */
@media (min-width: 1024px) {
    #chat-history {
        --overlap-ratio: 0.7;
        --chat-gutter-inner: clamp(0.625rem, 1.75vw, 1.25rem);
        --chat-gutter-outer: clamp(0.125rem, 0.55vw, 0.5rem);
        --chat-message-max-width: min(108ch, calc(100% - var(--chat-gutter-outer) - var(--chat-gutter-inner)));
        --chat-process-max-width: var(--chat-message-max-width);
    }
}

@media (min-width: 1280px) {
    #chat-history {
        --overlap-ratio: 0.78;
        --chat-message-max-width: min(118ch, calc(100% - var(--chat-gutter-outer) - var(--chat-gutter-inner)));
        --chat-process-max-width: var(--chat-message-max-width);
    }
}

@media (min-width: 1536px) {
    #chat-history {
        --overlap-ratio: 0.85;
        --chat-message-max-width: min(128ch, calc(100% - var(--chat-gutter-outer) - var(--chat-gutter-inner)));
        --chat-process-max-width: var(--chat-message-max-width);
    }
}

@media (min-width: 1920px) {
    #chat-history {
        --chat-gutter-inner: clamp(3rem, 7vw, 10rem);
        --chat-gutter-outer: clamp(3rem, 7vw, 10rem);
    }
}

/* Mobile optimizations - near edge-to-edge */
@media (max-width: 767px) {
    #chat-history {
        --chat-gutter-inner: 0.125rem;
        --chat-gutter-outer: 0.125rem;
        --chat-message-max-width: 100%;
        --chat-process-max-width: 100%;
        --overlap-ratio: 0.94;
    }
    
    /* Make mobile sidebar less transparent */
    #chat-sidebar {
        background-color: var(--chat-canvas) !important; /* canvas parchment */
        width: min(20rem, 92vw) !important;
        min-width: min(20rem, 92vw) !important;
    }

    #chat-sidebar.sidebar-collapsed {
        width: min(20rem, 92vw) !important;
        min-width: min(20rem, 92vw) !important;
    }

    #chat-sidebar > .flex-1.overflow-y-auto {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        padding-left: 0.375rem;
        padding-right: 0.375rem;
    }

    .chat-list-section-header,
    .chat-mode-group-header {
        min-height: 2.75rem;
    }

    #chat-sidebar .chat-item {
        min-height: 3.25rem !important;
        padding: 0.75rem !important;
    }

    #chat-sidebar .chat-item:hover,
    #chat-sidebar .chat-item.chat-item-active {
        transform: none;
    }

    #chat-sidebar .chat-menu-btn {
        min-width: 2.75rem;
        min-height: 2.75rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    #chat-sidebar [id^="chat-menu-"] {
        min-width: 11rem;
    }
}

/* Tool execution card styles */
.tool-execution-card {
    animation: slideInFromLeft 0.3s ease-out;
}

@keyframes slideInFromLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Tool card inner surface */
.tool-exec-card-inner {
    background: var(--chat-panel);
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.tool-execution-card .tool-exec-card-inner:hover {
    box-shadow: none;
    transform: none;
}

.agent-process-collapsible .agent-process-body .tool-execution-card {
    margin-bottom: 0 !important;
}

.agent-process-collapsible > div {
    background: #F8F7F4;
    border-color: var(--chat-line);
}

.agent-process-toggle:hover {
    background: rgba(255, 255, 255, 0.55);
}

.agent-process-body {
    background: var(--chat-panel);
    overflow-x: hidden;
    max-width: 100%;
}

/* Process steps were built with .chat-row gutters; inside the collapsible body that doubled padding and broke flex rows */
#chat-history .agent-process-body .tool-execution-card.chat-row {
    padding-left: 0 !important;
    padding-right: 0 !important;
}

#chat-history .agent-process-body .chat-process-shell {
    width: 100%;
    max-width: 100%;
}

.agent-process-card-surface {
    border-radius: 0.75rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.agent-process-collapsible .agent-process-toggle {
    border-radius: 0;
}

.agent-process-collapsible > .chat-process-shell {
    border-radius: 0.75rem;
    overflow: hidden;
}

/* Compact subway timeline for agent tool execution */
.agent-process-panel {
    animation: fadeIn 0.25s ease-out;
}

.agent-process-panel-inner {
    box-shadow: none;
}

.agent-subway-list {
    max-height: min(12rem, 40vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.375rem 0.5rem 0.5rem;
    position: relative;
}

.agent-subway-list:not(:empty)::after {
    content: '';
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    display: block;
    height: 0.75rem;
    margin-top: -0.75rem;
    pointer-events: none;
    background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.95));
}

.agent-subway-round-divider {
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #94a3b8;
    padding: 0.375rem 0.5rem 0.125rem 1.75rem;
}

.agent-subway-step {
    display: flex;
    align-items: flex-start;
    gap: 0.375rem;
    min-height: 2rem;
    padding: 0.25rem 0.375rem;
    border-radius: 0.375rem;
    transition: background-color 0.15s ease;
}

.agent-subway-step.is-active {
    background: rgba(15, 118, 110, 0.08);
}

.agent-subway-step.is-expanded {
    background: rgba(248, 250, 252, 0.95);
}

.agent-subway-rail {
    position: relative;
    width: 1rem;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    padding-top: 0.375rem;
}

.agent-subway-rail::before {
    content: '';
    position: absolute;
    top: 1.125rem;
    bottom: -0.375rem;
    left: 50%;
    width: 2px;
    transform: translateX(-50%);
    background: #e2e8f0;
}

.agent-subway-step:last-child .agent-subway-rail::before,
.agent-subway-round-divider + .agent-subway-step:last-child .agent-subway-rail::before {
    display: none;
}

.agent-subway-node {
    position: relative;
    z-index: 1;
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 9999px;
    border: 2px solid #cbd5e1;
    background: #fff;
    flex-shrink: 0;
}

.agent-subway-step.is-active .agent-subway-node {
    border-color: var(--chat-accent);
    background: var(--chat-accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.2);
    animation: subway-pulse 1.2s ease-in-out infinite;
}

.agent-subway-step.is-done .agent-subway-node {
    border-color: #22c55e;
    background: #22c55e;
}

.agent-subway-step.is-error .agent-subway-node {
    border-color: #ef4444;
    background: #ef4444;
}

@keyframes subway-pulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15); }
    50% { box-shadow: 0 0 0 5px rgba(15, 118, 110, 0.25); }
}

.agent-subway-step-toggle {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: flex-start;
    gap: 0.375rem;
    text-align: left;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
}

.agent-subway-step-toggle-static {
    cursor: default;
    pointer-events: none;
}

.agent-subway-step-toggle-body {
    flex: 1;
    min-width: 0;
}

.agent-subway-step-label {
    display: block;
    font-size: 0.8125rem;
    line-height: 1.25rem;
    color: #334155;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agent-subway-step.is-active .agent-subway-step-label {
    color: var(--chat-accent-hover);
    font-weight: 500;
}

.agent-subway-step.is-error .agent-subway-step-label {
    color: #b91c1c;
}

.agent-subway-step-detail,
.agent-subway-step-error {
    display: none;
    margin-top: 0.125rem;
    font-size: 0.75rem;
    line-height: 1.125rem;
    white-space: normal;
}

.agent-subway-step.is-expanded .agent-subway-step-detail,
.agent-subway-step.is-expanded .agent-subway-step-error {
    display: block;
}

.agent-subway-step-detail {
    color: #64748b;
}

.agent-subway-step-error {
    color: #dc2626;
}

.agent-subway-step.is-expanded .agent-subway-step-label {
    white-space: normal;
}

.agent-subway-expand-chevron {
    margin-top: 0.2rem;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.agent-subway-step.is-expanded .agent-subway-expand-chevron {
    transform: rotate(180deg);
}

.agent-process-collapsible .agent-process-body .agent-process-panel {
    margin-bottom: 0 !important;
}

.agent-process-collapsible .agent-process-body .agent-process-panel > .chat-row,
#chat-history .agent-process-body .agent-process-panel.chat-row {
    padding-left: 0 !important;
    padding-right: 0 !important;
}

.agent-process-collapsible .agent-process-body .agent-subway-list {
    max-height: min(16rem, 50vh);
}

.sources-button-row {
    width: 100%;
    /* Padding comes from .chat-row-assistant (outer left / inner right) */
    justify-content: flex-start;
}

.sources-button-shell {
    width: min(100%, var(--chat-bubble-overlap-width));
    max-width: min(100%, var(--chat-bubble-overlap-width));
}

.sources-button-card {
    background: var(--chat-highlight);
    border: 1px solid var(--chat-line);
    box-shadow: none;
}

.message-search-context-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.625rem;
    border-top: 1px solid rgba(148, 163, 184, 0.35);
    font-size: 0.6875rem;
    line-height: 1.35;
    color: #64748b;
}

.search-context-label {
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #94a3b8;
    flex-shrink: 0;
}

.search-context-sep {
    color: #cbd5e1;
    user-select: none;
}

.search-context-mode {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-weight: 600;
    color: var(--chat-accent-hover);
    background: var(--chat-highlight);
    border: 1px solid var(--chat-line);
}

.search-context-mode-ev {
    color: var(--chat-highlight-ink);
    background: var(--chat-brand-soft);
    border-color: var(--chat-line);
}

.search-context-mode-cross_deposition {
    color: #0f766e;
    background: rgba(240, 253, 250, 0.95);
    border-color: rgba(153, 246, 228, 0.9);
}

.search-context-docs {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    min-width: 0;
}

.search-context-doc {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    padding: 0.125rem 0.45rem;
    border-radius: 9999px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-context-doc-depo {
    color: var(--chat-accent);
    background: var(--chat-highlight);
    border: 1px solid var(--chat-line);
}

.search-context-doc-file {
    color: #0f766e;
    background: rgba(240, 253, 250, 0.95);
    border: 1px solid rgba(153, 246, 228, 0.85);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ========================================
   ENHANCED MESSAGE BUBBLE STYLES
   ======================================== */

#chat-history {
    scroll-padding-bottom: 7rem;
}

/*
 * Empty/new chat: welcome uses h-full, but chat-history also has ~5rem bottom
 * padding for the scroll-to-bottom control. That combo always overflows.
 * Center with flex instead and drop the message-only padding while empty.
 */
#chat-history:has(#welcome-message:not(.hidden)),
#chat-history:has(#main-loading-state:not(.hidden)) {
    display: flex;
    flex-direction: column;
    padding-bottom: 0.5rem;
    overflow-y: auto;
}

#chat-history #welcome-message:not(.hidden),
#chat-history #main-loading-state:not(.hidden) {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
}

#chat-history > .message-container {
    margin-bottom: 0 !important;
}

#chat-history .chat-bubble-shell-user {
    /* Hug the question text; stay right-aligned in the row */
    width: fit-content;
    max-width: min(100%, var(--chat-message-max-width));
    flex: 0 1 auto;
    margin-left: auto;
}

#chat-history .message-bubble-assistant,
#chat-history .message-bubble-status,
#chat-history .message-bubble-error {
    position: relative;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    line-height: 1.55;
    overflow-x: auto;
}

#chat-history .message-bubble-user {
    position: relative;
    width: fit-content;
    max-width: 100%;
    min-width: 0;
    line-height: 1.55;
    padding: 0.75rem 1rem;
}

#chat-history .message-bubble-assistant > .flex,
#chat-history .message-bubble-assistant.message-streaming > .flex {
    min-width: 0;
    max-width: 100%;
}

#chat-history .message-bubble-assistant,
#chat-history .message-bubble-status,
#chat-history .message-bubble-error {
    padding: 0.875rem 3rem 0.875rem 1rem;
}

#chat-history .message-bubble-status,
#chat-history .message-bubble-error {
    padding-right: 1rem;
}

#chat-history .message-bubble-with-actions {
    padding-right: 3rem;
}

#chat-history .message-bubble-assistant .message-actions {
    opacity: 0.72;
}

#chat-history .message-bubble-assistant:hover .message-actions {
    opacity: 1;
}

#chat-history .message-content,
#chat-history .streaming-content,
#chat-history .user-message-content {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#chat-history .user-message-content {
    white-space: pre-wrap;
}

#chat-history .message-content > :first-child,
#chat-history .streaming-content > :first-child {
    margin-top: 0;
}

#chat-history .message-content > :last-child,
#chat-history .streaming-content > :last-child {
    margin-bottom: 0;
}

#chat-history .message-content p,
#chat-history .streaming-content p {
    margin: 0.5rem 0;
    line-height: 1.65;
}

#chat-history .message-content ul,
#chat-history .message-content ol,
#chat-history .streaming-content ul,
#chat-history .streaming-content ol {
    margin: 0.55rem 0 0.55rem 1.25rem;
    padding-left: 0.75rem;
}

#chat-history .message-content li,
#chat-history .streaming-content li {
    margin: 0.25rem 0;
}

#chat-history .message-content pre,
#chat-history .streaming-content pre {
    margin: 0.75rem 0;
    padding: 0.875rem;
    border-radius: 0.75rem;
    background: #0f172a;
    color: #e2e8f0;
    border: none;
    overflow-x: auto;
}

#chat-history .message-content pre code,
#chat-history .streaming-content pre code {
    display: block;
    color: inherit;
    background: transparent;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
    white-space: pre;
}

#chat-history .message-content :not(pre) > code,
#chat-history .streaming-content :not(pre) > code {
    background: rgba(15, 23, 42, 0.08);
    color: #334155;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.8125rem;
}

#chat-history .message-content .md-table-wrap,
#chat-history .streaming-content .md-table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

#chat-history .message-content .md-table-wrap table,
#chat-history .streaming-content .md-table-wrap table {
    width: 100%;
    table-layout: fixed;
}

#chat-history .message-content .md-table-cell,
#chat-history .streaming-content .md-table-cell {
    max-width: 0;
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    vertical-align: top;
}

#chat-history .message-content blockquote,
#chat-history .streaming-content blockquote {
    margin: 0.75rem 0;
    padding-left: 0.875rem;
    border-left: 3px solid #99F6E4;
    color: #475569;
}

/* Message fade-in animation */
@keyframes messageFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* User message bubble — fully rounded, no speech-tail square corner */
.message-bubble-user {
    animation: messageFadeIn 0.3s ease-out;
    background: #E8E4DB;
    color: #1C1917;
    box-shadow: none;
    border: 1px solid #D9D4C9;
    border-radius: 12px;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.message-bubble-user:hover {
    background: #E0DBD0;
    border-color: #CDC7BA;
    transform: none;
    box-shadow: none;
}

/* Assistant message bubble - flat panel */
.message-bubble-assistant {
    animation: messageFadeIn 0.3s ease-out;
    background: var(--chat-panel);
    box-shadow: none;
    border: 1px solid var(--chat-line);
    border-radius: 12px;
    transition: border-color 0.15s ease;
}

.message-bubble-assistant:hover {
    transform: none;
    box-shadow: none;
    border-color: #D4D0C6;
}

/* Status message bubble */
.message-bubble-status {
    animation: messageFadeIn 0.25s ease-out;
    background: #FFFBEB;
    box-shadow: none;
    border: 1px solid var(--chat-line);
    border-radius: 0.75rem;
}

/* Error message bubble */
.message-bubble-error {
    animation: messageFadeIn 0.25s ease-out;
    background: #FEF2F2;
    box-shadow: none;
    border: 1px solid #FECACA;
    border-radius: 0.75rem;
}

/* Streaming message container - subtle pulse while loading */
.message-streaming {
    animation: messageFadeIn 0.3s ease-out;
}
    50% {
        box-shadow: 0 0 0 1px rgba(15, 118, 110, 0.2);
    }
}

/* Message container hover to reveal actions */
.message-container {
    position: relative;
}

.message-container .message-actions {
    opacity: 0;
    transition: opacity 0.2s ease;
}

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

/* Credit notification styling */
.credit-notification {
    animation: messageFadeIn 0.3s ease-out;
}

/* ========================================
   SIDEBAR POLISH STYLES
   Warm parchment personality; teal used sparingly.
   Keep Your/Shared + mode grouping structure.
   ======================================== */

/* Sidebar header */
.sidebar-header-glass {
    background: linear-gradient(180deg, rgba(255, 252, 247, 0.9) 0%, rgba(235, 232, 225, 0.55) 100%);
    border-bottom: 1px solid var(--chat-line);
}

/* Sidebar footer */
.sidebar-footer-glass {
    background: linear-gradient(0deg, rgba(255, 252, 247, 0.85) 0%, rgba(235, 232, 225, 0.4) 100%);
    }

.sidebar-header-icon {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.65rem;
    background: linear-gradient(145deg, #FFFCF7 0%, #E8E4DB 100%);
    color: var(--chat-accent);
    border: 1px solid var(--chat-line);
    box-shadow: 0 1px 2px rgba(28, 25, 23, 0.04);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Chat item styling */
#chat-sidebar .chat-item {
    background: transparent;
    border: 1px solid transparent;
    box-shadow: none;
    transform: none;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

#chat-sidebar .chat-item:hover {
    transform: none;
    box-shadow: none;
    border-color: transparent;
    background: rgba(255, 252, 247, 0.7);
}

/* Active chat — warm surface + thin brand rail */
#chat-sidebar .chat-item.chat-item-active {
    background: #FFFCF7;
    border: 1px solid var(--chat-line);
    border-left: 3px solid var(--chat-accent);
    box-shadow: 0 1px 2px rgba(28, 25, 23, 0.04);
    transform: none;
}

#chat-sidebar .chat-item:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.28);
}

#chat-sidebar .new-chat-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.35);
}

#sidebar-collapse-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.28);
    border-radius: 0.5rem;
}

#chat-sidebar .chat-item.chat-item-active:hover {
    transform: none;
    background: #FFFCF7;
}

.chat-list-section {
    background: rgba(255, 252, 247, 0.55);
    border: 1px solid var(--chat-line);
    border-radius: 0.85rem;
    overflow: visible;
    box-shadow: 0 1px 2px rgba(28, 25, 23, 0.03);
}

.chat-list-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    min-height: 2.5rem;
    padding: 0.55rem 0.75rem;
    text-align: left;
    background: linear-gradient(180deg, #F7F4EC 0%, #F1EEE6 100%);
    border: none;
    border-bottom: 1px solid transparent;
    border-radius: 0.85rem;
    cursor: pointer;
    transition: background 0.15s ease;
}

.chat-list-section-shared .chat-list-section-header {
    background: linear-gradient(180deg, #F5F2EB 0%, #EEEBE3 100%);
}

.chat-list-section-header:hover,
.chat-list-section-header:focus-visible {
    background: var(--chat-canvas);
    outline: none;
}

.chat-list-section-header[aria-expanded="true"] {
    border-radius: 0.85rem 0.85rem 0 0;
    border-bottom-color: var(--chat-line);
}

.chat-list-section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    font-size: 0.8125rem;
    font-weight: 700;
    color: #3F3A32;
    letter-spacing: 0.01em;
    text-transform: none;
}

.chat-list-section-title svg {
    flex-shrink: 0;
    width: 0.95rem;
    height: 0.95rem;
    color: var(--chat-accent);
    opacity: 0.75;
}

.chat-list-section-count {
    flex-shrink: 0;
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1;
    padding: 0.18rem 0.45rem;
    border-radius: 9999px;
    background: rgba(15, 118, 110, 0.1);
    color: var(--chat-accent);
    text-transform: none;
    letter-spacing: 0;
}

.chat-list-section-shared .chat-list-section-count {
    background: rgba(120, 113, 108, 0.12);
    color: #57534E;
}

.chat-list-section-body:not(.hidden) {
    padding: 0.45rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.chat-list-section-body.hidden,
.chat-mode-group-body.hidden {
    display: none !important;
}

.chat-mode-group {
    border-radius: 0.7rem;
    border: 1px solid #E8E4DB;
    background: rgba(255, 255, 255, 0.72);
    overflow: visible;
}

.chat-mode-group-general,
.chat-mode-group-ev,
.chat-mode-group-cross_deposition {
    border-left: 1px solid #E8E4DB;
    background: rgba(255, 255, 255, 0.78);
}

.chat-mode-group-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    min-height: 2.25rem;
    padding: 0.45rem 0.6rem;
    text-align: left;
    background: transparent;
    border: none;
    border-radius: 0.7rem;
    cursor: pointer;
    transition: background 0.15s ease;
}

.chat-mode-group:has(.chat-mode-group-body:not(.hidden)) .chat-mode-group-header {
    border-radius: 0.7rem 0.7rem 0 0;
}

.chat-mode-group-header:hover,
.chat-mode-group-header:focus-visible {
    background: rgba(243, 240, 232, 0.85);
    outline: none;
}

.chat-mode-group-label {
    flex: 1;
    min-width: 0;
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.25;
    color: #44403C;
}

.chat-mode-group-count {
    flex-shrink: 0;
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1;
    padding: 0.15rem 0.4rem;
    border-radius: 9999px;
    background: rgba(168, 162, 158, 0.18);
    color: #57534E;
}

.chat-mode-group-body:not(.hidden) {
    padding: 0 0.35rem 0.35rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chat-mode-group-chevron,
.chat-list-section-chevron {
    flex-shrink: 0;
    width: 0.9rem;
    height: 0.9rem;
    color: #A8A29E;
    transition: transform 0.2s ease;
}

.chat-mode-group-chevron.is-expanded,
.chat-list-section-chevron.is-expanded {
    transform: rotate(90deg);
}

#chat-sidebar .chat-item-in-group {
    border-radius: 0.55rem;
}

#chat-sidebar .chat-menu-btn:hover {
    background: rgba(15, 118, 110, 0.08);
    color: var(--chat-accent);
}

/* Chat menu dropdown — match app header menus */
#chat-sidebar [id^="chat-menu-"] {
    background: #FFFCF7;
    box-shadow: 0 1px 2px rgba(28, 25, 23, 0.06);
    border: 1px solid var(--chat-line);
}

#chat-sidebar [id^="chat-menu-"].menu-up {
    top: auto;
    bottom: 100%;
    margin-bottom: 0.25rem;
}

/* Ensure chat-item with open menu stays above all others */
#chat-sidebar .chat-item.menu-open {
    z-index: 100 !important;
    position: relative !important;
}

#chat-sidebar .chat-mode-group:has(.chat-item.menu-open),
#chat-sidebar .chat-list-section:has(.chat-item.menu-open) {
    z-index: 50;
    position: relative;
}

/* Prevent hover transforms from pushing other items above the open menu */
#chat-sidebar .chat-item.menu-open ~ .chat-item {
    z-index: 1 !important;
}

/* New Chat — ink filled, brand hover */
.new-chat-btn {
    background: #1C1917;
    color: #FFFCF7;
    border: 1px solid #1C1917;
    position: relative;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(28, 25, 23, 0.12);
}

.new-chat-btn:hover {
    background: var(--chat-accent);
    border-color: var(--chat-accent);
    color: var(--chat-panel);
}

/* Empty state */
#empty-chat-state {
    animation: fadeIn 0.4s ease-out;
}

#empty-chat-state > div {
    background: transparent;
}

#empty-chat-state .empty-chat-icon {
    background: linear-gradient(145deg, #FFFCF7 0%, #E8E4DB 100%);
    color: var(--chat-accent);
    border: 1px solid var(--chat-line);
    box-shadow: 0 1px 2px rgba(28, 25, 23, 0.04);
}

/* Evidence/mode as a quiet toolbar inside the composer card */
.composer-context-bar {
    background: transparent;
    border: none;
    margin: 0.35rem 0 0;
    padding: 0.35rem 0.25rem 0.1rem;
    border-top: 1px solid #EDEAE3;
}

.composer-context-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    max-width: 11rem;
    padding: 0.2rem 0.45rem;
    border: none;
    border-radius: 0.4rem;
    background: transparent;
    color: #78716C;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1.2;
    box-shadow: none;
    transition: background 0.15s ease, color 0.15s ease;
}

.composer-context-chip:hover {
    background: rgba(0, 0, 0, 0.045);
    color: #1C1917;
    border-color: transparent;
}

.composer-context-chip svg {
    width: 0.875rem;
    height: 0.875rem;
    color: #A8A29E;
    flex-shrink: 0;
}

.composer-context-chip #selected-count,
.composer-context-chip #selected-contextual-count,
.composer-context-chip #chat-mode-trigger-label {
    font-size: 0.6875rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Open menus upward from the footer toolbar */
.composer-context-bar #dropdown-menu,
.composer-context-bar #contextual-dropdown-menu,
.composer-context-bar #chat-mode-menu {
    top: auto !important;
    bottom: 100% !important;
    margin-top: 0 !important;
    margin-bottom: 0.4rem !important;
    width: 18rem !important;
    max-width: min(20rem, 90vw) !important;
    left: 0;
    right: auto;
    z-index: 40;
}

.composer-context-bar #chat-mode-menu {
    left: auto;
    right: 0;
}

#send-button[data-mode="stop"] {
    background: #B45309;
}

#send-button[data-mode="stop"]:hover:not(:disabled) {
    background: #92400E;
}

/* Active chat title band */
.chat-title-bar {
    background: linear-gradient(180deg, #F7F4EC 0%, #F0EDE5 100%);
    border-bottom: 1px solid var(--chat-line);
    padding: 0.4rem 0.75rem;
}

@media (min-width: 768px) {
    .chat-title-bar {
        padding: 0.45rem 1rem;
    }
}

/* ========================================
   INPUT AREA
   ======================================== */

#chatbot-compose-form,
#chatbot-compose-form:focus,
#chatbot-compose-form:focus-within,
#chatbot-compose-form:focus-visible {
    outline: none;
    box-shadow: none;
}

/* Textarea must stay chromeless — a square outline next to the round send btn is the bug */
#user-input {
    border: 0 !important;
    border-radius: 8px;
    outline: none !important;
    outline-offset: 0 !important;
    box-shadow: none !important;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
}

#user-input:focus,
#user-input:focus-visible,
#user-input:active {
    border: 0 !important;
    outline: none !important;
    outline-offset: 0 !important;
    box-shadow: none !important;
}

#send-button:focus,
#send-button:focus-visible {
    outline: none;
    box-shadow: none;
}

/* Chat menu button */
.chat-menu-btn-enhanced {
    transition: background-color 0.15s ease, color 0.15s ease;
    background: transparent;
}

.chat-menu-btn-enhanced:hover {
    background: rgba(15, 118, 110, 0.08);
    box-shadow: none;
    transform: none;
}

/* Current chat menu — match app header menus */
#current-chat-menu {
    background: #FFFCF7;
    box-shadow: 0 1px 2px rgba(28, 25, 23, 0.06);
    border: 1px solid var(--chat-line);
}

/* ========================================
   LOADING STATES ENHANCEMENTS
   ======================================== */

/* Branded pulsing dots loader */
.branded-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.branded-loader-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--chat-accent);
    animation: brandedPulse 1.4s ease-in-out infinite;
}

.branded-loader-dot:nth-child(1) { animation-delay: 0s; }
.branded-loader-dot:nth-child(2) { animation-delay: 0.2s; }
.branded-loader-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes brandedPulse {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Skeleton loading animation */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--chat-brand-soft) 0%,
        var(--chat-line) 50%,
        var(--chat-brand-soft) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: 0.5rem;
}

@keyframes skeleton-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Skeleton chat item */
.skeleton-chat-item {
    padding: 0.75rem;
    border-radius: 0.5rem;
    background: white;
    border: 1px solid var(--chat-line);
    margin-bottom: 0.5rem;
}

.skeleton-title {
    height: 16px;
    width: 75%;
    margin-bottom: 8px;
}

.skeleton-date {
    height: 12px;
    width: 40%;
}

/* Main loading state enhancement */
.main-loader-container {
    animation: fadeIn 0.3s ease-out;
}

#welcome-message:not(.hidden) .text-center {
    animation: contentReveal 0.35s ease-out;
}

#main-loading-state {
    transition: opacity 0.22s ease-out;
}

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

/* ========================================
   CHAT SEARCH MODAL
   Warm parchment shell + teal accents — matches sidebar.
   ======================================== */

.chat-search-open-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    flex-shrink: 0;
    border-radius: 0.65rem;
    background: linear-gradient(145deg, #FFFCF7 0%, #E8E4DB 100%);
    color: var(--chat-accent, #0F766E);
    border: 1px solid var(--chat-line, #E4E1D9);
    box-shadow: 0 1px 2px rgba(28, 25, 23, 0.04);
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-search-open-btn:hover {
    color: #FFFCF7;
    background: var(--chat-accent, #0F766E);
    border-color: var(--chat-accent, #0F766E);
    box-shadow: 0 2px 6px rgba(15, 118, 110, 0.25);
}

.chat-search-open-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.35);
}

#chat-search-modal {
    --chat-ink: #0F172A;
    --chat-accent: #0F766E;
    --chat-accent-hover: #115E59;
    --chat-highlight: #F0FDFA;
    --chat-highlight-ink: #134E4A;
    --chat-mute: #64748B;
    --chat-surface: #F3F1EB;
    --chat-canvas: #EBE8E1;
    --chat-panel: #FFFFFF;
    --chat-line: #E4E1D9;
    --chat-brand-soft: #EEECE6;
}

.chat-search-backdrop {
    background: rgba(28, 25, 23, 0.48);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.chat-search-panel {
    background: linear-gradient(180deg, #FFFCF7 0%, #F7F4EC 42%, #F3F1EB 100%);
    border: 1px solid var(--chat-line);
    border-radius: 1.15rem;
    overflow: hidden;
    box-shadow:
        0 1px 0 rgba(255, 252, 247, 0.8) inset,
        0 18px 48px rgba(28, 25, 23, 0.18),
        0 4px 12px rgba(28, 25, 23, 0.08);
}

.chat-search-header {
    padding: 1.1rem 1.15rem 0.95rem;
    background: linear-gradient(180deg, rgba(255, 252, 247, 0.95) 0%, rgba(235, 232, 225, 0.55) 100%);
    border-bottom: 1px solid var(--chat-line);
}

.chat-search-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.95rem;
}

.chat-search-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.chat-search-brand-icon {
    width: 2.35rem;
    height: 2.35rem;
    border-radius: 0.7rem;
    background: linear-gradient(145deg, #FFFCF7 0%, #E8E4DB 100%);
    color: var(--chat-accent);
    border: 1px solid var(--chat-line);
    box-shadow: 0 1px 2px rgba(28, 25, 23, 0.04);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-search-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 650;
    letter-spacing: -0.01em;
    color: var(--chat-ink);
    line-height: 1.25;
}

.chat-search-subtitle {
    margin: 0.15rem 0 0;
    font-size: 0.75rem;
    color: var(--chat-mute);
    line-height: 1.3;
}

.chat-search-header-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.chat-search-kbd {
    display: none;
    align-items: center;
    gap: 0.2rem;
    padding: 0.2rem 0.45rem;
    border-radius: 0.4rem;
    border: 1px solid var(--chat-line);
    background: rgba(255, 252, 247, 0.85);
    color: #78716C;
    font-family: inherit;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1;
    box-shadow: 0 1px 0 rgba(28, 25, 23, 0.04);
}

@media (min-width: 640px) {
    .chat-search-kbd {
        display: inline-flex;
    }
}

.chat-search-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.55rem;
    color: #78716C;
    background: transparent;
    border: 1px solid transparent;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.chat-search-close:hover {
    color: var(--chat-ink);
    background: rgba(255, 252, 247, 0.9);
    border-color: var(--chat-line);
}

.chat-search-field {
    position: relative;
}

.chat-search-field-icon {
    pointer-events: none;
    position: absolute;
    left: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.05rem;
    height: 1.05rem;
    color: var(--chat-accent);
    opacity: 0.75;
}

.chat-search-input {
    width: 100%;
    padding: 0.8rem 0.95rem 0.8rem 2.65rem;
    font-size: 0.9375rem;
    line-height: 1.35;
    color: var(--chat-ink);
    background: #FFFCF7;
    border: 1px solid var(--chat-line);
    border-radius: 0.85rem;
    box-shadow: 0 1px 2px rgba(28, 25, 23, 0.04) inset;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-search-input::placeholder {
    color: #A8A29E;
}

.chat-search-input:focus {
    outline: none;
    border-color: var(--chat-accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.chat-search-input::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}

.chat-search-deep-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 0.85rem;
    padding: 0.7rem 0.85rem;
    border-radius: 0.85rem;
    border: 1px solid var(--chat-line);
    background: rgba(255, 252, 247, 0.72);
    cursor: pointer;
    user-select: none;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.chat-search-deep-toggle:hover {
    background: #FFFCF7;
    border-color: #D6D1C6;
}

.chat-search-deep-toggle:has(#chat-search-deep-toggle:checked) {
    background: var(--chat-highlight);
    border-color: rgba(15, 118, 110, 0.28);
    box-shadow: 0 0 0 1px rgba(15, 118, 110, 0.06);
}

.chat-search-deep-copy {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.chat-search-deep-label {
    font-size: 0.8125rem;
    font-weight: 650;
    color: var(--chat-ink);
    letter-spacing: -0.01em;
}

.chat-search-deep-hint {
    font-size: 0.7rem;
    color: var(--chat-mute);
}

.chat-search-switch {
    flex-shrink: 0;
}

.chat-search-switch-track {
    position: relative;
    display: block;
    width: 2.5rem;
    height: 1.4rem;
    border-radius: 9999px;
    background: #D6D3D1;
    border: 1px solid #C8C3BC;
    transition: background 0.18s ease, border-color 0.18s ease;
}

.chat-search-switch-thumb {
    position: absolute;
    top: 1px;
    left: 1px;
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 9999px;
    background: #FFFCF7;
    box-shadow: 0 1px 3px rgba(28, 25, 23, 0.2);
    transition: transform 0.18s ease;
}

#chat-search-deep-toggle:checked + .chat-search-switch-track {
    background: var(--chat-accent);
    border-color: var(--chat-accent-hover);
}

#chat-search-deep-toggle:checked + .chat-search-switch-track .chat-search-switch-thumb {
    transform: translateX(1.1rem);
}

#chat-search-deep-toggle:focus-visible + .chat-search-switch-track {
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.22);
}

.chat-search-body {
    max-height: min(52vh, 28rem);
    overflow-y: auto;
    padding: 0.85rem 0.85rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-search-section-messages {
    padding-top: 0.85rem;
    border-top: 1px solid var(--chat-line);
}

.chat-search-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0 0.2rem 0.45rem;
}

.chat-search-section-label {
    margin: 0;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #78716C;
}

.chat-search-status {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--chat-accent);
}

.chat-search-results {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.chat-search-result {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.7rem 0.8rem;
    border-radius: 0.75rem;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-search-result:hover,
.chat-search-result:focus-visible {
    outline: none;
    background: #FFFCF7;
    border-color: var(--chat-line);
    border-left: 3px solid var(--chat-accent);
    padding-left: calc(0.8rem - 2px);
    box-shadow: 0 1px 2px rgba(28, 25, 23, 0.04);
}

.chat-search-result-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--chat-ink);
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-search-result-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.3rem;
}

.chat-search-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.12rem 0.45rem;
    border-radius: 9999px;
    font-size: 0.65rem;
    font-weight: 650;
    letter-spacing: 0.01em;
    line-height: 1.3;
    color: var(--chat-highlight-ink);
    background: var(--chat-highlight);
    border: 1px solid rgba(15, 118, 110, 0.14);
}

.chat-search-pill-muted {
    color: #78716C;
    background: rgba(238, 236, 230, 0.9);
    border-color: var(--chat-line);
}

.chat-search-result-count {
    font-size: 0.7rem;
    color: var(--chat-mute);
}

.chat-search-result-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    min-width: 0;
}

.chat-search-result-row .chat-search-pill {
    flex-shrink: 0;
}

.chat-search-result-message .chat-search-result-title {
    flex: 1 1 auto;
    min-width: 0;
}

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

.chat-search-status.is-loading {
    animation: chatSearchPulse 1.1s ease-in-out infinite;
}

.chat-search-mark {
    color: var(--chat-highlight-ink);
    background: rgba(15, 118, 110, 0.14);
    border-radius: 0.2rem;
    padding: 0 0.12em;
    font-weight: 650;
}

.chat-search-empty {
    margin: 0;
    padding: 1.1rem 0.75rem;
    text-align: center;
    font-size: 0.8125rem;
    color: var(--chat-mute);
    border-radius: 0.75rem;
    background: rgba(255, 252, 247, 0.55);
    border: 1px dashed var(--chat-line);
}

.chat-search-more {
    display: block;
    width: 100%;
    margin-top: 0.35rem;
    padding: 0.55rem 0.75rem;
    border-radius: 0.65rem;
    border: 1px solid transparent;
    background: transparent;
    color: var(--chat-accent);
    font-size: 0.75rem;
    font-weight: 650;
    text-align: center;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chat-search-more:hover {
    background: var(--chat-highlight);
    border-color: rgba(15, 118, 110, 0.18);
    color: var(--chat-accent-hover);
}

/* ========================================
   MODAL REFINEMENTS
   ======================================== */

/* Modal backdrop animation (fill/blur via Tailwind on markup) */
.modal-backdrop {
    animation: backdropFadeIn 0.2s ease-out;
}

/* Modal content animation (surface via Tailwind on markup) */
.modal-content {
    animation: modalScaleIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes backdropFadeIn {
    from {
        opacity: 0;
        backdrop-filter: blur(0);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(4px);
    }
}

@keyframes modalScaleIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ========================================
   COPY BUTTON AND MESSAGE ACTIONS
   ======================================== */

/* Message actions container */
.message-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* Copy button styling */
.copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #e2e8f0;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
}

.copy-btn:hover {
    background: #ffffff;
    border-color: #cbd5e1;
    color: var(--chat-accent);
    transform: scale(1.05);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.copy-btn.copied {
    background: #10b981;
    border-color: #10b981;
    color: white;
}

.copy-btn svg {
    width: 14px;
    height: 14px;
}

/* ========================================
   SCROLL TO BOTTOM BUTTON
   ======================================== */

.scroll-to-bottom-btn {
    position: absolute;
    /* Sit centered above the compose bar — avoid overlapping the send control */
    bottom: 6.75rem;
    left: 50%;
    right: auto;
    width: 40px;
    height: 40px;
    border-radius: 9999px;
    background: var(--chat-accent);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.16);
    transition: background-color 0.15s ease, opacity 0.2s ease, transform 0.2s ease;
    z-index: 30;
    opacity: 0;
    transform: translate(-50%, 10px);
    pointer-events: none;
}

.scroll-to-bottom-btn.visible {
    opacity: 1;
    transform: translate(-50%, 0);
    pointer-events: auto;
}

.scroll-to-bottom-btn:hover {
    transform: translate(-50%, 0);
    background: var(--chat-accent-hover);
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.2);
}

.scroll-to-bottom-btn:active {
    transform: translate(-50%, 0) scale(0.96);
}

.scroll-to-bottom-btn svg {
    width: 18px;
    height: 18px;
}

/* New message count badge */
.scroll-to-bottom-btn .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 767px) {
    .scroll-to-bottom-btn {
        /* Clear taller mobile composer + safe area */
        bottom: calc(7.25rem + env(safe-area-inset-bottom, 0px));
        width: 38px;
        height: 38px;
    }
}

@media (min-width: 768px) {
    .scroll-to-bottom-btn {
        bottom: 7.5rem;
    }
}
