/* =========================================================================
   ImapLAB - Oberfläche im Gmail-Stil

   Gestaltungsprinzipien, an denen sich das orientiert:
     - durchgehende Kopfleiste mit grosser, gefüllter Suche
     - links Pillen-Navigation, rechts abgerundet bis an die Fensterkante
     - sehr dichte, einzeilige Nachrichtenliste (40px)
     - gelesen = leicht eingefärbt, ungelesen = weiss und fett
     - Aktionen erscheinen erst beim Überfahren der Zeile

   Mobile-first: Basis ist das Handy, ab 768px die feste Navigation,
   ab 1100px die dreispaltige Leseansicht.
   ========================================================================= */

:root {
  --bg:          #f6f8fc;
  --surface:     #ffffff;
  --surface-2:   #f1f3f4;   /* Suchfeld, Hover-Flächen */
  --surface-3:   #e8eaed;   /* gedrückt / stärkerer Hover */
  --row-read:    #f2f6fc;   /* gelesene Zeile */
  --border:      #dadce0;
  --border-soft: #e8eaed;
  --text:        #202124;
  --text-2:      #5f6368;
  --accent:      #0b57d0;
  --accent-ink:  #ffffff;
  --accent-soft: #d3e3fd;   /* aktive Pille, ausgewählte Zeile */
  --danger:      #d93025;
  --ok:          #188038;
  --warn:        #b06000;
  --star:        #f4b400;
  --shadow-1:    0 1px 2px rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15);
  --shadow-2:    0 1px 3px 0 rgba(60,64,67,.3), 0 4px 8px 3px rgba(60,64,67,.15);
  --appbar-h:    64px;
  --nav-w:       256px;
  --tap:         40px;
  --safe-b:      env(safe-area-inset-bottom, 0px);
  --safe-t:      env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #131314;
    --surface:     #1e1f20;
    --surface-2:   #2d2e30;
    --surface-3:   #37393b;
    --row-read:    #1b1c1d;
    --border:      #3c4043;
    --border-soft: #2d2e30;
    --text:        #e3e3e3;
    --text-2:      #9aa0a6;
    --accent:      #a8c7fa;
    --accent-ink:  #062e6f;
    --accent-soft: #0842a0;
    --danger:      #f28b82;
    --ok:          #81c995;
    --warn:        #fdd663;
    --shadow-1:    0 1px 2px rgba(0,0,0,.6), 0 1px 3px 1px rgba(0,0,0,.4);
    --shadow-2:    0 1px 3px rgba(0,0,0,.6), 0 4px 8px 3px rgba(0,0,0,.45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Google Sans", Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--text-2); }
.err { color: var(--danger); }
code { font: 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- Knöpfe */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer;
  text-decoration: none; white-space: nowrap;
  transition: background .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; box-shadow: var(--shadow-1); }
.btn--primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn--primary:hover { background: var(--accent); filter: brightness(1.1); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn--ghost:hover { background: var(--surface-2); box-shadow: none; }
.btn--danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn--danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); box-shadow: none; }
.btn--block { width: 100%; }
.btn--sm { min-height: 32px; padding: 0 14px; font-size: 13px; }
.btn.is-disabled, .btn:disabled { opacity: .4; pointer-events: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap); flex: none;
  border: 0; border-radius: 50%; background: transparent;
  color: var(--text-2); cursor: pointer; font-size: 18px; line-height: 1;
  text-decoration: none; transition: background .12s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.icon-btn:disabled, .icon-btn.is-disabled { opacity: .35; pointer-events: none; }
.icon-btn--sm { width: 32px; height: 32px; }
.icon-btn--sm .ic { width: 18px; height: 18px; }
.icon-btn--danger:hover { color: var(--danger); }
.icon-btn.is-on { color: var(--star); }

.linkbtn { border: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; padding: 6px 0; text-align: left; }

/* ---------------------------------------------------------------- Felder */
.field { display: block; margin-bottom: 16px; }
.field__label { display: block; margin-bottom: 6px; font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field__wrap { position: relative; display: block; }
.field__input {
  width: 100%; min-height: 44px; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 16px;   /* 16px verhindert das Zoomen auf iOS */
}
.field__input:focus { outline: 2px solid var(--accent); outline-offset: -2px; border-color: transparent; }
.field__input--sm { min-height: 32px; padding: 4px 10px; font-size: 13px; border-radius: 6px; }
.field__toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border: 0; background: none; cursor: pointer; font-size: 17px; opacity: .6; }

.gselect {
  min-height: 32px; max-width: 170px; padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px;
}

.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; }
.check input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

.gcheck { display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap); flex: none; cursor: pointer; border-radius: 50%; }
.gcheck:hover { background: var(--surface-3); }
.gcheck input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }

/* ---------------------------------------------------------------- Meldung */
.flash {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + var(--safe-b)); z-index: 300;
  display: flex; align-items: center; gap: 12px;
  max-width: min(560px, calc(100vw - 24px));
  padding: 14px 16px; border-radius: 6px;
  background: #323232; color: #fff;
  box-shadow: var(--shadow-2); font-size: 13.5px;
  animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } }
.flash__icon { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none; }
.flash--ok    .flash__icon { background: var(--ok); }
.flash--warn  .flash__icon { background: var(--warn); color: #202124; }
.flash--error .flash__icon { background: var(--danger); }
.flash__text { flex: 1; }
.flash__close { border: 0; background: none; font-size: 20px; cursor: pointer; color: #bdc1c6; padding: 0 4px; }

/* ================================================================ Kopfleiste */
.appbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 4px;
  height: calc(var(--appbar-h) + var(--safe-t));
  padding: var(--safe-t) 8px 0;
  background: var(--bg);
}
.appbar__menu { flex: none; }

.brand { display: flex; align-items: center; gap: 8px; padding: 0 6px; color: var(--text); flex: none; }
.brand:hover { text-decoration: none; }
.brand__mark { width: 28px; height: 28px; color: var(--accent); flex: none; }
.brand__name { font-size: 20px; font-weight: 400; letter-spacing: -.01em; color: var(--text-2); }

/* Die grosse Suche: gefüllt statt umrandet, beim Fokus weiss mit Schatten */
.gsearch {
  position: relative; display: flex; align-items: center;
  /* min-width:0 ist Pflicht: ohne das kann ein Flex-Element nicht unter seine
     Inhaltsbreite schrumpfen, und die rechte Knopfgruppe wird auf schmalen
     Bildschirmen aus dem Sichtbereich gedrückt. */
  flex: 1 1 auto; min-width: 0; max-width: 720px; margin: 0 8px;
  height: 46px; padding: 0 4px 0 2px;
  background: var(--surface-2); border-radius: 8px;
  transition: background .15s, box-shadow .15s, border-radius .15s;
}
.gsearch:focus-within { background: var(--surface); box-shadow: var(--shadow-1); }
.gsearch__btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; flex: none; border: 0; background: none; color: var(--text-2); cursor: pointer; border-radius: 50%; }
.gsearch__btn:hover { background: var(--surface-3); }
.gsearch__input {
  flex: 1; min-width: 0; height: 100%;
  border: 0; background: none; color: var(--text);
  font: inherit; font-size: 16px;
}
.gsearch__input:focus { outline: none; }
.gsearch__input::-webkit-search-cancel-button { display: none; }
.gsearch__clear { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; flex: none; border-radius: 50%; color: var(--text-2); }
.gsearch__clear:hover { background: var(--surface-3); }

.gsearch__more { position: relative; flex: none; }
.gsearch__more > summary { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; color: var(--text-2); cursor: pointer; list-style: none; }
.gsearch__more > summary::-webkit-details-marker { display: none; }
.gsearch__more > summary:hover { background: var(--surface-3); }
.gsearch__panel {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 120;
  width: min(340px, calc(100vw - 32px)); padding: 16px;
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: 8px; box-shadow: var(--shadow-2); font-size: 13px;
}
.gsearch__panel p { margin: 0 0 8px; }
.gsearch__hints { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 5px; }

.appbar__right { display: flex; align-items: center; gap: 2px; margin-left: auto; flex: none; }

.acctmenu { position: relative; }
.acctmenu > summary { display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap); border-radius: 50%; cursor: pointer; list-style: none; }
.acctmenu > summary::-webkit-details-marker { display: none; }
.acctmenu__panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 120;
  width: 280px; padding: 8px;
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: 12px; box-shadow: var(--shadow-2);
}
.acctmenu__head { display: flex; align-items: center; gap: 12px; padding: 10px 10px 14px; border-bottom: 1px solid var(--border-soft); margin-bottom: 6px; }
.acctmenu__head strong { display: block; font-size: 14px; }
.acctmenu__head small { display: block; font-size: 12.5px; }
.acctmenu__item { display: block; padding: 10px 12px; border-radius: 8px; color: var(--text); font-size: 13.5px; }
.acctmenu__item:hover { background: var(--surface-2); text-decoration: none; }
.acctmenu__item--danger { color: var(--danger); }

.avatar {
  width: 36px; height: 36px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: hsl(var(--h, 220) 55% 45%); color: #fff;
  font-size: 13px; font-weight: 600; letter-spacing: .02em;
}
.avatar--sm { width: 30px; height: 30px; font-size: 11.5px; }

/* ================================================================== Gerüst */
.shell { display: flex; min-height: calc(100dvh - var(--appbar-h)); }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 130;
  width: var(--nav-w); max-width: 84vw;
  display: flex; flex-direction: column;
  padding: 8px 0 calc(8px + var(--safe-b));
  background: var(--surface); border-right: 1px solid var(--border-soft);
  transform: translateX(-102%); transition: transform .2s ease;
  overflow-y: auto; overscroll-behavior: contain;
}
.sidebar.is-open { transform: none; box-shadow: var(--shadow-2); }
.scrim { position: fixed; inset: 0; z-index: 125; background: rgba(32, 33, 36, .5); border: 0; }

/* Der grosse Schreiben-Knopf */
.composebtn {
  display: inline-flex; align-items: center; gap: 12px;
  height: 56px; margin: 8px 12px 16px; padding: 0 24px 0 20px;
  border-radius: 16px; background: var(--accent-soft); color: var(--text);
  font-size: 14px; font-weight: 500; align-self: flex-start;
  transition: box-shadow .15s, background .15s;
}
.composebtn:hover { box-shadow: var(--shadow-1); text-decoration: none; filter: brightness(1.02); }
.composebtn__ic { width: 22px; height: 22px; }

.folders { display: flex; flex-direction: column; gap: 0; flex: 1; padding-right: 12px; }
.folder {
  display: flex; align-items: center; gap: 18px;
  height: 32px; padding: 0 12px 0 calc(24px + var(--depth, 0) * 14px);
  border-radius: 0 100px 100px 0; color: var(--text);
  font-size: 14px; letter-spacing: .01em;
}
.folder:hover { background: var(--surface-2); text-decoration: none; }
.folder.is-active { background: var(--accent-soft); font-weight: 700; }
.folder.is-active .ic { color: var(--text); }
.folder .ic { width: 19px; height: 19px; color: var(--text-2); }
.folder__name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder__count { font-size: 12px; color: var(--text-2); font-weight: 400; }
.folder__count--unseen { color: var(--text); font-weight: 700; }

/* Eingeklappter Teil der Ordnerliste */
.foldermore { display: block; }
.folder--more { list-style: none; cursor: pointer; }
.folder--more::-webkit-details-marker { display: none; }
.foldermore__chev { transition: transform .15s; }
.foldermore[open] .foldermore__chev { transform: rotate(180deg); }
.foldermore__list { display: flex; flex-direction: column; }

.sidebar__foot { padding: 12px 12px 0; margin-top: 8px; border-top: 1px solid var(--border-soft); }
.quota { padding: 4px 8px 12px; }
.quota__bar { height: 4px; border-radius: 99px; background: var(--border-soft); overflow: hidden; margin-bottom: 6px; }
.quota__bar span { display: block; height: 100%; background: var(--accent); }
.quota small { font-size: 11.5px; color: var(--text-2); }
.newfolder { display: flex; gap: 6px; }
.newfolder .field__input { flex: 1; }

/* ---------------------------------------------------------------- Inhalt */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding-bottom: var(--safe-b); }
.workspace { display: flex; flex: 1; min-height: 0; }
.pane--list { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pane--read { display: none; }

/* Die weisse, abgerundete Fläche - das Kennzeichen der neuen Gmail-Oberfläche */
.listform {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  overflow: hidden;
}

/* ------------------------------------------------------------ Werkzeuge */
.gtoolbar {
  display: flex; align-items: center; gap: 2px;
  height: 48px; padding: 0 8px 0 4px; flex: none;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
}
.gtoolbar[data-empty="1"] .gtoolbar__actions { display: none; }
.gtoolbar__actions { display: flex; align-items: center; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.gtoolbar__actions::-webkit-scrollbar { display: none; }
.gtoolbar__divider { width: 1px; height: 22px; background: var(--border); margin: 0 6px; flex: none; }
.gtoolbar__sel { font-size: 13px; color: var(--text-2); padding: 0 4px; white-space: nowrap; }
.gtoolbar__pager { display: flex; align-items: center; gap: 0; margin-left: auto; flex: none; }
.gtoolbar__range { font-size: 12.5px; color: var(--text-2); white-space: nowrap; margin-right: 6px; }

.searchbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; font-size: 13px; color: var(--text-2);
  background: var(--surface-2); border-bottom: 1px solid var(--border-soft);
}

/* --------------------------------------------------------------- Liste */
.glist { list-style: none; margin: 0; padding: 0; }

.grow {
  position: relative;
  display: flex; align-items: center;
  height: 40px; padding-right: 8px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
}
.grow.is-read   { background: var(--row-read); }
.grow.is-unread { background: var(--surface); }
.grow:hover { box-shadow: inset 1px 0 0 var(--border), inset -1px 0 0 var(--border), var(--shadow-1); z-index: 2; }
.grow.is-current { background: var(--accent-soft); }

.grow__check { margin-left: 2px; }
.gstar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex: none;
  border: 0; background: none; cursor: pointer; border-radius: 50%;
  color: var(--text-2);
}
.gstar:hover { background: var(--surface-3); }
.gstar .ic { width: 18px; height: 18px; }
.gstar.is-on { color: var(--star); }
.gstar.is-on .ic { fill: var(--star); stroke: var(--star); }

.grow__link {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px;
  height: 100%; padding: 0 8px 0 6px; color: inherit;
}
.grow__link:hover { text-decoration: none; }

.grow__from { flex: 0 0 168px; max-width: 168px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }

/* Betreff und Vorschautext teilen sich eine Zeile: der Betreff so lang wie
   nötig, der Vorschautext füllt den Rest und wird am Ende abgeschnitten. */
.grow__msg { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.grow__subject { }
.grow__snippet { color: var(--text-2); font-weight: 400; }
.grow__re { color: var(--text-2); margin-right: 4px; }
.grow__att { flex: none; display: inline-flex; color: var(--text-2); }
.grow__att .ic { width: 16px; height: 16px; }

.grow.is-unread .grow__from,
.grow.is-unread .grow__subject { font-weight: 700; }
.grow.is-read .grow__from { color: var(--text-2); }

.grow__date { flex: none; width: 76px; text-align: right; font-size: 12px; color: var(--text-2); }
.grow.is-unread .grow__date { font-weight: 700; color: var(--text); }

/* Aktionen erscheinen erst beim Überfahren und ersetzen das Datum */
.grow__hover {
  position: absolute; right: 8px; top: 0; height: 100%;
  display: none; align-items: center; gap: 2px;
  background: inherit; padding-left: 12px;
}
.grow:hover .grow__hover { display: flex; }
.grow:hover .grow__date { visibility: hidden; }
@media (hover: none) {
  /* Auf Touchgeräten gibt es kein Überfahren - dort bleibt das Datum stehen */
  .grow__hover { display: none !important; }
  .grow:hover .grow__date { visibility: visible; }
}

.chip { display: inline-block; padding: 0 6px; margin-right: 5px; border-radius: 4px; background: var(--surface-3); font-size: 11px; font-weight: 500; color: var(--text-2); vertical-align: 1px; }
.chip--draft { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }

.empty { padding: 72px 24px; text-align: center; color: var(--text-2); }
.empty__ic { width: 46px; height: 46px; fill: none; stroke: currentColor; stroke-width: 1.4; opacity: .35; margin-bottom: 12px; }

.fab {
  position: fixed; right: 16px; bottom: calc(16px + var(--safe-b)); z-index: 90;
  display: grid; place-items: center;
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--accent-soft); color: var(--text);
  box-shadow: var(--shadow-2);
}
.fab:hover { text-decoration: none; filter: brightness(1.04); }
@media (min-width: 768px) { .fab { display: none; } }

/* ---------------------------------------------------- Zweite Leiste (Views) */
.topbar {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 8px; flex: none;
  background: var(--surface); border-bottom: 1px solid var(--border-soft);
}
.topbar__title { flex: 1; margin: 0; font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__title--msg { font-size: 15px; }
.topbar__send { margin-left: auto; }

/* -------------------------------------------------------- Nachrichtenansicht */
.reader { background: var(--surface); }
.reader--solo { border-radius: 0; }

.msg { padding: 16px 16px calc(28px + var(--safe-b)); max-width: 100%; }
.msg__tools { display: flex; align-items: center; gap: 2px; margin: -4px 0 6px; }
.msg__toolsSpacer { flex: 1; }
.msg__subject { margin: 0 0 18px; font-size: 22px; line-height: 1.3; font-weight: 400; letter-spacing: 0; }

.msg__head { display: flex; gap: 12px; align-items: flex-start; padding-bottom: 14px; }
.msg__ident { flex: 1; min-width: 0; }
.msg__from { font-size: 14px; }
.msg__from strong { font-weight: 700; }
.msg__from .muted { font-size: 12.5px; }
.msg__to { font-size: 12.5px; margin-top: 2px; word-break: break-word; }
.msg__date { font-size: 12.5px; color: var(--text-2); white-space: nowrap; }

.msg__body { width: 100%; min-height: 160px; margin: 8px 0 16px; border: 0; background: var(--surface); display: block; }

.msg__foot { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 8px; }

.atts { margin: 8px 0 4px; }
.atts__head { font-size: 12px; font-weight: 500; color: var(--text-2); margin-bottom: 8px; }
.atts__list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.att a { display: flex; align-items: center; gap: 8px; width: 240px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 13px; }
.att a:hover { background: var(--surface-2); text-decoration: none; }
.att__ic { width: 16px; height: 16px; color: var(--text-2); }
.att__name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att__size { font-size: 11px; color: var(--text-2); white-space: nowrap; }

.notice { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 12px 0; padding: 10px 14px; border-radius: 8px; background: var(--surface-2); font-size: 13px; color: var(--text-2); }
.notice--ai { border-left: 3px solid var(--accent); }

/* ---------------------------------------------------------------- KI-Panel */
.ai { margin: 18px 0 8px; }
.ai__box { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: hidden; }
.ai__summary { display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; font-weight: 500; font-size: 14px; list-style: none; }
.ai__summary::-webkit-details-marker { display: none; }
.ai__summary::after { content: "▾"; margin-left: auto; color: var(--text-2); transition: transform .15s; }
.ai__box[open] .ai__summary::after { transform: rotate(180deg); }
.ai__summary .ic { color: var(--accent); }
.ai__body { padding: 0 16px 16px; border-top: 1px solid var(--border-soft); }
.ai__privacy { margin: 14px 0; padding: 10px 12px; border-left: 3px solid var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); border-radius: 0 8px 8px 0; font-size: 12.5px; line-height: 1.5; color: var(--text-2); }
.ai__controls { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.ai__ctl { display: flex; flex-direction: column; gap: 4px; flex: 1 1 140px; font-size: 12px; color: var(--text-2); }
.ai__ctl .field__input { min-height: 36px; }
.ai__hint { margin-bottom: 10px; font-size: 14px; min-height: 40px; }
.ai__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ai__status { font-size: 12.5px; color: var(--text-2); }
.ai__status.is-error { color: var(--danger); }
.ai__status.is-busy::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -1px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ai__result { margin-top: 14px; }
.ai__meta { font-size: 11.5px; color: var(--text-2); margin-bottom: 6px; }
.ai__text { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-size: 14.5px; line-height: 1.55; resize: vertical; }
.ai__text:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.ai__resultActions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ai__disclaimer { margin: 10px 0 0; font-size: 12px; color: var(--text-2); }
.compose__ai { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }

/* ---------------------------------------------------------------- Verfassen */
.compose { padding: 12px 16px calc(28px + var(--safe-b)); max-width: 900px; }
.compose__from { display: flex; gap: 8px; align-items: baseline; padding: 8px 2px; font-size: 13.5px; border-bottom: 1px solid var(--border-soft); }
.compose__from strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cfield { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border-soft); }
.cfield__label { width: 58px; flex: none; font-size: 13px; color: var(--text-2); }
.cfield__input { flex: 1; min-width: 0; min-height: 42px; border: 0; background: none; color: var(--text); font: inherit; font-size: 16px; padding: 8px 0; }
.cfield__input:focus { outline: none; }
.compose__body {
  width: 100%; margin-top: 14px; padding: 12px;
  border: 1px solid var(--border-soft); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 15px; line-height: 1.6; resize: vertical; min-height: 240px;
}
.compose__body:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.compose__attach { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; font-size: 13px; }
.compose__opts { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 8px; font-size: 13.5px; }
.compose__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.fwdatts { margin-top: 14px; border: 1px solid var(--border-soft); border-radius: 8px; padding: 6px 14px 10px; }
.fwdatts legend { font-size: 12px; color: var(--text-2); padding: 0 6px; }

/* ------------------------------------------------------- Einstellungen etc. */
.diag { padding: 16px; max-width: 900px; display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border-soft); border-radius: 12px; padding: 20px; }
.card h2 { margin: 0 0 14px; font-size: 16px; font-weight: 500; display: flex; align-items: center; gap: 10px; }
.pill { padding: 2px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 500; background: var(--surface-2); color: var(--text-2); }
.pill--ok  { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill--bad { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 6px 16px; margin: 0; font-size: 13.5px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; word-break: break-word; }
.taglist { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.taglist li { padding: 3px 10px; border: 1px solid var(--border-soft); border-radius: 999px; background: var(--surface-2); font-size: 12px; }
.transcript { margin-top: 14px; }
.transcript summary { cursor: pointer; font-size: 13px; color: var(--text-2); }
.transcript pre { margin: 10px 0 0; padding: 12px; background: var(--surface-2); border-radius: 8px; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }

/* ---------------------------------------------------------------- Anmeldung */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login__card { width: 100%; max-width: 448px; background: var(--surface); border: 1px solid var(--border-soft); border-radius: 28px; padding: 40px 40px calc(32px + var(--safe-b)); box-shadow: var(--shadow-1); }
.login__brand { text-align: center; margin-bottom: 28px; }
.login__logo { width: 48px; height: 48px; color: var(--accent); }
.login__brand h1 { margin: 12px 0 4px; font-size: 24px; font-weight: 400; }
.login__brand p { margin: 0; font-size: 14px; }
.login__note { margin: 18px 0 0; font-size: 12.5px; color: var(--text-2); line-height: 1.5; }
.advanced { margin: 4px 0 18px; border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.advanced > summary { cursor: pointer; font-size: 13.5px; color: var(--text-2); }
.advanced__grid { display: grid; gap: 0 12px; margin-top: 16px; }
@media (min-width: 480px) { .advanced__grid { grid-template-columns: 1fr 90px 140px; } }
@media (max-width: 520px) { .login__card { padding: 28px 22px calc(24px + var(--safe-b)); border-radius: 20px; } }

/* ================================================================ Ab Tablet */
@media (min-width: 768px) {
  .sidebar {
    position: sticky; top: var(--appbar-h);
    height: calc(100dvh - var(--appbar-h));
    transform: none; box-shadow: none; background: var(--bg); border-right: 0;
  }
  .scrim { display: none !important; }
  .appbar__menu { display: none; }
  .listform { margin-right: 0; }
}

/* ------------------------------------------- Geteilte Ansicht (zuschaltbar)
   Standardmässig füllt die Liste die ganze Breite. Erst wenn der Nutzer die
   geteilte Ansicht einschaltet, kommt der Lesebereich daneben - und auch nur
   dann, wenn genug Platz dafür ist. */
@media (min-width: 1100px) {
  .main { overflow: hidden; }
  .workspace { height: calc(100dvh - var(--appbar-h)); }
  .pane--list { overflow-y: auto; overscroll-behavior: contain; }
  .gtoolbar { position: sticky; top: 0; z-index: 40; }

  .workspace.is-split .pane--list {
    flex: 0 0 clamp(340px, 27vw, 420px);
  }
  .workspace.is-split .pane--read {
    display: block; flex: 1; min-width: 0; overflow-y: auto;
    background: var(--surface); border-radius: 16px 16px 0 0;
    margin-left: 12px;
  }

  /* In der schmalen Liste passen Absender und Betreff nicht mehr nebeneinander */
  .workspace.is-split .grow { height: auto; align-items: flex-start; padding: 6px 8px 6px 0; }
  .workspace.is-split .grow__link { flex-direction: column; align-items: flex-start; gap: 1px; padding-top: 2px; }
  .workspace.is-split .grow__from { flex: none; max-width: 100%; width: 100%; font-size: 13.5px; }
  .workspace.is-split .grow__msg { width: 100%; }
  .workspace.is-split .grow__snippet { display: none; }
  /* In der Spaltenrichtung würden Datum und Büroklammer eigene Zeilen
     belegen und die Zeile unnötig hoch machen - deshalb ausgeklinkt. */
  .workspace.is-split .grow__att { display: none; }
  .workspace.is-split .grow__from { padding-right: 58px; }
  .workspace.is-split .grow__date { position: absolute; right: 10px; top: 7px; width: auto; }
  .workspace.is-split .gcheck,
  .workspace.is-split .gstar { margin-top: 2px; }

  /* Auf 1280er-Schirmen zählt jeder Pixel: knapper Innenabstand, damit die
     Lesespalte die ~640px erreicht, die eine 78-Zeichen-Zeile braucht. */
  .reader { padding: 20px 16px 44px; }
  /* Feste Breite statt ch: die Einheit rechnet mit der Grundschrift der Seite
     (14px), der Mailtext in der iframe läuft aber mit 16px. Mit ch wäre die
     Spalte zu schmal und die auf ~78 Zeichen umbrochenen Klartext-Mails
     würden ein zweites Mal umbrochen. 700px fassen ~78 Zeichen bei 16px. */
  .reader .msg { max-width: 700px; padding: 0; }
  .reader__empty { display: grid; place-content: center; justify-items: center; height: 70dvh; color: var(--text-2); text-align: center; }
  .reader__emptyIc { width: 52px; height: 52px; fill: none; stroke: currentColor; stroke-width: 1.4; opacity: .3; margin-bottom: 12px; }
  .reader__hint { font-size: 12.5px; margin-top: 4px; }
  .reader__hint kbd { padding: 1px 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-2); font: inherit; font-size: 11.5px; }
}

/* Unter 1100px ist für zwei Spalten kein Platz - dort wird immer ganzseitig
   gelesen, auch wenn die geteilte Ansicht eingeschaltet ist. */
@media (max-width: 1099px) {
  .pane--read { display: none !important; }
}

@media (min-width: 1400px) {
  .reader { padding: 24px 40px 56px; }
}

/* Volle Breite: die Lesespalte der Einzelansicht bleibt trotzdem begrenzt */
.reader--solo .msg { max-width: 700px; margin: 0 auto; }
.splittoggle.is-on { background: var(--accent-soft); color: var(--text); }

.reader.is-loading { opacity: .4; transition: opacity .12s; }

@media (max-width: 599px) {
  /* Die Aufklapp-Felder sind breiter als der Platz rechts vom Knopf - auf
     schmalen Schirmen hängen sie deshalb am Fenster statt am Auslöser. */
  .gsearch__panel, .acctmenu__panel {
    position: fixed; left: 12px; right: 12px; width: auto;
    top: calc(var(--appbar-h) + var(--safe-t) - 4px);
  }

  .brand__name { display: none; }
  .appbar__hideSm { display: none; }
  .gsearch { margin: 0 4px; height: 44px; }
  .gtoolbar__range { display: none; }
  .listform { border-radius: 12px 12px 0 0; }
  .splittoggle { display: none; }

  /* Auf dem Handy passen Absender, Betreff und Vorschautext nicht in eine
     Zeile. Statt alles auf Bruchstücke zu kürzen: Absender und Datum oben,
     Betreff und Vorschautext darunter - zwei Zeilen, aber lesbar. */
  .grow { height: auto; align-items: flex-start; padding: 8px 8px 8px 0; }
  .grow__link { flex-direction: column; align-items: stretch; gap: 2px; padding: 0 4px 0 6px; }
  .grow__from { flex: none; max-width: none; padding-right: 64px; }
  /* Platz für das Büroklammer-Symbol reservieren, sonst läuft der
     Vorschautext darunter durch. */
  .grow__msg { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 13.5px; padding-right: 24px; }
  .grow__date { position: absolute; right: 10px; top: 8px; width: auto; }
  .grow__att { position: absolute; right: 10px; bottom: 8px; }
  .gcheck, .gstar { margin-top: 1px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* =========================================================================
   Einstellungsseite
   ========================================================================= */
.settabs {
  display: flex; gap: 4px; padding: 10px 16px 0; overflow-x: auto;
  border-bottom: 1px solid var(--border-soft); position: sticky; top: 0;
  background: var(--bg); z-index: 3;
}
.settabs__tab {
  padding: 8px 14px; border-radius: 8px 8px 0 0; font-size: 13.5px;
  color: var(--text-2); text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.settabs__tab:hover { background: var(--surface-2); }
.settabs__tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.sethead {
  margin: 22px 0 -4px; font-size: 13px; font-weight: 500; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-2); scroll-margin-top: 60px;
}
.sethead:first-child { margin-top: 4px; }
.setform { display: grid; gap: 16px; }

.setgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.setgrid--colors { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* Vorschau des Briefkopfs */
.tplpreview {
  border: 1px solid var(--border-soft); border-radius: 10px; overflow: hidden;
  background: #fff; margin-bottom: 14px;
}
.tplpreview__frame { display: block; width: 100%; height: 460px; border: 0; background: #fff; }

/* Hinterlegtes Logo */
.setlogo { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.setlogo__img {
  max-width: 200px; max-height: 90px; background: #fff; padding: 8px;
  border: 1px solid var(--border-soft); border-radius: 8px;
}
.setlogo__meta { font-size: 12.5px; }

/* Farbwahl: Feld und Farbtupfer nebeneinander */
.setcolor { display: flex; gap: 8px; align-items: center; }
.setcolor__pick {
  flex: none; width: 42px; height: 42px; padding: 2px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
.setcolor__text { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* Geltungsbereich einer Einstellung: persönlich oder gemeinsam */
.pill--own { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.topbar__who { margin-left: auto; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.setnote { padding: 12px 16px 0; font-size: 12.5px; line-height: 1.6; max-width: 900px; }
.setnote .pill { vertical-align: baseline; }

/* =========================================================================
   Anhang-Betrachter
   Liegt über der Nachricht, damit ein angetippter Anhang auf dem Handy die
   Seite nicht verlässt.
   ========================================================================= */
.viewer {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column;
  background: rgba(12, 14, 16, .94);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.viewer[hidden] { display: none; }
body.is-viewing { overflow: hidden; }

.viewer__bar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; flex: none;
  border-bottom: 1px solid rgba(255, 255, 255, .14);
}
.viewer__name {
  flex: 1; min-width: 0; color: #fff; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.viewer__dl {
  flex: none; background: rgba(255, 255, 255, .14); color: #fff;
  border: 1px solid rgba(255, 255, 255, .22); text-decoration: none;
}
.viewer__dl:hover { background: rgba(255, 255, 255, .24); }
.viewer__close {
  flex: none; width: 44px; height: 44px; border: 0; border-radius: 8px;
  background: rgba(255, 255, 255, .12); color: #fff; cursor: pointer;
  display: grid; place-items: center;
}
.viewer__close:hover { background: rgba(255, 255, 255, .24); }
.viewer__close .ic { width: 22px; height: 22px; }

.viewer__stage {
  flex: 1; min-height: 0; display: grid; place-items: center;
  padding: 12px; overflow: auto;
}
.viewer__img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  background: #fff; border-radius: 6px;
}
.viewer__frame {
  width: 100%; height: 100%; border: 0; border-radius: 6px; background: #fff;
}

.att__hint { font-weight: 400; }
@media (max-width: 600px) { .atts__hint { display: none; } }

/* „Mit KI antworten" sitzt in der Fusszeile zwischen den Verweisen */
.btn--ai { display: inline-flex; align-items: center; gap: 7px; }
.btn--ai .ic { width: 16px; height: 16px; }
.btn[data-busy][aria-busy="true"] { opacity: .6; pointer-events: none; }

/* „Mit KI antworten" in der Werkzeugleiste über der Nachricht */
.msg__aiBtn { flex: none; margin-right: 4px; }
.ai__hint { font-weight: 400; font-size: 12px; margin-left: 8px; }
@media (max-width: 560px) {
  .msg__aiBtnText { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  /* Auf die Grösse der Nachbar-Symbole, sonst fällt das Ziel zu klein aus */
  .msg__aiBtn { padding-left: 10px; padding-right: 10px; min-width: 40px; min-height: 40px; }
  .ai__hint { display: none; }
}
