:root {
  --green-dark: #103c34;
  --green: #08745c;
  --mint: #e4f1ec;
  --gold: #d59a32;
  --bg: #f5f4ef;
  --panel: #ffffff;
  --text: #1b2b27;
  --muted: #5d6f69;
  --line: #dde5e1;
  --danger: #b3261e;
  --hover: #eef4f1;
  --select: #e4f1ec;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1a17;
    --panel: #15231f;
    --text: #e6efeb;
    --muted: #9db1aa;
    --line: #26372f;
    --hover: #1b2d27;
    --select: #1f3a31;
    --mint: #1f3a31;
    --green: #3fb392;
  }
}
* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* Buttons */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 7px 12px; min-height: 36px; }
.btn:hover { background: var(--hover); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .row:focus-visible, .folder:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 9px; min-height: 30px; font-size: 13px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 26px; display: grid; gap: 12px; box-shadow: 0 8px 30px rgba(16, 60, 52, 0.08); }
.login h1 { margin: 0 0 4px; font-size: 20px; color: var(--green-dark); }
@media (prefers-color-scheme: dark) { .login h1 { color: var(--text); } }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 8px 10px; width: 100%; min-height: 36px; }
textarea { resize: vertical; }
.error { color: var(--danger); font-size: 13px; }
.notice { color: var(--green); font-size: 13px; }

/* App Shell */
.app { height: 100%; display: grid; grid-template-rows: 52px 1fr; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--green-dark); color: #fff; }
.topbar .brand { font-weight: 700; letter-spacing: 0.2px; display: flex; align-items: center; gap: 8px; }
.topbar .brand .dot { width: 22px; height: 22px; border-radius: 6px; background: var(--gold); display: inline-block; }
.topbar .search { flex: 1; max-width: 560px; margin-left: 12px; }
.topbar .search input { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.2); color: #fff; }
.topbar .search input::placeholder { color: rgba(255, 255, 255, 0.7); }
.topbar .spacer { flex: 1; }
.topbar .btn { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.25); color: #fff; }
.topbar .btn:hover { background: rgba(255, 255, 255, 0.2); }
.topbar .btn.primary { background: var(--gold); border-color: var(--gold); color: #1b1b1b; }
.hamburger { display: none; }

.panes { display: grid; grid-template-columns: 250px 380px 1fr; min-height: 0; }
.pane { min-height: 0; overflow: auto; border-right: 1px solid var(--line); background: var(--panel); }
.pane.reader { border-right: 0; display: flex; flex-direction: column; background: var(--panel); }

/* Sidebar */
.sidebar { background: var(--bg); padding: 8px 6px; }
.account { margin-bottom: 4px; }
.account-head { display: flex; align-items: center; gap: 6px; width: 100%; border: 0; background: transparent; padding: 8px; border-radius: var(--radius); font-weight: 600; text-align: left; }
.account-head:hover { background: var(--hover); }
.account-head .caret { width: 14px; color: var(--muted); }
.account-head .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: transparent; text-align: left; padding: 6px 8px 6px calc(24px + var(--depth, 0) * 14px); border-radius: var(--radius); }
.folder:hover { background: var(--hover); }
.folder.active { background: var(--select); font-weight: 600; color: var(--green-dark); }
@media (prefers-color-scheme: dark) { .folder.active { color: var(--text); } }
.folder .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--gold); color: #1b1b1b; border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 700; }
.write-tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; }
.write-tag.on { color: var(--green); border-color: var(--green); }

/* Liste */
.list-tools { position: sticky; top: 0; background: var(--panel); border-bottom: 1px solid var(--line); padding: 8px; display: flex; gap: 6px; flex-wrap: wrap; z-index: 2; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 14px; padding: 3px 10px; font-size: 13px; }
.chip.active { background: var(--green); color: #fff; border-color: var(--green); }
.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row:hover { background: var(--hover); }
.row.selected { background: var(--select); }
.row .from { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .from, .row.unread .subject { font-weight: 700; }
.row .date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.row .subject { grid-column: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.row .meta { grid-column: 2; text-align: right; color: var(--gold); font-size: 13px; }
.empty { padding: 28px 16px; color: var(--muted); text-align: center; }
.loadmore { padding: 10px; text-align: center; }

/* Reader */
.reader-tools { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.reader-head { padding: 12px 16px 8px; border-bottom: 1px solid var(--line); }
.reader-head h2 { margin: 0 0 6px; font-size: 18px; overflow-wrap: anywhere; }
.reader-head .line { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.reader-head .line b { color: var(--text); font-weight: 600; }
.reader-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.reader-body iframe { flex: 1; width: 100%; border: 0; background: #fff; min-height: 300px; }
.reader-body pre { margin: 0; padding: 14px 16px; white-space: pre-wrap; word-wrap: break-word; font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow: auto; flex: 1; }
.banner { background: var(--mint); padding: 8px 16px; font-size: 13px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.attachments { padding: 8px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; }
.attachments a { border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 10px; text-decoration: none; color: var(--text); font-size: 13px; }
.attachments a:hover { background: var(--hover); }

/* Dialoge */
.backdrop { position: fixed; inset: 0; background: rgba(8, 20, 17, 0.5); display: grid; place-items: center; padding: 12px; z-index: 50; }
.dialog { background: var(--panel); border-radius: 14px; width: min(760px, 100%); max-height: 94vh; overflow: auto; border: 1px solid var(--line); }
.dialog header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.dialog header h2 { margin: 0; font-size: 17px; }
.dialog .body { padding: 16px 18px; display: grid; gap: 12px; }
.dialog footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.acc-item { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: grid; gap: 6px; }
.acc-item .top { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center; }
.acc-item .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.switch { display: flex; align-items: center; gap: 8px; }
.switch input { width: auto; min-height: 0; }
.preview { border: 1px solid var(--gold); background: rgba(213, 154, 50, 0.1); border-radius: var(--radius); padding: 12px; display: grid; gap: 6px; }
.preview pre { margin: 0; white-space: pre-wrap; max-height: 220px; overflow: auto; font: 13px/1.5 inherit; }
.compose-files { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* Kontextmenü */
.menu { position: fixed; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); padding: 4px; z-index: 60; min-width: 220px; }
.menu button { display: flex; justify-content: space-between; gap: 18px; width: 100%; border: 0; background: transparent; padding: 7px 10px; border-radius: 6px; text-align: left; }
.menu button:hover { background: var(--hover); }
.menu .sep { height: 1px; background: var(--line); margin: 4px 0; }
.menu kbd, .kbd { color: var(--muted); font-size: 12px; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--green-dark); color: #fff; padding: 9px 16px; border-radius: 10px; z-index: 70; max-width: 90vw; }
.toast.err { background: var(--danger); }

/* Responsive */
@media (max-width: 1100px) { .panes { grid-template-columns: 220px 320px 1fr; } }
@media (max-width: 860px) {
  .hamburger { display: inline-block; }
  .panes { grid-template-columns: 1fr; position: relative; }
  .pane { border-right: 0; }
  .panes .sidebar { position: absolute; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 10; box-shadow: 4px 0 18px rgba(0, 0, 0, 0.2); transform: translateX(-105%); transition: transform 0.15s; }
  .panes.nav-open .sidebar { transform: none; }
  .panes .reader { display: none; }
  .panes.show-reader .list { display: none; }
  .panes.show-reader .reader { display: flex; }
  .topbar .search { margin-left: 0; }
  .grid2 { grid-template-columns: 1fr; }
  .back { display: inline-block !important; }
}
.back { display: none; }

/* Einzelfenster */
.viewer { min-height: 100%; display: flex; flex-direction: column; background: var(--panel); }
.viewer .reader-body iframe { min-height: 70vh; }
@media print { .reader-tools, .banner { display: none; } }

/* Nachrichten-Dialog */
.dialog.wide { width: min(1040px, 100%); height: min(92vh, 920px); display: flex; flex-direction: column; }
.dialog.wide .body { flex: 1; min-height: 0; overflow: auto; align-content: start; }
.dialog header { gap: 10px; }
.dialog header h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.msg-frame { width: 100%; height: 56vh; min-height: 300px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.msg-text { margin: 0; white-space: pre-wrap; word-wrap: break-word; font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.dialog .reader-head { padding: 0 0 8px; border-bottom: 1px solid var(--line); }
.dialog .attachments { padding: 0; border-top: 0; }

/* Logo */
.logo-login { width: min(280px, 100%); height: auto; margin: 0 auto 6px; display: block; }
.logo-top { height: 34px; width: auto; display: block; background: #fff; border-radius: 8px; padding: 3px 8px; }

/* KI */
.ai-box { background: var(--mint); border-radius: var(--radius); padding: 10px 14px; margin: 8px 16px; white-space: pre-wrap; font-size: 13px; }
.ai-box.error { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.dialog .ai-box { margin: 0; }
.ai-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.pad { padding: 8px; }
.grow { flex: 1; }
[hidden] { display: none !important; }

.launcher { position: relative; }
.launcher-btn { padding: 6px 8px; }
.waffle { display: grid; grid-template-columns: repeat(3, 4px); gap: 3px; }
.waffle i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; display: block; }
.launcher-panel { position: absolute; top: calc(100% + 8px); left: 0; z-index: 50; background: #fff; color: #1b1b1b; border: 1px solid #d0d5dd; border-radius: 12px; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22); padding: 12px; display: grid; grid-template-columns: repeat(3, 104px); gap: 6px; max-height: 70vh; overflow-y: auto; }
.launcher-item { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px; border-radius: 10px; text-decoration: none; color: inherit; font-size: 13px; text-align: center; }
a.launcher-item:hover, a.launcher-item:focus-visible { background: #eef2f6; }
.launcher-item.current { background: #e3f1f5; }
.launcher-item.off { opacity: 0.45; cursor: not-allowed; }
.sso-box { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; align-items: stretch; text-align: center; }
.sso-box .btn { text-decoration: none; display: inline-block; }
