/* PP Energy Browser - Discord-Archiv. Bewusst nur Systemschriften, keine externen Ressourcen. */
:root {
    color-scheme: dark;
    --bg: #14161b;
    --bg-raised: #1b1e25;
    --bg-sunken: #0f1115;
    --bg-hover: #20242c;
    --line: #2a2f3a;
    --line-strong: #3a4150;
    --ink: #e4e1d8;
    --ink-dim: #9a9890;
    --ink-faint: #6c6b66;
    --accent: #e0a64b;
    --accent-ink: #1b1408;
    --accent-soft: rgba(224, 166, 75, .14);
    --link: #8fb8e8;
    --mention: rgba(143, 184, 232, .16);
    --danger: #e0715b;
    --ok: #7fbf7a;
    --radius: 8px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 var(--font);
    min-height: 100vh;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6rem; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
code, pre { font-family: var(--mono); }

/* ---------- Kopfzeile ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .6rem max(16px, 2vw);
    padding-top: calc(.6rem + env(safe-area-inset-top, 0px));
    background: rgba(20, 22, 27, .92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}
.brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--ink);
    font-weight: 700;
    letter-spacing: .02em;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: var(--accent);
    color: var(--accent-ink);
    font-size: .95rem;
}
.brand-mark svg { width: 20px; height: 20px; display: block; }
.brand small { color: var(--ink-faint); font-weight: 400; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a {
    color: var(--ink-dim);
    padding: .3rem .65rem;
    border-radius: 6px;
}
.topbar nav a:hover, .topbar nav a.active { background: var(--bg-hover); color: var(--ink); text-decoration: none; }
.topbar .quicksearch { margin-left: auto; display: flex; gap: .4rem; }
.topbar .quicksearch input { width: min(320px, 50vw); }
.topbar .logout { color: var(--ink-faint); font-size: .9rem; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 1.25rem max(16px, 2vw) 4rem; }
.narrow { max-width: 900px; }
.wrap-wide { max-width: 1920px; }

/* ---------- Formulare & Buttons ---------- */
input[type=text], input[type=search], input[type=password], input[type=date], select, textarea {
    background: var(--bg-sunken);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    padding: .45rem .6rem;
    font: inherit;
    min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
label { display: block; font-size: .85rem; color: var(--ink-dim); margin-bottom: .25rem; }
.check { display: flex; align-items: center; gap: .45rem; color: var(--ink); font-size: .92rem; margin: .3rem 0; }
.btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    border: 1px solid var(--line-strong);
    background: var(--bg-raised);
    color: var(--ink);
    padding: .42rem .85rem;
    border-radius: 6px;
    font: inherit;
    font-size: .92rem;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: #ebb562; }
.btn-danger { color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #1a0b07; font-weight: 600; }
.btn-danger-solid:hover { background: #ea8a77; }
.btn-small { padding: .2rem .55rem; font-size: .82rem; }
.btn[disabled] { opacity: .5; cursor: default; }
.inline-form { display: inline; }

/* ---------- Karten, Hinweise ---------- */
.panel {
    background: var(--bg-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.25rem;
}
.panel > h2:first-child { margin-top: 0; }
.muted { color: var(--ink-dim); }
.faint { color: var(--ink-faint); font-size: .88rem; }
.flash { padding: .65rem 1rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid; }
.flash-success { border-color: rgba(127, 191, 122, .4); background: rgba(127, 191, 122, .08); }
.flash-error { border-color: rgba(224, 113, 91, .45); background: rgba(224, 113, 91, .08); }
.notice { border-left: 3px solid var(--accent); padding: .5rem .9rem; background: var(--accent-soft); border-radius: 0 6px 6px 0; margin: .75rem 0; font-size: .92rem; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--ink-dim); }
.empty .big { font-size: 2.5rem; display: block; margin-bottom: .5rem; }
.badge {
    display: inline-block;
    padding: 0 .4rem;
    border-radius: 4px;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .03em;
    background: var(--bg-hover);
    color: var(--ink-dim);
    vertical-align: middle;
}
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-bot { background: #4b5bbd; color: #fff; }
.status-queued { color: var(--ink-dim); }
.status-running { color: var(--accent); }
.status-completed { color: var(--ok); }
.status-failed { color: var(--danger); }
.status-cancelled { color: var(--ink-faint); }

table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.list th, table.list td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { color: var(--ink-dim); font-weight: 500; font-size: .82rem; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

/* ---------- Übersicht ---------- */
.stats { display: flex; gap: 1.5rem; flex-wrap: wrap; color: var(--ink-dim); margin: -.25rem 0 1.25rem; }
.stats strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.guild-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); gap: 1rem; }
.guild { background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.guild-head { display: flex; gap: .75rem; align-items: center; padding: .9rem 1rem; border-bottom: 1px solid var(--line); }
.guild-head h2 { margin: 0; font-size: 1.05rem; }
.guild-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    flex: none;
    object-fit: cover;
    display: grid;
    place-items: center;
    background: var(--bg-hover);
    color: var(--ink-dim);
    font-weight: 700;
}
.cat { padding: .4rem 0 .2rem; }
.cat-name { padding: .2rem 1rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-faint); font-weight: 600; }
.chan {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    padding: .28rem 1rem;
    color: var(--ink-dim);
}
.chan:hover { background: var(--bg-hover); color: var(--ink); text-decoration: none; }
.chan .icon { width: 1.1rem; text-align: center; color: var(--ink-faint); flex: none; }
.chan .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.chan .meta { font-size: .78rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chan.thread { padding-left: 2.4rem; font-size: .92rem; }
.chan-row { display: flex; align-items: center; }
.chan-row .chan { flex: 1; min-width: 0; }
.chan-del { padding: .2rem .7rem .2rem .3rem; color: var(--ink-faint); opacity: 0; font-size: .85rem; }
.chan-row:hover .chan-del, .chan-del:focus-visible { opacity: 1; }
.chan-del:hover { color: var(--danger); text-decoration: none; }
@media (hover: none) { .chan-del { opacity: .6; } }
.delete-list { margin: .75rem 0; }
.delete-form { display: grid; gap: .75rem; margin-top: 1rem; }
details.threads > summary { padding: .1rem 1rem .1rem 2.4rem; font-size: .8rem; color: var(--ink-faint); cursor: pointer; list-style: none; }
details.threads > summary::before { content: "▸ "; }
details.threads[open] > summary::before { content: "▾ "; }

/* ---------- Kanalansicht ---------- */
.channel-layout { display: grid; grid-template-columns: 310px minmax(0, 1fr) 340px; gap: 1.25rem; align-items: start; }
.channel-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: .25rem; }
.channel-head h1 { margin: 0; font-size: 1.3rem; }
.breadcrumb { font-size: .85rem; color: var(--ink-faint); margin-bottom: .35rem; }
.breadcrumb a { color: var(--ink-dim); }
.topic { color: var(--ink-dim); font-size: .92rem; margin: .25rem 0 0; }
.sidebar { position: sticky; top: 70px; display: flex; flex-direction: column; gap: 1rem; max-height: calc(100vh - 90px); overflow-y: auto; }
.sidebar .panel { margin: 0; padding: .9rem 1rem; }
.sidebar h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-faint); margin-bottom: .5rem; }
.sidebar form { display: flex; flex-direction: column; gap: .5rem; }
.sidebar input:not([type=checkbox]), .sidebar select { width: 100%; }
.sidebar label { margin: 0; }
.sidebar .row { display: flex; gap: .4rem; }
.sidebar .row > * { flex: 1; min-width: 0; }
.sidebar .thread-link { display: block; padding: .2rem 0; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pager { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin: .75rem 0; }
.pager .group { display: flex; gap: .4rem; flex-wrap: wrap; }

.messages { background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem 0; }
.day-sep {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin: .9rem 1rem .3rem;
    color: var(--ink-faint);
    font-size: .78rem;
    font-weight: 600;
}
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.msg { padding: .15rem 1rem; position: relative; }
.msg:not(.msg--grouped) { margin-top: .55rem; }
.msg:hover { background: rgba(255, 255, 255, .025); }
.msg--hl { background: var(--accent-soft) !important; box-shadow: inset 3px 0 0 var(--accent); }
.msg-row { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: .85rem; }
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: .95rem;
    color: #fff;
    user-select: none;
}
.avatar-small { width: 18px; height: 18px; font-size: .6rem; display: inline-grid; vertical-align: -3px; }
.msg-gutter .stamp { display: block; text-align: right; font-size: .68rem; color: var(--ink-faint); opacity: 0; padding-top: .2rem; }
.msg:hover .msg-gutter .stamp { opacity: 1; }
.msg-head { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.msg-author { font-weight: 600; color: var(--ink); }
.msg-head time, .msg-head .time { font-size: .75rem; color: var(--ink-faint); }
.msg-head a.time:hover { color: var(--ink-dim); }
.msg-edited { font-size: .7rem; color: var(--ink-faint); }
.msg-content { overflow-wrap: anywhere; white-space: normal; }
.msg-system { color: var(--ink-dim); font-size: .9rem; padding: .25rem 0 .25rem 55px; }
.msg-system .arrow { color: var(--ok); margin-right: .35rem; }
.msg-reply { display: flex; align-items: center; gap: .4rem; font-size: .82rem; color: var(--ink-dim); margin: 0 0 .1rem 20px; min-width: 0; }
.msg-reply::before { content: ""; width: 28px; height: 10px; border-left: 2px solid var(--line-strong); border-top: 2px solid var(--line-strong); border-top-left-radius: 6px; margin-top: 8px; flex: none; }
.msg-reply .snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.msg-reply .who { font-weight: 600; color: var(--ink); white-space: nowrap; }
.msg-forward { border-left: 3px solid var(--line-strong); padding-left: .7rem; margin: .25rem 0; }
.msg-forward .label { font-size: .75rem; color: var(--ink-faint); font-style: italic; }
.search-context { font-size: .8rem; color: var(--ink-faint); padding: .6rem 1rem 0 calc(1rem + 55px); }
.search-context a { color: var(--ink-dim); }

/* Markdown */
.md-code { background: var(--bg-sunken); border: 1px solid var(--line); border-radius: 4px; padding: 0 .3rem; font-size: .88em; }
.md-codeblock { background: var(--bg-sunken); border: 1px solid var(--line); border-radius: 6px; padding: .6rem .75rem; margin: .3rem 0; overflow-x: auto; font-size: .86rem; white-space: pre; }
.md-quote { border-left: 4px solid var(--line-strong); margin: .2rem 0; padding: 0 0 0 .7rem; color: var(--ink); }
.md-mention { background: var(--mention); color: var(--link); border-radius: 3px; padding: 0 .15rem; font-weight: 500; }
.md-spoiler { background: #000; color: transparent; border-radius: 3px; cursor: pointer; transition: color .1s; }
.md-spoiler.revealed { background: var(--bg-hover); color: inherit; }
.md-emoji { color: var(--ink-dim); }
.md-emoji-img { height: 1.375em; width: auto; vertical-align: -.35em; object-fit: contain; }
.msg-content--jumbo { font-size: 2.4rem; line-height: 1.25; }
.msg-content--jumbo .md-emoji-img, .md-emoji-img.md-jumbo { height: 3rem; vertical-align: middle; }
.reaction .md-emoji-img { height: 1.1rem; vertical-align: -.25rem; }
.sticker-img { display: block; width: 160px; height: 160px; object-fit: contain; margin-top: .3rem; }
.md-h { display: block; font-weight: 700; margin: .3rem 0 .1rem; }
.md-h1 { font-size: 1.35rem; }
.md-h2 { font-size: 1.18rem; }
.md-h3 { font-size: 1.05rem; }
.md-subtext { display: block; color: var(--ink-faint); font-size: .8rem; }
.md-time { background: var(--bg-hover); border-radius: 3px; padding: 0 .2rem; }
mark { background: rgba(224, 166, 75, .35); color: inherit; border-radius: 2px; }

/* Dateien */
.files { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .35rem; }
.file-img { display: block; border-radius: 6px; overflow: hidden; background: var(--bg-sunken); line-height: 0; max-width: min(420px, 100%); }
.file-img img { max-height: 320px; width: auto; max-width: 100%; height: auto; object-fit: contain; }
.files video { max-width: min(480px, 100%); max-height: 320px; border-radius: 6px; background: #000; }
.files audio { width: min(420px, 100%); }
.file-card {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .75rem;
    border: 1px solid var(--line);
    background: var(--bg-sunken);
    border-radius: 6px;
    max-width: 420px;
    min-width: 0;
}
.file-card .ico { font-size: 1.4rem; }
.file-card .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.file-card .fmeta { font-size: .75rem; color: var(--ink-faint); }
.file-card.missing { opacity: .7; }

/* Embeds */
.embed {
    border-left: 4px solid var(--line-strong);
    background: var(--bg-sunken);
    border-radius: 4px;
    padding: .55rem .8rem;
    margin-top: .35rem;
    max-width: 520px;
    font-size: .9rem;
}
.embed-provider { font-size: .75rem; color: var(--ink-faint); }
.embed-author { font-size: .82rem; font-weight: 600; }
.embed-title { font-weight: 600; display: block; margin: .1rem 0; }
.embed-desc { color: var(--ink-dim); }
.embed-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .4rem .8rem; margin-top: .4rem; }
.embed-fields .fname { font-weight: 600; font-size: .82rem; }
.embed-footer { font-size: .74rem; color: var(--ink-faint); margin-top: .35rem; }

.reactions { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .3rem; }
.reaction { border: 1px solid var(--line); background: var(--bg-sunken); border-radius: 6px; padding: 0 .45rem; font-size: .85rem; }
.reaction b { font-weight: 600; color: var(--ink-dim); margin-left: .2rem; font-size: .78rem; }
.sticker { display: inline-block; border: 1px dashed var(--line-strong); padding: .2rem .5rem; border-radius: 6px; font-size: .85rem; color: var(--ink-dim); margin-top: .3rem; }

/* Galerie */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(46%, 180px), 1fr)); gap: .5rem; }
.gallery a, .gallery .tile { position: relative; display: block; aspect-ratio: 1; background: var(--bg-sunken); border-radius: 6px; overflow: hidden; }
.gallery img, .gallery video { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery .tile-meta {
    position: absolute;
    inset: auto 0 0 0;
    padding: .3rem .45rem;
    background: linear-gradient(transparent, rgba(0, 0, 0, .75));
    color: #fff;
    font-size: .72rem;
    opacity: 0;
    transition: opacity .15s;
}
.gallery a:hover .tile-meta, .gallery .tile:hover .tile-meta { opacity: 1; }
.gallery .play { position: absolute; inset: 0; display: grid; place-items: center; font-size: 2rem; color: #fff; text-shadow: 0 0 8px #000; pointer-events: none; }

/* Suche */
.search-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: .75rem 1rem; align-items: end; }
.search-form .wide { grid-column: 1 / -1; }
.search-form .wide input { width: 100%; font-size: 1.05rem; padding: .6rem .8rem; }
.search-form select, .search-form input { width: 100%; }
.search-form .checks { display: flex; gap: 1rem; flex-wrap: wrap; }
.search-form .actions { display: flex; gap: .5rem; }
.results-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin: 1.25rem 0 .5rem; }
.result { border-bottom: 1px solid var(--line); padding-bottom: .5rem; }
.result:last-child { border-bottom: 0; }

/* Admin */
.source-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: .6rem; }
.source {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .6rem .8rem;
    background: var(--bg-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
}
.source:hover { border-color: var(--accent); text-decoration: none; }
.source .guild-icon { width: 36px; height: 36px; border-radius: 10px; font-size: .8rem; }
.pick-group { margin-bottom: 1rem; }
.pick-group h3 { display: flex; align-items: center; gap: .6rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); }
.pick { display: grid; grid-template-columns: auto 1.2rem minmax(0, 1fr) auto; gap: .55rem; align-items: center; padding: .35rem .5rem; border-radius: 6px; cursor: pointer; }
.pick:hover { background: var(--bg-hover); }
.pick .archived { font-size: .78rem; color: var(--ok); white-space: nowrap; }
.pick-blocked { cursor: not-allowed; color: var(--ink-faint); }
.pick-blocked:hover { background: none; }
.pick-blocked .pick-name { text-decoration: line-through; text-decoration-color: var(--ink-faint); }
.sticky-actions {
    position: sticky;
    bottom: 0;
    background: rgba(27, 30, 37, .96);
    border-top: 1px solid var(--line);
    padding: .75rem 1rem;
    padding-bottom: calc(.75rem + env(safe-area-inset-bottom, 0px));
    margin: 1rem -1.25rem -1.1rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
    border-radius: 0 0 var(--radius) var(--radius);
}
.token-form { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: .5rem; align-items: end; }
.token-form input { width: 100%; }
.progress-cell { font-variant-numeric: tabular-nums; white-space: nowrap; }
.job-progress { margin-top: .35rem; max-width: 520px; }
.job-progress .bar { height: 6px; border-radius: 3px; background: var(--bg-sunken); border: 1px solid var(--line); overflow: hidden; }
.job-progress .bar span { display: block; height: 100%; background: var(--accent); transition: width .6s ease; }
.job-progress .bar-indeterminate span { width: 30% !important; animation: indeterminate 1.4s ease-in-out infinite; }
@keyframes indeterminate { from { margin-left: -30%; } to { margin-left: 100%; } }
@media (prefers-reduced-motion: reduce) { .job-progress .bar-indeterminate span { animation: none; width: 100% !important; opacity: .4; } }
.job-progress .faint { margin-top: .2rem; font-variant-numeric: tabular-nums; }
.notice-warn { border-left-color: var(--danger); background: rgba(224, 113, 91, .08); }
.error-text { color: var(--danger); font-size: .82rem; overflow-wrap: anywhere; }

/* Lightbox */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(5, 6, 8, .93);
    display: grid;
    grid-template-rows: 1fr auto;
    padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}
.lightbox img { max-width: 96vw; max-height: 86vh; margin: auto; object-fit: contain; align-self: center; justify-self: center; }
.lightbox .lb-bar { display: flex; justify-content: center; gap: .6rem; padding: .7rem; flex-wrap: wrap; align-items: center; color: var(--ink-dim); font-size: .85rem; }
.lightbox .lb-nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 2rem; background: rgba(0, 0, 0, .4); border: 0; color: #fff; width: 48px; height: 64px; cursor: pointer; border-radius: 6px; }
.lightbox .lb-prev { left: 8px; }
.lightbox .lb-next { right: 8px; }

@media (max-width: 900px) {
    .channel-layout { grid-template-columns: minmax(0, 1fr); }
    .sidebar { position: static; max-height: none; order: -1; }
    /* Werkzeuge der Kanalansicht als ausklappbares Panel statt über dem Verlauf */
    .tools {
        position: fixed;
        inset: 0 0 0 auto;
        width: min(420px, 100vw);
        max-height: none;
        z-index: 50;
        background: var(--bg);
        border-left: 1px solid var(--line);
        padding: calc(.75rem + env(safe-area-inset-top, 0px)) 16px calc(1rem + env(safe-area-inset-bottom, 0px));
        transform: translateX(100%);
        transition: transform .2s ease;
        visibility: hidden;
    }
    .tools.open { transform: none; visibility: visible; box-shadow: -12px 0 40px rgba(0, 0, 0, .5); }
    .tools-toggle { display: inline-flex !important; }
    .tools-mobile-head { display: flex !important; }
    .token-form { grid-template-columns: 1fr; }
    .topbar .quicksearch { margin-left: 0; width: 100%; }
    .topbar .quicksearch input { width: 100%; flex: 1; }
}
@media (max-width: 520px) {
    .msg { padding: .15rem .6rem; }
    .msg-row { grid-template-columns: 32px minmax(0, 1fr); gap: .6rem; }
    .avatar { width: 32px; height: 32px; }
    .msg-system { padding-left: 42px; }
}

/* ---------- Kanal: endloser Verlauf ---------- */
.stream-loader, .stream-start { text-align: center; color: var(--ink-faint); font-size: .82rem; padding: .6rem 1rem; }
.stream-start { padding-top: 1rem; }
.messages { min-height: 40vh; }

/* ---------- Kanal: Werkzeugleiste ---------- */
/* Ohne !important, damit die Media-Queries weiter oben (mit !important) gewinnen */
.tools-toggle, .tools-mobile-head { display: none; }
.tools-mobile-head { align-items: center; justify-content: space-between; margin-bottom: .25rem; }
.tools { gap: .6rem; }
.tool { background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius); }
.tool > summary {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    padding: .65rem .9rem;
    cursor: pointer;
    list-style: none;
    font-weight: 600;
    font-size: .92rem;
    user-select: none;
}
.tool > summary::-webkit-details-marker { display: none; }
.tool > summary::after { content: "▸"; margin-left: auto; color: var(--ink-faint); transition: transform .15s; }
.tool[open] > summary::after { transform: rotate(90deg); }
.tool > summary:hover { background: var(--bg-hover); border-radius: var(--radius); }
.tool > summary .faint { font-weight: 400; font-size: .78rem; }
.tool > :not(summary) { margin-left: .9rem; margin-right: .9rem; }
.tool > :last-child { margin-bottom: .9rem; }
.tool h3 { margin-top: .25rem; }
.tool-hint { margin-top: 0; font-size: .8rem; }
.row-tight { align-items: center; }
.sidebar form.row { flex-direction: row; }
.doc { display: grid; gap: .05rem; padding: .4rem 0; border-bottom: 1px solid var(--line); font-size: .85rem; }
.doc:last-child { border-bottom: 0; }
.doc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta, .doc-actions { font-size: .76rem; }
.tool-search { gap: .6rem !important; margin-bottom: .9rem; }
.tool-search .row label { flex: 1; font-size: .78rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
    display: inline-flex !important;
    align-items: center;
    gap: .3rem;
    padding: .22rem .6rem;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    font-size: .82rem;
    color: var(--ink-dim);
    cursor: pointer;
    user-select: none;
}
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.hits { display: flex; flex-direction: column; gap: .15rem; margin: 0 -.5rem; }
.hit { display: block; padding: .45rem .5rem; border-radius: 6px; color: var(--ink); font-size: .88rem; }
.hit:hover { background: var(--bg-hover); text-decoration: none; }
.hit.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.hit-head { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; font-size: .8rem; }
.hit-head strong { font-weight: 600; }
.hit-thread { display: block; font-size: .75rem; color: var(--ink-faint); }
.hit-text { display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; color: var(--ink-dim); overflow-wrap: anywhere; margin-top: .1rem; }
.timeline { display: flex; flex-direction: column; }
.timeline-year { font-size: .75rem; font-weight: 700; color: var(--ink-faint); margin: .5rem 0 .15rem; letter-spacing: .05em; }
.timeline-year:first-child { margin-top: 0; }
.timeline-row, .person {
    display: grid;
    grid-template-columns: 2.6rem minmax(0, 1fr) 3.4rem;
    gap: .5rem;
    align-items: center;
    padding: .18rem .35rem;
    border-radius: 5px;
    color: var(--ink-dim);
    font-size: .82rem;
}
.person { grid-template-columns: minmax(0, 7rem) minmax(0, 1fr) 3.4rem; width: 100%; background: none; border: 0; font: inherit; font-size: .85rem; text-align: left; cursor: pointer; }
.person-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.timeline-row:hover, .person:hover { background: var(--bg-hover); color: var(--ink); text-decoration: none; }
.tl-bar { height: 8px; background: var(--bg-sunken); border-radius: 4px; overflow: hidden; }
.tl-bar span { display: block; height: 100%; background: var(--accent); opacity: .75; border-radius: 4px; min-width: 2px; }
.tl-count { text-align: right; font-variant-numeric: tabular-nums; font-size: .78rem; }

/* ---------- Kanal: Statistik-Spalte ---------- */
.stats-toggle { display: none !important; }
.stats-col { gap: .6rem; }
.stats-loading { padding: .5rem .25rem; }
.stats-col [data-stats-body] { display: flex; flex-direction: column; gap: .6rem; }
@media (max-width: 1499px) {
    .channel-layout { grid-template-columns: minmax(0, 1fr) 340px; }
    .stats-col {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(420px, 100vw);
        max-height: none;
        z-index: 50;
        background: var(--bg);
        border-right: 1px solid var(--line);
        padding: calc(.75rem + env(safe-area-inset-top, 0px)) 16px calc(1rem + env(safe-area-inset-bottom, 0px));
        transform: translateX(-100%);
        transition: transform .2s ease;
        visibility: hidden;
        overflow-y: auto;
    }
    .stats-col.open { transform: none; visibility: visible; box-shadow: 12px 0 40px rgba(0, 0, 0, .5); }
    .stats-toggle { display: inline-flex !important; }
    .stats-col .tools-mobile-head { display: flex !important; }
    .stats-col [data-stats-body] { display: flex; flex-direction: column; gap: .6rem; }
}
@media (max-width: 900px) {
    .channel-layout { grid-template-columns: minmax(0, 1fr); }
}

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; margin-bottom: .75rem; }
.kpi { background: var(--bg-sunken); border: 1px solid var(--line); border-radius: 6px; padding: .45rem .6rem; }
.kpi-value { display: block; font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); }
.kpi-label { display: block; font-size: .72rem; color: var(--ink-faint); }
.stat-list { margin: 0 0 .5rem; display: grid; gap: .15rem; font-size: .82rem; }
.stat-list > div { display: flex; justify-content: space-between; gap: .75rem; padding: .12rem 0; border-bottom: 1px dashed var(--line); }
.stat-list dt { color: var(--ink-dim); }
.stat-list dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }
.facts { margin: 0; padding-left: 1.1rem; font-size: .86rem; display: grid; gap: .35rem; }
.facts li::marker { color: var(--accent); }
/* Chat-Statistik: lange Liste in eigener Scrollbox, mit Schatten als Hinweis auf mehr Inhalt */
.facts-scroll {
    max-height: 17rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: .25rem .5rem .25rem 1.4rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background:
        linear-gradient(var(--bg-raised) 30%, transparent) top / 100% 2rem no-repeat local,
        linear-gradient(transparent, var(--bg-raised) 70%) bottom / 100% 2rem no-repeat local,
        radial-gradient(farthest-side at 50% 0, rgba(0, 0, 0, .45), transparent) top / 100% .7rem no-repeat scroll,
        radial-gradient(farthest-side at 50% 100%, rgba(0, 0, 0, .45), transparent) bottom / 100% .7rem no-repeat scroll;
}
.fact-link { color: inherit; text-decoration: underline dotted var(--ink-faint); text-underline-offset: 3px; }
.fact-link:hover { color: var(--accent); }
.chart-label { font-size: .74rem; font-weight: 600; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .05em; margin: .8rem 0 .35rem; }
.chart-label:first-child { margin-top: 0; }

.wordcloud { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: center; gap: .1rem .5rem; line-height: 1.15; padding: .25rem 0 .5rem; }
.word { background: none; border: 0; padding: .05rem .15rem; color: var(--ink); font: inherit; cursor: pointer; border-radius: 4px; }
.word:hover, .word:focus-visible { background: var(--accent-soft); color: var(--accent); opacity: 1 !important; }
.word-small { font-size: .8rem; background: var(--bg-sunken); border: 1px solid var(--line); padding: 0 .4rem; margin: .1rem .15rem 0 0; }
.typical { margin: .35rem 0 .5rem; font-size: .8rem; }

.vbars { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; align-items: end; height: 72px; border-bottom: 1px solid var(--line-strong); }
.vbar { display: block; height: max(var(--v), 1px); background: var(--accent); border-radius: 3px 3px 0 0; opacity: .85; }
.vbar:hover { opacity: 1; }
.vbars-axis { display: flex; justify-content: space-between; font-size: .68rem; color: var(--ink-faint); margin-top: .15rem; }
.hbars { display: grid; gap: .1rem; }
.hbar-row { display: grid; grid-template-columns: 1.6rem minmax(0, 1fr) 3.4rem; gap: .5rem; align-items: center; font-size: .8rem; color: var(--ink-dim); }

.heat { display: grid; grid-template-columns: 1.4rem repeat(24, minmax(0, 1fr)); gap: 2px; align-items: center; }
.heat-label { font-size: .66rem; color: var(--ink-faint); }
.heat-cell { display: block; aspect-ratio: 1; border-radius: 2px; background: var(--bg-sunken); outline: 1px solid var(--line); outline-offset: -1px; min-width: 0; }
.heat-cell.lv1 { background: rgba(224, 166, 75, .22); outline: 0; }
.heat-cell.lv2 { background: rgba(224, 166, 75, .45); outline: 0; }
.heat-cell.lv3 { background: rgba(224, 166, 75, .7); outline: 0; }
.heat-cell.lv4 { background: rgb(224, 166, 75); outline: 0; }
a.heat-cell:hover, a.heat-cell:focus-visible { outline: 2px solid var(--ink); outline-offset: 0; }
.heat-legend { display: flex; align-items: center; gap: 3px; font-size: .68rem; margin-top: .35rem; flex-wrap: wrap; }
.heat-legend .heat-cell { width: 10px; height: 10px; }
.cal-scroll { overflow-x: auto; padding-bottom: .25rem; }
.cal { display: flex; gap: 2px; min-width: min-content; }
.cal-week { display: grid; grid-template-rows: .9rem repeat(7, 11px); gap: 2px; width: 11px; }
.cal-week .heat-cell { width: 11px; height: 11px; aspect-ratio: auto; }
.cal-month { font-size: .62rem; color: var(--ink-faint); white-space: nowrap; overflow: visible; }
.cal-empty { visibility: hidden; }

.person-card { border-top: 1px solid var(--line); padding: .35rem 0; }
.person-card:first-of-type { border-top: 0; }
.person-card > summary { display: grid; grid-template-columns: minmax(0, 7rem) minmax(0, 1fr) 3rem; gap: .5rem; align-items: center; cursor: pointer; list-style: none; font-size: .85rem; padding: .15rem 0; }
.person-card > summary::-webkit-details-marker { display: none; }
.person-card[open] > summary .person-name { color: var(--accent); }
.person-card .stat-list { margin-top: .4rem; }
.pair { display: grid; grid-template-columns: minmax(0, 9rem) minmax(0, 1fr) 2.6rem; gap: .5rem; align-items: center; font-size: .8rem; padding: .1rem 0; }
.pair-names { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emoji-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.emoji-chip { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--line); background: var(--bg-sunken); border-radius: 6px; padding: .1rem .45rem; font-size: 1rem; }
.emoji-chip b { font-size: .72rem; color: var(--ink-dim); font-weight: 600; }
.record { display: block; padding: .4rem .5rem; margin: 0 -.5rem; border-radius: 6px; font-size: .84rem; color: var(--ink); overflow-wrap: anywhere; }
.record:hover { background: var(--bg-hover); text-decoration: none; }
.record strong { color: var(--accent); font-weight: 600; }

/* Tooltip für data-tip (Diagramme) */
.tip {
    position: fixed;
    z-index: 200;
    pointer-events: none;
    background: #0b0c0f;
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    padding: .3rem .55rem;
    font-size: .78rem;
    max-width: 260px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}

/* Handy: Kopfleiste nicht mitscrollen lassen, sie nähme sonst ein Viertel des Bildschirms ein */
@media (max-width: 600px) {
    .topbar { position: static; gap: .5rem .75rem; }
    .topbar nav { order: 2; }
    .topbar .logout { order: 3; margin-left: auto; }
    .topbar .quicksearch { order: 4; }
}

/* ---------- Personen-Profil (Dialog) ---------- */
.author-btn { background: none; border: 0; padding: 0; margin: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; border-radius: 50%; }
.msg-author.author-btn { border-radius: 4px; font-weight: 600; }
.author-btn:hover .avatar, .author-btn:focus-visible .avatar { outline: 2px solid var(--accent); outline-offset: 1px; }
.msg-author.author-btn:hover, .msg-author.author-btn:focus-visible { text-decoration: underline; color: var(--accent); }
.row-buttons { display: flex; gap: .4rem; flex-wrap: wrap; }

.person-dialog {
    width: min(1100px, 96vw);
    max-height: min(92vh, 1100px);
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    background: var(--bg);
    color: var(--ink);
    box-shadow: 0 24px 80px rgba(0, 0, 0, .6);
    overflow: hidden;
}
.person-dialog[open] { display: flex; flex-direction: column; }
.person-dialog::backdrop { background: rgba(5, 6, 8, .72); }
.person-dialog [data-dialog-body] { overflow-y: auto; overscroll-behavior: contain; }
.pd-loading { padding: 3rem 1rem; text-align: center; color: var(--ink-dim); }
.pd-head {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--bg-raised);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}
.pd-avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; display: grid; place-items: center; font-size: 1.6rem; font-weight: 700; color: #fff; flex: none; }
.pd-title { flex: 1; min-width: 12rem; }
.pd-title h2 { margin: 0 0 .15rem; font-size: 1.3rem; }
.pd-actions { display: flex; gap: .5rem; align-items: center; margin-left: auto; }
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.segmented button { background: var(--bg-sunken); border: 0; color: var(--ink-dim); font: inherit; font-size: .82rem; padding: .32rem .7rem; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--line-strong); }
.segmented button[aria-pressed=true] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.segmented button:disabled { opacity: .45; cursor: default; }
.pd-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.5rem; padding: 1rem 1.25rem; }
.pd-col { min-width: 0; }
.kpis-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi-value small { font-size: .8rem; font-weight: 400; }
.pd-col .record { display: block; }
.pd-thumbs { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; margin-top: .5rem; }
.pd-thumbs a { display: block; aspect-ratio: 1; border-radius: 4px; overflow: hidden; background: var(--bg-sunken); }
.pd-thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pd-foot { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; padding: .9rem 1.25rem; border-top: 1px solid var(--line); background: var(--bg-raised); }
a.person { text-decoration: none; }
@media (max-width: 860px) {
    .pd-grid { grid-template-columns: minmax(0, 1fr); }
    .kpis-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .person-dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; }
    .pd-thumbs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ---------- Personen-Profil: Persönlichkeit & Stil ---------- */
.pers { margin: 1rem 1.25rem 0; padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-raised); }
.pers-title { margin: 0 0 .75rem; font-size: 1rem; }
.pers-title .faint { display: block; font-weight: 400; font-size: .78rem; margin-top: .15rem; }
.pers-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.5rem; }
.pers-type { display: flex; align-items: center; gap: .8rem; margin-bottom: .6rem; }
.pers-code { font-size: 1.6rem; font-weight: 800; letter-spacing: .08em; color: var(--accent); background: var(--accent-soft); border-radius: 8px; padding: .2rem .55rem; font-variant-numeric: tabular-nums; }
.archetypes { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .4rem; }
.archetype { border: 1px solid var(--line-strong); border-radius: 999px; padding: .15rem .6rem; font-size: .82rem; background: var(--bg-sunken); }
.trait { margin-bottom: .65rem; }
.trait-head { display: flex; justify-content: space-between; gap: .5rem; font-size: .85rem; }
.scale { position: relative; height: 8px; border-radius: 4px; background: var(--bg-sunken); margin: .2rem 0 .15rem; overflow: hidden; }
.scale::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--line-strong); }
.scale-fill { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.trait-text { font-size: .8rem; color: var(--ink-dim); }
.trait-drivers { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .2rem; }
.driver { font-size: .7rem; border-radius: 4px; padding: 0 .35rem; background: var(--bg-sunken); color: var(--ink-dim); border: 1px solid var(--line); }
.axis { display: grid; grid-template-columns: 6.6rem minmax(0, 1fr) 6.6rem; gap: .5rem; align-items: center; font-size: .78rem; padding: .16rem 0; color: var(--ink-faint); }
.axis-left { text-align: right; }
.axis-strong { color: var(--ink); font-weight: 600; }
.axis-track { position: relative; height: 2px; background: var(--line-strong); }
.axis-track::after { content: ""; position: absolute; left: 50%; top: -3px; height: 8px; width: 1px; background: var(--line-strong); }
.axis-dot { position: absolute; top: 50%; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--bg-raised); }
.mood { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 2px; height: 80px; }
.mood-col { display: grid; grid-template-rows: 1fr 1fr; }
.mood-up { display: flex; align-items: flex-end; border-bottom: 1px solid var(--line-strong); }
.mood-down { display: flex; align-items: flex-start; }
.mood-bar { display: block; width: 100%; min-height: 2px; }
.mood-pos { background: var(--accent); border-radius: 3px 3px 0 0; }
.mood-neg { background: var(--link); border-radius: 0 0 3px 3px; }
.legend-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: .5rem; }
@media (max-width: 860px) {
    .pers { margin: 1rem .75rem 0; }
    .pers-grid { grid-template-columns: minmax(0, 1fr); }
    .axis { grid-template-columns: 5.4rem minmax(0, 1fr) 5.4rem; }
}

/* ---------- Wortwolke: ausblenden (Admin) ---------- */
.word-item { position: relative; display: inline-flex; align-items: baseline; }
.word-hide {
    position: absolute;
    top: -.35rem;
    right: -.45rem;
    width: 1.05rem;
    height: 1.05rem;
    border-radius: 50%;
    border: 1px solid var(--line-strong);
    background: var(--bg-raised);
    color: var(--ink-dim);
    font-size: .7rem;
    line-height: 1;
    padding: 0;
    cursor: pointer;
    opacity: 0;
    transition: opacity .12s;
}
.word-item:hover .word-hide, .word-hide:focus-visible { opacity: 1; }
.word-hide:hover { color: var(--danger); border-color: var(--danger); }
@media (hover: none) { .word-hide { opacity: .55; } }
.word-item.hidden-word { opacity: .25; text-decoration: line-through; pointer-events: none; }
.blacklist { display: flex; flex-wrap: wrap; gap: .35rem; margin: .9rem 0 .4rem; }
.blacklist-item { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--line-strong); background: var(--bg-sunken); border-radius: 999px; padding: .1rem .2rem .1rem .65rem; font-size: .85rem; }
.blacklist-item button { background: none; border: 0; color: var(--ink-faint); cursor: pointer; font-size: .95rem; padding: 0 .3rem; border-radius: 50%; }
.blacklist-item button:hover { color: var(--danger); }

/* ---------- Anmeldung, Benutzerverwaltung ---------- */
.login-page { display: flex; align-items: center; justify-content: center; padding: 2rem 16px; }
.login-box { width: 100%; max-width: 340px; background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.75rem 1.5rem; }
.login-box .brand { justify-content: center; font-size: 1.25rem; margin-bottom: 1.25rem; }
.login-box input[type=text], .login-box input[type=password] { width: 100%; margin-bottom: .9rem; }
.login-box .btn { width: 100%; justify-content: center; margin-top: .75rem; }
.user-form { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: flex-end; }
.user-form label:not(.check) { display: flex; flex-direction: column; gap: .25rem; margin: 0; }
.user-form .check { margin-bottom: .45rem; }
table.list td .inline-form { display: inline-flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
table.list td input[type=password] { width: 11rem; }
