:root {
  --bg: #f4f6f8;
  --flaeche: #fff;
  --rand: #dde3ea;
  --text: #16202b;
  --gedaempft: #64748b;
  --akzent: #10618f;
  --akzent-hell: #e7f1f8;
  --gruen: #157347;
  --rot: #b02a37;
  --gelb: #a16207;
  --radius: 10px;
  --schatten: 0 1px 2px rgba(16, 32, 43, .06), 0 4px 12px rgba(16, 32, 43, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--akzent); }

/* ------------------------------------------------------------------ Rahmen */

header.kopf {
  background: var(--flaeche);
  border-bottom: 1px solid var(--rand);
  position: sticky; top: 0; z-index: 1000;   /* über Leaflets Kartenebenen (max. 800) */
}
.kopf-innen {
  max-width: 1500px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 24px; min-height: 58px;
}
.marke { font-weight: 700; font-size: 16px; white-space: nowrap; }
.marke span { color: var(--gedaempft); font-weight: 400; font-size: 13px; margin-left: 6px; }
nav.reiter { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
nav.reiter button {
  border: 0; background: none; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  font: inherit; color: var(--gedaempft); white-space: nowrap;
}
nav.reiter button:hover { background: var(--bg); color: var(--text); }
nav.reiter button.an { background: var(--akzent-hell); color: var(--akzent); font-weight: 600; }
.kopf-benutzer { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--gedaempft); }

main { max-width: 1500px; margin: 0 auto; padding: 20px; }

/* ------------------------------------------------------------- Bausteine */

.karte {
  background: var(--flaeche); border: 1px solid var(--rand);
  border-radius: var(--radius); box-shadow: var(--schatten);
}
.karte + .karte { margin-top: 16px; }
.karte > h2, .karte > h3 {
  margin: 0; padding: 14px 18px; border-bottom: 1px solid var(--rand);
  font-size: 15px; font-weight: 600;
}
.karte-inhalt { padding: 18px; }

button, .knopf {
  font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--rand);
  background: var(--flaeche); color: var(--text); cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled) { border-color: #b9c4d0; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primaer { background: var(--akzent); border-color: var(--akzent); color: #fff; font-weight: 600; }
button.primaer:hover:not(:disabled) { background: #0d4e73; }
button.gefahr { color: var(--rot); border-color: #f0c8cc; }
button.klein { padding: 4px 10px; font-size: 13px; }
button.blank { border: 0; background: none; padding: 4px; color: var(--gedaempft); }
button.blank:hover { color: var(--text); }

input, select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--rand); border-radius: 8px;
  background: var(--flaeche); color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--akzent-hell); border-color: var(--akzent); }
textarea { resize: vertical; min-height: 90px; font-family: inherit; }
label { display: block; font-size: 13px; color: var(--gedaempft); margin-bottom: 4px; }
.feld { margin-bottom: 12px; }
.feld-reihe { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--gedaempft); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--rand);
  /* top: 0 – der Kopf klebt am Rand des waagerechten Scroll-Behälters,
     nicht am Viewport; mit 58px rutschte er über die erste Zeile. */
  position: sticky; top: 0; background: var(--flaeche); z-index: 5;
}
td { padding: 10px 12px; border-bottom: 1px solid #eef2f6; vertical-align: top; }
tbody tr:hover { background: #fafbfc; cursor: pointer; }
.tabelle-rahmen { overflow-x: auto; }

.plakette {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.st-neu           { background: #eef2f6; color: #475569; }
.st-recherche     { background: #fef3c7; color: #92400e; }
.st-kontaktiert   { background: #dbeafe; color: #1e40af; }
.st-im_gespraech  { background: #e0e7ff; color: #3730a3; }
.st-demo          { background: #ede9fe; color: #5b21b6; }
.st-angebot       { background: #fed7aa; color: #9a3412; }
.st-gewonnen      { background: #d1fae5; color: #065f46; }
.st-verloren      { background: #fee2e2; color: #991b1b; }
.st-kein_bedarf   { background: #f1f5f9; color: #64748b; }

.gedaempft { color: var(--gedaempft); }
.klein { font-size: 13px; }
.rechts { text-align: right; }
.zeile { display: flex; align-items: center; gap: 10px; }
.zeile-um { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.abstand { flex: 1; }

/* ----------------------------------------------------------- Kennzahlen */

.kennzahlen { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kennzahl {
  background: var(--flaeche); border: 1px solid var(--rand); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--schatten);
}
.kennzahl .wert { font-size: 26px; font-weight: 700; line-height: 1.1; }
.kennzahl .bez { font-size: 12px; color: var(--gedaempft); text-transform: uppercase; letter-spacing: .04em; margin-top: 4px; }
.kennzahl.warn .wert { color: var(--gelb); }
.kennzahl.gut .wert { color: var(--gruen); }

/* ------------------------------------------------------------- Detailblatt */

.blatt-hg {
  position: fixed; inset: 0; background: rgba(16, 32, 43, .45); z-index: 2000;
  display: flex; justify-content: flex-end;
}
.blatt {
  background: var(--bg); width: min(920px, 100%); height: 100%; overflow-y: auto;
  box-shadow: -8px 0 32px rgba(0, 0, 0, .18);
}
.blatt-kopf {
  background: var(--flaeche); border-bottom: 1px solid var(--rand);
  padding: 16px 20px; position: sticky; top: 0; z-index: 10;
}
.blatt-kopf h2 { margin: 0 0 4px; font-size: 19px; }
.blatt-inhalt { padding: 20px; }
.zwei-spalten { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .zwei-spalten { grid-template-columns: 1fr; } }

.verlauf { list-style: none; margin: 0; padding: 0; }
.verlauf li { padding: 12px 0; border-bottom: 1px solid #eef2f6; display: flex; gap: 12px; }
.verlauf li:last-child { border-bottom: 0; }
.verlauf .symbol {
  width: 30px; height: 30px; border-radius: 8px; background: var(--akzent-hell);
  display: grid; place-items: center; flex-shrink: 0; font-size: 15px;
}
.verlauf .rumpf { flex: 1; min-width: 0; }
.verlauf .text { white-space: pre-wrap; margin-top: 3px; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- Crawler */

.balken { height: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.balken > div { height: 100%; background: var(--akzent); transition: width .4s ease; }
.log {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
  background: #0f1b25; color: #cfe3f2; padding: 12px 14px; border-radius: 8px;
  max-height: 170px; overflow-y: auto; white-space: pre-wrap;
}
.pillen { display: flex; gap: 8px; flex-wrap: wrap; }
.pillen label {
  display: inline-flex; align-items: center; gap: 6px; margin: 0;
  border: 1px solid var(--rand); border-radius: 999px; padding: 6px 12px;
  cursor: pointer; background: var(--flaeche); color: var(--text); font-size: 14px;
}
.pillen input { width: auto; }

/* ------------------------------------------------------------------ Login */

.login-seite { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-karte { width: min(400px, 100%); }

.hinweis { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; }
.hinweis.fehler { background: #fee2e2; color: #991b1b; }
.hinweis.ok { background: #d1fae5; color: #065f46; }
.hinweis.info { background: var(--akzent-hell); color: var(--akzent); }

.leer { text-align: center; padding: 40px 20px; color: var(--gedaempft); }

/* ------------------------------------------------------------------ Karte */

#landkarte { height: calc(100vh - 240px); min-height: 420px; border-radius: var(--radius); }
.leaflet-container { font: inherit; }
.leaflet-popup-content { margin: 12px 14px; line-height: 1.55; }
.leaflet-popup-content a { color: var(--akzent); }
