:root {
  --bg: #F3F5F7; --karte: #FFFFFF; --text: #16202B; --leise: #5B6673; --linie: #E2E6EA; --linie-zart: #EDF0F3;
  --akzent: #0B5C6B; --akzent-text: #FFFFFF; --akzent-hell: #E3EFF1; --flaeche: #F6F8FA;
  --rot: #9F1D14; --rot-bg: #FDECEA; --orange: #7A4300; --orange-bg: #FFF1DC; --blau: #284F78; --blau-bg: #E8F0F7;
  --gut: #1E7A3C;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11181F; --karte: #19222C; --text: #E8EDF2; --leise: #9EABB7; --linie: #2C3844; --linie-zart: #24303B;
    --akzent: #6FC0CE; --akzent-text: #0A2A31; --akzent-hell: #17343A; --flaeche: #1F2A35;
    --rot: #F4A898; --rot-bg: #3A1A15; --orange: #F0B680; --orange-bg: #3A2614; --blau: #A9C6E8; --blau-bg: #1C2B3D;
    --gut: #7FD39A;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.ohne-admin .nur-admin { display: none !important; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px; line-height: 1.45;
}
[hidden] { display: none !important; }
h1 { margin: 0; font-size: 26px; line-height: 1.2; }
h2 { margin: 0; font-size: 18px; }
p { margin: 0; }
a { color: var(--akzent); }
.leise { color: var(--leise); }
.hinweis { color: var(--leise); font-size: 13px; }
.unsichtbar { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

button { font: inherit; cursor: pointer; border-radius: 8px; min-height: 44px; padding: 0 16px; color: inherit; }
button:disabled { opacity: .6; cursor: progress; }
.haupt { background: var(--akzent); color: var(--akzent-text); border: 0; font-weight: 600; }
.zweit { background: transparent; color: var(--akzent); border: 1.5px solid var(--akzent); font-weight: 600; align-self: flex-start; }
.text { background: transparent; border: 0; color: var(--leise); text-decoration: underline; align-self: flex-start; }
.text.gefahr { color: var(--rot); }
:focus-visible { outline: 3px solid var(--akzent); outline-offset: 2px; }

.feld { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--leise); text-align: left; max-width: 420px; }
input {
  min-height: 44px; padding: 8px 12px; font: inherit; font-size: 15px; color: var(--text);
  background: var(--karte); border: 1px solid var(--linie); border-radius: 8px;
}

/* ---------- Anmelden ---------- */
.mitte {
  min-height: 100vh; max-width: 420px; margin: 0 auto; padding: 24px 16px;
  display: flex; flex-direction: column; justify-content: center; gap: 14px; text-align: center;
}
.mitte .haupt { min-height: 50px; font-size: 16px; }
.logo-gross { width: 84px; height: 84px; align-self: center; }

/* ---------- Rahmen: Seitenleiste + Inhalt ---------- */
.rahmen { display: flex; min-height: 100vh; }
.seitenleiste {
  width: 248px; flex: none; background: var(--karte); border-right: 1px solid var(--linie);
  padding: 24px 14px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh;
}
.marke { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; }
.marke div { display: flex; flex-direction: column; }
.marke strong { font-size: 15px; }
.marke span { font-size: 12px; color: var(--leise); }
.nav { display: block; padding: 10px 12px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: 14px; }
.nav:hover { background: var(--flaeche); }
.nav.aktiv { background: var(--akzent-hell); color: var(--akzent); font-weight: 600; }
.nav.bald { color: var(--leise); }
.fueller { flex: 1; }

.inhalt { flex: 1; min-width: 0; padding: 28px 36px 48px; max-width: 1180px; }
.inhalt > div { display: flex; flex-direction: column; gap: 20px; }

.kopf { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; }
.kopf-werkzeuge input { width: 260px; }

.kacheln { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kachel {
  background: var(--karte); border: 1px solid var(--linie); border-radius: 12px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.kachel span, .kachel small { color: var(--leise); }
.kachel span { font-size: 13px; }
.kachel small { font-size: 12px; }
.kachel strong { font-size: 26px; font-variant-numeric: tabular-nums; }
.rot { color: var(--rot); }
.orange { color: var(--orange); }

.spalten { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.breit-spalte { flex: 999 1 460px; min-width: 0; }
.seitenspalte { flex: 1 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.karte {
  background: var(--karte); border: 1px solid var(--linie); border-radius: 12px; padding: 18px 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.karte-kopf { display: flex; align-items: baseline; justify-content: space-between; }

.erledigen-zeile { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 8px; background: var(--flaeche); color: var(--text); text-decoration: none; }
.erledigen-zeile:hover { background: var(--akzent-hell); }
.erledigen-zeile .zaehler { min-width: 28px; height: 28px; border-radius: 999px; background: var(--akzent); color: var(--akzent-text); font-weight: 700; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; }
.leer { padding: 18px 12px; border: 1px dashed var(--linie); border-radius: 10px; color: var(--leise); text-align: center; font-size: 14px; }

.termin { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 14px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--linie-zart); border-radius: 10px; }
.termin .datum { font-weight: 700; font-variant-numeric: tabular-nums; }
.termin .ort { color: var(--leise); font-size: 13px; }
.chip { display: inline-flex; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip.ueberfaellig { background: var(--rot-bg); color: var(--rot); }
.chip.woche { background: var(--orange-bg); color: var(--orange); }
.chip.spaeter { background: var(--blau-bg); color: var(--blau); }

.schritte { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; }
.schritte li.fertig { color: var(--gut); }
.schritte li.fertig::marker { content: "✓  "; }

.liste { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.liste li { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; background: var(--flaeche); border-radius: 8px; }
.liste small { display: block; color: var(--leise); font-size: 12px; }
.link-box { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--flaeche); border-radius: 8px; }
.link-box img { width: 180px; height: 180px; background: #fff; border-radius: 8px; }
.link-box code { word-break: break-all; font-size: 13px; }


/* ---------- Objekte ---------- */
.knopfreihe { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.schalter { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--leise); min-height: 44px; cursor: pointer; }
.schalter input { min-height: 0; width: 18px; height: 18px; }
.stapel { display: flex; flex-direction: column; gap: 22px; }
.mandant-block { display: flex; flex-direction: column; gap: 12px; }
.mandant-kopf { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px;
  padding-bottom: 8px; border-bottom: 1px solid var(--linie); }
.mandant-kopf h2 { font-size: 17px; }
.mandant-kopf .leise { font-size: 13px; }
.mandant-kopf .text { min-height: 36px; padding: 0 4px; font-size: 14px; }
.objekt-raster { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.objekt-karte {
  display: flex; flex-direction: column; gap: 6px; padding: 16px 18px; background: var(--karte);
  border: 1px solid var(--linie); border-radius: 12px; color: var(--text); text-decoration: none;
}
.objekt-karte:hover { border-color: var(--akzent); }
.objekt-karte strong { font-size: 16px; }
.objekt-karte .art { font-size: 12px; font-weight: 600; color: var(--akzent); text-transform: uppercase; letter-spacing: .04em; }
.objekt-karte .zahlen { font-size: 13px; color: var(--leise); margin-top: 4px; }
.objekt-karte.archiviert { opacity: .6; }
.marke-klein { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--flaeche); color: var(--leise); }

.zurueck { align-self: flex-start; text-decoration: none; font-size: 14px; min-height: 32px; display: inline-flex; align-items: center; }
.hinweis-band { padding: 10px 14px; border-radius: 8px; background: var(--orange-bg); color: var(--orange); font-size: 14px; }
.hinweis-band .text { color: inherit; min-height: 0; padding: 0 4px; }

.tabelle-box { overflow-x: auto; margin: 0 -4px; }
.tabelle { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabelle th { text-align: left; font-size: 12px; font-weight: 600; color: var(--leise); padding: 8px 10px; border-bottom: 1px solid var(--linie); white-space: nowrap; }
.tabelle td { padding: 10px; border-bottom: 1px solid var(--linie-zart); vertical-align: middle; }
.tabelle .zahl { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tabelle tfoot td { font-weight: 600; border-bottom: 0; }
.tabelle .text { min-height: 36px; padding: 0 4px; font-size: 14px; }
.tabelle tr.archiviert td { color: var(--leise); }

.angaben { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 8px 20px; margin: 0; font-size: 14px; }
.angaben dt { color: var(--leise); }
.angaben dd { margin: 0; white-space: pre-line; }
.seitenspalte-karte { flex: 1 1 300px; min-width: 0; }
.verlauf { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; font-size: 13px; max-height: 420px; overflow-y: auto; }
.verlauf li { padding-left: 12px; border-left: 2px solid var(--linie); }
.verlauf small { display: block; color: var(--leise); }
.verlauf ul { margin: 4px 0 0; padding-left: 16px; color: var(--leise); }

/* ---------- Verträge ---------- */
.stapel-eng { display: flex; flex-direction: column; gap: 10px; }
.stapel-eng:empty { display: none; }
.stapel-karten { display: flex; flex-direction: column; gap: 20px; }
.chip.aktiv { background: #E3F4E8; color: var(--gut); }
.chip.gekuendigt { background: var(--orange-bg); color: var(--orange); }
.chip.kuenftig { background: var(--blau-bg); color: var(--blau); }
.chip.beendet, .chip.leer { background: var(--flaeche); color: var(--leise); }
@media (prefers-color-scheme: dark) { .chip.aktiv { background: #173523; } }
.tabelle a { color: var(--text); font-weight: 600; text-decoration: none; }
.tabelle a:hover { color: var(--akzent); text-decoration: underline; }
.tabelle .leise-zelle { color: var(--leise); }
.mieter-karte { padding: 12px 14px; background: var(--flaeche); border-radius: 10px; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.mieter-karte strong { font-size: 15px; }
.mieter-karte .text { align-self: flex-start; min-height: 32px; padding: 0; font-size: 13px; }
.liste .text { min-height: 32px; padding: 0 4px; font-size: 13px; }

/* ---------- Dokumente ---------- */
.auswahl-klein { min-height: 44px; padding: 0 12px; font: inherit; font-size: 14px; color: var(--text); background: var(--karte); border: 1px solid var(--linie); border-radius: 8px; }
.ablagezone { border: 2px dashed var(--linie); border-radius: 12px; padding: 22px; text-align: center; display: flex; flex-direction: column; gap: 4px; background: var(--karte); }
.ablagezone.aktiv { border-color: var(--akzent); background: var(--akzent-hell); }
.knopf-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 8px; text-decoration: none; }
.chip.wartet, .chip.laeuft { background: var(--blau-bg); color: var(--blau); }
.chip.fertig { background: #E3F4E8; color: var(--gut); }
.chip.fehler, .chip.offen { background: var(--orange-bg); color: var(--orange); }
@media (prefers-color-scheme: dark) { .chip.fertig { background: #173523; } }
.dokument-raster { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.dokument-seiten { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; padding-right: 4px; }
.dokument-seiten img { width: 100%; border-radius: 8px; border: 1px solid var(--linie); background: #fff; scroll-margin-top: 8px; }
.dokument-seiten img.markiert { outline: 3px solid var(--akzent); }
.dokument-seiten .seite-nr { font-size: 12px; color: var(--leise); }
.dokument-pruefung { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.dokument-pruefung .formular-raster { margin-top: 4px; }
.fund { font-size: 12px; color: var(--leise); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.fund.ok::before { content: "✓"; color: var(--gut); font-weight: 700; }
.fund.warn { color: var(--orange); }
.fund.warn::before { content: "⚠"; }
.fund button { min-height: 0; padding: 0; border: 0; background: none; color: var(--akzent); text-decoration: underline; font-size: 12px; }
.einheiten-wahl { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 4px; }
.erkannter-text { white-space: pre-wrap; font-size: 13px; max-height: 360px; overflow-y: auto; background: var(--flaeche); padding: 12px; border-radius: 8px; }
details summary { cursor: pointer; min-height: 32px; }

/* ---------- Formular-Dialog ---------- */
dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(640px, calc(100% - 24px)); max-height: calc(100vh - 32px);
  background: var(--karte); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(10, 20, 28, .45); }
dialog form { display: flex; flex-direction: column; gap: 14px; padding: 20px 22px; }
.dialog-kopf, .dialog-fuss { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-kopf .text { text-decoration: none; font-size: 18px; min-height: 40px; }
.dialog-fuss { justify-content: flex-end; padding-top: 4px; }
.formular-raster { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.formular-raster .feld { max-width: none; }
.formular-raster .abschnitt { grid-column: 1 / -1; margin: 10px 0 -2px; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--akzent); }
.formular-raster .abschnitt:first-child { margin-top: 0; }
.formular-raster .feld.breit { grid-column: 1 / -1; }
.formular-raster .feld.pflicht > span:first-child::after { content: " *"; color: var(--rot); }
.formular-raster select, .formular-raster textarea {
  min-height: 44px; padding: 8px 12px; font: inherit; font-size: 15px; color: var(--text);
  background: var(--karte); border: 1px solid var(--linie); border-radius: 8px;
}
.formular-raster textarea { min-height: 80px; resize: vertical; }
.feld .einheit-wrap { display: flex; align-items: center; gap: 8px; }
.feld .einheit-wrap input { flex: 1; min-width: 0; }
.feld .einheit-wrap span { color: var(--leise); font-size: 14px; }
.feld .hilfe { font-size: 12px; color: var(--leise); }
.feld-gruppe { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--leise); }
.feld-gruppe .schalter { color: var(--text); font-size: 15px; min-height: 36px; }
.fehler-text { color: var(--rot); font-size: 14px; }

/* ---------- Untere Leiste (Handy) ---------- */
.leiste { display: none; }

#meldung {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 10px; max-width: calc(100% - 32px);
}
#meldung.fehler { background: var(--rot-bg); color: var(--rot); border: 1px solid var(--rot); }

@media (max-width: 860px) {
  .seitenleiste { display: none; }
  .inhalt { padding: max(18px, env(safe-area-inset-top)) 16px calc(88px + env(safe-area-inset-bottom)); }
  h1 { font-size: 22px; }
  .kopf-werkzeuge, .kopf-werkzeuge input { width: 100%; }
  .kacheln { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .leiste {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0;
    background: var(--karte); border-top: 1px solid var(--linie); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .leiste a { min-height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--leise); text-decoration: none; font-size: 11px; }
  .leiste a.aktiv { color: var(--akzent); font-weight: 700; }
  .leiste svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  #meldung { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .kopf-werkzeuge.knopfreihe { width: 100%; }
  .formular-raster { grid-template-columns: minmax(0, 1fr); }
  dialog { width: 100%; max-width: none; max-height: 100%; height: 100%; border-radius: 0; margin: 0; }
  dialog form { min-height: 100%; }
  .dialog-fuss { margin-top: auto; }
  .angaben { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .dokument-raster { grid-template-columns: minmax(0, 1fr); }
  .dokument-seiten { position: static; max-height: none; }
  .ablagezone { display: none; }
  .angaben dd { margin-bottom: 8px; }
  /* Tabellen mit .karten-mobil werden am Handy zu einer Liste von Karten */
  .karten-mobil thead { display: none; }
  .karten-mobil, .karten-mobil tbody, .karten-mobil tfoot, .karten-mobil tr, .karten-mobil td { display: block; width: 100%; }
  .karten-mobil tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 12px 4px; border-bottom: 1px solid var(--linie-zart); }
  .karten-mobil td { padding: 0; border: 0; text-align: left !important; }
  .karten-mobil td[data-rolle="titel"] { font-weight: 600; grid-column: 1; grid-row: 1; }
  .karten-mobil td[data-rolle="rechts"] { grid-column: 2; grid-row: 1; text-align: right !important; }
  .karten-mobil td[data-rolle="info"] { color: var(--leise); font-size: 13px; grid-column: 1 / -1; }
  .karten-mobil td[data-rolle="info"]:empty { display: none; }
  .karten-mobil td[data-vor]:not(:empty)::before { content: attr(data-vor) ": "; }
  .karten-mobil td[data-rolle="aktion"] { grid-column: 1 / -1; }
  .karten-mobil tfoot td { padding: 12px 4px 0; }
}
