:root {
  --bg: #0b0d10;
  --bg-raised: #131720;
  --bg-hover: #1a1f2b;
  --line: #232935;
  --text: #e8ecf3;
  --text-dim: #8b95a7;
  --text-faint: #5d6779;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.14);
  --danger: #ff6b6b;
  --radius: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --bg-raised: #ffffff;
    --bg-hover: #eef1f6;
    --line: #e0e4ec;
    --text: #131720;
    --text-dim: #5d6779;
    --text-faint: #8b95a7;
    --accent-soft: rgba(76, 141, 255, 0.1);
  }
}

* { box-sizing: border-box; }

/* Mehrere Elemente hier setzen `display: flex` und wuerden damit das
   hidden-Attribut ueberstimmen — versteckt heisst versteckt. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ── Kopfzeile ────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 17px;
}

.brand-mark { color: var(--accent); }
.brand-rest { color: var(--text-dim); margin-left: 6px; font-weight: 500; }

.tabs { display: flex; gap: 4px; }

.tab {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.tab:hover { background: var(--bg-hover); color: var(--text); }
.tab.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ── Layout ───────────────────────────────────────────────────────────────── */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

.reader { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }

/* Auf schmalen Fenstern gibt es nur eine Spalte: entweder die Liste oder die
   geoeffnete Nachricht — nie beides untereinander, sonst muesste man nach dem
   Antippen erst scrollen, um überhaupt etwas zu sehen. */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .reader:not(.is-open) { display: none; }
  body.is-reading .sidebar { display: none; }
}

.back-btn {
  display: none;
  background: none;
  border: 0;
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  margin-bottom: 12px;
}

@media (max-width: 860px) {
  .back-btn { display: block; }
}

/* ── Panels ───────────────────────────────────────────────────────────────── */

.panel {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.lead { margin: 0 0 14px; color: var(--text-dim); font-size: 14px; }

.address-row { display: flex; align-items: center; gap: 8px; }

.address {
  font-family: var(--mono);
  font-size: 15px;
  background: var(--bg-hover);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  flex: 1;
  overflow-x: auto;
  white-space: nowrap;
  user-select: all;
}

.panel-meta { margin-top: 10px; font-size: 13px; color: var(--text-faint); }
.panel-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Knöpfe ───────────────────────────────────────────────────────────────── */

.primary-btn,
.icon-btn,
.ghost-btn {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  transition: background 120ms ease, border-color 120ms ease;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  width: 100%;
}

.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:disabled { opacity: 0.5; cursor: default; filter: none; }

.icon-btn,
.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-dim);
  padding: 8px 12px;
  font-size: 13px;
}

.icon-btn:hover,
.ghost-btn:hover { background: var(--bg-hover); color: var(--text); }
.ghost-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

.link-btn {
  background: none;
  border: 0;
  color: var(--text-dim);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

/* ── Formulare ────────────────────────────────────────────────────────────── */

.form { display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-dim); }

.field input {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-hover);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
}

.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.alias-input { display: flex; align-items: stretch; }
.alias-input input { border-radius: 8px 0 0 8px; border-right: 0; flex: 1; min-width: 0; font-family: var(--mono); }

.alias-suffix {
  display: flex;
  align-items: center;
  padding: 0 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 0 8px 8px 0;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 13px;
  white-space: nowrap;
}

/* ── Hinweise ─────────────────────────────────────────────────────────────── */

.notice {
  margin: 12px 20px 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid transparent;
}

.notice.is-error { background: rgba(255, 107, 107, 0.12); color: var(--danger); }

/* ── Nachrichtenliste ─────────────────────────────────────────────────────── */

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 16px 20px 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.msglist { list-style: none; margin: 0; padding: 0 8px 16px; }

.msgitem {
  padding: 11px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.msgitem:hover { background: var(--bg-hover); }
.msgitem.is-selected { background: var(--accent-soft); }

.msgitem-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.msgitem-from { font-size: 13px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msgitem-time { font-size: 12px; color: var(--text-faint); flex-shrink: 0; }

.msgitem-subject {
  font-size: 14.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msgitem.is-unread .msgitem-subject { font-weight: 650; }
.msgitem.is-unread .msgitem-from { color: var(--text); }

.msgitem-preview {
  font-size: 13px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msgitem-badges { font-size: 12px; color: var(--text-faint); }

.empty { padding: 40px 20px; text-align: center; color: var(--text-faint); font-size: 14px; }
.empty p { margin: 0; }
.empty span { font-size: 13px; color: var(--text-faint); opacity: 0.7; }

.empty-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin: 0 auto 14px;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.25; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.3); }
}

@media (prefers-reduced-motion: reduce) {
  .empty-dot { animation: none; opacity: 0.5; }
}

/* ── Lesebereich ──────────────────────────────────────────────────────────── */

.reader-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 14px;
}

.reader-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.reader-head { padding: 22px 26px 16px; border-bottom: 1px solid var(--line); }
.reader-head h1 { margin: 0 0 8px; font-size: 20px; letter-spacing: -0.01em; line-height: 1.3; }

.reader-meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--text-dim); }
.reader-tools { margin-top: 14px; display: flex; gap: 8px; }

.attachments {
  padding: 12px 26px;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 13px;
  color: var(--text-dim);
  background: transparent;
  font-family: inherit;
  cursor: pointer;
}

.attachment:hover { background: var(--bg-hover); color: var(--text); }
.attachment-size { color: var(--text-faint); font-size: 12px; }

.msg-text {
  margin: 0;
  padding: 22px 26px;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
  flex: 1;
}

.msg-html {
  flex: 1;
  border: 0;
  width: 100%;
  background: #fff;
  min-height: 400px;
}

/* ── Fußzeile ─────────────────────────────────────────────────────────────── */

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--text-faint);
  background: var(--bg-raised);
}
