/*
 * Global z-index scale (see :root tokens below). Use the token, not the literal.
 * Values 1/2/10/11/15/50 inside the file are LOCAL to a parent stacking context
 * (sticky toolbars, image-tile overlays, drag handles, drop zones) and stay numeric.
 *
 *   --z-sidebar-overlay   99
 *   --z-sidebar          100
 *   --z-sidebar-handle   101
 *   --z-popover          150  (dropdown panels, user menu)
 *   --z-modal            200
 *   --z-sheet            300  (bottom sheet)
 *   --z-view-overlay      80  (full-area replacement views, e.g. admin panels)
 *   --z-log-detail      1000
 *   --z-floating-menu   9999  (tooltip popover)
 *   --z-overlay        10000  (image / document preview, HTML-app preview)
 *   --z-overlay-front  10001  (close buttons on top of overlays)
 */

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

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

html,
body {
    /* Dark-only app: this makes the native controls the browser paints itself
       (checkboxes, select popups, scrollbars, autofill) use their dark variant
       instead of the white default. */
    color-scheme: dark;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-hover);
}

a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

button {
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    border: none;
    outline: none;
    background: none;
    color: inherit;
    transition: all var(--transition-fast);
}

button:focus-visible,
[role="button"]:focus-visible,
[role="option"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius);
}

input,
textarea,
select {
    font-family: inherit;
    font-size: inherit;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    outline: none;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}

input:disabled,
textarea:disabled,
select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

/* Scrollbar (cross-browser) */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(var(--overlay-rgb), 0.1);
    border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(var(--overlay-rgb), 0.18);
}

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

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

/* === Brand === */
.brand {
    display: inline-flex;
    align-items: baseline;
    font-size: 1.35em;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--purple) 50%, var(--purple-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-card h1.brand {
    justify-content: center;
}

.login-card h1 {
    text-align: center;
    margin-bottom: 6px;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 32px;
    font-size: 13px;
}

.login-tabs {
    display: flex;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

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

.login-tabs button:hover {
    color: var(--text-secondary);
}

.login-tabs button.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

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

.login-form.hidden {
    display: none;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

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

.btn {
    padding: 10px 20px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 13px;
    transition: all var(--transition-fast);
    letter-spacing: 0.2px;
}

.btn-primary {
    background: var(--accent);
    color: var(--on-accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-danger {
    background: var(--danger);
    color: var(--on-color);
}

.btn-danger:hover {
    background: var(--danger-hover);
    box-shadow: 0 2px 8px var(--danger-subtle);
}

.btn-danger:active {
    transform: scale(0.97);
}

.btn-ghost {
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius);
}

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

.btn-ghost:active {
    transform: scale(0.97);
}

.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    display: none;
}

.alert.error {
    display: block;
    background: var(--danger-subtle);
    color: var(--danger);
    border: 1px solid color-mix(in srgb, var(--danger) 20%, transparent);
}

.alert.success {
    display: block;
    background: var(--success-subtle);
    color: var(--success);
    border: 1px solid color-mix(in srgb, var(--success) 20%, transparent);
}

/* === 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: var(--z-sidebar);
    position: relative;
    overflow: hidden;
}

.sidebar-resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 4px;
    cursor: col-resize;
    background: transparent;
    z-index: var(--z-sidebar-handle);
    transition: background var(--transition-base);
    touch-action: none;
}

.sidebar-resize-handle:hover {
    background: rgba(var(--overlay-rgb), 0.08);
}

.sidebar-resize-handle.active {
    background: var(--accent);
}

/* --- Sidebar Collapse Toggle --- */
.sidebar-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
    color: var(--text-muted);
    flex-shrink: 0;
    margin-left: auto;
}

.sidebar-collapse-btn:hover {
    color: var(--text-primary);
    background: rgba(var(--overlay-rgb), 0.07);
}

.sidebar-collapse-btn svg {
    transition: transform var(--transition-base);
}

/* --- Sidebar Collapsed State (Desktop) --- */
.sidebar.collapsed {
    width: 56px;
    min-width: 56px;
    max-width: 56px;
    transition: width var(--transition-slow), min-width var(--transition-slow), max-width var(--transition-slow);
}

.sidebar.collapsed .sidebar-resize-handle {
    display: none;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 0 8px;
}

.sidebar.collapsed .sidebar-header .brand {
    display: none;
}

.sidebar.collapsed #impersonation-banner {
    padding: 0 4px 8px;
}

.sidebar.collapsed #impersonation-banner button {
    font-size: 0;
    padding: 5px;
}

.sidebar.collapsed #impersonation-banner button::before {
    content: '\2190';
    font-size: 14px;
}

.sidebar.collapsed .sidebar-collapse-btn svg {
    transform: rotate(180deg);
}

.sidebar.collapsed .sidebar-actions {
    padding: 8px 4px 0;
    justify-content: center;
}

.sidebar.collapsed .sidebar-action-btn {
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    flex: 0 0 auto;
}

.sidebar.collapsed .sidebar-action-btn span {
    display: none;
}

.sidebar.collapsed .sidebar-search-wrap {
    display: none;
}

/* Hide the entire rich scroll body (pinned section + chat list) when collapsed.
   This is what removes the leaked "Angepinnt" label and the residual
   scrollbars — the icon rail stands in for it. */
.sidebar.collapsed .sidebar-body {
    display: none;
}

.sidebar.collapsed .sidebar-footer {
    padding: 6px 4px;
    margin-top: auto;
}

.sidebar.collapsed .user-info-btn {
    justify-content: center;
    padding: 8px;
}

.sidebar.collapsed .user-info-btn #user-name {
    left: 56px;
    bottom: 0;
    right: auto;
    min-width: 200px;
}

/* --- Collapsed icon rail (clean stand-in for the rich sidebar body) --- */
.sidebar-rail {
    display: none;
}

.sidebar.collapsed:not(.admin-mode) .sidebar-rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px 4px 0;
}

.sidebar-rail-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    color: var(--text-muted);
    transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar-rail-btn:hover {
    color: var(--text-primary);
    background: rgba(var(--overlay-rgb), 0.07);
}

.sidebar-rail-btn:active {
    transform: scale(0.95);
}

.sidebar-header .brand {
    gap: 0;
}

.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-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);
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    min-width: 24px;
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-search-clear:hover {
    color: var(--text-primary);
}

.sidebar-search-results {
    margin-top: 4px;
    max-height: 280px;
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.search-result-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-subtle);
    transition: background var(--transition-fast);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: rgba(var(--overlay-rgb), 0.04);
}

.search-result-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-result-snippet {
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-result-snippet mark {
    background: var(--accent-glow);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 0 1px;
}

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

.chat-list-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

/* Shared empty-state presentation (chat list, search results, …) */
.empty-icon {
    color: var(--text-muted);
    opacity: 0.55;
    margin-bottom: 2px;
}

.empty-title {
    color: var(--text-secondary);
    font-weight: 600;
}

.empty-hint {
    color: var(--text-muted);
    font-size: 12px;
}

/* Chat-list loading skeleton — shown until the first /api/chats response. */
.chat-list-skeleton {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px 10px;
}

.chat-list-skeleton .skeleton-row {
    height: 30px;
    border-radius: var(--radius);
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-hover) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
}

.chat-list-skeleton .skeleton-row:nth-child(2) {
    width: 85%;
}

.chat-list-skeleton .skeleton-row:nth-child(3) {
    width: 70%;
}

.chat-list-skeleton .skeleton-row:nth-child(4) {
    width: 90%;
}

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

    to {
        background-position: -200% 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-list-skeleton .skeleton-row {
        animation: none;
        background: var(--bg-secondary);
    }
}

/* Keyboard skip-to-content link — visually hidden until focused. */
.skip-link {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 9999;
    padding: 10px 16px;
    background: var(--accent);
    color: var(--on-accent);
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transform: translateY(-150%);
    transition: transform var(--transition-fast);
}

.skip-link:focus {
    transform: translateY(0);
    outline: 2px solid var(--on-accent);
    outline-offset: 2px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    transition: all var(--transition-fast);
    border-radius: var(--radius);
    margin: 1px 8px;
}

.chat-item:hover {
    background: rgba(var(--overlay-rgb), 0.05);
    color: var(--text-primary);
}

.chat-item.active {
    background: var(--accent-subtle);
    color: var(--text-primary);
}

.chat-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-item-actions {
    display: flex;
    gap: 2px;
    align-items: center;
    visibility: hidden;
}

.chat-item:hover .chat-item-actions {
    visibility: visible;
}

.chat-item-actions button {
    padding: 4px 8px;
    font-size: 12px;
    line-height: 1;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    min-width: 28px;
    min-height: 28px;
    justify-content: center;
}

.chat-item-actions button:hover {
    color: var(--danger);
    background: var(--danger-subtle);
}

@media (max-width: 768px) {
    .chat-item {
        position: relative;
        padding-right: 40px;
    }

    .chat-item-actions {
        display: none !important;
    }
}

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

.sidebar-footer {
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
}

.user-info-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    width: 100%;
    padding: 8px 10px;
    border-radius: var(--radius);
    transition: background var(--transition-fast);
}

.user-info-btn:hover {
    background: rgba(var(--overlay-rgb), 0.05);
    color: var(--text-primary);
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    color: var(--on-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}

@keyframes menuIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Main Area --- */

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

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

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

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

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

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

.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    padding: 40px;
}

.welcome h2 {
    font-size: 28px;
    color: var(--text-primary);
    font-weight: 300;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome p {
    font-size: 14px;
    color: var(--text-muted);
}

/* --- Starter Questions --- */
.starter-questions {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 480px;
}

.starter-item {
    padding: 12px 16px;
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    line-height: 1.4;
}

.starter-item:hover {
    color: var(--accent);
    background: var(--accent-subtle);
    border-color: var(--accent);
}

.starter-item:active {
    transform: scale(0.97);
}

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

.message {
    padding: 0;
}

.message.user {
    align-self: flex-end;
    max-width: 85%;
}

.message.user .message-content {
    background: var(--bg-elevated);
    border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
    padding: 10px 16px;
    /* User input is plain escaped text (no markdown) — keep the typed line
       breaks and blank-line paragraphs instead of collapsing them. */
    white-space: pre-wrap;
}

.message.assistant {
    padding: 8px 0;
}

@keyframes searchFade {

    0%,
    60% {
        background: var(--accent-glow);
    }

    100% {
        background: var(--accent-subtle);
    }
}

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

.message.user .message-sender {
    text-align: right;
}

.message-content {
    line-height: 1.7;
    word-break: break-word;
    min-width: 0;
}

/* During streaming, markdown is rendered without `.code-block-wrapper`, so the
   raw <pre> would otherwise force its column wider than its flex share — visible
   as the left model's answer bleeding into the right pane in dual-model chats.
   Soft-wrap (visual only — pre-wrap doesn't insert characters into the DOM, so
   the copy button's textContent and manual Strg+C selection both return the
   source as-typed). */
.message-content pre {
    max-width: 100%;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    overflow-x: hidden;
}

.message-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1px;
    margin-top: 4px;
    opacity: 0;
    transition: opacity var(--transition-base);
}

.message.user .message-actions {
    justify-content: flex-end;
}

.message:hover .message-actions {
    opacity: 1;
}

.message-actions:has(.speed-badge) {
    opacity: 1;
}

.msg-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.msg-icon-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

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

.msg-icon-btn.success {
    color: var(--success);
}

.speed-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 6px;
    padding: 2px 8px 2px 4px;
    font-size: 11px;
    color: var(--text-muted);
    border-radius: var(--radius);
    cursor: default;
}

.speed-badge svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.6;
}

.speed-badge span {
    font-weight: 500;
}

.speed-badge-wrap {
    display: contents;
}

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

.speed-detail.open {
    display: block;
}

/* --- Markdown Content --- */
.message-content p {
    margin: 0 0 8px;
}

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

.message-content ul,
.message-content ol {
    margin: 4px 0 8px 20px;
}

.message-content li {
    margin-bottom: 2px;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 16px 0 8px;
    color: var(--text-primary);
}

.message-content h1 {
    font-size: 1.4em;
}

.message-content h2 {
    font-size: 1.2em;
}

.message-content h3 {
    font-size: 1.1em;
}

.message-content blockquote {
    border-left: 3px solid var(--accent);
    padding: 4px 14px;
    margin: 8px 0;
    color: var(--text-secondary);
    background: var(--accent-subtle);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.message-content table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
    font-size: 13px;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
}

.message-content th {
    background: var(--bg-input);
    font-weight: 600;
}

.message-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 12px 0;
}

.message-content a {
    color: var(--accent);
}

.message-content img {
    max-width: 100%;
    border-radius: var(--radius);
}

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

/* Code: blocks */
.code-block-wrapper {
    position: relative;
    margin: 10px 0;
    border-radius: var(--radius);
    /* `clip` (not `hidden`) so the rounded corners are still clipped, but the
       wrapper is NOT a scroll container — that lets the sticky header below pin
       to the chat scrollport instead of being trapped inside this box. */
    overflow: clip;
    background: var(--code-bg);
    border: 1px solid rgba(var(--overlay-rgb), 0.06);
}

/* The header sticks to the top of the chat scroll area while a long block is in
   view, so the collapse toggle (and language label) stay reachable without
   scrolling back to the block's top. Background must be opaque — it floats over
   the code — so the subtle overlay tint is layered on top of the solid code bg. */
.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 14px;
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: var(--code-bg);
    background-image: linear-gradient(rgba(var(--overlay-rgb), 0.03), rgba(var(--overlay-rgb), 0.03));
    font-size: 11px;
    color: var(--text-muted);
    border-bottom: 1px solid rgba(var(--overlay-rgb), 0.04);
}

.code-copy-btn {
    font-size: 11px;
    color: var(--text-muted);
    padding: 2px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.code-copy-btn:hover {
    color: var(--text-primary);
    background: rgba(var(--overlay-rgb), 0.08);
}

.code-block-wrapper pre {
    margin: 0;
    padding: 14px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    overflow-x: hidden;
}

.code-block-wrapper pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: 13px;
    line-height: 1.5;
    white-space: inherit;
    overflow-wrap: inherit;
}

/* Code: collapse toggle (header) + collapsed placeholder */
.code-collapse-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.code-collapse-btn:hover {
    color: var(--text-primary);
    background: rgba(var(--overlay-rgb), 0.08);
}

.code-collapse-chevron {
    display: inline-flex;
    transition: transform var(--transition-fast);
}

.code-block-wrapper.collapsed .code-collapse-chevron {
    transform: rotate(-90deg);
}

.code-block-wrapper.collapsed pre {
    display: none;
}

.code-block-collapsed-info {
    display: none;
    padding: 10px 14px;
    font-size: 12px;
    font-style: italic;
    color: var(--text-muted);
}

.code-block-wrapper.collapsed .code-block-collapsed-info {
    display: block;
}

/* --- Think Block --- */
.think-block {
    margin-bottom: 10px;
    border: none;
    border-left: 2px solid var(--accent);
    border-radius: 0;
    background: none;
    padding-left: 12px;
}

.think-block summary {
    padding: 4px 0;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
    list-style: none;
}

.think-block summary::-webkit-details-marker {
    display: none;
}

.think-block summary::marker {
    display: none;
    content: '';
}

.think-block summary:hover {
    color: var(--text-secondary);
}

.think-chevron {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    transition: transform var(--transition-base);
    color: var(--text-muted);
}

.think-block[open] .think-chevron {
    transform: rotate(90deg);
}

.think-label {
    font-weight: 600;
}

.think-timer {
    font-weight: 400;
    opacity: 0.7;
}

.think-pulse {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    margin-left: 2px;
    vertical-align: middle;
    animation: think-pulse-anim 1.4s ease-in-out infinite;
}

@keyframes think-pulse-anim {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.3;
        transform: scale(0.7);
    }
}

.think-block .think-content {
    padding: 8px 0;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
    line-height: 1.5;
    opacity: 0.85;
}

/* --- Follow-ups --- */
.followups {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
}

.followups-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.followup-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 7px 12px;
    margin: 2px 0;
    font-size: 13px;
    color: var(--text-secondary);
    background: none;
    border: none;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-radius: var(--radius);
}

.followup-item:hover {
    color: var(--accent);
    background: var(--accent-subtle);
}

.followup-item:active {
    transform: scale(0.97);
}

/* --- RAG / web search sources (cited under each assistant message) --- */
.rag-sources,
.web-sources {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
}

.rag-sources+.web-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: none;
}

.rag-sources-label,
.web-sources-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

/* Requested web search failed / found nothing — the answer is NOT researched. */
.web-sources-notice {
    font-size: 12.5px;
    color: var(--text-muted);
}

.rag-sources-list,
.web-sources-list {
    list-style: decimal inside;
    padding-left: 0;
    margin: 0;
}

.rag-sources-list li,
.web-sources-list li {
    font-size: 13px;
    line-height: 1.55;
    margin: 2px 0;
    color: var(--text-secondary);
}

.web-sources-list a,
.rag-source-link {
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius);
    padding: 1px 4px;
    transition: all var(--transition-fast);
}

.web-sources-list a:hover,
.rag-source-link:hover,
.rag-source-link:focus-visible {
    color: var(--accent);
    background: var(--accent-subtle);
    text-decoration: underline;
}

.rag-source-link {
    background: transparent;
    border: none;
    cursor: pointer;
    font: inherit;
    text-align: left;
}

/* --- Streaming indicator --- */
.streaming-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: pulse 1.2s ease-in-out infinite;
    margin-left: 4px;
    vertical-align: middle;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.3;
        transform: scale(0.85);
    }
}

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

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

/* Floating "jump to latest" affordance — shown only when the user has scrolled
   up away from the bottom of an active conversation. */
.scroll-bottom-btn {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 10px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    z-index: 5;
    transition: background var(--transition-fast), color var(--transition-fast);
}

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

.scroll-bottom-btn[hidden] {
    display: none;
}

/* Honest expectation-setting line under the welcome heading. The extra class
   selector outranks `.welcome p` so the 14px subtitle size doesn't win. */
.welcome .welcome-disclaimer {
    margin: 0;
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
}

/* "Erneut versuchen" button shown on a failed response. */
.stream-retry-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 6px;
}

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

.input-row:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}

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

.input-row textarea:focus {
    box-shadow: none;
}

.send-btn {
    padding: 0;
    background: var(--accent);
    color: var(--on-accent);
    border-radius: var(--radius);
    font-size: 16px;
    height: 36px;
    width: 36px;
    min-width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--accent-hover);
    box-shadow: 0 2px 6px var(--accent-glow);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

.send-btn:active:not(:disabled) {
    transform: scale(0.97);
}

.send-btn.stop-mode {
    background: var(--danger);
}

.send-btn.stop-mode:hover {
    background: var(--danger-hover);
    box-shadow: 0 2px 6px var(--danger-subtle);
}

/* --- Input Toolbar --- */
/* flex-wrap: with every feature toggle enabled up to 11 fixed-width buttons
   share this row — narrower phones (S25/S25 Ultra: 336-360px of usable width)
   can only fit ~8, so the rest must wrap into a second row instead of being
   pushed off-screen (mic/TTS/share were unreachable on phones). */
.input-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    row-gap: 2px;
    max-width: 740px;
    margin: 8px auto 0;
    padding: 0 4px;
}

.input-toolbar-left,
.input-toolbar-right {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
}

/* keeps the right-hand group right-aligned when it wraps onto its own row */
.input-toolbar-right {
    margin-left: auto;
}

.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;
    position: relative;
}

.toolbar-btn:hover:not(:disabled) {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.toolbar-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.toolbar-btn.active {
    color: var(--accent);
    background: var(--accent-subtle);
}

.toolbar-btn.active:hover {
    background: var(--accent-glow);
}

/* The share button tints once the open chat has live shares, so the owner
   sees the shared state without opening the dialog. */
.toolbar-btn.is-shared {
    color: var(--accent);
}

.toolbar-btn.loading {
    pointer-events: none;
    opacity: 0.5;
    animation: toolbar-pulse 1s ease-in-out infinite;
}

@keyframes toolbar-pulse {

    0%,
    100% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }
}

/* --- 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: var(--z-modal);
    align-items: center;
    justify-content: center;
}

.modal-overlay.open {
    display: flex;
    animation: overlayIn 0.2s ease;
}

.modal-overlay.closing {
    display: flex;
    animation: overlayOut 0.15s ease forwards;
    pointer-events: none;
}

.modal-overlay.closing .modal {
    animation: modalOut 0.15s ease forwards;
}

@keyframes overlayIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes overlayOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

@keyframes modalOut {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }

    to {
        opacity: 0;
        transform: scale(0.96) translateY(8px);
    }
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    margin: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(8px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal.modal-wide {
    max-width: 860px;
}

.modal.modal-sm {
    max-width: 400px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 15px;
    font-weight: 700;
}

.modal-header .btn-ghost {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 14px;
    line-height: 1;
    flex-shrink: 0;
}

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

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

.modal-footer-spread {
    justify-content: space-between;
}

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

/* === Admin Dashboard === */
.dash-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
    flex-wrap: wrap;
}

.dash-title {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.4px;
    margin: 0;
    color: var(--text-primary);
}

/* card groups */
/* pending-registrations alert: an action, not a KPI */
.dash-alert {
    display: flex;
    align-items: center;
    width: 100%;
    gap: var(--space-sm);
    padding: 10px 16px;
    margin-bottom: var(--space-lg);
    border: 1px solid var(--danger);
    border-radius: var(--radius-lg);
    background: var(--bg-secondary);
    color: var(--danger);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
}

/* KPI band: equal tiles separated by hairlines (1px gap over border color).
   flex-shrink: 0 is load-bearing — overflow: hidden zeroes the automatic
   min-height, and the scrolling flex-column .view-panel would otherwise
   squeeze the band to its borders. */
.dash-band {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
    gap: 1px;
    background: var(--border-subtle);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    flex-shrink: 0;
}

.dash-tile {
    background: var(--bg-secondary);
    padding: 16px 18px;
    min-width: 0;
}

.dash-note {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: var(--space-sm);
}

.dash-card-val {
    font-size: 26px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    line-height: 1.15;
}

.dash-card-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.dash-card-sub {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 6px;
    font-weight: 500;
}

/* chart card */
.dash-chart-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 18px 20px 14px;
    margin-top: var(--space-xl);
    margin-bottom: var(--space-xl);
}

.dash-chart-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.dash-chart-titles {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.dash-chart-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}

.dash-chart-total {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

/* segmented range toggle */
.dash-range {
    display: inline-flex;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-pill);
    padding: 3px;
    gap: 2px;
}

.dash-range-btn {
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    padding: 5px 13px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.dash-range-btn:hover {
    color: var(--text-primary);
}

.dash-range-btn.active {
    background: var(--accent);
    color: var(--on-accent);
}

/* bar chart */
.dash-chart {
    width: 100%;
}

.dash-plot {
    position: relative;
    height: 168px;
    display: flex;
    align-items: flex-end;
    border-bottom: 1px solid var(--border-subtle);
}

.dash-ymax {
    position: absolute;
    top: -3px;
    right: 0;
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 600;
    opacity: 0.7;
}

.dash-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    width: 100%;
    height: 100%;
}

.dash-bar-wrap {
    flex: 1 1 0;
    height: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    min-width: 0;
}

.dash-bar {
    width: 100%;
    max-width: 30px;
    background: linear-gradient(180deg, var(--accent), var(--purple));
    border-radius: 3px 3px 0 0;
    transition: height var(--transition-slow), opacity var(--transition-fast);
}

.dash-bar-wrap:hover .dash-bar {
    opacity: 0.75;
}

.dash-axis {
    display: flex;
    gap: 2px;
    margin-top: 6px;
}

.dash-axis-cell {
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* empty state */
.dash-empty {
    height: 168px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 13px;
}

.dash-empty.sm {
    height: 80px;
    font-size: 12px;
}

/* detail tables: full width, stacked, no inner scroll — the page scrolls */
.dash-tables {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.dash-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.dash-panel-head {
    padding: 12px 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);
}

.dash-expander {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

.dash-expander:hover {
    color: var(--text-primary);
    background: rgba(var(--overlay-rgb), 0.02);
}

.dash-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 16px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-subtle);
}

.dash-row:last-child {
    border-bottom: none;
}

.dash-row:hover {
    background: rgba(var(--overlay-rgb), 0.02);
}

.dash-row-name {
    flex: 0 0 34%;
    min-width: 0;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dash-row-num {
    min-width: 44px;
    text-align: right;
    font-weight: 700;
    font-size: 12px;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.dash-row-meta {
    min-width: 60px;
    text-align: right;
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    /* Same trio as .dash-row-name: these tracks never grow to fit, and a long
       provider model name ("anthropic.claude-3-5-sonnet-20241022-v2:0") would
       otherwise wrap and leave one row taller than its neighbours. The full
       value stays available in the cell's tooltip. */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* head controls: range (scopes everything) + org selector side by side */
.dash-controls {
    display: flex;
    align-items: flex-end;
    gap: var(--space-md);
    flex-wrap: wrap;
}

.dash-controls .dash-range {
    height: 34px;
    align-items: center;
}

/* error state: never leave a stale scope's numbers standing */
.dash-error {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    padding: 14px 18px;
    margin-bottom: var(--space-xl);
    border: 1px solid var(--danger);
    border-radius: var(--radius-lg);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
}

/* labeled column headers + grid rows for the detail panels */
.dash-panel-cols {
    display: grid;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-subtle);
}

.dash-panel-cols span:not(:first-child) {
    text-align: right;
}

/* clickable sortable column headers */
.dash-th {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    /* A header wider than its track must clip, not bleed into the neighbouring
       column — the narrow breakpoints below squeeze these tracks hard. */
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color var(--transition-fast);
}

.dash-th:hover {
    color: var(--text-secondary);
}

.dash-th-active {
    color: var(--text-primary);
}

.dash-th:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 3px;
}

/* The track count must match the number of VISIBLE children, so every rule
   that hides a column below shrinks the grid in lockstep.
   Users:  Nutzer · Anfragen · Tokens · Top-Modell(.dash-col-opt) · Zuletzt aktiv
   Modelle: Modell · Antworten · Tokens · TTFT · TTLT · TPS (last three
   .dash-col-perf). */
.dash-cols-users {
    grid-template-columns: minmax(0, 1.2fr) 90px 96px minmax(130px, 0.8fr) 110px;
}

.dash-cols-models {
    grid-template-columns: minmax(0, 1.4fr) 96px 96px 90px 90px 90px;
}

.dash-row.dash-cols-users,
.dash-row.dash-cols-models,
.dash-row.dash-cols-billed {
    display: grid;
    gap: 10px;
    position: relative;
}

.dash-row.dash-cols-users > span,
.dash-row.dash-cols-models > span,
.dash-row.dash-cols-billed > span {
    position: relative;
    z-index: 1;
}

/* magnitude as a quiet background fill (share of the top entry) */
.dash-row-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: var(--accent-subtle);
    z-index: 0;
    pointer-events: none;
}

.dash-row-inactive {
    opacity: 0.55;
}
/* Foot note under a detail panel: what the table does NOT show. Quiet, but
   never hidden — a capped table that looks complete is the whole problem. */
.dash-panel-note {
    padding: 8px 16px 10px;
    font-size: 11px;
    line-height: 1.45;
    color: var(--text-muted);
    border-top: 1px solid var(--border-subtle);
}

.dash-row .dash-row-name {
    flex: initial;
}

/* keep the y-max readable when the rightmost bar is near full height */
.dash-ymax {
    background: var(--bg-secondary);
    padding: 0 4px;
    border-radius: 4px;
    z-index: 1;
}

@media (max-width: 760px) {
    .dash-head { align-items: stretch; }
    .dash-controls { align-items: stretch; flex-direction: column-reverse; }
    .dash-band { grid-template-columns: repeat(2, 1fr); }
    .dash-row { gap: 8px; padding: 9px 12px; }
    .dash-row-name { flex-basis: 30%; }
    .dash-row-meta { min-width: 48px; }
    /* the per-model latency columns yield to the essentials on narrow screens */
    .dash-col-perf { display: none; }
    /* ...and on the users table Top-Modell follows Tokens out */
    .dash-col-opt { display: none; }
    .dash-cols-users { grid-template-columns: minmax(0, 1fr) 72px 72px 84px; }
    .dash-cols-models { grid-template-columns: minmax(0, 1fr) 76px 76px; }
    .dash-panel-cols, .dash-row.dash-cols-users, .dash-row.dash-cols-models { gap: 6px; }
    .dash-plot, .dash-empty { height: 144px; }
}

/* --- Admin Tables --- */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: none;
    border: none;
    border-radius: 0;
    overflow: hidden;
}

.admin-table th {
    text-align: left;
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-subtle);
    background: none;
}

.admin-table th:not(.no-sort) {
    cursor: pointer;
    user-select: none;
}

.admin-table th:not(.no-sort):hover {
    color: var(--text-secondary);
}

.admin-table th:not(.no-sort)::after {
    content: '';
    display: inline-block;
    margin-left: 4px;
    vertical-align: middle;
    border-left: 3.5px solid transparent;
    border-right: 3.5px solid transparent;
    border-bottom: 4px solid currentColor;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.admin-table th:not(.no-sort):hover::after {
    opacity: 0.35;
}

.admin-table th.sort-asc::after {
    opacity: 1 !important;
    border-bottom: 4px solid var(--accent);
    border-top: none;
}

.admin-table th.sort-desc::after {
    opacity: 1 !important;
    border-bottom: none;
    border-top: 4px solid var(--accent);
}

.admin-table td {
    padding: 8px 12px;
    vertical-align: middle;
    white-space: nowrap;
}

.admin-table tr {
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--border-subtle);
}

.admin-table tbody tr:hover td {
    background: rgba(var(--overlay-rgb), 0.02);
}

.admin-table tbody tr:last-child {
    border-bottom: none;
}

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

.badge {
    display: inline-block;
    min-width: 64px;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.2px;
    text-align: center;
}

.badge-admin {
    background: var(--accent-subtle);
    color: var(--accent);
}

.badge-pending {
    background: var(--warning-subtle);
    color: var(--warning);
}

/* Role-change confirmations pass multi-line consequence text. */
#confirm-message {
    white-space: pre-line;
}

.action-btn {
    padding: 5px 12px;
    font-size: 11px;
    white-space: nowrap;
    font-weight: 600;
    border-radius: var(--radius);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    background: var(--bg-input);
    transition: all var(--transition-fast);
}

.action-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-color: rgba(var(--overlay-rgb), 0.12);
}

.action-btn:active {
    transform: scale(0.97);
}

.action-btn.danger {
    color: var(--danger);
}

.action-btn.danger:hover {
    background: var(--danger-subtle);
    border-color: color-mix(in srgb, var(--danger) 20%, transparent);
}

.action-btn.success {
    color: var(--success);
}

.action-btn.success:hover {
    background: var(--success-subtle);
    border-color: color-mix(in srgb, var(--success) 20%, transparent);
}

/* --- Admin Forms --- */
.settings-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;
}

.save-check {
    color: var(--success);
    margin-left: 6px;
    font-size: 0.85em;
    opacity: 1;
    transition: opacity var(--transition-slow);
}

.save-check.fade-out {
    opacity: 0;
}

.conn-form {
    padding: 16px 20px;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.conn-form .form-group {
    flex: 1;
    min-width: 180px;
}

.conn-save-btn {
    white-space: nowrap;
    font-size: 13px;
    padding: 10px 20px;
    border: 1px solid transparent;
    box-sizing: border-box;
    min-width: 160px;
    text-align: center;
}

.input-with-icon {
    position: relative;
}

.input-with-icon input {
    width: 100%;
    padding-right: 40px;
}

/* Mask text input as bullets without using type=password — avoids the
   browser's "save password" prompt on view-switch / panel hide. */
input.masked {
    -webkit-text-security: disc;
    text-security: disc;
    font-family: text-security-disc, inherit;
    letter-spacing: 0.15em;
}

.input-with-icon .input-icon-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
}

.input-with-icon .input-icon-btn:hover {
    color: var(--text-primary);
}

/* Meta row beneath .conn-form — columns mirror the form cells so the left
   cell sits under API-URL and the hint under API-KEY. On wide viewports the
   spacer reserves the button column; on narrow viewports the spacer hides
   and the cells wrap naturally (min-width forces them to their own rows
   rather than cramming the hint into a sliver). */
.conn-meta {
    display: flex;
    padding: 4px 20px 14px;
    gap: 12px;
    font-size: 12px;
    color: var(--text-muted);
    flex-wrap: wrap;
    align-items: flex-start;
}

.conn-meta-cell {
    flex: 1 1 240px;
    min-width: 240px;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.4;
}

.conn-meta-hint {
    flex-wrap: wrap;
    /* let inline <code> badges wrap cleanly */
}

/* At narrow widths the form would otherwise wrap only the Save button onto
   its own row, leaving an awkward empty column beside it. Stack everything
   vertically instead — URL, Key, button and meta each become full-width. */
@media (max-width: 700px) {
    .conn-form {
        flex-direction: column;
        align-items: stretch;
    }

    .conn-form .form-group {
        min-width: 0;
        flex: none;
    }

    .conn-save-btn {
        width: 100%;
        min-width: 0;
    }
}

.conn-meta-hint code {
    padding: 1px 5px;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    font-family: monospace;
    font-size: 11px;
    color: var(--text-primary);
}

/* --- Toggle --- */
.toggle {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    cursor: pointer;
}

.toggle input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    transition: all var(--transition-base);
}

.toggle-slider::before {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    left: 2px;
    top: 2px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition-base);
}

.toggle input:focus-visible+.toggle-slider {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.toggle input:checked+.toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
}

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

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

/* --- Logs --- */
.logs-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.log-filter-tabs {
    display: flex;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 2px;
    margin-right: auto;
}

.log-filter-tab {
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    background: none;
    border: none;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.log-filter-tab:hover {
    color: var(--text-primary);
}

.log-filter-tab.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

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

.log-hint {
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
    margin-top: 12px;
    opacity: 0.7;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 16px;
    justify-content: center;
}

.period-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all var(--transition-fast);
}

.period-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-color: rgba(var(--overlay-rgb), 0.12);
}

.period-btn.active {
    background: var(--accent);
    color: var(--on-accent);
    border-color: var(--accent);
}

.period-btn:active {
    transform: scale(0.97);
}

.period-btn:disabled {
    opacity: 0.4;
    pointer-events: none;
}

.pagination-ellipsis {
    min-width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 13px;
}

@media (max-width: 600px) {
    .pagination .pagination-outer {
        display: none;
    }

    .period-btn {
        min-width: 28px;
        height: 28px;
        padding: 0 6px;
        font-size: 12px;
    }

    .pagination-ellipsis {
        min-width: 20px;
        height: 28px;
        font-size: 12px;
    }
}

.log-timestamp {
    white-space: nowrap;
    color: var(--text-muted);
}

.log-level {
    display: inline-block;
    min-width: 64px;
    text-align: center;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.log-level-error {
    background: var(--danger-subtle);
    color: var(--danger);
}

.log-level-warning {
    background: var(--warning-subtle);
    color: var(--warning);
}

.log-level-info {
    background: rgba(var(--overlay-rgb), 0.05);
    color: var(--text-muted);
}

.log-source {
    color: var(--text-muted);
}

.log-row-clickable {
    cursor: pointer;
}

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

.log-detail-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    z-index: var(--z-log-detail);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    overflow: hidden;
}

@media (max-width: 600px) {
    .log-detail-overlay {
        padding: 8px;
    }

    .log-detail-panel,
    .log-detail-panel-lg {
        max-width: 100%;
        max-height: 90vh;
        border-radius: var(--radius);
    }
}

.log-detail-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 800px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.log-detail-panel-lg {
    max-width: 960px;
    max-height: 85vh;
}

.log-detail-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.log-detail-source {
    font-weight: 600;
    color: var(--text-secondary);
}

.log-detail-time {
    color: var(--text-muted);
    font-size: 13px;
    margin-left: auto;
    margin-right: 4px;
}

.log-detail-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    margin-left: 8px;
    flex-shrink: 0;
}

.log-detail-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.log-detail-message {
    padding: 16px 20px;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.log-detail-traceback {
    padding: 0 20px 20px;
    overflow: auto;
    flex: 1;
    min-height: 0;
}

.log-detail-traceback-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.log-copy-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-transform: none;
    letter-spacing: 0;
}

.log-copy-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.log-copy-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-color: rgba(var(--overlay-rgb), 0.12);
}

.log-copy-btn.copied {
    color: var(--success);
    border-color: color-mix(in srgb, var(--success) 20%, transparent);
}

.log-detail-traceback pre {
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 16px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--danger);
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
    overflow-x: auto;
}

/* --- Admin Card (unified card-with-header pattern) --- */
.admin-card {
    background: none;
    border: none;
    border-radius: 0;
    overflow: visible;
}

.admin-card+.admin-card {
    margin-top: 16px;
}

.admin-card-header {
    padding: var(--space-md) var(--space-lg);
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-subtle);
    background: none;
}

.admin-card .admin-table {
    border: none;
    border-radius: 0;
    background: none;
}

.admin-card-help {
    padding: 8px var(--space-lg);
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border-subtle);
}

.prompt-input-field {
    margin-top: 10px;
    width: 100%;
}

/* --- Admin settings: constrained width, card layout, label-left rows --- */
.settings-layout {
    max-width: 880px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.settings-layout .profile-tabs {
    padding: 0;
    border-bottom: none;
    margin: 0;
}

.pcard {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.pcard-head {
    padding: 11px 16px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-subtle);
}

.pcard-help {
    margin: 0;
    padding: 10px 16px 0;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

.pcard-body {
    padding: 2px 16px;
}

.pcard-empty {
    padding: 14px;
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
}

.field-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.field-row:last-child {
    border-bottom: none;
}

.field-label {
    flex: 1 1 auto;
    font-size: 13px;
    color: var(--text-primary);
    cursor: default;
}

.field-control {
    flex: 0 0 auto;
    width: 300px;
    max-width: 50%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.field-control-toggle {
    width: auto;
}

.field-control select,
.field-control input[type="text"],
.field-control input[type="number"] {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    padding: 7px 10px;
    font-size: 13px;
    box-sizing: border-box;
}

.field-control input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.field-control input[type="number"]::-webkit-outer-spin-button,
.field-control input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.field-control select:focus,
.field-control input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
    outline: none;
}

.allowed-models-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 6px;
    max-height: 280px;
    overflow: auto;
    padding: 4px;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
}

.pcard .allowed-models-list {
    margin: 12px 16px 16px;
    max-width: none;
}

@media (max-width: 640px) {
    .field-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .field-row-toggle {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    .field-control {
        width: 100%;
        max-width: none;
        justify-content: flex-start;
    }

    .field-control-toggle {
        width: auto;
    }
}

.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-actions .btn {
    font-size: 12px;
    padding: 5px 14px;
}

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        height: 100dvh;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-resize-handle {
        display: none;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: var(--z-sidebar-overlay);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .hamburger {
        display: block;
    }

    .model-selector {
        flex-wrap: nowrap;
        max-width: 85%;
        overflow: visible;
    }

    .sidebar-collapse-btn {
        display: none;
    }

    .messages-container {
        padding: 0 16px 16px;
    }

    .input-area {
        padding: 10px 12px calc(14px + env(safe-area-inset-bottom, 0px));
    }

    .toolbar-btn {
        width: 38px;
        height: 38px;
        -webkit-tap-highlight-color: transparent;
    }

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

    .input-toolbar {
        padding: 0;
    }

    .speed-badge {
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .speed-detail.open {
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
}
@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: var(--z-overlay);
    cursor: zoom-out;
    backdrop-filter: blur(4px);
    touch-action: none;
    overflow: hidden;
}

.image-preview-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: var(--z-overlay-front);
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    color: var(--on-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.image-preview-caption {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 80vw;
    max-height: 20vh;
    overflow-y: auto;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    border-radius: var(--radius);
    backdrop-filter: blur(8px);
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    box-shadow: var(--shadow-lg);
}

.image-preview-caption.is-placeholder {
    font-style: italic;
    opacity: 0.7;
}

/* === HTML / single-file-app preview === */
.code-block-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.code-action-btn {
    font-size: 11px;
    color: var(--text-muted);
    padding: 2px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.code-action-btn:hover {
    color: var(--text-primary);
    background: rgba(var(--overlay-rgb), 0.08);
}

.code-action-btn--accent {
    color: var(--accent);
    font-weight: 600;
}

.code-action-btn--accent:hover {
    color: var(--accent-hover);
    background: var(--accent-subtle);
}

/* Disabled = the deck card's download button while the .pptx builds in the
   background ("Präsentation wird vorbereitet…"). */
.code-action-btn:disabled {
    opacity: 0.55;
    cursor: default;
}

.code-action-btn:disabled:hover {
    color: var(--text-muted);
    background: none;
}

/* HTML blocks: actions sit at the bottom of the block (mirrors the header). */
.code-block-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 6px 14px;
    background: rgba(var(--overlay-rgb), 0.03);
    border-top: 1px solid rgba(var(--overlay-rgb), 0.04);
}

/* Tables stay rahmenlos — no card chrome around them. A table already has its
   own geometry (border-collapse cells); wrapping it in the dark rounded code
   card would feel heavy and double-framed. Just a thin scroll-container so
   wide tables don't push the bubble sideways, plus a floating action row. */
.table-block-wrapper {
    margin: 10px 0;
}

.table-block-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-block-scroll>table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: transparent;
}

.table-block-scroll th,
.table-block-scroll td {
    padding: 6px 12px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid rgba(var(--overlay-rgb), 0.07);
}

.table-block-scroll thead th {
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid rgba(var(--overlay-rgb), 0.18);
}

.table-block-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 2px;
    padding-top: 4px;
}
.csv-analysis-table .table-block-wrapper {
    margin: 4px 0 0;
}
.book-tab.active {
    color: var(--accent);
    border-color: var(--border);
    background: var(--accent-subtle);
    font-weight: 600;
}
.ask-dot.done {
    background: var(--accent);
    opacity: 0.45;
}

.ask-dot.active {
    background: var(--accent);
    opacity: 1;
    transform: scale(1.3);
}

.ask-q.active {
    display: block;
    animation: askStepIn 0.18s ease;
}

@keyframes askStepIn {
    from { opacity: 0; transform: translateX(8px); }
    to { opacity: 1; transform: none; }
}

.ask-opt.sel {
    border-color: var(--accent);
    background: var(--accent-subtle);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.ask-other.open {
    display: block;
}

.html-preview-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: var(--z-overlay);
    animation: overlayIn var(--transition-fast);
}

.html-preview-panel {
    display: flex;
    flex-direction: column;
    width: min(1100px, 96vw);
    height: min(900px, 92vh);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.html-preview-bar {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 8px 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
}

.html-preview-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-right: auto;
}

.html-preview-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.html-preview-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: var(--text-secondary);
    padding: 7px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.html-preview-btn:hover {
    color: var(--text-primary);
    background: rgba(var(--overlay-rgb), 0.08);
}

.html-preview-btn svg {
    flex: none;
}

.html-preview-close {
    padding: 7px;
}

.html-preview-frame-wrap {
    flex: 1;
    min-height: 0;
    background: #fff;
}

.html-preview-frame {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: #fff;
}

@media (max-width: 640px) {
    .html-preview-overlay {
        padding: 0;
    }

    .html-preview-panel {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        border: 0;
        border-radius: 0;
    }

    .html-preview-title {
        font-size: 14px;
    }

    .html-preview-btn {
        padding: 9px;
    }

    .html-preview-btn>span {
        display: none;
    }

    /* icon-only on phones to save width */
    .html-preview-close svg {
        width: 18px;
        height: 18px;
    }
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle);
}

.btn-outline:active {
    transform: scale(0.97);
}

.members-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.import-users-result {
    max-height: 180px;
    overflow-y: auto;
    margin-top: 4px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* Custom file picker — hides the native (grey) input, drives it from a
   styled button plus a live filename label. */
.file-picker {
    display: flex;
    align-items: center;
    gap: 10px;
}

.file-picker input[type="file"] {
    display: none;
}

.file-picker .btn-sm {
    flex-shrink: 0;
}

.file-picker-name {
    font-size: 12.5px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.file-picker-name.has-file {
    color: var(--text-secondary);
    font-weight: 500;
}

/* Input with trailing inline actions (e.g. password field: reveal + generate).
   align-items: stretch so the buttons match the input's height exactly. */
.input-with-actions {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.input-with-actions > input {
    flex: 1;
    min-width: 0;
}

.input-with-actions .btn-sm {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
}

.input-action-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    padding: 0;
    border-radius: var(--radius);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}

.input-action-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-subtle);
}

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

/* Custom Checkbox */
.cb {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    width: 18px;
    height: 18px;
}

.cb input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.cb-box {
    width: 18px;
    height: 18px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--text-muted);
    background: transparent;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.cb-box::after {
    content: '';
    display: none;
    width: 4px;
    height: 8px;
    border: solid var(--on-accent);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) translateY(-1px);
}

.cb input:checked+.cb-box {
    background: var(--accent);
    border-color: var(--accent);
}

.cb input:checked+.cb-box::after {
    display: block;
}

.cb input:focus-visible+.cb-box {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.cb:hover .cb-box {
    border-color: var(--accent);
}

/* --- Admin: members toolbar --- */
.members-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-subtle);
}

.members-toolbar-spacer { flex: 1; }

.members-search {
    flex: 0 1 240px;
    padding: 7px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
}

.members-search:focus {
    outline: none;
    border-color: var(--accent);
}

.members-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* === Global Toast === */
#toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: var(--z-overlay);
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    padding: 10px 18px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    max-width: 400px;
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateX(40px);
    cursor: default;
}

.toast-in {
    animation: toast-slide-in 0.25s ease forwards;
}

.toast-out {
    animation: toast-slide-out 0.2s ease forwards;
}

.toast-success {
    background: var(--success-subtle);
    color: var(--success);
    border: 1px solid color-mix(in srgb, var(--success) 20%, transparent);
}

.toast-error {
    background: var(--danger-subtle);
    color: var(--danger);
    border: 1px solid color-mix(in srgb, var(--danger) 20%, transparent);
}

.toast-info {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

@keyframes toast-slide-in {
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toast-slide-out {
    from {
        opacity: 1;
        transform: translateX(0);
    }

    to {
        opacity: 0;
        transform: translateX(40px);
    }
}

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

.cm-share-toggle.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 500;
}

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

/* === 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-docs {
    display: contents;
}

/* The file-count bubble is absolutely positioned inside the attach button, so
   the button has to be the containing block — otherwise the badge escapes to
   the next positioned ancestor. */
#toolbar-attach {
    position: relative;
}

.attach-count {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--on-color);
    font-size: 10px;
    font-weight: 600;
    line-height: 16px;
    text-align: center;
    pointer-events: none;
    box-sizing: border-box;
    user-select: none;
    animation: attach-count-pop 180ms ease-out;
}

.attach-count[hidden] {
    display: none;
}

/* Halo matches whichever surface the button sits on, so the badge reads as a
   floating bubble rather than glued to the icon. */
#toolbar-attach .attach-count {
    box-shadow: 0 0 0 2px var(--bg-primary);
}

@keyframes attach-count-pop {
    from {
        transform: scale(0.6);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Unified attachment boxes (images + docs) */
.attachments-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 6px;
}

.attach-box {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-lg);
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.attach-box:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

/* Image box */
.attach-box-image {
    background: var(--bg-secondary);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attach-box-image img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: inherit;
}

/* Document box */
.attach-box-doc {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 6px 7px;
    gap: 2px;
}

.attach-box-ext {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.attach-box-preview {
    flex: 1;
    width: 100%;
    overflow: hidden;
    font-size: 6px;
    line-height: 1.4;
    color: var(--text-muted);
    opacity: 0.6;
    word-break: break-all;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    line-clamp: 4;
    -webkit-box-orient: vertical;
}

.attach-box-preview:empty::before {
    content: 'Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod';
    opacity: 0.3;
}

.attach-box-name {
    font-size: 8px;
    color: var(--text-secondary);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    line-height: 1.2;
}

/* Single X button used for both "cancel upload" and "remove uploaded file". */
.attach-box .attach-box-remove {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    color: var(--on-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    z-index: 15;
    opacity: 0;
    transition: opacity var(--transition-fast), background var(--transition-fast);
}

/* Always-visible affordance while user can act:
   - finished upload (has data-file-id) → must be visible without hover so
     the user can find the delete handle on touch + sees it at a glance
   - hover (any state)                  → fully opaque
   - uploading / error                  → must be obvious for cancel/dismiss */
.attach-box[data-file-id] .attach-box-remove {
    opacity: 0.7;
}

.attach-box:hover .attach-box-remove,
.attach-box.uploading .attach-box-remove,
.attach-box.error .attach-box-remove,
.attach-box[data-file-id]:hover .attach-box-remove {
    opacity: 1;
}

.attach-box .attach-box-remove:hover {
    background: var(--danger);
}

.attach-box.uploading {
    opacity: 1;
}

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

/* Upload progress ring — drives stroke-dashoffset from JS. */
.attach-box-progress {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    z-index: 11;
    pointer-events: none;
}

.attach-box-progress-ring-wrap {
    position: relative;
    width: 38px;
    height: 38px;
}

.attach-box-ring {
    width: 100%;
    height: 100%;
    display: block;
    transform: rotate(-90deg);
}

.attach-box-ring .ring-track,
.attach-box-ring .ring-fill {
    fill: none;
    stroke-width: 3;
    stroke-linecap: round;
}

.attach-box-ring .ring-track {
    stroke: rgba(255, 255, 255, 0.22);
}

.attach-box-ring .ring-fill {
    stroke: var(--on-color);
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 250ms ease-out;
}

/* Indeterminate state used until the first real % arrives. */
.attach-box-ring.indeterminate .ring-fill {
    stroke-dasharray: 18 82;
    transition: none;
    animation: ringSpin 1.1s linear infinite;
}

@keyframes ringSpin {
    from {
        stroke-dashoffset: 100;
    }

    to {
        stroke-dashoffset: 0;
    }
}

.attach-box-progress-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--on-color);
    line-height: 1;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.attach-box-progress-eta {
    font-size: 9px;
    line-height: 1;
    color: rgba(255, 255, 255, 0.75);
    font-variant-numeric: tabular-nums;
    min-height: 9px;
    letter-spacing: 0.02em;
}

.attach-box.done::after {
    content: '\2713';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    border-radius: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--success);
    font-size: 26px;
    font-weight: 700;
    animation: checkPop 0.3s ease-out;
    z-index: 10;
}

@keyframes checkPop {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.attach-box.updated {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
    transition: box-shadow 0.4s ease, border-color 0.4s ease;
}

.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: var(--z-overlay);
    padding: 24px;
    backdrop-filter: blur(4px);
    animation: doc-preview-fade 160ms ease-out;
}

@keyframes doc-preview-fade {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.doc-preview-panel {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    max-width: 920px;
    width: 100%;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: doc-preview-pop 180ms cubic-bezier(0.2, 0.7, 0.3, 1);
}

@keyframes doc-preview-pop {
    from {
        transform: translateY(8px) scale(0.985);
        opacity: 0;
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.doc-preview-header {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.doc-preview-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.doc-preview-close {
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.doc-preview-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.doc-preview-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
}

.doc-preview-image {
    background: var(--img-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    max-height: 50vh;
    overflow: hidden;
    border-bottom: 1px solid var(--border);
}

.doc-preview-image img {
    max-width: 100%;
    max-height: 50vh;
    object-fit: contain;
    display: block;
}

.doc-preview-text {
    padding: 20px 24px;
    margin: 0;
    font-size: 14px;
    line-height: 1.65;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    font-family: inherit;
}

.doc-preview-markdown {
    white-space: normal;
}

.doc-preview-markdown h1,
.doc-preview-markdown h2,
.doc-preview-markdown h3,
.doc-preview-markdown h4 {
    margin: 1em 0 0.5em;
    overflow-wrap: anywhere;
    line-height: 1.3;
}

.doc-preview-markdown h1:first-child,
.doc-preview-markdown h2:first-child,
.doc-preview-markdown h3:first-child {
    margin-top: 0;
}

.doc-preview-markdown p {
    margin: 0.6em 0;
    overflow-wrap: anywhere;
}

.doc-preview-markdown ul,
.doc-preview-markdown ol {
    padding-inline-start: 1.5em;
    margin: 0.6em 0;
}

.doc-preview-markdown li {
    margin: 0.25em 0;
    overflow-wrap: anywhere;
}

.doc-preview-markdown a {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.doc-preview-markdown table {
    border-collapse: collapse;
    margin: 0.8em 0;
    font-size: 12px;
    width: 100%;
    table-layout: fixed;
}

.doc-preview-markdown th,
.doc-preview-markdown td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
    word-break: break-word;
    overflow-wrap: anywhere;
    vertical-align: top;
}

.doc-preview-markdown th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.doc-preview-markdown pre {
    background: var(--bg-secondary);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    overflow-x: hidden;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Code-block wrappers inside the doc preview must wrap, not scroll */
.doc-preview-markdown .code-block-wrapper {
    margin: 10px 0;
    max-width: 100%;
}

.doc-preview-markdown .code-block-wrapper pre {
    overflow-x: hidden;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.doc-preview-markdown .code-block-wrapper pre code {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}

@media (max-width: 768px) {
    .doc-preview-overlay {
        padding: 8px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        padding-top: calc(8px + env(safe-area-inset-top, 0px));
    }

    .doc-preview-panel {
        max-height: calc(100vh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    }

    .doc-preview-header {
        padding: 12px 14px;
    }

    .doc-preview-title {
        font-size: 13px;
    }

    .doc-preview-close {
        width: 36px;
        height: 36px;
        margin-right: -6px;
        font-size: 24px;
    }

    .doc-preview-text {
        padding: 14px 16px;
        font-size: 14px;
        line-height: 1.6;
    }

    .doc-preview-image,
    .doc-preview-image img {
        max-height: 38vh;
    }

    .doc-preview-markdown table {
        font-size: 11px;
    }

    .doc-preview-markdown th,
    .doc-preview-markdown td {
        padding: 4px 6px;
    }

    .doc-preview-markdown pre {
        font-size: 12px;
        padding: 8px 10px;
    }
}

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

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

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

.admin-nav-back {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    margin-bottom: 4px;
    border: none;
    border-radius: var(--radius);
    background: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

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

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

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

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

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

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

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

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

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

.sidebar.collapsed .sidebar-admin-nav {
    padding: 0 4px;
}

.sidebar.collapsed .admin-nav-back {
    justify-content: center;
    padding: 8px;
}

.sidebar.collapsed .admin-nav-back span {
    display: none;
}

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

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

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

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

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

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

.bs-backdrop.open {
    opacity: 1;
}

.bs-backdrop.closing {
    opacity: 0;
    pointer-events: none;
}

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

.bs-backdrop.open .bs-sheet {
    transform: translateY(0);
}

.bs-backdrop.closing .bs-sheet {
    transform: translateY(100%);
}

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

.bs-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    margin: 4px 0 0;
}

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

.bs-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}

.bs-actions button {
    min-height: 50px;
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 600;
    border-radius: var(--radius-lg);
    border: 1px solid transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.bs-actions .bs-confirm {
    background: var(--accent);
    color: var(--on-accent);
}

.bs-actions .bs-confirm.danger {
    background: var(--danger);
    color: var(--on-color);
}

.bs-actions .bs-confirm:hover,
.bs-actions .bs-confirm:active {
    filter: brightness(1.05);
}

.bs-actions .bs-cancel {
    background: transparent;
    color: var(--text-primary);
    border-color: var(--border);
}

.bs-actions .bs-cancel:hover,
.bs-actions .bs-cancel:active {
    background: rgba(var(--overlay-rgb), 0.06);
}

@media (min-width: 769px) {
    .bs-backdrop {
        align-items: center;
    }

    .bs-sheet {
        border-radius: var(--radius-xl);
        border-bottom: 1px solid var(--border);
        max-width: 420px;
        margin: 20px;
        padding-bottom: 16px;
    }

    .bs-handle {
        display: none;
    }
}

/* === Impersonation === */

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

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

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

.cm-vision-toggle:not(.active) {
    opacity: 0.55;
}

.cm-vision-toggle:not(.active):hover {
    opacity: 0.85;
}

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

#toolbar-vision-toggle:not(.active):hover {
    opacity: 0.75;
}

/* === Queued upload boxes === */
/* Pre-rendered boxes that are waiting their turn behind an active upload. Visible
   so the user sees the whole batch up-front, but visibly inactive. */
.attach-box.queued {
    opacity: 0.45;
    filter: saturate(0.75);
}

.attach-box.queued::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(45deg,
            transparent 0,
            transparent 6px,
            rgba(var(--overlay-rgb, 0, 0, 0), 0.06) 6px,
            rgba(var(--overlay-rgb, 0, 0, 0), 0.06) 12px);
    border-radius: inherit;
    pointer-events: none;
    z-index: 1;
}

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

.sidebar.admin-mode.settings-active .sidebar-admin-nav {
    display: none !important;
}

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

.sidebar.search-active .sidebar-body,
.sidebar.settings-active .sidebar-body {
    display: none;
}

.sidebar.settings-active .sidebar-search-wrap {
    display: none;
}

.sidebar.settings-active .sidebar-actions {
    display: none;
}

.sidebar-takeover {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0;
    background: var(--bg-sidebar);
    animation: takeoverFadeIn 140ms ease-out;
}

.sidebar-takeover[hidden] {
    display: none !important;
}

@keyframes takeoverFadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sidebar-takeover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px 6px 14px;
    height: 40px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-takeover-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
}

.sidebar-takeover-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.sidebar-takeover-close:hover {
    color: var(--text-primary);
    background: rgba(var(--overlay-rgb), 0.07);
}

/* Search-takeover-specific: results list fills remaining space, soft scrollbar. */
.sidebar-search-takeover .sidebar-search-results {
    margin-top: 0;
    max-height: none;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 6px 6px 12px;
    overscroll-behavior: contain;
}

.sidebar-search-takeover .sidebar-search-results::-webkit-scrollbar {
    width: 6px;
}

.sidebar-search-takeover .sidebar-search-results::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-search-takeover .sidebar-search-results::-webkit-scrollbar-thumb {
    background: rgba(var(--overlay-rgb), 0.15);
    border-radius: var(--radius-sm);
}

.sidebar-search-takeover .sidebar-search-results::-webkit-scrollbar-thumb:hover {
    background: rgba(var(--overlay-rgb), 0.25);
}

.sidebar-search-takeover .search-result-item {
    padding: 10px 14px;
    border-radius: var(--radius);
    border-bottom: none;
    margin-bottom: 2px;
}

.sidebar-search-takeover .search-result-item:hover {
    background: rgba(var(--overlay-rgb), 0.06);
}

.sidebar-search-takeover .search-result-title {
    font-size: 13px;
}

.sidebar-search-takeover .search-result-snippet {
    white-space: normal;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
    line-height: 1.4;
    max-height: 2.8em;
}

/* ======================================================================
   Pinned chats section (top of sidebar body)
   ====================================================================== */
.sidebar-pinned {
    border-bottom: 1px solid var(--border-subtle);
    padding: 6px 0 8px;
    flex-shrink: 0;
    max-height: 28vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sidebar-pinned::-webkit-scrollbar {
    width: 6px;
}

.sidebar-pinned::-webkit-scrollbar-thumb {
    background: rgba(var(--overlay-rgb), 0.12);
    border-radius: var(--radius-sm);
}

.sidebar-section-label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 14px 6px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.sidebar-section-label svg {
    color: var(--purple);
    opacity: 0.8;
}

.sidebar-pinned-list {
    padding: 0 0 2px;
}

/* ======================================================================
   Settings (user) takeover panel
   ====================================================================== */
.sidebar-settings-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    /* Outer breathing room so the card stack never touches the sidebar edges. */
    padding: 14px 12px 24px;
}

.sidebar-settings-body::-webkit-scrollbar {
    width: 6px;
}

.sidebar-settings-body::-webkit-scrollbar-thumb {
    background: rgba(var(--overlay-rgb), 0.15);
    border-radius: var(--radius-sm);
}

/* Section card — subtle background + internal padding so labels never sit
   flush against the sidebar edge. Removes the "everything-glued-to-the-rail"
   feel of the previous flat layout. */
.settings-section {
    background: color-mix(in srgb, var(--bg-elevated) 50%, transparent);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 14px 14px 12px;
    margin-bottom: 10px;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.settings-section-help {
    font-size: 11.5px;
    color: var(--text-muted);
    line-height: 1.4;
    margin: -4px 0 10px;
}

.settings-textarea {
    width: 100%;
    min-height: 90px;
    max-height: 240px;
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    resize: vertical;
    font-family: inherit;
    line-height: 1.45;
}

.settings-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
    outline: none;
}

.settings-pi-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 8px 0 12px;
}

.settings-inline-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.settings-inline-toggle-text {
    font-size: 12.5px;
    color: var(--text-secondary);
    font-weight: 500;
}

.settings-pi-counter {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.settings-section-cta {
    width: 100%;
    margin-top: 8px;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    border-radius: var(--radius);
    background: transparent;
    border: 1px solid transparent;
    transition: all var(--transition-fast);
    text-align: left;
}

.settings-row+.settings-row {
    margin-top: 2px;
}

.settings-row:hover {
    background: rgba(var(--overlay-rgb), 0.07);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}

.settings-row-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    flex-shrink: 0;
    color: var(--text-muted);
}

.settings-row-label {
    flex: 1;
}

.settings-row:hover .settings-row-chevron {
    opacity: 1;
    transform: translateX(2px);
    transition: transform var(--transition-fast);
}

.settings-row-danger {
    color: var(--danger);
}

.settings-row-danger:hover {
    background: var(--danger-subtle);
    color: var(--danger);
    border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

.settings-row-danger .settings-row-icon {
    color: var(--danger);
    opacity: 0.9;
}

/* Collapsible password section inside the profile block */
.settings-details {
    margin: 6px 0 4px;
    border-top: 1px dashed var(--border-subtle);
    padding-top: 8px;
}

.settings-details>summary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 2px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.settings-details>summary::-webkit-details-marker {
    display: none;
}

.settings-details>summary::before {
    content: '▸';
    font-size: 9px;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
    display: inline-block;
}

.settings-details[open]>summary::before {
    transform: rotate(90deg);
}

.settings-details>summary:hover {
    color: var(--text-primary);
}

.settings-details>summary:hover::before {
    color: var(--text-primary);
}

/* Tighter form-group inside settings panel */
.sidebar-settings-body .form-group-sm {
    margin-bottom: 8px;
}

.sidebar-settings-body .form-group-sm label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 3px;
    font-weight: 500;
}

.sidebar-settings-body .form-group-sm input {
    width: 100%;
    padding: 7px 10px;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.sidebar-settings-body .form-group-sm input:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.sidebar-settings-body .form-group-sm input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
    outline: none;
}

/* Updated user-info-btn: cog hint + cleaner spacing */
.user-info-btn {
    /* override base — single flex row with cog at the end */
    gap: 10px;
}

.user-info-btn .user-info-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
    font-weight: 500;
}

.user-info-cog {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    color: var(--text-muted);
    opacity: 0.6;
    transition: opacity var(--transition-fast), color var(--transition-fast);
}

.user-info-btn:hover .user-info-cog {
    opacity: 1;
    color: var(--text-primary);
}

.sidebar.collapsed .user-info-cog {
    display: none;
}

.sidebar.collapsed .user-info-text {
    display: none;
}

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

/* ======================================================================
   Admin: Info button in models table
   ====================================================================== */
.admin-info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.admin-info-btn:hover {
    color: var(--accent);
    background: var(--accent-subtle);
}

.admin-info-btn.has-info {
    color: var(--accent);
}

.admin-info-btn svg {
    width: 14px;
    height: 14px;
}

#modelinfo-textarea {
    min-height: 140px;
    max-height: 360px;
}

#modelinfo-counter {
    margin-top: 6px;
    text-align: right;
}

/* ======================================================================
   Mobile: search/settings takeover should fill the whole sidebar
   ====================================================================== */
@media (max-width: 768px) {
    .sidebar-takeover-header {
        height: 44px;
        padding: 6px 8px 6px 14px;
    }

    .sidebar-settings-body {
        padding: 12px 10px 24px;
    }

    .settings-section {
        padding: 12px 12px 10px;
        margin-bottom: 8px;
    }

    .sidebar-pinned {
        max-height: 24vh;
    }
}

/* Image-generation mode: tint the send button so the active (sticky) mode is
   impossible to miss alongside the "Bild beschreiben…" placeholder. */
.send-btn.img-mode {
    background: var(--purple);
}

.send-btn.img-mode:hover {
    background: var(--purple-light);
}

/* Honour the OS "reduce motion" setting — neutralise animations and
   transitions for users who are sensitive to movement. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

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

.label-optional {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 11px;
}

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

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

/* Inline form error (create-user dialog etc.). */
.form-error {
    font-size: 12.5px;
    color: var(--danger);
    background: var(--danger-subtle);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    padding: 8px 12px;
    line-height: 1.4;
}

/* ── Model row meta-line (Context window + capabilities under the model name) */
.model-name-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.model-meta {
    font-size: 11px;
    color: var(--text-secondary);
    font-family: monospace;
    line-height: 1.3;
    letter-spacing: 0.01em;
}

/* A model the provider stopped advertising: flagged, removable only via the
   explicit „Entfernen" (badge + button reuse .badge-pending / .action-btn). */
.model-row-unavailable .model-name-cell,
.model-row-unavailable .display-name-cell {
    color: var(--text-muted);
}

.model-unavailable-line {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

/* Pin/unpin actions in normal chat-item action row */
.chat-item-pin {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 5px;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.chat-item-pin svg {
    width: 12px;
    height: 12px;
}

.chat-item-pin:hover {
    color: var(--purple);
    background: rgba(var(--overlay-rgb), 0.08);
}

.chat-item-pin.pinned {
    color: var(--purple);
}

.chat-item-pin.pinned:hover {
    color: var(--purple);
    background: color-mix(in srgb, var(--purple) 12%, transparent);
}

/* --- Model selector (single dropdown in the chat header) --- */
.model-selector {
    position: relative;
    display: flex;
    align-items: center;
    min-width: 0;
}

.model-select-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 320px;
    padding: 6px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.model-select-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.model-select-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: var(--z-popover);
    min-width: 260px;
    max-width: 380px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 4px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.model-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    background: none;
    border: none;
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

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

.model-menu-item.active {
    background: var(--accent-subtle);
    color: var(--accent);
}

.model-menu-item.unavailable .model-menu-name {
    opacity: 0.6;
}

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

.model-menu-badge {
    font-size: 10.5px;
    padding: 1px 6px;
    border-radius: var(--radius-pill);
    background: var(--warning-subtle);
    color: var(--warning);
    white-space: nowrap;
}

.model-menu-info,
.model-menu-default {
    display: inline-flex;
    align-items: center;
    color: var(--text-muted);
    opacity: 0.65;
}

.model-menu-default:hover {
    opacity: 1;
    color: var(--accent);
}

.model-menu-default.on {
    opacity: 1;
    color: var(--accent);
}

.model-menu-empty {
    padding: 12px;
    color: var(--text-muted);
    font-size: 12.5px;
}

/* --- Inline message editing --- */
.message-edit {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message-edit-input {
    width: 100%;
    min-height: 80px;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    color: var(--text-primary);
    font: inherit;
    resize: vertical;
}

.message-edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* --- Inline rename of a model's display name --- */
.display-name-input {
    width: 100%;
    padding: 4px 6px;
    background: var(--bg-input);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font: inherit;
}

/* --- Connection status dot --- */
.conn-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 6px;
    border-radius: 50%;
    background: var(--text-muted);
}

.conn-dot.ok { background: var(--success); }
.conn-dot.bad { background: var(--danger); }

/* --- Misc form + table helpers --- */
.form-help {
    font-size: 12.5px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0 0 10px;
}

.settings-toggle-counter {
    font-size: 11.5px;
    color: var(--text-muted);
    text-align: right;
}

.modelinfo-textarea {
    width: 100%;
    min-height: 90px;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font: inherit;
    resize: vertical;
}

.log-message {
    max-width: 520px;
    overflow-wrap: anywhere;
}

.import-users-skip {
    font-size: 12px;
    color: var(--warning);
    margin-top: 4px;
}

.admin-table thead th.sorted-asc::after { content: ' ↑'; }
.admin-table thead th.sorted-desc::after { content: ' ↓'; }

/* --- Drop target highlight for the whole chat area --- */
.chat-area.drag-over {
    outline: 2px dashed var(--accent);
    outline-offset: -8px;
    background: var(--accent-subtle);
}

/* --- Full-size image preview --- */
.image-preview-img {
    max-width: 92vw;
    max-height: 84vh;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.model-meta-unknown {
    color: var(--warning);
    cursor: help;
}

/* Checkbox in the users table — the native control, just sized to the row. */
.member-check {
    width: 15px;
    height: 15px;
    accent-color: var(--accent);
    cursor: pointer;
}
