:root {
  --bg: #f4f1ec;
  --surface: #fffdf9;
  --surface-2: #ebe6de;
  --line: #ddd6cb;
  --ink: #1d2329;
  --ink-2: #59626b;
  --accent: #c2410c;
  --accent-ink: #fff;
  --accent-soft: #fbe3d6;
  --danger: #b42318;
  --ok: #2b8a3e;
  --radius: 12px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16191d;
    --surface: #1f2328;
    --surface-2: #2a2f35;
    --line: #353b42;
    --ink: #eceae6;
    --ink-2: #a2a9b1;
    --accent: #f0814a;
    --accent-ink: #1a0d05;
    --accent-soft: #3d2416;
    --danger: #ff8a80;
    --ok: #69db7c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 8px; }
.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }
.pad { padding: 0 16px; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; font-size: 0.9rem; }

/* Knöpfe */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn.small { padding: 6px 12px; font-size: 0.9rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg, .nav-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Anmeldung */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%);
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 28px; display: grid; gap: 10px;
}
.login-card input { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.2rem; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 800;
}

/* Grundgerüst: Handy */
.app { height: 100%; display: flex; flex-direction: column; }
.view { flex: 1; overflow: auto; padding-top: var(--safe-t); padding-bottom: calc(var(--nav-h) + var(--safe-b) + 8px); }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.nav-brand, .compose-btn { display: none; }
.nav-btn {
  flex: 1; border: 0; background: none; cursor: pointer; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-2); font-size: 0.72rem; font-weight: 600;
}
.nav-btn svg { width: 24px; height: 24px; }
.nav-btn[aria-current="page"] { color: var(--accent); }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--ink); color: var(--bg); font-size: 0.7rem; line-height: 18px; text-align: center;
}
.badge.accent { background: var(--accent); color: var(--accent-ink); }

.pane-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px 10px; position: sticky; top: 0; z-index: 5; background: var(--bg);
}
.head-actions { display: flex; gap: 8px; align-items: center; }

.search { padding: 0 16px 8px; }
.search input {
  width: 100%; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 0.88rem; font-weight: 600; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dot, var(--ink-2)); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .count { font-weight: 500; opacity: 0.75; }
.list-tools { display: flex; justify-content: space-between; align-items: center; padding: 2px 16px 8px; }
.toggle { display: inline-flex; gap: 8px; align-items: center; font-size: 0.9rem; }
.toggle input { accent-color: var(--accent); width: 18px; height: 18px; }

.acc-error {
  margin: 0 16px 8px; padding: 10px 12px; border-radius: 10px;
  background: var(--accent-soft); font-size: 0.88rem;
}

.mail-list { list-style: none; margin: 0; padding: 0; }
.mail-item {
  display: grid; grid-template-columns: 4px 1fr auto; gap: 0 12px;
  padding: 12px 16px 12px 0; border-bottom: 1px solid var(--line); cursor: pointer;
}
.mail-item:hover, .mail-item[aria-selected="true"] { background: var(--surface); }
.mail-item .bar { grid-row: 1 / 4; background: var(--acc, var(--line)); border-radius: 0 3px 3px 0; opacity: 0.85; }
.mail-item .from { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item .date { color: var(--ink-2); font-size: 0.82rem; white-space: nowrap; }
.mail-item .subject {
  grid-column: 2 / 4; font-size: 0.93rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mail-item .meta { grid-column: 2 / 4; font-size: 0.78rem; color: var(--ink-2); display: flex; gap: 8px; }
.mail-item.unread .from, .mail-item.unread .subject { font-weight: 700; }
.mail-item.unread .from::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); margin-right: 6px; vertical-align: middle;
}
.flag { color: var(--accent); }
.list-empty { padding: 40px 16px; text-align: center; color: var(--ink-2); }
.skeleton { height: 64px; margin: 1px 16px; border-radius: 8px; background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Detailansicht: Handy zeigt sie als Vollbild */
.detail-pane { display: none; }
.view-inbox.show-detail .list-pane { display: none; }
.view-inbox.show-detail .detail-pane { display: block; }
.empty-detail { padding: 40px; text-align: center; }
.detail-head { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.detail-top { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.back-btn { display: inline-flex; }
.detail-subject { font-size: 1.25rem; font-weight: 700; margin: 4px 0 10px; overflow-wrap: anywhere; }
.detail-meta { font-size: 0.9rem; display: grid; gap: 2px; }
.detail-meta b { font-weight: 600; }
.acc-tag {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 600;
  padding: 2px 10px; border-radius: 999px; background: var(--surface-2);
}
.acc-tag .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dot); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.attachment {
  text-decoration: none; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; font-size: 0.85rem;
}
.body-bar { display: flex; justify-content: flex-end; padding: 8px 16px 0; }
.body-frame { width: 100%; border: 0; background: #fff; min-height: 300px; display: block; }
.body-text { white-space: pre-wrap; padding: 16px; margin: 0; font: inherit; overflow-wrap: anywhere; }

/* Assistent */
.view-assistant { display: flex; flex-direction: column; padding-bottom: 0; overflow: hidden; }
.chat { flex: 1; overflow: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.chat-intro { margin: auto 0; text-align: center; color: var(--ink-2); }
.suggestions { display: grid; gap: 8px; margin-top: 16px; }
.suggest {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px;
  text-align: left; cursor: pointer; color: var(--ink);
}
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.error { align-self: flex-start; background: var(--accent-soft); }
.msg .acts { margin-top: 8px; font-size: 0.78rem; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 4px; }
.msg .acts span { background: var(--surface-2); border-radius: 6px; padding: 1px 6px; }
.msg .go-pending { margin-top: 8px; }
.typing { align-self: flex-start; color: var(--ink-2); font-size: 0.9rem; }
.typing::after { content: "…"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }
.chat-input {
  border-top: 1px solid var(--line); background: var(--bg);
  padding: 10px 16px calc(var(--nav-h) + var(--safe-b) + 10px);
}
.chat-ref { font-size: 0.82rem; color: var(--ink-2); margin-bottom: 6px; display: flex; justify-content: space-between; gap: 8px; }
.chat-ref button { border: 0; background: none; color: var(--accent); cursor: pointer; font-weight: 600; }
.chat-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-row textarea {
  flex: 1; resize: none; max-height: 160px; padding: 10px 14px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--surface);
}

/* Freigaben */
.pending-list { display: grid; gap: 12px; padding: 12px 16px; }
.pending-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 8px; }
.pending-card label, .sheet label { display: grid; gap: 4px; font-size: 0.82rem; color: var(--ink-2); font-weight: 600; }
.pending-card input, .pending-card textarea, .pending-card select,
.sheet input, .sheet select, .sheet textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-weight: 400; font-size: 1rem;
}
.pending-card textarea { min-height: 160px; resize: vertical; }
.pending-src { font-size: 0.8rem; color: var(--ink-2); }
.pending-actions { display: flex; gap: 8px; justify-content: flex-end; }
.done-list, .activity, .account-status { list-style: none; margin: 0; padding: 0 16px 16px; }
.done-list li, .activity li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 0.88rem; }
.activity li .when { color: var(--ink-2); font-size: 0.78rem; }
.card { margin: 0 16px 16px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card .activity, .card .account-status { padding: 0; }
.account-status li { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.account-status .res { font-size: 0.82rem; color: var(--ink-2); }
.account-status .res.ok { color: var(--ok); }

/* Verfassen */
.sheet {
  border: 0; padding: 0; width: 100%; max-width: 640px; max-height: 100%;
  background: var(--surface); color: var(--ink); border-radius: 16px 16px 0 0;
  margin: auto auto 0;
}
.sheet::backdrop { background: rgb(0 0 0 / 0.35); }
.sheet form { display: grid; gap: 10px; padding: 0 16px calc(16px + var(--safe-b)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 0 6px; position: sticky; top: 0; background: var(--surface); }
.sheet textarea { resize: vertical; min-height: 200px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 0.9rem;
  max-width: calc(100% - 32px);
}

.mobile-only { display: grid; }

/* Mac und große Bildschirme */
@media (min-width: 900px) {
  .app { flex-direction: row; }
  .mobile-only { display: none; }
  .nav {
    position: static; flex-direction: column; width: 220px; height: 100%;
    padding: 16px 12px; gap: 4px; border-top: 0; border-right: 1px solid var(--line); background: var(--surface);
  }
  .nav-brand { display: flex; padding: 4px 8px 16px; }
  .nav-btn { flex: 0; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 12px; border-radius: 10px; font-size: 0.95rem; }
  .nav-btn[aria-current="page"] { background: var(--accent-soft); }
  .badge { position: static; margin-left: auto; }
  .compose-btn { display: block; margin-top: 12px; }
  .view { padding-bottom: 16px; }
  .view-inbox { display: grid; grid-template-columns: minmax(320px, 400px) 1fr; padding: 0; overflow: hidden; }
  .view-inbox[hidden] { display: none; }
  .list-pane { overflow: auto; border-right: 1px solid var(--line); }
  .detail-pane, .view-inbox.show-detail .detail-pane { display: block; overflow: auto; background: var(--surface); }
  .view-inbox.show-detail .list-pane { display: block; }
  .back-btn { display: none; }
  .chat-input { padding-bottom: 16px; }
  .view-assistant, .view-pending, .view-more { max-width: 820px; }
  .sheet { border-radius: 16px; margin: auto; }
  .toast { bottom: 24px; }
}

/* Ordner */
.sheet-inner { padding: 0 16px calc(16px + var(--safe-b)); }
#folders { max-height: 88vh; }
.folder-tree { display: grid; gap: 2px; padding-bottom: 8px; }
.folder-acc {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 14px; padding: 6px 0; border-bottom: 1px solid var(--line);
}
.folder-acc .acc-tag { font-size: 0.9rem; }
.folder-row {
  display: flex; align-items: center; gap: 4px; border-radius: 10px;
  padding-left: calc(var(--depth, 0) * 18px);
}
.folder-row.current .folder-btn { background: var(--accent-soft); font-weight: 700; }
.folder-btn {
  flex: 1; display: flex; align-items: center; gap: 10px; text-align: left;
  border: 0; background: none; padding: 10px 10px; border-radius: 10px; cursor: pointer; min-height: 44px;
}
.folder-btn:hover { background: var(--surface-2); }
.folder-btn:disabled { cursor: default; color: var(--ink-2); background: none; }
.folder-btn svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; color: var(--ink-2); }
.folder-btn .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-more { border: 0; background: none; width: 40px; height: 40px; border-radius: 10px; cursor: pointer; color: var(--ink-2); font-size: 1.2rem; }
.folder-more:hover { background: var(--surface-2); }
.folder-all { font-weight: 700; }
.folder-menu { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px 0 8px calc(var(--depth, 0) * 18px + 38px); }
.folder-path { font-size: 0.82rem; color: var(--ink-2); padding: 0 16px 6px; }
