/*
 * ai_assistant_core.css
 * Shared AI Assistant Core Styles (Reusable Core)
 * Version: v2.6.0
 * Generated Date: 2026-08-23 CST
 * 
 * CSS Variables can be overridden per project for UI adaptation.
 * Each project defines its own palette via :root or inline <style>.
 */

/* ===== Default CSS Variables (Dark Glass - fallback) ===== */
:root {
    --ai-fab-bg: linear-gradient(135deg, rgba(139, 92, 246, 0.9), rgba(59, 130, 246, 0.9));
    --ai-fab-color: #fff;
    --ai-fab-shadow: 0 4px 16px rgba(139, 92, 246, 0.3);
    --ai-fab-size: 52px;
    --ai-fab-bottom: 28px;
    --ai-fab-right: 28px;
    --ai-fab-z: 9998;

    --ai-modal-width: 534px;
    --ai-bookmark-width: 90px;
    --ai-modal-height: 616px;
    --ai-modal-bg: rgba(13, 17, 23, 0.92);
    --ai-modal-border: 1px solid rgba(255, 255, 255, 0.08);
    --ai-modal-radius: 16px;
    --ai-modal-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
    --ai-modal-animation: aiModalSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    --ai-header-bg: rgba(255, 255, 255, 0.03);
    --ai-header-border: rgba(255, 255, 255, 0.06);
    --ai-title-color: #e2e8f0;

    --ai-bubble-user-bg: rgba(139, 92, 246, 0.2);
    --ai-bubble-user-border: 1px solid rgba(139, 92, 246, 0.4);
    --ai-bubble-user-color: #e2e8f0;
    --ai-bubble-assistant-bg: rgba(255, 255, 255, 0.04);
    --ai-bubble-assistant-border: 1px solid rgba(148, 163, 184, 0.12);
    --ai-bubble-assistant-color: #cbd5e1;

    --ai-input-bg: rgba(255, 255, 255, 0.04);
    --ai-input-border: rgba(255, 255, 255, 0.08);
    --ai-input-color: #e2e8f0;
    --ai-input-focus-border: rgba(139, 92, 246, 0.5);

    --ai-accent: #8b5cf6;
    --ai-accent-hover: #7c3aed;
    --ai-text: #e2e8f0;
    --ai-text-muted: #94a3b8;
    --ai-divider: rgba(255, 255, 255, 0.06);
    --ai-btn-reset: #f87171;
    --ai-btn-reset-border: rgba(239, 68, 68, 0.2);

    --ai-settings-bg: rgba(13, 17, 23, 0.96);
    --ai-settings-border: rgba(255, 255, 255, 0.08);
    --ai-settings-input-bg: rgba(255, 255, 255, 0.05);
    --ai-settings-input-border: rgba(255, 255, 255, 0.1);

    --ai-chat-fs: 13px;
    --ai-bubble-radius: 14px;
}

/* ===== Light Theme (overrides dark glass defaults) ===== */
[data-theme="light"] {
    /* FAB */
    --ai-fab-shadow: 0 4px 16px rgba(139, 92, 246, 0.25);

    /* Modal — white glass */
    --ai-modal-bg: rgba(255, 255, 255, 0.94);
    --ai-modal-border: 1px solid rgba(0, 0, 0, 0.1);
    --ai-modal-shadow: 0 8px 40px rgba(0, 0, 0, 0.12);

    /* Header — light gray, not dark */
    --ai-header-bg: rgba(248, 249, 250, 0.92);
    --ai-header-border: rgba(0, 0, 0, 0.08);
    --ai-title-color: #1a1a2e;

    /* Bubbles */
    --ai-bubble-user-bg: rgba(139, 92, 246, 0.12);
    --ai-bubble-user-border: 1px solid rgba(139, 92, 246, 0.3);
    --ai-bubble-user-color: #2a3040;
    --ai-bubble-assistant-bg: rgba(245, 246, 248, 0.85);
    --ai-bubble-assistant-border: 1px solid rgba(0, 0, 0, 0.08);
    --ai-bubble-assistant-color: #1a1a2e;

    /* Input — light field on white */
    --ai-input-bg: rgba(255, 255, 255, 0.85);
    --ai-input-border: rgba(0, 0, 0, 0.12);
    --ai-input-color: #1a1a2e;
    --ai-input-focus-border: rgba(139, 92, 246, 0.5);

    /* Text */
    --ai-accent: #7c3aed;
    --ai-accent-hover: #6d28d9;
    --ai-text: #2a3040;
    --ai-text-muted: #6b7280;
    --ai-divider: rgba(0, 0, 0, 0.08);

    --ai-btn-reset: #ef4444;
    --ai-btn-reset-border: rgba(239, 68, 68, 0.2);

    /* Settings */
    --ai-settings-bg: rgba(255, 255, 255, 0.96);
    --ai-settings-border: rgba(0, 0, 0, 0.08);
    --ai-settings-input-bg: rgba(0, 0, 0, 0.03);
    --ai-settings-input-border: rgba(0, 0, 0, 0.12);

    /* Status bar fallback variables */
    --text-dim: rgba(0, 0, 0, 0.45);
    --border-subtle: rgba(0, 0, 0, 0.06);
    --surface-subtle: rgba(0, 0, 0, 0.02);
    --accent: #22c55e;
}

/* ===== FAB Button ===== */
.ai-assistant-fab {
    position: fixed;
    bottom: var(--ai-fab-bottom);
    right: var(--ai-fab-right);
    width: var(--ai-fab-size);
    height: var(--ai-fab-size);
    border-radius: 50%;
    background: var(--ai-fab-bg);
    color: var(--ai-fab-color);
    border: none;
    box-shadow: var(--ai-fab-shadow);
    cursor: pointer;
    z-index: var(--ai-fab-z);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-assistant-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(139, 92, 246, 0.4);
}

.ai-assistant-fab:active {
    transform: scale(0.95);
}

.ai-assistant-fab svg {
    width: 24px;
    height: 24px;
}

/* ===== Chat Modal ===== */
.ai-assistant-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 14000;
    background: transparent;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    pointer-events: none;
}

.ai-assistant-modal-backdrop.is-open {
    display: flex;
}

.ai-assistant-modal {
    position: relative;
    width: var(--ai-modal-width);
    max-width: 92vw;
    height: var(--ai-modal-height);
    max-height: 85vh;
    background: var(--ai-modal-bg);
    border: var(--ai-modal-border);
    border-radius: var(--ai-modal-radius);
    box-shadow: var(--ai-modal-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: var(--ai-modal-animation);
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
}
/* 键盘打开时，模态窗底部对齐输入法上方，避免被遮挡 */
.ai-assistant-modal.keyboard-open {
    max-height: var(--ai-keyboard-height, 60vh);
}

/* Bookmarks sit outside modal — no margin push needed */
.ai-resize-handle,
.ai-modal-header,
.ai-chat-status,
.ai-chat-history,
.ai-attachment-preview,
.ai-chat-form,
.ai-session-panel {
    margin-left: 0;
}

@keyframes aiModalSlideUp {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ===== Modal Header ===== */
.ai-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--ai-header-bg);
    border-bottom: 1px solid var(--ai-header-border);
    flex-shrink: 0;
}

.ai-assistant-modal.floating-mode .ai-modal-header {
    cursor: move;
    user-select: none;
    touch-action: none;
}

.ai-assistant-modal.floating-mode .ai-modal-header-right,
.ai-assistant-modal.floating-mode .ai-modal-header-right * {
    cursor: default;
}

.ai-modal-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-modal-header-left svg {
    width: 18px;
    height: 18px;
    color: var(--ai-accent);
}

.ai-modal-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ai-title-color);
    letter-spacing: 0.02em;
}

.ai-modal-header-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-modal-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--ai-text-muted);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
}

.ai-modal-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--ai-text);
}

.ai-modal-btn.ai-btn-close:hover {
    background: rgba(239, 68, 68, 0.12);
    color: #f87171;
}

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

/* ===== Chat Status Bar ===== */
.ai-chat-status {
    display: none;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    flex-wrap: wrap;
    position: relative;
    padding: 6px 12px;
    font-size: 11px;
    color: var(--text-dim, rgba(255,255,255,0.45));
    border-bottom: 1px solid var(--border-subtle, rgba(255,255,255,0.06));
    background: var(--surface-subtle, rgba(255,255,255,0.015));
    flex-shrink: 0;
    min-height: 32px;
}

.ai-chat-status-msg,
.ai-chat-status-sync,
.ai-chat-status-rag,
.ai-chat-status-refresh {
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(100,116,139,0.25);
    border-radius: 999px;
    gap: 6px;
    min-height: 22px;
    padding: 3px 9px;
    white-space: nowrap;
    line-height: 1;
}

.ai-chat-status-rag {
    background: transparent;
    cursor: pointer;
    font: inherit;
}

.ai-chat-status-rag:hover {
    border-color: var(--ai-accent);
}

.ai-chat-status-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.ai-chat-status-refresh {
    background: transparent;
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-dim, rgba(255,255,255,0.45));
    transition: color 0.2s, border-color 0.2s;
}

.ai-chat-status-refresh:hover {
    color: var(--ai-accent);
    border-color: var(--ai-accent);
}
.ai-chat-status-refresh:hover svg {
    animation: aiRefreshSpin 0.7s linear infinite;
}

@keyframes aiRefreshSpin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.ai-status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.ai-rag-mode-menu {
    display: none;
    position: absolute;
    right: 12px;
    top: calc(100% + 4px);
    z-index: 20;
    min-width: 142px;
    padding: 6px;
    border: var(--ai-modal-border);
    border-radius: 8px;
    background: var(--ai-modal-bg);
    box-shadow: var(--ai-modal-shadow);
}

.ai-rag-mode-menu.is-open {
    display: grid;
    gap: 4px;
}

.ai-rag-mode-menu button,
.ai-rag-guidance-actions button {
    border: 1px solid var(--ai-input-border);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--ai-title-color);
    cursor: pointer;
    font: inherit;
    padding: 6px 8px;
    text-align: left;
}

.ai-rag-mode-menu button:hover,
.ai-rag-guidance-actions button:hover {
    border-color: var(--ai-accent);
    color: var(--ai-accent);
}

.ai-rag-guidance {
    display: grid;
    gap: 10px;
}

.ai-rag-guidance-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* ===== Chat History ===== */
.ai-chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-size: var(--ai-chat-fs);
    line-height: 1.6;
}

.ai-chat-history::-webkit-scrollbar {
    width: 4px;
}

.ai-chat-history::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
}

/* ===== Bubbles ===== */
.ai-bubble {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: var(--ai-bubble-radius);
    font-size: var(--ai-chat-fs);
    line-height: 1.6;
    position: relative;
    word-break: break-word;
}

.ai-bubble.user {
    align-self: flex-end;
    background: var(--ai-bubble-user-bg);
    border: var(--ai-bubble-user-border);
    color: var(--ai-bubble-user-color);
    border-bottom-right-radius: 4px;
}

.ai-bubble.assistant {
    align-self: flex-start;
    background: var(--ai-bubble-assistant-bg);
    border: var(--ai-bubble-assistant-border);
    color: var(--ai-bubble-assistant-color);
    border-bottom-left-radius: 4px;
    width: 100%;
}

/* Copy button */
.ai-bubble .ai-copy-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--ai-modal-bg);
    border: var(--ai-modal-border);
    color: var(--ai-text-muted);
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    gap: 3px;
}

.ai-bubble:hover .ai-copy-btn {
    opacity: 1;
}

.ai-bubble .ai-copy-btn:hover {
    color: var(--ai-accent);
    border-color: var(--ai-accent);
}

/* Markdown overrides inside bubbles */
.ai-bubble.assistant p {
    margin: 0 0 0.6em 0;
}

.ai-bubble.assistant p:last-child {
    margin-bottom: 0;
}

.ai-bubble.assistant pre {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.6em 0;
    font-size: 12px;
}

.ai-bubble.assistant code {
    font-family: 'JetBrains Mono', 'SF Mono', monospace;
    font-size: 0.9em;
}

.ai-bubble.assistant pre code {
    font-size: 12px;
}

.ai-bubble.assistant ul, .ai-bubble.assistant ol {
    padding-left: 1.5em;
    margin: 0.4em 0;
}

.ai-bubble.assistant blockquote {
    border-left: 3px solid var(--ai-accent);
    padding-left: 12px;
    margin: 0.6em 0;
    opacity: 0.85;
}

/* Welcome placeholder */
.ai-welcome {
    text-align: center;
    color: var(--ai-text-muted);
    padding: 32px 16px;
    font-size: 13px;
}

.ai-welcome svg {
    width: 40px;
    height: 40px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.ai-welcome-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
}

.ai-welcome-chip {
    background: var(--ai-bubble-assistant-bg);
    border: var(--ai-bubble-assistant-border);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 12px;
    color: var(--ai-text-muted);
    transition: all 0.15s;
}

.ai-welcome-chip:hover {
    color: var(--ai-text);
    border-color: var(--ai-accent);
}

/* ===== Input Area ===== */
.ai-current-model {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

.ai-model-notice {
    display: flex;
    align-items: center;
    gap: 7px;
    width: min(100%, 534px);
    margin: 2px auto 10px;
    padding: 7px 2px;
    border-top: 1px solid var(--ai-divider);
    border-bottom: 1px solid var(--ai-divider);
    color: var(--ai-text-muted);
    font-size: 11px;
    line-height: 1.35;
}

.ai-model-notice svg {
    flex: 0 0 auto;
    opacity: 0.82;
}

.ai-chat-form {
    padding: 10px 12px;
    border-top: 1px solid var(--ai-divider);
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
    background: var(--ai-header-bg);
}

.ai-route-selector {
    position: relative;
    flex-shrink: 0;
}

.ai-route-toggle {
    box-sizing: border-box;
    flex: 0 0 auto;
    min-width: 96px;
    max-width: 146px;
    height: 36px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    border: 1px solid var(--ai-input-border);
    border-radius: 8px;
    background: transparent;
    color: var(--ai-text-muted);
    font: inherit;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.ai-route-toggle [data-route-toggle-label] {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-route-toggle:hover,
.ai-route-toggle[aria-expanded="true"] {
    color: var(--ai-accent);
    border-color: var(--ai-accent);
    background: color-mix(in srgb, var(--ai-accent) 10%, transparent);
}

.ai-route-toggle:focus-visible,
.ai-route-provider:focus-visible,
.ai-route-choice:focus-visible {
    outline: 2px solid var(--ai-accent);
    outline-offset: 2px;
}

.ai-route-menu {
    position: absolute;
    left: 0;
    bottom: calc(100% + 9px);
    z-index: 260;
    display: none;
    box-sizing: border-box;
    width: min(176px, calc(100vw - 32px));
    max-height: min(300px, 48vh);
    overflow: visible;
    border: 1px solid var(--ai-settings-border);
    border-radius: 12px;
    background: var(--ai-settings-bg);
    box-shadow: var(--ai-modal-shadow);
}

.ai-route-menu.is-open {
    display: block;
}

.ai-route-providers,
.ai-route-models {
    min-width: 0;
    overflow-y: auto;
    padding: 7px;
    scrollbar-width: thin;
}

.ai-route-providers {
    max-height: min(300px, 48vh);
}

.ai-route-models {
    position: absolute;
    left: calc(100% + 6px);
    bottom: 0;
    display: none;
    box-sizing: border-box;
    width: min(188px, calc(100vw - 32px));
    max-height: min(300px, 48vh);
    border: 1px solid var(--ai-settings-border);
    border-radius: 12px;
    background: var(--ai-settings-bg);
    box-shadow: var(--ai-modal-shadow);
}

.ai-route-models.is-open {
    display: block;
}

.ai-route-provider,
.ai-route-choice {
    box-sizing: border-box;
    width: 100%;
    height: 32px;
    min-height: 32px;
    margin: 0 0 2px;
    padding: 0 9px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--ai-text);
    font: inherit;
    font-size: 11px;
    line-height: 1.2;
    text-align: left;
    overflow-wrap: anywhere;
    cursor: pointer;
}

.ai-route-provider {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.ai-route-choice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.ai-route-choice-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-route-trailing {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-left: auto;
    flex: 0 0 auto;
}

.ai-route-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 14px;
    width: 14px;
    margin: 0;
    color: var(--ai-accent);
    font-size: 13px;
    font-weight: 800;
    line-height: 1;
}

.ai-route-chevron {
    color: var(--ai-text-muted);
    font-size: 18px;
    line-height: 1;
}

.ai-route-provider:hover,
.ai-route-choice:hover:not(:disabled) {
    color: var(--ai-accent);
    border-color: color-mix(in srgb, var(--ai-accent) 35%, transparent);
    background: color-mix(in srgb, var(--ai-accent) 11%, transparent);
}

.ai-route-provider.is-selected-provider,
.ai-route-choice.is-selected {
    font-weight: 700;
}

.ai-route-provider.is-open .ai-route-chevron {
    color: var(--ai-accent);
}

.ai-route-smart-global {
    margin-bottom: 7px;
    border-bottom-color: var(--ai-divider);
    border-radius: 8px;
}

.ai-route-choice.is-selected {
    font-weight: 700;
}

.ai-route-back {
    display: none;
    width: 100%;
    height: 32px;
    align-items: center;
    gap: 6px;
    margin: 0 0 5px;
    padding: 0 9px;
    border: 0;
    border-bottom: 1px solid var(--ai-divider);
    background: transparent;
    color: var(--ai-text-muted);
    font: inherit;
    font-size: 11px;
    font-weight: 650;
    text-align: left;
    cursor: pointer;
}

.ai-route-models.is-inline .ai-route-back {
    display: flex;
}

.ai-route-choice:disabled {
    color: var(--ai-text-muted);
    opacity: 0.45;
    cursor: not-allowed;
}

.ai-chat-input {
    box-sizing: border-box;
    flex: 1;
    background: var(--ai-input-bg);
    border: 1px solid var(--ai-input-border);
    border-radius: 8px;
    padding: 9px 12px;
    color: var(--ai-input-color);
    font-family: inherit;
    font-size: 13px;
    resize: none; /* 由 JS auto-resize 接管高度 */
    outline: none;
    min-height: 36px;
    max-height: calc(7.5em + 18px); /* five 1.5em lines plus vertical padding */
    line-height: 1.5;
    transition: border-color 0.2s, height 0.15s ease;
}

.ai-chat-input:focus {
    border-color: var(--ai-input-focus-border);
}

.ai-chat-input::placeholder {
    color: var(--ai-text-muted);
    opacity: 0.6;
}

.ai-chat-submit {
    box-sizing: border-box;
    background: var(--ai-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.ai-chat-submit:hover {
    background: var(--ai-accent-hover);
}

.ai-chat-submit:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ai-chat-submit svg {
    width: 16px;
    height: 16px;
}

/* Stop button (replaces send during generation) */
.ai-chat-stop {
    background: #92400e !important;
}

.ai-chat-stop:hover {
    background: #b45309 !important;
}

/* ===== Attach Button ===== */
.ai-attach-btn {
    box-sizing: border-box;
    background: transparent;
    color: var(--ai-text-muted);
    border: 1px solid var(--ai-input-border);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.ai-attach-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--ai-accent);
    border-color: var(--ai-accent);
}

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

/* ===== Hidden File Input ===== */
.ai-file-input-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ===== Attachment Preview ===== */
.ai-attachment-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 16px 0 16px;
    border-top: 1px solid var(--ai-divider);
    background: var(--ai-header-bg);
    flex-shrink: 0;
}

.ai-attachment-item {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--ai-input-border);
    border-radius: 8px;
    padding: 5px 8px;
    max-width: 180px;
    position: relative;
}

.ai-attachment-thumb {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
}

.ai-attachment-file-icon {
    font-size: 18px;
    flex-shrink: 0;
    line-height: 1;
}

.ai-attachment-name {
    font-size: 11px;
    color: var(--ai-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
}

.ai-attachment-remove {
    background: none;
    border: none;
    color: var(--ai-text-muted);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
    flex-shrink: 0;
    transition: color 0.15s;
}

.ai-attachment-remove:hover {
    color: var(--ai-btn-reset);
}

/* ===== Thinking Cursor ===== */
.ai-thinking-cursor {
    display: inline-block;
    width: 8px;
    height: 1em;
    background-color: var(--ai-accent);
    animation: aiBlink 1s step-end infinite;
    vertical-align: middle;
    margin-left: 2px;
    border-radius: 1px;
}

.ai-rag-status {
    color: var(--ai-text-muted);
    font-size: 0.92em;
    font-weight: 500;
}

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

/* ===== Settings Modal ===== */
.ai-settings-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10001;
    background: rgba(0, 0, 0, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
}

.ai-settings-backdrop.is-open {
    display: flex;
}

.ai-settings-panel {
    width: 437px;
    max-width: 92vw;
    background: var(--ai-settings-bg);
    border: var(--ai-settings-border);
    border-radius: var(--ai-modal-radius);
    box-shadow: var(--ai-modal-shadow);
    padding: 24px;
    animation: aiModalSlideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-settings-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--ai-title-color);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-settings-title svg {
    width: 18px;
    height: 18px;
    color: var(--ai-accent);
}

.ai-settings-group {
    margin-bottom: 16px;
}

.ai-settings-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--ai-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.ai-settings-input {
    width: 100%;
    box-sizing: border-box;
    background: var(--ai-settings-input-bg);
    border: 1px solid var(--ai-settings-input-border);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--ai-input-color);
    font-family: 'JetBrains Mono', 'SF Mono', monospace;
    font-size: 12px;
    outline: none;
    transition: border-color 0.2s;
}

.ai-settings-input:focus {
    border-color: var(--ai-accent);
}

.ai-settings-select {
    width: 100%;
    box-sizing: border-box;
    background: var(--ai-settings-input-bg);
    border: 1px solid var(--ai-settings-input-border);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--ai-input-color);
    font-size: 13px;
    outline: none;
    cursor: pointer;
}

.ai-settings-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
}

.ai-settings-btn {
    flex: 1;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
}

.ai-settings-btn.primary {
    background: var(--ai-accent);
    color: #fff;
}

.ai-settings-btn.primary:hover {
    background: var(--ai-accent-hover);
}

.ai-settings-btn.secondary {
    background: transparent;
    color: var(--ai-text-muted);
    border: 1px solid var(--ai-input-border);
}

.ai-settings-btn.secondary:hover {
    color: var(--ai-text);
    border-color: var(--ai-text-muted);
}

.ai-settings-hint {
    font-size: 10px;
    color: var(--ai-text-muted);
    opacity: 0.7;
    margin-top: 4px;
}

/* Settings external links */
.ai-settings-links {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.ai-settings-link {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 7px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    color: var(--ai-text-muted);
    border: 1px solid var(--ai-input-border);
    background: transparent;
    cursor: pointer;
    transition: all 0.15s;
}

.ai-settings-link:hover {
    color: var(--ai-accent);
    border-color: var(--ai-accent);
    background: rgba(255, 255, 255, 0.04);
}

/* ===== Light Theme — hardcoded value overrides ===== */
[data-theme="light"] .ai-modal-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .ai-attach-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .ai-attachment-item {
    background: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .ai-chat-history::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .ai-bubble.assistant pre {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .ai-settings-link:hover {
    background: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .ai-assistant-modal-backdrop {
    background: transparent;
}

[data-theme="light"] .ai-session-bookmarks {
    box-shadow: 0 4px 24px rgba(0,0,0,0.1);
}
[data-theme="light"] .ai-session-tab:hover {
    background: rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .ai-session-new:hover {
    background: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .ai-settings-backdrop {
    background: rgba(0, 0, 0, 0.42);
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .ai-assistant-modal-backdrop {
        /* 微调遮罩层内边距，确保 modal 上下左右留有呼吸空间 */
        padding: 6px;
    }
    .ai-assistant-modal {
        /* 宽度：90vw，左右各留 5vw 安全间距 (符合 Universal Rules §4.6) */
        width: 90vw;
        max-width: 90vw;
        /* 上下边距各 10% 视口高度，确保顶部操作栏和底部输入框完整显示不被遮挡 (符合 Universal Rules §4.6) */
        height: 80dvh;
        max-height: 80dvh;
        /* 溢出滚动 (符合 Universal Rules §4.6) */
        overflow-y: auto;
        /* 恢复圆角，避免全屏直角的生硬感 */
        border-radius: 14px;
    }
    /* 移动端悬浮窗模式：默认半屏高度，位于页面上半部，便于边看文档边提问 */
    .ai-assistant-modal.floating-mode {
        width: 88vw;
        max-width: none;
        height: 50dvh;
        max-height: none;
        border-radius: 14px;
    }
    .ai-chat-input {
        /* 移动端增大输入框最大高度，依靠 JS 自动撑高 */
        max-height: 40vh;
        resize: none;
    }
    .ai-current-model {
        padding-inline: 12px;
    }
    .ai-chat-form {
        padding-inline: 12px;
        gap: 6px;
    }
    .ai-route-toggle {
        min-width: 96px;
        max-width: 126px;
        padding: 0 8px;
    }
    .ai-route-menu {
        width: min(168px, calc(90vw - 24px));
    }
    .ai-route-models {
        width: min(168px, calc(90vw - 24px));
    }
    .ai-assistant-fab {
        --ai-fab-size: 46px;
        --ai-fab-bottom: 20px;
        --ai-fab-right: 20px;
    }
}


/* ================================
   Floating Mode — Drag & Resize
   ================================ */

/* When floating, the backdrop becomes transparent and the modal uses fixed positioning */
.ai-assistant-modal-backdrop.floating {
    background: transparent;
    pointer-events: none;
}

.ai-assistant-modal-backdrop.floating .ai-assistant-modal {
    pointer-events: all;
}

.ai-assistant-modal.floating-mode {
    position: fixed;
    left: auto;
    top: auto;
    width: 534px;
    height: 616px;
    max-width: none;
    max-height: none;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.08);
    animation: none;
    transition: none;
}
/* 浮动模式下不受键盘过渡影响 */
.ai-assistant-modal.floating-mode.keyboard-open {
    transition: none;
}

/* Drag handle — visible only in floating mode */
.ai-drag-handle {
    display: none;
    cursor: grab;
    color: var(--ai-text-muted);
    font-size: 14px;
    padding: 2px 4px;
    border-radius: 3px;
    transition: color 0.15s;
    touch-action: none; /* prevent browser touch gestures from interfering */
    user-select: none;
}

.ai-drag-handle:hover {
    color: var(--ai-text);
}

.ai-drag-handle:active {
    cursor: grabbing;
}

.ai-assistant-modal.floating-mode .ai-drag-handle {
    display: flex;
}

/* Resize handle — bottom-right corner, visible only in floating mode */
.ai-resize-handle {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s ease;
    touch-action: none;
}
.ai-resize-handle svg { opacity: 0.4; color: var(--ai-text-muted); }
.ai-assistant-modal.floating-mode .ai-resize-handle { display: flex; opacity: 0.5; }
.ai-resize-handle:hover { opacity: 1 !important; }

/* Edge/Corners resize handles (only active in floating mode) */
.ai-resize-edge,
.ai-resize-corner {
    display: none;
    position: absolute;
    z-index: 5;
    touch-action: none;
}
.ai-assistant-modal.floating-mode .ai-resize-edge,
.ai-assistant-modal.floating-mode .ai-resize-corner {
    display: block;
}
/* Edges - 6px thick */
.ai-resize-n { top: -2px; left: 10px; right: 10px; height: 6px; cursor: ns-resize; }
.ai-resize-s { bottom: -2px; left: 10px; right: 10px; height: 6px; cursor: ns-resize; }
.ai-resize-e { right: -2px; top: 10px; bottom: 10px; width: 6px; cursor: ew-resize; }
.ai-resize-w { left: -2px; top: 10px; bottom: 10px; width: 6px; cursor: ew-resize; }
/* Corners - 12px */
.ai-resize-nw { top: -3px; left: -3px; width: 12px; height: 12px; cursor: nwse-resize; }
.ai-resize-ne { top: -3px; right: -3px; width: 12px; height: 12px; cursor: nesw-resize; }
.ai-resize-sw { bottom: -3px; left: -3px; width: 12px; height: 12px; cursor: nesw-resize; }
.ai-resize-se { bottom: -3px; right: -3px; width: 12px; height: 12px; cursor: nwse-resize; }

/* Detach button — toggles floating mode */
.ai-detach-btn svg {
    transition: transform 0.2s;
}

.ai-assistant-modal.floating-mode .ai-detach-btn svg {
    transform: rotate(180deg);
}

/* ================================
   Font Size Controls
   ================================ */

.ai-font-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    margin-right: 2px;
}

.ai-font-label {
    font-size: 10px;
    color: var(--ai-text-muted);
    padding-right: 3px;
    white-space: nowrap;
    user-select: none;
}

.ai-font-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 5px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.05);
    color: var(--ai-text-muted);
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    line-height: 1;
    transition: all 0.2s;
}

.ai-font-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--ai-text);
    border-color: var(--ai-accent);
}

.ai-bubble {
    transition: font-size 0.15s ease;
}

/* ===== Session Bookmarks (left sidebar, attached to modal top) ===== */
.ai-session-bookmarks {
    display: none;
    position: absolute;
    left: max(8px, calc(50% - min(var(--ai-modal-width), 92vw) / 2 - var(--ai-bookmark-width) - 8px));
    top: 50%;
    transform: translateY(-50%);
    flex-direction: column;
    width: var(--ai-bookmark-width);
    max-height: calc(100vh - 140px);
    margin-right: 0;
    flex-shrink: 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(148,163,184,0.15) transparent;
    border-radius: 12px;
    background: var(--ai-modal-bg);
    border: var(--ai-modal-border);
    box-shadow: 0 4px 24px rgba(0,0,0,0.25);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 4px;
    pointer-events: auto;
}

@media (max-width: 640px) {
    .ai-session-bookmarks {
        left: 5vw;
        top: max(6px, env(safe-area-inset-top, 0px));
        width: 90vw;
        max-height: 42px;
        transform: none;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        z-index: 2;
    }

    .ai-session-list {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
    }
}
.ai-assistant-modal-backdrop.is-open .ai-session-bookmarks {
    display: flex;
}

.ai-session-new {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 34px;
    margin: 0 0 4px 0;
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--ai-text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    line-height: 1;
    flex-shrink: 0;
}
.ai-session-new:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--ai-accent);
    color: var(--ai-accent);
}

.ai-session-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 0;
    width: 100%;
    scrollbar-width: thin;
    scrollbar-color: rgba(148,163,184,0.15) transparent;
}

.ai-session-tab {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 38px;
    padding: 7px 8px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--ai-text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: center;
    line-height: 1.35;
    box-sizing: border-box;
    user-select: none;
}
.ai-session-tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--ai-text);
    border-color: rgba(255, 255, 255, 0.06);
}
.ai-session-tab.active {
    background: rgba(var(--accent-pr, 139), var(--accent-pg, 92), var(--accent-pb, 246), 0.12);
    color: #fff;
    border-color: rgba(var(--accent-pr, 139), var(--accent-pg, 92), var(--accent-pb, 246), 0.28);
    box-shadow: 0 0 6px rgba(var(--accent-pr, 139), var(--accent-pg, 92), var(--accent-pb, 246), 0.08);
    font-weight: 500;
}

.ai-session-tab-name {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-all;
    font-size: 12px;
    line-height: 1.35;
    pointer-events: none;
    width: 100%;
}

.ai-session-tab-del {
    position: absolute;
    right: 1px;
    top: 1px;
    display: none;
    width: 14px;
    height: 14px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.7);
    color: #fff;
    font-size: 10px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s ease;
    line-height: 1;
}
.ai-session-tab:hover .ai-session-tab-del { opacity: 0.8; display: flex; }

/* Sync button — match RAG pill unified style */
#ai-sync-btn {
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid rgba(100,116,139,0.25);
    border-radius: 999px;
    min-height: 22px;
    padding: 3px 9px;
    font: inherit;
    background: transparent;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    line-height: 1;
    color: inherit;
}
#ai-sync-btn:hover {
    background: rgba(139, 92, 246, 0.1);
    border-color: rgba(139, 92, 246, 0.35);
}

/* ===== Session Panel ===== */
.ai-session-panel {
    display: none;
    position: absolute;
    bottom: 52px;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--ai-modal-bg);
    border: 1px solid var(--ai-modal-border);
    border-bottom-left-radius: var(--ai-modal-radius);
    border-bottom-right-radius: var(--ai-modal-radius);
    padding: 16px;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35);
    animation: aiSlideUp 0.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
.ai-session-panel.is-open {
    display: block;
}

.ai-session-panel-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--ai-title-color);
    margin-bottom: 12px;
}

.ai-session-panel-group {
    margin-bottom: 10px;
}
.ai-session-panel-group label {
    display: block;
    font-size: 11px;
    color: var(--ai-text-muted);
    margin-bottom: 4px;
}
.ai-session-panel-group input {
    width: 100%;
    padding: 7px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--ai-input-border);
    border-radius: 6px;
    color: var(--ai-input-color);
    font-size: 12px;
    outline: none;
    box-sizing: border-box;
}
.ai-session-panel-group input:focus {
    border-color: var(--ai-input-focus-border);
}

.ai-hint {
    font-size: 10px;
    color: var(--ai-text-muted);
    margin-top: 3px;
    line-height: 1.3;
    opacity: 0.7;
}

.ai-session-panel-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}
.ai-btn-primary {
    padding: 6px 14px;
    background: var(--ai-accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s ease;
}
.ai-btn-primary:hover { opacity: 0.85; }
.ai-btn-secondary {
    padding: 6px 14px;
    background: transparent;
    color: var(--ai-text-muted);
    border: 1px solid var(--ai-divider);
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
}
.ai-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--ai-text);
}

/* Sync Toggle Button (inside session panel) */
.ai-sync-toggle-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 7px 12px;
    border: 1px solid;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}
.ai-sync-toggle-btn.ai-sync-active {
    background: rgba(16, 185, 129, 0.08);
    border-color: rgba(16, 185, 129, 0.3);
    color: #10b981;
}
.ai-sync-toggle-btn.ai-sync-active .ai-sync-toggle-icon {
    width: 8px; height: 8px; border-radius: 50%; background: #10b981;
    box-shadow: 0 0 5px rgba(16, 185, 129, 0.5);
}
.ai-sync-toggle-btn.ai-sync-paused {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.3);
    color: #f87171;
}
.ai-sync-toggle-btn.ai-sync-paused .ai-sync-toggle-icon {
    width: 8px; height: 8px; border-radius: 50%; background: #f87171;
    box-shadow: 0 0 5px rgba(239, 68, 68, 0.5);
}

/* ===== Narrow Viewport: Session Bookmarks — Top Horizontal Scroll ===== */
/* MUST come after all desktop rules so mobile overrides take precedence */
@media (max-width: 640px) {
    .ai-assistant-modal-backdrop.is-open {
        flex-direction: column;
        align-items: center;
        padding-top: 8px;
        gap: 2px;
    }
    .ai-session-bookmarks {
        flex-direction: row;
        align-items: center;
        width: 90vw;
        max-width: 90vw;
        height: auto;
        max-height: none;
        margin-right: 0;
        margin-bottom: 0;
        overflow-y: hidden;
        overflow-x: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
        border-radius: 10px;
        padding: 3px 4px;
    }
    .ai-session-bookmarks::-webkit-scrollbar {
        display: none;
    }
    .ai-session-new {
        flex-shrink: 0;
        width: auto;
        min-width: 66px;
        height: 30px;
        margin: 0 3px 0 0;
        padding: 0 10px;
        font-size: 11px;
        border-radius: 6px;
    }
    .ai-session-list {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        flex: 0 0 auto;
        gap: 3px;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    .ai-session-list::-webkit-scrollbar {
        display: none;
    }
    .ai-session-tab {
        flex-shrink: 0;
        width: auto;
        min-width: auto;
        padding: 5px 8px;
        white-space: nowrap;
        min-height: 30px;
        font-size: 11px;
        justify-content: center;
    }
    .ai-session-tab-name {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 5em;
        font-size: 11px;
    }
    .ai-session-tab-del {
        right: 0px;
        top: 0px;
        width: 12px;
        height: 12px;
        font-size: 9px;
    }
}

/* ===== Collaboration Chat Button ===== */
.ai-chat-status-collab {
    background: transparent;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-dim, rgba(255,255,255,0.45));
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(100,116,139,0.25);
    border-radius: 999px;
    min-height: 22px;
    padding: 3px 9px;
    gap: 5px;
    white-space: nowrap;
    line-height: 1;
}
.ai-chat-status-collab:hover {
    color: var(--ai-accent);
    border-color: var(--ai-accent);
    background: rgba(139, 92, 246, 0.1);
}
.ai-chat-status-collab svg {
    width: 14px;
    height: 14px;
}
/* Light theme */
[data-theme="light"] .ai-chat-status-collab {
    color: rgba(0,0,0,0.4);
    border-color: rgba(0,0,0,0.15);
}
[data-theme="light"] .ai-chat-status-collab:hover {
    color: var(--ai-accent);
    border-color: var(--ai-accent);
    background: rgba(139, 92, 246, 0.08);
}

/* ===== Interval Refresh Button (Lightning) ===== */
.ai-chat-status-interval {
    background: transparent;
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-dim, rgba(255,255,255,0.45));
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(100,116,139,0.25);
    border-radius: 999px;
    min-height: 22px;
    padding: 3px 9px;
    gap: 4px;
    white-space: nowrap;
    line-height: 1;
}
.ai-chat-status-interval:hover {
    color: #fbbf24;
    border-color: #fbbf24;
    background: rgba(251, 191, 36, 0.1);
}
.ai-chat-status-interval.is-active {
    color: #fbbf24;
    border-color: #fbbf24;
    background: rgba(251, 191, 36, 0.15);
}
/* Light theme: interval button */
[data-theme="light"] .ai-chat-status-interval {
    color: rgba(0,0,0,0.45);
    border-color: rgba(0,0,0,0.15);
}
[data-theme="light"] .ai-chat-status-interval:hover,
[data-theme="light"] .ai-chat-status-interval.is-active {
    color: #d97706;
    border-color: #d97706;
    background: rgba(251, 191, 36, 0.12);
}

/* ===== Interval Menu (dropdown) ===== */
.ai-interval-menu {
    display: none;
    position: absolute;
    top: calc(100% + 2px);
    right: 0;
    z-index: 210;
    background: var(--ai-modal-bg);
    border: 1px solid var(--ai-modal-border);
    border-radius: 10px;
    padding: 6px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.35);
    min-width: 130px;
    animation: aiSlideUp 0.15s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
.ai-interval-menu.is-open {
    display: block;
}
.ai-interval-menu button {
    display: block;
    width: 100%;
    padding: 7px 12px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--ai-text);
    font-size: 12px;
    cursor: pointer;
    text-align: left;
    transition: background 0.1s;
}
.ai-interval-menu button:hover {
    background: rgba(139, 92, 246, 0.12);
}
.ai-interval-menu button.is-selected {
    color: var(--ai-accent);
    font-weight: 600;
}
/* Light theme */
[data-theme="light"] .ai-interval-menu {
    box-shadow: 0 4px 24px rgba(0,0,0,0.12);
}
[data-theme="light"] .ai-interval-menu button:hover {
    background: rgba(139, 92, 246, 0.08);
}

/* ===== Collaboration Chat Window ===== */
.ai-collab-chat-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10001;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
}
.ai-collab-chat-backdrop.is-open {
    display: flex;
}
.ai-collab-chat-window {
    position: relative;
    width: 380px;
    max-width: 92vw;
    max-height: 520px;
    background: var(--ai-modal-bg);
    border: var(--ai-modal-border);
    border-radius: var(--ai-modal-radius);
    box-shadow: var(--ai-modal-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: var(--ai-modal-animation);
}

/* Collab header */
.ai-collab-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--ai-header-border);
    background: var(--ai-header-bg);
    flex-shrink: 0;
}
.ai-collab-header-left {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-shrink: 0;
}
.ai-collab-header-left svg {
    width: 16px;
    height: 16px;
    color: var(--ai-accent);
}
.ai-collab-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ai-title-color);
    letter-spacing: 0.02em;
}
.ai-collab-header-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}
.ai-collab-header-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid rgba(100,116,139,0.25);
    border-radius: 6px;
    color: var(--ai-text-muted);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 11px;
    line-height: 1;
    min-height: 26px;
    transition: all 0.15s;
}
.ai-collab-header-btn:hover {
    color: var(--ai-text);
    border-color: var(--ai-accent);
}
.ai-collab-close-btn {
    background: transparent;
    border: none;
    color: var(--ai-text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 2px 6px;
    line-height: 1;
    border-radius: 4px;
    transition: all 0.15s;
}
.ai-collab-close-btn:hover {
    color: #f87171;
    background: rgba(239, 68, 68, 0.1);
}

/* Collab resize handles — 8-way (same pattern as main-window floating mode) */
.ai-collab-chat-window {
    position: relative;
}
.ai-collab-resize-edge,
.ai-collab-resize-corner {
    position: absolute;
    z-index: 5;
    touch-action: none;
}
/* Edges - 6px thick */
.ai-collab-resize-n { top: -2px; left: 10px; right: 10px; height: 6px; cursor: ns-resize; }
.ai-collab-resize-s { bottom: -2px; left: 10px; right: 10px; height: 6px; cursor: ns-resize; }
.ai-collab-resize-e { right: -2px; top: 10px; bottom: 10px; width: 6px; cursor: ew-resize; }
.ai-collab-resize-w { left: -2px; top: 10px; bottom: 10px; width: 6px; cursor: ew-resize; }
/* Corners - 12px */
.ai-collab-resize-nw { top: -3px; left: -3px; width: 12px; height: 12px; cursor: nwse-resize; }
.ai-collab-resize-ne { top: -3px; right: -3px; width: 12px; height: 12px; cursor: nesw-resize; }
.ai-collab-resize-sw { bottom: -3px; left: -3px; width: 12px; height: 12px; cursor: nesw-resize; }
.ai-collab-resize-se { bottom: -3px; right: -3px; width: 12px; height: 12px; cursor: nwse-resize; }

/* User name row */
.ai-collab-user-row {
    display: flex;
    gap: 8px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--ai-divider);
    flex-shrink: 0;
    align-items: center;
}
.ai-collab-user-row input {
    flex: 1;
    padding: 6px 10px;
    background: var(--ai-input-bg);
    border: 1px solid var(--ai-input-border);
    border-radius: 6px;
    color: var(--ai-input-color);
    font-size: 12px;
    outline: none;
}
.ai-collab-user-row input:focus {
    border-color: var(--ai-input-focus-border);
}
.ai-collab-user-row button {
    padding: 6px 12px;
    background: var(--ai-accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}
.ai-collab-user-row button:hover {
    background: var(--ai-accent-hover);
}

/* Messages area */
.ai-collab-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 120px;
}
.ai-collab-messages::-webkit-scrollbar {
    width: 4px;
}
.ai-collab-messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.08);
    border-radius: 2px;
}

/* Chat bubbles */
.ai-collab-message-row {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}
.ai-collab-message-row-self {
    align-self: flex-end;
    align-items: flex-end;
}
.ai-collab-message-row-other {
    align-self: flex-start;
    align-items: flex-start;
}

.ai-collab-bubble-self,
.ai-collab-bubble-other {
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
    width: 100%;
    box-sizing: border-box;
}
.ai-collab-bubble-self {
    background: var(--ai-bubble-user-bg);
    border: var(--ai-bubble-user-border);
    color: var(--ai-bubble-user-color);
    border-bottom-right-radius: 4px;
}
.ai-collab-bubble-other {
    background: var(--ai-bubble-assistant-bg);
    border: var(--ai-bubble-assistant-border);
    color: var(--ai-bubble-assistant-color);
    border-bottom-left-radius: 4px;
}

.ai-collab-bubble-meta {
    display: flex;
    gap: 6px;
    padding: 2px 6px 0;
    font-size: 10px;
    opacity: 0.55;
    white-space: nowrap;
}
.ai-collab-bubble-meta .ai-collab-bubble-name {
    font-weight: 600;
}
.ai-collab-bubble-text {
    font-size: 13px;
}
.ai-collab-bubble-time {
    font-size: 10px;
    opacity: 0.7;
}

/* Input row */
.ai-collab-input-row {
    display: flex;
    gap: 8px;
    padding: 8px 14px;
    border-top: 1px solid var(--ai-divider);
    flex-shrink: 0;
}
.ai-collab-input-row input {
    flex: 1;
    padding: 8px 12px;
    background: var(--ai-input-bg);
    border: 1px solid var(--ai-input-border);
    border-radius: 8px;
    color: var(--ai-input-color);
    font-size: 13px;
    outline: none;
}
.ai-collab-input-row input:focus {
    border-color: var(--ai-input-focus-border);
}
.ai-collab-input-row button {
    padding: 8px 16px;
    background: var(--ai-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}
.ai-collab-input-row button:hover {
    background: var(--ai-accent-hover);
}

/* Settings panel */
/* Settings panel — floating overlay above input row */
.ai-collab-settings {
    position: absolute;
    bottom: 54px;
    left: 8px;
    right: 8px;
    max-height: 260px;
    overflow-y: auto;
    padding: 14px;
    background: var(--ai-modal-bg);
    border: 1px solid var(--ai-header-border);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.45);
    z-index: 10;
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.ai-collab-settings.is-open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
.ai-collab-settings::-webkit-scrollbar {
    width: 4px;
}
.ai-collab-settings::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.12);
    border-radius: 2px;
}
.ai-collab-settings label {
    display: block;
    font-size: 11px;
    color: var(--ai-text-muted);
    margin-bottom: 4px;
    margin-top: 8px;
}
.ai-collab-settings label:first-child {
    margin-top: 0;
}
.ai-collab-settings input,
.ai-collab-settings select {
    width: 100%;
    padding: 6px 10px;
    background: var(--ai-settings-input-bg);
    border: 1px solid var(--ai-settings-input-border);
    border-radius: 6px;
    color: var(--ai-input-color);
    font-size: 12px;
    outline: none;
    box-sizing: border-box;
}
.ai-collab-settings input:focus,
.ai-collab-settings select:focus {
    border-color: var(--ai-input-focus-border);
}
.ai-collab-settings select {
    cursor: pointer;
}
.ai-collab-settings-buttons {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}
.ai-collab-settings-buttons button {
    flex: 1;
    padding: 7px 12px;
    background: var(--ai-accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
}
.ai-collab-settings-buttons button:hover {
    background: var(--ai-accent-hover);
}
.ai-collab-settings-buttons .ai-collab-btn-secondary {
    background: rgba(255,255,255,0.08);
    color: var(--ai-text-muted);
}
.ai-collab-settings-buttons .ai-collab-btn-secondary:hover {
    background: rgba(255,255,255,0.12);
}

/* Empty state */
.ai-collab-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--ai-text-muted);
    font-size: 12px;
    gap: 6px;
    opacity: 0.6;
}
.ai-collab-empty svg {
    width: 36px;
    height: 36px;
    opacity: 0.4;
}

/* Light theme overrides for collab chat */
[data-theme="light"] .ai-collab-chat-backdrop {
    background: rgba(0, 0, 0, 0.3);
}
[data-theme="light"] .ai-collab-chat-window {
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .ai-collab-settings {
    background: rgba(0,0,0,0.03);
}
[data-theme="light"] .ai-collab-header-btn {
    border-color: rgba(0,0,0,0.12);
    color: var(--ai-text-muted);
}
[data-theme="light"] .ai-collab-header-btn:hover {
    color: var(--ai-text);
    border-color: var(--ai-accent);
}
[data-theme="light"] .ai-collab-close-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
}
[data-theme="light"] .ai-collab-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.12);
}
[data-theme="light"] .ai-collab-bubble-name {
    color: var(--ai-text-muted);
}
[data-theme="light"] .ai-chat-status-interval {
    color: rgba(0,0,0,0.45);
}
[data-theme="light"] .ai-chat-status-interval:hover,
[data-theme="light"] .ai-chat-status-interval.is-active {
    color: #d97706;
    border-color: #d97706;
    background: rgba(251, 191, 36, 0.12);
}

/* ===== Collab Chat Danger/Delete Button ===== */
.ai-collab-btn-danger {
    background: transparent !important;
    color: var(--ai-btn-reset) !important;
    border: 1px solid var(--ai-btn-reset-border) !important;
}
.ai-collab-btn-danger:hover {
    background: rgba(239, 68, 68, 0.12) !important;
}

/* ===== Toast Notification ===== */
.ai-toast {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 99999;
    padding: 10px 24px;
    background: rgba(0, 0, 0, 0.78);
    color: #fff;
    font-size: 13px;
    border-radius: 999px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
    transform: translateX(-50%) translateY(8px);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}
.ai-toast.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
[data-theme="light"] .ai-toast {
    background: rgba(30, 30, 40, 0.85);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* ===== Mobile Responsive: Collab Chat Overlay ===== */
@media (max-width: 640px) {
    .ai-collab-chat-backdrop {
        align-items: flex-start;
        justify-content: center;
        padding-top: 10vh;
    }
    .ai-collab-chat-window {
        width: 94vw;
        max-width: 420px;
        max-height: 70vh;
        border-radius: 14px;
    }
    .ai-collab-messages {
        max-height: 40vh;
    }
    /* On very narrow screens, overlay above AI modal */
    @media (max-width: 420px) {
        .ai-collab-chat-backdrop {
            padding-top: 4vh;
        }
        .ai-collab-chat-window {
            width: 96vw;
            max-width: 100vw;
            max-height: 82vh;
        }
        .ai-collab-messages {
            max-height: 50vh;
        }
        .ai-collab-chat-header {
            padding: 8px 10px;
        }
        .ai-collab-user-row {
            padding: 6px 10px;
        }
        .ai-collab-input-row {
            padding: 6px 10px;
        }
    }
}
