/* ============================================
   SnapGPT — Chat Interface Styles (UI 2.0)
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --sidebar-width: 260px;
    --sidebar-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
    --sidebar-ease-soft: cubic-bezier(0.16, 1, 0.3, 1);
    --primary-gradient: linear-gradient(90deg, #ff4a36 0%, #dd98ff 100%);
    --premium-gradient: linear-gradient(90deg, #ff4a36 0%, #dd98ff 100%);
    --background: #0f0f11;
    --sidebar-bg: #0a0a0c;
    --card-bg: #1a1a1e;
    --card-border: rgba(255, 255, 255, 0.07);
    --card-hover-border: rgba(255, 255, 255, 0.14);
    --text-primary: rgba(255, 255, 255, 0.95);
    --text-secondary: rgba(255, 255, 255, 0.55);
    --accent-purple: #8b5cf6;
    --accent-purple-hover: #7c3aed;
    --message-user-bg: #1e1e24;
    --message-ai-bg: transparent;
    --input-bg: #1a1a1e;
    --green: #22c55e;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

svg { flex-shrink: 0; }

/* ---- Chat Layout ---- */
.chat-container {
    display: flex;
    height: 100vh;
}

/* ---- Sidebar ---- */
.chat-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.28s var(--sidebar-ease), transform 0.32s var(--sidebar-ease), box-shadow 0.32s ease;
    flex-shrink: 0;
}

.chat-sidebar.collapsed {
    width: 52px;
    overflow: visible;
}

.chat-sidebar.collapsed .sidebar-header,
.chat-sidebar.collapsed .chat-history,
.chat-sidebar.collapsed .sidebar-top-bar,
.chat-sidebar.collapsed .sidebar-user-section,
.chat-sidebar.collapsed .sidebar-header-search {
    display: none;
}

.chat-sidebar.collapsed .sidebar-rail {
    display: flex;
}

/* Sidebar Rail */
.sidebar-rail {
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem 0 0.4rem;
    height: 100%;
    overflow: visible;
}

.sidebar-rail-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    margin-bottom: 0.35rem;
}

.sidebar-rail-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.sidebar-rail-btn svg {
    width: 20px;
    height: 20px;
}

.sidebar-rail-spacer { flex: 1; }

/* Sidebar Top Bar */
.sidebar-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.65rem;
    border-bottom: 1px solid var(--card-border);
}

.sidebar-home-btn,
.sidebar-collapse-btn,
.sidebar-mobile-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.sidebar-home-btn:hover,
.sidebar-collapse-btn:hover,
.sidebar-mobile-close-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.sidebar-home-btn svg,
.sidebar-collapse-btn svg,
.sidebar-mobile-close-btn svg {
    width: 20px;
    height: 20px;
}

.sidebar-mobile-close-btn { display: none; }

/* Sidebar Header */
.sidebar-header {
    padding: 0.65rem 0.65rem 0;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
}

.sidebar-header-search {
    padding: 0.35rem 0.65rem 0.45rem;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.45rem 0.6rem;
    background: transparent;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.new-chat-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--card-hover-border);
}

.new-chat-content {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}

.new-chat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
}

.new-chat-btn:hover .new-chat-icon {
    color: var(--text-primary);
}

.new-chat-icon svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
}

.new-chat-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- Model Selector ---- */
.model-selector {
    position: relative;
}

.model-selector-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.375rem 0.5rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    height: 32px;
    line-height: 1;
    font-family: inherit;
}

.model-selector-btn:hover,
.model-selector-btn:focus-visible {
    background: rgba(255, 255, 255, 0.06);
}

.model-selector-btn:focus-visible { outline: none; }

.model-selector-btn.open {
    background: rgba(255, 255, 255, 0.08);
}

.model-selector-btn .model-version { color: inherit; }

.model-selector-btn .extended-label {
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.8125rem;
    display: none;
}

.model-selector-btn .extended-label.visible {
    display: inline;
}

.model-selector-btn .chevron {
    color: inherit;
    opacity: 0.5;
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

.model-selector-btn.open .chevron { opacity: 0.8; }

/* Model Dropdown */
.model-dropdown {
    position: absolute;
    bottom: calc(100% + 0.5rem);
    right: 0;
    min-width: 280px;
    max-width: 320px;
    padding: 0.375rem;
    background: rgba(18, 18, 22, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-lg);
    z-index: 1000;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(24px);
    opacity: 0;
    transform: translateY(4px) scale(0.98);
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

.model-dropdown.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    visibility: visible;
    pointer-events: auto;
}

.model-option {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 0.5rem;
    align-items: center;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 10px;
    transition: background 0.12s ease;
    outline: none;
    user-select: none;
}

.model-option .model-logo {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: rgba(255, 255, 255, 0.7);
    align-self: start;
    margin-top: 0.125rem;
}

.model-option-info { min-width: 0; }

.model-option-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
}

.model-option-desc {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.125rem;
    white-space: nowrap;
}

.model-option:hover { background: rgba(255, 255, 255, 0.06); }
.model-option.selected { background: transparent; }

.model-option .check-icon {
    width: 16px;
    height: 16px;
    color: var(--accent-purple);
    opacity: 0;
    flex-shrink: 0;
    align-self: start;
    margin-top: 0.125rem;
}

.model-option.selected .check-icon { opacity: 1; }
.model-option + .model-option { margin-top: 0; }

.model-name-with-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.model-dropdown-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.06);
    margin: 0.375rem 0.5rem;
}

/* Extended Thinking Toggle */
.extended-thinking-option {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.75rem;
    align-items: center;
    padding: 0.5rem;
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
}

.extended-thinking-option:hover { background: rgba(255, 255, 255, 0.06); }
.extended-thinking-option.disabled { opacity: 0.35; pointer-events: none; }

.extended-thinking-info { min-width: 0; }

.extended-thinking-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
}

.extended-thinking-desc {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.125rem;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    flex-shrink: 0;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    transition: background 0.2s ease;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.toggle-switch input:checked + .toggle-slider { background: var(--accent-purple); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }

/* More Models */
.more-models-trigger {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 0.5rem;
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    transition: background 0.12s ease;
}

.more-models-trigger:hover { background: rgba(255, 255, 255, 0.06); }

.more-models-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.more-models-trigger:hover .more-models-label { color: var(--text-primary); }

.more-models-chevron {
    color: var(--text-secondary);
    transition: transform 0.2s ease;
    width: 16px;
    height: 16px;
}

.more-models-trigger:hover .more-models-chevron { color: var(--text-primary); }
.more-models-trigger.open .more-models-chevron { transform: rotate(90deg); }

.more-models-panel { display: none; }
.more-models-panel.show { display: block; }

/* ---- Reasoning Block ---- */
.reasoning-block {
    padding-top: 0.375rem;
    padding-bottom: 0.375rem;
    margin-bottom: 0.25rem;
}

.reasoning-block.inline-thinking {
    margin-top: 0.25rem;
}

.reasoning-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0;
    background: none;
    border: none;
    cursor: pointer;
    width: 100%;
    text-align: left;
    color: var(--text-secondary);
    transition: color 0.15s ease;
    font-family: inherit;
}

.reasoning-toggle:hover { color: var(--text-primary); }

.reasoning-toggle-inner {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    min-width: 0;
}

.reasoning-sparkle {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-purple);
}

.reasoning-sparkle svg {
    width: 20px;
    height: 20px;
}

.reasoning-summary {
    font-size: 0.8125rem;
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reasoning-summary.reasoning-shimmer {
    background: linear-gradient(90deg, var(--text-secondary) 30%, rgba(255, 255, 255, 0.7) 50%, var(--text-secondary) 80%);
    background-size: 400% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmertext 2.25s infinite;
}

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

.reasoning-chevron {
    display: inline-flex;
    flex-shrink: 0;
    transition: transform 0.2s ease;
    color: var(--text-secondary);
}

.reasoning-chevron svg { width: 12px; height: 12px; }
.reasoning-block:not(.open) .reasoning-chevron { transform: rotate(-90deg); }

.reasoning-panel {
    display: grid;
    transition: grid-template-rows 0.3s ease-out;
    grid-template-rows: 0fr;
}

.reasoning-block.open .reasoning-panel { grid-template-rows: 1fr; }

.reasoning-panel-inner {
    overflow: hidden;
    min-width: 0;
}

.reasoning-timeline {
    display: flex;
    flex-direction: column;
    padding-top: 0.5rem;
}

.reasoning-step {
    display: flex;
    flex-direction: row;
}

.reasoning-step-rail {
    width: 20px;
    display: flex;
    justify-content: center;
    flex-shrink: 0;
}

.reasoning-step-rail-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 0.25rem;
}

.reasoning-step-icon {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.reasoning-step-icon svg { width: 16px; height: 16px; }

.reasoning-step-connector {
    width: 1px;
    flex: 1;
    margin-top: 0.25rem;
    background: var(--card-border);
}

.reasoning-step-content {
    flex: 1;
    min-width: 0;
    padding-top: 0.125rem;
}

.reasoning-text {
    padding: 0 0.625rem;
    font-size: 0.8125rem;
    line-height: 1.7;
    color: rgba(255, 255, 255, 0.55);
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 200px;
    overflow: hidden;
    position: relative;
}

.reasoning-block.open .reasoning-text {
    max-height: none;
    overflow: visible;
}

.reasoning-text p { margin: 0 0 0.75rem; }
.reasoning-text p:last-child { margin-bottom: 0; }

.reasoning-step-done {
    padding-left: 0.625rem;
    padding-top: 0.125rem;
    padding-bottom: 0.25rem;
    font-size: 0.8125rem;
    color: rgba(255, 255, 255, 0.55);
}

.reasoning-step-spacer { height: 8px; }

.reasoning-step-spacer .reasoning-step-rail .reasoning-step-connector {
    margin-top: 0;
    height: 100%;
}

.reasoning-streaming::after {
    content: '';
    display: inline-block;
    width: 0.4em;
    height: 0.9em;
    background: var(--text-secondary);
    margin-left: 2px;
    animation: reasoningBlink 0.8s steps(2) infinite;
    vertical-align: text-bottom;
    border-radius: 1px;
}

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

/* Model Selector Loading */
.model-selector-btn.is-loading .model-version,
.model-selector-btn.is-loading .chevron { display: none; }
.model-selector-btn.is-loading .extended-label { display: none !important; }

.model-version-skeleton { display: none; }

.model-selector-btn.is-loading .model-version-skeleton {
    display: inline-block;
    width: 56px;
    height: 14px;
    border-radius: 4px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0.08) 50%, rgba(255, 255, 255, 0.04) 100%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s ease-in-out infinite;
    vertical-align: middle;
}

/* ---- Chat Header ---- */
.chat-header { padding: 0.5rem; }

/* ---- Chat History ---- */
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 0.35rem 0.45rem 0.65rem;
}

.chat-history-search {
    display: flex;
    align-items: center;
    padding: 0;
    border: none;
    background: transparent;
}

.chat-history-search svg {
    width: 15px;
    height: 15px;
    min-width: 15px;
    color: var(--text-secondary);
    flex-shrink: 0;
    margin-right: 0.6rem;
    margin-left: -2px;
}

.chat-history-search input {
    flex: 1;
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.8125rem;
    padding: 0.45rem 0;
    outline: none;
    font-family: inherit;
}

.chat-history-search input::placeholder {
    color: rgba(255, 255, 255, 0.3);
    user-select: none;
}

.chat-history-search input:focus::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

.chat-history::-webkit-scrollbar { width: 3px; }
.chat-history::-webkit-scrollbar-track { background: transparent; }
.chat-history::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 999px;
}

/* Auth loading */
.sidebar-user-section.auth-loading,
.sidebar-rail-profile.auth-loading {
    visibility: hidden;
}

/* ---- Sidebar User Section ---- */
.sidebar-user-section {
    padding: 0.6rem 0.75rem 0.75rem;
    border-top: 1px solid var(--card-border);
    position: relative;
}

.sidebar-user-button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-primary);
    padding: 0.4rem 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    transition: all 0.15s ease;
    font-family: inherit;
}

.sidebar-user-button:hover,
.sidebar-user-button:focus-visible {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--card-border);
}

.sidebar-user-button:focus-visible { outline: none; }

.sidebar-user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.7);
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

.sidebar-user-initial {
    font-size: 0.75rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-user-email {
    font-size: 0.8rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.sidebar-user-chevron {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.sidebar-user-button[aria-expanded="true"] .sidebar-user-chevron {
    transform: rotate(180deg);
}

.sidebar-user-button.sign-in-mode {
    background: transparent;
    border-color: var(--card-border);
    justify-content: center;
    padding: 0.5rem 0.75rem;
}

.sidebar-user-button.sign-in-mode:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--card-hover-border);
}

.sidebar-user-button.sign-in-mode .sidebar-user-avatar,
.sidebar-user-button.sign-in-mode .sidebar-user-chevron {
    display: none;
}

.sidebar-user-button.sign-in-mode .sidebar-user-email {
    text-align: center;
    font-weight: 500;
}

/* Quota Popover */
.sidebar-quota-popover {
    position: absolute;
    left: 0.75rem;
    bottom: calc(100% + 0.65rem);
    width: calc(100% - 1.5rem);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 0.85rem;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transform: translateY(6px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 20;
}

.sidebar-quota-popover.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.quota-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.quota-name {
    font-size: 0.8rem;
    font-weight: 600;
}

.quota-value {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.quota-bar {
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.quota-progress {
    height: 100%;
    border-radius: 999px;
    transition: width 0.5s ease;
}

.premium-progress {
    background: var(--premium-gradient);
    background-size: 200% 100%;
    animation: gradientShift 3s linear infinite;
}

.quota-detail {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.quota-unlimited {
    color: var(--green);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 500;
}

.quota-unlimited svg {
    fill: var(--green);
    stroke: none;
}

.sidebar-logout-btn {
    margin-top: 0.65rem;
    width: 100%;
    padding: 0.45rem 0.65rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--card-border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.sidebar-logout-btn:hover {
    border-color: rgba(239, 68, 68, 0.4);
    background: rgba(239, 68, 68, 0.08);
    color: #fca5a5;
}

.sidebar-manage-account-btn {
    margin-top: 0.65rem;
    width: 100%;
    padding: 0.45rem 0.65rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--card-border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.sidebar-manage-account-btn:hover {
    border-color: rgba(139, 92, 246, 0.4);
    background: rgba(139, 92, 246, 0.08);
    color: #c4b5fd;
}

/* Sidebar Rail Profile */
.sidebar-rail-profile {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 0.35rem;
}

.sidebar-rail-profile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    transition: all 0.15s ease;
}

.sidebar-rail-profile-btn:hover,
.sidebar-rail-profile-btn:focus-visible {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--card-border);
}

.sidebar-rail-profile-btn:focus-visible { outline: none; }

.sidebar-rail-avatar {
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.7rem;
    font-weight: 600;
}

.sidebar-rail-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

.sidebar-rail-initial {
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-quota-popover-rail {
    left: calc(100% + 0.6rem);
    bottom: 0;
    width: 240px;
}

.sidebar-rail-profile-btn.sign-in-mode {
    background: transparent;
    border-color: var(--card-border);
}

.sidebar-rail-profile-btn.sign-in-mode:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--card-hover-border);
}

.sidebar-rail-profile-btn.sign-in-mode .sidebar-rail-avatar {
    background: rgba(255, 255, 255, 0.1);
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* ---- Chat History Items ---- */
.chat-history-section {
    margin-bottom: 0.5rem;
}

.chat-history-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
    padding: 0.3rem 0.55rem 0.2rem;
    letter-spacing: 0.1em;
    font-weight: 600;
}

.chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0.55rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.12s ease;
    margin-bottom: 1px;
    position: relative;
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.04);
    outline: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-item.active {
    background: rgba(139, 92, 246, 0.08);
    outline: 1px solid rgba(139, 92, 246, 0.25);
}

.chat-item-title {
    flex: 1;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 0.5rem;
}

.chat-item.active .chat-item-title {
    color: var(--text-primary);
    font-weight: 500;
}

.chat-item-actions {
    display: flex;
    gap: 0.15rem;
    min-width: 2rem;
    justify-content: flex-end;
    opacity: 0;
    pointer-events: none;
    transform: translateX(4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
    margin-right: -0.25rem;
}

.chat-item:hover .chat-item-actions,
.chat-item:focus-within .chat-item-actions {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
}

.chat-item-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.2rem;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.35);
    cursor: pointer;
    border-radius: 5px;
    transition: all 0.12s ease;
}

.chat-item-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
}

.chat-item-btn.delete:hover {
    background: rgba(239, 68, 68, 0.08);
    color: #f87171;
}

.chat-item-btn svg { width: 15px; height: 15px; }

.chat-item-spinner {
    position: absolute;
    right: 0.35rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-purple);
    animation: spin 1s linear infinite;
    flex-shrink: 0;
    transition: opacity 0.15s ease;
}

.chat-item:hover .chat-item-spinner,
.chat-item:focus-within .chat-item-spinner {
    opacity: 0;
    pointer-events: none;
}

/* Obfuscated chat items */
.chat-history-obfuscated .chat-history-label { color: rgba(255, 255, 255, 0.25); }
.chat-history-obfuscated { position: relative; }

.chat-item-obfuscated {
    cursor: default;
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed rgba(255, 255, 255, 0.06);
    border-radius: 6px;
}

.chat-item-obfuscated .chat-item-title {
    position: relative;
    color: transparent;
}

.chat-item-obfuscated .chat-item-title::after {
    content: '';
    display: block;
    height: 0.45rem;
    width: 65%;
    border-radius: 4px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.03));
}

.chat-history-obfuscated.is-loading .chat-item-obfuscated {
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.05);
    background: linear-gradient(110deg, rgba(255, 255, 255, 0.03) 10%, rgba(255, 255, 255, 0.06) 28%, rgba(255, 255, 255, 0.03) 45%);
    background-size: 200% 100%;
    animation: sidebarShimmer 1.6s var(--sidebar-ease) infinite;
}

.chat-history-obfuscated.is-loading .chat-item-obfuscated .chat-item-title::after {
    background: linear-gradient(110deg, rgba(255, 255, 255, 0.1) 15%, rgba(255, 255, 255, 0.2) 35%, rgba(255, 255, 255, 0.06) 55%);
    background-size: 220% 100%;
    animation: sidebarShimmer 1.6s var(--sidebar-ease) infinite;
}

.chat-history-loader {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.55rem 0.55rem;
    color: rgba(255, 255, 255, 0.4);
}

.chat-history-loader .loader-bar {
    position: relative;
    flex: 1;
    height: 2px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    overflow: hidden;
}

.chat-history-loader .loader-bar::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.35) 50%, transparent 100%);
    transform: translateX(-100%);
    animation: loaderSweep 1.4s var(--sidebar-ease-soft) infinite;
}

.chat-history-loader .loader-dots {
    display: inline-flex;
    gap: 0.25rem;
}

.chat-history-loader .loader-dot {
    width: 3px;
    height: 3px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.3);
    animation: loaderDot 1s ease-in-out infinite;
}

.chat-history-loader .loader-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-history-loader .loader-dot:nth-child(3) { animation-delay: 0.3s; }

.chat-history-hint {
    padding: 0.25rem 0.55rem 0.55rem;
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.3);
}

@keyframes sidebarShimmer {
    0% { background-position: -120% 0; }
    100% { background-position: 120% 0; }
}

@keyframes loaderSweep {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

@keyframes loaderDot {
    0%, 80%, 100% { opacity: 0.4; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-2px); }
}

/* ---- Confirm Dialogs ---- */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1200;
    backdrop-filter: blur(4px);
}

.confirm-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.confirm-dialog {
    width: min(360px, calc(100% - 2rem));
    background: #111114;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
    color: var(--text-primary);
}

.confirm-title {
    font-size: 1rem;
    margin: 0 0 0.35rem;
    font-weight: 600;
}

.confirm-body {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0 0 0.75rem;
    line-height: 1.5;
}

.confirm-tip {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    padding: 0.5rem 0.6rem;
    margin-bottom: 1rem;
}

.confirm-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.confirm-btn {
    border-radius: 10px;
    border: 1px solid transparent;
    padding: 0.45rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    font-family: inherit;
}

.confirm-btn.ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: rgba(255, 255, 255, 0.08);
}

.confirm-btn.ghost:hover {
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.15);
}

.confirm-btn.danger {
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.25);
}

.confirm-btn.danger:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #fee2e2;
}

.confirm-btn.primary {
    background: rgba(139, 92, 246, 0.15);
    color: #c4b5fd;
    border-color: rgba(139, 92, 246, 0.25);
    font-weight: 500;
}

.confirm-btn.primary:hover {
    background: rgba(139, 92, 246, 0.22);
    color: #ddd6fe;
}

.google-signin-quick {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.55rem 0.85rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    margin-bottom: 0.65rem;
}

.google-signin-quick:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.18);
}

.google-signin-quick.loading {
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
}

.google-signin-quick svg {
    flex-shrink: 0;
}

.signin-divider {
    text-align: center;
    margin-bottom: 0.65rem;
    color: var(--text-dim);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.signin-divider::before,
.signin-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
}

#signInOverlay .confirm-actions {
    justify-content: stretch;
}

#signInOverlay .confirm-btn {
    flex: 1;
    text-align: center;
    padding: 0.55rem 0.85rem;
    font-size: 0.85rem;
}

/* ---- Main Chat Area ---- */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-thread {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.chat-thread.is-empty {
    display: grid;
    grid-template-rows: 1fr auto 1fr;
    gap: 0;
}

.chat-thread.is-empty .chat-messages {
    grid-row: 1;
    align-self: end;
    padding-top: 0;
    padding-bottom: 0;
}

.chat-thread.is-empty .chat-input-container {
    grid-row: 2;
    align-self: center;
    padding-top: 0;
    padding-bottom: 0;
}

.chat-thread.is-empty .welcome-state {
    flex: 0 0 auto;
    justify-content: flex-end;
    padding: 0 2rem 0.75rem;
}

.chat-thread.is-empty .welcome-title { margin-bottom: 0; }

/* Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
}

.scroll-to-latest {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 12px);
    transform: translateX(-50%) translateY(6px);
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: hidden;
    pointer-events: none;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.15s ease, visibility 0s linear 0.2s;
    z-index: 20;
}

.scroll-to-latest.show {
    visibility: visible;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
    transition-delay: 0s;
}

.scroll-to-latest:hover { background: var(--card-bg); border-color: var(--text-secondary); }
.scroll-to-latest svg { width: 18px; height: 18px; }


/* Welcome State */
.welcome-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--text-primary);
    text-align: center;
    padding: 2rem;
}

.welcome-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-style: italic;
    font-weight: 400;
    font-size: 2rem;
    color: rgba(255, 255, 255, 0.7);
}

.welcome-subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
    max-width: 480px;
}

/* ---- Message Styles ---- */
.message {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 48rem;
    margin: 0 auto;
    padding: 0 1rem;
}

@media (min-width: 1280px) { .message { max-width: 56rem; } }
@media (min-width: 1536px) { .message { max-width: 64rem; } }

.message.user { align-items: flex-end; }

.message.user .message-bubble {
    background: var(--message-user-bg);
    padding: 0.75rem 1rem;
    border-radius: 18px 18px 4px 18px;
    max-width: 70%;
    word-wrap: break-word;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.message.user .message-bubble p {
    margin: 0;
    line-height: 1.6;
}

.message.assistant { align-items: flex-start; }

.message.assistant .message-bubble {
    background: transparent;
    padding: 0;
    width: 100%;
    max-width: 100%;
}

.message-bubble p {
    margin: 0;
    line-height: 1.7;
}

.message-bubble pre {
    background: #111114;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin: 1rem 0;
    overflow-x: auto;
}

.message-bubble code {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.85rem;
}

/* Message Images */
.message-images-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.message-image {
    max-width: 300px;
    max-height: 200px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.2s ease;
    object-fit: cover;
    margin-top: 0.75rem;
}

.message-images-container .message-image {
    max-width: 180px;
    max-height: 140px;
    margin-top: 0;
}

.message-image:hover { transform: scale(1.02); }

.message.assistant .message-image {
    max-width: 512px;
    max-height: 512px;
    border-radius: var(--radius-md);
    margin-top: 0.75rem;
    object-fit: contain;
}

.message.assistant .message-images-container .message-image {
    max-width: 400px;
    max-height: 400px;
}

/* Documentation search indicator */
.docs-search-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0;
    margin-bottom: 0.25rem;
}

.docs-search-indicator .reasoning-sparkle { color: var(--text-secondary); }
.docs-search-indicator .reasoning-sparkle svg {
    width: 1rem;
    height: 1rem;
    animation: none;
}

/* Web search indicator */
.web-search-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0;
    margin-bottom: 0.25rem;
}

.web-search-indicator .reasoning-sparkle { color: var(--text-secondary); }
.web-search-indicator .reasoning-sparkle svg {
    width: 1rem;
    height: 1rem;
    animation: none;
}

.web-search-indicator.searching .reasoning-sparkle {
    background: linear-gradient(90deg, var(--text-secondary) 30%, rgba(255, 255, 255, 0.7) 50%, var(--text-secondary) 80%);
    background-size: 400% 100%;
    animation: shimmertext 2.25s infinite;
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='black'%3E%3Cpath fill-rule='evenodd' d='M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z' clip-rule='evenodd'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='black'%3E%3Cpath fill-rule='evenodd' d='M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z' clip-rule='evenodd'/%3E%3C/svg%3E");
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
}

.web-search-indicator.searching .reasoning-sparkle svg {
    visibility: hidden;
}

/* Image/Code indicators */
.code-running-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0;
}

.image-generating-indicator {
    display: flex;
    flex-direction: column;
    padding: 0.75rem 0;
}

/* Image skeleton placeholder */
.image-skeleton-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.image-skeleton {
    width: 300px;
    height: 300px;
    border-radius: var(--radius-md);
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0.08) 50%, rgba(255, 255, 255, 0.04) 100%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s ease-in-out infinite;
}

@media (max-width: 600px) {
    .image-skeleton {
        width: 200px;
        height: 200px;
    }
}

.code-running-indicator .spinning,
.image-generating-indicator .spinning {
    animation: spin 1s linear infinite;
}

/* Code Execution Block */
.code-exec-block {
    padding-top: 0.375rem;
    padding-bottom: 0.375rem;
    margin-bottom: 0.25rem;
}

.code-exec-block .reasoning-sparkle { color: #60a5fa; }

.code-exec-block .reasoning-panel {
    display: grid;
    transition: grid-template-rows 0.3s ease-out;
    grid-template-rows: 0fr;
}

.code-exec-block.open .reasoning-panel { grid-template-rows: 1fr; }
.code-exec-block:not(.open) .reasoning-chevron { transform: rotate(-90deg); }

.code-exec-code {
    margin: 0;
    padding: 0 0.625rem;
    font-size: 0.8rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.8);
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'SF Mono', 'Fira Code', monospace;
    background: transparent;
    max-height: 300px;
    overflow-y: auto;
}

.code-exec-code code {
    font-family: inherit;
    background: transparent;
    padding: 0;
}

.image-generating-text {
    font-size: 0.875rem;
    font-weight: 500;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0.75) 50%, rgba(255, 255, 255, 0.35) 100%);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmer 1.5s ease-in-out infinite;
    cursor: default;
    user-select: none;
}

/* ---- Chat Input ---- */
.chat-input-container {
    position: relative;
    padding: 0.75rem 1.5rem 1.5rem;
    background: var(--background);
}

.quota-alert {
    display: none;
    flex-direction: column;
    gap: 0.35rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: 14px;
    padding: 0.75rem 1rem;
    margin: 0 auto 0.85rem;
    max-width: 720px;
    color: #fecaca;
    line-height: 1.4;
}

.quota-alert.show { display: flex; }

.quota-alert-title {
    font-weight: 600;
    color: #fee2e2;
    font-size: 0.875rem;
}

.quota-alert-detail {
    font-size: 0.75rem;
    color: rgba(252, 165, 165, 0.8);
}

.quota-alert-upgrade-btn {
    margin-top: 0.5rem;
    padding: 0.5rem 1rem;
    background: linear-gradient(110deg, #d4af37 0%, #e5e4e2 50%, #d4af37 100%);
    background-size: 200% auto;
    color: #000;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(212, 175, 55, 0.2);
    animation: shine 3s linear infinite;
    align-self: flex-start;
    font-family: inherit;
}

.quota-alert-upgrade-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.quota-alert-upgrade-btn:disabled { opacity: 0.6; cursor: not-allowed; }

@keyframes shine { to { background-position: 200% center; } }

.chat-input-wrapper {
    max-width: 720px;
    margin: 0 auto;
    position: relative;
}

.chat-input-box {
    display: flex;
    flex-direction: column;
    background: var(--input-bg);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 22px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    cursor: text;
}

.chat-input-box:hover {
    border-color: rgba(255, 255, 255, 0.1);
}

.chat-input-box:focus-within {
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: none;
}

.chat-input-inner {
    display: flex;
    flex-direction: column;
    margin: 0.6rem;
    gap: 0.5rem;
}

.input-textarea-wrapper { position: relative; }

/* Image Preview */
.image-preview-container {
    display: none;
    padding: 0;
    overflow-x: auto;
    max-width: 100%;
}

.image-preview-container.has-images { display: block; }

.image-previews-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.5rem;
    padding-bottom: 0.25rem;
}

.image-preview-wrapper {
    position: relative;
    display: inline-block;
    flex-shrink: 0;
}

.image-preview {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--card-border);
}

.remove-image-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    background: #111114;
    border: 1px solid var(--card-border);
    border-radius: 50%;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.remove-image-btn:hover {
    background: #ef4444;
    border-color: #ef4444;
}

.remove-image-btn svg { width: 12px; height: 12px; }

.image-count-badge {
    font-size: 0.7rem;
    color: var(--text-secondary);
    padding-left: 0.25rem;
}

/* Toast */
.toast-notification {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(150%);
    background: rgba(18, 18, 22, 0.95);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: 14px;
    padding: 0.75rem 1.25rem;
    color: var(--text-primary);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s var(--sidebar-ease);
    max-width: calc(100vw - 2rem);
}

.toast-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: #a78bfa;
}

.toast-message {
    flex: 1;
    font-weight: 500;
}

/* Input Row */
.input-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.input-row-left {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex: 1;
    min-width: 0;
}

.input-row-right {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.attach-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
    position: relative;
    margin-left: 2px;
}

.attach-btn:hover { background: rgba(255, 255, 255, 0.06); }
.attach-btn:active { transform: scale(0.95); }
.attach-btn.open { background: rgba(255, 255, 255, 0.08); }
.attach-btn svg { width: 20px; height: 20px; }

/* Attachment Dropdown */
.attach-dropdown {
    position: absolute;
    bottom: calc(100% + 0.25rem);
    left: 0;
    min-width: 11rem;
    max-width: 280px;
    padding: 0.375rem;
    background: rgba(18, 18, 22, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    z-index: 1000;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(24px);
    opacity: 0;
    transform: translateY(4px) scale(0.98);
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s ease;
}

.attach-dropdown.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    visibility: visible;
    pointer-events: auto;
}

.attach-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.5rem;
    min-height: 32px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    position: relative;
    transition: none;
    user-select: none;
}

.attach-menu-item:hover { background: rgba(255, 255, 255, 0.06); }
.attach-menu-item:active { background: rgba(255, 255, 255, 0.08); }
.attach-menu-item + .attach-menu-item { margin-top: 0; }

.attach-menu-item .menu-icon {
    width: 18px;
    height: 18px;
    color: var(--text-primary);
    flex-shrink: 0;
}

.attach-menu-item span {
    font-weight: 400;
    font-size: 0.8125rem;
    color: var(--text-primary);
    white-space: nowrap;
}

.attach-menu-item.disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.attach-menu-item.disabled:hover { background: transparent; }
.attach-menu-item.disabled .menu-icon,
.attach-menu-item.disabled span { color: var(--text-secondary); }

.attach-menu-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.06);
    margin: 0.375rem 0.5rem;
}

.attach-menu-checkbox { justify-content: flex-start; }

.attach-menu-checkbox .check-icon {
    width: 16px;
    height: 16px;
    margin-left: auto;
    flex-shrink: 0;
    display: none;
}

.attach-menu-checkbox.active { color: #a78bfa; }
.attach-menu-checkbox.active .menu-icon,
.attach-menu-checkbox.active span { color: #a78bfa; }

.attach-menu-checkbox.active .check-icon {
    display: block;
    color: #a78bfa;
}

/* Chat Input */
.chat-input {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9375rem;
    line-height: 1.5;
    font-family: inherit;
    font-weight: 400;
    resize: none;
    outline: none;
    max-height: 24rem;
    min-height: 2.5rem;
    padding: 6px 6px 0 6px;
}

.chat-input::placeholder { color: rgba(255, 255, 255, 0.35); }

/* Send Button */
.send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
    padding: 6px;
}

.send-btn:not(:disabled) { color: var(--text-primary); }
.send-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.send-btn .stop-icon { display: none; }

.send-btn.is-stop {
    background: #ef4444;
    color: #fff;
    border-radius: var(--radius-sm);
}

.send-btn.is-stop:hover { background: #dc2626; }
.send-btn.is-stop .send-icon { display: none; }
.send-btn.is-stop .stop-icon { display: block; }

.send-btn svg { width: 16px; height: 16px; }

#imageInput { display: none; }

/* Loading dots */
.message.loading .message-bubble {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.loading-dots { display: flex; gap: 4px; }

.loading-dots span {
    width: 7px;
    height: 7px;
    background: var(--accent-purple);
    border-radius: 50%;
    animation: dotPulse 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

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

/* Web Search Loading */
.web-search-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0;
}

.web-search-loading-icon {
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
}

.web-search-loading-text {
    font-size: 0.875rem;
    font-weight: 500;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0.75) 50%, rgba(255, 255, 255, 0.35) 100%);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmer 1.5s ease-in-out infinite;
}

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

/* Citation Pills */
.citation-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    max-width: 120px;
    height: 18px;
    padding: 0 8px;
    margin-left: 4px;
    background: rgba(139, 92, 246, 0.1);
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    color: var(--accent-purple);
    text-decoration: none;
    transition: all 0.12s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
    position: relative;
    top: -1px;
}

.citation-pill:hover {
    background: rgba(139, 92, 246, 0.2);
    color: #a78bfa;
}

.citation-pill-text {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Sidebar Toggle Mobile */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 1000;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.sidebar-toggle svg { width: 20px; height: 20px; }

/* Loading Container */
.loading-container {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    text-align: center;
    padding: 0 1rem;
    background-color: var(--background);
    z-index: 100;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(139, 92, 246, 0.15);
    border-radius: 50%;
    border-top-color: var(--accent-purple);
    animation: spin 1s ease-in-out infinite;
    flex-shrink: 0;
}

.loading-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

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

/* ---- Mobile ---- */
@media (max-width: 768px) {
    .chat-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 999;
        transform: translateX(-100%);
    }

    .chat-sidebar.open {
        transform: translateX(0);
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
    }

    .sidebar-toggle { display: flex; }
    .sidebar-toggle.hidden { display: none; }

    .chat-header { padding-left: 2.5rem; }
    .chat-input-container { padding: 0.75rem; }
    .welcome-title { font-size: 1.5rem; }

    .sidebar-collapse-btn { display: none; }
    .sidebar-mobile-close-btn { display: flex; }

    .message { padding: 0 0.5rem; }

    .send-btn {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }

    .send-btn svg { width: 16px; height: 16px; }
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s var(--sidebar-ease-soft), visibility 0s linear 0.25s;
}

.sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.25s var(--sidebar-ease-soft);
}

/* Empty State */
.empty-chats {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Streaming cursor */
.streaming-cursor::after {
    content: '';
    display: inline-block;
    width: 7px;
    height: 0.85em;
    background: white;
    vertical-align: text-bottom;
    animation: blink 1s infinite;
    margin-left: 3px;
}

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

/* ---- Message Actions ---- */
.message-actions {
    display: flex;
    align-items: center;
    gap: 0.125rem;
    margin-top: 0.25rem;
    margin-left: -0.375rem;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.message:hover .message-actions,
.message:focus-within .message-actions,
.message .message-actions:focus-within,
.message .message-actions.has-active,
.message .retry-dropdown.show ~ .message-actions,
.message-actions:has(.retry-dropdown.show) {
    opacity: 1;
}

.message-actions:has(.retry-dropdown.show) {
    opacity: 1 !important;
}

.message.user .message-actions {
    justify-content: flex-end;
    margin-left: 0;
    margin-right: -0.375rem;
}

.message-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 7px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
    position: relative;
}

.message-action-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.message-action-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.4);
}

.message-action-btn:disabled { cursor: not-allowed; opacity: 0.5; }
.message-action-btn:disabled:hover { background: transparent; color: var(--text-secondary); }

.message-action-btn .icon-container {
    position: relative;
    width: 16px;
    height: 16px;
}

.message-action-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.message-action-btn .icon-default,
.message-action-btn .icon-success {
    position: absolute;
    inset: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.message-action-btn .icon-default { transform: scale(1); opacity: 1; }
.message-action-btn .icon-success { transform: scale(0); opacity: 0; color: var(--green); }
.message-action-btn.active .icon-default { transform: scale(0); opacity: 0; }
.message-action-btn.active .icon-success { transform: scale(1); opacity: 1; }
.message-action-btn.branch-off-btn.active .icon-success { color: var(--accent-purple); }
.message-action-btn .btn-text { display: none; }

/* Retry Dropdown */
.retry-dropdown-container { position: relative; }

.retry-dropdown {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    min-width: 200px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 0.25rem;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(16px);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(6px) scale(0.95);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
}

.retry-dropdown.position-below {
    bottom: auto;
    top: calc(100% + 8px);
    transform: translateX(-50%) translateY(-6px) scale(0.95);
}

.retry-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0) scale(1);
}

.retry-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.12s ease;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.retry-dropdown-item:hover { background: rgba(255, 255, 255, 0.06); }

.retry-dropdown-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.retry-dropdown-item:hover svg { color: var(--text-primary); }

.retry-dropdown-divider {
    position: relative;
    height: 1px;
    background: var(--card-border);
    margin: 0.65rem 0.5rem;
}

.retry-dropdown-divider::after {
    content: 'or try a different model';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--card-bg);
    padding: 0 0.5rem;
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.retry-dropdown-model {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.45rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.12s ease;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.retry-dropdown-model:hover { background: rgba(255, 255, 255, 0.06); }

.retry-dropdown-model svg,
.retry-dropdown-model .model-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.retry-dropdown-model:hover svg,
.retry-dropdown-model:hover .model-icon { color: var(--text-primary); }

/* Copy tooltip */
.copy-tooltip {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    padding: 0.3rem 0.5rem;
    border-radius: 6px;
    font-size: 0.7rem;
    color: var(--text-primary);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.copy-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--card-bg);
}

.copy-tooltip.show { opacity: 1; visibility: visible; }

/* Lightbox */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

.lightbox.show { display: flex; }

.lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: var(--radius-sm);
}

/* ---- Markdown Content ---- */
.message-bubble h1, .message-bubble h2, .message-bubble h3,
.message-bubble h4, .message-bubble h5, .message-bubble h6 {
    margin: 1rem 0 0.5rem 0;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.message-bubble h1 { font-size: 1.6rem; }
.message-bubble h2 { font-size: 1.35rem; }
.message-bubble h3 { font-size: 1.15rem; }
.message-bubble h4 { font-size: 1.05rem; }
.message-bubble h5 { font-size: 0.95rem; }
.message-bubble h6 { font-size: 0.85rem; color: var(--text-secondary); }

.message-bubble h1:first-child,
.message-bubble h2:first-child,
.message-bubble h3:first-child { margin-top: 0; }

.message-bubble ul, .message-bubble ol {
    margin: 0.75rem 0;
    padding-left: 1.5rem;
}

.message-bubble li {
    margin: 0.3rem 0;
    line-height: 1.7;
}

.message-bubble li > ul, .message-bubble li > ol { margin: 0.25rem 0; }

.message-bubble ul.contains-task-list {
    list-style: none;
    padding-left: 0;
}

.message-bubble li.task-list-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.message-bubble li.task-list-item input[type="checkbox"] {
    margin-top: 0.25rem;
    width: 16px;
    height: 16px;
    accent-color: var(--accent-purple);
}

.message-bubble blockquote {
    margin: 1rem 0;
    padding: 0.75rem 1rem;
    border-left: 3px solid var(--accent-purple);
    background: rgba(139, 92, 246, 0.06);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
}

.message-bubble blockquote p { margin: 0.25rem 0; }
.message-bubble blockquote blockquote {
    margin-top: 0.5rem;
    border-left-color: rgba(139, 92, 246, 0.4);
}

.message-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.85rem;
    overflow-x: auto;
    display: block;
}

.message-bubble thead { background: rgba(255, 255, 255, 0.03); }

.message-bubble th, .message-bubble td {
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--card-border);
    text-align: left;
}

.message-bubble th { font-weight: 600; }
.message-bubble tr:nth-child(even) { background: rgba(255, 255, 255, 0.02); }

.message-bubble hr {
    margin: 1.5rem 0;
    border: none;
    border-top: 1px solid var(--card-border);
}

.message-bubble a {
    color: var(--accent-purple);
    text-decoration: none;
    transition: color 0.15s ease;
}

.message-bubble a:hover {
    color: #a78bfa;
    text-decoration: underline;
}

.message-bubble img:not(.message-image) {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin: 0.75rem 0;
}

.message-bubble code:not(pre code) {
    background: rgba(255, 255, 255, 0.08);
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

.message-bubble pre {
    background: #0d0d10;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin: 1rem 0;
    overflow-x: auto;
}

.message-bubble pre code {
    background: transparent;
    padding: 0;
    font-size: 0.8125rem;
    line-height: 1.6;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

.code-block {
    position: relative;
    margin: 1rem 0;
}

.code-block pre { margin: 0; }

.code-copy-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
    z-index: 2;
}

.code-copy-btn:hover,
.code-copy-btn:focus-visible {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.code-copy-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.4);
}

.code-copy-btn:active { transform: scale(0.96); }

.code-block:hover .code-copy-btn,
.code-block:focus-within .code-copy-btn { opacity: 1; }

.code-copy-btn .icon-container {
    position: relative;
    width: 16px;
    height: 16px;
}

.code-copy-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.code-copy-btn .icon-default,
.code-copy-btn .icon-success {
    position: absolute;
    inset: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.code-copy-btn .icon-default { transform: scale(1); opacity: 1; }
.code-copy-btn .icon-success { transform: scale(0); opacity: 0; color: var(--green); }
.code-copy-btn.active .icon-default { transform: scale(0); opacity: 0; }
.code-copy-btn.active .icon-success { transform: scale(1); opacity: 1; }

.message-bubble del { color: var(--text-secondary); }
.message-bubble strong { font-weight: 600; }
.message-bubble em { font-style: italic; }
.message-bubble sup, .message-bubble sub { font-size: 0.75em; }

.message-bubble .katex-display { margin: 1rem 0; overflow-x: auto; overflow-y: hidden; }
.message-bubble .katex { font-size: 1.1em; }

.message-bubble .katex-display-wrapper {
    margin: 1rem 0;
    overflow-x: auto;
    overflow-y: hidden;
    text-align: center;
}

.message-bubble .math-error {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.message-bubble .math-pending {
    color: var(--text-secondary);
    background: rgba(139, 92, 246, 0.08);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-family: 'KaTeX_Math', 'Times New Roman', serif;
    font-style: italic;
}

.message-bubble .footnotes {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--card-border);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.message-bubble .footnote-ref {
    font-size: 0.75em;
    vertical-align: super;
}

.message-bubble > p:first-child { margin-top: 0; }
.message-bubble > p:last-child { margin-bottom: 0; }
.message-bubble p + p { margin-top: 0.75rem; }

/* ---- Edit Message ---- */
.message.user.editing .message-bubble { background: #1a1a20; }

.edit-message-form {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.edit-textarea-wrapper {
    padding: 0.75rem 1rem 0.5rem;
    width: 100%;
}

.edit-message-textarea {
    width: 100%;
    min-height: 24px;
    max-height: 300px;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.6;
    resize: none;
    outline: none;
    overflow-y: auto;
}

.edit-message-textarea::placeholder { color: var(--text-secondary); }

.edit-actions-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 0.5rem 0.5rem;
    gap: 0.25rem;
}

.edit-cancel-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 7px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.12s ease;
}

.edit-cancel-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.edit-cancel-btn svg { width: 16px; height: 16px; }

.edit-submit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    background: var(--accent-purple);
    border: none;
    border-radius: 7px;
    color: white;
    cursor: pointer;
    transition: all 0.12s ease;
}

.edit-submit-btn:hover { background: var(--accent-purple-hover); }
.edit-submit-btn:active { transform: scale(0.95); }
.edit-submit-btn svg { width: 16px; height: 16px; }

.message.editing .message-actions { display: none; }

/* ---- Skeleton Loaders ---- */
.skeleton-chat-item {
    display: flex;
    align-items: center;
    padding: 0.45rem 0.65rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.2rem;
}

.skeleton-chat-title {
    height: 10px;
    border-radius: 4px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0.07) 50%, rgba(255, 255, 255, 0.04) 100%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s ease-in-out infinite;
}

.skeleton-chat-item:nth-child(1) .skeleton-chat-title { width: 75%; }
.skeleton-chat-item:nth-child(2) .skeleton-chat-title { width: 60%; }
.skeleton-chat-item:nth-child(3) .skeleton-chat-title { width: 85%; }
.skeleton-chat-item:nth-child(4) .skeleton-chat-title { width: 50%; }
.skeleton-chat-item:nth-child(5) .skeleton-chat-title { width: 70%; }

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

#chatHistoryList.is-loading { display: none; }
#emptyChatsMessage.is-loading { display: none; }
.skeleton-container { display: none; }
.skeleton-container.is-loading { display: block; }
