:root {
  --bg: #0f1115;
  --bg-2: #161922;
  --bg-3: #1e222e;
  --line: #2a2f3d;
  --text: #e7e9ee;
  --muted: #8b91a1;
  --accent: #5b8cff;
  --accent-2: #3d6be0;
  --danger: #ff5b6e;
  --ok: #36d399;
  --radius: 10px;
}

:root[data-theme="light"] {
  --bg: #f5f6f8;
  --bg-2: #ffffff;
  --bg-3: #eceef3;
  --line: #d9dde4;
  --text: #1a1d24;
  --muted: #6b7280;
  --accent: #3d6be0;
  --accent-2: #3d6be0;
  --danger: #e23b4e;
  --ok: #1a9d6b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 14px;
}

/* Solange nicht angemeldet: nur das Login-Fenster zeigen */
body.locked .topbar,
body.locked .layout { display: none; }

/* --- Topbar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 15px; font-weight: 600; letter-spacing: .2px; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.status { color: var(--muted); font-size: 12px; }
.me-name { font-size: 12px; font-weight: 600; color: var(--text); margin-left: 2px; }
.tb-divider { width: 1px; height: 20px; background: var(--line); margin: 0 2px; }
.icon-btn-bare {
  background: none; border: none; color: var(--muted);
  cursor: pointer; padding: 7px; border-radius: 8px;
  display: inline-flex; align-items: center;
}
.icon-btn-bare:hover { background: var(--bg-3); color: var(--text); }
.icon-btn-bare svg { display: block; }

/* --- Buttons --- */
.btn {
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-danger { color: var(--danger); border-color: transparent; }
.btn-danger:hover { border-color: var(--danger); }

/* --- Layout --- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 340px 1fr;
  overflow: hidden;
}
.pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  overflow: hidden;
}
.pane-view { border-right: none; }
.pane-head {
  padding: 10px 14px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.pane-head.row { display: flex; gap: 8px; align-items: center; }

/* --- Konten --- */
.account-search {
  margin: 8px 10px;
  padding: 6px 9px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}
.account-search:focus { outline: none; border-color: var(--accent); }

/* Toolbar: Sortierung + Tag-Filter + Auswaehlen */
.account-toolbar {
  display: flex; gap: 6px; align-items: center;
  padding: 0 10px 8px;
}
.account-toolbar .mini-select {
  flex: 1; min-width: 0;
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px;
  padding: 5px 7px; font-size: 12px; font-family: inherit;
}
.account-toolbar .mini-select:focus { outline: none; border-color: var(--accent); }
.icon-btn {
  flex: 0 0 auto;
  background: var(--bg-3); border: 1px solid var(--line);
  color: var(--muted); cursor: pointer;
  border-radius: 7px; padding: 5px 8px; font-size: 12px;
  display: inline-flex; align-items: center; gap: 5px;
}
.icon-btn:hover { border-color: var(--accent); color: var(--text); }
.icon-btn.active { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.icon-btn svg { display: block; }

/* Icon-only Button in der Topbar */
.btn-icon { padding: 7px 9px; display: inline-flex; align-items: center; }
.btn-icon svg { display: block; }

/* Popup-Menue (Sortierung / Import) */
.sort-wrap, .menu-wrap { position: relative; flex: 0 0 auto; }
.popmenu.right { left: auto; right: 0; }
.popmenu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 30;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px; min-width: 140px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  display: flex; flex-direction: column; gap: 2px;
}
.popmenu.hidden { display: none; }
.popmenu button {
  background: none; border: none; color: var(--text); cursor: pointer;
  text-align: left; padding: 7px 9px; border-radius: 6px;
  font-size: 12px; font-family: inherit;
}
.popmenu button:hover { background: var(--bg-3); }

/* Bulk-Leiste bei Mehrfachauswahl */
.bulk-bar {
  display: none;
  align-items: center; gap: 8px;
  padding: 8px 10px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.bulk-bar.show { display: flex; }
.bulk-bar .count {
  margin-right: auto;
  min-width: 22px; height: 22px; padding: 0 7px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-2); color: #fff;
  border-radius: 11px; font-size: 12px; font-weight: 600;
}

.account-list { list-style: none; overflow-y: auto; flex: 1; }
.account-item {
  display: flex;
  flex-direction: column;
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.account-item:hover { background: var(--bg-2); }
.account-item.active { background: var(--bg-3); box-shadow: inset 3px 0 0 var(--accent); }
.account-item.dragging { opacity: 0.4; }
.account-item.drop-target { box-shadow: inset 0 2px 0 var(--accent); }
.account-item.selected { background: color-mix(in srgb, var(--accent) 16%, transparent); box-shadow: inset 3px 0 0 var(--accent); }
.account-item[draggable="true"] { cursor: grab; }

.account-item .a-top { display: flex; align-items: flex-start; gap: 8px; }
.account-item .a-select {
  appearance: none; -webkit-appearance: none;
  flex: 0 0 auto;
  align-self: center;            /* vertikal mittig */
  width: 18px; height: 18px;
  border: 2px solid var(--line);
  border-radius: 5px;
  background: var(--bg-3);
  position: relative;
  cursor: pointer;
  pointer-events: none;          /* Klick auf die ganze Zeile schaltet um */
  transition: background .12s, border-color .12s;
}
.account-item .a-select:checked {
  background: var(--accent-2);
  border-color: var(--accent-2);
}
.account-item .a-select:checked::after {
  content: "";
  position: absolute;
  left: 4px; top: 1px;
  width: 5px; height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.account-item .a-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.account-item .a-label { font-weight: 600; font-size: 13px; }
.account-item .a-mail {
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.account-item .a-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }

/* Aktionen poppen unter dem Konto auf */
.account-item .a-actions { display: none; gap: 5px; margin-top: 8px; }
.account-item:hover .a-actions { display: flex; }
.account-item .a-actions button {
  flex: 1;
  background: var(--bg-3); border: 1px solid var(--line);
  color: var(--muted); cursor: pointer;
  padding: 7px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
}
.account-item .a-actions button svg { width: 16px; height: 16px; }
.account-item .a-actions button:hover { background: var(--bg-2); color: var(--text); }
.account-item .a-actions .a-copy:hover { color: var(--accent); }
.account-item .a-actions .a-del:hover { color: var(--danger); }

/* --- Nachrichtenliste --- */
.select {
  flex: 1;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 13px;
}
.message-list { list-style: none; overflow-y: auto; flex: 1; }
.message-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.message-item:hover { background: var(--bg-2); }
.message-item.active { background: var(--bg-3); }
.message-item.unread .m-subject { font-weight: 700; }
.message-item.unread::before {
  content: ""; display: inline-block;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); margin-right: 7px; vertical-align: middle;
}
.m-top { display: flex; justify-content: space-between; gap: 8px; }
.m-from { color: var(--text); font-size: 13px; }
.m-date { color: var(--muted); font-size: 11px; white-space: nowrap; }
.m-subject { font-size: 13px; margin-top: 2px; color: var(--text); }

/* --- Nachricht --- */
.message-view { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.empty {
  margin: auto; text-align: center; color: var(--muted);
  line-height: 1.7; font-size: 13px;
}
.mv-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.mv-subject { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.mv-meta { font-size: 12px; color: var(--muted); line-height: 1.6; }
.mv-actions { padding: 10px 20px; display: flex; gap: 8px; border-bottom: 1px solid var(--line); }
.mv-body { flex: 1; }
.mv-body iframe { width: 100%; height: 100%; border: none; background: #fff; }
.mv-text { padding: 18px 20px; white-space: pre-wrap; line-height: 1.6; }
.mv-attach { padding: 10px 20px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }

/* --- Modal --- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
/* Proxy-Dialog ueber anderen Dialogen (wird aus Konto/Import geoeffnet) */
#proxiesModal { z-index: 60; }
.modal-box {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  width: 440px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-box h2 { font-size: 16px; margin-bottom: 14px; }
.modal-box label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 15px;
}
.modal-box input, .modal-box textarea {
  width: 100%;
  margin-top: 5px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.modal-box input:focus, .modal-box textarea:focus {
  outline: none; border-color: var(--accent);
}
.hint {
  font-size: 12px; color: var(--muted);
  background: var(--bg-3); border-radius: 7px;
  padding: 9px 11px; line-height: 1.5;
}
.input-with-btn { display: flex; gap: 8px; margin-top: 5px; align-items: stretch; }
.input-with-btn input { margin-top: 0; flex: 1; min-width: 0; }
.input-with-btn .btn { flex: 0 0 auto; white-space: nowrap; }
.proxy-result { font-size: 12px; margin-top: 8px; }
.proxy-result.ok { color: var(--ok); }
.proxy-result.bad { color: var(--danger); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.error { color: var(--danger); font-size: 12px; margin-top: 12px; min-height: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* --- Tags --- */
.tag-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--text);
}
.tag-chip-sm { padding: 1px 7px; font-size: 11px; border-radius: 10px; }

/* --- Proxy-Verwaltung --- */
.hint-sm { font-size: 11px; color: var(--muted); margin-top: 6px; }
.modal-box h3.sub {
  font-size: 13px; margin-top: 18px; margin-bottom: 2px;
  color: var(--text); font-weight: 600;
}
.proxy-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.proxy-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 11px;
  font-size: 13px;
}
.proxy-item .btn-danger { padding: 3px 9px; font-size: 12px; }

/* --- Sammel-Import --- */
.bulk-list { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.bulk-item {
  display: grid;
  grid-template-columns: 1fr 130px minmax(60px, auto);
  gap: 8px;
  align-items: center;
}
.bulk-mail {
  font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bulk-item .select { padding: 4px 7px; font-size: 12px; }
.bulk-status { font-size: 11px; color: var(--muted); }
.bulk-status.ok { color: var(--ok); }
.bulk-status.bad { color: var(--danger); }

/* --- Tag-Farb-Auswahl --- */
.color-swatches { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 6px; }
.swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.swatch.selected { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg-2); }

/* --- Aktiv/Archiv-Umschalter --- */
.seg-toggle {
  display: flex;
  gap: 4px;
  padding: 4px 10px 10px;
}
.seg-btn {
  flex: 1;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  transition: background .12s, border-color .12s, color .12s;
}
.seg-btn:hover { border-color: var(--accent); color: var(--text); }
.seg-btn.active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}
.seg-count {
  background: rgba(255, 255, 255, 0.10);
  border-radius: 9px;
  padding: 1px 7px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.seg-btn:not(.active) .seg-count {
  background: var(--bg-3);
  color: var(--muted);
}

/* --- Formular-Feinschliff --- */
.modal-box textarea { resize: vertical; min-height: 80px; }
/* Selects im Dialog: volle Breite + gleiche Hoehe wie Inputs */
.modal-box .select { width: 100%; padding: 8px 10px; margin-top: 5px; }
/* Ausnahme: kompakte Selects in der Import-Vorschau */
.modal-box .bulk-item .select { margin-top: 0; padding: 4px 7px; }
.modal-box input[type="checkbox"] {
  width: 15px; height: 15px;
  accent-color: var(--accent);
  margin: 0; flex: 0 0 auto; cursor: pointer;
}
.modal-box code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg); border-radius: 4px; padding: 1px 5px; font-size: 11px;
}
/* Labels im 2-Spalten-Grid ohne Extra-Abstand (Gap reicht) */
.grid2 label { margin-top: 0; }
.at-sub { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.tag-list { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }

/* Anklickbare Tag-Auswahl (Konto-Tags) */
.tag-pick { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.tag-chip.pick {
  cursor: pointer; font-family: inherit; font-size: 13px;
  padding: 6px 13px; line-height: 1;
}
.tag-chip.pick:hover { filter: brightness(1.12); }

/* --- Scrollbars --- */
::-webkit-scrollbar { width: 9px; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
