:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #dde1e6;
  --text: #1d2228;
  --muted: #6b7480;
  --accent: #2563eb;
  --accent-soft: #e0e9fd;
  --row-hover: #f2f5fa;
  --unread: #111827;
  --flag: #d97706;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --panel: #1b1e24;
    --border: #2c3139;
    --text: #e4e7eb;
    --muted: #8d96a3;
    --accent: #60a5fa;
    --accent-soft: #1e3352;
    --row-hover: #232831;
    --unread: #ffffff;
    --flag: #fbbf24;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
button, input, select {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }

/* Kopfzeile */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; align-self: center; white-space: nowrap; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; flex: 1; }
.field { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.field.grow { flex: 1; min-width: 180px; }
.field input, .field select { color: var(--text); font-size: 14px; }
.status { font-size: 12px; color: var(--muted); align-self: center; }
.status.error { color: #dc2626; }

.user { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); align-self: center; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* Login */
.login {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.login[hidden] { display: none; }
.login-box {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 24px; display: flex; flex-direction: column; gap: 12px;
}
.login-box h1 { font-size: 18px; margin: 0; }
.login-box p { margin: 0; font-size: 13px; }
.login-box input { width: 100%; }
.login-error { color: #dc2626; font-size: 13px; min-height: 1em; }

/* Layout */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr) minmax(0, 0.9fr);
  gap: 1px;
  background: var(--border);
}
.pane { background: var(--panel); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.pane-head {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.pane-head input { flex: 1; min-width: 0; }

/* Gruppen */
.group-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.group-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.group-list li:hover { background: var(--row-hover); }
.group-list li.active { background: var(--accent-soft); }
.group-list .g-text { flex: 1; min-width: 0; }
.group-list .g-key { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-list .g-label { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  font-size: 12px; padding: 1px 8px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--border); white-space: nowrap;
}
.badge.unread { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Mailliste */
.mail-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-link { color: var(--accent); text-decoration: none; font-size: 13px; white-space: nowrap; }
.table-wrap { overflow: auto; flex: 1; }
.mail-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.mail-table th {
  position: sticky; top: 0; background: var(--panel); z-index: 1;
  text-align: left; font-weight: 600; font-size: 12px; color: var(--muted);
  padding: 6px 8px; border-bottom: 1px solid var(--border); cursor: pointer; user-select: none;
}
.mail-table th.sorted { color: var(--accent); }
.mail-table th.sorted.asc::after { content: " ▲"; }
.mail-table th.sorted.desc::after { content: " ▼"; }
.mail-table th:nth-child(1) { width: 130px; }
.mail-table th:nth-child(2), .mail-table th:nth-child(3) { width: 20%; }
.mail-table th:nth-child(5) { width: 15%; }
.mail-table th:nth-child(6) { width: 56px; }
.mail-table th:nth-child(7) { width: 70px; }
.score { font-variant-numeric: tabular-nums; }
.score.high { color: #dc2626; font-weight: 600; }
.score.mid { color: var(--flag); }
.reasons { margin: 4px 0 0; padding-left: 18px; }
.reasons li { margin: 1px 0; }
.reasons .pts { color: var(--muted); font-size: 12px; }
.digest { padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }
.digest h2 { margin: 0; font-size: 17px; }
.digest table { border-collapse: collapse; font-size: 13px; }
.digest td, .digest th { padding: 4px 10px 4px 0; text-align: left; border-bottom: 1px solid var(--border); }
.digest .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.digest .result { font-size: 13px; }
.mail-table td {
  padding: 6px 8px; border-bottom: 1px solid var(--border);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mail-table tbody tr { cursor: pointer; }
.mail-table tbody tr:hover { background: var(--row-hover); }
.mail-table tbody tr.active { background: var(--accent-soft); }
.mail-table tr.unread td { font-weight: 600; color: var(--unread); }
.mail-table tr.deleted td { text-decoration: line-through; opacity: .6; }
.num { text-align: right; }
.flag { color: var(--flag); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 8px; border-top: 1px solid var(--border); }
.muted { color: var(--muted); }

/* Detailansicht */
.detail { overflow: auto; }
.detail .empty { margin: auto; color: var(--muted); padding: 24px; text-align: center; }
.detail-head { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.detail-head h2 { margin: 0 0 8px; font-size: 17px; word-break: break-word; }
.detail-head dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; margin: 0; font-size: 13px; }
.detail-head dt { color: var(--muted); }
.detail-head dd { margin: 0; word-break: break-word; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.detail-actions a, .detail-actions button { font-size: 13px; }
.detail-actions a {
  color: var(--accent); text-decoration: none; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 6px;
}
.tabs { display: flex; gap: 2px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; }
.tabs button.active { border-bottom-color: var(--accent); color: var(--accent); }
.body-text { white-space: pre-wrap; word-break: break-word; padding: 12px 16px; margin: 0; font: 13px/1.5 ui-monospace, Consolas, monospace; }
.body-html { width: 100%; flex: 1; min-height: 60vh; border: 0; background: #fff; }
.header-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.header-table td { padding: 3px 16px; border-bottom: 1px solid var(--border); vertical-align: top; word-break: break-all; }
.header-table td:first-child { color: var(--muted); white-space: nowrap; width: 1%; }
.attachments { padding: 8px 16px; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 6px; }
.attachments a { font-size: 12px; color: var(--accent); text-decoration: none; border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; }
.close-detail { display: none; }

/* Responsiv */
@media (max-width: 1200px) {
  .layout { grid-template-columns: minmax(200px, 260px) minmax(0, 1fr); }
  .detail {
    position: fixed; inset: 0 0 0 auto; width: min(720px, 100vw); z-index: 10;
    box-shadow: -8px 0 24px rgba(0,0,0,.25); display: none;
  }
  .detail.open { display: flex; }
  .close-detail { display: inline-block; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: minmax(0, 35vh) minmax(0, 1fr); }
  .mail-table th:nth-child(3), .mail-table td:nth-child(3),
  .mail-table th:nth-child(5), .mail-table td:nth-child(5),
  .mail-table th:nth-child(6), .mail-table td:nth-child(6),
  .mail-table th:nth-child(7), .mail-table td:nth-child(7) { display: none; }
  .mail-table th:nth-child(1) { width: 92px; }
  .mail-table th:nth-child(2) { width: 35%; }
}
