/*
 * z-index scale:
 *   99  — sidebar overlay (backdrop)
 *  100  — sidebar
 *  101  — sidebar resize handle
 *  150  — dropdown panels, user menu
 *  200  — modal overlays
 * 1000  — log detail overlay
 * 9999  — context menus
 * 10000 — image/doc preview overlays, toasts
 */

/* === Reset & Base === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #242424;
    --bg-sidebar: #141414;
    --bg-input: #2a2a2a;
    --bg-hover: #333;
    --bg-elevated: #2e2e2e;
    --text-primary: #f0f0f0;
    --text-secondary: #a0a0a0;
    --text-muted: #909090;
    --accent: #7c9eff;
    --accent-hover: #6a8ff0;
    --accent-subtle: rgba(124,158,255,0.1);
    --accent-glow: rgba(124,158,255,0.15);
    --border: #2e2e2e;
    --border-subtle: rgba(var(--overlay-rgb),0.06);
    --danger: #f06060;
    --danger-hover: #e05050;
    --danger-subtle: rgba(240,96,96,0.12);
    --success: #4ade80;
    --success-hover: #3cc970;
    --success-subtle: rgba(74,222,128,0.12);
    --warning: #fbbf24;
    --warning-subtle: rgba(251,191,36,0.12);
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --sidebar-width: 268px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --transition-slow: 0.3s ease;
    --overlay-rgb: 255,255,255;
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    --purple: #a78bfa;
    --purple-light: #c084fc;
    --code-bg: #0d1117;
    --img-backdrop: #000;
    --on-color: #fff;
    --on-accent: #1a1a2e;
    --radius-sm: 4px;
    --radius-pill: 999px;
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-sidebar: #fafafa;
    --bg-input: #f0f0f0;
    --bg-hover: #e8e8e8;
    --bg-elevated: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #555;
    --text-muted: #6b6b6b;
    --accent: #3b6ce0;
    --accent-hover: #2d5fd0;
    --accent-subtle: rgba(59,108,224,0.1);
    --accent-glow: rgba(59,108,224,0.12);
    --border: #e0e0e0;
    --border-subtle: rgba(0,0,0,0.06);
    --danger: #cc3333;
    --danger-hover: #b52d2d;
    --danger-subtle: rgba(204,51,51,0.1);
    --success: #15803d;
    --success-hover: #117035;
    --success-subtle: rgba(21,128,61,0.1);
    --warning: #a16207;
    --warning-subtle: rgba(161,98,7,0.1);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --overlay-rgb: 0,0,0;
    --purple: #7c3aed;
    --purple-light: #9333ea;
    --code-bg: #f6f8fa;
    --on-accent: #fff;
    --img-backdrop: #e5e5e5;
}

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

a { color: var(--accent); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--accent-hover); }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }

button {
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    border: none;
    outline: none;
    background: none;
    color: inherit;
    transition: all var(--transition-fast);
}
button:focus-visible,
[role="button"]:focus-visible,
[role="option"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius);
}

input, textarea, select {
    font-family: inherit;
    font-size: inherit;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    outline: none;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}
input:disabled, textarea:disabled, select:disabled { opacity: 0.5; cursor: not-allowed; }
input::placeholder, textarea::placeholder { color: var(--text-muted); }

/* Scrollbar (cross-browser) */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(var(--overlay-rgb),0.1); border-radius: var(--radius-sm); }
::-webkit-scrollbar-thumb:hover { background: rgba(var(--overlay-rgb),0.18); }

/* === Login Page === */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
    background-image: radial-gradient(ellipse at 50% 0%, var(--accent-subtle) 0%, transparent 60%);
}

.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 44px 40px;
    width: 100%;
    max-width: 400px;
    margin: 20px;
    box-shadow: var(--shadow-lg);
}

/* === Brand === */
.brand {
    display: inline-flex;
    align-items: baseline;
    gap: 0;
}
.brand-anox {
    font-size: 1.6em;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--purple) 50%, var(--purple-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.brand-chat {
    font-size: 0.85em;
    font-weight: 300;
    letter-spacing: 0.3px;
    color: var(--text-primary);
    -webkit-text-fill-color: var(--text-primary);
    opacity: 0.85;
}
.brand-pro {
    font-size: 0.7em;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--accent);
    -webkit-text-fill-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    border-radius: var(--radius-sm);
    padding: 1px 6px;
    margin-left: 6px;
    vertical-align: baseline;
}

.login-card h1.brand {
    justify-content: center;
}
.login-card h1 {
    text-align: center;
    margin-bottom: 6px;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
}
.login-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 32px;
    font-size: 13px;
}

.login-tabs { display: flex; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.login-tabs button {
    flex: 1; padding: 10px; font-size: 13px; font-weight: 600;
    color: var(--text-muted); border-bottom: 2px solid transparent;
    margin-bottom: -1px; transition: color var(--transition-base), border-color var(--transition-base);
    letter-spacing: 0.2px;
}
.login-tabs button:hover { color: var(--text-secondary); }
.login-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form.hidden { display: none; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
    font-size: 12px; font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn {
    padding: 10px 20px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 13px;
    transition: all var(--transition-fast);
    letter-spacing: 0.2px;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 2px 8px var(--accent-glow); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.btn-danger { background: var(--danger); color: var(--on-color); }
.btn-danger:hover { background: var(--danger-hover); box-shadow: 0 2px 8px var(--danger-subtle); }
.btn-danger:active { transform: scale(0.97); }
.btn-ghost { color: var(--text-secondary); padding: 6px 12px; border-radius: var(--radius); }
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }
.btn-ghost:active { transform: scale(0.97); }

.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; display: none; }
.alert.error { display: block; background: var(--danger-subtle); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 20%, transparent); }
.alert.success { display: block; background: var(--success-subtle); color: var(--success); border: 1px solid color-mix(in srgb, var(--success) 20%, transparent); }

.text-danger { color: var(--danger); }

/* === App Layout === */
.app { display: flex; height: 100vh; height: 100dvh; }

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    min-width: 200px;
    max-width: 480px;
    background: var(--bg-sidebar);
    border-right: none;
    display: flex;
    flex-direction: column;
    height: 100vh;
    transition: transform var(--transition-slow);
    z-index: 100;
    position: relative;
    overflow: hidden;
}
.sidebar-resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 4px;
    cursor: col-resize;
    background: transparent;
    z-index: 101;
    transition: background var(--transition-base);
}
.sidebar-resize-handle:hover { background: rgba(var(--overlay-rgb),0.08); }
.sidebar-resize-handle.active { background: var(--accent); }

/* --- Sidebar Collapse Toggle --- */
.sidebar-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
    color: var(--text-muted);
    flex-shrink: 0;
    margin-left: auto;
}
.sidebar-collapse-btn:hover { color: var(--text-primary); background: rgba(var(--overlay-rgb),0.07); }
.sidebar-collapse-btn svg { transition: transform var(--transition-base); }

/* --- Sidebar Collapsed State (Desktop) --- */
.sidebar.collapsed {
    width: 56px;
    min-width: 56px;
    max-width: 56px;
    transition: width var(--transition-slow), min-width var(--transition-slow), max-width var(--transition-slow);
}
.sidebar.collapsed .sidebar-resize-handle { display: none; }
.sidebar.collapsed .sidebar-header { justify-content: center; padding: 0 8px; }
.sidebar.collapsed .sidebar-header .brand { display: none; }
.sidebar.collapsed #impersonation-banner { padding: 0 4px 8px; }
.sidebar.collapsed #impersonation-banner button { font-size: 0; padding: 5px; }
.sidebar.collapsed #impersonation-banner button::before { content: '\2190'; font-size: 14px; }
.sidebar.collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }
.sidebar.collapsed .sidebar-actions { padding: 8px 4px 0; }
.sidebar.collapsed .sidebar-action-btn { justify-content: center; padding: 7px; }
.sidebar.collapsed .sidebar-action-btn span { display: none; }
.sidebar.collapsed .sidebar-search-wrap { display: none; }
.sidebar.collapsed #chat-list { visibility: hidden !important; pointer-events: none; }
.sidebar.collapsed #chat-list * { visibility: hidden !important; }
.sidebar.collapsed .sidebar-footer { padding: 6px 4px; }
.sidebar.collapsed .user-info-btn { justify-content: center; padding: 8px; }
.sidebar.collapsed .user-info-btn #user-name,
.sidebar.collapsed .user-menu { left: 56px; bottom: 0; right: auto; min-width: 200px; }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 52px;
    flex-shrink: 0;
}
.sidebar-header h2 { font-size: 15px; font-weight: 700; letter-spacing: -0.2px; line-height: 1; }
.sidebar-header .brand { gap: 0; }
.sidebar-header .brand-anox { font-size: 1.4em; }
.sidebar-header .brand-chat { font-size: 0.8em; }

.sidebar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 10px 0;
}
.sidebar-action-btn {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--radius);
    transition: all var(--transition-fast);
    white-space: nowrap;
}
.sidebar-action-btn svg { flex-shrink: 0; }
.sidebar-action-btn:hover { background: rgba(var(--overlay-rgb),0.07); color: var(--text-primary); }
.sidebar-action-btn:active { transform: scale(0.97); }
.sidebar-action-btn:first-child { flex: 1; }

/* --- Sidebar Search --- */
.sidebar-search-wrap { padding: 8px 10px 4px; }
.sidebar-search-box {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    min-height: 32px;
    background: rgba(var(--overlay-rgb),0.05);
    border-radius: var(--radius);
    border: 1px solid transparent;
    transition: all var(--transition-fast);
}
.sidebar-search-box:focus-within { border-color: var(--accent); background: rgba(var(--overlay-rgb),0.07); box-shadow: 0 0 0 2px var(--accent-subtle); }
.sidebar-search-icon { color: var(--text-muted); flex-shrink: 0; }
.sidebar-search-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 6px 0;
    font-size: 13px;
    color: var(--text-primary);
    outline: none;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
}
.sidebar-search-input::-webkit-search-cancel-button,
.sidebar-search-input::-webkit-search-decoration { -webkit-appearance: none; }
.sidebar-search-input:focus { box-shadow: none; }
.sidebar-search-input::placeholder { color: var(--text-muted); }
.sidebar-search-clear {
    color: var(--text-muted);
    font-size: 11px;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    line-height: 1;
    min-width: 24px;
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sidebar-search-clear:hover { color: var(--text-primary); }
.sidebar-search-results {
    margin-top: 4px;
    max-height: 280px;
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}
.search-result-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-subtle);
    transition: background var(--transition-fast);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: rgba(var(--overlay-rgb),0.04); }
.search-result-title { font-size: 12px; font-weight: 600; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-snippet { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-snippet mark { background: var(--accent-glow); color: var(--text-primary); border-radius: var(--radius-sm); padding: 0 1px; }
.search-no-results { padding: 12px; text-align: center; font-size: 13px; color: var(--text-muted); }

.sidebar-scroll {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 0 12px;
}

.chat-list-group-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 16px 16px 6px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.chat-list-group-label + .chat-item ~ .chat-list-group-label {
    border-top: 1px solid rgba(var(--overlay-rgb), 0.1);
    margin-top: 8px;
    padding-top: 14px;
}

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

.chat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    transition: all var(--transition-fast);
    border-radius: var(--radius);
    margin: 1px 8px;
}
.chat-item:hover { background: rgba(var(--overlay-rgb),0.05); color: var(--text-primary); }
.chat-item.active { background: var(--accent-subtle); color: var(--text-primary); }

.chat-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-actions { display: flex; gap: 2px; align-items: center; visibility: hidden; }
.chat-item:hover .chat-item-actions { visibility: visible; }
.chat-item-actions button { padding: 4px 8px; font-size: 12px; color: var(--text-muted); border-radius: var(--radius-sm); display: flex; align-items: center; min-width: 28px; min-height: 28px; justify-content: center; }
.chat-item-actions button:hover { color: var(--danger); background: var(--danger-subtle); }

/* Mobile kebab menu */
.chat-item-menu-btn { display: none; }
.chat-item-menu { display: none; }

@media (max-width: 768px) {
    .chat-item { position: relative; padding-right: 40px; }
    .chat-item-actions { display: none !important; }
    .chat-item-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        right: 8px;
        top: 50%;
        transform: translateY(-50%);
        width: 28px;
        height: 28px;
        font-size: 18px;
        color: var(--text-muted);
        border-radius: var(--radius);
        flex-shrink: 0;
        -webkit-tap-highlight-color: transparent;
    }
    .chat-item-menu-btn:hover,
    .chat-item.menu-open .chat-item-menu-btn {
        color: var(--text-primary);
        background: rgba(var(--overlay-rgb), 0.08);
    }
    .chat-item.menu-open .chat-item-menu {
        display: flex;
        flex-direction: column;
        position: absolute;
        right: 8px;
        top: 100%;
        z-index: 200;
        background: var(--bg-secondary);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow-md);
        min-width: 140px;
        padding: 4px;
    }
    .chat-item-menu button {
        padding: 8px 12px;
        font-size: 13px;
        color: var(--text-secondary);
        text-align: left;
        border-radius: var(--radius-sm);
        -webkit-tap-highlight-color: transparent;
    }
    .chat-item-menu button:hover,
    .chat-item-menu button:active {
        background: rgba(var(--overlay-rgb), 0.06);
        color: var(--text-primary);
    }
    .chat-item-menu button.danger {
        color: var(--danger);
    }
    .chat-item-menu button.danger:hover,
    .chat-item-menu button.danger:active {
        background: var(--danger-subtle);
    }
}

.chat-item.streaming .chat-item-title::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 6px;
    flex-shrink: 0;
    animation: pulse 1.2s ease-in-out infinite;
}

.sidebar-footer {
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
}
.user-menu-wrapper { position: relative; }
.user-info-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    width: 100%;
    padding: 8px 10px;
    border-radius: var(--radius);
    transition: background var(--transition-fast);
}
.user-info-btn:hover { background: rgba(var(--overlay-rgb),0.05); color: var(--text-primary); }
.user-avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    color: var(--on-accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
    flex-shrink: 0;
}
.user-menu {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 150;
    padding: 6px;
    animation: menuIn 0.15s ease-out;
}
.user-menu.open { display: block; }
@keyframes menuIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.user-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    border-radius: var(--radius);
    transition: all var(--transition-fast);
    text-align: left;
}
.user-menu-item .umi { display: inline-flex; width: 18px; text-align: center; justify-content: center; flex-shrink: 0; font-size: 14px; }
.user-menu-item:hover { background: rgba(var(--overlay-rgb),0.06); color: var(--text-primary); }
.user-menu-item.danger { color: var(--danger); }
.user-menu-item.danger:hover { background: var(--danger-subtle); }
.user-menu-divider { height: 1px; background: var(--border); margin: 4px 6px; }

/* --- Main Area --- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.main.chat-drop-active::before {
    content: 'Datei hier ablegen';
    position: absolute;
    inset: 8px;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-subtle);
    border: 2px dashed var(--accent);
    border-radius: 12px;
    color: var(--accent);
    font-size: 20px;
    font-weight: 600;
    pointer-events: none;
    backdrop-filter: blur(2px);
}

.main-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    height: 52px;
    background: var(--bg-primary);
    flex-shrink: 0;
}

.hamburger { display: none; padding: 8px; font-size: 18px; color: var(--text-secondary); }
.hamburger:hover { color: var(--text-primary); }

/* --- Model Dropdown (custom) --- */
.provider-warning {
    font-size: 11px;
    color: var(--warning);
    padding: 2px 12px 0;
    line-height: 1.3;
}
.model-dropdown-panel {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 300px;
    max-height: 420px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 150;
    overflow: hidden;
    flex-direction: column;
}
.model-dropdown-search-wrap { padding: 8px; }
.model-dropdown-search {
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
}
.model-dropdown-search:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-subtle); }
.model-dropdown-list { overflow-y: auto; padding: 0 0 6px; max-height: 360px; }
.model-dropdown-list::-webkit-scrollbar { width: 6px; }
.model-dropdown-list::-webkit-scrollbar-track { background: transparent; }
.model-dropdown-list::-webkit-scrollbar-thumb { background: rgba(var(--overlay-rgb),.15); border-radius: var(--radius-sm); }
.model-dropdown-list::-webkit-scrollbar-thumb:hover { background: rgba(var(--overlay-rgb),.25); }
.model-dropdown-group {
    padding: 10px 14px 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.model-dropdown-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    /* Right-padding reserves space for the always-visible star + the
       hover-faded edit/delete buttons, so the item-name never shifts when
       the actions appear. This is the core of the no-jitter fix. */
    padding: 9px 64px 9px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition-fast);
    width: 100%;
    box-sizing: border-box;
}
.model-dropdown-item:hover { background: rgba(var(--overlay-rgb),0.05); color: var(--text-primary); }
.model-dropdown-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-dropdown-item.in-use::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--accent);
    opacity: .45;
}
.model-dropdown-item-actions {
    /* Always rendered with stable layout — the star is permanently visible,
       edit/delete only fade in on hover. Avoids the display: none → flex
       repaint that caused subpixel item-jitter on hover. */
    display: flex;
    align-items: center;
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    gap: 2px;
}
.model-dropdown-item-actions button {
    padding: 2px 5px;
    font-size: 12px;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.model-dropdown-item-actions .model-dropdown-edit,
.model-dropdown-item-actions .model-dropdown-delete,
.model-dropdown-item-actions .model-dropdown-copy {
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease, color var(--transition-fast), background var(--transition-fast);
}
.model-dropdown-item:hover .model-dropdown-edit,
.model-dropdown-item:hover .model-dropdown-delete,
.model-dropdown-item:hover .model-dropdown-copy,
.model-dropdown-item:focus-within .model-dropdown-edit,
.model-dropdown-item:focus-within .model-dropdown-delete,
.model-dropdown-item:focus-within .model-dropdown-copy {
    opacity: 1;
    pointer-events: auto;
}
.model-dropdown-item-actions .model-dropdown-edit:hover { color: var(--text-primary); background: rgba(var(--overlay-rgb),0.08); }
.model-dropdown-item-actions .model-dropdown-delete:hover { color: var(--danger); background: var(--danger-subtle); }
.model-dropdown-item-actions .model-dropdown-copy:hover { color: var(--text-primary); background: rgba(var(--overlay-rgb),0.08); }
.model-dropdown-item-actions .model-dropdown-copy svg { width: 13px; height: 13px; display: block; }
.model-dropdown-fav {
    color: var(--text-muted);
    opacity: 0.35;
    transition: opacity var(--transition-fast), color var(--transition-fast), background var(--transition-fast);
}
.model-dropdown-fav svg { display: block; }
.model-dropdown-item:hover .model-dropdown-fav { opacity: 0.7; }
.model-dropdown-fav:hover { opacity: 1 !important; background: rgba(var(--overlay-rgb),0.08); }
.model-dropdown-fav.is-fav {
    color: var(--purple);
    opacity: 1;
}
.model-dropdown-fav.is-fav:hover { color: var(--purple); background: color-mix(in srgb, var(--purple) 12%, transparent); }
.model-dropdown-group-favorites {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--purple);
}
.model-dropdown-group-favorites .model-dropdown-group-star {
    display: inline-flex;
    align-items: center;
}
.model-dropdown-group-favorites .model-dropdown-group-star svg { width: 11px; height: 11px; }
.model-dropdown-empty { padding: 16px; text-align: center; font-size: 13px; color: var(--text-muted); }
.model-dropdown-add { color: var(--text-muted); gap: 8px; padding-right: 14px; }
.model-dropdown-add svg { flex-shrink: 0; }
.model-dropdown-add:hover { color: var(--accent); }

/* --- Model Chip Selector --- */
.model-selector {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    max-width: 70%;
}

.model-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.model-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    height: 30px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.model-chip.clickable {
    cursor: pointer;
}

.model-chip.clickable:hover {
    border-color: var(--accent);
    background: var(--accent-subtle);
}

/* Active panel indicator — only set by JS on mobile where the swipe pager
   makes "currently viewed model" meaningful. Rendered as a small underline
   below the chip so it doesn't clash with the hover/tap feedback (which uses
   border + background colors). */
.model-chip { position: relative; }
.model-chip.active-panel::after {
    content: '';
    position: absolute;
    left: 25%;
    right: 25%;
    bottom: -6px;
    height: 2px;
    border-radius: 1px;
    background: var(--accent);
}

.model-chip-name {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.model-chip-remove {
    color: var(--text-muted);
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    transition: background var(--transition-fast), color var(--transition-fast);
    margin-left: 2px;
    opacity: .5;
}

.model-chip-remove svg {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
}

.model-chip-remove:hover {
    background: var(--danger-subtle);
    color: var(--danger);
    opacity: 1;
}

.model-add-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
    overflow: hidden;
    transition: width var(--transition-base), border-radius var(--transition-base), padding var(--transition-base), border-color var(--transition-base), background var(--transition-base);
}

.model-add-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.model-add-btn.expanding {
    width: 170px;
    border-radius: var(--radius-pill);
    padding: 5px 12px;
    border-color: var(--accent);
    background: var(--accent-subtle);
}

.model-add-btn .add-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity var(--transition-fast);
}

.model-add-btn .add-placeholder {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    max-width: 0;
    opacity: 0;
    display: none;
    transition: max-width var(--transition-base), opacity var(--transition-fast) .05s, margin var(--transition-base);
    margin-left: 0;
}

.model-add-btn.expanding .add-icon {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.model-add-btn.expanding .add-placeholder {
    display: inline;
    max-width: 160px;
    opacity: 1;
    margin-left: 0;
}

.model-selector.open .model-dropdown-panel {
    display: block;
    animation: menuIn 0.15s ease-out;
}

/* --- Side-by-Side Messages --- */
.message-row {
    display: flex;
    gap: 0;
    width: 100%;
}

.message-row .message-column {
    flex: 1;
    min-width: 0;
    border-right: 1px solid var(--border);
    padding: 8px 16px;
}

.message-row .message-column:last-child {
    border-right: none;
}

.message-column-header {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    padding-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.message-row.scrollable {
    overflow-x: auto;
    flex-wrap: nowrap;
}

.message-row.scrollable .message-column {
    min-width: 400px;
    flex-shrink: 0;
}

.messages-container.multi-model {
    max-width: 100%;
    padding: 16px 12px 24px;
}

/* Swipe-Pager-Dots: nur im Mobile-Block überschrieben, auf Desktop ausgeblendet */
.message-row-dots { display: none; }


.message-column .streaming-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: pulse 1.2s ease-in-out infinite;
}

.main-header-spacer { flex: 1; }

/* --- Chat Area --- */
.chat-area {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
}

.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    padding: 40px;
}
.welcome h2 {
    font-size: 28px;
    color: var(--text-primary);
    font-weight: 300;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.welcome p { font-size: 14px; color: var(--text-muted); }

/* --- Starter Questions --- */
.starter-questions {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 480px;
}
.starter-item {
    padding: 12px 16px;
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    line-height: 1.4;
}
.starter-item:hover {
    color: var(--accent);
    background: var(--accent-subtle);
    border-color: var(--accent);
}
.starter-item:active { transform: scale(0.97); }

/* --- Messages --- */
.messages-container {
    max-width: 740px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    padding: 16px 24px 24px;
    gap: 6px;
}

.message {
    padding: 0;
}
.message.user {
    align-self: flex-end;
    max-width: 85%;
}
.message.user .message-content {
    background: var(--bg-elevated);
    border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
    padding: 10px 16px;
}
.message.assistant {
    padding: 8px 0;
}

.search-highlight {
    background: var(--accent-glow);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 1px 2px;
    animation: searchFade 3s ease-out;
}
@keyframes searchFade {
    0%, 60% { background: var(--accent-glow); }
    100% { background: var(--accent-subtle); }
}

.message-sender {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-muted);
    letter-spacing: 0.2px;
}
.message.user .message-sender { text-align: right; }

.message-content {
    line-height: 1.7;
    word-break: break-word;
    min-width: 0;
}
/* During streaming, markdown is rendered without `.code-block-wrapper`, so the
   raw <pre> would otherwise force its column wider than its flex share — visible
   as the left model's answer bleeding into the right pane in dual-model chats. */
.message-content pre {
    max-width: 100%;
    overflow-x: auto;
}
.message-content-empty {
    color: var(--text-secondary);
}

.message-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1px;
    margin-top: 4px;
    opacity: 0;
    transition: opacity var(--transition-base);
}
.message.user .message-actions { justify-content: flex-end; }
.message:hover .message-actions { opacity: 1; }
.message-actions:has(.speed-badge) { opacity: 1; }
.msg-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
    color: var(--text-muted);
    transition: all var(--transition-fast);
}
.msg-icon-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.msg-icon-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.msg-icon-btn.success { color: var(--success); }
.speed-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 6px;
    padding: 2px 8px 2px 4px;
    font-size: 11px;
    color: var(--text-muted);
    border-radius: var(--radius);
    cursor: default;
}
.speed-badge svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.6;
}
.speed-badge span { font-weight: 500; }

.speed-badge-wrap { display: contents; }
.speed-detail {
    display: none;
    flex-basis: 100%;
    font-size: 11px;
    color: var(--text-muted);
    padding: 2px 0;
    line-height: 1.5;
}
.speed-detail.open { display: block; }

/* --- Markdown Content --- */
.message-content p { margin: 0 0 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { margin: 4px 0 8px 20px; }
.message-content li { margin-bottom: 2px; }
.message-content h1, .message-content h2, .message-content h3,
.message-content h4, .message-content h5, .message-content h6 {
    margin: 16px 0 8px;
    color: var(--text-primary);
}
.message-content h1 { font-size: 1.4em; }
.message-content h2 { font-size: 1.2em; }
.message-content h3 { font-size: 1.1em; }
.message-content blockquote {
    border-left: 3px solid var(--accent);
    padding: 4px 14px;
    margin: 8px 0;
    color: var(--text-secondary);
    background: var(--accent-subtle);
    border-radius: 0 var(--radius) var(--radius) 0;
}
.message-content table { border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 13px; }
.message-content th, .message-content td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.message-content th { background: var(--bg-input); font-weight: 600; }
.message-content hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.message-content a { color: var(--accent); }
.message-content img { max-width: 100%; border-radius: var(--radius); }

/* Code: inline */
.message-content code {
    background: rgba(var(--overlay-rgb),0.08);
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.87em;
}

/* Code: blocks */
.code-block-wrapper {
    position: relative;
    margin: 10px 0;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--code-bg);
    border: 1px solid rgba(var(--overlay-rgb),0.06);
}
.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 14px;
    background: rgba(var(--overlay-rgb),0.03);
    font-size: 11px;
    color: var(--text-muted);
    border-bottom: 1px solid rgba(var(--overlay-rgb),0.04);
}
.code-copy-btn {
    font-size: 11px; color: var(--text-muted);
    padding: 2px 10px; border-radius: var(--radius-sm); cursor: pointer;
    transition: all var(--transition-fast);
}
.code-copy-btn:hover { color: var(--text-primary); background: rgba(var(--overlay-rgb),0.08); }
.code-block-wrapper pre { margin: 0; padding: 14px; overflow-x: auto; }
.code-block-wrapper pre code {
    background: none; padding: 0; border-radius: 0;
    font-size: 13px; line-height: 1.5;
}

/* --- Think Block --- */
.think-block {
    margin-bottom: 10px;
    border: none;
    border-left: 2px solid var(--accent);
    border-radius: 0;
    background: none;
    padding-left: 12px;
}
.think-block summary {
    padding: 4px 0;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
    list-style: none;
}
.think-block summary::-webkit-details-marker { display: none; }
.think-block summary::marker { display: none; content: ''; }
.think-block summary:hover { color: var(--text-secondary); }
.think-chevron {
    width: 16px; height: 16px; flex-shrink: 0;
    transition: transform var(--transition-base);
    color: var(--text-muted);
}
.think-block[open] .think-chevron { transform: rotate(90deg); }
.think-label { font-weight: 600; }
.think-timer { font-weight: 400; opacity: 0.7; }
.think-pulse {
    display: inline-block; width: 6px; height: 6px;
    background: var(--accent); border-radius: 50%;
    margin-left: 2px; vertical-align: middle;
    animation: think-pulse-anim 1.4s ease-in-out infinite;
}
@keyframes think-pulse-anim {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.3; transform: scale(0.7); }
}
.think-block .think-content {
    padding: 8px 0;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
    line-height: 1.5;
    opacity: 0.85;
}

/* --- Follow-ups --- */
.followups {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
}
.followups-label { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.followup-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 7px 12px;
    margin: 2px 0;
    font-size: 13px;
    color: var(--text-secondary);
    background: none;
    border: none;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-radius: var(--radius);
}
.followup-item:hover { color: var(--accent); background: var(--accent-subtle); }
.followup-item:active { transform: scale(0.97); }

/* --- Web search sources --- */
.web-sources {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
}
.web-sources-label { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.web-sources-list {
    list-style: decimal inside;
    padding-left: 0;
    margin: 0;
}
.web-sources-list li {
    font-size: 13px;
    line-height: 1.55;
    margin: 2px 0;
    color: var(--text-secondary);
}
.web-sources-list a {
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius);
    padding: 1px 4px;
    transition: all var(--transition-fast);
}
.web-sources-list a:hover { color: var(--accent); background: var(--accent-subtle); text-decoration: underline; }

/* --- Streaming indicator --- */
.streaming-dot {
    display: inline-block; width: 6px; height: 6px;
    background: var(--accent); border-radius: 50%;
    animation: pulse 1.2s ease-in-out infinite; margin-left: 4px; vertical-align: middle;
}
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.3; transform: scale(0.85); } }

.describe-hint {
    color: var(--text-muted); font-size: 0.9em; margin-left: 6px; font-style: italic;
}

/* --- Input Area --- */
.input-area {
    padding: var(--space-md) var(--space-xl) 18px;
    background: var(--bg-primary);
    flex-shrink: 0;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 740px;
    margin: 0 auto;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 5px 5px 5px 16px;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
.input-row:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}

.input-row textarea {
    flex: 1;
    resize: none;
    min-height: 28px;
    max-height: 50vh;
    padding: 6px 0;
    font-size: 16px;
    line-height: 1.5;
    border: none;
    background: transparent;
    outline: none;
}
.input-row textarea:focus { box-shadow: none; }

.send-btn {
    padding: 0;
    background: var(--accent);
    color: var(--on-accent);
    border-radius: var(--radius);
    font-size: 16px;
    height: 36px;
    width: 36px;
    min-width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-hover); box-shadow: 0 2px 6px var(--accent-glow); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.send-btn:active:not(:disabled) { transform: scale(0.97); }
.send-btn.stop-mode { background: var(--danger); }
.send-btn.stop-mode:hover { background: var(--danger-hover); box-shadow: 0 2px 6px var(--danger-subtle); }

/* --- Input Toolbar --- */
.input-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 740px;
    margin: 4px auto 0;
    padding: 0 4px;
}
.input-toolbar-left, .input-toolbar-right {
    display: flex;
    align-items: center;
    gap: 2px;
}
.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    color: var(--text-muted);
    transition: all var(--transition-fast);
    padding: 0;
}
.toolbar-btn:hover:not(:disabled) {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.toolbar-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.toolbar-btn.active {
    color: var(--accent);
    background: var(--accent-subtle);
}
.toolbar-btn.active:hover {
    background: var(--accent-glow);
}
.toolbar-btn.loading {
    pointer-events: none;
    opacity: 0.5;
    animation: toolbar-pulse 1s ease-in-out infinite;
}
@keyframes toolbar-pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* --- STT Recording Overlay --- */
.stt-overlay {
    display: none;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 740px;
    margin: 0 auto;
    height: 48px;
    padding: 0 6px;
    background: var(--bg-input);
    border: 1px solid var(--accent);
    border-radius: var(--radius-lg);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}
.stt-overlay.active {
    display: flex;
}
.stt-overlay.transcribing {
    display: flex;
}
.stt-overlay.transcribing .stt-waveform { display: none; }
.stt-overlay.transcribing .stt-done-btn { display: none; }
.stt-overlay.transcribing .stt-cancel-btn {
    order: 1;
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: var(--radius);
    background: var(--danger);
    color: var(--on-color);
}
.stt-overlay.transcribing .stt-cancel-btn:hover {
    background: var(--danger-hover);
    box-shadow: 0 2px 6px var(--danger-subtle);
}
.stt-overlay.transcribing .stt-timer {
    flex: 1;
    text-align: center;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.stt-overlay.transcribing .stt-timer::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
/* Reuses @keyframes spin defined below */
.stt-cancel-btn, .stt-done-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    transition: background var(--transition-fast);
}
.stt-cancel-btn {
    background: rgba(var(--overlay-rgb),0.08);
    color: var(--text-muted);
}
.stt-cancel-btn:hover { background: var(--danger-subtle); color: var(--danger); }
.stt-done-btn {
    background: var(--accent);
    color: var(--on-accent);
}
.stt-done-btn:hover { background: var(--accent-hover); }
.stt-waveform {
    flex: 1;
    height: 32px;
    overflow: hidden;
}
.stt-waveform canvas {
    display: block;
    width: 100%;
    height: 100%;
}
.stt-timer {
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
    min-width: 36px;
    text-align: right;
}

/* --- Voice Mode Overlay --- */
.voice-overlay {
    display: none;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 740px;
    margin: 0 auto;
    height: 48px;
    padding: 0 6px;
    background: var(--bg-input);
    border: 1px solid var(--accent);
    border-radius: var(--radius-lg);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}
.voice-overlay.active { display: flex; }
.voice-waveform {
    flex: 1;
    height: 32px;
    overflow: hidden;
}
.voice-waveform canvas {
    display: block;
    width: 100%;
    height: 100%;
}
.voice-overlay.connecting .voice-waveform { display: none; }
.voice-overlay.responding .voice-waveform { display: none; }
.voice-overlay.transcribing .voice-waveform { display: none; }
.voice-status {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}
.voice-overlay.responding .voice-status {
    flex: 1;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.voice-overlay.responding .voice-status::before {
    content: '';
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    animation: voice-pulse 1.2s ease-in-out infinite;
}
.voice-overlay.transcribing .voice-status {
    flex: 1;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.voice-overlay.transcribing .voice-status::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.voice-overlay.connecting .voice-status {
    flex: 1;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.voice-overlay.connecting .voice-status::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.voice-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    transition: background var(--transition-fast);
}
.voice-close-btn {
    background: rgba(var(--overlay-rgb),0.08);
    color: var(--text-muted);
}
.voice-close-btn:hover { background: var(--danger-subtle); color: var(--danger); }

.voice-mute-btn {
    background: rgba(var(--overlay-rgb),0.08);
    color: var(--text-muted);
}
.voice-mute-btn:hover { background: rgba(var(--overlay-rgb),0.16); color: var(--text); }
.voice-mute-btn svg { width: 18px; height: 18px; }
.voice-mute-btn .mic-off { display: none; }
.voice-mute-btn.muted {
    background: var(--danger);
    color: var(--on-color);
}
.voice-mute-btn.muted:hover { background: var(--danger); }
.voice-mute-btn.muted .mic-on { display: none; }
.voice-mute-btn.muted .mic-off { display: block; }

.voice-overlay.muted .voice-status { color: var(--danger); }
.toolbar-btn.voice-active {
    color: var(--accent);
    background: var(--accent-subtle);
}
@keyframes voice-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.3); }
}

/* --- Modal --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open { display: flex; animation: overlayIn 0.2s ease; }
.modal-overlay.closing { display: flex; animation: overlayOut 0.15s ease forwards; pointer-events: none; }
.modal-overlay.closing .modal { animation: modalOut 0.15s ease forwards; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes overlayOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes modalOut { from { opacity: 1; transform: scale(1) translateY(0); } to { opacity: 0; transform: scale(0.96) translateY(8px); } }

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    margin: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s ease-out;
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal.modal-wide { max-width: 860px; }
.modal.modal-sm { max-width: 400px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-header .btn-ghost {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 14px;
    line-height: 1;
    flex-shrink: 0;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
}
.modal-footer-spread { justify-content: space-between; }
.modal-footer-actions { display: flex; gap: 8px; }

/* --- Custom Model Layout --- */
.cm-top-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.label-optional { font-weight: 400; color: var(--text-muted); font-size: 11px; }
/* CM file upload header with + button */
.cm-files-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.cm-files-header label { margin-bottom: 0; }
.cm-files-header input[type="file"] { display: none; }
.cm-add-file-btn {
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
    border: 1.5px dashed var(--border);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}
.cm-add-file-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle);
}

/* CM file grid — reuses .attach-box from chat */
.cm-file-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 0;
}
.cm-file-grid:empty::after {
    content: 'Noch keine Dateien';
    color: var(--text-muted);
    font-size: 12px;
    opacity: 0.5;
    padding: 12px 0;
}
.cm-file-grid.dragover {
    background: var(--accent-subtle);
    border-radius: var(--radius);
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
    padding: 8px;
}

/* Audio text box variant */
.attach-box-audio {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 6px 7px;
    gap: 2px;
}
.attach-box-audio .attach-box-ext {
    color: var(--accent);
}

@media (max-width: 640px) {
    .modal.modal-wide { max-width: 100%; }
    .modal { margin: 10px; max-width: calc(100vw - 20px); }
    .modal.modal-sm { max-width: calc(100vw - 20px); }
    .cm-top-row { grid-template-columns: 1fr; }
    .cm-card { padding: var(--space-md); }
    .cm-share-toggles { gap: 4px; }
    .cm-share-toggle { padding: 5px 10px; font-size: 12px; }
}

/* === Admin === */

/* --- Stats --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    transition: all var(--transition-fast);
}
.stat-card:hover {
    border-color: rgba(var(--overlay-rgb),0.1);
}
.stat-card .stat-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    line-height: 1.2;
}
.stat-card .stat-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card-link { cursor: pointer; }
.stat-card-link:hover { border-color: var(--accent); background: var(--accent-subtle); }


.ranking-list {
    margin-top: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 4px 0;
}
.ranking-item {
    display: flex; align-items: center; gap: 14px;
    padding: 12px 16px; font-size: 13px;
    border-bottom: 1px solid var(--border-subtle);
    transition: background var(--transition-fast);
}
.ranking-item:last-child { border-bottom: none; }
.ranking-item:hover { background: rgba(var(--overlay-rgb),0.02); }
.ranking-name { min-width: 150px; font-weight: 500; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-bar { flex: 1; height: 5px; background: rgba(var(--overlay-rgb),0.06); border-radius: var(--radius-sm); overflow: hidden; }
.ranking-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--purple)); border-radius: var(--radius-sm); transition: width var(--transition-slow); }
.ranking-count { font-size: 12px; color: var(--text-muted); min-width: 32px; text-align: right; font-weight: 600; }

/* --- Admin Tables --- */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: none;
    border: none;
    border-radius: 0;
    overflow: hidden;
}
.admin-table th {
    text-align: left; padding: 8px 12px;
    font-size: 11px; font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-subtle);
    background: none;
}
.admin-table th:not(.no-sort) {
    cursor: pointer; user-select: none;
}
.admin-table th:not(.no-sort):hover { color: var(--text-secondary); }
.admin-table th:not(.no-sort)::after {
    content: ''; display: inline-block; margin-left: 4px; vertical-align: middle;
    border-left: 3.5px solid transparent; border-right: 3.5px solid transparent;
    border-bottom: 4px solid currentColor; opacity: 0; transition: opacity var(--transition-fast);
}
.admin-table th:not(.no-sort):hover::after { opacity: 0.35; }
.admin-table th.sort-asc::after {
    opacity: 1 !important; border-bottom: 4px solid var(--accent); border-top: none;
}
.admin-table th.sort-desc::after {
    opacity: 1 !important; border-bottom: none; border-top: 4px solid var(--accent);
}
.admin-table td {
    padding: 8px 12px;
    vertical-align: middle;
    white-space: nowrap;
}
.admin-table tr { transition: background var(--transition-fast); border-bottom: 1px solid var(--border-subtle); }
.admin-table tbody tr:hover td { background: rgba(var(--overlay-rgb),0.02); }
.admin-table tbody tr:last-child { border-bottom: none; }

.admin-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.badge {
    display: inline-block;
    min-width: 64px;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.2px;
    text-align: center;
}
.badge-admin { background: var(--accent-subtle); color: var(--accent); }
.badge-user { background: var(--success-subtle); color: var(--success); }
.badge-pending { background: var(--warning-subtle); color: var(--warning); }
.badge-online { background: var(--success-subtle); color: var(--success); }
.badge-offline { background: rgba(var(--overlay-rgb),0.05); color: var(--text-muted); }

.action-btns { vertical-align: middle; }
.action-btns-wrap { display: flex; gap: 4px; justify-content: flex-end; align-items: center; flex-wrap: nowrap; }
.action-btn {
    padding: 5px 12px;
    font-size: 11px;
    white-space: nowrap;
    font-weight: 600;
    border-radius: var(--radius);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    background: var(--bg-input);
    transition: all var(--transition-fast);
}
.action-btn:hover { color: var(--text-primary); background: var(--bg-hover); border-color: rgba(var(--overlay-rgb),0.12); }
.action-btn:active { transform: scale(0.97); }
.action-btn.danger { color: var(--danger); }
.action-btn.danger:hover { background: var(--danger-subtle); border-color: color-mix(in srgb, var(--danger) 20%, transparent); }
.action-btn.success { color: var(--success); }
.action-btn.success:hover { background: var(--success-subtle); border-color: color-mix(in srgb, var(--success) 20%, transparent); }

/* --- Admin Forms --- */
.settings-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 680px;
}
.settings-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.settings-section-title {
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-subtle);
    background: none;
}
.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
}
.settings-grid select, .settings-grid input { width: 100%; }
.settings-grid input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.settings-grid input[type="number"]::-webkit-outer-spin-button,
.settings-grid input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.settings-grid .toggle { margin-top: 4px; }
.save-check {
    color: var(--success);
    margin-left: 6px;
    font-size: 0.85em;
    opacity: 1;
    transition: opacity var(--transition-slow);
}
.save-check.fade-out { opacity: 0; }

.conn-form { padding: 16px 20px; display: flex; flex-direction: row; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.conn-form .form-group { flex: 1; min-width: 180px; }
.conn-save-btn { white-space: nowrap; font-size: 13px; padding: 10px 20px; border: 1px solid transparent; box-sizing: border-box; min-width: 160px; text-align: center; }
.input-with-icon { position: relative; }
.input-with-icon input { width: 100%; padding-right: 40px; }
/* Compound selector (0,2,1) beats [data-tooltip] (0,1,0) which the title→
   tooltip migration would otherwise apply and force the eye-toggle into the
   document flow at the left of the input. */
.input-with-icon .input-icon-btn {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer; padding: 4px;
    color: var(--text-muted); display: flex; align-items: center;
}
.input-with-icon .input-icon-btn:hover { color: var(--text-primary); }
/* Meta row beneath .conn-form — columns mirror the form cells so the left
   cell sits under API-URL and the hint under API-KEY. On wide viewports the
   spacer reserves the button column; on narrow viewports the spacer hides
   and the cells wrap naturally (min-width forces them to their own rows
   rather than cramming the hint into a sliver). */
.conn-meta {
    display: flex;
    padding: 4px 20px 14px;
    gap: 12px;
    font-size: 12px;
    color: var(--text-muted);
    flex-wrap: wrap;
    align-items: flex-start;
}
.conn-meta-cell {
    flex: 1 1 240px;
    min-width: 240px;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.4;
}
.conn-meta-hint {
    flex-wrap: wrap;  /* let inline <code> badges wrap cleanly */
}
.conn-meta-spacer {
    flex: 0 0 auto;
    min-width: 160px;  /* matches .conn-save-btn min-width */
}
/* Once the main area can't fit two 240px cells + a 160px spacer side by side,
   the spacer is noise — drop it so status + hint each keep their own row. */
@media (max-width: 900px) {
    .conn-meta-spacer { display: none; }
}

/* At narrow widths the form would otherwise wrap only the Save button onto
   its own row, leaving an awkward empty column beside it. Stack everything
   vertically instead — URL, Key, button and meta each become full-width. */
@media (max-width: 700px) {
    .conn-form { flex-direction: column; align-items: stretch; }
    .conn-form .form-group { min-width: 0; flex: none; }
    .conn-save-btn { width: 100%; min-width: 0; }
}
.conn-meta-hint code {
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    font-family: var(--font-mono, monospace);
    font-size: 11px;
    color: var(--text-primary);
}
.sync-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.sync-dot.online { background: var(--success); }
.sync-dot.offline { background: var(--danger); }

/* --- Toggle --- */
.toggle { position: relative; display: inline-block; width: 36px; height: 20px; cursor: pointer; }
.toggle input { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }
.toggle-slider {
    position: absolute; inset: 0;
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    transition: all var(--transition-base);
}
.toggle-slider::before {
    content: ""; position: absolute;
    width: 14px; height: 14px;
    left: 2px; top: 2px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition-base);
}
.toggle input:focus-visible + .toggle-slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle input:checked + .toggle-slider { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); background: var(--on-accent); }
#models-table thead th { vertical-align: bottom; }
.th-visible-col .toggle-header { display: block; min-width: 36px; min-height: 20px; margin-bottom: 4px; }

/* --- Model Drag & Drop --- */
.drag-handle-cell { width: 36px; text-align: center; padding-left: 8px !important; padding-right: 0 !important; }
.drag-handle {
    cursor: grab;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    user-select: none;
    opacity: 0.4;
    transition: opacity var(--transition-fast), color var(--transition-fast);
}
.drag-handle:hover { opacity: 1; color: var(--text-secondary); }
.drag-handle:active { cursor: grabbing; }
tr.dragging { opacity: 0.35; }
.drag-indicator {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent);
    pointer-events: none;
    z-index: 10;
    border-radius: var(--radius-sm);
    box-shadow: 0 0 6px var(--accent);
}

.sysprompt-textarea {
    width: 100%;
    min-height: 50vh;
    font-size: 13px;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    line-height: 1.6;
    padding: 14px 16px;
    resize: vertical;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.display-name-cell {
    cursor: default;
    border-bottom: 1px dashed transparent;
    transition: border-color var(--transition-fast);
}
.display-name-cell:hover { border-bottom-color: var(--text-muted); }
.display-name-edit,
.display-name-edit:focus {
    width: 100%;
    padding: 0;
    margin: 0;
    font-size: inherit;
    line-height: inherit;
    background: transparent;
    color: var(--accent);
    border: none;
    border-bottom: 1px solid var(--accent);
    border-radius: 0;
    outline: none;
    box-shadow: none;
    font-family: inherit;
}

/* --- Logs --- */
.logs-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}
.log-filter-tabs {
    display: flex;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 2px;
    margin-right: auto;
}
.log-filter-tab {
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    background: none;
    border: none;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}
.log-filter-tab:hover { color: var(--text-primary); }
.log-filter-tab.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}
.log-empty { color: var(--text-muted); font-size: 13px; padding: 20px 0; text-align: center; }
.log-hint { color: var(--text-muted); font-size: 12px; text-align: center; margin-top: 12px; opacity: 0.7; }
.pagination { display: flex; gap: 6px; margin-top: 16px; justify-content: center; }
.period-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all var(--transition-fast);
}
.period-btn:hover { color: var(--text-primary); background: var(--bg-hover); border-color: rgba(var(--overlay-rgb),0.12); }
.period-btn.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.period-btn:active { transform: scale(0.97); }
.log-timestamp { white-space: nowrap; color: var(--text-muted); }
.log-level { display: inline-block; min-width: 64px; text-align: center; padding: 3px 10px; border-radius: var(--radius-pill); font-size: 11px; font-weight: 600; letter-spacing: 0.2px; }
.log-level-error { background: var(--danger-subtle); color: var(--danger); }
.log-level-warning { background: var(--warning-subtle); color: var(--warning); }
.log-level-info { background: rgba(var(--overlay-rgb),0.05); color: var(--text-muted); }
.log-source { color: var(--text-muted); }

.log-row-clickable { cursor: pointer; }
.log-row-clickable:hover td { background: rgba(var(--overlay-rgb),0.03); }

.log-detail-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    overflow: hidden;
}
@media (max-width: 600px) {
    .log-detail-overlay { padding: 8px; }
    .log-detail-panel, .log-detail-panel-lg { max-width: 100%; max-height: 90vh; border-radius: var(--radius); }
}
.log-detail-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 800px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.log-detail-panel-lg {
    max-width: 960px;
    max-height: 85vh;
}
.log-detail-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
}
.log-detail-source { font-weight: 600; color: var(--text-secondary); }
.log-detail-time { color: var(--text-muted); font-size: 13px; margin-left: auto; margin-right: 4px; }
.log-detail-close {
    font-size: 22px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    border-radius: var(--radius-sm);
    margin-left: 8px;
}
.log-detail-close:hover { color: var(--text-primary); background: var(--bg-hover); }
.log-detail-message {
    padding: 16px 20px;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.log-detail-traceback {
    padding: 0 20px 20px;
    overflow: auto;
    flex: 1;
    min-height: 0;
}
.log-detail-traceback-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.log-copy-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-transform: none;
    letter-spacing: 0;
}
.log-copy-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.log-copy-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-color: rgba(var(--overlay-rgb),0.12);
}
.log-copy-btn.copied {
    color: var(--success);
    border-color: color-mix(in srgb, var(--success) 20%, transparent);
}
.log-detail-traceback pre {
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 16px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--danger);
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
    overflow-x: auto;
}

/* --- Admin Card (unified card-with-header pattern) --- */
.admin-card {
    background: none;
    border: none;
    border-radius: 0;
    overflow: visible;
}
.admin-card + .admin-card { margin-top: 16px; }
.admin-card-header {
    padding: var(--space-md) var(--space-lg);
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-subtle);
    background: none;
}

.admin-card .admin-table { border: none; border-radius: 0; background: none; }
.admin-card .ranking-list { border: none; border-radius: 0; margin-top: 0; background: none; }
.prompt-input-field { margin-top: 10px; width: 100%; }

/* --- Inline edit (chat rename, message edit) --- */
.inline-edit-input {
    width: 100%;
    padding: 0 4px;
    margin: 0 -4px;
    font-size: inherit;
    background: rgba(var(--overlay-rgb),0.06);
    color: var(--text-primary);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    outline: none;
    caret-color: var(--accent);
}
.inline-edit-input:focus { box-shadow: 0 0 0 2px var(--accent-subtle); border-color: var(--accent); }
.message.user.editing { max-width: 100%; align-self: stretch; }
.message.user.editing .message-content { background: transparent; padding: 0; }
.message.user.editing .message-sender { display: none; }
.edit-textarea {
    width: 100%;
    min-height: 44px;
    max-height: 400px;
    resize: none;
    overflow-y: auto;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-family: inherit;
    font-size: inherit;
    line-height: 1.6;
}
.edit-textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-subtle); }
.edit-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 6px; }
.edit-actions .btn { font-size: 12px; padding: 5px 14px; }

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar {
        position: fixed; top: 0; left: 0; height: 100vh; height: 100dvh;
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-resize-handle,
    .sidebar-folders-resize { display: none; }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99; }
    .sidebar-overlay.open { display: block; }
    .hamburger { display: block; }
    .model-selector { flex-wrap: nowrap; max-width: 85%; overflow: visible; }
    .model-chips { flex-wrap: nowrap; }
    .model-chip-name { max-width: 100px; }
    .model-add-btn.expanding { width: 140px; }
    .model-dropdown-panel {
        position: fixed;
        top: 52px;
        left: 8px;
        right: 8px;
        min-width: unset;
        max-height: 60vh;
    }
    .users-toolbar-row { flex-wrap: wrap; }
    .users-search-box { flex-basis: 100%; min-width: 0; }
    .org-group { flex-basis: 100%; flex-wrap: wrap; }
    .org-group select { flex: 1 1 100%; width: 100%; min-width: 0; }
    .action-btns-wrap { flex-wrap: nowrap; }
    .action-btns-wrap .action-btn { text-align: center; }
    .sidebar-collapse-btn { display: none; }
    .messages-container { padding: 0 16px 16px; }
    .input-area { padding: 10px 12px calc(14px + env(safe-area-inset-bottom, 0px)); }
    .toolbar-btn {
        width: 38px;
        height: 38px;
        -webkit-tap-highlight-color: transparent;
    }
    .toolbar-btn svg { width: 20px; height: 20px; }
    .input-toolbar { padding: 0; }
    /* Multi-Model auf Mobile: horizontaler Swipe-Pager mit Scroll-Snap statt Stapelung */
    .message-row {
        flex-direction: row;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        scroll-behavior: smooth;
        overscroll-behavior-x: contain;
        scrollbar-width: none;
    }
    .message-row::-webkit-scrollbar { display: none; }
    .message-row.scrollable { overflow-x: auto; }
    .message-row .message-column,
    .message-row.scrollable .message-column {
        flex: 0 0 100%;
        min-width: 100%;
        scroll-snap-align: start;
        border-right: none;
        border-bottom: none;
    }
    .message-row-dots {
        display: flex;
        justify-content: center;
        gap: 6px;
        padding: 4px 0 10px;
    }
    .message-row-dot {
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: var(--border);
        transition: background var(--transition-fast), transform var(--transition-fast);
    }
    .message-row-dot.active {
        background: var(--accent);
        transform: scale(1.3);
    }
    .speed-badge { cursor: pointer; -webkit-tap-highlight-color: transparent; }
    .speed-detail.open { cursor: pointer; -webkit-tap-highlight-color: transparent; }
    .edit-textarea { font-size: 16px; }
}

/* Generated images: wide, clean display */
.generated-image-wrap {
    margin: 10px 0;
    width: 100%;
}
.generated-image-wrap img {
    width: 100%;
    border-radius: var(--radius-xl);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    display: block;
}
.generated-image-wrap img:hover {
    transform: scale(1.01);
    box-shadow: var(--shadow-md);
}
.generated-image-wrap img:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-xl);
}

/* Image generation loading indicator */
.img-generating {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    max-width: 512px;
    margin: 10px 0;
    color: var(--text-secondary);
    font-size: 13px;
}
.img-generating-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Image preview overlay (fullscreen) */
.image-preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    cursor: zoom-out;
    backdrop-filter: blur(4px);
    touch-action: none;
    overflow: hidden;
}
.image-preview-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 10001;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(0,0,0,0.5);
    color: var(--on-color);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.image-preview-full {
    max-width: 90vw;
    max-height: 85vh;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    transform-origin: center center;
    will-change: transform;
    user-select: none;
    -webkit-user-select: none;
}
.image-preview-caption {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 80vw;
    max-height: 20vh;
    overflow-y: auto;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    border-radius: var(--radius-md);
    backdrop-filter: blur(8px);
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    box-shadow: var(--shadow-lg);
}
.image-preview-caption.is-placeholder {
    font-style: italic;
    opacity: 0.7;
}

/* === Admin: User Search & Bulk === */
.users-toolbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}
.users-toolbar-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
}
.org-group {
    display: flex;
    gap: 4px;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3px;
    background: var(--bg-secondary);
}
.org-group select {
    border: none;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13px;
    padding: 4px 8px;
    min-width: 140px;
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.org-group select option {
    background: var(--bg-primary);
    color: var(--text-primary);
}
.org-group select:focus { outline: none; }
.org-group .btn {
    padding: 4px 10px;
    font-size: 12px;
    white-space: nowrap;
    border-radius: var(--radius-sm);
}
.users-search-box {
    flex: 1;
    min-width: 200px;
    position: relative;
}
.users-search-box input {
    width: 100%;
    height: 100%;
    padding: 8px 32px 8px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    box-sizing: border-box;
}
.users-search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}
.users-search-clear {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    border: none;
    background: var(--bg-hover);
    color: var(--text-muted);
    border-radius: 50%;
    font-size: 11px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    align-items: center;
    justify-content: center;
}
.users-search-clear:hover {
    background: var(--border);
    color: var(--text-primary);
}
.users-bulk-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: transparent;
    border-radius: var(--radius);
    visibility: hidden;
    opacity: 0;
    transition: opacity var(--transition-fast), visibility var(--transition-fast);
}
.users-bulk-actions.visible {
    visibility: visible;
    opacity: 1;
}
.users-bulk-actions span {
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
    font-weight: 500;
    margin-right: 4px;
}
.users-bulk-actions .btn {
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 600;
}
.btn-success {
    background: var(--success);
    color: var(--on-color);
    border: none;
}
.btn-success:hover {
    background: var(--success-hover);
    box-shadow: 0 2px 8px var(--success-subtle);
}
.btn-success:active { transform: scale(0.97); }
.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle);
}
.btn-outline:active { transform: scale(0.97); }

/* Bulk org popover */
.bulk-org-popover {
    position: fixed;
    z-index: 10000;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    max-height: 300px;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.bulk-org-option.cb {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
}
.bulk-org-option.cb:hover {
    background: rgba(var(--overlay-rgb), 0.06);
}
.bulk-org-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bulk-org-count {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: auto;
    flex-shrink: 0;
}

/* Custom Checkbox */
.cb {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    width: 18px;
    height: 18px;
}
.cb input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}
.cb-box {
    width: 18px;
    height: 18px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--text-muted);
    background: transparent;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}
.cb-box::after {
    content: '';
    display: none;
    width: 4px;
    height: 8px;
    border: solid var(--on-accent);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) translateY(-1px);
}
.cb input:checked + .cb-box {
    background: var(--accent);
    border-color: var(--accent);
}
.cb input:checked + .cb-box::after {
    display: block;
}
.cb input:focus-visible + .cb-box { outline: 2px solid var(--accent); outline-offset: 2px; }
.cb:hover .cb-box {
    border-color: var(--accent);
}
.th-cb, .td-cb {
    width: 40px;
    text-align: center;
}
tr.row-selected {
    background: var(--accent-subtle) !important;
}
tr.row-deleting {
    opacity: 0.4;
    pointer-events: none;
    transition: max-height var(--transition-slow), opacity var(--transition-slow);
    overflow: hidden;
}
.badge-deleting {
    background: var(--text-muted);
    color: var(--bg-primary);
    font-style: italic;
}

/* === Global Toast === */
#toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    padding: 10px 18px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    max-width: 400px;
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateX(40px);
    cursor: default;
}
.toast-in {
    animation: toast-slide-in 0.25s ease forwards;
}
.toast-out {
    animation: toast-slide-out 0.2s ease forwards;
}
.toast-success {
    background: var(--success-subtle);
    color: var(--success);
    border: 1px solid color-mix(in srgb, var(--success) 20%, transparent);
}
.toast-error {
    background: var(--danger-subtle);
    color: var(--danger);
    border: 1px solid color-mix(in srgb, var(--danger) 20%, transparent);
}
.toast-info {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
@keyframes toast-slide-in {
    to { opacity: 1; transform: translateX(0); }
}
@keyframes toast-slide-out {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}

/* --- Admin utility classes --- */
.user-email-cell { color: var(--text-muted); font-size: 12px; }
.model-dropdown-divider { height: 1px; background: var(--border); margin: 4px 10px; }

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* Org cell in user table */
td.org-cell { white-space: normal; vertical-align: middle; }
.cm-section-label {
    font-weight: 600;
    margin-bottom: var(--space-sm);
    font-size: 13px;
}

/* Share toggles — horizontal pill row */
.cm-share-toggles {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: var(--space-sm);
}
.cm-share-toggle {
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    user-select: none;
}
.cm-share-toggle:hover { border-color: var(--accent); color: var(--text-primary); }
.cm-share-toggle.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 500;
}

.cm-share-detail {
    margin-top: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--border);
    transition: opacity var(--transition-fast);
}
.cm-share-detail.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.cm-share-search {
    width: 100%;
    padding: 7px 12px;
    font-size: 13px;
    margin-bottom: var(--space-sm);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
}
.cm-share-search:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-subtle); }
.cm-share-search::placeholder { color: var(--text-muted); }
.cm-share-list {
    max-height: 280px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 2px 16px;
    align-content: start;
}

.share-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.share-item:hover { background: var(--bg-hover); }
.share-user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}
.share-user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.share-user-email {
    font-size: 10px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}

.share-group-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: var(--space-sm) var(--space-sm) var(--space-xs);
    font-weight: 600;
    letter-spacing: 0.5px;
    grid-column: 1 / -1;
}

.shared-by {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
}

.btn-sm {
    padding: 5px 12px;
    font-size: 12px;
}

.share-placeholder {
    color: var(--text-muted);
    font-size: 13px;
    font-style: italic;
    padding: var(--space-sm);
}

.model-share-btn.has-shares { color: var(--accent); font-weight: 600; }

/* === Utility Classes === */
.hidden { display: none !important; }

/* --- Attachments Bar (images + docs combined) --- */
.attachments-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 740px;
    margin: 0 auto 10px;
    justify-content: center;
}
.attachments-bar:not(:has(.attach-box)) {
    display: none;
}
.attachments-images,
.attachments-docs {
    display: contents;
}

/* Unified attachment boxes (images + docs) */
.attachments-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 6px;
}
.attach-box {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-lg);
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.attach-box:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

/* Image box */
.attach-box-image {
    background: var(--bg-secondary);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
}
.attach-box-image img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: inherit;
}
.attach-box-image .attach-box-ext {
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    z-index: 1;
}

/* Document box */
.attach-box-doc {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 6px 7px;
    gap: 2px;
}
.attach-box-ext {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.attach-box-preview {
    flex: 1;
    width: 100%;
    overflow: hidden;
    font-size: 6px;
    line-height: 1.4;
    color: var(--text-muted);
    opacity: 0.6;
    word-break: break-all;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    line-clamp: 4;
    -webkit-box-orient: vertical;
}
.attach-box-preview:empty::before {
    content: 'Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod';
    opacity: 0.3;
}
.attach-box-name {
    font-size: 8px;
    color: var(--text-secondary);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    line-height: 1.2;
}

/* Single X button used for both "cancel upload" and "remove uploaded file".
   Higher specificity (.attach-box .attach-box-remove) defeats [data-tooltip]
   from the title→data-tooltip migration, which would otherwise force
   position:relative and drop the button into flex flow. */
.attach-box .attach-box-remove {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    border: none;
    color: var(--on-color);
    font-size: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    z-index: 15;
    opacity: 0;
    transition: opacity var(--transition-fast), background var(--transition-fast);
}
/* Always-visible affordance while user can act:
   - hover (done state) → reveal so user knows they can detach
   - uploading           → cancel handle must be obvious
   - error               → user must be able to dismiss the failed tile */
.attach-box:hover .attach-box-remove,
.attach-box.uploading .attach-box-remove,
.attach-box.error .attach-box-remove {
    opacity: 1;
}
.attach-box .attach-box-remove:hover {
    background: var(--danger);
}

/* Uploading state */
.attach-box.migration-pending {
    opacity: 0.6;
}
.attach-box.migration-pending::after {
    content: '⏳';
    position: absolute;
    top: 4px;
    right: 6px;
    font-size: 12px;
    z-index: 10;
}

.attach-box.uploading {
    opacity: 1;
}
.attach-box.uploading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
    border-radius: inherit;
    z-index: 10;
}

/* Upload progress ring — drives stroke-dashoffset from JS. */
.attach-box-progress {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    z-index: 11;
    pointer-events: none;
}
.attach-box-progress-ring-wrap {
    position: relative;
    width: 38px;
    height: 38px;
}
.attach-box-ring {
    width: 100%;
    height: 100%;
    display: block;
    transform: rotate(-90deg);
}
.attach-box-ring .ring-track,
.attach-box-ring .ring-fill {
    fill: none;
    stroke-width: 3;
    stroke-linecap: round;
}
.attach-box-ring .ring-track {
    stroke: rgba(255, 255, 255, 0.22);
}
.attach-box-ring .ring-fill {
    stroke: var(--on-color);
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 250ms ease-out;
}
/* Indeterminate state used until the first real % arrives. */
.attach-box-ring.indeterminate .ring-fill {
    stroke-dasharray: 18 82;
    transition: none;
    animation: ringSpin 1.1s linear infinite;
}
@keyframes ringSpin {
    from { stroke-dashoffset: 100; }
    to   { stroke-dashoffset: 0; }
}
.attach-box-progress-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--on-color);
    line-height: 1;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.attach-box-progress-eta {
    font-size: 9px;
    line-height: 1;
    color: rgba(255, 255, 255, 0.75);
    font-variant-numeric: tabular-nums;
    min-height: 9px;
    letter-spacing: 0.02em;
}
.attach-box.done::after {
    content: '\2713';
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
    border-radius: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--success);
    font-size: 26px;
    font-weight: 700;
    animation: checkPop 0.3s ease-out;
    z-index: 10;
}
@keyframes checkPop {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}
.attach-box.error {
    border-color: var(--danger);
    opacity: 0.6;
}
.attach-box.error::after {
    content: '\2717';
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
    border-radius: inherit;
    display: flex;
    z-index: 10;
    align-items: center;
    justify-content: center;
    color: var(--danger);
    font-size: 26px;
    font-weight: 700;
}

/* Document preview overlay */
.doc-preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 24px;
    backdrop-filter: blur(4px);
}
.doc-preview-panel {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    max-width: 700px;
    width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}
.doc-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.doc-preview-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}
.doc-preview-close {
    color: var(--text-secondary);
    font-size: 22px;
    padding: 0 4px;
    line-height: 1;
}
.doc-preview-close:hover {
    color: var(--text-primary);
}
.doc-preview-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}
.doc-preview-image {
    background: var(--img-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
}
.doc-preview-image img {
    max-width: 100%;
    display: block;
}
.doc-preview-text {
    padding: 18px;
    margin: 0;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
}
.doc-preview-markdown {
    white-space: normal;
}
.doc-preview-markdown h2,
.doc-preview-markdown h3 {
    margin: 1em 0 0.5em;
}
.doc-preview-markdown table {
    border-collapse: collapse;
    margin: 0.8em 0;
    font-size: 12px;
    width: 100%;
}
.doc-preview-markdown th,
.doc-preview-markdown td {
    border: 1px solid var(--border);
    padding: 4px 8px;
    text-align: left;
}
.doc-preview-markdown th {
    background: var(--bg-secondary);
    font-weight: 600;
}
.doc-preview-markdown p {
    margin: 0.5em 0;
}
.doc-preview-markdown pre {
    background: var(--bg-secondary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
}

/* === View System === */
.view-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 24px 32px;
    gap: 16px;
}

.view-panel .admin-card {
    max-width: 100%;
}

/* === Admin Sidebar Nav === */
.sidebar-admin-nav {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
    padding: 0 8px;
}

.admin-nav-back {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    margin-bottom: 4px;
    border: none;
    border-radius: var(--radius);
    background: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.admin-nav-back:hover { background: rgba(var(--overlay-rgb),0.06); color: var(--text-primary); }
.sidebar.collapsed .admin-nav-back span:not(svg) { display: none; }

.admin-nav-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.admin-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: var(--radius);
    background: none;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
}

.admin-nav-item:hover {
    background: rgba(var(--overlay-rgb),0.07);
    color: var(--text-primary);
}

.admin-nav-item.active {
    background: var(--accent-subtle);
    color: var(--text-primary);
    font-weight: 600;
}

.admin-nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.admin-nav-icon svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Collapsed sidebar: hide admin nav text, show only icons */
.sidebar.collapsed .admin-nav-item {
    justify-content: center;
    padding: 8px;
}

.sidebar.collapsed .admin-nav-item span:not(.admin-nav-icon) {
    display: none;
}

.sidebar.collapsed .sidebar-admin-nav {
    padding: 0 4px;
}
.sidebar.collapsed .admin-nav-back {
    justify-content: center;
    padding: 8px;
}
.sidebar.collapsed .admin-nav-back span { display: none; }


/* === Inline Profile Panel === */
#user-menu-profile {
    padding: 8px 12px 4px;
}

#user-menu-profile .form-group-sm {
    margin-bottom: 6px;
}

#user-menu-profile .form-group-sm label {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

#user-menu-profile .form-group-sm input {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13px;
}

#user-menu-profile .form-group-sm input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#user-menu-profile .user-menu-divider {
    margin: 8px 0;
}

#user-menu-profile .profile-save-btn {
    width: 100%;
    margin-top: 4px;
}

/* === Model Editor View === */
.cm-editor-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: var(--space-lg);
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 10;
    padding-bottom: var(--space-sm);
}
.cm-editor-header h3 { margin: 0; font-size: 17px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cm-editor-header-actions { display: flex; gap: 8px; flex-shrink: 0; }

.cm-editor-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    max-width: 800px;
}
.cm-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
}
.cm-card > label:first-child { margin-bottom: var(--space-sm); display: block; }
.cm-card textarea { min-height: 200px; max-height: 60vh; width: 100%; resize: none; }

/* --- Daten weiterer Modelle (linked custom models as additional RAG sources) --- */
.cm-links-header { margin-bottom: var(--space-sm); }
.cm-links-header label { display: block; margin-bottom: 4px; }
.cm-links-help {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}
.cm-links-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.cm-links-placeholder {
    color: var(--text-muted);
    font-size: 13px;
    font-style: italic;
    padding: var(--space-sm) 0;
}
.cm-link-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}
.cm-link-item:hover { border-color: var(--accent); }
.cm-link-info { min-width: 0; flex: 1; }
.cm-link-name {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cm-link-meta { margin-top: 2px; }
.cm-link-badge {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-weight: 500;
}
.cm-link-badge-own {
    background: var(--accent-subtle);
    color: var(--accent);
}
.cm-link-badge-shared {
    background: rgba(255,255,255,0.04);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
[data-theme="light"] .cm-link-badge-shared { background: rgba(0,0,0,0.04); }

/* iOS-style toggle switch */
.cm-link-toggle {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 22px;
    flex-shrink: 0;
}
.cm-link-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.cm-link-toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 999px;
    transition: background var(--transition-fast);
}
.cm-link-toggle-slider::before {
    content: '';
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--transition-fast);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.cm-link-toggle input:checked + .cm-link-toggle-slider { background: var(--accent); }
.cm-link-toggle input:checked + .cm-link-toggle-slider::before { transform: translateX(16px); }
.cm-link-toggle input:focus-visible + .cm-link-toggle-slider {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (max-width: 768px) {
    .view-panel {
        padding: 16px;
    }
}

/* === Inline Confirm === */
.inline-confirming {
    color: var(--danger) !important;
    font-weight: 600;
    white-space: nowrap;
}

.ic-label {
    margin-right: 4px;
}

.ic-yes, .ic-no {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    font-weight: 700;
}

.ic-yes:hover {
    background: var(--success-subtle);
    color: var(--success);
}

.ic-no:hover {
    background: var(--danger-subtle);
    color: var(--danger);
}

/* === Bottom-sheet confirmation === */
.bs-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 300;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition-base);
}
.bs-backdrop.open { opacity: 1; }
.bs-backdrop.closing { opacity: 0; pointer-events: none; }

.bs-sheet {
    width: 100%;
    max-width: 540px;
    background: var(--bg-secondary);
    border-top-left-radius: var(--radius-xl);
    border-top-right-radius: var(--radius-xl);
    border: 1px solid var(--border);
    border-bottom: none;
    box-shadow: var(--shadow-lg);
    padding: 8px 20px calc(16px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    gap: 8px;
    transform: translateY(100%);
    transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}
.bs-backdrop.open .bs-sheet { transform: translateY(0); }
.bs-backdrop.closing .bs-sheet { transform: translateY(100%); }

.bs-handle {
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: var(--border);
    margin: 8px auto 4px;
    flex-shrink: 0;
}

.bs-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    margin: 4px 0 0;
}
.bs-message {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    margin: 0 0 8px;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.bs-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}
.bs-actions button {
    min-height: 50px;
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 600;
    border-radius: var(--radius-lg);
    border: 1px solid transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.bs-actions .bs-confirm {
    background: var(--accent);
    color: var(--on-accent);
}
.bs-actions .bs-confirm.danger {
    background: var(--danger);
    color: var(--on-color);
}
.bs-actions .bs-confirm:hover,
.bs-actions .bs-confirm:active { filter: brightness(1.05); }
.bs-actions .bs-cancel {
    background: transparent;
    color: var(--text-primary);
    border-color: var(--border);
}
.bs-actions .bs-cancel:hover,
.bs-actions .bs-cancel:active {
    background: rgba(var(--overlay-rgb), 0.06);
}

@media (min-width: 769px) {
    .bs-backdrop { align-items: center; }
    .bs-sheet {
        border-radius: var(--radius-xl);
        border-bottom: 1px solid var(--border);
        max-width: 420px;
        margin: 20px;
        padding-bottom: 16px;
    }
    .bs-handle { display: none; }
}

/* === Inline Prompt === */
.inline-prompt-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    font-size: 13px;
}

.ip-label {
    color: var(--text-secondary);
    white-space: nowrap;
}

.ip-input {
    flex: 1;
    min-width: 120px;
    max-width: 200px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13px;
}

.ip-ok, .ip-cancel {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    font-weight: 700;
}

.ip-ok:hover {
    background: var(--success-subtle);
    color: var(--success);
}

.ip-cancel:hover {
    background: var(--danger-subtle);
    color: var(--danger);
}

/* === Impersonation === */

#impersonation-banner {
    padding: 0 16px 8px;
}

#impersonation-banner button {
    width: 100%;
    background: none;
    color: var(--warning);
    border: 1px solid var(--warning);
    border-radius: var(--radius);
    padding: 5px 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
}

#impersonation-banner button:hover {
    background: var(--warning);
    color: #000;
}

/* === Delete Spinner Overlay === */

#delete-spinner-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-spinner-box {
    background: var(--bg-primary);
    border-radius: var(--radius);
    padding: 32px 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-lg);
}

.delete-spinner-box p {
    margin: 0;
    font-size: 14px;
    color: var(--text-secondary);
}

/* === Migration === */

.migration-config {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px 16px;
    margin-bottom: 20px;
}

.migration-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
}

.migration-card-header {
    padding: 12px 16px;
    font-weight: 600;
    font-size: 14px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.migration-card-body {
    padding: 16px;
}

.migration-log {
    max-height: 500px;
    overflow-y: auto;
    font-size: 13px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    margin-bottom: 12px;
}

.migration-log-item {
    padding: 3px 0;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
}

.migration-log-item.done { color: var(--success); }
.migration-log-item.active { color: var(--text-primary); }
.migration-log-item.error { color: var(--danger); }

.mig-icon {
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.migration-progress-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.migration-progress {
    flex: 1;
    height: 8px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.migration-progress-bar {
    height: 100%;
    width: 0;
    background: var(--accent);
    border-radius: var(--radius-sm);
    transition: width var(--transition-slow);
}

.migration-progress-text {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    min-width: 120px;
}

.migration-actions {
    display: flex;
    gap: 8px;
}

/* ── Form hint: one-line caption beneath a form row. Lives outside the flex/
     grid of its sibling inputs so it doesn't push them around. ────────── */
.form-hint {
    margin: 0;
    padding: 0 20px 14px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-secondary);
}
.form-hint code {
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    font-family: var(--font-mono, monospace);
    font-size: 11px;
    color: var(--text-primary);
}

/* ── Model row meta-line (Context window + capabilities under the model name) */
.model-name-cell { display: flex; flex-direction: column; gap: 2px; }
.model-meta {
    font-size: 11px;
    color: var(--text-secondary);
    font-family: var(--font-mono, monospace);
    line-height: 1.3;
    letter-spacing: 0.01em;
}
.model-meta-unknown {
    color: var(--warning);
    cursor: help;
}

.migration-policy {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px 14px;
    margin-bottom: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
}
.migration-policy-icon {
    flex-shrink: 0;
    font-size: 16px;
    line-height: 1.35;
    color: var(--accent);
}
.migration-policy strong {
    color: var(--text-primary);
    font-weight: 600;
}

.migration-audit {
    margin-top: 12px;
    padding: 10px 14px;
    background: var(--warning-subtle, rgba(251,191,36,0.10));
    border: 1px solid var(--border);
    border-left: 3px solid var(--warning);
    border-radius: var(--radius);
    font-size: 13px;
}
.migration-audit-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}
.migration-audit-list {
    margin: 0;
    padding-left: 20px;
    color: var(--text-secondary);
    max-height: 180px;
    overflow-y: auto;
}
.migration-audit-list li {
    font-family: var(--font-mono, monospace);
    font-size: 12px;
    word-break: break-all;
}

@media (max-width: 640px) {
    .migration-config {
        grid-template-columns: 1fr;
    }
}


/* ========= Sidebar Folders ========= */
.sidebar-folders {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.folder-list {
    display: flex;
    flex-direction: column;
    padding: 2px 0 4px;
}
.folder-list:empty { display: none; }

.sidebar-folders:has(.folder-list:not(:empty)) {
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 4px;
    height: var(--folders-height, 40vh);
    max-height: 70vh;
}

.sidebar-folders-resize {
    height: 4px;
    cursor: row-resize;
    background: transparent;
    flex-shrink: 0;
    transition: background var(--transition-base);
}
.sidebar-folders-resize:hover { background: rgba(var(--overlay-rgb), 0.08); }
.sidebar-folders-resize.active { background: var(--accent); }
.sidebar-folders:not(:has(.folder-list:not(:empty))) + .sidebar-folders-resize { display: none; }
.sidebar.collapsed .sidebar-folders-resize { display: none; }

.folder-safezone {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 6px 8px;
    padding: 7px 12px;
    border: 1px dashed var(--border-subtle);
    border-radius: var(--radius);
    font-size: 11.5px;
    font-weight: 500;
    color: var(--text-muted);
    opacity: 0.65;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}
.folder-safezone:hover {
    opacity: 1;
    border-color: var(--border);
    color: var(--text);
    background: rgba(var(--overlay-rgb), 0.04);
}
body.dnd-active.dnd-chat .folder-safezone {
    opacity: 1;
    border-width: 1.5px;
    border-color: var(--border);
    padding: 10px 12px;
    font-size: 12px;
    color: var(--text);
}
.folder-safezone.drop-target-active {
    border-style: solid;
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle);
    opacity: 1;
}
.sidebar.collapsed .folder-safezone { display: none; }

.folder-item {
    display: flex;
    flex-direction: column;
    margin: 1px 8px;
    border-radius: var(--radius);
    transition: background var(--transition-fast);
}
.folder-item.drop-target-active {
    background: var(--accent-subtle);
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.folder-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius);
    user-select: none;
    position: relative;
}
.folder-header:hover { background: rgba(var(--overlay-rgb), 0.05); color: var(--text-primary); }

.folder-chevron {
    width: 14px; height: 14px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}
.folder-item.collapsed .folder-chevron { transform: rotate(-90deg); }

.folder-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.folder-name.inline-edit-input,
input.inline-edit-input {
    flex: 1;
    padding: 2px 6px;
    font-size: 13px;
    font-weight: 600;
    background: var(--bg-primary);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    outline: none;
    min-width: 0;
}

.folder-actions {
    display: flex;
    gap: 2px;
    align-items: center;
    visibility: hidden;
}
.folder-header:hover .folder-actions { visibility: visible; }
.folder-actions button {
    padding: 4px 8px;
    font-size: 12px;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    min-width: 28px;
    min-height: 28px;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
}
.folder-actions button:hover { color: var(--danger); background: var(--danger-subtle); }

/* Mobile kebab menu — hidden on desktop */
.folder-menu-btn { display: none; }
.folder-menu { display: none; }

.folder-chats {
    display: flex;
    flex-direction: column;
    padding-left: 14px;
    padding-bottom: 2px;
}
.folder-item.collapsed .folder-chats { display: none; }
.folder-chats .chat-item {
    margin: 1px 4px;
    font-size: 12.5px;
    padding: 6px 10px;
}
.folder-chats:empty::before {
    content: 'Leer';
    display: block;
    padding: 4px 14px;
    color: var(--text-muted);
    font-size: 11px;
    font-style: italic;
}

/* Folder reorder uses live FLIP swap (see app.js); no slot elements needed. */
body.dnd-active.dnd-folder .folder-item.drop-target-active {
    outline: none;
    background: transparent;
}

/* ========= DnD Ghost & Chip ========= */
.drag-ghost {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    opacity: 0.95;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.drag-chip {
    position: fixed;
    z-index: 10000;
    pointer-events: none;
    background: var(--accent);
    color: #fff;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    white-space: nowrap;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.drag-source { opacity: 0.4; }

body.dnd-active { user-select: none; -webkit-user-select: none; }
[data-draggable] { touch-action: pan-y; }
body.dnd-active [data-draggable] { touch-action: none; }
body.dnd-active, body.dnd-active * { cursor: grabbing !important; }

@media (max-width: 768px) {
    .folder-header { position: relative; padding-right: 40px; }
    .folder-actions { display: none !important; }
    .folder-chats .chat-item { margin: 1px 0 1px 8px; }
    .sidebar-scroll { scrollbar-width: none; }
    .sidebar-scroll::-webkit-scrollbar { display: none; }
    .folder-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        right: 8px;
        top: 50%;
        transform: translateY(-50%);
        width: 28px;
        height: 28px;
        font-size: 18px;
        color: var(--text-muted);
        border-radius: var(--radius);
        background: transparent;
        border: none;
        cursor: pointer;
        flex-shrink: 0;
        -webkit-tap-highlight-color: transparent;
    }
    .folder-menu-btn:hover,
    .folder-item.menu-open .folder-menu-btn {
        color: var(--text-primary);
        background: rgba(var(--overlay-rgb), 0.08);
    }
    .folder-item.menu-open .folder-menu {
        display: flex;
        flex-direction: column;
        position: absolute;
        right: 8px;
        top: 100%;
        z-index: 200;
        background: var(--bg-secondary);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow-md);
        min-width: 140px;
        padding: 4px;
    }
    .folder-menu button {
        padding: 8px 12px;
        text-align: left;
        font-size: 13px;
        color: var(--text-secondary);
        border-radius: var(--radius-sm);
        background: transparent;
        border: none;
        cursor: pointer;
    }
    .folder-menu button:hover { background: rgba(var(--overlay-rgb), 0.08); color: var(--text-primary); }
    .folder-menu button.danger { color: var(--danger); }
    .folder-menu button.danger:hover { background: var(--danger-subtle); }
}

/* === Custom tooltips === */
/* Migrates `title="..."` to `data-tooltip="..."` at runtime (see app.js) so the
   browser's slow native tooltip is suppressed and we render our own — fast,
   themed, consistent across OS/browsers. */
[data-tooltip] {
    position: relative;
}
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    background: var(--bg-elevated, var(--bg-secondary));
    color: var(--text-primary);
    padding: 5px 9px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.3;
    white-space: nowrap;
    pointer-events: none;
    z-index: 1000;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(2px);
    transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
}
[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    transition-delay: 0.18s;
}
/* Long tooltips: allow wrapping, cap width. */
[data-tooltip-long]::after {
    white-space: normal;
    max-width: 240px;
    text-align: center;
}

/* === Vision toggle === */

/* Inline-image vision-off marker (overlay on user-message thumbnails) */
.msg-image-vision-off {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    pointer-events: none;
}
.msg-image-vision-off svg { width: 14px; height: 14px; }

/* Custom-model editor: vision default row */
.cm-vision-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    flex-wrap: wrap;
}
.cm-vision-text { flex: 1 1 240px; min-width: 0; }
.cm-vision-text label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
}
.cm-vision-help {
    color: var(--text-muted);
    font-size: 13px;
    margin: 0;
    line-height: 1.4;
}
.cm-vision-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    width: auto;
    height: auto;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
}
.cm-vision-toggle:not(.active) {
    opacity: 0.55;
}
.cm-vision-toggle:not(.active):hover { opacity: 0.85; }

/* Toolbar vision toggle: dimmed when off, full color when on (the .active style is
   already provided by .toolbar-btn.active above; we only add the off state). */
#toolbar-vision-toggle:not(.active) {
    opacity: 0.45;
}
#toolbar-vision-toggle:not(.active):hover {
    opacity: 0.75;
}

/* === Queued upload boxes === */
/* Pre-rendered boxes that are waiting their turn behind an active upload. Visible
   so the user sees the whole batch up-front, but visibly inactive. */
.attach-box.queued {
    opacity: 0.45;
    filter: saturate(0.75);
}
.attach-box.queued::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        45deg,
        transparent 0,
        transparent 6px,
        rgba(var(--overlay-rgb, 0, 0, 0), 0.06) 6px,
        rgba(var(--overlay-rgb, 0, 0, 0), 0.06) 12px
    );
    border-radius: inherit;
    pointer-events: none;
    z-index: 1;
}

/* ======================================================================
   Admin-Mode sidebar: hide every chat-side surface so only the admin nav
   (+ brand header + user footer) remains. One source of truth — adding a
   new chat section is free; it inherits the hide.
   ====================================================================== */
.sidebar.admin-mode .sidebar-actions,
.sidebar.admin-mode .sidebar-search-wrap,
.sidebar.admin-mode .sidebar-body,
.sidebar.admin-mode .sidebar-folders-resize,
.sidebar.admin-mode .sidebar-takeover { display: none !important; }

/* ======================================================================
   Sidebar body wrapper + Takeover panels
   ----------------------------------------------------------------------
   `#sidebar-body` holds everything between the search box and the footer
   (pinned section, folders, chat list). When the user opens search or the
   settings panel, a `.sidebar-takeover` slides in via [hidden] toggling and
   the body's display is suppressed by a state class on the sidebar root.
   ====================================================================== */
.sidebar-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}
.sidebar.search-active .sidebar-body,
.sidebar.settings-active .sidebar-body { display: none; }
.sidebar.search-active .sidebar-folders-resize,
.sidebar.settings-active .sidebar-folders-resize { display: none; }
.sidebar.settings-active .sidebar-search-wrap { display: none; }
.sidebar.settings-active .sidebar-actions { display: none; }

.sidebar-takeover {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0;
    background: var(--bg-sidebar);
    animation: takeoverFadeIn 140ms ease-out;
}
.sidebar-takeover[hidden] { display: none !important; }
@keyframes takeoverFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
.sidebar-takeover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px 6px 14px;
    height: 40px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-subtle);
}
.sidebar-takeover-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
}
.sidebar-takeover-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
    color: var(--text-muted);
    transition: all var(--transition-fast);
}
.sidebar-takeover-close:hover { color: var(--text-primary); background: rgba(var(--overlay-rgb),0.07); }

/* Search-takeover-specific: results list fills remaining space, soft scrollbar. */
.sidebar-search-takeover .sidebar-search-results {
    margin-top: 0;
    max-height: none;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 6px 6px 12px;
    overscroll-behavior: contain;
}
.sidebar-search-takeover .sidebar-search-results::-webkit-scrollbar { width: 6px; }
.sidebar-search-takeover .sidebar-search-results::-webkit-scrollbar-track { background: transparent; }
.sidebar-search-takeover .sidebar-search-results::-webkit-scrollbar-thumb {
    background: rgba(var(--overlay-rgb),0.15);
    border-radius: 3px;
}
.sidebar-search-takeover .sidebar-search-results::-webkit-scrollbar-thumb:hover {
    background: rgba(var(--overlay-rgb),0.25);
}
.sidebar-search-takeover .search-result-item {
    padding: 10px 14px;
    border-radius: var(--radius);
    border-bottom: none;
    margin-bottom: 2px;
}
.sidebar-search-takeover .search-result-item:hover {
    background: rgba(var(--overlay-rgb),0.06);
}
.sidebar-search-takeover .search-result-title { font-size: 13px; }
.sidebar-search-takeover .search-result-snippet {
    white-space: normal;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
    line-height: 1.4;
    max-height: 2.8em;
}

/* ======================================================================
   Pinned chats section (top of sidebar body)
   ====================================================================== */
.sidebar-pinned {
    border-bottom: 1px solid var(--border-subtle);
    padding: 6px 0 8px;
    flex-shrink: 0;
    max-height: 28vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.sidebar-pinned::-webkit-scrollbar { width: 6px; }
.sidebar-pinned::-webkit-scrollbar-thumb {
    background: rgba(var(--overlay-rgb),0.12);
    border-radius: 3px;
}
.sidebar-section-label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 14px 6px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.sidebar-section-label svg { color: var(--purple); opacity: 0.8; }
.sidebar-pinned-list { padding: 0 0 2px; }
.sidebar-pinned-list .chat-item.pinned::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 14px;
    border-radius: 2px;
    background: var(--purple);
    opacity: 0.6;
}
.sidebar-pinned-list .chat-item { padding-left: 18px; }

/* Pin/unpin actions in normal chat-item action row */
.chat-item-pin {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 5px;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.chat-item-pin svg { width: 12px; height: 12px; }
.chat-item-pin:hover { color: var(--purple); background: rgba(var(--overlay-rgb),0.08); }
.chat-item-pin.pinned { color: var(--purple); }
.chat-item-pin.pinned:hover { color: var(--purple); background: color-mix(in srgb, var(--purple) 12%, transparent); }

/* ======================================================================
   Settings (user) takeover panel
   ====================================================================== */
.sidebar-settings-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    /* Outer breathing room so the card stack never touches the sidebar edges. */
    padding: 14px 12px 24px;
}
.sidebar-settings-body::-webkit-scrollbar { width: 6px; }
.sidebar-settings-body::-webkit-scrollbar-thumb {
    background: rgba(var(--overlay-rgb),0.15);
    border-radius: 3px;
}
/* Section card — subtle background + internal padding so labels never sit
   flush against the sidebar edge. Removes the "everything-glued-to-the-rail"
   feel of the previous flat layout. */
.settings-section {
    background: color-mix(in srgb, var(--bg-elevated) 50%, transparent);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 14px 14px 12px;
    margin-bottom: 10px;
}
.settings-section:last-child { margin-bottom: 0; }
.settings-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.settings-section-help {
    font-size: 11.5px;
    color: var(--text-muted);
    line-height: 1.4;
    margin: -4px 0 10px;
}
.settings-textarea {
    width: 100%;
    min-height: 90px;
    max-height: 240px;
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    resize: vertical;
    font-family: inherit;
    line-height: 1.45;
}
.settings-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
    outline: none;
}
.settings-pi-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 8px 0 12px;
}
.settings-inline-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}
.settings-inline-toggle-text {
    font-size: 12.5px;
    color: var(--text-secondary);
    font-weight: 500;
}
.settings-pi-counter {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.settings-section-cta {
    width: 100%;
    margin-top: 8px;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    border-radius: var(--radius);
    background: transparent;
    border: 1px solid transparent;
    transition: all var(--transition-fast);
    text-align: left;
}
.settings-row + .settings-row { margin-top: 2px; }
.settings-row:hover {
    background: rgba(var(--overlay-rgb),0.07);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}
.settings-row-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    flex-shrink: 0;
    color: var(--text-muted);
}
.settings-row-label { flex: 1; }
.settings-row-chevron { color: var(--text-muted); flex-shrink: 0; opacity: 0.6; }
.settings-row:hover .settings-row-chevron { opacity: 1; transform: translateX(2px); transition: transform var(--transition-fast); }
.settings-row-danger { color: var(--danger); }
.settings-row-danger:hover {
    background: var(--danger-subtle);
    color: var(--danger);
    border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}
.settings-row-danger .settings-row-icon { color: var(--danger); opacity: 0.9; }

/* Collapsible password section inside the profile block */
.settings-details {
    margin: 6px 0 4px;
    border-top: 1px dashed var(--border-subtle);
    padding-top: 8px;
}
.settings-details > summary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 2px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.settings-details > summary::-webkit-details-marker { display: none; }
.settings-details > summary::before {
    content: '▸';
    font-size: 9px;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
    display: inline-block;
}
.settings-details[open] > summary::before { transform: rotate(90deg); }
.settings-details > summary:hover { color: var(--text-primary); }
.settings-details > summary:hover::before { color: var(--text-primary); }

/* Tighter form-group inside settings panel */
.sidebar-settings-body .form-group-sm { margin-bottom: 8px; }
.sidebar-settings-body .form-group-sm label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 3px;
    font-weight: 500;
}
.sidebar-settings-body .form-group-sm input {
    width: 100%;
    padding: 7px 10px;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.sidebar-settings-body .form-group-sm input:disabled { opacity: 0.55; cursor: not-allowed; }
.sidebar-settings-body .form-group-sm input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
    outline: none;
}

/* Updated user-info-btn: cog hint + cleaner spacing */
.user-info-btn {
    /* override base — single flex row with cog at the end */
    gap: 10px;
}
.user-info-btn .user-info-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
    font-weight: 500;
}
.user-info-cog {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    color: var(--text-muted);
    opacity: 0.6;
    transition: opacity var(--transition-fast), color var(--transition-fast);
}
.user-info-btn:hover .user-info-cog { opacity: 1; color: var(--text-primary); }
.sidebar.collapsed .user-info-cog { display: none; }
.sidebar.collapsed .user-info-text { display: none; }

/* Mobile: cog visibility */
@media (max-width: 768px) {
    .user-info-cog { opacity: 0.85; }
}

/* ======================================================================
   Model Picker overlay (full chat-area panel with 4 columns)
   ====================================================================== */
.model-picker-overlay {
    position: absolute;
    top: 52px; /* matches .main-header height */
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    animation: modelPickerIn 140ms ease-out;
}
.model-picker-overlay[hidden] { display: none !important; }
@keyframes modelPickerIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
.model-picker-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    background: var(--bg-primary);
}
.model-picker-search-wrap {
    position: relative;
    flex: 1;
    max-width: 480px;
}
.model-picker-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}
.model-picker-search {
    width: 100%;
    padding: 9px 12px 9px 32px;
    font-size: 13px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
}
.model-picker-search:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-subtle); outline: none; }
.model-picker-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    color: var(--text-muted);
    transition: all var(--transition-fast);
    margin-left: auto;
}
.model-picker-close:hover { color: var(--text-primary); background: rgba(var(--overlay-rgb),0.07); }
.model-picker-columns {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1px;
    background: var(--border-subtle);
    overflow: hidden;
    min-height: 0;
}
.model-picker-column {
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}
.model-picker-column-header {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 14px 16px 10px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
    flex-shrink: 0;
}
.model-picker-column[data-column="favorites"] .model-picker-column-header svg { color: var(--purple); opacity: 0.85; }
.model-picker-list {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px 6px 14px;
}
.model-picker-list::-webkit-scrollbar { width: 6px; }
.model-picker-list::-webkit-scrollbar-thumb {
    background: rgba(var(--overlay-rgb),0.15);
    border-radius: 3px;
}
.model-picker-list::-webkit-scrollbar-thumb:hover { background: rgba(var(--overlay-rgb),0.25); }
.model-picker-empty {
    padding: 18px 14px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12.5px;
    line-height: 1.45;
}
.model-picker-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    font-size: 13px;
    color: var(--text-primary);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition-fast);
}
.model-picker-item:hover { background: rgba(var(--overlay-rgb),0.06); }
.model-picker-item.in-use {
    background: var(--accent-subtle);
    color: var(--text-primary);
}
.model-picker-item-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.model-picker-item-sub {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
    margin-top: 1px;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.model-picker-item-actions {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}
.model-picker-item-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: all var(--transition-fast);
}
.model-picker-item-actions button svg { width: 13px; height: 13px; }
.model-picker-item-actions button:hover { color: var(--text-primary); background: rgba(var(--overlay-rgb),0.08); }
.model-picker-item-actions .model-picker-info:hover { color: var(--accent); }
.model-picker-item-actions .model-picker-fav.is-fav { color: var(--purple); opacity: 1; }
.model-picker-item-actions .model-picker-fav { opacity: 0.4; }
.model-picker-item:hover .model-picker-item-actions .model-picker-fav { opacity: 0.75; }
.model-picker-item-actions .model-picker-delete:hover { color: var(--danger); background: var(--danger-subtle); }
.model-picker-item-actions .model-picker-default {
    opacity: 0.4;
    color: var(--text-muted);
}
.model-picker-item:hover .model-picker-item-actions .model-picker-default { opacity: 0.75; }
.model-picker-item-actions .model-picker-default.is-default {
    color: var(--accent);
    opacity: 1;
}
.model-picker-item-actions .model-picker-default:hover { color: var(--accent); background: var(--accent-subtle); }
/* Default model is visualised by the filled house icon alone — no text pill,
   otherwise the row reads "name STANDARD <icons>" which feels noisy. */

/* Mobile model picker: stack columns, allow vertical scroll */
@media (max-width: 768px) {
    .model-picker-overlay { top: 48px; }
    .model-picker-header { padding: 10px 12px; flex-wrap: wrap; }
    .model-picker-columns {
        grid-template-columns: 1fr;
        grid-auto-rows: min-content;
        overflow-y: auto;
        gap: 0;
    }
    .model-picker-column { border-bottom: 1px solid var(--border-subtle); }
    .model-picker-column:last-child { border-bottom: none; }
    .model-picker-list { max-height: none; padding: 4px 8px 8px; }
}

/* ======================================================================
   Global hover-info popover (used by model picker info icon)
   ----------------------------------------------------------------------
   Single instance lives at root of <main>; JS positions it via inline
   left/top so it can never be clipped by overflow:hidden parents.
   ====================================================================== */
.hover-info-popover {
    position: fixed;
    z-index: 9999;
    max-width: 320px;
    padding: 10px 12px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: 12.5px;
    line-height: 1.45;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    pointer-events: none;
    white-space: pre-wrap;
    word-break: break-word;
}
.hover-info-popover[hidden] { display: none !important; }

/* ======================================================================
   Admin: Info button in models table
   ====================================================================== */
.admin-info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
    color: var(--text-muted);
    transition: all var(--transition-fast);
}
.admin-info-btn:hover { color: var(--accent); background: var(--accent-subtle); }
.admin-info-btn.has-info { color: var(--accent); }
.admin-info-btn svg { width: 14px; height: 14px; }
#modelinfo-textarea { min-height: 140px; max-height: 360px; }
#modelinfo-counter { margin-top: 6px; text-align: right; }

/* ======================================================================
   Mobile: search/settings takeover should fill the whole sidebar
   ====================================================================== */
@media (max-width: 768px) {
    .sidebar-takeover-header { height: 44px; padding: 6px 8px 6px 14px; }
    .sidebar-settings-body { padding: 12px 10px 24px; }
    .settings-section { padding: 12px 12px 10px; margin-bottom: 8px; }
    .sidebar-pinned { max-height: 24vh; }
}
