:root {
  --bg: #f4f5f8;
  --sidebar: #eceef3;
  --panel: #ffffff;
  --text: #1c2230;
  --muted: #697187;
  --line: #e2e5eb;
  --hover: #f1f3f7;
  --selected: #e7edfd;
  --accent: #3563e9;
  --accent-hover: #2b54cf;
  --accent-weak: #e8eefd;
  --brand: #3563e9;          /* Blau des App-Symbols – auch im Dunkel-Modus gleich */
  --danger: #d33d33;
  --ok: #1f9d5b;
  --warn: #c98a00;
  --ai: #7b4fd6;
  --ai-weak: #f2ecfd;
  --flag: #e0362c;
  --ok-strong: #137a44;      /* Text auf hellgrünem Grund (Kontrast ≥ 4.5:1) */
  --warn-strong: #8a5a00;
  --switch-off: #c3c9d4;
  --tag-bg: #fdecc8;
  --tag-fg: #8a5a00;
  --shadow: 0 10px 40px rgba(20, 28, 45, .18);
  --shadow-sm: 0 1px 2px rgba(20, 28, 45, .05);
  --shadow-md: 0 4px 14px rgba(20, 28, 45, .08);
  --radius: 10px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

/* Dunkel: nach Windows-Einstellung – oder fest per Einstellungen → Darstellung (data-theme auf <html>).
   Die Werte stehen zweimal: einmal für „Wie Windows“, einmal für „Dunkel“ fest. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171c;
    --sidebar: #191b21;
    --panel: #1e2027;
    --text: #e5e8ef;
    --muted: #979fb2;
    --line: #2c3039;
    --hover: #252831;
    --selected: #243152;
    --accent: #6b8fff;
    --accent-hover: #87a4ff;
    --accent-weak: #232e4b;
    --danger: #f06a60;
    --ok: #4cc987;
    --warn: #e6b13a;
    --ai: #a887f2;
    --ai-weak: #2a2440;
    --flag: #ff5a52;
    --ok-strong: #4cc987;
    --warn-strong: #e6b13a;
    --switch-off: #4a505c;
    --tag-bg: #4a3a14;
    --tag-fg: #f3c969;
    --shadow: 0 10px 40px rgba(0, 0, 0, .5);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .25);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --tag-bg: #4a3a14;
    --tag-fg: #f3c969;
    --bg: #15171c;
    --sidebar: #191b21;
    --panel: #1e2027;
    --text: #e5e8ef;
    --muted: #979fb2;
    --line: #2c3039;
    --hover: #252831;
    --selected: #243152;
    --accent: #6b8fff;
    --accent-hover: #87a4ff;
    --accent-weak: #232e4b;
    --danger: #f06a60;
    --ok: #4cc987;
    --warn: #e6b13a;
    --ai: #a887f2;
    --ai-weak: #2a2440;
    --flag: #ff5a52;
    --ok-strong: #4cc987;
    --warn-strong: #e6b13a;
    --switch-off: #4a505c;
    --shadow: 0 10px 40px rgba(0, 0, 0, .5);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .25);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, .35);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
[hidden] { display: none !important; }
/* Nur für Screenreader (sichtbares Label steht schon als Überschrift daneben) */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
/* Tastatur-Fokus immer deutlich sichtbar (nicht bei Mausklick) */
:where(button, summary, a, [tabindex]):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Windows-Einstellung „Animationen anzeigen: aus“ respektieren */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px; margin: 0 1px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--panel);
  font: 600 11px/1 "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif; color: var(--text);
}

.i {
  width: 18px; height: 18px; flex: none;
  stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.i.big { width: 48px; height: 48px; stroke-width: 1.2; }
.i.sm { width: 14px; height: 14px; }

/* ---------- Grundlayout ---------- */
#app {
  display: grid;
  grid-template-columns: 250px minmax(320px, 400px) 1fr;
  height: 100vh;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { color: var(--danger); }
.btn.ai { background: var(--ai-weak); border-color: transparent; color: var(--ai); font-weight: 600; }
.btn.ai:hover { filter: brightness(.97); }
.btn.wide { width: 100%; }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--flag); }
.icon-btn.on .i { fill: currentColor; }

/* ---------- Sidebar ---------- */
#sidebar {
  display: flex; flex-direction: column; gap: 14px;
  padding: 16px 12px; background: var(--sidebar); border-right: 1px solid var(--line); min-height: 0;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 2px 6px; }
#folders { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.folder {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; text-align: left;
}
.folder { transition: background .12s; }
.folder:hover { background: var(--hover); }
.folder.active { background: var(--selected); font-weight: 600; }
.folder.active > .i { color: var(--accent); }
.folder .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder .count { font-size: 12px; font-weight: 700; color: var(--accent); }
.folder .count.muted-count { color: var(--muted); }
.folder .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.folder .warn { color: var(--warn); display: inline-flex; }
.folder-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 10px 4px; }
.acc-line { display: flex; align-items: center; }
.acc-line .folder { flex: 1; min-width: 0; padding-left: 4px; }
.twisty {
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 30px; flex: none;
  border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 6px;
}
.twisty:hover { background: var(--hover); color: var(--text); }
.twisty .i { transition: transform .15s; }
.twisty.open .i { transform: rotate(90deg); }
.tree { display: flex; flex-direction: column; gap: 1px; margin: 1px 0 6px; }
.folder.sub { padding-top: 5px; padding-bottom: 5px; gap: 8px; font-size: 13px; color: var(--text); }
.folder.sub .i { color: var(--muted); }
.folder.sub.has-unread .name { font-weight: 600; }
.folder:disabled, .folder.nosel { cursor: default; opacity: .6; }
.folder:disabled:hover, .folder.nosel:hover { background: transparent; }
.folder.drop-target { background: var(--accent-weak); outline: 2px dashed var(--accent); outline-offset: -2px; }
.dragging { opacity: .45; }
/* Umsortieren per Ziehen: Linie zeigt, wo Konto/Ordner landet */
.order-before { box-shadow: inset 0 2px 0 var(--accent); }
.order-after { box-shadow: inset 0 -2px 0 var(--accent); }
.acc-group { border-radius: 8px; }
.move { width: min(460px, 92vw); max-height: 80vh; }
.move[open] { display: flex; flex-direction: column; }
.move .modal-body { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; min-height: 0; }
.move-list { display: flex; flex-direction: column; gap: 1px; overflow-y: auto; min-height: 120px; }
.sidebar-foot { display: flex; flex-direction: column; gap: 2px; }
/* Update-Hinweis unten links */
.update-banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; padding: 10px 12px;
  border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-size: 12.5px; box-shadow: var(--shadow-sm);
}
.update-banner.ready { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.update-banner > .i { color: var(--accent); }
.update-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.update-text span { color: var(--muted); }
.update-banner .btn { width: 100%; }
.program-card .card-ic { background: var(--hover); color: var(--muted); }
.theme-seg { display: flex; width: fit-content; max-width: 100%; flex-wrap: wrap; }
.sidebar-foot .btn { justify-content: flex-start; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Liste ---------- */
#list-pane { display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); min-height: 0; }
.list-head { padding: 16px 16px 10px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.list-title { display: flex; align-items: baseline; gap: 8px; }
.list-title h2 { margin: 0; font-size: 18px; }
#list-count { padding: 1px 8px; border-radius: 999px; background: var(--hover); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
#list-count:empty { display: none; }
.search {
  display: flex; align-items: center; gap: 8px; padding: 0 10px; height: 36px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--text); min-width: 0; }
.chips { display: flex; gap: 6px; }
.chip {
  padding: 3px 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 13px;
}
.chip.active { background: var(--accent-weak); border-color: transparent; color: var(--accent); font-weight: 600; }

#message-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; outline: none; user-select: none; }
.msg {
  position: relative; display: grid; grid-template-columns: 1fr auto; gap: 1px 10px;
  padding: 10px 14px 10px 32px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.msg { transition: background .12s; }
.msg:hover { background: var(--hover); }
.msg.selected { background: var(--selected); }
/* Klickflächen in der Zeile mind. 24 px (Fahne, Papierkorb, Kästchen), ohne das Layout zu verschieben */
.msg .flag-toggle, .msg .row-trash { padding: 4px; margin: -4px 0; }
.msg .pick::before { content: ""; position: absolute; inset: -5px; }
.msg .bar { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.msg .from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .date { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }
.msg .subject { grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.msg .subject span { overflow: hidden; text-overflow: ellipsis; }
.msg .snippet { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.unread .from, .msg.unread .subject { font-weight: 700; }
.msg.unread::after {
  content: ""; position: absolute; left: 14px; top: 16px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}
/* Auswahl-Kästchen: beim Drüberfahren sichtbar, in der Mehrfachauswahl immer (ersetzt dann den Ungelesen-Punkt) */
.msg .pick {
  position: absolute; left: 9px; top: 11px; width: 16px; height: 16px; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--muted); border-radius: 4px; background: var(--panel); color: #fff; opacity: 0;
}
.msg .pick .i { width: 12px; height: 12px; stroke-width: 3; visibility: hidden; }
.msg:hover .pick, #message-list.picking .pick { opacity: 1; }
.msg .pick:hover { border-color: var(--accent); }
.msg:hover::after, #message-list.picking .msg::after { display: none; }
#message-list.picking .msg.selected .pick { background: var(--accent); border-color: var(--accent); }
#message-list.picking .msg.selected .pick .i { visibility: visible; }
.msg .marks { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); flex: none; }
/* Beantwortet: im Blau des App-Symbols unterlegt, damit man es beim Überfliegen der Liste sofort sieht */
.msg .marks .answered {
  display: inline-flex; align-items: center; padding: 1px 6px; border-radius: 999px;
  background: var(--brand); color: #fff;
}
/* Rote Fahne „wichtig“: rechts in der Betreffzeile, beim Drüberfahren sichtbar, gesetzt immer */
.msg .flag-toggle {
  margin-left: auto; flex: none; display: inline-flex; align-items: center; padding: 1px 2px;
  border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; opacity: 0;
}
.msg:hover .flag-toggle, .msg.selected .flag-toggle, .msg .flag-toggle.on { opacity: 1; }
.msg .flag-toggle:hover { background: var(--hover); color: var(--flag); }
.msg .flag-toggle.on { color: var(--flag); }
.msg .flag-toggle.on .i { fill: currentColor; }
.msg .row-trash {
  flex: none; display: inline-flex; align-items: center; padding: 1px 2px; margin-left: 2px;
  border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; opacity: 0;
}
.msg:hover .row-trash, .msg.selected .row-trash { opacity: 1; }
.msg .row-trash:hover { background: var(--hover); color: var(--danger); }
.folder.special-flagged > .i { color: var(--flag); }
.folder .count.flag-count { color: var(--flag); }
.list-empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.list-more { padding: 12px; text-align: center; }

/* ---------- Lesebereich ---------- */
#reader { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel); }
.reader-empty { margin: auto; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; color: var(--muted); }
.reader-empty p { margin: 4px 0 0; max-width: 420px; font-size: 15px; font-weight: 500; color: var(--text); }
.empty-ic {
  width: 88px; height: 88px; display: flex; align-items: center; justify-content: center; border-radius: 50%;
  background: var(--accent-weak); color: var(--accent);
}
.empty-ic .i.big { width: 40px; height: 40px; stroke-width: 1.5; }
.kbd-hints { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; max-width: 440px; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.kbd-hints span { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.reader-head { padding: 14px 22px 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.toolbar { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; }
.subject-line { margin: 0; font-size: 20px; line-height: 1.3; word-break: break-word; }
.sender { display: flex; gap: 12px; align-items: center; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; flex: none; font-size: 15px;
}
.sender .who { flex: 1; min-width: 0; }
.sender .who .name { font-weight: 600; }
.sender .who .addr { color: var(--muted); }
.sender .who .rcpt { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender .when { text-align: right; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.tag {
  display: inline-flex; align-items: center; flex: none; padding: 0 7px; border-radius: 5px;
  font-size: 11px; font-weight: 600; line-height: 18px; background: var(--tag-bg); color: var(--tag-fg);
}
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px; border-radius: 999px;
  font-size: 12px; background: var(--hover); color: var(--text);
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; }

.ai-bar { display: flex; gap: 8px; align-items: center; }
.ai-bar input {
  flex: 1; min-width: 120px; height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
.ai-bar input:focus { outline: none; border-color: var(--ai); }
.ai-result {
  position: relative; padding: 12px 40px 12px 14px; border-radius: var(--radius); background: var(--ai-weak);
  line-height: 1.5; max-height: 40vh; overflow-y: auto;
}
.ai-result .ai-text { white-space: pre-wrap; }
.ai-result .ai-label { display: flex; align-items: center; gap: 6px; color: var(--ai); font-weight: 600; margin-bottom: 4px; }
.ai-result .icon-btn { position: absolute; top: 6px; right: 6px; }
.notice {
  display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-radius: 8px; background: var(--hover); font-size: 13px;
}
.attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.attachment {
  display: inline-flex; align-items: center; gap: 8px; max-width: 280px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer;
}
.attachment:hover { background: var(--hover); }
.attachment .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment .fsize { color: var(--muted); font-size: 12px; flex: none; }
.mail-frame { flex: 1; width: 100%; border: 0; background: #fff; min-height: 0; }

.loading { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); padding: 40px; }

/* Mehrfachauswahl: Sammelaktionen im Lesebereich */
.bulk { margin: auto; width: min(460px, 100%); padding: 30px 24px; display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; }
.bulk-count .i.big { color: var(--accent); }
.bulk-count h2 { margin: 6px 0 2px; font-size: 20px; }
.bulk-count p { margin: 0; }
.bulk-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
.bulk-actions .btn { justify-content: flex-start; }
.bulk-actions .btn.flag .i { color: var(--flag); }
.bulk-foot { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.bulk .small { margin: 0; font-size: 12.5px; }
.bulk .hint { margin: 0; }

/* ---------- Dialoge ---------- */
.modal {
  border: 0; padding: 0; border-radius: 14px; background: var(--panel); color: var(--text); box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(15, 20, 30, .45); animation: fade-in .18s ease-out; }
.modal[open] { animation: modal-in .2s var(--ease); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.985); } }
@keyframes fade-in { from { opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px 22px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.modal-body { position: relative; padding: 18px 22px 22px; overflow-y: auto; } /* relative: unsichtbare Labels (.sr-only) bleiben im Scrollbereich */

.compose { width: min(900px, 92vw); height: min(760px, 90vh); }
.compose form { display: flex; flex-direction: column; height: 100%; }
.compose-fields {
  display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 6px 10px; padding: 0 22px 10px;
}
.compose-fields label { color: var(--muted); font-size: 13px; }
.compose-fields input, .compose-fields select {
  height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); width: 100%;
}
.compose-fields input:focus, .compose-fields select:focus {
  outline: none; border-color: var(--accent);
}
#c-body {
  flex: 1; margin: 0 22px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
  resize: none; line-height: 1.5; min-height: 0;
}
#c-body:focus { outline: none; border-color: var(--accent); }
.attach-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 22px 0; }
.attach-row:empty { display: none; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border-radius: 999px; background: var(--hover); font-size: 13px;
}
.attach-chip input { margin: 0; }
.attach-chip .icon-btn { width: 24px; height: 24px; }
.file-btn { cursor: pointer; }
.compose-state { display: flex; flex-direction: column; min-width: 0; font-size: 12.5px; line-height: 1.3; }
.compose-state #compose-status:empty, .compose-state #compose-saved:empty { display: none; }
.compose-state #compose-saved { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Einstellungen: Rahmen, Reiter, Karten ---------- */
.settings { width: min(880px, 94vw); height: min(820px, 90vh); }
.settings[open] { display: flex; flex-direction: column; }
.settings-head { gap: 16px; padding: 12px 14px 12px 24px; border-bottom: 1px solid var(--line); }
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--hover); }
.seg .tab {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 14px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer; font-weight: 500; transition: background .15s, color .15s, box-shadow .15s;
}
.seg .tab:hover { color: var(--text); }
.seg .tab.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.seg .tab.active .i { color: var(--accent); }
.settings-body { flex: 1; min-height: 0; padding: 20px 24px 24px; background: var(--bg); }
.settings-body > section { display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.card-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.card-head:last-child { margin-bottom: 0; }
.card-ic {
  width: 34px; height: 34px; flex: none; display: flex; align-items: center; justify-content: center;
  border-radius: 9px; background: var(--accent-weak); color: var(--accent);
}
.card-title { flex: 1; min-width: 0; }
.card-title h4 { margin: 0; font-size: 14.5px; font-weight: 600; }
.card-title p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.note { display: flex; align-items: flex-start; gap: 8px; margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.note .i { margin-top: 2px; }
.pill {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; flex: none;
}
.pill.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok-strong); }
.pill.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn-strong); }
.count-pill {
  flex: none; display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 22px; padding: 0 8px;
  border-radius: 999px; background: var(--hover); color: var(--muted); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.icon-btn.danger-hover:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.empty { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 22px 16px; text-align: center; color: var(--muted); }
.empty .i { width: 28px; height: 28px; stroke-width: 1.5; color: var(--accent); opacity: .75; margin-bottom: 4px; }
.empty strong { color: var(--text); font-size: 14px; }
.empty span { font-size: 12.5px; max-width: 420px; line-height: 1.5; }

/* Eingabefelder in den Einstellungen (:where = geringe Spezifität, damit Karten sie gezielt anpassen können) */
.settings :where(input:not([type=checkbox], [type=hidden], [type=radio]), select, textarea) {
  width: 100%; height: 36px; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--text); transition: border-color .15s, box-shadow .15s, background .15s;
}
.settings :where(textarea) { height: auto; min-height: 90px; padding: 9px 11px; line-height: 1.55; resize: vertical; }
.settings :where(input, select, textarea):focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.settings input[type=checkbox] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); flex: none; }

/* Schiebeschalter (echte Checkbox, role=switch) */
.settings input.switch {
  appearance: none; -webkit-appearance: none; position: relative; width: 42px; height: 24px; border-radius: 999px;
  background: var(--switch-off); cursor: pointer; transition: background .2s var(--ease);
}
.settings input.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s var(--ease);
}
.settings input.switch:checked { background: var(--accent); }
.settings input.switch:checked::after { transform: translateX(18px); }
.settings input.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle-row { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.toggle-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.toggle-text strong { font-size: 14.5px; font-weight: 600; }
.toggle-text span { font-size: 12.5px; color: var(--muted); line-height: 1.45; }

/* ---------- Einstellungen → Konten ---------- */
.acc-list { display: flex; flex-direction: column; gap: 10px; }
.acc-card {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.acc-card:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); box-shadow: var(--shadow-md); }
.acc-avatar {
  width: 40px; height: 40px; flex: none; display: flex; align-items: center; justify-content: center; border-radius: 11px;
  color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .02em; text-shadow: 0 1px 1px rgba(0, 0, 0, .25);
}
.acc-card .info { flex: 1; min-width: 0; }
.acc-name { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.acc-name strong { white-space: nowrap; }
.acc-name .muted { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-status { display: flex; align-items: center; gap: 6px; margin-top: 2px; font-size: 12.5px; color: var(--muted); }
.acc-status.err { color: var(--danger); }
.ok-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--ok); }
.add-card {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 48px;
  border: 1.5px dashed color-mix(in srgb, var(--accent) 40%, var(--line)); border-radius: 12px;
  background: transparent; color: var(--accent); font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s;
}
.add-card:hover { background: var(--accent-weak); border-color: var(--accent); }

.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form .full { grid-column: 1 / -1; }
.form-title { display: flex; align-items: center; gap: 6px; margin: -4px 0 2px -8px; }
.form-title h4 { margin: 0; font-size: 15px; }
.i.back { transform: rotate(180deg); }
.form .field { display: flex; flex-direction: column; gap: 5px; }
.form .field > span { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.form .row { display: grid; grid-template-columns: 1fr 90px; gap: 8px; }
.hint { font-size: 12.5px; color: var(--muted); background: var(--hover); padding: 8px 10px; border-radius: 8px; }
.check { display: flex; align-items: center; gap: 8px; }
.folder-list {
  display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; max-height: 150px; overflow-y: auto;
}
.swatches { display: flex; gap: 8px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; transition: transform .12s; }
.swatch:hover { transform: scale(1.08); }
.swatch.active { box-shadow: 0 0 0 2px var(--text); }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; padding-top: 14px; border-top: 1px solid var(--line); }
.test-result { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.test-result:empty { display: none; }
.test-result .good { color: var(--ok-strong); }
.test-result .bad { color: var(--danger); }

/* ---------- Einstellungen → KI ---------- */
.key-row { display: flex; gap: 8px; align-items: center; }
.key-row input { flex: 1; }
.cost-card .card-ic { background: var(--ai-weak); color: var(--ai); }
.cost-grid { display: grid; grid-template-columns: 1.35fr repeat(3, 1fr); gap: 10px; }
.cost-total, .cost-tile { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 10px; background: var(--bg); min-width: 0; }
.cost-total { background: var(--ai-weak); }
.cost-label { font-size: 12px; font-weight: 500; color: var(--muted); }
.cost-value { font-size: 24px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; line-height: 1.25; }
.cost-num { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cost-sub { font-size: 12px; color: var(--muted); }
.cost-foot { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); }
.model-rows { display: flex; flex-direction: column; }
.model-row {
  display: grid; grid-template-columns: 30px 1fr minmax(300px, 55%); align-items: center; gap: 12px;
  padding: 11px 0; border-top: 1px solid var(--line);
}
.model-row:first-child { border-top: 0; padding-top: 0; }
.model-row:last-child { padding-bottom: 0; }
.model-ic { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; border-radius: 8px; background: var(--hover); color: var(--muted); }
.model-text { display: flex; flex-direction: column; min-width: 0; }
.model-text label { font-size: 13.5px; font-weight: 600; }
.model-text span { font-size: 12.5px; color: var(--muted); }
.privacy summary { display: flex; align-items: center; gap: 12px; cursor: pointer; list-style: none; border-radius: 8px; }
.privacy summary::-webkit-details-marker { display: none; }
.privacy .card-ic { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok-strong); }
.privacy .disclosure { color: var(--muted); transition: transform .2s var(--ease); }
.privacy[open] .disclosure { transform: rotate(90deg); }
.privacy ul { margin: 14px 0 8px; padding-left: 66px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; line-height: 1.5; }
.privacy > p { margin: 0 0 0 46px; font-size: 12.5px; line-height: 1.5; }
/* Speichern-Leiste klebt unten im Fenster; der KI-Reiter braucht dafür unten keinen Innenabstand */
.settings-body { padding-bottom: 0; }
.settings-body > section { padding-bottom: 24px; }
.settings-body > section:has(> .sticky-save) { padding-bottom: 0; }
.sticky-save {
  position: sticky; bottom: 0; z-index: 2; display: flex; align-items: center; justify-content: flex-end; gap: 14px;
  margin: 2px -24px 0; padding: 12px 24px; border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(8px);
}
.sticky-save .muted { font-size: 12.5px; }

/* ---------- Rückfrage ---------- */
.confirm { width: min(440px, 92vw); }
.confirm .modal-body { padding: 22px 22px 8px; }
#confirm-text { margin: 0; white-space: pre-wrap; line-height: 1.5; }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn.danger-fill:hover { filter: brightness(.95); }

/* ---------- KI-Feedback im Schreibfenster ---------- */
.ai-feedback {
  display: flex; align-items: center; gap: 8px; margin: 0 22px 8px; padding: 6px 8px 6px 12px;
  border-radius: 8px; background: var(--ai-weak); font-size: 13px;
}
.ai-feedback .ai-label { display: inline-flex; align-items: center; gap: 6px; color: var(--ai); font-weight: 600; }
.ai-bad { display: flex; gap: 8px; margin: 0 22px 8px; }
.ai-bad input { flex: 1; min-width: 0; height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.ai-bad input:focus { outline: none; border-color: var(--ai); }
.ai-bad select { height: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); padding: 0 6px; }

/* ---------- KI-Kosten unter der Zusammenfassung ---------- */
.ai-cost { margin-top: 6px; font-size: 12px; color: var(--muted); }

/* ---------- Einstellungen → Gelernt ---------- */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat {
  display: grid; grid-template-columns: auto 1fr; column-gap: 12px; align-items: center; padding: 14px 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-sm);
}
.stat-ic {
  grid-row: 1 / 3; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  border-radius: 10px; background: var(--accent-weak); color: var(--accent);
}
.stat-num { font-size: 22px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12.5px; color: var(--muted); }
.stat.attention { border-color: color-mix(in srgb, var(--ai) 45%, var(--line)); }
.stat.attention .stat-ic { background: var(--ai-weak); color: var(--ai); }
.suggest-card { border-color: color-mix(in srgb, var(--ai) 40%, var(--line)); }
.suggest-card .card-ic { background: var(--ai-weak); color: var(--ai); }
.rule-list { display: flex; flex-direction: column; gap: 2px; }
.rule { display: flex; align-items: center; gap: 8px; padding: 3px 4px 3px 10px; border-radius: 9px; transition: background .15s; }
.rule:hover { background: var(--hover); }
.rule-mark { width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--accent); }
.settings .rule .rule-text { flex: 1; min-width: 0; border-color: transparent; background: transparent; }
.settings .rule .rule-text:hover { border-color: var(--line); background: var(--panel); }
.settings .rule .rule-text:focus { border-color: var(--accent); background: var(--panel); }
.settings .rule select { width: auto; max-width: 200px; height: 32px; font-size: 13px; }
.rule.suggested { padding: 8px 8px 8px 12px; margin-bottom: 6px; background: var(--ai-weak); }
.rule.suggested:hover { background: var(--ai-weak); }
.rule.suggested .rule-mark { background: var(--ai); }
.settings .rule.suggested .rule-text { border-color: var(--line); background: var(--panel); }
.rule.new-rule { margin-top: 10px; padding: 12px 0 0 6px; border-top: 1px solid var(--line); border-radius: 0; }
.rule.new-rule:hover { background: transparent; }
.rule-plus { display: inline-flex; color: var(--accent); }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.acc-chip {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
  background: var(--hover); font-size: 12px; font-weight: 500; white-space: nowrap;
}
.acc-chip .dot { width: 8px; height: 8px; flex: none; border-radius: 50%; }
.example-list { display: flex; flex-direction: column; gap: 10px; }
.example { padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); transition: border-color .15s, box-shadow .15s; }
.example:hover { border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); box-shadow: var(--shadow-sm); }
.ex-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ex-head .icon-btn { width: 28px; height: 28px; }
.src-chip {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 6px;
  font-size: 11.5px; font-weight: 600; background: var(--hover); color: var(--muted);
}
.src-chip.draft_ok, .src-chip.good { background: color-mix(in srgb, var(--ok) 13%, transparent); color: var(--ok-strong); }
.src-chip.draft_fixed { background: var(--ai-weak); color: var(--ai); }
.src-chip.imported { background: var(--accent-weak); color: var(--accent); }
/* Lernen aus „Gesendet“ */
.import-list { display: flex; flex-direction: column; }
.import-row { display: flex; align-items: center; gap: 10px; padding: 10px 2px; }
.import-row + .import-row { border-top: 1px solid var(--line); }
.import-row:first-child { padding-top: 0; }
.import-row:last-child { padding-bottom: 0; }
.import-row > .dot { width: 9px; height: 9px; flex: none; border-radius: 50%; }
.import-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; }
.import-text .muted { font-size: 12.5px; }
.progress { display: block; height: 4px; margin-top: 4px; border-radius: 999px; background: var(--hover); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .3s var(--ease); }
.ex-date { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ex-subject { margin-top: 8px; font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ex-answer {
  margin-top: 3px; font-size: 13px; line-height: 1.5; color: var(--muted); white-space: pre-wrap;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---------- Adressbuch ---------- */
.i.fav { color: #d4a21c; fill: currentColor; }
.list-tools { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.contact-row {
  display: grid; grid-template-columns: 36px 1fr auto; grid-template-rows: auto auto; column-gap: 12px; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; transition: background .12s;
}
.contact-row:hover { background: var(--hover); }
.contact-row.selected { background: var(--selected); }
.ct-avatar, .ac-avatar, .contact-avatar {
  display: flex; align-items: center; justify-content: center; flex: none; border-radius: 50%;
  color: #fff; font-weight: 700; text-shadow: 0 1px 1px rgba(0, 0, 0, .2);
}
.ct-avatar { grid-row: 1 / 3; width: 36px; height: 36px; font-size: 13px; }
.ct-name { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-meta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ct-sub { grid-column: 2 / 4; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.contact-view {
  flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 16px;
  padding: 28px max(28px, calc((100% - 700px) / 2)) 40px;
}
.contact-head { display: flex; align-items: center; gap: 16px; }
.contact-avatar { width: 64px; height: 64px; font-size: 22px; }
.contact-avatar .i { width: 28px; height: 28px; }
.contact-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.contact-title h1 { margin: 0; font-size: 22px; line-height: 1.25; overflow-wrap: anywhere; }
.star-toggle.on { color: #d4a21c; }
.star-toggle.on .i { fill: currentColor; }
.contact-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.contact-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.contact-form .full { grid-column: 1 / -1; }
.contact-form .field { display: flex; flex-direction: column; gap: 5px; }
.contact-form .field > span { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.contact-form :where(input, textarea) {
  width: 100%; height: 36px; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--text); transition: border-color .15s, box-shadow .15s;
}
.contact-form textarea { height: auto; min-height: 72px; padding: 9px 11px; line-height: 1.5; resize: vertical; }
.contact-form :where(input, textarea):focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.contact-mails { display: flex; flex-direction: column; }
.contact-mail {
  display: grid; grid-template-columns: 18px 8px 1fr auto; align-items: center; gap: 10px; padding: 9px 6px;
  border: 0; border-top: 1px solid var(--line); background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.contact-mail:first-child { border-top: 0; }
.contact-mail:hover { background: var(--hover); }
.contact-mail.unread .subj { font-weight: 700; }
.contact-mail .dir { display: inline-flex; color: var(--muted); }
.contact-mail .dot { width: 8px; height: 8px; border-radius: 50%; }
.contact-mail .subj { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-mail .when { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Absender-Zeile in der Mail: Kontakt-Knopf */
.who-line { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.contact-chip {
  display: inline-flex; align-items: center; gap: 4px; align-self: center; height: 22px; padding: 0 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 12px; cursor: pointer; transition: color .15s, border-color .15s;
}
.contact-chip:hover { color: var(--accent); border-color: var(--accent); }
.contact-chip.add { border-style: dashed; }

/* Vorschläge beim Tippen (An/Cc/Bcc) */
.ac-box {
  position: absolute; z-index: 20; max-height: 320px; overflow-y: auto; padding: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-md);
}
.ac-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 7px; cursor: pointer; }
.ac-item.active, .ac-item:hover { background: var(--selected); }
.ac-avatar { width: 28px; height: 28px; font-size: 11px; }
.ac-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.ac-text strong { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-text span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  padding: 10px 16px; border-radius: 10px; background: #232733; color: #fff; box-shadow: var(--shadow);
  animation: toast-in .18s ease-out; max-width: 560px;
}
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Anmeldung (nur Server-Modus) ---------- */
body.auth-open #app { display: none; }
.auth {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  padding: 24px 16px; background: var(--bg); overflow-y: auto;
}
.auth-card {
  width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; padding: 28px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-md);
}
.auth-card.wide { max-width: 520px; }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand h1 { margin: 0; font-size: 22px; }
.auth-lead { margin: 0; color: var(--muted); line-height: 1.5; }
.auth-card .field { display: flex; flex-direction: column; gap: 5px; }
.auth-card .field > span { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.auth-card input {
  height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); font-size: 16px; /* 16px: sonst zoomt das iPhone beim Antippen hinein */
}
.auth-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.auth-card .btn.primary { height: 44px; }
.auth-error {
  margin: 0; padding: 10px 12px; border-radius: 8px; line-height: 1.4;
  background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger);
}
.auth-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 16px; line-height: 1.5; }
.auth-steps .field { margin-top: 10px; }
.auth-secret { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0 6px; }
.auth-secret code {
  padding: 8px 10px; border-radius: 8px; background: var(--hover);
  font-size: 15px; letter-spacing: .04em; user-select: all;
}
.auth-link { font-size: 13px; color: var(--accent); }

/* Einstellungen → Umzug vom PC auf den Server */
.transfer summary { display: flex; align-items: center; gap: 12px; cursor: pointer; list-style: none; border-radius: 8px; }
.transfer summary::-webkit-details-marker { display: none; }
.transfer .disclosure { color: var(--muted); transition: transform .2s var(--ease); }
.transfer[open] .disclosure { transform: rotate(90deg); }
.transfer .key-row { margin-bottom: 12px; }
.transfer-steps { margin: 14px 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; line-height: 1.5; }
.transfer-result {
  display: flex; flex-direction: column; gap: 4px; margin-top: 12px; padding: 12px 14px; border-radius: 10px;
  background: color-mix(in srgb, var(--ok) 12%, transparent); font-size: 13px; line-height: 1.5;
}
.transfer-result strong { display: flex; align-items: center; gap: 6px; color: var(--ok-strong); }
.transfer-result .bad { color: var(--danger); }
.transfer-warnings { display: flex; flex-direction: column; gap: 4px; font-size: 13px; line-height: 1.5; color: var(--danger); }
.transfer-warnings:not(:empty) { margin-bottom: 12px; }
.file-btn.disabled { opacity: .55; pointer-events: none; }

/* Einstellungen → „Anmeldung & Geräte“ */
.session-list { display: flex; flex-direction: column; gap: 8px; }
.session-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.session-row .info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.session-row .info .muted { font-size: 12.5px; }
.session-ic {
  display: grid; place-items: center; flex: none; width: 32px; height: 32px;
  border-radius: 8px; background: var(--hover); color: var(--muted);
}

@media (max-width: 1150px) {
  #app { grid-template-columns: 210px minmax(280px, 340px) 1fr; }
}

/* ---------- Handy (schmale Bildschirme, Bedienung mit dem Finger) ----------
   Eine Spalte statt drei: Liste vorn, Seitenleiste als Schublade, die geöffnete Mail legt sich
   über die Liste (public/js/mobile.js). Regeln: Tippflächen mind. 44 px, Eingabefelder 16 px
   (sonst zoomt das iPhone hinein), Abstand zu Notch und Home-Balken (safe-area). */
#btn-menu, #btn-compose-fab, #drawer-scrim, #reader-bar { display: none; }

@media (max-width: 900px) {
  html, body { height: 100dvh; }
  body { font-size: 16px; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
  input, select, textarea { font-size: 16px; }
  #app { display: block; height: 100dvh; }

  /* Tippflächen */
  .btn { height: 44px; }
  .btn.small { height: 40px; font-size: 14px; }
  .icon-btn { width: 44px; height: 44px; }
  .folder { min-height: 44px; }
  .folder.sub { min-height: 40px; font-size: 15px; }
  .twisty { width: 44px; height: 44px; }

  /* Seitenleiste als Schublade */
  #sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 30; width: min(86vw, 330px); border-right: 0;
    padding: calc(16px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
    transform: translateX(-103%); visibility: hidden;
    transition: transform .26s var(--ease), visibility 0s .26s;
  }
  #app.drawer-open #sidebar { transform: none; visibility: visible; box-shadow: var(--shadow); transition: transform .26s var(--ease), visibility 0s; }
  #drawer-scrim:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(15, 20, 30, .45); animation: fade-in .2s ease-out; }

  /* Liste */
  #list-pane { height: 100dvh; border-right: 0; }
  .list-head { padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left)); }
  .list-title { align-items: center; gap: 4px; }
  .list-title h2 { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 20px; }
  #btn-menu { display: inline-flex; margin-left: -8px; color: var(--text); }
  .search { height: 44px; }
  .chips { gap: 8px; }
  .chip { min-height: 38px; padding: 0 16px; font-size: 14px; }
  #message-list { padding-bottom: calc(92px + env(safe-area-inset-bottom)); overscroll-behavior-y: contain; }
  .msg { padding: 12px max(14px, env(safe-area-inset-right)) 12px calc(30px + env(safe-area-inset-left)); gap: 2px 10px; }
  .msg .date { font-size: 13px; }
  .msg .snippet { font-size: 14px; }
  .msg .pick, .msg .row-trash { display: none; } /* Mehrfachauswahl und Zeilen-Papierkorb brauchen die Maus */
  /* Fähnchen in der Zeile nur als Anzeige (zu klein zum Antippen) – markiert wird in der geöffneten Mail */
  .msg .flag-toggle { pointer-events: none; }
  .msg .flag-toggle:not(.on) { display: none; }
  .contact-row { min-height: 56px; }
  .list-tools { flex-wrap: wrap; }

  /* „Neue Mail“ in Daumennähe */
  #btn-compose-fab {
    display: flex; align-items: center; justify-content: center; position: fixed; z-index: 5;
    right: calc(18px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
    width: 58px; height: 58px; border: 0; border-radius: 50%; cursor: pointer;
    background: var(--accent); color: #fff; box-shadow: 0 6px 18px rgba(20, 28, 45, .3);
    transition: transform .12s, background .12s;
  }
  #btn-compose-fab .i { width: 24px; height: 24px; }
  #btn-compose-fab:active { transform: scale(.95); background: var(--accent-hover); }

  /* Geöffnete Mail (oder Kontakt) legt sich von rechts über die Liste */
  #reader-bar {
    display: flex; align-items: center; position: fixed; top: 0; left: 0; right: 0; z-index: 12;
    height: calc(52px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 8px 0 max(4px, env(safe-area-inset-left));
    background: var(--panel); border-bottom: 1px solid var(--line);
  }
  #reader {
    position: fixed; z-index: 11; top: calc(52px + env(safe-area-inset-top)); left: 0; right: 0; bottom: 0;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
  }
  #reader-bar, #reader { transform: translateX(100%); visibility: hidden; transition: transform .28s var(--ease), visibility 0s .28s; }
  #app.reading #reader-bar, #app.reading #reader { transform: none; visibility: visible; transition: transform .28s var(--ease), visibility 0s; }
  #btn-back { max-width: 76vw; padding: 0 12px 0 4px; gap: 2px; color: var(--accent); font-weight: 500; }
  #btn-back .i { width: 22px; height: 22px; }
  #back-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Kopf der Mail: Aktionen als Symbole in einer Reihe, darunter Betreff, Absender, KI */
  .reader-head { padding: 8px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left)); }
  .toolbar { gap: 2px; }
  .toolbar .btn.small { width: 44px; height: 44px; padding: 0; gap: 0; font-size: 0; } /* nur das Symbol; der Text bleibt für Vorleseprogramme */
  .toolbar .btn.small.primary, .toolbar [data-act="to-inbox"] { width: auto; padding: 0 12px; gap: 7px; font-size: 14px; }
  .toolbar .i { width: 20px; height: 20px; }
  .toolbar .sep { margin: 0 2px; }
  .sender { flex-wrap: wrap; row-gap: 2px; }
  .sender .when { flex-basis: 100%; padding-left: 52px; text-align: left; }
  .contact-chip { min-height: 40px; padding-left: 12px; padding-right: 12px; }
  .ai-bar { flex-wrap: wrap; }
  .ai-bar input { order: -1; flex-basis: 100%; height: 44px; }
  .ai-bar .btn { flex: 1; height: 44px; }
  .ai-result { max-height: none; }
  .notice { flex-wrap: wrap; }
  .attachment { min-height: 44px; }
  /* Erst scrollt der Kopf weg, dann die Mail in ihrem Rahmen (der Rahmen ist so hoch wie der Bildschirm) */
  .mail-frame { flex: none; height: calc(100dvh - 52px - env(safe-area-inset-top)); }

  /* Kontakt-Ansicht */
  .contact-form { grid-template-columns: 1fr; }
  .contact-actions .btn { flex: 1 1 auto; }
  .contact-form input, .contact-form textarea { min-height: 44px; }

  /* „Feste Mauer“: Kein Bereich lässt sich seitlich verschieben – auch dann nicht, wenn doch einmal
     etwas zu breit gerät. (Der Mail-Rahmen selbst scrollt breite Newsletter weiter in sich.) */
  .modal-body, .settings-body, .compose form, #reader, #message-list, #folders, .move-list, .auth { overflow-x: hidden; }

  /* Fenster im Vollbild: Schreiben und Einstellungen */
  .modal { max-width: none; max-height: none; }
  .compose, .settings { width: 100vw; height: 100dvh; margin: 0; border-radius: 0; }
  .compose .modal-head, .settings .modal-head { padding: calc(8px + env(safe-area-inset-top)) 8px 8px 16px; }

  /* Schreiben: Senden-Leiste direkt unter dem Titel (bleibt sichtbar, wenn die Tastatur offen ist) */
  .compose form { overflow-y: auto; }
  .compose form > :not(.modal-head):not(.modal-foot) { order: 2; }
  .compose .modal-foot { order: 1; flex-wrap: wrap; padding: 4px 12px 10px; border-top: 0; border-bottom: 1px solid var(--line); }
  .compose-state { order: 5; flex-basis: 100%; }
  .compose-fields { grid-template-columns: 54px 1fr; gap: 8px; padding: 10px 12px; }
  .compose-fields input, .compose-fields select { height: 44px; }
  #c-body { flex: 1 0 auto; min-height: 45dvh; margin: 0 12px calc(12px + env(safe-area-inset-bottom)); }
  .ai-feedback, .ai-bad { flex-wrap: wrap; margin: 0 12px 8px; }
  .ai-bad input, .ai-bad select { height: 44px; }
  .attach-row { padding: 8px 12px 0; }

  /* Einstellungen */
  .settings-head { flex-wrap: wrap; row-gap: 8px; }
  .settings-head .seg { order: 3; width: 100%; }
  .settings-head .seg .tab { flex: 1; justify-content: center; height: 40px; padding: 0 8px; }
  .settings-body { padding: 14px 12px 0; }
  .settings-body > section { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .settings :where(input:not([type=checkbox], [type=hidden], [type=radio]), select) { height: 44px; }
  .settings input[type=checkbox]:not(.switch) { width: 20px; height: 20px; }
  .card { padding: 14px; }
  .card-head { flex-wrap: wrap; }
  .drag-note { display: none; } /* Umsortieren per Ziehen gibt es nur mit der Maus */
  .acc-card { flex-wrap: wrap; gap: 10px 12px; }
  .acc-card .info { flex-basis: calc(100% - 56px); }
  .acc-name { flex-wrap: wrap; gap: 0 8px; }
  .acc-card .btn { flex: 1; }
  .form { grid-template-columns: 1fr; }
  .form-actions { flex-wrap: wrap; }
  .swatches { flex-wrap: wrap; gap: 12px; }
  .swatch { width: 36px; height: 36px; }
  .key-row { flex-wrap: wrap; }
  .cost-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .cost-total { grid-column: 1 / -1; }
  /* minmax(0, …): Ein Auswahlfeld mit langem Eintrag darf die Zeile nicht breiter drücken als den
     Bildschirm (Safari rechnet solche Felder breiter als Chrome). */
  .model-row { grid-template-columns: 30px minmax(0, 1fr); }
  .model-row select { grid-column: 1 / -1; }
  .settings-body > section, .card, .card-title, .toggle-text, .model-text { min-width: 0; }
  .settings :where(input, select, textarea), .compose-fields :where(input, select), .contact-form :where(input, textarea) { min-width: 0; max-width: 100%; }
  select { text-overflow: ellipsis; }
  .key-row input { flex: 1 1 180px; }
  .privacy ul { padding-left: 22px; }
  .privacy > p { margin-left: 0; }
  .stat-row { grid-template-columns: 1fr; }
  .sticky-save { margin: 2px -12px 0; padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); }
  .session-row { flex-wrap: wrap; }
  .theme-seg { width: 100%; flex-wrap: nowrap; }
  .theme-seg .tab { flex: 1; justify-content: center; height: 40px; padding: 0 6px; font-size: 14px; white-space: nowrap; }
  .theme-seg .tab .i { display: none; }

  /* „Verschieben nach …“ als Blatt von unten, Rückfragen bleiben klein in der Mitte */
  .move { width: 100vw; max-height: 85dvh; margin: auto 0 0; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }

  /* Meldungen über dem runden Knopf */
  #toasts { left: 12px; right: 12px; bottom: calc(88px + env(safe-area-inset-bottom)); transform: none; align-items: center; }
  .toast { max-width: 100%; }

  /* Anmeldung */
  .auth { place-items: start center; padding: calc(24px + env(safe-area-inset-top)) 14px calc(24px + env(safe-area-inset-bottom)); }
  .auth-card { padding: 22px 18px; }
  .auth-card input { height: 46px; }
  .auth-card .btn.small { height: 40px; }
}
