/* ─── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: var(--size-body);
  color: var(--text-primary);
  background: var(--bg-grouped);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  line-height: 1.35;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); text-decoration: none; }
input, textarea, select { font: inherit; color: inherit; }

/* HIG/Accessibility: deutlicher Focus-Ring auf allen Form-Controls.
 * Greift auch in form-rows ohne extra Wrapper. */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: 6px;
}
/* Nicht-fokussierten Form-Controls einen subtilen "click-feedback" geben */
.form-row > input:hover:not(:focus),
.form-row > select:hover:not(:focus),
.form-row > textarea:hover:not(:focus) {
  background: rgba(120,120,128,0.06) !important;
}

/* ─── Shell ─────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; min-height: 100vh; }

.header {
  position: sticky; top: 0; z-index: 5;
  height: var(--header-h);
  display: flex; align-items: center;
  padding: 0 var(--s-4);
  background: var(--bg-toolbar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
          backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}
.header__back {
  /* Apple-Style: Pfeil + Text als ein großer Tap-Target.
   * min-height/padding sorgen für die HIG-empfohlene 44 pt Mindest-Touch-Fläche. */
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 10px 14px 10px 4px;
  margin: -10px 0 -10px -4px;     /* visuell nicht größer wirken — nur Klickfläche */
  min-height: 44px;
  font-size: var(--size-title-2);
  color: var(--accent);
  background: none; border: 0;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0, 122, 255, 0.18);
}
.header__back:hover  { background: rgba(0, 122, 255, 0.08); }
.header__back:active { background: rgba(0, 122, 255, 0.16); }
.header__back:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.header__title {
  flex: 1 1 auto;
  font-size: var(--size-title-2);
  font-weight: var(--weight-semi);
  text-align: center;
  margin: 0;
}
.header__actions { flex: 0 0 auto; display: flex; gap: var(--s-2); }
.header__btn {
  width: 32px; height: 32px;
  border-radius: var(--r-pill);
  background: rgba(120,120,128,0.12);
  border: 0; color: var(--text-primary);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px;
  text-decoration: none;
  /* HIG: 44×44 pt Touch-Target durch unsichtbare Erweiterung der Hit-Area.
   * Visuell bleibt der Button 32×32, klickbar ist er 44×44. */
  position: relative;
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0, 122, 255, 0.18);
}
.header__btn::before {
  content: "";
  position: absolute;
  top: -6px; right: -6px; bottom: -6px; left: -6px;
  /* min 44px Tap-Area, transparent — fängt Klicks/Taps ab */
}
.header__btn:active { background: rgba(120,120,128,0.22); }
.header__btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.header--large {
  height: 100px;
  align-items: flex-end;
  padding-bottom: var(--s-3);
}
.header--large .header__title {
  font-size: var(--size-largetitle);
  font-weight: var(--weight-bold);
  text-align: left;
  letter-spacing: -0.4px;
}
.header--large .header__sub {
  font-size: var(--size-footnote);
  color: var(--text-tertiary);
  margin-top: 2px;
}
.header--large .header__heading-wrap { flex: 1 1 auto; }

.main {
  flex: 1 1 auto;
  padding: var(--s-4);
  padding-bottom: calc(var(--tabbar-h) + var(--s-6) + env(safe-area-inset-bottom, 0));
}

/* Bottom Tab Bar (Mobile) */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0));
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: var(--bg-toolbar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
          backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
  display: flex; z-index: 5;
}
.tabbar__item {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  background: none; border: 0;
  color: var(--text-tertiary);
  text-decoration: none;
  font-size: 10px;
  font-weight: var(--weight-med);
  padding: 0;
}
.tabbar__item .ic { font-size: 22px; line-height: 1; }
.tabbar__item.is-active { color: var(--accent); }

/* ─── Sections / Cards / Rows ────────────────────────────── */
.section { margin-bottom: var(--s-6); }
.section__label {
  text-transform: uppercase;
  font-size: var(--size-caption);
  font-weight: var(--weight-semi);
  color: var(--text-tertiary);
  letter-spacing: 0.4px;
  padding: 0 var(--s-4) var(--s-2);
}
.section__hint {
  font-size: var(--size-footnote);
  color: var(--text-tertiary);
  padding: var(--s-2) var(--s-4) 0;
}

.card {
  background: var(--bg-card);
  border-radius: var(--r-card);
  overflow: hidden;
}
.card + .card { margin-top: var(--s-3); }

.row {
  display: flex; align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  min-height: 56px;
  position: relative;
  background: var(--bg-card);
  text-decoration: none;
  color: inherit;
  width: 100%;
  text-align: left;
  border: 0;
}
.row + .row::before {
  content: ""; position: absolute;
  left: var(--s-4); right: 0; top: 0;
  height: 0.5px; background: var(--separator);
}
.row__leading { flex: 0 0 auto; font-size: 22px; line-height: 1; }
.row__main { flex: 1 1 auto; min-width: 0; }
.row__title {
  font-size: var(--size-body);
  font-weight: var(--weight-med);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row__sub {
  font-size: var(--size-footnote);
  color: var(--text-tertiary);
  margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row__trailing {
  flex: 0 0 auto;
  display: flex; align-items: center;
  gap: var(--s-2);
  color: var(--text-tertiary);
  font-size: var(--size-footnote);
}
.row__chevron { color: var(--text-quaternary); font-size: 18px; margin-left: var(--s-1); }
.row.is-tappable:active { background: rgba(0,0,0,0.04); }
.row.is-tappable:hover { background: rgba(0,0,0,0.02); }

/* ─── Status ────────────────────────────────────────────── */
.status {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--size-footnote);
  font-weight: var(--weight-med);
}
.status--done    { color: var(--success); }
.status--running { color: var(--warn); }
.status--queued  { color: var(--pending); }
.status--failed  { color: var(--danger); }
.status .dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; background: currentColor;
}
.status--running .dot { animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.55; transform: scale(0.85); }
}
.status__icon {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: var(--weight-semi);
  color: #fff; flex: 0 0 22px;
}
.status__icon--done      { background: var(--success); }
.status__icon--failed    { background: var(--danger); }
.status__icon--running   { background: var(--warn); }
.status__icon--queued    { background: var(--pending); }
.status__icon--restarted { background: #ff9500; }   /* Orange — durch Restart unterbrochen + neu submittet */

/* Priority-Pill (0..100) für Trigger und queued Fires */
.prio-pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.prio-pill--low  { background: #e5e5ea; color: #555; }
.prio-pill--mid  { background: #dbeafe; color: #1a4ba0; }
.prio-pill--high { background: #ffe5cc; color: #b25a00; }
.prio-pill--crit { background: #fde0e0; color: #a01818; }

/* ─── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s-2);
  font-size: var(--size-body);
  font-weight: var(--weight-semi);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-button);
  border: 0;
  background: rgba(120,120,128,0.16);
  color: var(--text-primary);
  min-height: 44px;
  text-decoration: none;
}
.btn--primary { background: var(--accent); color: var(--text-on-accent); }
.btn--danger  { background: var(--danger); color: var(--text-on-accent); }
/* iOS „Tinted" Button: Akzent-Farbe als Text auf abgemildertem Akzent-Hintergrund.
 * Optisch zwischen ghost (nur Text) und primary (filled). Standard für sekundäre
 * Aktionen in iOS-Sheets/Forms. */
.btn--tinted  { background: rgba(0, 122, 255, 0.12); color: var(--accent); }
.btn--tinted:hover  { background: rgba(0, 122, 255, 0.18); }
.btn--tinted:active { background: rgba(0, 122, 255, 0.25); }
.btn--ghost   { background: transparent; color: var(--accent); }
.btn--full    { width: 100%; }
.btn--small   {
  font-size: var(--size-footnote);
  padding: 6px 12px;
  min-height: 32px;
}
.btn-mini {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border-radius: var(--r-pill);
  background: rgba(120,120,128,0.16);
  border: 0; font-size: 14px;
  color: var(--text-secondary);
  position: relative;
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0, 122, 255, 0.18);
}
/* HIG: ausgedehnte Tap-Area (44×44) ohne visuelle Vergrößerung */
.btn-mini::before {
  content: "";
  position: absolute;
  top: -7px; right: -7px; bottom: -7px; left: -7px;
}
.btn-mini:active { background: rgba(120,120,128,0.28); }
.btn-mini:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn-mini--danger { color: var(--danger); }

/* ─── Search Bar ────────────────────────────────────────── */
.searchbar { position: relative; margin-bottom: var(--s-4); }
.searchbar input {
  width: 100%;
  background: rgba(120,120,128,0.12);
  border: 0; border-radius: var(--r-button);
  padding: 8px 12px 8px 32px;
  font-size: var(--size-body);
  height: 36px; color: var(--text-primary);
}
.searchbar::before {
  content: "🔍"; position: absolute;
  left: 10px; top: 50%; transform: translateY(-50%);
  font-size: 13px; color: var(--text-tertiary);
  pointer-events: none;
}

/* ─── Filter Pills ──────────────────────────────────────── */
.pills {
  display: flex; gap: var(--s-2);
  overflow-x: auto;
  padding: 0 var(--s-4) var(--s-3);
  margin: 0 calc(var(--s-4) * -1);
  -webkit-overflow-scrolling: touch;
}
.pills::-webkit-scrollbar { display: none; }
.pill {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: var(--r-pill);
  background: rgba(120,120,128,0.12);
  font-size: var(--size-footnote);
  font-weight: var(--weight-med);
  color: var(--text-secondary);
  border: 0; white-space: nowrap;
  cursor: pointer;
}
.pill.is-active { background: var(--accent); color: var(--text-on-accent); }

/* ─── Bottom Sheet ──────────────────────────────────────── */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 20;
  opacity: 0;
  transition: opacity .2s;
}
.sheet-backdrop.is-open { opacity: 1; }
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg-grouped);
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  box-shadow: var(--shadow-high);
  z-index: 21;
  padding: 8px var(--s-4) calc(var(--s-6) + env(safe-area-inset-bottom, 0));
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform .25s ease-out;
}
.sheet.is-open { transform: translateY(0); }
.sheet__handle {
  width: 36px; height: 5px;
  background: var(--text-quaternary);
  border-radius: 3px;
  margin: 4px auto var(--s-3);
}
/* Runder ×-Schließbutton oben rechts — konsistent in allen Bottom-Sheets,
 * damit der User nicht raten muss wie er das Sheet wieder los wird. */
.sheet__close {
  position: absolute;
  top: var(--s-3);
  right: var(--s-3);
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(120,120,128,0.16);
  border: 0;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-primary);
  z-index: 1;
}
.sheet__close:active { background: rgba(120,120,128,0.30); }
.sheet__title {
  font-size: var(--size-title-1);
  font-weight: var(--weight-bold);
  margin: 0 0 4px;
  letter-spacing: -0.3px;
}
.sheet__sub {
  font-size: var(--size-footnote);
  color: var(--text-tertiary);
  margin: 0 0 var(--s-4);
  font-family: var(--font-mono);
}

/* ─── Form Rows ─────────────────────────────────────────── *
 * Layout-Regel: Label links (auto-width), Control rechts (rechtsbündig
 * + einheitliche Breite pro Input-Typ). Damit sehen alle Settings-Pages
 * konsistent aus, egal ob Toggle, Text-Input, Number, Time oder Select. */
.form-row {
  display: flex; align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  min-height: 44px;
  position: relative;
  background: var(--bg-card);
}
.form-row + .form-row::before {
  content: ""; position: absolute;
  left: var(--s-4); right: 0; top: 0;
  height: 0.5px; background: var(--separator);
}
.form-row__label {
  flex: 0 0 auto;
  color: var(--text-primary);
  font-size: var(--size-body);
}
.form-row__value {
  flex: 1 1 auto; text-align: right;
  color: var(--text-tertiary);
  font-size: var(--size-body);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Einheitliche Größen pro Input-Typ — !important, damit inline-styles
 * (alte HTML-Pages, Wireframe-Imports) übersteuert werden. */
.form-row > input,
.form-row > select,
.form-row > textarea {
  font: inherit;
  font-size: var(--size-body);
  color: var(--text-primary);
  background: transparent !important;
  border: 0 !important;
  margin-left: auto !important;       /* schiebt das Control nach rechts */
  text-align: right !important;
  flex: 0 0 auto !important;
  outline: none;
}
.form-row > input[type="text"],
.form-row > input[type="email"],
.form-row > input[type="url"],
.form-row > input[type="password"],
.form-row > input[type="search"],
.form-row > input:not([type]) {
  width: 65% !important;
  max-width: 360px !important;
}
.form-row > input[type="number"] {
  width: 110px !important;
}
.form-row > input[type="time"] {
  width: 110px !important;
}
.form-row > input[type="date"] {
  width: 150px !important;
}
.form-row > select {
  max-width: 65% !important;
  /* Damit der Native-Pfeil nicht rechts „flieht" — kompakter Look. */
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  padding-right: 18px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%23999' d='M0 0l5 6 5-6z'/></svg>") !important;
  background-repeat: no-repeat !important;
  background-position: right 4px center !important;
}
.form-row > textarea {
  width: 100% !important;
  text-align: left !important;
  min-height: 80px;
  resize: vertical;
}

/* Toggle: immer ganz rechts. Egal ob inline-styled oder nicht. */
.toggle {
  position: relative;
  width: 51px; height: 31px;
  background: rgba(120,120,128,0.16);
  border-radius: var(--r-pill);
  flex: 0 0 auto;
  border: 0; padding: 0;
  cursor: pointer;
  transition: background .2s;
}
.form-row > .toggle {
  margin-left: auto !important;
}
.toggle::after {
  content: ""; position: absolute;
  top: 2px; left: 2px;
  width: 27px; height: 27px;
  background: #fff; border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  transition: left .2s;
}
.toggle.is-on { background: var(--success); }
.toggle.is-on::after { left: 22px; }

/* Multi-Line-Form-Rows (display:block) — z. B. Notiz-Felder mit Textarea —
 * brauchen kein right-align, der textarea selbst regelt das via :not-Selektor. */
.form-row[style*="display:block"] > input,
.form-row[style*="display:block"] > textarea {
  text-align: left !important;
  width: 100% !important;
  max-width: none !important;
  margin-left: 0 !important;
}

/* ─── Misc ──────────────────────────────────────────────── */
.muted { color: var(--text-tertiary); }
.mono  { font-family: var(--font-mono); font-size: var(--size-footnote); }
.tag {
  display: inline-block;
  font-size: var(--size-caption);
  font-weight: var(--weight-semi);
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: rgba(120,120,128,0.14);
  color: var(--text-secondary);
  letter-spacing: 0.2px;
}
.tag--warn   { background: rgba(255, 149, 0, 0.18);  color: #b25d00; }
.tag--danger { background: rgba(255, 59, 48, 0.16);  color: #b1221c; }
.tag--accent { background: rgba(0, 122, 255, 0.14);  color: var(--accent); }
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(120,120,128,0.2);
  border-top-color: var(--text-tertiary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state {
  text-align: center;
  padding: var(--s-6) var(--s-4);
  color: var(--text-tertiary);
  font-size: var(--size-footnote);
}
.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--tabbar-h) + var(--s-4) + env(safe-area-inset-bottom, 0));
  transform: translateX(-50%) translateY(80px);
  padding: 10px 16px;
  border-radius: var(--r-button);
  background: rgba(28, 28, 30, 0.92);
  color: #fff;
  font-size: var(--size-footnote);
  font-weight: var(--weight-med);
  /* MUSS über allem liegen — Mail-Overlay (9500), Composer-Sheet (9501),
     andere Modals. Fehler-Toasts wurden sonst hinter dem Composer
     gerendert und der User sah nur „Senden hat nicht geklappt" ohne
     den eigentlichen SMTP-Fehler. */
  z-index: 99999;
  box-shadow: var(--shadow-mid);
  opacity: 0;
  transition: transform .2s, opacity .2s;
  pointer-events: none;
}
.toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.is-error { background: rgba(255, 59, 48, 0.95); }

/* ─── Desktop ≥ 768 px ──────────────────────────────────── */
@media (min-width: 768px) {
  .header { height: 56px; padding: 0 var(--s-6); }
  .header--large { height: 56px; align-items: center; padding-bottom: 0; }
  .header--large .header__title { font-size: var(--size-title-2); text-align: left; }
  .header--large .header__sub {
    margin-top: 0; margin-left: var(--s-3);
    display: inline-block; vertical-align: middle;
  }
  .header__title { text-align: left; }
  .desktop-tabs {
    display: flex; align-items: center; gap: var(--s-1);
    margin: 0 auto 0 var(--s-6);
  }
  .desktop-tabs a {
    padding: 6px 14px;
    border-radius: var(--r-button);
    color: var(--text-secondary);
    font-size: var(--size-callout);
    font-weight: var(--weight-med);
  }
  .desktop-tabs a.is-active {
    background: rgba(0, 122, 255, 0.10);
    color: var(--accent);
  }
  .tabbar { display: none; }
  .main {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--s-6);
    padding-bottom: var(--s-8);
  }
  .main--narrow {
    max-width: var(--content-max-narrow);
  }
  .row { padding: var(--s-3) var(--s-5); }
  .toast { bottom: var(--s-6); }
}

/* Lange Labels in Rows dürfen wrappen — verhindert Abschnitte auf /active */
.row__title--wrap, .row__sub--wrap {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  word-break: break-word;
}

/* ─── Kebab-Menü ────────────────────────────────────────── */
.kebab-menu {
  position: fixed;
  z-index: 100;
  background: var(--bg-card);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-high);
  min-width: 220px;
  max-width: 280px;
  padding: 6px 0;
  overflow: hidden;
  animation: kebab-fade .12s ease-out;
}
@keyframes kebab-fade {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.kebab-menu__item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 10px var(--s-4);
  width: 100%;
  background: none; border: 0;
  color: var(--text-primary);
  font-size: var(--size-body);
  text-decoration: none;
  cursor: pointer;
  text-align: left;
}
.kebab-menu__item:hover { background: rgba(0,0,0,0.04); }
.kebab-menu__item:active { background: rgba(0,0,0,0.08); }
.kebab-menu__item--danger { color: var(--danger); }
.kebab-menu__icon {
  width: 22px; font-size: 18px;
  flex: 0 0 auto;
  text-align: center;
}
.kebab-menu__sep {
  height: 0.5px;
  background: var(--separator);
  margin: 4px 0;
}
@media (max-width: 767px) {
  .desktop-tabs { display: none; }
}

/* ─── App-Switcher ────────────────────────────────────────── */
/* Header-Button mit Tool-Name + Chevron, sitzt links wo sonst der Title war.
 * Tap öffnet Bottom-Sheet zum App-Wechsel. */
.app-switcher-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(120,120,128,0.12);
  border: 0;
  padding: 8px 12px 8px 10px;
  border-radius: var(--r-pill);
  font: inherit;
  color: var(--text-primary);
  cursor: pointer;
  min-height: 36px;
  max-width: 100%;
}
.app-switcher-btn:active { background: rgba(120,120,128,0.22); }
.app-switcher-btn__icon { font-size: 16px; line-height: 1; }
.app-switcher-btn__label { font-weight: var(--weight-semi); font-size: var(--size-callout); }
.app-switcher-btn__chev { font-size: 11px; color: var(--text-secondary); }

.header__app-switcher {
  flex: 0 0 auto;
  margin-right: var(--s-3);
}

/* In Sub-Pages (Header hat einen Back-Button) wird der App-Switcher ausgeblendet
 * — User soll erst zur Modul-Hauptseite zurück, bevor er wechselt.
 * :has() ist in modernen Browsern verfügbar (Safari 15.4+, Chrome 105+, FF 121+). */
.header:has(.header__back) .header__app-switcher,
.header:has(.header__back) #appSwitcherSlot {
  display: none !important;
}

/* Side-Drawer für den App-Switcher (Apple-Sidebar-Pattern, iPadOS/macOS-Style) */
.app-switcher__bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.22s ease;
}
.app-switcher__bg.is-open { opacity: 1; }
.app-switcher__sheet {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 201;
  background: var(--bg-card);
  border-radius: 0 16px 16px 0;       /* nur rechts gerundet — Drawer-Look */
  padding: calc(env(safe-area-inset-top) + var(--s-3))
           var(--s-3)
           calc(env(safe-area-inset-bottom) + var(--s-3))
           calc(env(safe-area-inset-left) + var(--s-3));
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(.32,.72,0,1);
  box-shadow: 2px 0 12px rgba(0,0,0,0.08);
  width: 88vw;
  max-width: 320px;
  overflow-y: auto;
}
.app-switcher__sheet.is-open { transform: translateX(0); }
/* Vertikaler Handle (statt horizontalem Drag-Bar) — kleiner Hinweis, dass man
 * den Drawer auch wegwischen kann. */
.app-switcher__handle {
  display: none;
}
.app-switcher__title {
  font-size: var(--size-footnote);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 var(--s-2) var(--s-2);
}
.app-switcher__row {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3);
  border-radius: var(--r-card);
  text-decoration: none;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.app-switcher__row:active { background: rgba(0,0,0,0.06); }
.app-switcher__row.is-active { background: rgba(0,122,255,0.10); }
.app-switcher__icon {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-grouped);
  border-radius: 10px;
  font-size: 22px;
  flex: 0 0 auto;
}
.app-switcher__main { flex: 1 1 auto; min-width: 0; }
.app-switcher__label {
  display: block;
  font-weight: var(--weight-semi);
  font-size: var(--size-headline);
  line-height: 1.2;
}
.app-switcher__sub {
  display: block;
  font-size: var(--size-footnote);
  color: var(--text-secondary);
  margin-top: 2px;
}
.app-switcher__check {
  color: var(--accent);
  font-weight: 700;
  flex: 0 0 auto;
}

/* ─── App-Desktop-Nav ────────────────────────────────────── */
/* Sichtbar nur auf Desktop. Sitzt direkt unter dem Header.
 * Auf Mobile bleibt die Bottom-Tabbar das primäre Navigations-Element. */
.app-desktop-nav { display: none; }

@media (min-width: 768px) {
  .app-desktop-nav {
    display: flex;
    gap: 6px;
    padding: 8px var(--s-4);
    background: var(--bg-toolbar);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
            backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid var(--separator);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: sticky;
    top: var(--header-h);   /* klebt unter dem Header (56px), statt mit zu scrollen */
    z-index: 4;
  }
  .app-desktop-nav__item {
    padding: 8px 14px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-primary);
    font-size: var(--size-callout);
    font-weight: var(--weight-semi);
    white-space: nowrap;
  }
  .app-desktop-nav__item:hover { background: rgba(120,120,128,0.10); }
  .app-desktop-nav__item.is-active {
    background: rgba(0,122,255,0.12);
    color: var(--accent);
  }

  /* Auf Desktop: Bottom-Tabbar weg, Kebab weg — alles ist oben sichtbar.
   * Action-Buttons (+, ⚙, ↻, 📝, ×, ‹) bleiben — die sind nicht im Kebab. */
  .tabbar { display: none !important; }
  #kebabBtn { display: none !important; }
  /* Damit Pages ohne Tabbar unten kein Padding für Tabbar mehr brauchen */
  .main { padding-bottom: var(--s-4) !important; }
}

/* Mobile: die alten desktop-tabs sind eh hidden via existing rule, hier
 * sicherheitshalber noch die neue Variante. */
@media (max-width: 767px) {
  .app-desktop-nav { display: none !important; }
}

/* ─── Reply-Composer Sheet (siehe modules/mail/static/reply-composer.js) ──
 *
 * Bottom-Sheet mit eigenem Top-Bar (Abbrechen / Titel / Senden), darunter
 * Empfänger-Chips, Subject, Editor und Anhang-Section. Outer-Scroll wird
 * via .rc-bg gelockt (eigener Backdrop, kein Body-Lock — Composer kann
 * über Mail-Detail-Overlay aufgehen ohne dessen Scroll-State zu killen).
 */
.rc-bg {
  position: fixed; inset: 0;
  z-index: 9500;
  background: rgba(0,0,0,0.25);
  opacity: 0;
  transition: opacity 0.24s ease;
}
.rc-bg.is-open { opacity: 1; }
.rc-sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 9501;
  background: var(--bg-page, #fff);
  border-radius: 14px 14px 0 0;
  max-height: 92vh;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(.32,.72,0,1);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.rc-sheet.is-open { transform: translateY(0); }
@media (min-width: 900px) {
  .rc-sheet {
    left: 50%; bottom: auto; top: 5vh;
    transform: translateX(-50%) translateY(-20px);
    width: min(720px, 92vw);
    max-height: 90vh;
    border-radius: 14px;
    opacity: 0;
    box-shadow: 0 24px 60px rgba(0,0,0,0.25);
  }
  .rc-sheet.is-open { transform: translateX(-50%) translateY(0); opacity: 1; }
}
.rc-sheet__bar {
  display: flex; align-items: center;
  height: 48px; padding: 0 var(--s-3);
  border-bottom: 0.5px solid var(--separator);
  background: var(--bg-card);
  flex: 0 0 auto;
}
.rc-sheet__cancel, .rc-sheet__send {
  background: transparent; border: 0;
  font-size: var(--size-callout);
  padding: 8px 12px; cursor: pointer;
  border-radius: var(--r-button);
  min-height: 36px;
}
.rc-sheet__cancel { color: var(--text-secondary); }
.rc-sheet__cancel:hover { background: rgba(0,0,0,0.04); }
.rc-sheet__send {
  color: var(--accent); font-weight: var(--weight-semi);
}
.rc-sheet__send:hover { background: rgba(0,122,255,0.10); }
.rc-sheet__title {
  flex: 1; text-align: center;
  font-weight: var(--weight-semi);
  font-size: var(--size-callout);
}
.rc-sheet__body {
  flex: 1 1 auto;
  overflow: auto;
  padding: var(--s-3) var(--s-3) var(--s-5);
}
.rc-row {
  display: flex; align-items: flex-start;
  gap: var(--s-2);
  padding: 6px 0;
  border-bottom: 0.5px solid var(--separator);
}
.rc-row__lbl {
  flex: 0 0 60px;
  font-size: var(--size-footnote);
  color: var(--text-tertiary);
  padding-top: 8px;
}
.rc-row__val { padding-top: 8px; color: var(--text-primary); }
.rc-row__chips { flex: 1; }
.rc-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.rc-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 4px 3px 10px;
  border-radius: var(--r-pill);
  background: rgba(0,122,255,0.10);
  color: var(--accent);
  font-size: var(--size-footnote);
  max-width: 100%;
}
.rc-chip--invalid { background: rgba(255,59,48,0.14); color: #b1221c; }
.rc-chip > span:first-child {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 240px;
}
.rc-chip__x {
  background: transparent; border: 0;
  font-size: 16px; line-height: 1;
  padding: 0 6px; cursor: pointer;
  color: inherit; opacity: 0.7;
}
.rc-chip__x:hover { opacity: 1; }
#rcInp_to, #rcInp_cc, #rcInp_bcc {
  width: 100%; border: 0; background: transparent;
  font: inherit; padding: 6px 0;
  outline: none;
}
.rc-row__toggle {
  display: flex; gap: 12px; margin-top: 4px;
}
.rc-link {
  background: transparent; border: 0;
  color: var(--accent); font-size: var(--size-footnote);
  cursor: pointer; padding: 0;
}
.rc-link:hover { text-decoration: underline; }
.rc-subj {
  width: 100%; border: 0; background: transparent;
  font: inherit; padding: 8px 0;
  outline: none;
  font-size: var(--size-callout);
}
.rc-row--check {
  border: 0; padding: 8px 0; gap: 8px;
  font-size: var(--size-footnote); color: var(--text-secondary);
  cursor: pointer;
}
.rc-row--check input { margin: 0; }
.rc-fmt {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; margin-top: 8px;
}
.rc-fmt__btn {
  background: rgba(120,120,128,0.10); border: 0;
  padding: 5px 12px; border-radius: var(--r-button);
  cursor: pointer; color: var(--text-secondary);
  font-size: var(--size-footnote);
}
.rc-fmt__btn.is-active { background: var(--accent); color: #fff; }
.rc-fmt__spacer { flex: 1; }
.rc-ai-btn {
  background: linear-gradient(135deg, rgba(0,122,255,0.16), rgba(88,86,214,0.14));
  color: var(--accent);
}
.rc-toolbar {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 6px; background: rgba(120,120,128,0.06);
  border-radius: 8px;
}
.rc-toolbar button {
  background: transparent; border: 0; cursor: pointer;
  padding: 4px 10px; border-radius: 4px;
  font-size: 14px; color: var(--text-primary);
  min-width: 32px; min-height: 28px;
}
.rc-toolbar button:hover { background: rgba(0,0,0,0.06); }
.rc-toolbar__sep {
  width: 1px; background: var(--separator); margin: 4px 4px;
}
.rc-editor {
  min-height: 180px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: 8px;
  font: inherit; font-size: var(--size-callout);
  line-height: 1.5;
  outline: none;
  margin-top: 8px;
}
.rc-editor--plain {
  resize: vertical;
  width: 100%;
  border: 0;
  white-space: pre-wrap;
}
.rc-editor--html:empty::before {
  content: attr(data-placeholder);
  color: var(--text-tertiary);
}
.rc-editor blockquote {
  margin: 8px 0 8px 8px; padding: 4px 12px;
  border-left: 2px solid var(--separator); color: var(--text-secondary);
}
.rc-att-section {
  padding: 12px 0; border-top: 0.5px solid var(--separator);
  margin-top: 12px;
}
.rc-att-section .rc-row__lbl {
  display: block; padding: 0 0 6px;
}
.rc-att-row {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 0; font-size: var(--size-footnote);
  cursor: pointer;
}
.rc-att-own {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 8px 0;
}
.rc-att-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 4px 3px 10px;
  background: rgba(52,199,89,0.14);
  color: #1d7a34;
  border-radius: var(--r-pill);
  font-size: var(--size-footnote);
}
.rc-att-chip__x {
  background: transparent; border: 0;
  font-size: 16px; line-height: 1;
  padding: 0 6px; cursor: pointer; color: inherit; opacity: 0.7;
}
.rc-att-chip__x:hover { opacity: 1; }
.rc-att-add {
  display: inline-flex; align-items: center;
  padding: 8px 14px; border: 0.5px dashed var(--separator);
  border-radius: 8px; cursor: pointer;
  color: var(--accent); font-size: var(--size-footnote);
  margin-top: 4px;
}
.rc-att-add:hover { background: rgba(0,122,255,0.06); }
.rc-save-status {
  margin-top: 12px;
  font-size: 11px; color: var(--text-tertiary);
  text-align: right;
}

/* KI-Vorschlag-Sub-Sheet */
.rc-suggest {
  position: fixed; inset: 0;
  z-index: 9600;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.22s ease;
}
.rc-suggest.is-open { opacity: 1; }
.rc-suggest__head, .rc-suggest__body {
  width: min(420px, 92vw);
  background: var(--bg-card);
}
.rc-suggest__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-radius: 12px 12px 0 0;
  border-bottom: 0.5px solid var(--separator);
}
.rc-suggest__body {
  padding: 16px;
  border-radius: 0 0 12px 12px;
}
.rc-suggest__close {
  background: transparent; border: 0;
  font-size: 18px; cursor: pointer; color: var(--text-secondary);
  padding: 4px 8px; border-radius: 4px;
}
.rc-suggest__lbl {
  display: block; font-size: var(--size-footnote);
  font-weight: var(--weight-semi); color: var(--text-secondary);
  margin-bottom: 6px;
}
.rc-radio-grid {
  display: grid; gap: 4px;
}
.rc-radio {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 0; cursor: pointer;
  font-size: var(--size-callout);
}
.rc-suggest #rcBullets {
  width: 100%; border: 0.5px solid var(--separator);
  border-radius: 6px;
  padding: 8px; font: inherit;
  font-size: var(--size-footnote);
  resize: vertical;
}
.rc-suggest__hint {
  font-size: var(--size-caption); color: var(--text-tertiary);
  margin-top: 8px; line-height: 1.4;
}
.rc-suggest__msg {
  min-height: 18px; padding: 8px 0;
  font-size: var(--size-footnote); color: var(--text-secondary);
}
.rc-suggest__actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 8px;
}

/* ─── Mail-Detail-Overlay (siehe mail.js openMailOverlay) ────────────
 *
 * Vollbild-Overlay mit eigener Top-Bar + Iframe. Slide-Up auf Mobil,
 * Fade auf Desktop. Body bekommt `has-mail-overlay` damit Outer-Scroll
 * gelockt ist (sonst kann man hinter dem Overlay scrollen, was iOS-
 * untypisch ist und auf Desktop genauso falsch wirkt).
 */
body.has-mail-overlay { overflow: hidden; }
.mail-overlay {
  position: fixed; inset: 0;
  z-index: 9000;
  background: var(--bg-page, var(--bg-primary, #f2f2f7));
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(.32,.72,0,1);
  /* Sicherheitsnetz: viewport-fit cover hat oben/unten safe-area, das
   * iframe füllt rein und das Top-Bar fängt den oberen Bereich ab. */
}
.mail-overlay.is-open { transform: translateY(0); }
.mail-overlay__bar {
  display: flex; align-items: center;
  height: 44px;
  padding: env(safe-area-inset-top) var(--s-3) 0;
  background: var(--bg-card);
  border-bottom: 0.5px solid var(--separator);
  flex: 0 0 auto;
}
.mail-overlay__back {
  background: transparent; border: 0;
  font-size: var(--size-body);
  color: var(--accent);
  padding: 8px 12px 8px 4px;
  cursor: pointer;
  border-radius: var(--r-button);
  min-height: 36px;
}
.mail-overlay__back:hover { background: rgba(0,0,0,0.04); }
.mail-overlay__title {
  flex: 1 1 auto;
  text-align: center;
  font-weight: var(--weight-semi);
  font-size: var(--size-callout);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  /* Text-Klick darf nicht den Back-Button auslösen — pointer-events off */
  pointer-events: none;
  padding: 0 8px;
}
.mail-overlay__open {
  text-decoration: none;
  color: var(--text-tertiary);
  font-size: 18px;
  padding: 8px 10px;
  border-radius: var(--r-button);
  min-height: 36px;
  display: inline-flex; align-items: center;
}
.mail-overlay__open:hover { background: rgba(0,0,0,0.04); color: var(--accent); }
.mail-overlay__frame {
  flex: 1 1 auto;
  border: 0;
  width: 100%;
  background: var(--bg-page, #f2f2f7);
}

/* Embed-Mode der mail-mail.html: eigene App-Header + Tabbar weg, sonst
 * sieht man im Overlay zwei Header übereinander. Padding rausnehmen. */
body.is-embed .header,
body.is-embed > .app > .header,
body.is-embed .tabbar,
body.is-embed .app-desktop-nav { display: none !important; }
body.is-embed .main { padding-bottom: var(--s-4) !important; padding-top: 0 !important; }
body.is-embed .app { padding-top: 0 !important; }

/* Desktop: Overlay nicht 100% — eher modal-Sheet mit max-width. */
@media (min-width: 900px) {
  .mail-overlay {
    inset: 5vh 5vw;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    transform: translateY(20px);
    opacity: 0;
    transition: transform 0.22s cubic-bezier(.32,.72,0,1), opacity 0.22s ease;
  }
  .mail-overlay.is-open { transform: translateY(0); opacity: 1; }
  body.has-mail-overlay::before {
    content: ""; position: fixed; inset: 0; z-index: 8999;
    background: rgba(0,0,0,0.4);
    animation: mailOvFadeIn 0.22s ease forwards;
  }
}
@keyframes mailOvFadeIn { from { opacity: 0 } to { opacity: 1 } }
