:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1b2128;
  --muted: #687380;
  --border: #dfe3e8;
  --accent: #2b5f8f;
  --accent-soft: #e3edf6;
  --danger: #b4443a;
  --unread: #2b5f8f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111519;
    --surface: #1a2027;
    --text: #e6ebf0;
    --muted: #8c97a3;
    --border: #29313a;
    --accent: #6aa5dc;
    --accent-soft: #1d2f40;
    --danger: #e0786e;
    --unread: #6aa5dc;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); font-size: .9rem; }
.small { font-size: .8rem; margin: 0; }

/* Buttons */
.btn {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 10px; padding: .55rem 1rem; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.block { display: block; width: 100%; margin: 12px 0; }
.btn:disabled { opacity: .5; }
.small-btn { padding: .35rem .7rem; font-size: .88rem; }
.icon-btn { border: 0; background: none; font-size: 1.3rem; cursor: pointer; color: var(--muted); padding: .4rem; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: .3rem .8rem; font-size: .85rem; cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border-radius: var(--radius);
  padding: 2rem 1.5rem; box-shadow: var(--shadow); display: grid; gap: .9rem; text-align: center;
  justify-items: center;
}
.login-card h1 { margin: 0; font-size: 1.4rem; }
.login-card input, .login-card button { width: 100%; }
.login-card input { border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem; background: var(--bg); }
.error { color: var(--danger); margin: 0; }

/* Layout */
#app { max-width: 820px; margin: 0 auto; min-height: 100%; }
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 14px) 16px 8px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
}
.topbar h1 { margin: 0; font-size: 1.6rem; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar #top-info { flex: 1; text-align: right; white-space: nowrap; }
.topbar .icon-btn { align-self: center; }
main { padding: 0 16px calc(90px + env(safe-area-inset-bottom)); }

.toolbar { display: flex; gap: .5rem; align-items: center; margin-bottom: 8px; }
.toolbar select {
  flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: 10px;
  padding: .45rem .6rem; background: var(--surface);
}
.suche { flex: 1; min-width: 0; }
.suche input {
  width: 100%; border: 1px solid var(--border); border-radius: 999px; padding: .4rem .9rem; background: var(--surface);
}

/* Mails */
.mail-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.mail-list:empty { display: none; }
.mail {
  display: flex; gap: .65rem; align-items: flex-start; padding: .65rem .85rem;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.mail:last-child { border-bottom: 0; }
.mail .dot { flex: none; width: 9px; height: 9px; border-radius: 50%; margin-top: .45rem; }
.mail.ungelesen .dot { background: var(--unread); }
.mail .body { flex: 1; min-width: 0; }
.mail .zeile { display: flex; gap: .5rem; align-items: baseline; }
.mail .von { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail.ungelesen .von, .mail.ungelesen .betreff { font-weight: 650; }
.mail .datum { flex: none; font-size: .8rem; color: var(--muted); }
.mail .betreff { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .93rem; }
.mail .adresse { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail input[type=checkbox] { flex: none; width: 20px; height: 20px; margin-top: .2rem; accent-color: var(--accent); }
.mail.gewaehlt { background: var(--accent-soft); }
.empty { text-align: center; color: var(--muted); padding: 3rem 0; }

/* Karten (Übersicht, Regeln, Konten) */
.card-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .8rem .95rem; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 .2rem; font-size: 1.02rem; }
.card .aktionen { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.card.aus { opacity: .75; }
.compact .card { padding: .5rem .8rem; font-size: .88rem; }
.group-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 4px 8px; font-weight: 600; }
.zahlen { display: flex; gap: 1.5rem; margin: .4rem 0 .6rem; }
.zahl b { display: block; font-size: 1.6rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.zahl span { font-size: .8rem; color: var(--muted); }
.absender { list-style: none; margin: 0; padding: 0; }
.absender li { display: flex; align-items: center; gap: .5rem; padding: .4rem 0; border-top: 1px solid var(--border); }
.absender .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.absender .n { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; }
.badge { background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 0 .4rem; font-size: .8rem; }
.badge.an { background: var(--accent); color: #fff; }

/* Schalter */
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.regel-kopf { display: flex; gap: .6rem; align-items: center; }
.regel-kopf h3 { flex: 1; margin: 0; }

/* Auswahl-Leiste */
.auswahl-bar {
  position: fixed; left: 0; right: 0; bottom: calc(58px + env(safe-area-inset-bottom)); z-index: 6;
  max-width: 820px; margin: 0 auto; padding: 8px 12px; background: var(--surface);
  border-top: 1px solid var(--border); display: flex; gap: .4rem; align-items: center;
}
.auswahl-bar span { font-weight: 600; min-width: 2rem; text-align: center; }
.auswahl-bar button {
  flex: 1; border: 1px solid var(--border); background: var(--bg); border-radius: 10px; padding: .5rem .2rem;
  font-size: .85rem; cursor: pointer;
}
.auswahl-bar button.danger { color: var(--danger); }

/* FAB + Tabbar */
.fab {
  position: fixed; right: max(16px, calc(50% - 394px)); bottom: calc(76px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
  font-size: 2rem; line-height: 1; box-shadow: 0 6px 18px rgba(0,0,0,.2); cursor: pointer; z-index: 6;
}
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 7; background: var(--surface);
  border-top: 1px solid var(--border); display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; max-width: 160px; border: 0; background: none; padding: .5rem 0 .55rem; cursor: pointer;
  display: grid; justify-items: center; gap: 1px; font-size: .72rem; color: var(--muted);
}
.tabbar button span { font-size: 1.2rem; line-height: 1.2; }
.tabbar button.active { color: var(--accent); font-weight: 600; }

/* Dialoge */
dialog {
  width: min(560px, calc(100% - 32px)); max-height: calc(100% - 32px); border: 0; border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
.form { padding: 1.2rem; display: grid; gap: .8rem; }
.form h2 { margin: 0; font-size: 1.2rem; }
.form h3 { margin: .2rem 0 0; font-size: 1rem; }
.form label { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); }
.form label.inline { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.form label.check-label { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: .92rem; }
.form input:not([type=checkbox]), .form select, .form textarea {
  border: 1px solid var(--border); border-radius: 10px; padding: .5rem .65rem;
  background: var(--bg); color: var(--text); width: 100%; min-width: 0;
}
.form label.inline input, .form label.inline select { width: auto; }
.form label.inline input[type=number] { width: 5rem; }
.form input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; align-items: end; }
.row-inline { display: flex; gap: .5rem; }
.row-inline input { flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: 10px; padding: .5rem .65rem; background: var(--bg); }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: .6rem .7rem .7rem; margin: 0; display: grid; gap: .6rem; }
legend { font-size: .85rem; color: var(--muted); padding: 0 .3rem; font-weight: 600; }
.bedingung { display: grid; grid-template-columns: 1fr 1fr 1.4fr auto; gap: .35rem; align-items: center; }
.bedingung .icon-btn { font-size: 1.1rem; }
@media (max-width: 480px) {
  .bedingung { grid-template-columns: 1fr 1fr auto; }
  .bedingung input { grid-column: 1 / 3; grid-row: 2; }
  .bedingung .icon-btn { grid-column: 3; grid-row: 1 / 3; }
}
details summary { cursor: pointer; font-size: .85rem; color: var(--muted); }
details .row { margin-top: .5rem; }
.hinweis { margin: 0; font-size: .85rem; background: var(--accent-soft); border-radius: 10px; padding: .55rem .7rem; }
.dialog-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.regel-test { border: 1px solid var(--border); border-radius: 10px; padding: .6rem .7rem; font-size: .85rem; max-height: 220px; overflow: auto; }
.regel-test ul { margin: .3rem 0 0; padding-left: 1.1rem; }
.ordner-auswahl { display: grid; gap: 4px; max-height: 50vh; overflow: auto; }
.ordner-auswahl button {
  text-align: left; border: 1px solid var(--border); background: var(--bg); border-radius: 10px;
  padding: .5rem .7rem; cursor: pointer;
}

/* Mail lesen (Vollbild) */
dialog.full {
  width: 100%; max-width: 820px; height: 100%; max-height: 100%; margin: 0 auto; border-radius: 0;
}
.mail-view { display: flex; flex-direction: column; height: 100%; }
.mail-actions {
  display: flex; gap: .35rem; align-items: center; padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.mail-head { padding: .7rem 1rem .5rem; border-bottom: 1px solid var(--border); }
.mail-head h2 { margin: 0 0 .3rem; font-size: 1.15rem; overflow-wrap: anywhere; }
.mail-tools { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.anhaenge { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.anhaenge button { border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: .25rem .6rem; font-size: .82rem; cursor: pointer; }
#mail-frame { flex: 1; width: 100%; border: 0; background: #fff; }
#mail-text { flex: 1; margin: 0; padding: 1rem; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: .95rem; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(130px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: 10px; z-index: 20;
  display: flex; gap: 1rem; align-items: center; max-width: calc(100% - 32px);
}
.laden {
  position: fixed; top: calc(env(safe-area-inset-top) + 10px); left: 50%; transform: translateX(-50%); z-index: 30;
  background: var(--accent); color: #fff; padding: .25rem .9rem; border-radius: 999px; font-size: .85rem;
}
