/* JSC Mail App – Apple-Mail-artiges Design */
:root {
  --bg: #1c1c1e;
  --bg-secondary: #2c2c2e;
  --bg-tertiary: #3a3a3c;
  --bg-elevated: #242426;
  --text: #f5f5f7;
  --text-secondary: #98989d;
  --text-dim: #636366;
  --accent: #0a84ff;
  --red: #ff453a;
  --orange: #ff9f0a;
  --yellow: #ffd60a;
  --green: #30d158;
  --blue: #0a84ff;
  --purple: #bf5af2;
  --separator: rgba(84,84,88,0.35);
  /* Kategorie-Farben (bewusst anders als Flag-Farben) */
  --cat-kunde: #2ac3de;
  --cat-rechnung: #73daca;
  --cat-server-alert: #f7768e;
  --cat-geschaeftlich: #7aa2f7;
  --cat-persoenlich: #e0af68;
  --cat-newsletter: #449dab;
  --cat-spam: #565a6e;
  --cat-sonstiges: #787c99;
  --cat-bounces: #9d7cd8;
  --sidebar-width: 220px;
  --list-width: 360px;
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 0.2s cubic-bezier(0.25,0.1,0.25,1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

.hidden { display: none !important; }

/* ============ LOGIN ============ */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 100;
}
.login-box {
  width: 320px; padding: 40px 32px;
  background: var(--bg-secondary);
  border-radius: 16px;
  text-align: center;
}
.login-icon { font-size: 48px; margin-bottom: 12px; }
.login-box h1 {
  font-size: 22px; font-weight: 600;
  margin-bottom: 24px;
}
.login-box input {
  width: 100%; padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color var(--transition);
}
.login-box input:focus { border-color: var(--accent); }
.login-box button {
  width: 100%; padding: 12px;
  background: var(--accent);
  border: none; border-radius: var(--radius);
  color: #fff; font-size: 16px; font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition);
}
.login-box button:active { opacity: 0.7; }
.login-error {
  margin-top: 12px; padding: 8px;
  background: rgba(255,69,58,0.15);
  border-radius: var(--radius-sm);
  color: var(--red); font-size: 13px;
}

/* ============ APP LAYOUT ============ */
#app {
  display: flex;
  height: 100vh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ============ SIDEBAR ============ */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-elevated);
  border-right: 1px solid var(--separator);
  display: flex; flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 8px;
  position: sticky; top: 0;
  background: var(--bg-elevated);
  z-index: 2;
}
.sidebar-title {
  font-size: 13px; font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.btn-compose {
  width: 28px; height: 28px;
  background: var(--accent);
  border: none; border-radius: 50%;
  color: #fff; font-size: 16px; line-height: 28px;
  cursor: pointer;
  transition: transform var(--transition), opacity var(--transition);
}
.btn-compose:active { transform: scale(0.9); opacity: 0.7; }

#nav { padding: 4px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}
.nav-item:hover { background: rgba(255,255,255,0.06); }
.nav-item.active { background: rgba(10,132,255,0.2); }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0;
}
.nav-label {
  flex: 1; font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-count {
  font-size: 12px; color: var(--text-dim);
  min-width: 20px; text-align: right;
}
.nav-count:not(:empty) { color: var(--accent); font-weight: 600; }
.nav-divider { height: 1px; background: var(--separator); margin: 8px 12px; }
/* Aufklappbare Postfach-Listen */
.nav-collapse { padding: 0 4px; }
.nav-collapse-toggle {
  display: block; padding: 4px 12px;
  font-size: 11px; color: var(--text-dim);
  cursor: pointer; user-select: none;
  transition: color var(--transition);
}
.nav-collapse-toggle:hover { color: var(--text); }
.nav-sub-list { padding: 0; }
.nav-sub-list.hidden { display: none; }
.nav-sub-item {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 8px 3px 16px;
  font-size: 12px; color: var(--text-secondary);
  cursor: pointer; border-radius: 6px;
  transition: background var(--transition);
}
.nav-sub-item:hover { background: rgba(255,255,255,0.06); }
body.light .nav-sub-item:hover { background: rgba(0,0,0,0.04); }
.nav-sub-item.active { background: var(--accent); color: #fff; }
.nav-sub-item .sub-drag {
  cursor: grab; color: var(--text-dim); font-size: 10px;
  padding: 0 2px; flex-shrink: 0;
}
.nav-sub-item .sub-drag:active { cursor: grabbing; }
.nav-sub-item .sub-addr { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-sub-item .sub-count { flex-shrink: 0; font-size: 11px; margin-left: auto; }
.nav-sub-item .sub-count .count-unread { color: var(--accent); font-weight: 600; }
.nav-sub-item .sub-count .count-total { color: var(--text-dim); }
.nav-sub-item.dragging { opacity: 0.4; }
.nav-sub-item.drag-over { border-top: 2px solid var(--accent); }

.nav-section {
  font-size: 11px; font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 12px 4px;
}

/* Status-Bar */
.status-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--separator);
  font-size: 11px;
  flex-wrap: wrap;
}
.status-item {
  white-space: nowrap;
  cursor: pointer;
  color: var(--text-dim);
  padding: 2px 4px;
  border-radius: 3px;
  transition: background var(--transition);
}
.status-item:hover { background: rgba(255,255,255,0.06); }
body.light .status-item:hover { background: rgba(0,0,0,0.04); }
.status-ok { color: #30d158; }
.status-warning { color: #ff9f0a; }
.status-error { color: #ff453a; font-weight: 600; }
@keyframes status-blink { 0%,100% { opacity:1; } 50% { opacity:0.5; } }
.status-error { animation: status-blink 2s infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.cat-spinner { display: inline-block; animation: spin 1s linear infinite; }
/* Status Popup */
.status-popup-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.status-popup {
  background: var(--bg-secondary); border: 1px solid var(--separator);
  border-radius: 10px; padding: 16px 20px;
  min-width: 280px; max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
body.light .status-popup { background: #fff; box-shadow: 0 8px 32px rgba(0,0,0,0.15); }
.status-popup-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; font-size: 15px; font-weight: 600;
}
.status-popup-x {
  background: none; border: none; color: var(--text-dim);
  font-size: 20px; cursor: pointer;
}
.status-popup-x:hover { color: var(--text); }
.status-popup-row { font-size: 13px; color: var(--text); margin-bottom: 6px; }
.status-popup-bar-bg {
  height: 8px; background: var(--bg-tertiary);
  border-radius: 4px; overflow: hidden; margin: 10px 0 4px;
}
.status-popup-bar { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.5s; }
.status-popup-pct { font-size: 12px; color: var(--text-dim); text-align: right; }

/* Sidebar Footer / Logout */
.sidebar-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--separator);
  margin-top: auto;
}
.btn-logout {
  width: 100%; padding: 8px 12px;
  background: none; border: none;
  color: var(--text-dim); font-size: 12px;
  cursor: pointer; border-radius: var(--radius-sm);
  text-align: left;
  transition: background var(--transition), color var(--transition);
}
.btn-logout:hover { background: rgba(255,69,58,0.15); color: var(--red); }
body.light .btn-logout:hover { background: rgba(255,69,58,0.1); }

/* ============ MAIL-LISTE ============ */
#mail-list-panel {
  width: var(--list-width);
  min-width: 280px;
  border-right: 1px solid var(--separator);
  display: flex; flex-direction: column;
  background: var(--bg);
}
.list-header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--separator);
  min-height: 48px;
}
.list-header h2 {
  font-size: 18px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.read-filter-group {
  display: flex; gap: 0; margin-left: 8px;
  border: 1px solid var(--separator); border-radius: 6px;
  overflow: hidden; flex-shrink: 0;
}
.read-filter {
  padding: 4px 12px; background: none; border: none;
  color: var(--text-secondary); font-size: 12px;
  cursor: pointer; transition: all var(--transition);
  border-right: 1px solid var(--separator);
}
.read-filter:last-child { border-right: none; }
.read-filter.active { background: var(--accent); color: #fff; }
.read-filter:not(.active):hover { background: rgba(255,255,255,0.06); }
body.light .read-filter:not(.active):hover { background: rgba(0,0,0,0.04); }
.list-count { font-size: 12px; color: var(--text-dim); margin-left: auto; white-space: nowrap; }
.count-unread { color: var(--accent); font-weight: 600; }
.count-total { color: var(--text-dim); font-weight: 400; }
.list-actions { display: flex; gap: 4px; }
.btn-icon {
  width: 32px; height: 32px;
  background: none; border: none;
  color: var(--accent);
  font-size: 18px; cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.btn-icon:hover { background: rgba(255,255,255,0.06); }
.btn-icon:active { opacity: 0.6; }
.btn-filter {
  padding: 4px 10px;
  background: none; border: 1px solid var(--separator);
  border-radius: 12px;
  color: var(--text-secondary); font-size: 11px;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-filter.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.mail-list {
  flex: 1; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Mail-Item */
.mail-item {
  display: flex; flex-direction: column;
  padding: 12px 16px;
  border-bottom: 1px solid var(--separator);
  cursor: pointer;
  transition: background 0.15s ease;
  position: relative;
  overflow: hidden;
}
.mail-item:active { background: rgba(255,255,255,0.04); }
.mail-item.active { background: rgba(10,132,255,0.15); }
.mail-item.unread .mi-sender { font-weight: 700; color: var(--text); }
.mail-item.unread .mi-subject { font-weight: 600; }
.mail-item.unread::before {
  content: '';
  position: absolute; left: 4px; top: 50%; transform: translateY(-50%);
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
}

.mi-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.mi-sender {
  font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; margin-right: 8px;
  color: var(--text-secondary);
}
.mi-date { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.mi-subject {
  font-size: 13px; font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 2px;
}
.mi-preview {
  font-size: 12px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mi-flag {
  width: 8px; height: 8px; border-radius: 50%;
  position: absolute; right: 16px; top: 14px;
}
.mi-category {
  display: inline-block;
  font-size: 10px; font-weight: 600;
  padding: 1px 6px; border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  margin-right: 6px;
}
.mi-attachment { font-size: 12px; color: var(--text-dim); }

/* Swipe-Actions */
.swipe-wrapper {
  position: relative;
  overflow: hidden;
}
.swipe-action {
  position: absolute; top: 0; bottom: 0;
  display: flex; align-items: center; justify-content: center;
  width: 80px; font-size: 20px;
  transition: opacity 0.2s;
}
.swipe-action-left {
  left: 0; background: var(--green);
}
.swipe-action-right {
  right: 0; background: var(--red);
}
.swipe-content {
  position: relative;
  background: var(--bg);
  transition: transform 0.25s cubic-bezier(0.25,0.1,0.25,1);
  z-index: 1;
}
.swipe-content.swiping { transition: none; }

/* ============ MAIL-DETAIL ============ */
#mail-detail-panel {
  flex: 1; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}
.mail-detail { padding: 0; }
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; color: var(--text-dim);
}
.empty-icon { font-size: 64px; margin-bottom: 16px; opacity: 0.3; }
.empty-state p { font-size: 16px; }

.detail-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--separator);
}
.detail-subject {
  font-size: 20px; font-weight: 700;
  margin-bottom: 12px; line-height: 1.3;
}
.detail-meta { display: flex; gap: 12px; align-items: flex-start; }
.detail-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.detail-from-info { flex: 1; min-width: 0; }
.detail-from-name { font-size: 15px; font-weight: 600; }
.detail-from-addr { font-size: 12px; color: var(--text-secondary); }
.detail-to { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.detail-date { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.detail-actions {
  display: flex; gap: 8px; padding: 12px 24px;
  border-bottom: 1px solid var(--separator);
}
.detail-actions .btn-action {
  padding: 6px 14px;
  background: var(--bg-tertiary);
  border: none; border-radius: var(--radius-sm);
  color: var(--text); font-size: 13px;
  cursor: pointer;
  transition: background var(--transition);
}
.detail-actions .btn-action:hover { background: rgba(255,255,255,0.12); }
.detail-actions .btn-action:active { opacity: 0.6; }

.detail-summary {
  padding: 12px 24px;
  background: rgba(10,132,255,0.08);
  border-bottom: 1px solid var(--separator);
  font-size: 13px; color: var(--text-secondary);
  line-height: 1.5;
}
.detail-summary strong { color: var(--accent); font-weight: 600; }

.detail-body {
  padding: 20px 24px;
  font-size: 14px; line-height: 1.7;
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.detail-body a { color: var(--accent); }
/* HTML-Mails: Original-Darstellung wie Apple Mail (heller Content-Bereich) */
.detail-body-html {
  background: #ffffff;
  color: #1a1a1a;
  padding: 16px;
  border-radius: var(--radius);
  margin: 0 -8px;
}
.detail-body-html a { color: #0066cc; }
.detail-body-html img { max-width: 100%; height: auto; }

/* Bilder laden Bar */
.detail-img-bar {
  padding: 8px 24px;
  background: rgba(255,159,10,0.1);
  border-bottom: 1px solid var(--separator);
}
.detail-img-bar .btn-action { font-size: 12px; }

/* Kopierbare E-Mail-Adressen */
.copyable-email {
  user-select: text; -webkit-user-select: text;
  cursor: pointer;
  border-bottom: 1px dotted var(--text-dim);
  transition: color 0.15s;
}
.copyable-email:hover { color: var(--accent); }
.copyable-email.copied { color: #30d158; border-bottom-color: #30d158; }

.detail-body-iframe {
  width: 100%;
  min-height: 100px;
}
.detail-body-iframe iframe {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  pointer-events: auto;
}
.detail-attachments {
  padding: 12px 24px;
  border-top: 1px solid var(--separator);
}
.detail-attachments h4 {
  font-size: 12px; color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.attachment-item {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 12px; color: var(--text);
  margin: 0 6px 6px 0;
  cursor: pointer;
  transition: background var(--transition);
}
.attachment-item:hover { background: rgba(255,255,255,0.1); }

/* Thread */
.thread-mail { border-top: 1px solid var(--separator); }
.thread-mail .detail-header { padding: 16px 24px 12px; }
.thread-toggle {
  font-size: 12px; color: var(--accent);
  cursor: pointer; padding: 8px 24px;
  background: none; border: none;
  text-align: left; width: 100%;
}

/* ============ COMPOSE MODAL ============ */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal-content {
  background: var(--bg-secondary);
  border-radius: 12px;
  width: 640px;
  min-width: 380px; min-height: 350px;
  max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.25s cubic-bezier(0.25,0.1,0.25,1);
  position: absolute;
  box-shadow: 0 12px 48px rgba(0,0,0,0.4);
}
.compose-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--separator);
  cursor: move; /* Drag-Handle */
  user-select: none;
}
.compose-header h3 { font-size: 16px; font-weight: 600; }
.btn-text {
  background: none; border: none;
  color: var(--accent); font-size: 14px;
  cursor: pointer;
}
.btn-primary {
  background: var(--accent); border: none;
  color: #fff; font-size: 14px; font-weight: 600;
  padding: 6px 16px; border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity var(--transition);
}
.btn-primary:active { opacity: 0.7; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.compose-fields {
  padding: 8px 16px;
  border-bottom: 1px solid var(--separator);
}
.field-row {
  display: flex; align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--separator);
}
.field-row:last-child { border-bottom: none; }
.field-row label {
  width: 55px; font-size: 13px;
  color: var(--text-secondary); flex-shrink: 0;
}
.field-row input, .field-row select {
  flex: 1; background: none; border: none;
  color: var(--text); font-size: 14px;
  outline: none; padding: 4px 0;
}
.field-row select { background: var(--bg-tertiary); border-radius: 4px; padding: 4px 8px; }
/* Attachment-Leiste im Compose */
.compose-attachments-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--separator);
  flex-wrap: wrap;
}
.btn-attach {
  padding: 4px 10px;
  background: var(--bg-tertiary); border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 12px;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}
.btn-attach:hover { background: rgba(255,255,255,0.1); }
body.light .btn-attach:hover { background: rgba(0,0,0,0.06); }
.compose-attachments-list {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.compose-attachment-item {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  font-size: 11px; color: var(--text-secondary);
}
.compose-attachment-remove {
  background: none; border: none;
  color: var(--red); font-size: 12px;
  cursor: pointer; padding: 0 2px;
  line-height: 1;
}
.compose-attachment-remove:hover { color: var(--text); }

/* Rich-Text Toolbar */
.compose-toolbar {
  display: flex; align-items: center; gap: 2px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--separator);
  flex-wrap: wrap;
  background: var(--bg-tertiary);
}
.ct-btn {
  width: 28px; height: 28px;
  background: none; border: 1px solid transparent;
  border-radius: 4px; color: var(--text);
  font-size: 13px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.ct-btn:hover { background: rgba(255,255,255,0.08); border-color: var(--separator); }
body.light .ct-btn:hover { background: rgba(0,0,0,0.06); }
.ct-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.ct-select {
  height: 28px; padding: 0 4px;
  background: var(--bg-secondary); border: 1px solid var(--separator);
  border-radius: 4px; color: var(--text); font-size: 11px;
  cursor: pointer;
}
.ct-color {
  width: 28px; height: 28px; padding: 0; border: 1px solid var(--separator);
  border-radius: 4px; cursor: pointer; background: none;
}
.ct-sep {
  width: 1px; height: 20px;
  background: var(--separator); margin: 0 4px;
}

/* Rich-Text Editor */
.compose-editor {
  flex: 1; min-height: 200px;
  padding: 16px;
  color: var(--text); font-size: 14px;
  line-height: 1.6; outline: none;
  font-family: Helvetica, Arial, sans-serif;
  overflow-y: auto;
}
.compose-editor:empty:before {
  content: attr(data-placeholder);
  color: var(--text-dim);
  pointer-events: none;
}
.compose-editor a { color: var(--accent); }
#compose-body-plain.hidden { display: none; }
.compose-content.drag-hover { outline: 2px dashed var(--accent); outline-offset: -4px; }

/* Resize-Handle unten rechts */
.compose-resize-handle {
  position: absolute; bottom: 0; right: 0;
  width: 18px; height: 18px;
  cursor: nwse-resize; z-index: 10;
  background: linear-gradient(135deg, transparent 50%, var(--text-dim) 50%, transparent 52%,
    transparent 62%, var(--text-dim) 62%, transparent 64%,
    transparent 74%, var(--text-dim) 74%, transparent 76%);
  opacity: 0.5;
  border-radius: 0 0 12px 0;
}
.compose-resize-handle:hover { opacity: 1; }

/* Inline-Bilder im Compose-Editor */
.inline-img-wrapper {
  margin: 8px 0; display: inline-block; max-width: 100%;
  border: 1px solid var(--separator); border-radius: 6px;
  overflow: hidden; background: var(--bg-tertiary);
}
.inline-img { display: block; height: auto; }
.inline-img-sizes {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px; font-size: 11px; color: var(--text-dim);
  background: var(--bg-tertiary); border-bottom: 1px solid var(--separator);
}
.img-size-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.img-size-info { font-size: 10px; color: var(--text-dim); }
.img-size-select {
  padding: 2px 4px; font-size: 11px;
  background: var(--bg-secondary); border: 1px solid var(--separator);
  border-radius: 4px; color: var(--text); cursor: pointer;
}

/* ============ SKELETON ============ */
.skeleton-list { padding: 8px 0; }
.skeleton-item {
  height: 72px; margin: 0 16px 8px;
  background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-tertiary) 50%, var(--bg-secondary) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ============ PAGINATION ============ */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 8px;
  border-top: 1px solid var(--separator);
}
.pagination button {
  padding: 4px 12px;
  background: var(--bg-tertiary); border: none;
  border-radius: var(--radius-sm);
  color: var(--text); font-size: 13px;
  cursor: pointer;
}
.pagination button:disabled { opacity: 0.3; cursor: default; }
.page-info { font-size: 12px; color: var(--text-dim); }

/* ============ TOAST ============ */
.toast {
  position: fixed; bottom: 40px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-tertiary);
  color: var(--text); font-size: 14px;
  padding: 10px 20px; border-radius: 20px;
  opacity: 0; transition: all 0.3s ease;
  z-index: 300;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ ANIMATIONS ============ */
@keyframes fadeIn { from{opacity:0} to{opacity:1} }
@keyframes slideUp { from{transform:translateY(20px);opacity:0} to{transform:translateY(0);opacity:1} }

/* ============ KEYBOARD SHORTCUTS HINT ============ */
.kbd-hint {
  position: fixed; bottom: 8px; right: 12px;
  font-size: 11px; color: var(--text-dim);
  opacity: 0.4;
}

/* ============ RESPONSIVE ============ */
.mobile-only { display: none; }

@media (max-width: 900px) {
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.25,0.1,0.25,1);
  }
  #sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    z-index: 49;
  }
  .mobile-only { display: flex; }
  #mail-list-panel { width: 100%; min-width: 0; border-right: none; }
  #mail-detail-panel {
    position: fixed; inset: 0;
    z-index: 40;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.25,0.1,0.25,1);
    background: var(--bg);
  }
  #mail-detail-panel.open { transform: translateX(0); }
  .detail-back {
    display: block; padding: 12px 16px;
    background: none; border: none; border-bottom: 1px solid var(--separator);
    color: var(--accent); font-size: 14px;
    cursor: pointer; width: 100%; text-align: left;
  }
}

@media (min-width: 901px) {
  .detail-back { display: none; }
}

/* ============ MOBILE TOOLBAR ============ */
.mobile-toolbar {
  display: none;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--separator);
  background: var(--bg-elevated);
  min-height: 44px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.mobile-toolbar .tb-separator {
  height: 20px;
  margin: 0 2px;
}
.mobile-toolbar .tb-btn {
  width: 34px; height: 34px;
  flex-shrink: 0;
}
.mobile-toolbar .tb-flag-picker { position: relative; }
.mobile-toolbar .tb-flag-dropdown {
  bottom: 100%;
  top: auto;
}
.mt-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--separator);
  background: var(--bg-elevated);
}
.mt-search-row.hidden { display: none; }
.mt-search-input {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.mt-search-input:focus { border-color: var(--accent); }

@media (max-width: 900px) {
  .mobile-toolbar { display: flex; }

  /* Compose-Modal: Fullscreen auf Mobile */
  .modal {
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
  }
  .modal-content {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0;
    position: fixed !important;
    top: 0 !important; left: 0 !important;
    right: 0 !important; bottom: 0 !important;
    animation: none;
  }
  .compose-header {
    cursor: default; /* Kein Drag auf Mobile */
  }
  .compose-resize-handle { display: none; }
  .compose-toolbar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
  }
  .compose-toolbar .ct-btn,
  .compose-toolbar .ct-select,
  .compose-toolbar .ct-color,
  .compose-toolbar .ct-sep {
    flex-shrink: 0;
  }
  .compose-editor {
    min-height: 120px;
  }
}

/* ============ TOOLBAR (Apple Mail Style) ============ */
.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--separator);
  background: var(--bg-elevated);
  min-height: 48px;
  flex-shrink: 0;
}
.tb-btn {
  width: 36px; height: 36px;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
  padding: 0;
}
.tb-btn svg { pointer-events: none; }
.tb-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.tb-btn:active { opacity: 0.6; }
.tb-btn:disabled { opacity: 0.2; cursor: default; }
.tb-btn:disabled:hover { background: none; color: var(--text-secondary); }
.tb-separator {
  width: 1px; height: 24px;
  background: var(--separator);
  margin: 0 4px;
  flex-shrink: 0;
}
.tb-spacer { flex: 1; }
.tb-selection-info {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  margin-right: 8px;
}
.tb-flag-picker { position: relative; }
.tb-flag-dropdown {
  position: absolute;
  top: 100%; right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  padding: 8px 10px;
  display: flex; gap: 6px;
  z-index: 100;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  animation: fadeIn 0.12s ease;
}
.tb-flag-dropdown .tb-flag-dot {
  width: 20px; height: 20px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--text-dim);
  transition: transform 0.15s;
}
.tb-flag-dropdown .tb-flag-dot:hover { transform: scale(1.3); border-color: rgba(255,255,255,0.3); }
.tb-flag-dropdown .tb-flag-dot[data-flag=""] {
  border: 1px solid var(--separator);
  font-size: 13px;
}

/* Toolbar-Suche (Lupe → Eingabefeld) */
.tb-search {
  display: flex; align-items: center;
  position: relative;
}
.tb-search-input {
  width: 0;
  padding: 0;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: width 0.25s cubic-bezier(0.25,0.1,0.25,1), padding 0.25s, opacity 0.2s;
  opacity: 0;
}
.tb-search-input.open {
  width: 200px;
  padding: 7px 12px;
  opacity: 1;
}
.tb-search-input::placeholder { color: var(--text-dim); }

/* Multi-Select */
.mail-item.multi-selected {
  background: rgba(10,132,255,0.2);
}
.mail-item.multi-selected::after {
  content: '\\2713';
  position: absolute;
  right: 6px; bottom: 6px;
  font-size: 12px; color: var(--accent);
  font-weight: 700;
}

/* ============ RESIZE HANDLES ============ */
.resize-handle {
  width: 5px;
  cursor: col-resize;
  background: transparent;
  position: relative;
  flex-shrink: 0;
  z-index: 5;
  transition: background 0.15s;
}
.resize-handle:hover,
.resize-handle.dragging {
  background: var(--accent);
}
.resize-handle::after {
  content: '';
  position: absolute; top: 0; bottom: 0;
  left: -3px; right: -3px;
}

/* ============ CONTEXT MENU ============ */
.context-menu {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  padding: 4px 0;
  min-width: 200px;
  z-index: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: fadeIn 0.12s ease;
  font-size: 13px;
}
.ctx-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 14px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.1s;
}
.ctx-item:hover { background: var(--accent); border-radius: 0; }
.ctx-item-icon { width: 18px; text-align: center; font-size: 14px; }
.ctx-separator {
  height: 1px;
  background: var(--separator);
  margin: 4px 0;
}
.ctx-section-label {
  padding: 6px 14px 2px;
  font-size: 11px; font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
}
.ctx-flags {
  display: flex; gap: 6px; align-items: center;
  padding: 6px 14px;
}
.ctx-flag-dot {
  width: 18px; height: 18px; border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
}
.ctx-flag-dot:hover { transform: scale(1.25); border-color: rgba(255,255,255,0.3); }
.ctx-flag-dot.active { border-color: var(--text); }
.ctx-flag-remove {
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: var(--text-dim);
  cursor: pointer;
  border-radius: 50%;
  border: 1px solid var(--separator);
}
.ctx-flag-remove:hover { color: var(--text); border-color: var(--text-dim); }
.ctx-submenu {
  position: relative;
}
.ctx-submenu-items {
  display: none;
  position: absolute;
  left: 100%; top: -4px;
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  padding: 4px 0;
  min-width: 160px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.ctx-submenu:hover .ctx-submenu-items { display: block; }
.ctx-item .ctx-arrow { margin-left: auto; color: var(--text-dim); font-size: 10px; }
.ctx-item.danger { color: var(--red); }
.ctx-item.danger:hover { background: var(--red); color: #fff; }

/* Kategorie-Badge Farben in Mail-Liste */
.mi-category[data-cat="Kunde"] { background: var(--cat-kunde); color: #000; }
.mi-category[data-cat="Rechnung"] { background: var(--cat-rechnung); color: #000; }
.mi-category[data-cat="Server-Alert"] { background: var(--cat-server-alert); color: #000; }
.mi-category[data-cat="Geschaeftlich"] { background: var(--cat-geschaeftlich); color: #000; }
.mi-category[data-cat="Persoenlich"] { background: var(--cat-persoenlich); color: #000; }
.mi-category[data-cat="Newsletter"] { background: var(--cat-newsletter); color: #000; }
.mi-category[data-cat="Spam"] { background: var(--cat-spam); color: var(--text); }
.mi-category[data-cat="spam"] { background: var(--cat-spam); color: var(--text); }
.mi-category[data-cat="Sonstiges"] { background: var(--cat-sonstiges); color: #000; }
.mi-category[data-cat="Bounces"] { background: var(--cat-bounces); color: #000; }

/* ============ MAIL-POPUP (Doppelklick) ============ */
.mail-popup {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 250;
  animation: fadeIn 0.15s ease;
}
.mail-popup-window {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 740px; height: 600px;
  min-width: 400px; min-height: 300px;
  background: var(--bg-secondary);
  border: 1px solid var(--separator);
  border-radius: 12px;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 16px 64px rgba(0,0,0,0.6);
  animation: slideUp 0.2s cubic-bezier(0.25,0.1,0.25,1);
}
.mail-popup-toolbar {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--separator);
  flex-shrink: 0;
  cursor: grab;
}
.mail-popup-toolbar.dragging { cursor: grabbing; }
.mail-popup-content {
  flex: 1; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-secondary);
}
/* Bessere Lesbarkeit im Popup */
.mail-popup-content .detail-header { background: var(--bg-secondary); }
.mail-popup-content .detail-subject { color: var(--text); }
.mail-popup-content .detail-from-name { color: var(--text); }
.mail-popup-content .detail-from-addr { color: var(--text-secondary); }
.mail-popup-content .detail-to { color: var(--text-dim); }
.mail-popup-content .detail-date { color: var(--text-secondary); }
.mail-popup-content .detail-body { color: var(--text); }
.mail-popup-content .detail-summary { background: rgba(10,132,255,0.1); }

/* Popup Resize-Handle */
.popup-resize-handle {
  position: absolute; bottom: 0; right: 0;
  width: 18px; height: 18px;
  cursor: nwse-resize; z-index: 10;
  background: linear-gradient(135deg, transparent 50%, var(--text-dim) 50%, transparent 52%,
    transparent 62%, var(--text-dim) 62%, transparent 64%,
    transparent 74%, var(--text-dim) 74%, transparent 76%);
  opacity: 0.5;
  border-radius: 0 0 12px 0;
}
.popup-resize-handle:hover { opacity: 1; }

/* ============ KI-LEISTE ============ */
.ai-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 60;
}
.ai-toggle {
  position: fixed;
  bottom: 12px; right: 16px;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  background: var(--accent);
  border: none; border-radius: 20px;
  color: #fff; font-size: 13px; font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(10,132,255,0.4);
  transition: transform 0.2s, opacity 0.2s;
  z-index: 61;
}
.ai-toggle:hover { transform: scale(1.05); }
.ai-toggle:active { opacity: 0.8; }
.ai-toggle svg { pointer-events: none; }
.ai-toggle.hidden { display: none; }
.ai-panel {
  position: relative;
  background: var(--bg-elevated);
  border-top: 1px solid var(--separator);
  padding: 12px 16px;
  display: flex; flex-direction: column; gap: 8px;
  animation: slideUp 0.2s ease;
}
.ai-input-row {
  display: flex; align-items: center; gap: 8px;
}
.ai-input {
  flex: 1; padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--separator);
  border-radius: 8px;
  color: var(--text); font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
.ai-input:focus { border-color: var(--accent); }
.ai-input::placeholder { color: var(--text-dim); }
.ai-send-btn {
  width: 36px; height: 36px;
  background: var(--accent);
  border: none; border-radius: 50%;
  color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.2s;
}
.ai-send-btn:hover { opacity: 0.85; }
.ai-close-btn {
  width: 32px; height: 32px;
  background: none; border: none;
  color: var(--red); font-size: 18px;
  cursor: pointer; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.ai-close-btn:hover { background: rgba(255,69,58,0.15); }
.ai-result {
  position: absolute;
  bottom: 100%;
  left: 16px; right: 16px;
  margin-bottom: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  box-shadow: 0 -8px 32px rgba(0,0,0,0.5);
  font-size: 13px; color: var(--text-secondary);
  line-height: 1.5;
  max-height: 50vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.2s ease;
}
.ai-result-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--separator);
  flex-shrink: 0;
}
.ai-result-header strong { color: var(--accent); font-size: 13px; }
.ai-result-close {
  background: none; border: none;
  color: var(--text-dim); font-size: 16px;
  cursor: pointer; padding: 2px 6px;
}
.ai-result-close:hover { color: var(--text); }
.ai-result-interpretation {
  padding: 10px 14px;
  color: var(--accent);
  font-weight: 500;
  border-bottom: 1px solid var(--separator);
  flex-shrink: 0;
}
.ai-result-count {
  padding: 6px 14px;
  font-size: 12px; color: var(--green);
  font-weight: 600;
  border-bottom: 1px solid var(--separator);
  flex-shrink: 0;
}
.ai-result-list {
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
.ai-result-item {
  display: flex; flex-direction: column;
  padding: 8px 14px;
  border-bottom: 1px solid var(--separator);
  cursor: pointer;
  transition: background 0.15s;
}
.ai-result-item:hover { background: rgba(255,255,255,0.06); }
.ai-result-item:last-child { border-bottom: none; }
.ai-result-item-subject {
  font-size: 13px; font-weight: 500;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ai-result-item-meta {
  font-size: 11px; color: var(--text-dim);
  margin-top: 2px;
}
.ai-result strong { color: var(--accent); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ============ LIGHT THEME ============ */
body.light {
  --bg: #ffffff;
  --bg-secondary: #f5f5f7;
  --bg-tertiary: #e8e8ed;
  --bg-elevated: #f0f0f5;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-dim: #8e8e93;
  --separator: rgba(60,60,67,0.18);
  --cat-kunde: #0891b2;
  --cat-rechnung: #059669;
  --cat-server-alert: #dc2626;
  --cat-geschaeftlich: #2563eb;
  --cat-persoenlich: #d97706;
  --cat-newsletter: #0d9488;
  --cat-spam: #6b7280;
  --cat-sonstiges: #6b7280;
  --cat-bounces: #7c3aed;
}
/* Light: hover/active States mit dunklen rgba statt hellen */
body.light .nav-item:hover { background: rgba(0,0,0,0.04); }
body.light .mail-item:active { background: rgba(0,0,0,0.03); }
body.light .tb-btn:hover { background: rgba(0,0,0,0.06); color: var(--text); }
body.light .tb-flag-dropdown .tb-flag-dot:hover { border-color: rgba(0,0,0,0.25); }
body.light .ctx-flag-dot:hover { border-color: rgba(0,0,0,0.25); }
body.light .btn-icon:hover { background: rgba(0,0,0,0.04); }
body.light .detail-actions .btn-action:hover { background: rgba(0,0,0,0.06); }
body.light .attachment-item:hover { background: rgba(0,0,0,0.05); }
body.light .ai-result-item:hover { background: rgba(0,0,0,0.04); }
body.light .resize-handle:hover,
body.light .resize-handle.dragging { background: var(--accent); }
/* Light: Shadows weicher */
body.light .tb-flag-dropdown { box-shadow: 0 6px 24px rgba(0,0,0,0.12); }
body.light .context-menu { box-shadow: 0 8px 32px rgba(0,0,0,0.12); }
body.light .ctx-submenu-items { box-shadow: 0 8px 32px rgba(0,0,0,0.12); }
body.light .mail-popup { background: rgba(0,0,0,0.2); }
body.light .mail-popup-window { box-shadow: 0 16px 64px rgba(0,0,0,0.15); }
body.light .ai-result { box-shadow: 0 -8px 32px rgba(0,0,0,0.1); }
body.light .ai-toggle { box-shadow: 0 4px 16px rgba(10,132,255,0.25); }
body.light .sidebar-overlay { background: rgba(0,0,0,0.2); }
/* Light: Kategorie-Badges heller Text auf dunklem Badge */
body.light .mi-category[data-cat="Kunde"] { color: #fff; }
body.light .mi-category[data-cat="Rechnung"] { color: #fff; }
body.light .mi-category[data-cat="Server-Alert"] { color: #fff; }
body.light .mi-category[data-cat="Geschaeftlich"] { color: #fff; }
body.light .mi-category[data-cat="Persoenlich"] { color: #fff; }
body.light .mi-category[data-cat="Newsletter"] { color: #fff; }
body.light .mi-category[data-cat="Sonstiges"] { color: #fff; }
body.light .mi-category[data-cat="Bounces"] { color: #fff; }
/* Light: Danger-Items */
body.light .ctx-item.danger:hover { color: #fff; }
/* Light: HTML-Mail-Body (bereits hell, kleinen Rahmen hinzufuegen) */
body.light .detail-body-html {
  background: #ffffff;
  border: 1px solid var(--separator);
}
/* Light: Scrollbar */
body.light ::-webkit-scrollbar-thumb { background: #c7c7cc; }
body.light ::-webkit-scrollbar-thumb:hover { background: #a1a1a6; }
/* Theme-Toggle Button */
.theme-toggle {
  width: 36px; height: 36px;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
  padding: 0;
  margin-left: -2px;
}
.theme-toggle:hover { background: rgba(255,255,255,0.08); color: var(--text); }
body.light .theme-toggle:hover { background: rgba(0,0,0,0.06); color: var(--text); }
