/* Anteroom — Premium Chat UI */

/* ============================================================
   SELF-HOSTED FONTS
   ============================================================ */
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/inter-regular.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 500; font-display: swap; src: url('/fonts/inter-500.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 600; font-display: swap; src: url('/fonts/inter-600.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 700; font-display: swap; src: url('/fonts/inter-700.woff2') format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/jetbrains-mono-regular.woff2') format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 500; font-display: swap; src: url('/fonts/jetbrains-mono-500.woff2') format('woff2'); }
@font-face { font-family: 'Cinzel'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/cinzel-regular.woff2') format('woff2'); }
@font-face { font-family: 'Cinzel'; font-style: normal; font-weight: 700; font-display: swap; src: url('/fonts/cinzel-700.woff2') format('woff2'); }

/* ============================================================
   THEME SYSTEM — CSS Custom Properties
   ============================================================ */

:root {
    --transition-speed: 0.15s;
    --transition-theme: 0.5s;
    --easing: cubic-bezier(0.4, 0, 0.2, 1);
    --easing-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', 'Monaco', monospace;
    --font-deco: 'Cinzel', 'Georgia', serif;
}

/* --- Midnight (Default) — Digital Speakeasy dark --- */
[data-theme="midnight"], :root {
    --bg-primary: #0f1115;
    --bg-secondary: #13151d;
    --bg-sidebar: rgba(15, 17, 21, 0.85);
    --bg-input: #1a1d27;
    --bg-hover: #1e2130;
    --bg-active: #252838;
    --bg-card: #161821;
    --bg-user-msg: #1e2330;
    --bg-assistant-msg: transparent;
    --bg-tool-call: #141729;
    --bg-gradient-start: #0f1115;
    --bg-gradient-end: #0d0f15;

    --text-primary: #e4e5e9;
    --text-secondary: #b8c4d4;
    --text-muted: #8890a0;

    --border-color: rgba(255, 255, 255, 0.06);
    --border-glow: rgba(197, 160, 89, 0.2);

    --accent: #C5A059;
    --accent-hover: #b08d4a;
    --accent-glow: rgba(197, 160, 89, 0.3);
    --accent-subtle: rgba(197, 160, 89, 0.1);
    --accent-gradient-start: #C5A059;
    --accent-gradient-end: #b08d4a;
    --accent-blue: #3B82F6;

    --error: #ef4444;
    --warning: #f59e0b;

    --code-bg: #0d0f15;
    --code-header-bg: #13151d;
    --code-border: rgba(255, 255, 255, 0.04);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 20px rgba(197, 160, 89, 0.15);

    --input-glow: 0 0 0 2px rgba(197, 160, 89, 0.15), 0 0 20px rgba(197, 160, 89, 0.08);
    --sidebar-blur: blur(20px);
    --sidebar-opacity: 0.85;
    --modal-backdrop-blur: blur(8px);

    --topbar-bg: rgba(15, 17, 21, 0.8);

    --scrollbar-thumb: #2a2d3a;
    --scrollbar-track: transparent;

    --msg-user-border: var(--accent-blue);
    --welcome-gradient: linear-gradient(135deg, #C5A059, #3B82F6);
}

/* --- Dawn — Warm editorial light --- */
[data-theme="dawn"] {
    --bg-primary: #faf8f5;
    --bg-secondary: #f2efe9;
    --bg-sidebar: rgba(242, 239, 233, 0.95);
    --bg-input: #ffffff;
    --bg-hover: #edeae4;
    --bg-active: #e5e1da;
    --bg-card: #ffffff;
    --bg-user-msg: #ffffff;
    --bg-assistant-msg: transparent;
    --bg-tool-call: #faf6ee;
    --bg-gradient-start: #faf8f5;
    --bg-gradient-end: #f5f2ed;

    --text-primary: #1a1a1a;
    --text-secondary: #6b6b6b;
    --text-muted: #9a9a9a;

    --border-color: rgba(0, 0, 0, 0.08);
    --border-glow: rgba(156, 124, 58, 0.2);

    --accent: #9C7C3A;
    --accent-hover: #86692e;
    --accent-glow: rgba(156, 124, 58, 0.2);
    --accent-subtle: rgba(156, 124, 58, 0.08);
    --accent-gradient-start: #9C7C3A;
    --accent-gradient-end: #86692e;
    --accent-blue: #2563EB;

    --error: #dc2626;
    --warning: #d97706;

    --code-bg: #f6f4f0;
    --code-header-bg: #edeae4;
    --code-border: rgba(0, 0, 0, 0.06);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);
    --shadow-glow: 0 0 20px rgba(156, 124, 58, 0.1);

    --input-glow: 0 0 0 2px rgba(156, 124, 58, 0.12), 0 0 16px rgba(156, 124, 58, 0.06);
    --sidebar-blur: blur(12px);
    --sidebar-opacity: 0.95;
    --modal-backdrop-blur: blur(6px);

    --topbar-bg: rgba(250, 248, 245, 0.9);

    --scrollbar-thumb: #d4d0c8;
    --scrollbar-track: transparent;

    --msg-user-border: var(--accent-blue);
    --welcome-gradient: linear-gradient(135deg, #9C7C3A, #C5A059);
}

/* --- Aurora — Dark with animated gradient accents --- */
[data-theme="aurora"] {
    --bg-primary: #090b10;
    --bg-secondary: #0c0e14;
    --bg-sidebar: rgba(9, 11, 16, 0.85);
    --bg-input: #12151e;
    --bg-hover: #161a26;
    --bg-active: #1c2030;
    --bg-card: #0f1118;
    --bg-user-msg: #12151e;
    --bg-assistant-msg: transparent;
    --bg-tool-call: #10122a;
    --bg-gradient-start: #090b10;
    --bg-gradient-end: #060810;

    --text-primary: #e2e4ea;
    --text-secondary: #8a8ea0;
    --text-muted: #555872;

    --border-color: rgba(255, 255, 255, 0.05);
    --border-glow: rgba(197, 160, 89, 0.3);

    --accent: #C5A059;
    --accent-hover: #b08d4a;
    --accent-glow: rgba(197, 160, 89, 0.3);
    --accent-subtle: rgba(197, 160, 89, 0.1);
    --accent-gradient-start: #C5A059;
    --accent-gradient-end: #3B82F6;
    --accent-blue: #3B82F6;

    --error: #ef4444;
    --warning: #f59e0b;

    --code-bg: #060810;
    --code-header-bg: #0c0e14;
    --code-border: rgba(255, 255, 255, 0.04);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 30px rgba(197, 160, 89, 0.15), 0 0 60px rgba(59, 130, 246, 0.08);

    --input-glow: 0 0 0 2px rgba(197, 160, 89, 0.2), 0 0 20px rgba(197, 160, 89, 0.1);
    --sidebar-blur: blur(24px);
    --sidebar-opacity: 0.85;
    --modal-backdrop-blur: blur(12px);

    --topbar-bg: rgba(9, 11, 16, 0.8);

    --scrollbar-thumb: #1c2030;
    --scrollbar-track: transparent;

    --msg-user-border: linear-gradient(to bottom, #C5A059, #3B82F6);
    --welcome-gradient: linear-gradient(135deg, #C5A059, #3B82F6, #10b981);
}

/* --- Ember — Warm luxury dark --- */
[data-theme="ember"] {
    --bg-primary: #171210;
    --bg-secondary: #1a1512;
    --bg-sidebar: rgba(23, 18, 16, 0.88);
    --bg-input: #211a16;
    --bg-hover: #271f1a;
    --bg-active: #30261e;
    --bg-card: #1e1814;
    --bg-user-msg: #231c17;
    --bg-assistant-msg: transparent;
    --bg-tool-call: #241a14;
    --bg-gradient-start: #171210;
    --bg-gradient-end: #130f0c;

    --text-primary: #e8e0d8;
    --text-secondary: #a89888;
    --text-muted: #6e5e50;

    --border-color: rgba(255, 255, 255, 0.06);
    --border-glow: rgba(197, 160, 89, 0.25);

    --accent: #C5A059;
    --accent-hover: #b08d4a;
    --accent-glow: rgba(197, 160, 89, 0.25);
    --accent-subtle: rgba(197, 160, 89, 0.1);
    --accent-gradient-start: #C5A059;
    --accent-gradient-end: #b08d4a;
    --accent-blue: #3B82F6;

    --error: #ef4444;
    --warning: #f59e0b;

    --code-bg: #130f0c;
    --code-header-bg: #1a1512;
    --code-border: rgba(255, 255, 255, 0.04);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 20px rgba(197, 160, 89, 0.12);

    --input-glow: 0 0 0 2px rgba(197, 160, 89, 0.15), 0 0 20px rgba(197, 160, 89, 0.08);
    --sidebar-blur: blur(20px);
    --sidebar-opacity: 0.88;
    --modal-backdrop-blur: blur(8px);

    --topbar-bg: rgba(23, 18, 16, 0.8);

    --scrollbar-thumb: #30261e;
    --scrollbar-track: transparent;

    --msg-user-border: var(--accent-blue);
    --welcome-gradient: linear-gradient(135deg, #C5A059, #b08d4a);
}


/* ============================================================
   RESET & BASE
   ============================================================ */

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

html {
    height: 100%;
    transition: background-color var(--transition-theme) var(--easing),
                color var(--transition-theme) var(--easing);
}

body {
    height: 100%;
    font-family: var(--font-ui);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================================
   SCROLLBAR
   ============================================================ */

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

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}


/* ============================================================
   LAYOUT
   ============================================================ */

.app-container {
    display: flex;
    height: 100vh;
    background: linear-gradient(180deg, var(--bg-gradient-start), var(--bg-gradient-end));
}


/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-sidebar);
    -webkit-backdrop-filter: var(--sidebar-blur);
    backdrop-filter: var(--sidebar-blur);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    transition: width 0.25s var(--easing), min-width 0.25s var(--easing),
                background-color var(--transition-theme) var(--easing);
    z-index: 10;
}

.sidebar-header {
    padding: 12px 12px 8px;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 8px 0 12px;
    font-family: 'Cinzel', Georgia, serif;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--accent);
}

.btn-new-chat {
    width: 100%;
    padding: 9px 14px;
    background: transparent;
    color: var(--text-primary);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-ui);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all var(--transition-speed) var(--easing);
}
.btn-new-chat:hover {
    background: var(--accent-subtle);
    border-style: solid;
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: var(--shadow-glow);
}
.btn-new-chat svg {
    flex-shrink: 0;
    opacity: 0.7;
    transition: transform var(--transition-speed) var(--easing),
                opacity var(--transition-speed) var(--easing);
}
.btn-new-chat:hover svg {
    opacity: 1;
    transform: rotate(90deg);
}

.new-chat-row {
    display: flex;
    gap: 4px;
}
.new-chat-row .btn-new-chat {
    flex: 1;
}
.btn-new-type-dropdown {
    padding: 9px 8px;
    background: transparent;
    color: var(--text-muted);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-speed) var(--easing);
}
.btn-new-type-dropdown:hover {
    background: var(--accent-subtle);
    border-style: solid;
    border-color: var(--accent);
    color: var(--accent);
}

.new-conv-dropdown {
    min-width: 130px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 60;
    padding: 4px;
    font-size: 13px;
}
.new-conv-dropdown-item {
    padding: 7px 12px;
    border-radius: 5px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background var(--transition-speed) var(--easing);
}
.new-conv-dropdown-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.new-conv-type {
    padding: 6px 4px;
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font-ui);
    transition: all var(--transition-speed) var(--easing);
}
.new-conv-type:hover {
    border-style: solid;
    border-color: var(--accent);
    color: var(--accent);
}

.sidebar-type-filter {
    padding: 6px 4px;
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 11px;
    font-family: var(--font-ui);
    flex-shrink: 0;
}

.conv-type-badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
    margin-right: 4px;
}
.conv-type-note {
    background: var(--accent-subtle);
    color: var(--accent);
}
.conv-type-document {
    background: rgba(139, 92, 246, 0.15);
    color: rgb(139, 92, 246);
}

.sidebar-search {
    padding: 0 12px 10px;
    display: flex;
    gap: 6px;
}
.sidebar-search input {
    flex: 1;
    min-width: 0;
    padding: 7px 12px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 12px;
    font-family: var(--font-ui);
    outline: none;
    transition: border-color var(--transition-speed) var(--easing),
                box-shadow var(--transition-speed) var(--easing);
}
.sidebar-search input:focus {
    border-color: var(--accent);
    box-shadow: var(--input-glow);
}
.sidebar-search input::placeholder {
    color: var(--text-muted);
}
.type-filter-select {
    width: 72px;
    padding: 5px 6px;
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 11px;
    font-family: var(--font-ui);
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 4px center;
    padding-right: 18px;
    transition: border-color var(--transition-speed) var(--easing);
}
.type-filter-select:focus {
    border-color: var(--accent);
}
.type-filter-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.conversation-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all var(--transition-speed) var(--easing);
}
.conversation-item:hover {
    background: var(--bg-hover);
}
.conversation-item.active {
    background: var(--bg-active);
    color: var(--text-primary);
}
.conversation-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
    animation: slideIndicator 0.2s var(--easing);
}

@keyframes slideIndicator {
    from { height: 0%; opacity: 0; }
    to { height: 60%; opacity: 1; }
}

.conversation-item .conv-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item .conv-slug {
    display: block;
    font-size: 0.7em;
    opacity: 0.5;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-item .conv-actions {
    display: none;
    gap: 4px;
    flex-shrink: 0;
}
.conversation-item:hover .conv-actions {
    display: flex;
}

.conv-actions button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 12px;
    border-radius: 4px;
    transition: all var(--transition-speed) var(--easing);
}
.conv-actions button:hover {
    color: var(--text-primary);
    background: var(--bg-primary);
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-settings {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 13px;
    font-family: var(--font-ui);
    transition: all var(--transition-speed) var(--easing);
}
.btn-settings:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.mcp-status {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: auto;
}


/* ============================================================
   FOLDERS
   ============================================================ */

.folder-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    transition: color var(--transition-speed) var(--easing);
    user-select: none;
}
.folder-header:hover {
    color: var(--text-secondary);
}
.folder-header .folder-chevron {
    display: flex;
    transition: transform var(--transition-speed) var(--easing);
}
.folder-header.collapsed .folder-chevron {
    transform: rotate(-90deg);
}
.folder-header .folder-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.folder-header .folder-actions {
    display: none;
    gap: 2px;
}
.folder-header:hover .folder-actions {
    display: flex;
}
.folder-actions button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 11px;
    border-radius: 3px;
    transition: color var(--transition-speed) var(--easing);
}
.folder-actions button:hover {
    color: var(--text-primary);
}

.folder-contents {
    overflow: hidden;
    transition: max-height 0.3s var(--easing);
}
.folder-contents.collapsed {
    max-height: 0 !important;
}

.folder-contents .conversation-item {
    padding-left: 28px;
}
.folder-header .folder-actions button[data-action="subfolder"] {
    font-size: 14px;
    font-weight: 700;
}

.move-to-folder-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 12px;
    border-radius: 4px;
    transition: color var(--transition-speed) var(--easing);
}
.move-to-folder-btn:hover {
    color: var(--accent);
}

.folder-dropdown {
    position: fixed;
    min-width: 160px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 60;
    padding: 4px;
    font-size: 13px;
}
.folder-dropdown-item {
    padding: 6px 10px;
    border-radius: 5px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background var(--transition-speed) var(--easing);
}
.folder-dropdown-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.db-copy-dropdown {
    position: fixed;
    min-width: 160px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 60;
    padding: 4px;
    font-size: 13px;
}

/* Tags on conversations */
.conv-tags {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-top: 2px;
}
.conv-tag {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 3px;
    border: 1px solid;
    line-height: 1.4;
    white-space: nowrap;
}
.conversation-item {
    flex-wrap: wrap;
}

/* Tag dropdown */
.tag-dropdown {
    position: fixed;
    min-width: 160px;
    max-height: 240px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 60;
    padding: 4px;
    font-size: 13px;
}
.tag-dropdown-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 5px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background var(--transition-speed) var(--easing);
}
.tag-dropdown-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.tag-dropdown-item.active {
    color: var(--accent);
    font-weight: 500;
}
.tag-dropdown-new {
    border-top: 1px solid var(--border-color);
    margin-top: 2px;
    padding-top: 8px;
    color: var(--accent);
}
.tag-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Drag-and-drop */
.conversation-item.dragging {
    opacity: 0.4;
}
.folder-header.drag-over,
.folder-contents.drag-over,
.unfiled-zone.drag-over {
    background: var(--accent-glow);
    border-radius: 6px;
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
}
.drop-candidate {
    transition: background 0.15s var(--easing), outline 0.15s var(--easing);
}
.unfiled-zone {
    min-height: 8px;
}

/* Conversation type badges */
.conv-type-badge {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
    line-height: 1.4;
}
.conv-type-note {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}
.conv-type-document {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}


/* ============================================================
   NOTE ENTRIES
   ============================================================ */

/* --- Date Group Headers --- */
.note-date-header {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px 8px;
}
.note-date-header:first-child {
    padding-top: 8px;
}
.note-date-line {
    flex: 1;
    height: 1px;
    background: var(--border-color);
}
.note-date-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

/* --- Note Entries --- */
.note-entry {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    animation: messageIn 0.3s var(--easing);
    position: relative;
}
.note-entry:last-child {
    border-bottom: none;
}

.note-entry-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.note-entry-timestamp {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.note-entry-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s var(--easing);
}
.note-entry:hover .note-entry-actions {
    opacity: 1;
}

.note-action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 3px 5px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: all 0.12s var(--easing);
}
.note-action-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.note-action-delete:hover {
    color: var(--error);
    background: rgba(239, 68, 68, 0.1);
}

.note-entry-content {
    font-size: 15px;
    line-height: 1.65;
    color: var(--text-primary);
}
.note-entry-content p { margin-bottom: 8px; }
.note-entry-content p:last-child { margin-bottom: 0; }
.note-entry-content pre { margin: 8px 0; }
.note-entry-content code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 13px;
    border: 1px solid var(--code-border);
}
.note-entry-content pre code {
    display: block;
    padding: 12px 16px;
    border-radius: 0;
    border: none;
}

/* --- Note Inline Edit --- */
.note-edit-textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--accent);
    border-radius: 8px;
    font-size: 15px;
    line-height: 1.6;
    font-family: var(--font-ui);
    resize: vertical;
    min-height: 80px;
    outline: none;
    box-shadow: var(--input-glow);
}
.note-edit-buttons {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    justify-content: flex-end;
}
.note-edit-buttons .btn-modal-save,
.note-edit-buttons .btn-modal-cancel {
    padding: 6px 14px;
    font-size: 12px;
}

/* --- Note Delete Confirmation --- */
.note-delete-confirm {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    margin-top: 8px;
    background: rgba(239, 68, 68, 0.06);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    animation: messageIn 0.15s var(--easing);
}
.note-delete-yes {
    padding: 4px 12px;
    background: var(--error);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font-ui);
    transition: background 0.12s;
}
.note-delete-yes:hover {
    background: #dc2626;
}
.note-delete-no {
    padding: 4px 12px;
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font-ui);
    transition: all 0.12s;
}
.note-delete-no:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* --- Note Entry Remove Animation --- */
@keyframes noteRemove {
    from { opacity: 1; max-height: 500px; padding: 12px 20px; margin-bottom: 0; }
    to { opacity: 0; max-height: 0; padding: 0 20px; margin-bottom: 0; overflow: hidden; }
}
.note-entry-removing {
    animation: noteRemove 0.3s var(--easing) forwards;
}


/* ============================================================
   DOCUMENT VIEW
   ============================================================ */

/* --- Document Toolbar --- */
.document-toolbar {
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px 0;
}
.document-word-count {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}
.document-edit-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font-ui);
    transition: all 0.15s var(--easing);
}
.document-edit-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-subtle);
}

/* --- Document Edit Mode --- */
.document-edit-area {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px 20px 40px;
    width: 100%;
}
.document-edit-textarea {
    width: 100%;
    min-height: 400px;
    padding: 20px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.7;
    font-family: var(--font-mono);
    resize: vertical;
    outline: none;
    transition: border-color 0.15s var(--easing), box-shadow 0.15s var(--easing);
}
.document-edit-textarea:focus {
    border-color: var(--accent);
    box-shadow: var(--input-glow);
}
.document-edit-buttons {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    justify-content: flex-end;
}
.document-edit-buttons .btn-modal-save,
.document-edit-buttons .btn-modal-cancel {
    padding: 8px 18px;
    font-size: 13px;
}

.document-view {
    max-width: 720px;
    margin: 0 auto;
    padding: 40px 20px;
}
.document-section {
    font-size: 16px;
    line-height: 1.75;
    color: var(--text-primary);
    margin-bottom: 24px;
}
.document-section:last-child { margin-bottom: 0; }
.document-section h1,
.document-section h2,
.document-section h3 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}
.document-section h1:first-child,
.document-section h2:first-child,
.document-section h3:first-child {
    margin-top: 0;
}
.document-section p { margin-bottom: 12px; }
.document-section p:last-child { margin-bottom: 0; }
.document-section pre {
    position: relative;
    margin: 12px 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--code-border);
}
.document-section code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 13px;
    border: 1px solid var(--code-border);
}
.document-section pre code {
    display: block;
    padding: 12px 16px;
    background: var(--code-bg);
    border-radius: 0;
    border: none;
}
.document-section ul, .document-section ol {
    margin: 8px 0;
    padding-left: 24px;
}
.document-section li { margin: 4px 0; }
.document-section table {
    border-collapse: collapse;
    margin: 12px 0;
    width: 100%;
}
.document-section th, .document-section td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}
.document-section th {
    background: var(--bg-input);
}
.document-section blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--text-secondary);
}


/* ============================================================
   MAIN CHAT AREA
   ============================================================ */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: linear-gradient(180deg, var(--bg-gradient-start), var(--bg-gradient-end));
}

.setup-banner {
    padding: 12px 20px;
    background: var(--warning);
    color: #000;
    text-align: center;
    font-size: 14px;
}
.setup-banner code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: var(--font-mono);
}

/* Chat topbar */
.chat-topbar {
    padding: 8px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    background: var(--topbar-bg);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}

.mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: all var(--transition-speed) var(--easing);
}
.mobile-menu-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}


/* ============================================================
   MESSAGES
   ============================================================ */

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
}

.welcome-message {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-secondary);
    animation: fadeIn 0.5s var(--easing);
}
.welcome-logo {
    margin-bottom: 24px;
    opacity: 0.9;
}
.welcome-message h2 {
    font-family: var(--font-deco);
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 12px;
    background: var(--welcome-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.welcome-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 28px;
    max-width: 380px;
    margin-left: auto;
    margin-right: auto;
}
.welcome-action {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
    color: var(--text-primary);
    transition: background 0.15s var(--easing), border-color 0.15s var(--easing);
}
.welcome-action:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}
.welcome-action-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--bg-sidebar);
    color: var(--accent);
}
.welcome-action-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.welcome-action-text strong {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}
.welcome-action-text span {
    font-size: 12px;
    color: var(--text-secondary);
}
.welcome-tips {
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}
.welcome-tips strong {
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 1px 5px;
    background: var(--bg-input);
    border-radius: 4px;
    border: 1px solid var(--border-color);
}
.welcome-tip-sep {
    opacity: 0.4;
}

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

.message {
    padding: 16px 0;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    padding-left: 20px;
    padding-right: 20px;
    animation: messageIn 0.3s var(--easing);
}

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

.message.user .message-content {
    background: var(--bg-user-msg);
    padding: 12px 16px;
    border-radius: 12px;
    border-left: 3px solid var(--accent);
    box-shadow: var(--shadow-sm);
}

.message.assistant .message-content {
    border-left: 2px solid var(--accent);
    padding-left: 16px;
}

.message-role {
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.message.user .message-role {
    color: var(--accent-blue, var(--accent));
}
.message.assistant .message-role {
    color: var(--accent);
}

.message.system-hidden {
    display: none;
}

.message-content {
    line-height: 1.65;
    font-size: 15px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-content p {
    margin-bottom: 12px;
}
.message-content p:last-child {
    margin-bottom: 0;
}

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

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

.message-content table {
    border-collapse: collapse;
    margin: 12px 0;
    width: 100%;
}
.message-content th, .message-content td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}
.message-content th {
    background: var(--bg-input);
}


/* ============================================================
   CODE BLOCKS
   ============================================================ */

.message-content pre {
    position: relative;
    margin: 12px 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--code-border);
    box-shadow: var(--shadow-sm);
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--code-header-bg);
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    border-bottom: 1px solid var(--code-border);
}

.btn-copy-code {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font-ui);
    padding: 2px 8px;
    border-radius: 4px;
    opacity: 0;
    transition: all var(--transition-speed) var(--easing);
}
.message-content pre:hover .btn-copy-code {
    opacity: 1;
}
.btn-copy-code:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.message-content pre code {
    display: block;
    padding: 12px 16px;
    background: var(--code-bg);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
}

.message-content code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 13px;
    border: 1px solid var(--code-border);
}
.message-content pre code {
    padding: 12px 16px;
    border-radius: 0;
    border: none;
}


/* ============================================================
   MESSAGE ACTIONS
   ============================================================ */

.message-actions {
    margin-top: 8px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity var(--transition-speed) var(--easing);
}
.message:hover .message-actions {
    opacity: 1;
}
@media (hover: none) {
    .message-actions {
        opacity: 1;
    }
}

.btn-action-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-family: var(--font-ui);
    transition: all var(--transition-speed) var(--easing);
}
.btn-action-icon:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    transform: scale(1.05);
}

.btn-copy-message {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font-ui);
    padding: 4px 8px;
    border-radius: 4px;
    transition: all var(--transition-speed) var(--easing);
}
.btn-copy-message:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}


/* ============================================================
   RAG SOURCE PROVENANCE
   ============================================================ */

.rag-sources {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-ui);
}
.rag-sources summary {
    cursor: pointer;
    user-select: none;
    opacity: 0.6;
    transition: opacity var(--transition-speed) var(--easing);
}
.rag-sources summary:hover {
    opacity: 1;
}
.rag-sources-list {
    list-style: none;
    padding: 4px 0 0 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.rag-sources-list li {
    display: flex;
    align-items: center;
    gap: 4px;
}
.source-badge {
    display: inline-block;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 500;
}
.source-badge--source, .source-badge--knowledge {
    background: rgba(59, 130, 246, 0.15);
    color: #6ea8fe;
}
.source-badge--message, .source-badge--conversation {
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
}
.source-badge--attached {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
}
.source-label {
    opacity: 0.8;
}

/* ============================================================
   MESSAGE EDIT
   ============================================================ */

.message-edit-textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--accent);
    border-radius: 8px;
    font-size: 15px;
    line-height: 1.6;
    font-family: var(--font-ui);
    resize: vertical;
    min-height: 60px;
    outline: none;
    box-shadow: var(--input-glow);
}
.message-edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    justify-content: flex-end;
}
.message-edit-actions .btn-modal-save,
.message-edit-actions .btn-modal-cancel {
    padding: 6px 14px;
    font-size: 12px;
}


/* ============================================================
   TOOL CALLS
   ============================================================ */

.tool-call {
    margin: 8px 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-tool-call);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.tool-call summary {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    list-style: none;
    transition: background var(--transition-speed) var(--easing);
}
.tool-call summary:hover {
    background: var(--bg-hover);
}
.tool-call summary::-webkit-details-marker {
    display: none;
}
.tool-call summary::before {
    content: '\25B6 ';
    font-size: 10px;
    margin-right: 6px;
    display: inline-block;
    transition: transform var(--transition-speed) var(--easing);
}
.tool-call[open] summary::before {
    transform: rotate(90deg);
}
.tool-call .tool-content {
    padding: 8px 12px;
    border-top: 1px solid var(--border-color);
    font-size: 13px;
}
.tool-call .tool-content pre {
    margin: 4px 0;
}
.tool-call.tool-status-success summary::after {
    content: '\2713';
    color: #22c55e;
    margin-left: 6px;
    font-size: 12px;
}
.tool-call.tool-status-error summary::after {
    content: '\2717';
    color: var(--error);
    margin-left: 6px;
    font-size: 12px;
}
.tool-call.tool-status-error {
    border-color: rgba(239, 68, 68, 0.3);
}
.tool-call .tool-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

.tool-call .tool-elapsed {
    color: var(--text-muted);
    font-size: 0.85em;
    margin-left: 6px;
}


/* ============================================================
   TOOL CALL GROUPS (dedup)
   ============================================================ */

.tool-call-group {
    margin: 8px 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.tool-call-group > summary {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
    list-style: none;
    transition: background var(--transition-speed) var(--easing);
}
.tool-call-group > summary:hover {
    background: var(--bg-hover);
}
.tool-call-group > summary::-webkit-details-marker {
    display: none;
}
.tool-call-group > summary::before {
    content: '\25B6 ';
    font-size: 10px;
    margin-right: 6px;
    display: inline-block;
    transition: transform var(--transition-speed) var(--easing);
}
.tool-call-group[open] > summary::before {
    transform: rotate(90deg);
}
.tool-call-group > .tool-call {
    margin: 0;
    border: none;
    border-top: 1px solid var(--border-color);
    border-radius: 0;
    box-shadow: none;
}

/* ============================================================
   ATTACHMENTS
   ============================================================ */

.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}
.attachment-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--bg-input);
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.attachment-chip img {
    max-width: 120px;
    max-height: 80px;
    border-radius: 4px;
}


/* ============================================================
   THINKING INDICATOR
   ============================================================ */

.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
    color: var(--text-muted);
    font-size: 13px;
}
.thinking-dot {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: pulse 1.4s infinite;
}
.thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dot:nth-child(3) { animation-delay: 0.4s; }

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

.thinking-phase-label {
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.7;
    margin-left: 6px;
    white-space: nowrap;
    transition: color 0.3s ease, opacity 0.3s ease;
}
.thinking-phase-label.stall {
    color: var(--warning, #e2a93b);
    opacity: 1;
}

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


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

.input-area {
    border-top: 1px solid var(--border-color);
    padding: 16px 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.attachment-previews {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}
.attachment-previews:empty {
    display: none;
    margin: 0;
}

.attachment-preview {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}
.attachment-preview .remove-attachment {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    transition: color var(--transition-speed) var(--easing);
}
.attachment-preview .remove-attachment:hover {
    color: var(--error);
}
.attachment-preview img {
    max-width: 48px;
    max-height: 32px;
    border-radius: 3px;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: transparent;
    border-radius: 0;
    padding: 8px 4px;
    border: none;
    border-bottom: 1px solid #334155;
    transition: border-color var(--transition-speed) var(--easing),
                box-shadow var(--transition-speed) var(--easing);
}
.input-row:focus-within {
    border-bottom-color: var(--accent);
    box-shadow: 0 1px 0 0 var(--accent);
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 200px;
    font-family: var(--font-ui);
}
#message-input::placeholder {
    color: var(--text-muted);
}

.btn-attach, .btn-send, .btn-stop {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-speed) var(--easing);
}
.btn-attach:hover {
    color: var(--text-primary);
    transform: scale(1.05);
}
.btn-send {
    color: var(--accent);
}
.btn-send:hover {
    color: var(--accent-hover);
    transform: scale(1.05);
    filter: drop-shadow(0 0 8px var(--accent-glow));
}
.btn-send:disabled {
    color: var(--text-muted);
    cursor: default;
    transform: none;
    filter: none;
}
.btn-stop {
    color: var(--error);
}
.btn-stop:hover {
    color: #dc2626;
}


/* ============================================================
   ERRORS & LOADING
   ============================================================ */

.error-message {
    padding: 8px 12px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    border-radius: 6px;
    color: var(--error);
    font-size: 13px;
    margin-top: 8px;
}

.btn-retry {
    background: none;
    border: 1px solid var(--error);
    color: var(--error);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-family: var(--font-ui);
    margin-top: 6px;
    transition: background var(--transition-speed) var(--easing);
}
.btn-retry:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* --- Approval Prompt --- */
.approval-prompt {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    margin: 12px 0;
    background: rgba(234, 179, 8, 0.06);
    border: 1px solid rgba(234, 179, 8, 0.3);
    border-radius: 8px;
    font-size: 13px;
    animation: approval-slide-in 0.2s var(--easing);
}
@keyframes approval-slide-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.approval-icon {
    flex-shrink: 0;
    color: #eab308;
    padding-top: 2px;
}
.approval-body {
    flex: 1;
    min-width: 0;
}
.approval-title {
    font-weight: 600;
    color: #eab308;
    margin-bottom: 4px;
}
.approval-reason {
    color: var(--text-secondary);
    margin-bottom: 8px;
    word-break: break-word;
}
.approval-details code {
    display: inline-block;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-primary);
    word-break: break-all;
    margin-bottom: 8px;
}
.approval-actions {
    display: flex;
    gap: 8px;
}
.approval-btn {
    padding: 6px 16px;
    border-radius: 6px;
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background var(--transition-speed) var(--easing), opacity var(--transition-speed);
}
.approval-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.approval-deny {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.approval-deny:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.25);
}
.approval-allow {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.3);
}
.approval-allow:hover:not(:disabled) {
    background: rgba(34, 197, 94, 0.25);
}
.approval-session {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.3);
}
.approval-session:hover:not(:disabled) {
    background: rgba(59, 130, 246, 0.25);
}
.approval-always {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
    border: 1px solid rgba(168, 85, 247, 0.3);
}
.approval-always:hover:not(:disabled) {
    background: rgba(168, 85, 247, 0.25);
}
.approval-status {
    font-size: 12px;
    font-weight: 500;
    padding: 4px 0;
}
.approval-allowed .approval-status {
    color: #22c55e;
}
.approval-denied .approval-status {
    color: #ef4444;
}
.approval-allowed {
    border-color: rgba(34, 197, 94, 0.2);
    background: rgba(34, 197, 94, 0.04);
}
.approval-denied {
    border-color: rgba(239, 68, 68, 0.2);
    background: rgba(239, 68, 68, 0.04);
}
.approval-expired .approval-status {
    color: #9ca3af;
}
.approval-expired {
    border-color: rgba(156, 163, 175, 0.2);
    background: rgba(156, 163, 175, 0.04);
    opacity: 0.7;
}

/* ask_user prompt card */
.ask-user-prompt {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    margin: 12px 0;
    background: rgba(59, 130, 246, 0.06);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 8px;
    font-size: 13px;
    animation: approval-slide-in 0.2s var(--easing);
}
.ask-user-icon {
    flex-shrink: 0;
    color: #3b82f6;
    padding-top: 2px;
}
.ask-user-body {
    flex: 1;
    min-width: 0;
}
.ask-user-title {
    font-weight: 600;
    color: #3b82f6;
    margin-bottom: 4px;
}
.ask-user-question {
    color: var(--text-primary);
    margin-bottom: 10px;
    word-break: break-word;
}
.ask-user-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.ask-user-btn {
    padding: 6px 16px;
    border-radius: 6px;
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background var(--transition-speed) var(--easing), opacity var(--transition-speed);
}
.ask-user-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.ask-user-option {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.3);
}
.ask-user-option:hover:not(:disabled) {
    background: rgba(59, 130, 246, 0.25);
}
.ask-user-submit {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.3);
}
.ask-user-submit:hover:not(:disabled) {
    background: rgba(34, 197, 94, 0.25);
}
.ask-user-cancel {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.ask-user-cancel:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.25);
}
.ask-user-input-row {
    display: flex;
    gap: 8px;
    width: 100%;
}
.ask-user-input {
    flex: 1;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid rgba(59, 130, 246, 0.3);
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 12px;
    outline: none;
}
.ask-user-input:focus {
    border-color: #3b82f6;
}
.ask-user-input:disabled {
    opacity: 0.5;
}
.ask-user-status {
    font-size: 12px;
    font-weight: 500;
    padding: 4px 0;
    word-break: break-word;
}
.ask-user-answered .ask-user-status {
    color: #3b82f6;
}
.ask-user-cancelled .ask-user-status {
    color: #ef4444;
}
.ask-user-answered {
    border-color: rgba(59, 130, 246, 0.2);
    background: rgba(59, 130, 246, 0.04);
}
.ask-user-cancelled {
    border-color: rgba(239, 68, 68, 0.2);
    background: rgba(239, 68, 68, 0.04);
}
.ask-user-expired .ask-user-status {
    color: #9ca3af;
}
.ask-user-expired {
    border-color: rgba(156, 163, 175, 0.2);
    background: rgba(156, 163, 175, 0.04);
    opacity: 0.7;
}

.loading-spinner {
    display: flex;
    justify-content: center;
    padding: 20px;
}
.loading-spinner::after {
    content: '';
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}


/* ============================================================
   OFFLINE BANNER
   ============================================================ */

.read-only-banner {
    padding: 8px 16px;
    background: rgba(234, 179, 8, 0.15);
    border-bottom: 1px solid var(--warning);
    color: var(--warning);
    font-size: 13px;
    text-align: center;
}

.offline-banner {
    padding: 8px 16px;
    background: rgba(239, 68, 68, 0.15);
    border-bottom: 1px solid var(--error);
    color: var(--error);
    font-size: 13px;
    text-align: center;
}


/* ============================================================
   DRAG & DROP
   ============================================================ */

.drag-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--accent-subtle);
    border: 3px dashed var(--accent);
    display: none;
    z-index: 100;
    pointer-events: none;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--accent);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}
.drag-overlay.active {
    display: flex;
}


/* ============================================================
   RENAME INPUT
   ============================================================ */

.rename-input {
    background: var(--bg-input);
    border: 1px solid var(--accent);
    color: var(--text-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: var(--font-ui);
    width: 100%;
    outline: none;
    box-shadow: var(--input-glow);
}


/* ============================================================
   EMPTY & PLEASE-WAIT STATES
   ============================================================ */

.empty-state {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 13px;
}

.please-wait {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 4px;
    animation: fadeInOut 2s ease-in-out;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0; }
    20%, 80% { opacity: 1; }
}


/* ============================================================
   MODALS
   ============================================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    -webkit-backdrop-filter: var(--modal-backdrop-blur);
    backdrop-filter: var(--modal-backdrop-blur);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 520px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s var(--easing);
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}
.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}
.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 20px;
    padding: 0 4px;
    border-radius: 4px;
    transition: all var(--transition-speed) var(--easing);
}
.modal-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}
.setting-group {
    margin-bottom: 20px;
}
.setting-group:last-child {
    margin-bottom: 0;
}
.setting-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.setting-group select,
.setting-group textarea,
.setting-group input[type="text"] {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    font-family: var(--font-ui);
    outline: none;
    transition: border-color var(--transition-speed) var(--easing),
                box-shadow var(--transition-speed) var(--easing);
}
.setting-group select:focus,
.setting-group textarea:focus,
.setting-group input[type="text"]:focus {
    border-color: var(--accent);
    box-shadow: var(--input-glow);
}
.setting-group textarea {
    resize: vertical;
    min-height: 80px;
}
.setting-hint {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}
.setting-group select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
    cursor: pointer;
}
.setting-group select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 8px;
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
}
.btn-modal-cancel {
    padding: 8px 16px;
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-family: var(--font-ui);
    transition: all var(--transition-speed) var(--easing);
}
.btn-modal-cancel:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.btn-modal-save {
    padding: 8px 16px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-ui);
    transition: all var(--transition-speed) var(--easing);
}
.btn-modal-save:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 16px var(--accent-glow);
}

/* Space Sources (in Space Modal) */
.space-sources-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-input);
}
.space-sources-list:empty::after {
    content: 'No sources linked to this space.';
    display: block;
    padding: 12px;
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
}
.space-source-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}
.space-source-row:last-child { border-bottom: none; }
.space-source-row .source-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}
.space-source-row .source-type {
    font-size: 11px;
    color: var(--text-muted);
    margin: 0 8px;
    text-transform: uppercase;
}
.space-source-row .btn-unlink {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
    line-height: 1;
}
.space-source-row .btn-unlink:hover { color: var(--danger, #e74c3c); }
.space-sources-add { margin-top: 6px; }
.space-sources-picker {
    width: 100%;
    padding: 6px 8px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    font-family: var(--font-ui);
}
.source-space-badge {
    display: inline-block;
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--accent);
    color: #fff;
    margin-left: 6px;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.sources-space-filter {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-secondary);
}
.sources-space-filter label { cursor: pointer; user-select: none; }
.sources-space-filter input[type="checkbox"] { accent-color: var(--accent); }


/* ============================================================
   THEME PICKER (in Settings Modal)
   ============================================================ */

.theme-picker {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 8px;
}
.theme-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 8px;
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: all var(--transition-speed) var(--easing);
}
.theme-card:hover {
    border-color: var(--text-muted);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.theme-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}
.theme-preview {
    display: flex;
    gap: 3px;
    width: 100%;
    height: 24px;
    border-radius: 4px;
    overflow: hidden;
}
.theme-preview span {
    flex: 1;
    border-radius: 3px;
}
.theme-card-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: capitalize;
}
.theme-card.active .theme-card-label {
    color: var(--accent);
}


/* ============================================================
   FILE BROWSER (Add Database modal)
   ============================================================ */

.browse-path-row {
    display: flex;
    gap: 8px;
}
.browse-path-row input {
    flex: 1;
}
.btn-browse {
    padding: 8px 16px;
    background: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-family: var(--font-ui);
    white-space: nowrap;
    transition: all var(--transition-speed) var(--easing);
}
.btn-browse:hover {
    background: var(--bg-active);
    color: var(--text-primary);
    border-color: var(--accent);
}

.browse-panel {
    margin-top: 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    max-height: 280px;
    display: flex;
    flex-direction: column;
}
.browse-current {
    padding: 8px 12px;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    background: var(--bg-input);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.browse-entries {
    overflow-y: auto;
    flex: 1;
}
.browse-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition-speed) var(--easing);
}
.browse-entry:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.browse-entry-icon {
    flex-shrink: 0;
    width: 16px;
    text-align: center;
    opacity: 0.7;
}
.browse-entry.is-dir .browse-entry-icon {
    color: var(--accent);
    opacity: 1;
}
.browse-entry.is-file .browse-entry-icon {
    color: var(--warning);
}
.browse-entry-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.browse-up {
    font-weight: 500;
    color: var(--text-muted);
}


/* ============================================================
   MODEL SELECTOR
   ============================================================ */

.model-selector {
    position: relative;
    font-size: 13px;
}
.model-selector-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-family: var(--font-ui);
    transition: all var(--transition-speed) var(--easing);
}
.model-selector-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-color: var(--border-color);
}
.model-selector-btn.active {
    color: var(--text-primary);
    background: var(--bg-input);
    border-color: var(--border-color);
}
.model-selector-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 200px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 50;
    padding: 4px;
}
.model-selector-dropdown.open {
    display: block;
    animation: dropdownIn 0.15s var(--easing);
}

@keyframes dropdownIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.model-selector-item {
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background var(--transition-speed) var(--easing);
}
.model-selector-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.model-selector-item.selected {
    color: var(--accent);
}
.model-selector-item.selected::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
}


/* ============================================================
   SIDEBAR SECTIONS & SPACES
   ============================================================ */

.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    margin-bottom: 6px;
}
.sidebar-section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
}
.btn-section-action {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-family: var(--font-ui);
    transition: color var(--transition-speed) var(--easing),
                background var(--transition-speed) var(--easing);
}
.btn-section-action:hover {
    color: var(--accent);
    background: var(--bg-hover);
}

/* --- Database Selector --- */

.sidebar-databases {
    padding: 4px 0 0;
    border-bottom: 1px solid rgba(197, 160, 89, 0.15);
    margin-bottom: 4px;
}

.db-list {
    padding: 0 8px;
    max-height: 120px;
    overflow-y: auto;
}

.db-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all var(--transition-speed) var(--easing);
}

.db-item:hover {
    background: var(--bg-hover);
}

.db-item.active {
    background: var(--bg-active);
    color: var(--accent);
    font-weight: 500;
}

.db-item-icon {
    display: flex;
    flex-shrink: 0;
    opacity: 0.6;
}

.db-item.active .db-item-icon {
    opacity: 1;
    color: var(--accent);
}

.db-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.db-item-remove {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    line-height: 1;
    transition: opacity 0.15s, color 0.15s;
}

.db-item:hover .db-item-remove {
    opacity: 0.6;
}

.db-item-remove:hover {
    opacity: 1 !important;
    color: var(--danger, #ef4444);
}

/* Space active bar */
.space-active-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px 8px;
    gap: 8px;
}
.space-active-info {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 500;
    min-width: 0;
}
.space-active-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.space-active-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}
.btn-space-action {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition-speed) var(--easing),
                background var(--transition-speed) var(--easing);
}
.btn-space-action:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.space-origin {
    font-size: 10px;
    color: var(--text-muted);
    margin-left: 4px;
    padding: 1px 5px;
    border-radius: 3px;
    background: color-mix(in srgb, var(--text-muted) 12%, transparent);
}

.sidebar-spaces {
    padding: 4px 0 0;
}
.space-list {
    padding: 2px 8px;
}
.space-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all var(--transition-speed) var(--easing);
}
.space-item:hover {
    background: var(--bg-hover);
}
.space-item.active {
    background: var(--bg-active);
    color: var(--accent);
    font-weight: 500;
}
.space-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.space-item-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}
.space-item-action {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    transition: opacity 0.15s, color 0.15s;
}
.space-item:hover .space-item-action {
    opacity: 0.6;
}
.space-item-action:hover {
    opacity: 1 !important;
    color: var(--text-primary);
    background: var(--bg-hover);
}
.space-item-delete:hover {
    color: var(--danger, #ef4444) !important;
}
.space-empty-hint {
    font-size: 12px;
    color: var(--text-muted);
    padding: 8px;
    font-style: italic;
}

/* Space indicator in chat header */
.chat-space-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 500;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    border-radius: 4px;
    margin-left: 8px;
}


/* ============================================================
   RAW TOGGLE
   ============================================================ */

.btn-raw-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font-ui);
    transition: all var(--transition-speed) var(--easing);
    margin-left: auto;
}
.btn-raw-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-color: var(--border-color);
}
.btn-raw-toggle.active {
    color: var(--accent);
    background: var(--accent-subtle);
    border-color: var(--accent);
}


/* ============================================================
   COMMAND PALETTE
   ============================================================ */

.palette-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    z-index: 300;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 15vh;
}
.palette-modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 520px;
    max-width: 90vw;
    max-height: 400px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    overflow: hidden;
    animation: paletteIn 0.2s var(--easing-spring);
}

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

.palette-input {
    padding: 14px 16px;
    background: transparent;
    color: var(--text-primary);
    border: none;
    border-bottom: 1px solid var(--border-color);
    font-size: 15px;
    font-family: var(--font-ui);
    outline: none;
}
.palette-input::placeholder {
    color: var(--text-muted);
}
.palette-results {
    overflow-y: auto;
    flex: 1;
    padding: 4px;
}
.palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background var(--transition-speed) var(--easing);
}
.palette-item:hover,
.palette-item.active {
    background: var(--bg-hover);
}
.palette-icon {
    font-size: 14px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}
.palette-label {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.palette-hint {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}
.palette-empty {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 13px;
}


/* ============================================================
   AURORA BACKGROUND ANIMATION
   ============================================================ */

[data-theme="aurora"] .app-container::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(197, 160, 89, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(59, 130, 246, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(16, 185, 129, 0.05) 0%, transparent 50%);
    animation: auroraShift 20s ease-in-out infinite alternate;
}

@keyframes auroraShift {
    0% {
        background:
            radial-gradient(ellipse at 20% 50%, rgba(197, 160, 89, 0.08) 0%, transparent 50%),
            radial-gradient(ellipse at 80% 20%, rgba(59, 130, 246, 0.06) 0%, transparent 50%),
            radial-gradient(ellipse at 50% 80%, rgba(16, 185, 129, 0.05) 0%, transparent 50%);
    }
    33% {
        background:
            radial-gradient(ellipse at 40% 30%, rgba(197, 160, 89, 0.06) 0%, transparent 50%),
            radial-gradient(ellipse at 70% 70%, rgba(59, 130, 246, 0.08) 0%, transparent 50%),
            radial-gradient(ellipse at 20% 60%, rgba(16, 185, 129, 0.06) 0%, transparent 50%);
    }
    66% {
        background:
            radial-gradient(ellipse at 60% 70%, rgba(197, 160, 89, 0.07) 0%, transparent 50%),
            radial-gradient(ellipse at 30% 30%, rgba(59, 130, 246, 0.05) 0%, transparent 50%),
            radial-gradient(ellipse at 80% 50%, rgba(16, 185, 129, 0.07) 0%, transparent 50%);
    }
    100% {
        background:
            radial-gradient(ellipse at 50% 40%, rgba(197, 160, 89, 0.08) 0%, transparent 50%),
            radial-gradient(ellipse at 60% 60%, rgba(59, 130, 246, 0.07) 0%, transparent 50%),
            radial-gradient(ellipse at 30% 80%, rgba(16, 185, 129, 0.06) 0%, transparent 50%);
    }
}

[data-theme="aurora"] .sidebar {
    border-right-color: transparent;
    border-image: linear-gradient(to bottom, rgba(197, 160, 89, 0.3), rgba(59, 130, 246, 0.2), rgba(16, 185, 129, 0.2)) 1;
}

[data-theme="aurora"] .message.user .message-content {
    border-image: linear-gradient(to bottom, #C5A059, #3B82F6) 1;
    border-left-style: solid;
    border-left-width: 3px;
}

[data-theme="aurora"] ::-webkit-scrollbar-thumb {
    background: linear-gradient(to bottom, #C5A059, #3B82F6);
    border-radius: 3px;
}


/* ============================================================
   DAWN LIGHT THEME OVERRIDES
   ============================================================ */

[data-theme="dawn"] .message.user .message-content {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06), 0 0 1px rgba(0, 0, 0, 0.04);
}

/* Light-mode highlight.js overrides for code blocks */
[data-theme="dawn"] .hljs {
    color: #383a42;
    background: #f6f4f0;
}
[data-theme="dawn"] .hljs-comment,
[data-theme="dawn"] .hljs-quote {
    color: #a0a1a7;
    font-style: italic;
}
[data-theme="dawn"] .hljs-keyword,
[data-theme="dawn"] .hljs-selector-tag,
[data-theme="dawn"] .hljs-subst {
    color: #a626a4;
}
[data-theme="dawn"] .hljs-number,
[data-theme="dawn"] .hljs-literal,
[data-theme="dawn"] .hljs-variable,
[data-theme="dawn"] .hljs-template-variable,
[data-theme="dawn"] .hljs-tag .hljs-attr {
    color: #986801;
}
[data-theme="dawn"] .hljs-string,
[data-theme="dawn"] .hljs-doctag {
    color: #50a14f;
}
[data-theme="dawn"] .hljs-title,
[data-theme="dawn"] .hljs-section,
[data-theme="dawn"] .hljs-selector-id {
    color: #4078f2;
    font-weight: bold;
}
[data-theme="dawn"] .hljs-type,
[data-theme="dawn"] .hljs-class .hljs-title {
    color: #c18401;
}
[data-theme="dawn"] .hljs-tag,
[data-theme="dawn"] .hljs-name,
[data-theme="dawn"] .hljs-attribute {
    color: #e45649;
}
[data-theme="dawn"] .hljs-regexp,
[data-theme="dawn"] .hljs-link {
    color: #50a14f;
}
[data-theme="dawn"] .hljs-symbol,
[data-theme="dawn"] .hljs-bullet {
    color: #4078f2;
}
[data-theme="dawn"] .hljs-built_in,
[data-theme="dawn"] .hljs-builtin-name {
    color: #c18401;
}
[data-theme="dawn"] .hljs-meta {
    color: #4078f2;
}
[data-theme="dawn"] .hljs-deletion {
    background: #fdd;
}
[data-theme="dawn"] .hljs-addition {
    background: #dfd;
}
[data-theme="dawn"] .hljs-emphasis {
    font-style: italic;
}
[data-theme="dawn"] .hljs-strong {
    font-weight: bold;
}

/* Dawn paper texture */
[data-theme="dawn"] .app-container {
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.015'/%3E%3C/svg%3E");
}


/* ============================================================
   MOBILE SIDEBAR OVERLAY
   ============================================================ */

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9;
    opacity: 0;
    transition: opacity 0.25s var(--easing);
}
.sidebar-overlay.active {
    display: block;
    opacity: 1;
}


/* ============================================================
   RESPONSIVE DESIGN
   ============================================================ */

/* Large desktop */
@media (min-width: 1400px) {
    .sidebar {
        width: 300px;
        min-width: 300px;
    }
    .message {
        max-width: 900px;
    }
    .input-area {
        max-width: 900px;
    }
}

/* Tablet */
@media (max-width: 1024px) and (min-width: 769px) {
    .sidebar {
        width: 240px;
        min-width: 240px;
    }
    .message {
        max-width: 100%;
    }
    .input-area {
        max-width: 100%;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        min-width: 280px;
        transform: translateX(-100%);
        transition: transform 0.25s var(--easing);
        z-index: 20;
        box-shadow: none;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .mobile-menu-btn {
        display: flex;
    }

    .message {
        max-width: 100%;
        padding-left: 12px;
        padding-right: 12px;
    }
    .input-area {
        max-width: 100%;
        padding: 12px;
    }

    .palette-modal {
        width: 95vw;
    }
    .modal {
        width: 95vw;
    }

    .theme-picker {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================================
   MCP SERVER MODAL
   ============================================================ */

.mcp-server-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
    gap: 12px;
}
.mcp-server-row:last-child {
    border-bottom: none;
}

.mcp-server-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    flex: 1;
}

.mcp-server-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.mcp-status-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 500;
    padding: 1px 8px;
    border-radius: 10px;
    text-transform: capitalize;
}
.mcp-status-connected {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}
.mcp-status-error {
    background: rgba(239, 68, 68, 0.15);
    color: var(--error);
}
.mcp-status-disconnected {
    background: rgba(100, 100, 100, 0.15);
    color: var(--text-muted);
}

.mcp-server-detail {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mcp-server-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.btn-mcp-action {
    padding: 5px 12px;
    font-size: 12px;
    font-family: var(--font-ui);
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-secondary);
    transition: all var(--transition-speed) var(--easing);
}
.btn-mcp-action:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--text-muted);
}
.btn-mcp-connect {
    background: var(--accent-subtle);
    color: var(--accent);
    border-color: var(--accent);
}
.btn-mcp-connect:hover {
    background: var(--accent);
    color: #fff;
}
.btn-mcp-danger {
    color: var(--error);
    border-color: transparent;
}
.btn-mcp-danger:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--error);
}


/* ============================================================
   CANVAS PANEL
   ============================================================ */

.canvas-panel {
    width: 50%;
    min-width: 400px;
    max-width: 60%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-color);
    background: var(--bg-secondary);
    z-index: 5;
}

.chat-main.with-canvas {
    flex: 1;
    min-width: 400px;
}

.canvas-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 8px;
}
.canvas-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.02em;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.canvas-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.canvas-mode-toggle {
    display: flex;
    background: var(--bg-input);
    border-radius: 6px;
    padding: 2px;
    gap: 2px;
}
.canvas-mode-btn {
    padding: 3px 10px;
    font-size: 11px;
    font-family: var(--font-ui);
    font-weight: 500;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-muted);
    background: transparent;
    transition: all 0.12s var(--easing);
}
.canvas-mode-btn.active {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.canvas-mode-btn:hover:not(.active) {
    color: var(--text-secondary);
}
.canvas-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.12s var(--easing);
    flex-shrink: 0;
}
.canvas-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.canvas-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.canvas-cm-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
}
.canvas-cm-wrap .cm-editor {
    flex: 1;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.canvas-preview {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.7;
}
.canvas-preview.excalidraw-active {
    padding: 0;
    overflow: hidden;
}
.canvas-preview h1, .canvas-preview h2, .canvas-preview h3,
.canvas-preview h4, .canvas-preview h5, .canvas-preview h6 {
    margin: 1.2em 0 0.5em;
    color: var(--text-primary);
}
.canvas-preview h1 { font-size: 1.6em; }
.canvas-preview h2 { font-size: 1.3em; }
.canvas-preview h3 { font-size: 1.1em; }
.canvas-preview p { margin: 0.6em 0; }
.canvas-preview ul, .canvas-preview ol {
    margin: 0.5em 0;
    padding-left: 24px;
}
.canvas-preview li { margin: 0.25em 0; }
.canvas-preview pre {
    margin: 0.8em 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--code-border);
}
.canvas-preview pre code {
    display: block;
    padding: 12px 16px;
    background: var(--code-bg);
    font-family: var(--font-mono);
    font-size: 13px;
    overflow-x: auto;
}
.canvas-preview code {
    background: var(--code-bg);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 13px;
    border: 1px solid var(--code-border);
}
.canvas-preview pre code {
    border: none;
    border-radius: 0;
}
.canvas-preview blockquote {
    border-left: 3px solid var(--accent);
    margin: 0.8em 0;
    padding: 4px 16px;
    color: var(--text-secondary);
}
.canvas-preview table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.8em 0;
}
.canvas-preview th, .canvas-preview td {
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    text-align: left;
}
.canvas-preview th {
    background: var(--bg-input);
    font-weight: 600;
}

.canvas-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 8px 16px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 8px;
}
#canvas-save {
    padding: 6px 16px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.12s var(--easing);
    font-family: var(--font-ui);
}
#canvas-save:hover {
    background: var(--accent-hover);
}
#canvas-save:disabled {
    opacity: 0.4;
    cursor: default;
}

.btn-canvas-toggle {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    font-family: var(--font-ui);
    font-size: 12px;
    transition: all 0.12s var(--easing);
}
.btn-canvas-toggle:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}
.btn-canvas-toggle.active {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-subtle);
}

/* Responsive: narrow screens -> canvas overlays */
@media (max-width: 900px) {
    .canvas-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 50%;
        min-width: 320px;
        z-index: 25;
        box-shadow: var(--shadow-lg);
    }
}
@media (max-width: 768px) {
    .canvas-panel {
        width: 100%;
        min-width: 100%;
    }
}


/* ============================================================
   PLAN MODE
   ============================================================ */

.btn-plan-toggle {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    font-family: var(--font-ui);
    font-size: 12px;
    transition: all 0.12s var(--easing);
}
.btn-plan-toggle:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}
.btn-plan-toggle.active {
    color: #eab308;
    border-color: #eab308;
    background: rgba(234, 179, 8, 0.08);
}

.plan-panel {
    width: 40%;
    min-width: 360px;
    max-width: 50%;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-color);
    background: var(--bg-secondary);
    z-index: 5;
}
.chat-main.with-plan {
    flex: 1;
    min-width: 400px;
}

.plan-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 8px;
}
.plan-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}
.plan-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.plan-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.12s;
}
.plan-close:hover {
    color: var(--text-primary);
}

.plan-status-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.plan-status-ready {
    color: #eab308;
    background: rgba(234, 179, 8, 0.12);
}

.plan-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}
.plan-empty {
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.6;
    text-align: center;
    padding: 40px 20px;
}
.plan-empty p {
    margin: 0 0 8px;
}
.plan-content {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
}
.plan-content h1, .plan-content h2, .plan-content h3 {
    margin: 16px 0 8px;
    color: var(--text-primary);
}
.plan-content h2 { font-size: 15px; }
.plan-content h3 { font-size: 13px; }
.plan-content ul, .plan-content ol {
    padding-left: 20px;
    margin: 8px 0;
}
.plan-content li {
    margin: 4px 0;
}
.plan-content code {
    font-size: 12px;
    background: var(--bg-input);
    padding: 1px 5px;
    border-radius: 3px;
}
.plan-content pre {
    background: var(--bg-input);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}
.plan-content pre code {
    background: none;
    padding: 0;
}

.plan-footer {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}
.plan-btn {
    flex: 1;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.12s var(--easing);
}
.plan-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.plan-approve {
    background: #22c55e;
    color: #fff;
}
.plan-approve:hover:not(:disabled) {
    background: #16a34a;
}
.plan-reject {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.plan-reject:hover:not(:disabled) {
    border-color: #ef4444;
    color: #ef4444;
}

/* Responsive: narrow screens -> plan panel overlays */
@media (max-width: 900px) {
    .plan-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 50%;
        min-width: 320px;
        z-index: 25;
        box-shadow: var(--shadow-lg);
    }
}
@media (max-width: 768px) {
    .plan-panel {
        width: 100%;
        min-width: 100%;
    }
}


/* ============================================================
   SOURCES PANEL
   ============================================================ */

.sources-panel {
    width: 40%;
    min-width: 360px;
    max-width: 50%;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-color);
    background: var(--bg-secondary);
    z-index: 5;
}

.chat-main.with-sources {
    flex: 1;
    min-width: 400px;
}

.sources-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 8px;
}
.sources-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}
.sources-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.sources-add-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: all 0.12s var(--easing);
}
.sources-add-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}
.sources-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.12s var(--easing);
    flex-shrink: 0;
}
.sources-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.sources-view-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.sources-view-tab {
    flex: 1;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}
.sources-view-tab:hover {
    color: var(--text-primary);
}
.sources-view-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.sources-toolbar {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.sources-search {
    flex: 1;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-ui);
    outline: none;
    transition: border-color 0.12s var(--easing);
}
.sources-search:focus {
    border-color: var(--accent);
}
.sources-search::placeholder {
    color: var(--text-muted);
}
.sources-type-filter {
    padding: 6px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 12px;
    font-family: var(--font-ui);
    cursor: pointer;
    outline: none;
}

/* Source list */
.sources-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}
.sources-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 40px 16px;
    font-size: 13px;
}
.sources-error {
    color: var(--error);
    text-align: center;
    padding: 20px 16px;
    font-size: 13px;
}
.sources-loading {
    color: var(--text-muted);
    text-align: center;
    padding: 20px 16px;
    font-size: 13px;
}
.source-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.12s var(--easing);
    border-bottom: 1px solid var(--border-color);
}
.source-item:hover {
    background: var(--bg-hover);
}
.source-item-main {
    flex: 1;
    min-width: 0;
}
.source-item-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.source-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 3px;
}
.source-item-date {
    font-size: 11px;
    color: var(--text-muted);
}

/* Source type badges */
.source-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 6px;
    border-radius: 3px;
    background: var(--accent-subtle);
    color: var(--accent);
}
.source-type-text { background: rgba(59, 130, 246, 0.1); color: #3b82f6; }
.source-type-file { background: rgba(168, 85, 247, 0.1); color: #a855f7; }
.source-type-url { background: rgba(34, 197, 94, 0.1); color: #22c55e; }

/* Source scope indicators (#853) */
.source-out-of-scope {
    opacity: 0.5;
}
.source-scope-badge {
    font-size: 10px;
    font-weight: 600;
    color: var(--warning, #eab308);
    margin-left: 4px;
}
.source-scope-warn {
    color: var(--warning, #eab308);
    font-size: 12px;
}
.source-type-group { background: rgba(168, 85, 247, 0.1); color: #a855f7; }

/* Source detail view */
.source-detail-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}
.source-back-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: all 0.12s var(--easing);
    flex-shrink: 0;
}
.source-back-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.source-detail-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}
.source-detail-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.source-detail-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    font-size: 12px;
    color: var(--text-muted);
}
.source-detail-chunks {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
}
.source-detail-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px 16px 8px;
}
.source-tag {
    display: inline-block;
    padding: 2px 8px;
    background: var(--accent-subtle);
    color: var(--accent);
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
}
.source-detail-content {
    padding: 12px 16px;
    flex: 1;
    overflow-y: auto;
}
.source-detail-content pre {
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0;
    font-family: var(--font-ui);
}
.source-detail-url {
    padding: 8px 16px;
}
.source-detail-url a {
    color: var(--accent-blue);
    text-decoration: none;
    font-size: 13px;
    word-break: break-all;
}
.source-detail-url a:hover {
    text-decoration: underline;
}
.source-detail-meta {
    padding: 4px 16px;
    font-size: 12px;
    color: var(--text-muted);
}
.source-detail-actions {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}
.source-delete-btn {
    color: var(--error) !important;
    border-color: var(--error) !important;
}
.source-delete-btn:hover {
    background: rgba(239, 68, 68, 0.1) !important;
}

/* Source detail fills panel */
.sources-detail {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* Source create form */
.sources-create {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.sources-create-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    padding: 0 12px;
    flex-shrink: 0;
}
.sources-tab {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-ui);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.12s var(--easing);
}
.sources-tab:hover {
    color: var(--text-primary);
}
.sources-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.sources-create-form {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
}
.sources-create-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: auto;
    padding-top: 12px;
}

/* File drop zone */
.source-file-drop {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s var(--easing);
    color: var(--text-muted);
    font-size: 13px;
}
.source-file-drop:hover,
.source-file-drop.dragover {
    border-color: var(--accent);
    background: var(--accent-subtle);
    color: var(--accent);
}
.source-file-drop p {
    margin: 0;
}
.source-file-name {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    display: block;
}
.source-upload-hint {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 6px;
    opacity: 0.7;
    line-height: 1.4;
}

/* Sources toggle button (topbar) */
.btn-sources-toggle {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    font-family: var(--font-ui);
    font-size: 12px;
    transition: all 0.12s var(--easing);
}
.btn-sources-toggle:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}
.btn-sources-toggle.active {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-subtle);
}

/* Source attached indicator in list */
.source-attached-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 6px;
    vertical-align: middle;
}

/* Source item attach button */
.source-item-attach {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    cursor: pointer;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    transition: all 0.12s var(--easing);
}
.source-item-attach:hover {
    color: var(--accent);
    border-color: var(--accent);
}
.source-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Source reference chips bar (above chat input) */
.sources-attached-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px 12px;
}
.source-ref-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: var(--accent-subtle);
    color: var(--accent);
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.source-ref-icon {
    display: inline-flex;
    flex-shrink: 0;
}
.source-ref-remove {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 13px;
    padding: 0 2px;
    opacity: 0.6;
    flex-shrink: 0;
}
.source-ref-remove:hover {
    opacity: 1;
}
.source-ref-tag {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}
.source-ref-group {
    background: rgba(168, 85, 247, 0.1);
    color: #a855f7;
}

/* Tag picker inline */
.source-tag-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px 0;
}
.source-tag-picker-item {
    padding: 3px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 11px;
    cursor: pointer;
    font-family: var(--font-ui);
    transition: all 0.12s var(--easing);
}
.source-tag-picker-item:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.source-tag-picker-cancel {
    padding: 3px 10px;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    font-family: var(--font-ui);
}
.source-tag-picker-empty {
    color: var(--text-muted);
    font-size: 11px;
    padding: 4px 0;
}

/* Tag remove button inside tag chip */
.source-tag-remove {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 13px;
    padding: 0 1px;
    opacity: 0.5;
    margin-left: 2px;
}
.source-tag-remove:hover {
    opacity: 1;
}

/* Tag add button */
.source-tag-add-btn {
    padding: 2px 8px;
    background: none;
    border: 1px dashed var(--border-color);
    border-radius: 10px;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    font-family: var(--font-ui);
    transition: all 0.12s var(--easing);
}
.source-tag-add-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Source action buttons row */
.source-attach-btn {
    background: var(--accent-subtle) !important;
    color: var(--accent) !important;
    border: 1px solid var(--accent) !important;
}
.source-edit-btn {
    background: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
}

.sources-attach-by-tag {
    padding: 6px 12px;
    border-bottom: 1px solid var(--border-color);
}
.sources-attach-tag-btn {
    background: none;
    border: 1px dashed var(--border-color);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.sources-attach-tag-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.source-group-members-label {
    padding: 8px 16px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}
.source-group-members {
    overflow-y: auto;
    flex: 1;
}
.source-group-member .source-item-attach {
    color: var(--text-error, #ef4444);
}
.sources-groups-list {
    overflow-y: auto;
    flex: 1;
}

/* Responsive: narrow screens -> sources overlays */
@media (max-width: 900px) {
    .sources-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 50%;
        min-width: 320px;
        z-index: 25;
        box-shadow: var(--shadow-lg);
    }
}
@media (max-width: 768px) {
    .sources-panel {
        width: 100%;
        min-width: 100%;
    }
}


/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-family: var(--font-ui);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: toastIn 0.2s var(--easing);
    pointer-events: auto;
}

.toast-warn {
    border-color: var(--warning, #eab308);
}
.toast-error {
    border-color: var(--error, #ef4444);
}
.toast-fade-out {
    animation: toastOut 0.3s var(--easing) forwards;
}

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

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


/* ============================================================
   SUB-AGENT LOADING STATE
   ============================================================ */

.tool-call.tool-call-subagent {
    border-left-width: 3px;
    border-left-color: var(--accent);
}
.tool-call.tool-call-subagent.subagent-running {
    animation: subagentPulse 2s ease-in-out infinite;
}
.tool-call.tool-call-subagent summary {
    font-weight: 600;
    color: var(--accent);
}
.tool-call.tool-call-subagent.tool-status-success summary {
    color: #22c55e;
}
.tool-call.tool-call-subagent.tool-status-error summary {
    color: var(--error);
}
.subagent-loading-prompt {
    color: var(--text-secondary);
    font-size: 12px;
    margin-bottom: 8px;
    max-height: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.subagent-cards-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

@keyframes subagentPulse {
    0%, 100% { border-left-color: var(--accent); }
    50% { border-left-color: transparent; }
}

/* ============================================================
   SUB-AGENT CARDS
   ============================================================ */

.subagent-card {
    margin: 8px 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-tool-call);
    padding: 10px 12px;
    font-size: 13px;
    overflow: hidden;
    transition: border-color 0.3s var(--easing);
}
.subagent-card.subagent-done {
    border-color: rgba(34, 197, 94, 0.3);
}
.subagent-card.subagent-error {
    border-color: rgba(239, 68, 68, 0.3);
}
.subagent-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}
.subagent-label {
    font-weight: 600;
    color: var(--accent);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.subagent-model {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-hover);
    padding: 1px 6px;
    border-radius: 4px;
}
.subagent-prompt {
    color: var(--text-secondary);
    font-size: 12px;
    margin-bottom: 6px;
    max-height: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.subagent-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.subagent-tool-chip {
    display: inline-block;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-active);
    padding: 2px 6px;
    border-radius: 4px;
}
.subagent-footer {
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-muted);
}
.subagent-error .subagent-footer {
    color: var(--error);
}


/* ============================================================
   ARTIFACTS PANEL
   ============================================================ */

.artifacts-panel {
    width: 40%;
    min-width: 360px;
    max-width: 50%;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-color);
    background: var(--bg-secondary);
    z-index: 5;
}
.chat-main.with-artifacts {
    flex: 1;
    min-width: 400px;
}
.artifacts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 8px;
}
.artifacts-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}
.artifacts-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.artifacts-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.12s var(--easing);
    flex-shrink: 0;
}
.artifacts-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.artifacts-view-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.artifacts-view-tab {
    flex: 1;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.12s var(--easing);
    border-bottom: 2px solid transparent;
}
.artifacts-view-tab:hover {
    color: var(--text-primary);
}
.artifacts-view-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.artifacts-toolbar {
    display: flex;
    gap: 6px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.artifacts-filter {
    flex: 1;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
}
.artifacts-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}
.artifacts-empty,
.artifacts-error,
.artifacts-loading {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}
.artifacts-error {
    color: var(--error);
}
.artifact-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.12s var(--easing);
    border-bottom: 1px solid var(--border-color);
}
.artifact-item:hover {
    background: var(--bg-hover);
}
.artifact-item-main {
    flex: 1;
    min-width: 0;
}
.artifact-item-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.artifact-item-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
}
.artifact-badge {
    display: inline-flex;
    align-items: center;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 6px;
    border-radius: 3px;
}
.artifact-version {
    font-size: 11px;
    color: var(--text-muted);
}
.artifact-count {
    font-size: 11px;
    color: var(--text-muted);
}
.artifact-detail-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}
.artifact-back-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    padding: 2px 6px;
    border-radius: 4px;
}
.artifact-back-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.artifact-detail-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}
.artifact-detail-body {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}
.artifact-detail-meta {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}
.artifact-detail-fqn {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}
.artifact-detail-desc {
    font-size: 13px;
    color: var(--text-secondary);
}
.artifact-detail-content {
    margin-top: 12px;
}
.artifact-detail-content pre {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    font-size: 12px;
    color: var(--text-primary);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 400px;
    overflow-y: auto;
}
.artifact-detail-versions {
    margin-top: 16px;
    font-size: 12px;
    color: var(--text-secondary);
}
.artifact-detail-versions ul {
    margin: 6px 0 0 16px;
    padding: 0;
}
.artifact-detail-versions li {
    margin-bottom: 4px;
}
.artifact-detail-actions {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}
.artifact-delete-btn {
    background: none;
    border: 1px solid var(--error);
    color: var(--error);
    padding: 6px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.12s var(--easing);
}
.artifact-delete-btn:hover {
    background: var(--error);
    color: #fff;
}
.artifacts-detail {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.btn-artifacts-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    transition: all 0.15s var(--easing);
}
.btn-artifacts-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.btn-artifacts-toggle.active {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-subtle);
}

/* Workflows Panel (#961) */
.workflows-panel {
    width: 40%;
    min-width: 360px;
    max-width: 50%;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-color);
    background: var(--bg-secondary);
    z-index: 5;
}
.chat-main.with-workflows-panel {
    flex: 1;
    min-width: 400px;
}
.workflows-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 8px;
}
.workflows-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}
.workflows-header-actions { display: flex; align-items: center; gap: 6px; }
.workflows-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 2px 6px;
}
.workflows-close:hover { color: var(--text-primary); }
.workflows-toolbar {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.workflows-filter {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
}
.workflows-list {
    overflow-y: auto;
    flex: 1;
    padding: 8px;
}
.workflows-detail {
    overflow-y: auto;
    flex: 1;
    padding: 8px 16px;
}
.wf-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 16px;
    font-size: 13px;
}
.wf-run-card {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: background 0.1s;
}
.wf-run-card:hover { background: var(--bg-hover); }
.wf-run-card-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.wf-run-workflow { font-size: 13px; font-weight: 500; color: var(--text-primary); }
.wf-run-card-meta { font-size: 11px; color: var(--text-muted); }
.wf-status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    color: #fff;
}
.wf-detail-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.wf-detail-workflow { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.wf-detail-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; }
.wf-back-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 12px;
}
.wf-back-btn:hover { background: var(--bg-hover); }
.wf-step-timeline { display: flex; flex-direction: column; gap: 2px; }
.wf-step {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    border-left: 2px solid var(--border-color);
    margin-left: 6px;
    padding-left: 14px;
}
.wf-step-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.wf-step-info { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.wf-step-id { font-weight: 500; color: var(--text-primary); }
.wf-step-status { color: var(--text-muted); }
.wf-step-duration { color: var(--text-muted); font-size: 11px; }
.btn-workflows-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    border-radius: 6px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.15s var(--easing);
}
.btn-workflows-toggle:hover { color: var(--text-primary); background: var(--bg-hover); }
.btn-workflows-toggle.active { color: var(--accent); border-color: var(--accent); background: var(--accent-subtle); }
