:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #8a8a86;
  --line: #e4e4e0;
  --accent: #1f6feb;
  --danger: #d93025;
  --bar: rgba(246, 246, 244, 0.86);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161616;
    --surface: #1f1f1f;
    --text: #ececea;
    --muted: #8f8f8b;
    --line: #2e2e2c;
    --accent: #5a9bff;
    --danger: #ff6159;
    --bar: rgba(22, 22, 22, 0.86);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Helvetica Neue", system-ui, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Kopfleiste */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--line);
}
.bar h1 { margin: 0; font-size: 17px; font-weight: 600; text-align: center; white-space: nowrap; }
.bar > :first-child { justify-self: start; }
.bar > :last-child { justify-self: end; }
.bar-left { margin: 0; }
.link { color: var(--accent); font-size: 17px; }
.back { white-space: nowrap; }
.icon { color: var(--accent); display: grid; place-items: center; width: 34px; height: 34px; }
.icon.danger { color: var(--danger); }
.icon.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Liste */
.messages { list-style: none; margin: 0; padding: 0; background: var(--surface); }
.item { position: relative; overflow: hidden; border-bottom: 0.5px solid var(--line); transition: height 0.25s ease, opacity 0.25s ease; }
.item.removing { height: 0 !important; opacity: 0; border-bottom-width: 0; }
.row {
  position: relative; background: var(--surface);
  padding: 12px 16px 12px 28px;
  touch-action: pan-y;
  transition: transform 0.2s ease;
}
.item:active .row { background: var(--line); }
.swipe-bg {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 22px;
  background: #8a8a86; color: #fff; font-weight: 600;
  transition: background 0.15s;
}
.item.armed .swipe-bg { background: var(--danger); }
.line1 { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
time { color: var(--muted); font-size: 14px; flex-shrink: 0; }
.subject { color: var(--muted); font-size: 15px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread .row::before {
  content: ""; position: absolute; left: 10px; top: 19px;
  width: 9px; height: 9px; border-radius: 50%; background: var(--accent);
}
.unread .subject { color: var(--text); }

.status { padding: 32px 16px; text-align: center; color: var(--muted); }
.status:empty { display: none; }
.more { display: block; width: 100%; padding: 18px; color: var(--accent); }

/* ---------- Detail */
.message { padding: 16px; }
.msg-subject { margin: 0 0 12px; font-size: 22px; line-height: 1.25; font-weight: 700; overflow-wrap: anywhere; }
.msg-meta { color: var(--muted); font-size: 14px; line-height: 1.5; padding-bottom: 12px; border-bottom: 0.5px solid var(--line); overflow-wrap: anywhere; }
.msg-from { color: var(--text); font-size: 16px; font-weight: 600; }
.msg-from .email { color: var(--muted); font-weight: 400; font-size: 14px; }
.attachments { list-style: none; margin: 12px 0 0; padding: 0; font-size: 14px; }
.attachments li { padding: 4px 0; overflow-wrap: anywhere; }
.attachments span { color: var(--muted); }
.load-images {
  margin-top: 12px; padding: 8px 12px; border-radius: 8px;
  background: var(--surface); border: 0.5px solid var(--line); color: var(--accent); font-size: 14px;
}
.msg-body { margin-top: 14px; }
.msg-body iframe { display: block; width: 100%; height: 120px; border: 0; border-radius: 10px; background: #fff; }
.plain { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; }
.plain a, .message a { color: var(--accent); }

/* ---------- Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: rgba(30, 30, 30, 0.92); color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 15px; z-index: 20;
}
.toast.error { background: var(--danger); }

/* ---------- Login */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 320px; display: grid; gap: 12px; text-align: center; }
.login img { justify-self: center; border-radius: 16px; }
.login h1 { margin: 0 0 8px; font-size: 24px; }
.login input {
  font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 10px;
  border: 0.5px solid var(--line); background: var(--surface); color: var(--text);
}
/* Für Passwort-Manager sichtbar, für Menschen nicht */
.login .vh { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.login button { padding: 12px; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; font-size: 17px; }
.login .error { color: var(--danger); margin: 0; }
