:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a1d24;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar h1 {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 24px 8px;
  color: var(--text);
}

.sidebar a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}

.sidebar a:hover { background: var(--bg); color: var(--text); }
.sidebar a.active { background: #eef2ff; color: var(--primary); }

.main {
  flex: 1;
  padding: 32px 40px;
  max-width: 1100px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h2 { margin: 0; font-size: 22px; }
.page-header p { margin: 4px 0 0; color: var(--text-muted); font-size: 14px; }

button, .btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}

button:hover, .btn:hover { background: var(--bg); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-danger { color: var(--danger); }

.btn-danger-solid {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}
.btn-danger-solid:hover { background: var(--danger); filter: brightness(0.92); }

input, textarea, select {
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  background: var(--surface);
  color: var(--text);
}

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}

.field { margin-bottom: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.customer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.customer-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  text-decoration: none;
  color: inherit;
  display: block;
}

.fav-star {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 2px;
  color: var(--text-muted);
}
.fav-star:hover { color: #f5a623; }
.fav-star.active { color: #f5a623; }

.fav-star-lg {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  padding: 4px;
  color: var(--text-muted);
}
.fav-star-lg:hover { color: #f5a623; }
.fav-star-lg.active { color: #f5a623; }

.filter-toggle.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.customer-card:hover { border-color: var(--primary); }

.customer-card h3 { margin: 0 0 4px; font-size: 16px; padding-right: 28px; }
.customer-card .email { color: var(--text-muted); font-size: 13px; margin-bottom: 10px; }
.customer-card .summary { font-size: 13px; color: var(--text); line-height: 1.5; }
.customer-card .meta { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
}

.badge.positive { background: #dcfce7; color: var(--success); }
.badge.negative { background: #fee2e2; color: var(--danger); }
.badge.urgent { background: #fef3c7; color: var(--warning); }
.badge.neutral { background: #e5e7eb; color: var(--text-muted); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: white;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 100;
  max-width: 360px;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

.account-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.account-row:last-child { border-bottom: none; }

.account-row .info { display: flex; flex-direction: column; gap: 2px; }
.account-row .info .label { font-weight: 600; }
.account-row .info .meta { font-size: 12px; color: var(--text-muted); }
.account-row .actions { display: flex; gap: 8px; }

.provider-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--primary);
}

.section { margin-bottom: 32px; }
.section h3 { font-size: 15px; margin: 0 0 12px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }

@media (max-width: 640px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    gap: 12px;
  }
  .sidebar h1 { margin: 0; }
  .main { padding: 20px; max-width: 100%; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

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

.email-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.email-item .row1 {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.email-item .subject { font-weight: 600; margin-bottom: 6px; }
.email-item .body { font-size: 13px; color: var(--text); white-space: pre-wrap; line-height: 1.5; max-height: 160px; overflow-y: auto; }
.email-item.outgoing { border-left: 3px solid var(--primary); }
.email-item.incoming { border-left: 3px solid var(--success); }
.email-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  margin-left: 6px;
  vertical-align: middle;
}
.email-delete-btn:hover { color: var(--danger); }

.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
button.btn-primary .spinner { border-color: rgba(255,255,255,0.4); border-top-color: white; }
button:not(.btn-primary) .spinner { border-color: rgba(0,0,0,0.15); border-top-color: var(--text); }

@keyframes spin { to { transform: rotate(360deg); } }

.back-link {
  display: inline-block;
  margin-bottom: 16px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
}
.back-link:hover { color: var(--text); }

.help-text { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* --- Login ---------------------------------------------------------------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }

/* --- Sidebar-Benutzerbox --------------------------------------------------- */
.sidebar-user {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.sidebar-user .su-name { font-size: 14px; font-weight: 600; color: var(--text); }
.sidebar-user .su-role { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.sidebar-user .su-logout {
  width: 100%;
  font-size: 13px;
  padding: 8px;
}

/* --- Auto-Sync-Steuerung im Postfach --------------------------------------- */
.autosync {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-muted);
}
.autosync .interval-input { width: 72px; padding: 6px 8px; }
.autosync input[disabled] { opacity: 0.5; }

/* Einfacher Toggle-Switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border); border-radius: 24px; transition: 0.2s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px;
  background: white; border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* Tabelle Benutzerverwaltung */
.user-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.user-table th, .user-table td {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px;
}
.user-table th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.role-tag {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: #eef2ff; color: var(--primary); font-weight: 600;
}
.role-tag.mitarbeiter { background: var(--bg); color: var(--text-muted); }
