:root {
  --color-primary: #1d4ed8;
  --color-primary-dark: #1e3a8a;
  --color-bg: #f4f6f9;
  --color-card: #ffffff;
  --color-border: #e2e6ec;
  --color-text: #1f2430;
  --color-muted: #6b7280;
  --color-success-bg: #dcfce7;
  --color-success-text: #166534;
  --color-error-bg: #fee2e2;
  --color-error-text: #991b1b;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 1rem 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Topbar */
.topbar {
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.topbar .brand { font-weight: 700; color: var(--color-primary-dark); }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar .user-box { display: flex; align-items: center; gap: .75rem; font-size: .9rem; color: var(--color-muted); }
.topbar .user-name small { color: var(--color-muted); }

/* Login page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 10px 30px rgba(0,0,0,.06);
}
.login-box h1 { margin-top: 0; font-size: 1.3rem; text-align: center; }
.login-box .subtitle { text-align: center; color: var(--color-muted); margin-bottom: 1.5rem; font-size: .9rem; }

/* Forms */
label {
  display: block;
  margin-bottom: .9rem;
  font-size: .85rem;
  font-weight: 600;
  color: var(--color-muted);
}
input[type=text], input[type=email], input[type=password], select, textarea {
  display: block;
  width: 100%;
  margin-top: .3rem;
  padding: .55rem .7rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: .95rem;
  font-family: inherit;
  color: var(--color-text);
}
textarea { resize: vertical; }

.btn {
  display: inline-block;
  padding: .5rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: #fff;
  color: var(--color-text);
  cursor: pointer;
  font-size: .85rem;
}
.btn:hover { background: #f1f3f6; text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-small { padding: .3rem .6rem; font-size: .78rem; }
.btn-block { width: 100%; text-align: center; }

/* Alerts */
.alert { padding: .75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: .9rem; }
.alert-success { background: var(--color-success-bg); color: var(--color-success-text); }
.alert-error { background: var(--color-error-bg); color: var(--color-error-text); }

/* Stat cards */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: .75rem;
  margin: 1rem 0 1.5rem;
}
.stat-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .9rem;
  text-align: center;
}
.stat-number { font-size: 1.5rem; font-weight: 700; color: var(--color-primary-dark); }
.stat-label { font-size: .78rem; color: var(--color-muted); margin-top: .2rem; }

/* Filter bar */
.filter-bar { display: flex; align-items: flex-end; gap: 1rem; margin-bottom: 1rem; }
.filter-bar label { margin-bottom: 0; }
.filter-bar select { width: auto; }
.result-count { font-size: .85rem; color: var(--color-muted); padding-bottom: .55rem; }

/* Tables */
.lead-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}
.lead-table th, .lead-table td {
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  font-size: .85rem;
  vertical-align: top;
}
.lead-table th { background: #f8f9fb; color: var(--color-muted); font-weight: 600; }
.lead-table tr:last-child td { border-bottom: none; }
.lead-table small { color: var(--color-muted); }

/* Badges */
.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-new { background: #dbeafe; color: #1e40af; }
.badge-progress { background: #fef3c7; color: #92400e; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-muted { background: #e5e7eb; color: #374151; }

/* Detail page */
.back-link { display: inline-block; margin-bottom: .5rem; font-size: .9rem; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.kv-table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.kv-table th { text-align: left; color: var(--color-muted); font-weight: 600; width: 40%; padding: .3rem 0; vertical-align: top; font-size: .82rem; }
.kv-table td { padding: .3rem 0; font-size: .88rem; }
.message-box { white-space: pre-wrap; background: #f8f9fb; border: 1px solid var(--color-border); border-radius: 6px; padding: .8rem; font-size: .9rem; }
.muted { color: var(--color-muted); font-size: .85rem; }

.note-list { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
.note-list li { border-bottom: 1px solid var(--color-border); padding: .6rem 0; }
.note-list li:last-child { border-bottom: none; }
.note-meta { font-size: .78rem; color: var(--color-muted); margin-bottom: .2rem; }
.note-body { font-size: .88rem; white-space: pre-wrap; }

.inline-country-form { display: flex; align-items: center; gap: .4rem; }
.inline-country-form select { width: auto; min-width: 120px; }

/* Checkbox grid (Länder-Zuordnung) */
.checkbox-toolbar { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; }
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .4rem 1rem;
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: .85rem;
  background: #fbfcfd;
}
.checkbox-item {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-bottom: 0;
  font-weight: 400;
  font-size: .88rem;
  color: var(--color-text);
  cursor: pointer;
}
.checkbox-item input[type=checkbox] {
  width: auto;
  margin: 0;
}

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
}
