:root {
    --bg: #0f1115;
    --bg-elevated: #171a21;
    --border: #2a2e38;
    --text: #e6e6e6;
    --text-muted: #9aa4b2;
    --accent: #6c5ce7;
    --accent-hover: #5b4bd1;
    --success: #1f7a44;
    --success-bg: #10321f;
    --success-text: #7ee6a4;
    --error: #7a2438;
    --error-bg: #3a1620;
    --error-text: #ff9fb2;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { color: #a29bfe; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Guest (Login/Register) ---- */
.guest-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.guest-wrap { width: 100%; max-width: 420px; padding: 16px; }
.auth-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px; padding: 32px; }
.auth-brand { font-size: 1.3rem; margin-bottom: 8px; }
.auth-card h1 { margin-top: 0; font-size: 1.4rem; }
.auth-switch { margin-top: 20px; font-size: .9rem; color: var(--text-muted); text-align: center; }

form label { display: block; margin: 12px 0 4px; font-size: .85rem; color: #c7cdd6; }
form input, form textarea, form select {
    width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text); font-size: .95rem; font-family: inherit;
}
form textarea { resize: vertical; }
form input[type="checkbox"] { width: auto; padding: 0; margin: 0; }
.checkbox-label { display: flex; align-items: center; gap: 8px; margin: 16px 0 4px; font-size: .9rem; color: #c7cdd6; cursor: pointer; }
form button[type="submit"], .composer button {
    margin-top: 20px; padding: 11px 20px; border-radius: 8px; border: none;
    background: var(--accent); color: white; font-size: .95rem; font-weight: 600; cursor: pointer;
}
form button[type="submit"]:hover, .composer button:hover { background: var(--accent-hover); }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: .9rem; }
.alert-error { background: var(--error-bg); border: 1px solid var(--error); color: var(--error-text); }
.alert-success { background: var(--success-bg); border: 1px solid var(--success); color: var(--success-text); }

/* ---- App shell ---- */
.app-shell { display: flex; height: 100vh; }
.sidebar {
    width: 260px; flex-shrink: 0; background: var(--bg-elevated); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 16px;
}
.sidebar-brand { font-size: 1.15rem; font-weight: 700; margin-bottom: 20px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-nav a {
    padding: 9px 12px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: .92rem;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.05); }
.sidebar-nav a.active { background: var(--accent); color: white; }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; display: flex; align-items: center; justify-content: space-between; }
.sidebar-user { font-size: .85rem; color: var(--text-muted); }

.link-button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: .85rem; padding: 0; }
.link-button:hover { color: var(--error-text); text-decoration: underline; }

.main-area { flex: 1; overflow-y: auto; }

/* ---- Chat ---- */
.chat-layout { display: flex; height: 100vh; }
.conv-list { width: 260px; flex-shrink: 0; border-right: 1px solid var(--border); padding: 16px; overflow-y: auto; }
.new-conv-btn {
    width: 100%; padding: 10px; border-radius: 8px; border: 1px dashed var(--border);
    background: transparent; color: var(--text); cursor: pointer; margin-bottom: 12px; font-size: .9rem;
}
.new-conv-btn:hover { background: rgba(255,255,255,.05); }
.conv-item {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 9px 10px; border-radius: 8px; color: var(--text); margin-bottom: 2px; text-decoration: none;
}
.conv-item:hover { background: rgba(255,255,255,.05); text-decoration: none; }
.conv-item.active { background: rgba(108,92,231,.2); }
.conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .88rem; }
.conv-delete { background: none; border: none; color: var(--text-muted); cursor: pointer; flex-shrink: 0; }
.conv-delete:hover { color: var(--error-text); }

.chat-panel { flex: 1; display: flex; flex-direction: column; height: 100vh; }
.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 18px; }
.msg { max-width: 720px; }
.msg-user { align-self: flex-end; }
.msg-role { font-size: .75rem; color: var(--text-muted); margin-bottom: 4px; }
.msg-user .msg-role { text-align: right; }
.msg-content {
    padding: 12px 16px; border-radius: 12px; line-height: 1.5; white-space: pre-wrap; font-size: .95rem;
}
.msg-user .msg-content { background: var(--accent); color: white; border-bottom-right-radius: 2px; }
.msg-assistant .msg-content { background: var(--bg-elevated); border: 1px solid var(--border); border-bottom-left-radius: 2px; }
.msg-sources { font-size: .75rem; color: var(--text-muted); margin-top: 6px; }
.empty-hint { color: var(--text-muted); text-align: center; margin-top: 40px; }

.composer { display: flex; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--border); }
.composer textarea {
    flex: 1; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--bg-elevated); color: var(--text); font-family: inherit; font-size: .95rem;
    resize: none; max-height: 160px;
}
.composer button { margin-top: 0; align-self: flex-end; }

/* ---- Generic pages ---- */
.page { padding: 32px 40px; max-width: 900px; }
.page h1 { margin-top: 0; }
.page-sub { color: var(--text-muted); font-size: .92rem; max-width: 640px; }
.card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px; padding: 24px; margin-bottom: 24px; }
.card h2 { margin-top: 0; font-size: 1rem; }
.stacked-form label:first-of-type { margin-top: 0; }

.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th, .data-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--text-muted); font-weight: 500; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.inline-form { display: inline; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; }
.badge-ready, .badge-completed { background: var(--success-bg); color: var(--success-text); }
.badge-processing, .badge-queued, .badge-running { background: rgba(108,92,231,.2); color: #b8b0ff; }
.badge-failed { background: var(--error-bg); color: var(--error-text); }

.stat-row { display: flex; gap: 16px; margin-bottom: 24px; }
.stat-tile { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px; padding: 20px 24px; flex: 1; }
.stat-value { font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: .85rem; }

.code-block { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-size: .8rem; overflow-x: auto; }
.prose-block { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 16px; font-size: .9rem; line-height: 1.6; white-space: pre-wrap; }
.hint { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }

/* ---- Responsive: mobiler Header + Drawer-Navigation ---- */
.mobile-topbar {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    position: sticky;
    top: 0;
    z-index: 20;
}
.mobile-topbar-brand { font-weight: 700; }
.mobile-toggle {
    background: none; border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); padding: 8px 12px; font-size: .95rem; cursor: pointer; flex-shrink: 0;
}
.mobile-toggle:hover { background: rgba(255,255,255,.05); }

.sidebar-brand { display: flex; align-items: center; justify-content: space-between; }
.sidebar-close {
    display: none; background: none; border: none; color: var(--text-muted);
    font-size: 1.1rem; cursor: pointer; padding: 4px;
}

.sidebar-overlay {
    display: none;
    position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 25;
}
.sidebar-overlay.visible { display: block; }

.chat-topbar { display: none; padding: 10px 16px; border-bottom: 1px solid var(--border); }

.main-area { display: flex; flex-direction: column; }

/* Tabellen auf schmalen Bildschirmen horizontal scrollbar statt umbrechen */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---- Tablet ---- */
@media (max-width: 1024px) {
    .sidebar { width: 220px; }
    .conv-list { width: 220px; }
    .page { padding: 24px; }
}

/* ---- Mobil (Smartphone) ---- */
@media (max-width: 768px) {
    .mobile-topbar { display: flex; }

    .sidebar-close { display: block; }
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; width: 260px; max-width: 82vw;
        transform: translateX(-100%); transition: transform .2s ease; z-index: 30;
    }
    .sidebar.sidebar-open { transform: translateX(0); }

    .main-area { width: 100%; }

    /* Chat-Seite: Konversationsliste als eigener Drawer */
    .chat-layout { height: auto; flex: 1; min-height: 0; flex-direction: column; }
    .chat-topbar { display: block; }
    .conv-list {
        position: fixed; top: 0; left: 0; bottom: 0; width: 260px; max-width: 82vw;
        background: var(--bg); border-right: 1px solid var(--border);
        transform: translateX(-100%); transition: transform .2s ease; z-index: 30;
    }
    .conv-list.conv-list-open { transform: translateX(0); }
    .chat-panel { height: auto; flex: 1; min-height: 0; }
    .messages { min-height: 0; padding: 16px; }
    .msg { max-width: 100%; }
    .composer { padding: 12px 16px; }

    .page { padding: 20px 16px; }
    .card { padding: 16px; }

    .stat-row { flex-wrap: wrap; }
    .stat-tile { flex: 1 1 45%; padding: 16px; }
}

@media (max-width: 480px) {
    .stat-tile { flex: 1 1 100%; }
    .auth-card { padding: 20px; }
    .composer { flex-direction: column; align-items: stretch; }
    .composer button { align-self: stretch; }
}
