/*
 * z-index scale:
 *   99  — sidebar overlay (backdrop)
 *  100  — sidebar, admin-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: #888;
    --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;
}

[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: #757575;
    --accent: #4a7aff;
    --accent-hover: #3a6aef;
    --accent-subtle: rgba(74,122,255,0.1);
    --accent-glow: rgba(74,122,255,0.12);
    --border: #e0e0e0;
    --border-subtle: rgba(0,0,0,0.06);
    --danger: #e04040;
    --danger-hover: #d03030;
    --danger-subtle: rgba(224,64,64,0.1);
    --success: #22c55e;
    --success-hover: #1aab50;
    --success-subtle: rgba(34,197,94,0.1);
    --warning: #e5a600;
    --warning-subtle: rgba(229,166,0,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;
}

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); }

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 {
    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::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: 4px; }
::-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, #7c9eff 0%, #a78bfa 50%, #c084fc 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: 4px;
    padding: 1px 6px;
    margin-left: 6px;
    vertical-align: baseline;
}
.brand-sm .brand-anox { font-size: 1.3em; }
.brand-sm .brand-chat { font-size: 0.75em; }
.brand-sm .brand-pro { font-size: 0.6em; padding: 1px 5px; margin-left: 5px; }

.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: #fff; }
.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.4; cursor: not-allowed; box-shadow: none; }
.btn-danger { background: var(--danger); color: #fff; }
.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); }

.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 rgba(240,96,96,0.2); }
.alert.success { display: block; background: var(--success-subtle); color: var(--success); border: 1px solid rgba(74,222,128,0.2); }

/* === 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;
}
.sidebar-resize-handle,
.admin-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,
.admin-sidebar-resize-handle:hover { background: rgba(var(--overlay-rgb),0.08); }
.sidebar-resize-handle.active,
.admin-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 .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-info-btn .user-menu-chevron { display: none; }
.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: 3px;
    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-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: rgba(124,158,255,0.25); color: var(--text-primary); border-radius: 2px; padding: 0 1px; }
.search-no-results { padding: 12px; text-align: center; font-size: 12px; color: var(--text-muted); }

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    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-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.pinned .chat-item-actions { visibility: visible; }
.chat-item.pinned .chat-item-actions .pin-btn { display: flex; }
.chat-item.pinned .chat-item-actions button[data-action="delete"] { visibility: hidden; }
.chat-item.pinned:hover .chat-item-actions button[data-action="delete"] { visibility: visible; }
.chat-item-actions button { padding: 4px 8px; font-size: 12px; color: var(--text-muted); border-radius: 4px; 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); }
.chat-item-actions .pin-btn { color: var(--text-muted); }
.chat-item-actions .pin-btn:hover { color: var(--accent); background: var(--accent-subtle); }
.chat-item-actions .pin-btn.pinned { color: var(--accent); opacity: 0.7; }
.chat-item-actions .pin-btn.pinned:hover { opacity: 1; background: var(--accent-subtle); }

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

@media (max-width: 768px) {
    .chat-item { position: relative; }
    .chat-item-actions { display: none !important; }
    .chat-item-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        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, 0 4px 12px rgba(0,0,0,0.15));
        min-width: 140px;
        padding: 4px;
    }
    .chat-item-menu button {
        padding: 8px 12px;
        font-size: 13px;
        color: var(--text-secondary);
        text-align: left;
        border-radius: 4px;
        -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.5s ease-in-out infinite;
}

.sidebar-footer {
    padding: 6px 8px;
}
.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-menu-chevron { margin-left: auto; color: var(--text-muted); flex-shrink: 0; }
.user-avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    color: #fff;
    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: 6px;
    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; }

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

.hamburger, .admin-hamburger { display: none; padding: 8px; font-size: 18px; color: var(--text-secondary); }
.hamburger:hover, .admin-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: 3px; }
.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;
    padding: 9px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition-fast);
}
.model-dropdown-item:hover { background: rgba(var(--overlay-rgb),0.05); color: var(--text-primary); }
.model-dropdown-item-name { flex: 1; 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 {
    display: none;
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    gap: 2px;
}
.model-dropdown-item:hover .model-dropdown-item-actions { display: flex; }
.model-dropdown-item-actions button {
    padding: 2px 5px;
    font-size: 12px;
    color: var(--text-muted);
    border-radius: 4px;
}
.model-dropdown-item-actions button:hover { color: var(--text-primary); background: rgba(var(--overlay-rgb),0.08); }
.model-dropdown-item-actions button:last-child:hover { color: var(--danger); background: var(--danger-subtle); }
.model-dropdown-empty { padding: 16px; text-align: center; font-size: 13px; color: var(--text-muted); }
.model-dropdown-add { color: var(--text-muted); gap: 8px; }
.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: 999px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    transition: border-color .15s, background .15s;
}

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

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

.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 .15s, color .15s;
    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 .2s ease-out, border-radius .2s ease-out, padding .2s ease-out, border-color .2s ease-out, background .2s ease-out;
}

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

.model-add-btn.expanding {
    width: 170px;
    border-radius: 999px;
    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 .15s;
}

.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 .2s ease-out, opacity .15s ease-out .05s, margin .2s ease-out;
    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;
}


.message-column .streaming-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: pulse 1s 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: 13.5px;
    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);
}

/* --- 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: rgba(124,158,255,0.3);
    color: var(--text-primary);
    border-radius: 3px;
    padding: 1px 2px;
    animation: searchFade 3s ease-out;
}
@keyframes searchFade {
    0%, 60% { background: rgba(124,158,255,0.35); }
    100% { background: rgba(124,158,255,0.1); }
}

.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;
}

.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: 6px;
    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: 6px;
    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: 5px;
    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: #0d1117;
    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: 4px; 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 0.2s ease;
    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;
    padding: 7px 12px;
    margin: 2px 0;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    border-radius: var(--radius);
}
.followup-item:hover { color: var(--accent); background: var(--accent-subtle); }

/* --- 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); } }

/* --- 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: #fff;
    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.4; 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.3;
    cursor: not-allowed;
}
.toolbar-btn.active {
    color: var(--accent);
    background: var(--accent-subtle);
}
.toolbar-btn.active:hover {
    background: rgba(124,158,255,0.18);
}

/* --- 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: #fff;
}
.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 0.15s;
}
.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: #fff;
}
.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;
}

/* --- 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-full {
    max-width: 900px;
    max-height: calc(100vh - 40px);
    width: 100%;
    height: 100%;
}
.modal.modal-full .modal-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.modal.modal-full .cm-col textarea { min-height: 300px; }
.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-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-alert {
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    display: none;
}
.modal-alert.error { display: block; background: var(--danger-subtle); color: var(--danger); }
.modal-alert.success { display: block; background: var(--success-subtle); color: var(--success); }

/* --- Custom Model Layout --- */
.cm-top-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cm-columns { display: flex; flex-direction: column; gap: 16px; }
.cm-col { display: flex; flex-direction: column; }
.cm-col textarea { min-height: 160px; resize: vertical; }
.label-optional { font-weight: 400; color: var(--text-muted); font-size: 11px; }
.cm-files-hint { font-size: 12px; color: var(--text-muted); padding: 6px 0; display: none; }
.cm-files-hint.active { display: block; }

/* 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 0.15s;
    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); }
    .modal.modal-full { max-width: 100vw; max-height: 100vh; margin: 0; border-radius: 0; }
    .cm-top-row { grid-template-columns: 1fr; }
}

/* --- File Upload Area --- */
.file-upload-area {
    border: 2px dashed rgba(var(--overlay-rgb),0.1);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-base);
}
.file-upload-area:hover, .file-upload-area.dragover {
    border-color: var(--accent);
    background: var(--accent-subtle);
    color: var(--text-secondary);
}
.file-upload-area input[type="file"] { display: none; }

.file-upload-status {
    font-size: 12px;
    color: var(--text-muted);
    padding: 6px 0;
    display: none;
}
.file-upload-status.active { display: block; color: var(--accent); }

.file-list { display: flex; flex-direction: column; gap: 4px; }
.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-input);
    border-radius: var(--radius);
    font-size: 13px;
    border: 1px solid var(--border-subtle);
}
.file-item-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.file-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item-chunks { color: var(--text-muted); font-size: 11px; white-space: nowrap; }
.file-item button { color: var(--text-muted); padding: 2px 6px; font-size: 14px; border-radius: 4px; }
.file-item button:hover { color: var(--danger); background: var(--danger-subtle); }

/* === Admin Layout === */
.admin-layout { display: flex; height: 100vh; overflow: hidden; }
.admin-layout input,
.admin-layout textarea,
.admin-layout select { scrollbar-width: none; }
.admin-layout input::-webkit-scrollbar,
.admin-layout textarea::-webkit-scrollbar,
.admin-layout select::-webkit-scrollbar { display: none; }
.admin-layout input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.admin-layout input[type="number"]::-webkit-outer-spin-button,
.admin-layout input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.admin-sidebar {
    position: relative;
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: none;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.admin-sidebar-header {
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 52px;
}
.admin-sidebar-header-row { display: flex; align-items: center; justify-content: space-between; width: 100%; }
.admin-sidebar-header h2 { font-size: 16px; font-weight: 700; letter-spacing: -0.2px; line-height: 1.2; }
.admin-sidebar-header p { font-size: 11px; color: var(--text-muted); margin-top: 1px; line-height: 1.2; }
.admin-nav { flex: 1; padding: 8px; overflow-y: auto; }
.admin-nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-radius: var(--radius);
    font-size: 13px; color: var(--text-secondary);
    cursor: pointer; transition: all var(--transition-fast);
    margin-bottom: 2px;
    font-weight: 500;
    position: relative;
}
.admin-nav-item:hover { background: rgba(var(--overlay-rgb),0.05); color: var(--text-primary); }
.admin-nav-item.active {
    background: var(--accent-subtle);
    color: var(--accent);
    font-weight: 600;
}
.admin-nav-item.active .admin-nav-icon svg { stroke-width: 2.5; }
.admin-nav-icon { width: 20px; text-align: center; display: flex; align-items: center; justify-content: center; }
.admin-nav-icon svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.admin-sidebar-footer { padding: 14px 20px; }
.admin-sidebar-footer a {
    font-size: 13px; color: var(--text-secondary);
    text-decoration: none; display: flex; align-items: center; gap: 8px;
    transition: all var(--transition-fast);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-weight: 500;
}
.admin-sidebar-footer a:hover { color: var(--text-primary); background: rgba(var(--overlay-rgb),0.05); }

/* --- Admin Sidebar Collapsed --- */
.admin-sidebar.collapsed {
    width: 56px;
    min-width: 56px;
    transition: width var(--transition-slow), min-width var(--transition-slow);
}
.admin-sidebar.collapsed .admin-sidebar-resize-handle { display: none; }
.admin-sidebar.collapsed .admin-sidebar-header-row > div:first-child { display: none; }
.admin-sidebar.collapsed .admin-sidebar-header-row { justify-content: center; }
.admin-sidebar.collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }
.admin-sidebar.collapsed .admin-sidebar-header { padding: 0 8px; }
.admin-sidebar.collapsed .admin-nav-item { justify-content: center; padding: 10px; gap: 0; overflow: hidden; color: transparent; font-size: 0; }
.admin-sidebar.collapsed .admin-nav-icon { color: var(--text-secondary); }
.admin-sidebar.collapsed .admin-nav-item.active .admin-nav-icon { color: var(--accent); }
.admin-sidebar.collapsed .admin-sidebar-footer a { justify-content: center; font-size: 0; color: transparent; }
.admin-sidebar.collapsed .admin-sidebar-footer a svg { color: var(--text-secondary); }

.admin-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.admin-header {
    padding: 0 28px;
    flex-shrink: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    height: 52px;
}
.admin-header h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.2px; }
.admin-content { flex: 1; overflow-y: auto; padding: 28px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* --- 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); }

.stats-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.period-toggle {
    display: inline-flex;
    gap: 0;
    margin-bottom: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 3px;
}
.period-btn {
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    color: var(--text-muted);
    transition: all var(--transition-fast);
}
.period-btn:hover { color: var(--text-secondary); }
.period-btn.active { color: var(--text-primary); background: var(--bg-hover); }

.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: 3px; overflow: hidden; }
.ranking-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #a78bfa); border-radius: 3px; 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: 20px;
    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 { 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.danger { color: var(--danger); }
.action-btn.danger:hover { background: var(--danger-subtle); border-color: rgba(240,96,96,0.2); }
.action-btn.success { color: var(--success); }
.action-btn.success:hover { background: var(--success-subtle); border-color: rgba(74,222,128,0.2); }

/* --- 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: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px;
}
.settings-grid select, .settings-grid input { width: 100%; }
.settings-grid .toggle { margin-top: 4px; }
.settings-save-row { margin-top: 12px; }

.conn-form { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.conn-form .form-group { max-width: 500px; }
.input-with-icon { position: relative; }
.input-with-icon input { width: 100%; padding-right: 40px; }
.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-icon-btn:hover { color: var(--text-primary); }
.conn-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.conn-sync-status {
    padding: 8px 20px;
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.conn-sync-status .sync-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.conn-sync-status .sync-dot.online { background: var(--success); }
.conn-sync-status .sync-dot.offline { background: var(--danger); }

/* --- Toggle --- */
.toggle { position: relative; display: inline-block; width: 36px; height: 20px; cursor: pointer; }
.toggle input { display: none; }
.toggle-slider {
    position: absolute; inset: 0;
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: 10px;
    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:checked + .toggle-slider { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); background: #fff; }
.toggle-header { vertical-align: middle; margin-right: 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: 1px;
    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;
    justify-content: flex-end;
    margin-bottom: 12px;
}
.log-empty { color: var(--text-muted); font-size: 13px; padding: 20px 0; text-align: center; }
.pagination { display: flex; gap: 6px; margin-top: 16px; justify-content: center; }
.log-timestamp { white-space: nowrap; color: var(--text-muted); }
.log-level { display: inline-block; padding: 3px 10px; border-radius: 20px; 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-details-hint {
    font-size: 10px;
    color: var(--accent);
    opacity: 0.6;
    margin-left: 6px;
    vertical-align: middle;
}
.log-row-clickable:hover .log-details-hint { opacity: 1; }

.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);
}
.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);
}
.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; }
.log-detail-close {
    font-size: 22px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    border-radius: 4px;
    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;
}
.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: rgba(74,222,128,0.2);
}
.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; }
.admin-alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin: 16px 0 0; display: none; }
.admin-alert + .admin-card { margin-top: 16px; }
.admin-alert.success { display: block; background: var(--success-subtle); color: var(--success); border: 1px solid rgba(74,222,128,0.15); }
.admin-alert.error { display: block; background: var(--danger-subtle); color: var(--danger); border: 1px solid rgba(240,96,96,0.15); }
.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: none;
    border-radius: 4px;
    outline: none;
    caret-color: var(--accent);
}
.inline-edit-input:focus { box-shadow: none; }
.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 !important; border-color: var(--accent) !important; box-shadow: 0 0 0 2px var(--accent-subtle) !important; }
.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-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-select { min-width: 120px; }
    .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;
    }
    .admin-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        height: 100dvh;
        transform: translateX(-100%);
        z-index: 100;
        width: var(--sidebar-width);
        transition: transform var(--transition-slow);
    }
    .admin-sidebar.open { transform: translateX(0); }
    .admin-sidebar.collapsed { width: var(--sidebar-width); min-width: unset; }
    .admin-sidebar.collapsed .admin-sidebar-header-row > div:first-child { display: block; }
    .admin-sidebar.collapsed .admin-sidebar-header-row { justify-content: space-between; }
    .admin-sidebar.collapsed .admin-nav-item { font-size: 13px; color: var(--text-secondary); justify-content: flex-start; padding: 10px 14px; gap: 10px; }
    .admin-sidebar.collapsed .admin-nav-item.active { color: var(--accent); }
    .admin-sidebar.collapsed .admin-sidebar-footer a { font-size: 13px; color: var(--text-secondary); justify-content: flex-start; }
    .admin-sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99; }
    .admin-sidebar-overlay.open { display: block; }
    .admin-hamburger { display: block; }
    .sidebar-collapse-btn { display: none; }
    .admin-content { padding: 20px; }
    .settings-grid { grid-template-columns: 1fr; }

    .users-toolbar { flex-wrap: wrap; }
    .users-search-box { flex-basis: 100%; min-width: 0; }
    .action-btns { flex-wrap: wrap; }
    .action-btns .action-btn { flex: 1 1 100%; text-align: center; }
    .admin-header { padding: 14px 20px; }
    .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; }
    .message-row {
        flex-direction: column;
    }
    .message-row .message-column {
        min-width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .message-row .message-column:last-child {
        border-bottom: none;
    }
    .speed-badge { cursor: pointer; -webkit-tap-highlight-color: transparent; }
    .speed-detail.open { cursor: pointer; -webkit-tap-highlight-color: transparent; }
}

/* === Chat Images === */
.message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0;
    justify-content: flex-end;
}
.chat-image {
    max-width: 320px;
    max-height: 240px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    object-fit: contain;
    background: var(--bg-secondary);
}
.chat-image:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-md);
}

/* 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);
}

/* 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);
}
.image-preview-full {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

/* Image paste preview in input area */
.image-preview-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 52px 6px;
    justify-content: center;
}

/* === Admin: User Search & Bulk === */
.users-toolbar {
    display: flex;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 12px;
}
.users-search-box {
    flex: 1;
    min-width: 200px;
}
.users-search-box input {
    width: 100%;
    height: 100%;
    padding: 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-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: #fff;
    border: none;
}
.btn-success:hover {
    background: var(--success-hover);
    box-shadow: 0 2px 8px var(--success-subtle);
}
.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);
}

/* 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: 6px;
    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: 4px;
    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 white;
    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:hover .cb-box {
    border-color: var(--accent);
}
.th-cb, .td-cb {
    width: 40px;
    text-align: center;
}
tr.row-selected {
    background: var(--accent-subtle) !important;
}

/* === Admin: Chat Viewer === */
.admin-chat-messages {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 70vh;
    overflow-y: auto;
}
.admin-msg {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    max-width: 85%;
}
.admin-msg-user {
    background: var(--accent-subtle);
    align-self: flex-end;
    border: 1px solid rgba(124,158,255,0.15);
}
.admin-msg-assistant {
    background: var(--bg-elevated);
    align-self: flex-start;
    border: 1px solid var(--border);
}
.admin-msg-sender {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.admin-msg-time {
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 8px;
}
.admin-msg-content {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
}
.admin-msg-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}
.admin-chat-image {
    max-width: 200px;
    max-height: 150px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    object-fit: contain;
    background: var(--bg-secondary);
}

/* === 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 rgba(74,222,128,0.2);
}
.toast-error {
    background: var(--danger-subtle);
    color: var(--danger);
    border: 1px solid rgba(240,96,96,0.2);
}
.toast-info {
    background: var(--accent-subtle);
    color: var(--accent);
    border: 1px solid rgba(124,158,255,0.2);
}
@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 --- */
.stats-grid-gap { margin-bottom: 12px; }
.admin-card-header-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-md); }
.user-email-cell { color: var(--text-muted); font-size: 12px; }
.admin-empty-state { padding: 20px; color: var(--text-muted); }
.model-dropdown-divider { height: 1px; background: var(--border); margin: 4px 10px; }

/* === Organizations === */

.org-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
}

.org-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition-fast);
    user-select: none;
}

.org-chip:hover {
    border-color: var(--accent);
    background: rgba(var(--overlay-rgb), 0.04);
}

.org-chip.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.org-chip-count {
    background: rgba(var(--overlay-rgb), 0.08);
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}

.org-chip.active .org-chip-count {
    background: rgba(255,255,255,0.2);
}

/* Org popover */
.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);
    width: 260px;
    max-height: 400px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.org-popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}
.org-popover-title {
    font-weight: 600;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.org-popover-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.org-popover-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 4px 6px;
    border-radius: 4px;
    color: var(--text-muted);
    transition: background var(--transition-fast), color var(--transition-fast);
}
.org-popover-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.org-popover-btn-danger:hover {
    background: rgba(var(--danger-rgb, 239, 68, 68), 0.1);
    color: var(--danger);
}
.org-popover-search {
    margin: 8px 10px 4px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 12px;
    outline: none;
}
.org-popover-search:focus {
    border-color: var(--accent);
}
.org-popover-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 6px;
    display: flex;
    flex-direction: column;
}
.org-popover-item.cb {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
}
.org-popover-item.cb:hover {
    background: rgba(var(--overlay-rgb), 0.06);
}
.org-popover-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.org-popover-footer {
    padding: 6px 10px 10px;
    border-top: 1px solid var(--border);
}
.org-popover-filter-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--accent);
    font-size: 12px;
    padding: 4px 0;
    width: 100%;
    text-align: left;
}
.org-popover-filter-btn:hover {
    text-decoration: underline;
}

.org-delete-options {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

.org-delete-options .btn {
    width: 100%;
    text-align: left;
}

.org-delete-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0 0 var(--space-sm) 0;
    line-height: 1.5;
}

.org-delete-hint.danger {
    color: var(--danger);
}

/* Org tags in user table */
td.org-cell { white-space: normal; display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.org-tag {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--accent-subtle);
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    position: relative;
}
.org-tag-x {
    display: none;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    margin-left: 2px;
    opacity: 0.6;
}
.org-tag-x:hover { opacity: 1; }
.org-tag:hover .org-tag-x { display: inline; }
.org-tag:hover { padding-right: 4px; }
.org-add-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    border: 1px dashed var(--border);
    background: none;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}
.org-add-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle);
}
.org-tag-empty {
    color: var(--text-muted);
    font-size: 12px;
}

.org-context-menu {
    position: fixed;
    z-index: 9999;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 200px;
    padding: var(--space-xs);
}

.org-ctx-item {
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    border-radius: 6px;
    font-size: 13px;
}

.org-ctx-item:hover {
    background: var(--bg-secondary);
}

.org-ctx-item.danger {
    color: var(--danger);
}

.org-select {
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}
.org-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}

.cm-share-section {
    margin-top: 16px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.cm-section-title {
    font-weight: 600;
    margin-bottom: var(--space-sm);
    font-size: 13px;
}

.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: 320px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 2px 12px;
    align-content: start;
}
.modal.modal-full .cm-share-list { max-height: none; flex: 1; overflow-y: auto; }


.share-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 4px;
}

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

.share-toggle-row {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
    margin-bottom: 4px;
}
.share-toggle-row .share-item-all {
    border-bottom: none;
    padding-bottom: 4px;
    white-space: nowrap;
}
.share-item-all {
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
    margin-bottom: 4px;
    grid-column: 1 / -1;
}

.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; }
.model-share-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
    line-height: 1.4;
}

/* === 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: 10px;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.15s;
}
.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;
}
.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;
}

/* Remove button on staging boxes */
.attach-box-remove {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0,0,0,0.55);
    border: none;
    color: #fff;
    font-size: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    line-height: 1;
    padding: 0;
    z-index: 15;
}
.attach-box:hover .attach-box-remove {
    opacity: 1;
}
.attach-box-remove:hover {
    background: var(--danger);
}
.attach-box.error .attach-box-remove {
    opacity: 1;
}

/* Cancel button on uploading boxes */
.attach-box-cancel {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0,0,0,0.7);
    border: none;
    color: #fff;
    font-size: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    z-index: 15;
    opacity: 0.85;
    transition: opacity 0.15s, background 0.15s;
}
.attach-box-cancel:hover {
    opacity: 1;
    background: var(--danger);
}

/* Uploading state */
.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;
}
.attach-box.uploading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 22px;
    height: 22px;
    margin: -11px 0 0 -11px;
    border: 2.5px solid rgba(255,255,255,0.25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    z-index: 11;
}
.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: #4ade80;
    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: 80vh;
    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-image {
    border-bottom: 1px solid var(--border);
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    max-height: 45vh;
    overflow: hidden;
}
.doc-preview-image img {
    width: 100%;
    max-height: 45vh;
    object-fit: contain;
    display: block;
}
.doc-preview-text {
    padding: 18px;
    margin: 0;
    overflow-y: auto;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
}

.attach-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 6px;
    box-shadow: var(--shadow-lg);
    z-index: 100;
    display: flex;
    gap: 2px;
}
.attach-menu-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 20px;
    color: var(--text-primary);
    font-size: 11px;
    font-weight: 500;
    border-radius: 10px;
    text-align: center;
    transition: background .15s;
}
.attach-menu-item svg {
    opacity: .85;
}
.attach-menu-item:active {
    background: var(--bg-secondary);
}
