:root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e6e8ec;
    --text-dim: #9aa3af;
    --accent: #4f7cff;
    --accent-hover: #3e68e0;
    --danger: #e5484d;
    --success: #30a46c;
    --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Auth pages */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 380px;
}
.auth-card h1 { margin: 0 0 1rem; font-size: 1.4rem; }
.auth-card label {
    display: block;
    margin-bottom: 0.85rem;
    font-size: 0.9rem;
    color: var(--text-dim);
}
.auth-card input {
    display: block;
    width: 100%;
    margin-top: 0.3rem;
    padding: 0.65rem 0.75rem;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.55rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    font-family: inherit;
    text-decoration: none;
}
.btn:hover { background: #262b35; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.alert {
    padding: 0.7rem 0.9rem;
    margin-bottom: 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
}
.alert.error { background: rgba(229, 72, 77, 0.15); border: 1px solid var(--danger); }
.alert.info { background: rgba(79, 124, 255, 0.12); border: 1px solid var(--accent); }

.muted { color: var(--text-dim); font-size: 0.9rem; }

/* App layout */
body.app {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: 100vh;
    overflow: hidden;
}
body.app.with-canvas {
    grid-template-columns: 280px minmax(360px, 1fr) minmax(480px, 1.3fr);
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: 100%;
}
.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.sidebar-header h1 { margin: 0; font-size: 1.1rem; }
.conversation-list {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding: 0.5rem;
}
.conversation-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.7rem;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 2px;
}
.conversation-item:hover { background: var(--surface-2); color: var(--text); }
.conversation-item.active { background: var(--surface-2); color: var(--text); }
.conversation-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item .delete {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 0.25rem;
    opacity: 0;
}
.conversation-item:hover .delete { opacity: 1; }
.conversation-item .delete:hover { color: var(--danger); }

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
}
.user-badge { display: block; color: var(--text-dim); margin-bottom: 0.3rem; }
.footer-links { display: flex; flex-direction: column; gap: 0.4rem; }
.footer-links a { color: var(--text-dim); text-decoration: none; padding: 0.2rem 0; }
.footer-links a:hover { color: var(--text); }

/* Chat */
.chat {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}
.chat-header {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.model-select { font-size: 0.9rem; color: var(--text-dim); }
.model-select select {
    margin-left: 0.4rem;
    padding: 0.35rem 0.5rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
}
.search-indicator {
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-dim);
}
.search-indicator.on { color: var(--success); border-color: var(--success); }

.messages {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding: 1.5rem;
}
.empty-state {
    max-width: 600px;
    margin: 4rem auto;
    text-align: center;
    color: var(--text-dim);
}
.empty-state h2 { color: var(--text); margin-bottom: 0.5rem; }

.message {
    max-width: 820px;
    margin: 0 auto 1.25rem;
    padding: 0.8rem 1rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
}
.message.user {
    background: var(--surface-2);
    border-color: #2e3444;
}
.message .role {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    margin-bottom: 0.35rem;
}
.message .content { white-space: pre-wrap; word-wrap: break-word; }
.message .content pre {
    background: #0b0d12;
    padding: 0.75rem;
    border-radius: 6px;
    overflow-x: auto;
    border: 1px solid var(--border);
}
.message .content code { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 0.9em; }
.message .searches {
    margin-top: 0.75rem;
    padding-top: 0.6rem;
    border-top: 1px dashed var(--border);
    font-size: 0.82rem;
    color: var(--text-dim);
}
.message .searches a { color: var(--accent); }
.message.typing .content::after {
    content: '▍';
    animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.chat-input {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.input-box {
    max-width: 820px;
    margin: 0 auto;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0.5rem 0.75rem 0.5rem;
}
.input-box textarea {
    width: 100%;
    background: transparent;
    color: var(--text);
    border: none;
    outline: none;
    font-family: inherit;
    font-size: 0.95rem;
    resize: none;
    min-height: 2.4rem;
    max-height: 220px;
    padding: 0.35rem 0;
}
.input-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.35rem;
    border-top: 1px dashed transparent;
}
.input-actions .spacer { flex: 1; }
.icon-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-dim);
    font-size: 1.15rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
}
.icon-btn:hover:not([disabled]) { background: var(--surface); color: var(--text); }
.icon-btn[disabled] { opacity: 0.4; cursor: not-allowed; }

/* Bildgenerierung */
.img-gen-wrap { position: relative; display: inline-block; }
.img-gen-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    min-width: 240px;
    z-index: 50;
    padding: 6px;
}
.img-gen-menu[hidden] { display: none; }
.img-gen-title {
    font-size: 0.75rem;
    color: var(--text-dim);
    padding: 4px 8px 2px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.img-gen-menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--text);
    padding: 0.5rem 0.7rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: inherit;
}
.img-gen-menu button:hover { background: var(--surface-2); }

.icon-btn#imageGenBtn.active {
    background: rgba(168, 85, 247, 0.18);
    color: #c4b5fd;
    border-color: rgba(168, 85, 247, 0.45);
}

.img-gen-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0 0 0.4rem;
    padding: 0.35rem 0.6rem;
    background: rgba(168, 85, 247, 0.12);
    border: 1px solid rgba(168, 85, 247, 0.35);
    border-radius: 999px;
    color: #c4b5fd;
    font-size: 0.82rem;
}
.img-gen-status[hidden] { display: none; }
.img-gen-status strong { color: var(--text); font-weight: 600; }
.img-gen-status .icon-btn {
    font-size: 0.9rem;
    padding: 0.1rem 0.4rem;
    color: #c4b5fd;
}
.img-gen-status .icon-btn:hover:not([disabled]) {
    background: rgba(168, 85, 247, 0.25);
    color: var(--text);
}

/* In-Nachricht Bilder */
.message .generated-image {
    margin-top: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    max-width: 640px;
    background: var(--surface);
}
.message .generated-image img { display: block; width: 100%; height: auto; }
.message .generated-image .gi-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.4rem 0.7rem;
    font-size: 0.78rem;
    color: var(--text-dim);
    background: var(--surface-2);
    border-top: 1px solid var(--border);
}
.message .generated-image .gi-meta a { color: var(--text-dim); }
.message .generated-image .gi-meta a:hover { color: var(--text); }
.message .generated-image.pending {
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-size: 0.9rem;
    background: repeating-linear-gradient(135deg, var(--surface), var(--surface) 10px, var(--surface-2) 10px, var(--surface-2) 20px);
    animation: giPulse 2s ease-in-out infinite;
}
.message .generated-image.pending.portrait { aspect-ratio: 2 / 3; }
.message .generated-image.pending.landscape { aspect-ratio: 3 / 2; }
@keyframes giPulse {
    0%, 100% { opacity: 0.75; }
    50%      { opacity: 1; }
}

.message .gen-files {
    margin-top: 0.75rem;
    padding-top: 0.6rem;
    border-top: 1px dashed var(--border);
    font-size: 0.82rem;
    color: var(--text-dim);
}
.message .gen-files strong { display: block; margin-bottom: 0.4rem; }
.message .gen-files-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.message .gen-file {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.7rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    transition: background 0.12s, border-color 0.12s;
    max-width: 100%;
}
.message .gen-file:hover {
    background: var(--surface-2);
    border-color: var(--accent);
}
.message .gen-file .gf-icon { font-size: 1.1rem; }
.message .gen-file .gf-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}
.message .gen-file .gf-size { flex-shrink: 0; font-size: 0.75rem; }

.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding-bottom: 0.3rem;
}
.attachments:empty { display: none; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    font-size: 0.82rem;
    color: var(--text-dim);
}
.chip.loading { opacity: 0.7; }
.chip button {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 0.15rem;
    margin-left: 0.2rem;
}
.chip button:hover { color: var(--danger); }

.msg-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}
.att-chip {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.25rem 0.5rem;
    font-size: 0.85rem;
    color: var(--text-dim);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
.att-chip img {
    max-width: 220px;
    max-height: 180px;
    border-radius: 6px;
    display: block;
}

.msg-actions {
    display: flex;
    gap: 0.3rem;
    margin-top: 0.5rem;
    opacity: 0;
    transition: opacity 0.15s;
}
.message:hover .msg-actions { opacity: 1; }
.ghost-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.78rem;
    padding: 0.22rem 0.55rem;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
}
.ghost-btn:hover { color: var(--text); background: var(--surface-2); }

.tool-pill {
    display: inline-block;
    background: rgba(79, 124, 255, 0.12);
    border: 1px solid var(--accent);
    color: var(--accent);
    border-radius: 999px;
    padding: 0.2rem 0.7rem;
    font-size: 0.82rem;
    margin: 0.35rem 0;
}

.message .content pre {
    position: relative;
    padding-top: 2rem;
}
.message .content pre .copy-btn {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.72rem;
    padding: 0.2rem 0.5rem;
    border-radius: 5px;
    cursor: pointer;
    font-family: inherit;
}
.message .content pre .copy-btn:hover { color: var(--text); }

.message .content p { margin: 0.3rem 0; }
.message .content ul, .message .content ol { margin: 0.3rem 0; padding-left: 1.25rem; }
.message .content table { border-collapse: collapse; margin: 0.5rem 0; }
.message .content th, .message .content td {
    border: 1px solid var(--border);
    padding: 0.3rem 0.6rem;
    font-size: 0.9em;
}
.message .content blockquote {
    border-left: 3px solid var(--border);
    padding-left: 0.8rem;
    color: var(--text-dim);
    margin: 0.4rem 0;
}

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

.drop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 17, 21, 0.85);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    z-index: 1000;
    border: 3px dashed var(--accent);
    pointer-events: none;
}
.drop-overlay[hidden] { display: none; }

/* Admin */
.admin-page { padding: 0; }
.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.admin-header h1 { margin: 0; font-size: 1.1rem; }
.admin-main {
    max-width: 760px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}
.admin-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.admin-form section { margin-bottom: 1.5rem; }
.admin-form section:last-child { margin-bottom: 1rem; }
.admin-form h2 { font-size: 1rem; margin: 0 0 0.75rem; color: var(--text); }
.admin-form h3 { font-size: 0.95rem; margin: 1.25rem 0 0.5rem; }
.admin-form label {
    display: block;
    margin-bottom: 0.8rem;
    font-size: 0.9rem;
    color: var(--text-dim);
}
.admin-form label.checkbox {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.admin-form input[type="text"],
.admin-form input[type="password"],
.admin-form select,
.admin-form textarea {
    display: block;
    width: 100%;
    margin-top: 0.3rem;
    padding: 0.55rem 0.7rem;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
}

.user-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}
.user-table th, .user-table td {
    padding: 0.6rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}
.user-table th { color: var(--text-dim); font-weight: 500; }

.inline-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.inline-form input[type="text"], .inline-form input[type="password"] {
    flex: 1;
    padding: 0.5rem 0.7rem;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    min-width: 150px;
}
.checkbox.inline { display: inline-flex; color: var(--text-dim); font-size: 0.9rem; gap: 0.3rem; }

/* Prompts */
.two-col {
    display: grid;
    grid-template-columns: 1fr 100px;
    gap: 0.75rem;
}
.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.prompt-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.prompt-row {
    display: flex;
    gap: 0.75rem;
    padding: 0.7rem 0.85rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    align-items: flex-start;
}
.prompt-icon {
    font-size: 1.4rem;
    width: 1.8rem;
    text-align: center;
    flex-shrink: 0;
}
.prompt-main { flex: 1; min-width: 0; }
.prompt-title {
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.prompt-slug {
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 0.78rem;
    color: var(--accent);
    background: rgba(79, 124, 255, 0.12);
    padding: 0.05rem 0.4rem;
    border-radius: 4px;
}
.prompt-preview {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-top: 0.2rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.prompt-actions {
    display: flex;
    gap: 0.3rem;
    flex-shrink: 0;
}
.ghost-btn.danger { color: var(--danger); border-color: rgba(229, 72, 77, 0.4); }
.ghost-btn.danger:hover { background: rgba(229, 72, 77, 0.12); }

/* Prompt picker modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 800;
}
.modal-backdrop[hidden] { display: none; }
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: min(620px, 92vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 1rem; }
.modal-body {
    padding: 0.75rem 1rem 1rem;
    overflow-y: auto;
    min-height: 0;
}
.modal-search {
    width: 100%;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.55rem 0.7rem;
    margin-bottom: 0.75rem;
    font-family: inherit;
    font-size: 0.95rem;
}
.prompt-row.clickable { cursor: pointer; }
.prompt-row.clickable:hover { border-color: var(--accent); }

/* Slash-command autocomplete */
.slash-pop {
    position: absolute;
    z-index: 500;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.3rem;
    max-height: 260px;
    overflow-y: auto;
    min-width: 280px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.slash-pop[hidden] { display: none; }
.slash-item {
    display: flex;
    gap: 0.5rem;
    padding: 0.45rem 0.6rem;
    border-radius: 6px;
    cursor: pointer;
    align-items: center;
}
.slash-item.active, .slash-item:hover { background: var(--surface-2); }
.slash-item .s-icon { width: 1.2rem; text-align: center; }
.slash-item .s-main { flex: 1; min-width: 0; }
.slash-item .s-title {
    font-size: 0.88rem;
    color: var(--text);
    display: flex;
    gap: 0.4rem;
    align-items: center;
}
.slash-item .s-slug {
    font-family: ui-monospace, monospace;
    font-size: 0.75rem;
    color: var(--accent);
}
.slash-item .s-preview {
    font-size: 0.78rem;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Assistants */
.assistant-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
}
.assistant-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    position: relative;
    transition: border-color 0.15s, transform 0.05s;
}
.assistant-card.clickable { cursor: pointer; }
.assistant-card.clickable:hover { border-color: var(--accent); }
.assistant-card.clickable:active { transform: scale(0.98); }
.assistant-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(79, 124, 255, 0.25);
}
.assistant-emoji {
    font-size: 1.8rem;
    line-height: 1;
}
.assistant-name {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--text);
}
.assistant-desc {
    font-size: 0.82rem;
    color: var(--text-dim);
    min-height: 1em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.assistant-actions {
    display: flex;
    gap: 0.3rem;
    margin-top: 0.4rem;
}
.assistant-actions:empty { display: none; }

/* Empty-State: Assistenten-Auswahl */
.assistant-picker {
    margin-top: 1.5rem;
    text-align: left;
}
.assistant-picker h3 {
    margin: 0 0 0.6rem;
    font-size: 0.95rem;
    color: var(--text-dim);
    text-align: center;
}
.assistant-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.6rem;
    max-width: 720px;
    margin: 0 auto;
}
.assistant-picker .muted { text-align: center; }

/* Canvas pane (ChatGPT-Canvas-Style) */
.canvas-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: 100%;
    border-left: 1px solid var(--border);
    background: var(--surface);
    overflow: hidden;
}
.canvas-pane[hidden] { display: none; }
.canvas-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
.canvas-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1 1 0;
    min-width: 0;
}
.canvas-title {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 4px 6px;
    border-radius: 6px;
    width: 100%;
    outline: none;
}
.canvas-title:hover,
.canvas-title:focus { border-color: var(--border); background: var(--surface); }
.canvas-meta {
    display: flex;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-dim);
    padding: 0 6px;
}
.canvas-badge {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 1px 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.68rem;
}
.canvas-version { color: var(--text-dim); }
.canvas-save { font-size: 0.72rem; }
.canvas-save.dirty { color: var(--accent); }
.canvas-save.saving { color: var(--text-dim); }
.canvas-save.saved { color: var(--success); }
.canvas-save.error { color: var(--danger); }
.canvas-actions {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
    align-items: center;
}
.canvas-download { position: relative; }
.canvas-download-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    min-width: 220px;
    z-index: 50;
    padding: 4px;
}
.canvas-download-menu[hidden] { display: none; }
.canvas-download-menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--text);
    padding: 0.55rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: inherit;
}
.canvas-download-menu button:hover { background: var(--surface-2); }
.canvas-editor {
    flex: 1 1 0;
    width: 100%;
    min-height: 0;
    padding: 1rem 1.25rem;
    background: var(--bg);
    color: var(--text);
    border: none;
    outline: none;
    resize: none;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.92rem;
    line-height: 1.55;
    tab-size: 4;
}
.canvas-editor.flash {
    animation: canvasFlash 0.8s ease-out;
}
@keyframes canvasFlash {
    0%   { background: rgba(79, 124, 255, 0.18); }
    100% { background: var(--bg); }
}

/* Canvas Auswahl-Toolbar */
.canvas-sel-toolbar {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.55rem 0.75rem 0.7rem;
    background: var(--surface-2);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.canvas-sel-toolbar[hidden] { display: none; }
.canvas-sel-toolbar.busy { opacity: 0.75; pointer-events: none; }
.canvas-sel-toolbar .csel-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}
.canvas-sel-toolbar .csel-presets button {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 999px;
    padding: 0.25rem 0.7rem;
    font-size: 0.8rem;
    cursor: pointer;
    font-family: inherit;
}
.canvas-sel-toolbar .csel-presets button:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.canvas-sel-toolbar .csel-presets button.active {
    background: rgba(79, 124, 255, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}
.canvas-sel-toolbar .csel-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.canvas-sel-toolbar .csel-input {
    flex: 1;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.45rem 0.6rem;
    font-family: inherit;
    font-size: 0.88rem;
    outline: none;
}
.canvas-sel-toolbar .csel-input:focus { border-color: var(--accent); }
.canvas-sel-status {
    font-size: 0.78rem;
    color: var(--text-dim);
}
.canvas-sel-status.error { color: var(--danger); }
.canvas-sel-status.ok    { color: var(--success); }

.search-test {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.5rem;
}
.search-test-out {
    padding: 0.55rem 0.7rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 0.85rem;
    line-height: 1.45;
    color: var(--text);
}
.search-test-out.ok    { border-color: var(--success); background: rgba(34, 197, 94, 0.08); }
.search-test-out.error { border-color: var(--danger);  background: rgba(248, 113, 113, 0.08); }
.search-test-out[hidden] { display: none; }

@media (max-width: 1200px) {
    body.app.with-canvas {
        grid-template-columns: minmax(360px, 1fr) minmax(420px, 1.2fr);
    }
    body.app.with-canvas .sidebar { display: none; }
}

@media (max-width: 720px) {
    body.app { grid-template-columns: 1fr; }
    body.app.with-canvas { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    body.app.with-canvas .chat { display: none; }
}

/* ── Transcribe page ────────────────────────────────────────── */
.transcribe-textarea {
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 0.9rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    resize: vertical;
}
.transcribe-meta {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 0.4rem;
}
.transcribe-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}
.transcribe-row:last-child { border-bottom: none; }
.transcribe-row-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.transcribe-filename {
    font-weight: 600;
    word-break: break-all;
}
.transcribe-preview {
    font-size: 0.85rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.transcribe-row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
    flex-shrink: 0;
}
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
}
.spinner.hidden { display: none; }

/* Wissensbasis (RAG) */
.icon-btn.kb-toggle.active {
    background: rgba(56, 189, 248, 0.18);
    color: var(--accent);
    border-color: rgba(56, 189, 248, 0.45);
}
.message .kb-sources {
    margin-top: 0.6rem;
    padding: 0.5rem 0.75rem;
    border-left: 3px solid var(--accent);
    background: rgba(56, 189, 248, 0.07);
    border-radius: 6px;
    font-size: 0.82rem;
    color: var(--text-dim);
}
.message .kb-sources strong { color: var(--text); font-weight: 600; }
.message .kb-sources ul { margin: 0.35rem 0 0; padding-left: 1.1rem; }
.message .kb-sources li { margin: 0.15rem 0; }

.admin-nav { display: flex; gap: 0.5rem; align-items: center; }

.kb-upload { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.kb-status {
    margin-top: 0.6rem;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.9rem;
    border: 1px solid var(--border);
    background: var(--surface-2);
}
.kb-status.ok  { border-color: rgba(34, 197, 94, 0.4);  background: rgba(34, 197, 94, 0.1); }
.kb-status.err { border-color: rgba(239, 68, 68, 0.4);  background: rgba(239, 68, 68, 0.1); }
.kb-status.info { border-color: rgba(56, 189, 248, 0.4); background: rgba(56, 189, 248, 0.1); }

.kb-table th, .kb-table td { font-size: 0.88rem; }
.kb-table a { color: var(--accent); text-decoration: none; }
.kb-table a:hover { text-decoration: underline; }
.btn.danger.armed {
    background: #ef4444;
    border-color: #ef4444;
    color: #fff;
    animation: armPulse 0.9s ease-in-out infinite alternate;
}
@keyframes armPulse { from { box-shadow: 0 0 0 rgba(239,68,68,0); } to { box-shadow: 0 0 0 4px rgba(239,68,68,0.25); } }

.retention-hint {
    margin-top: 1.2rem;
    padding: 0.55rem 0.8rem;
    border-radius: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-dim);
    display: inline-block;
}
