:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --border: #e2e4e8;
  --text: #1a1d21;
  --muted: #6b7280;
  --accent: #0f5da8;
  --accent-soft: #e8f1fa;
  --danger: #b42318;
  --unread: #0f5da8;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { background: #f0f2f5; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #0c4c8a; }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover { background: #e9ebef; color: var(--text); }
button.danger { color: var(--danger); }
button:disabled { opacity: 0.5; cursor: default; }

.hidden { display: none !important; }

/* ---------------------------------------------------------------- Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 16px; letter-spacing: 0.2px; }
.brand strong { color: var(--accent); }
.account { color: var(--muted); font-size: 12px; }
.topbar input[type="search"] {
  flex: 1;
  max-width: 420px;
  margin-left: auto;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: var(--bg);
}
.sync-status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sync-status.error { color: var(--danger); }

/* ---------------------------------------------------------------- Layout */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 210px 380px 1fr;
  min-height: 0;
}

/* Ordner */
.folders {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 10px 6px;
  overflow-y: auto;
}
.folder {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
}
.folder:hover { background: #eef0f3; }
.folder.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.folder .count {
  margin-left: auto;
  font-size: 11px;
  color: #fff;
  background: var(--accent);
  border-radius: 10px;
  padding: 1px 7px;
}
.folder.active .count { background: var(--accent); }

/* Mail-Liste */
.list-pane {
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.list-header {
  padding: 10px 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.message-list { flex: 1; overflow-y: auto; }
.msg-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.msg-item:hover { background: #f7f8fa; }
.msg-item.active { background: var(--accent-soft); }
.msg-item .row1 { display: flex; gap: 8px; align-items: baseline; }
.msg-item .from {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-item.unread .from, .msg-item.unread .subject { font-weight: 700; color: var(--unread); }
.msg-item .date { font-size: 11px; color: var(--muted); white-space: nowrap; }
.msg-item .subject {
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-item .snippet {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-item .badges { font-size: 11px; }
.more { margin: 8px auto; display: block; }
.list-empty { padding: 30px 14px; color: var(--muted); text-align: center; }

/* Lesebereich */
.reading-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}
.empty-state {
  margin: auto;
  text-align: center;
  color: var(--muted);
}
.empty-state .hint { max-width: 420px; font-size: 12px; }
.message-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 18px;
  gap: 8px;
}
.msg-toolbar { display: flex; gap: 8px; }
.msg-toolbar .spacer { flex: 1; }
.msg-subject { margin: 4px 0 0; font-size: 19px; }
.msg-meta { font-size: 12.5px; color: var(--text); line-height: 1.5; }
.meta-label { color: var(--muted); display: inline-block; min-width: 44px; }
.msg-attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.attachment {
  display: inline-block;
  padding: 4px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}
.attachment:hover { background: var(--accent-soft); }
.msg-images-bar {
  font-size: 12px;
  color: var(--muted);
  background: #fff8e6;
  border: 1px solid #f0e2b6;
  border-radius: 6px;
  padding: 6px 10px;
}
#msg-frame {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  width: 100%;
  min-height: 200px;
}
.msg-conversation { font-size: 12px; color: var(--muted); }
.msg-conversation .conv-item { padding: 3px 0; cursor: pointer; }
.msg-conversation .conv-item:hover { color: var(--accent); }

/* ---------------------------------------------------------------- KI (Phase 2) */
.list-header { display: flex; align-items: center; gap: 8px; }
.list-header select {
  margin-left: auto;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
  max-width: 150px;
}
.cat-chip {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 10px;
  white-space: nowrap;
  color: #fff;
  background: #8a919c;
}
.cat-orange { background: #e08600; }
.cat-blue { background: #2563ac; }
.cat-teal { background: #0e8074; }
.cat-purple { background: #7c4dbb; }
.cat-red { background: #c03a2e; }
.cat-slate { background: #5a6b81; }
.cat-grey { background: #8a919c; }
.msg-item .cat-chip { margin-right: 6px; }
.msg-ai-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.msg-summary { color: var(--muted); font-style: italic; flex: 1; }
.msg-ai-row select {
  font: inherit;
  font-size: 11.5px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 4px;
}
.draft-panel {
  border: 1px solid #f0d9ae;
  background: #fffaf0;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.draft-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.draft-head .spacer { flex: 1; }
.draft-lang { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 0 6px; }
.draft-panel textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  resize: vertical;
  background: #fff;
}
.draft-actions { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.draft-offer { padding: 2px 0; }

/* ---------------------------------------------------------------- Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 30, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--panel);
  border-radius: 10px;
  padding: 18px 20px;
  width: min(680px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.modal label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.modal input[type="text"], .modal textarea, .modal select {
  font: inherit;
  color: var(--text);
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.modal textarea { resize: vertical; }
.compose-note { font-size: 11.5px; color: var(--muted); }
.compose-row2 { display: flex; gap: 12px; }
.compose-row2 label { flex: 1; }
.draft-sig-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.draft-sig-label select {
  font: inherit;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  max-width: 190px;
}
.sig-manager {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fafbfc;
}
.sig-manager-head { display: flex; align-items: center; gap: 8px; }
.sig-manager-head select { flex: 1; font: inherit; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; }
.sig-fields { display: flex; gap: 10px; }
.sig-fields label { flex: 1; }
.sig-save-row { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.compose-error { color: var(--danger); font-size: 12.5px; margin-right: auto; }
.sig-preview-label { font-size: 12.5px; color: var(--muted); }
#s-sig-preview { border: 1px dashed var(--border); border-radius: 6px; height: 320px; background: #fff; }
.sig-preview-label button { padding: 2px 10px; font-size: 12px; }
.sig-preview-label button.active { background: var(--accent-soft); color: var(--accent); }

/* ---------------------------------------------------------------- Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1d21;
  color: #fff;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 100;
}
.toast.error { background: var(--danger); }

/* ---------------------------------------------------------------- Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 34px 30px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}
.login-card .brand { font-size: 20px; text-align: center; }
.login-card input {
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.login-card button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  padding: 9px;
}
.login-error { color: var(--danger); font-size: 12.5px; min-height: 16px; text-align: center; }
