/* ---------- Farben & Grundwerte ---------- */
:root {
  --btn-fill: #0071e3;
  --bg: #f5f5f7; --panel: #ffffff; --panel-2: #f9f9fb; --text: #1d1d1f; --muted: #6e6e73;
  --line: rgba(0,0,0,.08); --line-2: rgba(0,0,0,.14); --accent: #0071e3; --accent-text: #fff;
  --accent-soft: rgba(0,113,227,.1); --danger: #d70015; --ok: #1f7a35; --warn: #9a4500;
  --glass: rgba(255,255,255,.72); --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --bubble: #e9e9eb; --sk: rgba(0,0,0,.06);
  --r: 14px; --r-s: 10px; --t: 180ms cubic-bezier(.2,.8,.2,1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --btn-fill: #0060c7;
    --bg: #000; --panel: #1c1c1e; --panel-2: #232325; --text: #f5f5f7; --muted: #98989d;
    --line: rgba(255,255,255,.08); --line-2: rgba(255,255,255,.16); --accent: #0a84ff;
    --accent-soft: rgba(10,132,255,.18); --danger: #ff453a; --ok: #30d158; --warn: #ff9f0a;
    --glass: rgba(28,28,30,.72); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    --bubble: #2c2c2e; --sk: rgba(255,255,255,.07); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --btn-fill: #0060c7;
  --bg: #000; --panel: #1c1c1e; --panel-2: #232325; --text: #f5f5f7; --muted: #98989d;
  --line: rgba(255,255,255,.08); --line-2: rgba(255,255,255,.16); --accent: #0a84ff;
  --accent-soft: rgba(10,132,255,.18); --danger: #ff453a; --ok: #30d158; --warn: #ff9f0a;
  --glass: rgba(28,28,30,.72); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  --bubble: #2c2c2e; --sk: rgba(255,255,255,.07); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; transition: background var(--t), color var(--t); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 17px; } h3 { font-size: 13px; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--sk); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; } .row.between { justify-content: space-between; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Bedienelemente ---------- */
.btn {
  font: 500 13px var(--font); color: var(--text); background: var(--panel); border: 1px solid var(--line-2);
  border-radius: 999px; padding: 6px 14px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; gap: 6px; transition: background var(--t), transform var(--t), opacity var(--t); white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; transform: none; }
.btn.primary { background: var(--btn-fill); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--sk); }
.btn.small { padding: 3px 10px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; padding: 10px; }
.btn.danger { color: var(--danger); }
input, select, textarea {
  font: 13px var(--font); color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--r-s); padding: 7px 10px; transition: border-color var(--t), box-shadow var(--t); min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; width: 100%; }
select { appearance: none; padding-right: 26px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 50%, calc(100% - 9px) 50%; background-size: 4px 4px; background-repeat: no-repeat; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 11px; color: var(--muted); font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line-2); background: transparent; color: var(--text); cursor: pointer; transition: all var(--t); }
.chip.on { background: var(--btn-fill); border-color: var(--btn-fill); color: #fff; }
.chip.static { cursor: default; background: var(--sk); border-color: transparent; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--sk); }
.badge.hoch { color: var(--danger); } .badge.mittel { color: var(--warn); } .badge.niedrig { color: var(--ok); }

/* ---------- Segment-Schalter (Theme) ---------- */
.seg { display: inline-flex; background: var(--sk); border-radius: 9px; padding: 2px; }
.seg button { font: 500 12px var(--font); border: 0; background: transparent; color: var(--muted); padding: 4px 10px; border-radius: 7px; cursor: pointer; transition: all var(--t); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- Kopfleiste & Layout ---------- */
.bar {
  position: sticky; top: 0; z-index: 10; height: 52px; display: flex; align-items: center; gap: 12px; padding: 0 20px;
  background: var(--glass); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-right: auto; }
.brand img { width: 24px; height: 24px; }
.nav { display: flex; gap: 2px; }
.grid { display: grid; grid-template-columns: 172px minmax(0, 1fr) minmax(0, 1fr); gap: 16px; padding: 16px; height: calc(100vh - 52px); }
.grid.rail-right { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 172px; }
.grid.rail-right > .rail { order: 1; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); min-height: 0; position: relative; }

/* ---------- Bot (links) ---------- */
.bot { display: flex; flex-direction: column; gap: 12px; padding: 16px; overflow: auto; }
.opts { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; padding: 8px 12px; border-radius: var(--r); background: var(--panel-2); border: 1px solid var(--line); }
.opts > summary { display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none; min-width: 0; }
.opts > summary::-webkit-details-marker { display: none; }
.opts-sum { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opts-edit { font-size: 12px; color: var(--accent); font-weight: 500; }
.opts[open] .opts-edit { visibility: hidden; }
.opts[open] .opts-sum { display: none; }
.opts[open] > summary { margin-bottom: 4px; }
.opts-hint { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); padding: 6px 10px; margin-bottom: 10px; border-radius: var(--r-s); background: var(--accent-soft); }
.more { position: relative; }
.more > summary { list-style: none; padding: 6px 12px; font-size: 16px; line-height: 1; }
.more > summary::-webkit-details-marker { display: none; }
.more-list { position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 20; min-width: 210px; padding: 6px; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.2); animation: pop var(--t); }
.more-list button { text-align: left; font: 13px var(--font); color: var(--text); background: none; border: 0; padding: 7px 10px; border-radius: 7px; cursor: pointer; }
.more-list button:hover:not(:disabled), .more-list button:focus-visible { background: var(--accent); color: var(--accent-text); }
.more-list button:disabled { opacity: .4; cursor: default; }
.btn.next { background: #1f7a35; color: #fff; border-color: transparent; box-shadow: 0 0 0 3px rgba(48,209,88,.25); }
.opts select { background-color: var(--panel); }
.toolbar { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }
.preview { flex: 1 0 auto; min-height: 180px; /* kein eigener Scrollbalken: die Spalte scrollt als Ganzes */ border: 1px solid var(--line); border-radius: var(--r); background: var(--panel-2); padding: 18px 20px; }
.empty { height: 100%; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-icon { font-size: 28px; opacity: .5; margin-bottom: 6px; }
.subject { width: 100%; font-size: 17px; font-weight: 600; border: 0; background: transparent; padding: 0 0 10px; border-bottom: 1px solid var(--line); border-radius: 0; }
.subject:focus { box-shadow: none; border-color: var(--accent); }
.body:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; border-radius: 4px; }
.body { white-space: pre-wrap; outline: none; padding: 12px 0; min-height: 80px; line-height: 1.6; }
.sig { font: inherit; color: var(--muted); white-space: pre-wrap; margin: 4px 0 0; }
.quoted { margin-top: 14px; color: var(--muted); }
.quoted summary { cursor: pointer; font-size: 12px; }
.quoted pre { font: 12px/1.5 var(--font); white-space: pre-wrap; border-left: 2px solid var(--line-2); padding-left: 10px; margin: 8px 0 0; }
.thumbs { display: flex; gap: 10px; flex-wrap: wrap; }
.thumb { position: relative; width: 120px; border-radius: var(--r-s); overflow: hidden; border: 2px solid transparent; cursor: pointer; background: var(--panel); transition: border-color var(--t), transform var(--t); padding: 0; }
.thumb:hover { transform: translateY(-1px); }
.thumb img { display: block; width: 100%; height: 80px; object-fit: cover; }
.thumb span { display: block; font-size: 11px; color: var(--muted); padding: 4px 6px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb.on { border-color: var(--accent); }
.thumb.on::after { content: "✓"; position: absolute; top: 5px; right: 5px; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; display: grid; place-items: center; }
.chosen { margin: 6px 0 4px; }
.chosen .thumb { width: auto; max-width: 100%; cursor: default; border: 1px solid var(--line); }
.chosen .thumb img { height: auto; max-height: 240px; width: auto; max-width: 100%; object-fit: contain; }
.chosen .thumb .rm { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.55); color: #fff; cursor: pointer; }
.suggest { flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; }
.actions { flex: 0 0 auto; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.actions .btn.ghost { padding: 6px 9px; }
.chatbox { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px 12px; border-radius: var(--r); background: var(--panel-2); border: 1px solid var(--line); }
.chat-head { display: flex; align-items: center; gap: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.chat-head div { display: flex; align-items: baseline; gap: 8px; min-width: 0; line-height: 1.3; }
.chat-head .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none; background: linear-gradient(135deg, #5ac8fa, #0a64e0); color: #fff; font-size: 11px; }
.chat:empty { display: none; }
.chat-input textarea { background: var(--panel); }
.hint { font-size: 12px; color: var(--muted); margin: -4px 2px 0; }
@media (max-height: 860px) { #ctxHint { display: none; } }  /* Platz für den Entwurf; Tipps stehen auch unter „?“ */
.actions-sep { flex: 1; }
.btn.on { color: var(--ok); border-color: var(--ok); }

/* Vorgänge am rechten Rand */
.rail { display: flex; flex-direction: column; gap: 6px; padding: 10px 8px; overflow: auto; scrollbar-width: thin; border-radius: 16px; transition: border-color var(--t), background var(--t); }
.faq-add { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
#kbTabs { margin-bottom: 4px; }
.rail.over { border-color: var(--accent); background: var(--accent-soft); }
.rail-head { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 2px; position: sticky; top: -10px; z-index: 2; background: var(--panel); margin-top: -10px; padding-top: 10px; }
.rail-head .btn { padding: 2px 9px; font-size: 12px; }
.rail-head .count { display: inline-block; min-width: 18px; text-align: center; font-size: 11px; background: var(--sk); border-radius: 999px; padding: 0 6px; margin-left: 4px; color: var(--text); text-transform: none; letter-spacing: 0; }
.rail-head .count:empty { display: none; }
.rail-list { display: flex; flex-direction: column; gap: 4px; }
.rail-empty { padding: 6px 2px; margin: 0; }
.rail-foot { margin: auto 0 0; padding: 6px 2px 0; font-size: 11px; line-height: 1.5; color: var(--muted); }
.vcard { position: relative; flex: none; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); overflow: hidden; transition: border-color var(--t), box-shadow var(--t), background var(--t); }
.vcard:hover { border-color: var(--line-2); }
.vcard.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); background: var(--panel); }
.vcard-main { all: unset; box-sizing: border-box; display: flex; flex-direction: column; gap: 2px; width: 100%; padding: 6px 22px 6px 9px; cursor: pointer; }
.vcard-main:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.vcard-subj { font-weight: 600; font-size: 12.5px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vcard-from, .vcard-job { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.vcard-meta { display: flex; gap: 6px; align-items: center; min-width: 0; }
.vdot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: none; border: 1.5px solid var(--muted); }
.vdot.entwurf { border: 0; background: var(--accent); }
.vdot.geprueft { border: 0; background: var(--ok); border-radius: 2px; }
.urgent { color: var(--danger); }

.vcard.running .vcard-job { color: var(--accent); }
.vcard.running::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 200% 100%; animation: sh 1.2s linear infinite; }
.vcard.fresh { animation: glow 1.4s ease-in-out 3; }
.vcard.fresh .vcard-job { color: var(--ok); font-weight: 600; }
.vcard.err .vcard-job { color: var(--danger); }
.vcard-x { position: absolute; top: 4px; right: 3px; width: 18px; height: 18px; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; opacity: 0; font-size: 14px; line-height: 1; transition: opacity var(--t); }
.vcard:hover .vcard-x, .vcard.active .vcard-x, .vcard-x:focus-visible { opacity: 1; }
.vcard-x:hover { background: var(--sk); color: var(--text); }
.vbadge { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; padding: 1px 7px; border-radius: 999px; background: var(--sk); color: var(--muted); white-space: nowrap; }
.vbadge.entwurf { background: var(--accent-soft); color: var(--accent); }
.vbadge.geprueft { background: rgba(48,209,88,.15); color: var(--ok); }
.list li .vbadge { flex: none; }
@keyframes glow { 50% { box-shadow: 0 0 0 4px rgba(48,209,88,.35); } }
.chat { display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 85%; padding: 7px 12px; border-radius: 16px; white-space: pre-wrap; animation: pop var(--t); }
.msg.user { align-self: flex-end; background: var(--btn-fill); color: #fff; border-bottom-right-radius: 5px; }
.msg.assistant { align-self: flex-start; background: var(--bubble); border-bottom-left-radius: 5px; }
.chat-input { margin-top: auto; display: flex; gap: 8px; align-items: flex-end; }
.chat-input textarea { resize: none; overflow: hidden; min-height: 36px; border-radius: 18px; padding: 8px 14px; max-height: 60px; }
.chat-input .btn { width: 34px; height: 34px; padding: 0; justify-content: center; font-size: 16px; }

/* Kontextmenü */
.ctx { position: fixed; z-index: 50; width: 250px; padding: 6px; display: flex; flex-direction: column; background: color-mix(in srgb, var(--panel) 94%, transparent); backdrop-filter: saturate(180%) blur(24px); -webkit-backdrop-filter: saturate(180%) blur(24px); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.22); animation: pop var(--t); }
.ctx .mi { text-align: left; font: 13px var(--font); color: var(--text); background: none; border: 0; padding: 6px 10px; border-radius: 7px; cursor: pointer; }
.ctx .mi:hover, .ctx .mi:focus-visible { background: var(--accent); color: var(--accent-text); outline: none; }
.ctx hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }
.ctx-scope { display: flex; margin: 2px 2px 6px; }
.ctx-scope button { flex: 1; }
.ctx-scope button:disabled { opacity: .35; cursor: default; }
.ctx-custom input { width: 100%; margin: 2px 0; }
.ctx-busy { padding: 10px; color: var(--muted); font-size: 13px; }
.ctx.busy .mi, .ctx.busy hr, .ctx.busy form, .ctx.busy .ctx-scope, .ctx.busy .ctx-label, .ctx.busy .ctx-styles { display: none; }
.ctx-label { font-size: 11px; color: var(--muted); padding: 2px 10px; }
.ctx-styles { display: flex; flex-direction: column; max-height: 200px; overflow: auto; }
::highlight(rewrite) { background-color: rgba(10,132,255,.24); }
::highlight(ph) { background-color: rgba(255,204,0,.45); }
.ph-legend { background: rgba(255,204,0,.45); border-radius: 3px; padding: 0 3px; }
::highlight(cited) { text-decoration: underline dotted rgba(10,132,255,.55); text-underline-offset: 3px; }
.tip-quote { display: block; font-style: italic; opacity: .85; margin: 2px 0 4px; }
.cite-tip { position: fixed; z-index: 60; max-width: 420px; padding: 5px 10px; border-radius: 8px; font-size: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); pointer-events: none; }

/* Live-Antwort */
.gen-status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.body.streaming::after { content: ""; display: inline-block; width: 7px; height: 1.1em; margin-left: 2px; vertical-align: text-bottom; background: var(--accent); border-radius: 2px; animation: blink 1s steps(2) infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }

/* Analyse */
.qlist { list-style: none; padding: 0 !important; display: flex; flex-direction: column; gap: 4px; }
.qlist li { display: flex; gap: 8px; align-items: baseline; }
.qlist i { font-style: normal; font-weight: 700; width: 16px; text-align: center; flex: none; }
.q-ok i { color: var(--ok); } .q-gap i { color: var(--warn); } .q-open i { color: var(--muted); }
.warn-box { margin: 0; padding: 8px 10px; border-radius: var(--r-s); font-size: 12px; background: rgba(255,159,10,.12); border: 1px solid rgba(255,159,10,.35); }
.row.center { justify-content: center; margin-top: 10px; }
.list li .grow.link { all: unset; flex: 1; min-width: 0; cursor: pointer; border-radius: 6px; }
.list li .grow.link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.list li .grow.link b, .list li .grow.link span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list li .grow.link span { font-size: 12px; color: var(--muted); }
.docs td:first-child, .kb aside .list li .grow { overflow-wrap: anywhere; }
.gaps { display: flex; flex-direction: column; gap: 6px; padding: 10px; border-radius: var(--r-s); background: rgba(255,159,10,.1); border: 1px solid rgba(255,159,10,.3); }
.gaps ul { list-style: none; padding: 0 !important; display: flex; flex-direction: column; gap: 8px; }
.gap-form { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.chip.read { background: var(--accent-soft); color: var(--accent); }
.msg-wrap { align-self: flex-end; display: flex; flex-direction: column; align-items: flex-end; max-width: 85%; }
.msg-wrap .msg { max-width: 100%; }
.msg-act { border: 0; background: none; color: var(--muted); font-size: 11px; cursor: pointer; padding: 2px 4px; opacity: 0; transition: opacity var(--t); }
.msg-wrap:hover .msg-act, .msg-act:focus-visible { opacity: 1; }
.msg-act:hover { color: var(--accent); }
.checks { margin: 0 0 16px; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.cat-style { padding: 3px 22px 3px 6px !important; font-size: 11px !important; max-width: 110px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 6px 0; }
.check input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.settings .full { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 10px; }
.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.style-item { display: flex; flex-direction: column; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: var(--r-s); }
.style-item .row input { flex: 1; }

/* Skeleton */
#draft { transition: opacity var(--t); }
#draft.stale { opacity: .45; pointer-events: none; }
.preview-msg { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; }
.preview-msg p { margin: 0; }
.preview-msg #previewMsgDetail { max-width: 420px; word-break: break-word; }
.skeleton { display: flex; flex-direction: column; gap: 12px; }
.skeleton i { display: block; height: 14px; border-radius: 7px; background: linear-gradient(90deg, var(--sk) 0, var(--line-2) 50%, var(--sk) 100%); background-size: 200% 100%; animation: sh 1.3s infinite linear; }
.skeleton i:nth-child(1) { width: 45%; height: 20px; } .skeleton i:nth-child(3) { width: 92%; } .skeleton i:nth-child(4) { width: 80%; } .skeleton i:nth-child(5) { width: 35%; }

/* ---------- E-Mail (rechts) ---------- */
.mail { padding: 16px; overflow: auto; display: flex; flex-direction: column; }
.drop { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; border: 2px dashed var(--line-2); border-radius: var(--r); padding: 28px; transition: border-color var(--t), background var(--t); }
.drop.small { flex: none; padding: 18px; }
.drop.over, .drop.small.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; background: var(--accent-soft); color: var(--accent); margin-bottom: 6px; }
.drop-title { font-weight: 600; margin: 0; } .drop p { margin: 0; } .drop .row { margin-top: 10px; justify-content: center; }
.drop-overlay { position: absolute; inset: 8px; border-radius: 14px; border: 2px dashed var(--accent); background: var(--accent-soft); display: grid; place-items: center; font-weight: 600; color: var(--accent); opacity: 0; pointer-events: none; transition: opacity var(--t); backdrop-filter: blur(4px); }
.mail.over .drop-overlay { opacity: 1; }
.paste { flex: 1; display: flex; flex-direction: column; gap: 8px; } .paste textarea { flex: 1; resize: none; }
#mailView { display: flex; flex-direction: column; gap: 12px; }
.card { border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; background: var(--panel-2); display: flex; flex-direction: column; gap: 8px; animation: pop var(--t); }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; font-size: 13px; }
.meta dt { color: var(--muted); } .meta dd { margin: 0; word-break: break-word; }
.mbody { white-space: pre-wrap; border-top: 1px solid var(--line); padding-top: 10px; line-height: 1.6; word-break: break-word; }
.card ul { margin: 0; padding-left: 18px; }
.sources { list-style: none; padding: 0 !important; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }

/* ---------- Dialoge ---------- */
.dlg { border: 1px solid var(--line); border-radius: 18px; padding: 0; background: var(--panel); color: var(--text); box-shadow: 0 24px 80px rgba(0,0,0,.3); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 64px); }
.dlg.wide { width: min(1000px, calc(100vw - 32px)); }
.dlg[open] { animation: pop var(--t); display: flex; flex-direction: column; }
.dlg::backdrop { background: rgba(0,0,0,.3); backdrop-filter: blur(6px); }
.dlg > header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--glass); }
.x { border: 0; background: var(--sk); color: var(--muted); width: 26px; height: 26px; border-radius: 50%; cursor: pointer; font-size: 16px; line-height: 1; }
.dlg-body { padding: 18px; overflow: auto; }
.dlg-body h3 { margin: 16px 0 8px; } .dlg-body h3:first-child { margin-top: 0; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-s); }
.list li:hover { background: var(--panel-2); }
.list li .grow { flex: 1; min-width: 0; cursor: pointer; }
.list li .grow b, .list li .grow span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list li .grow span { font-size: 12px; color: var(--muted); }
.list.compact li { padding: 4px 8px; }
.kb { display: grid; grid-template-columns: 260px 1fr; gap: 24px; }
.kb aside { display: flex; flex-direction: column; gap: 8px; }
.kb aside h3 { margin: 10px 0 0; }
.kb-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.docs { width: 100%; border-collapse: collapse; font-size: 13px; }
.docs th { text-align: left; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.docs td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.docs td:first-child { word-break: break-word; }
.docs select { padding: 4px 24px 4px 8px; font-size: 12px; }
.bar-prog { height: 4px; border-radius: 2px; background: var(--sk); overflow: hidden; width: 90px; margin-top: 4px; }
.bar-prog i { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.st-error { color: var(--danger); } .st-ready { color: var(--ok); }
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.settings section { display: flex; flex-direction: column; gap: 10px; }
.settings .row input { flex: 1; }
.sig-item { display: flex; flex-direction: column; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: var(--r-s); }
.sec { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: var(--r-s); }
.qr { width: 180px; height: 180px; background: #fff; border-radius: 10px; padding: 6px; }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); padding: 32px 28px; display: flex; flex-direction: column; gap: 10px; text-align: center; animation: pop var(--t); }
.auth-card input { padding: 10px 12px; }
.auth-logo { width: 56px; height: 56px; margin: 0 auto 4px; }
.auth-card p { margin: 0 0 6px; }
.error { color: var(--danger); font-size: 13px; min-height: 1em; }

/* ---------- Toast ---------- */
.toast-act { margin-left: 10px; border: 0; border-radius: 999px; padding: 3px 10px; background: var(--btn-fill); color: #fff; font: 600 12px var(--font); cursor: pointer; }
.toast-x { margin-left: 8px; border: 0; background: none; color: inherit; font-size: 15px; cursor: pointer; }
.toast { display: flex; align-items: center; position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: 13px; box-shadow: var(--shadow); z-index: 100; animation: pop var(--t); max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); color: #fff; }

@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.99); } to { opacity: 1; transform: none; } }
@keyframes sh { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Schmale Bildschirme ---------- */
@media (max-width: 1240px) and (min-width: 961px) {
  .grid { grid-template-columns: 150px minmax(0, 1fr) minmax(0, 1fr); gap: 12px; padding: 12px; }
  .grid.rail-right { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 150px; }
}
@media (max-width: 960px) {
  .grid { grid-template-columns: minmax(0, 1fr); height: auto; padding: 12px 16px; }
  .toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .field select { width: 100%; min-width: 0; }
  .rail-head { position: sticky; left: 0; background: var(--panel); z-index: 1; }
  .bot { overflow: visible; }
  .grid > .rail, .grid.rail-right > .rail { order: -2; flex-direction: row; align-items: stretch; overflow-x: auto; padding: 8px; }
  .rail-head { flex-direction: column; justify-content: center; gap: 6px; padding: 0 4px; margin-top: 0; top: auto; }
  .rail-list { flex-direction: row; }
  .vcard { width: 170px; }
  .rail-foot { display: none; }
  .mail { min-height: 200px; }
  .preview { min-height: 260px; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .kb, .settings { grid-template-columns: 1fr; }
  .bar { padding: 0 12px; gap: 6px; }
  .brand span, .nav .btn { padding: 6px 8px; }
}
@media (max-width: 560px) {
  .bar { height: auto; flex-wrap: wrap; row-gap: 4px; padding: 8px 12px; }
  .brand { font-size: 0; gap: 0; }
  .nav { order: 3; width: 100%; justify-content: space-between; }
}

/* Touch: ausreichend große Tippziele, × immer sichtbar, kein Auto-Zoom auf iOS */
@media (pointer: coarse) {
  .btn, .seg button, .chip, .x, .opts > summary, .more-list button, .ctx .mi { min-height: 44px; }
  .vcard-x { opacity: 1; width: 36px; height: 36px; top: 2px; right: 2px; }
  input, select, textarea { min-height: 44px; font-size: 16px; }
}
@media (max-width: 560px) {
  .docs thead { display: none; }
  .docs tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .docs td { border: 0; padding: 0; }
}

/* + Neu-Menü, neue Mail, Hilfe */
.newmenu { position: relative; }
.newmenu > summary { list-style: none; }
.newmenu > summary::-webkit-details-marker { display: none; }
.newmenu .more-list { position: fixed; bottom: auto; right: auto; min-width: 230px; } /* fixed: die Leiste scrollt (overflow) und würde das Menü abschneiden; Position setzt app.js */
.compose { display: flex; flex-direction: column; gap: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.compose input, .compose select { width: 100%; }
.out { color: var(--accent); font-weight: 700; }
.msg.pending { opacity: .55; border: 1px dashed currentColor; }
.msg.pending::after { content: " · vorgemerkt"; font-size: 11px; }
.nbadge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 3px; border-radius: 999px; background: var(--warn); color: #fff; font-size: 11px; text-align: center; }
.btn.help { width: 30px; justify-content: center; padding: 6px 0; border-radius: 50%; }
.steps { margin: 0 0 14px; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; line-height: 1.55; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; margin: 0 0 12px; }
.keys dt { font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--sk); border-radius: 5px; padding: 1px 6px; justify-self: start; }
.keys dd { margin: 0; }
.st-review { color: var(--warn); }
@media (max-width: 560px) { .row2 { grid-template-columns: 1fr; } }
