:root {
  color-scheme: light;
  --bg: #f3f4f1; --surface: #ffffff; --raised: #ffffff; --sunken: #eceee9;
  --ink: #171a18; --ink2: #4c534f; --muted: #7b827e; --line: #dde0db; --line2: #c6cbc4;
  --accent: #0f6b3a; --accent-ink: #ffffff; --accent-soft: #e2efe6; --accent-hover: #0b5a30;
  --good: #1d7a3e; --goodbg: #e3f1e7; --warn: #8a5a00; --warnbg: #f8eed5; --crit: #b3261e; --critbg: #fae3e1;
  --info: #2d62a8; --infobg: #e5edf8; --lila: #6b4aa8; --lilabg: #eee8f8; --orange: #a4520f; --orangebg: #fbeadb;
  --shadow: 0 10px 30px rgba(20, 24, 22, .16);
  --r: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #101312; --surface: #181c1a; --raised: #202522; --sunken: #0c0f0e;
    --ink: #eef1ef; --ink2: #b9c1bc; --muted: #87908b; --line: #2a302d; --line2: #3b433e;
    --accent: #3fae6c; --accent-ink: #06150c; --accent-soft: #16301f; --accent-hover: #52c07e;
    --good: #4cc27a; --goodbg: #15291c; --warn: #e0b04a; --warnbg: #2c2512; --crit: #f07a70; --critbg: #341a18;
    --info: #7aa7e8; --infobg: #172234; --lila: #b59ae8; --lilabg: #251d36; --orange: #eb9a55; --orangebg: #33220f;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); font-variant-numeric: tabular-nums; }
a { color: var(--accent); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 700; }
h3 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink2); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Kopf ---------- */
.kopf { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top, 0); }
.kopf-innen { max-width: 1320px; margin: 0 auto; display: flex; align-items: center; gap: 18px; padding: 0 16px; min-height: 52px; }
.marke { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); font-weight: 700; white-space: nowrap; }
.marke svg { width: 26px; height: 26px; flex: none; }
.marke span { font-size: 15px; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.nav::-webkit-scrollbar { display: none; }
.nav a { text-decoration: none; color: var(--ink2); padding: 7px 11px; border-radius: 6px; white-space: nowrap; font-weight: 500; }
.nav a:hover { background: var(--sunken); color: var(--ink); }
.nav a.aktiv { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.konto { position: relative; }
.konto > button { background: none; border: 1px solid var(--line); color: var(--ink); border-radius: 999px; padding: 5px 12px; font: inherit; cursor: pointer; white-space: nowrap; }
.menue { position: absolute; right: 0; top: calc(100% + 6px); background: var(--raised); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); min-width: 190px; padding: 5px; display: flex; flex-direction: column; z-index: 30; }
.menue a, .menue button { text-align: left; background: none; border: 0; font: inherit; color: var(--ink); padding: 8px 10px; border-radius: 5px; text-decoration: none; cursor: pointer; }
.menue a:hover, .menue button:hover { background: var(--sunken); }
@media (max-width: 720px) {
  .kopf-innen { flex-wrap: wrap; gap: 6px 10px; padding-bottom: 6px; }
  .nav { order: 3; flex-basis: 100%; }
  .konto { margin-left: auto; }
}

main { max-width: 1320px; margin: 0 auto; padding: 18px 16px calc(90px + env(safe-area-inset-bottom, 0)); display: flex; flex-direction: column; gap: 16px; }
.leiste { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.leiste .rechts { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.zurueck { color: var(--ink2); text-decoration: none; font-size: 14px; }
.zurueck:hover { color: var(--accent); }

/* ---------- Knöpfe und Eingaben ---------- */
.btn { font: inherit; font-weight: 600; font-size: 14px; border-radius: 7px; padding: 7px 13px; border: 1px solid var(--line2); background: var(--raised); color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap; line-height: 1.3; }
.btn:hover { background: var(--sunken); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primaer { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primaer:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.gefahr { color: var(--crit); }
.btn.klein { padding: 3px 8px; font-size: 13px; font-weight: 500; }
.btn.flach { border-color: transparent; background: none; }
.btn.flach:hover { background: var(--sunken); }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 5px; border-radius: 4px; font: inherit; font-size: 14px; line-height: 1; }
.icon-btn:hover { color: var(--ink); background: var(--sunken); }

input, select, textarea { font: inherit; font-size: 15px; color: var(--ink); background: var(--raised); border: 1px solid var(--line2); border-radius: 6px; padding: 6px 9px; min-width: 0; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input[aria-invalid="true"] { border-color: var(--crit); background: var(--critbg); }
textarea { width: 100%; resize: vertical; min-height: 110px; line-height: 1.45; }
input.zahl { text-align: right; font-variant-numeric: tabular-nums; }
.suche { width: 260px; max-width: 100%; }
@media (max-width: 720px) { .leiste .rechts { margin-left: 0; width: 100%; } .leiste .rechts .suche { flex: 1; width: auto; } }

.felder { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px 14px; }
.feld { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.feld > span { font-size: 12.5px; color: var(--ink2); font-weight: 600; }
.feld.breit { grid-column: 1 / -1; }
@media (max-width: 480px) { .felder { grid-template-columns: 1fr 1fr; gap: 10px; } }
.feld input, .feld select { width: 100%; }

/* Eingabezeile mit Einheit, für Rechnung und Einstellungen */
.zeilen { display: flex; flex-direction: column; gap: 6px; }
.zeile { display: grid; grid-template-columns: minmax(0, 1fr) 132px 74px 22px; align-items: center; gap: 8px; }
.zeile label { font-size: 14px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; hyphens: auto; overflow-wrap: anywhere; }
.zeile input { width: 100%; }
.zeile .einheit { font-size: 12.5px; color: var(--muted); }
.zeile.eigen input { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.annahme { font-size: 10.5px; font-weight: 600; letter-spacing: .03em; color: var(--ink2); background: var(--sunken); border-radius: 999px; padding: 1px 7px; }
.vorschlag { grid-column: 1 / -1; font-size: 13px; color: var(--ink2); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: -2px 0 4px; }
@media (max-width: 480px) { .zeile { grid-template-columns: minmax(0, 1fr) 112px 58px 20px; gap: 6px; } }

/* ---------- Flächen ---------- */
.karte { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.karte > .btn, .karte > a.btn { align-self: flex-start; }
.spalten { columns: 2 440px; column-gap: 16px; }
.spalten > .karte { break-inside: avoid; margin-bottom: 16px; }
.karte > .kopfzeile { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.zwei { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.links-schmal { display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 960px) { .zwei, .links-schmal { grid-template-columns: minmax(0, 1fr); } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.kpi .lab { font-size: 12.5px; color: var(--ink2); font-weight: 600; }
.kpi .wert { font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.kpi .unter { font-size: 12.5px; color: var(--ink2); }
.kpi.gut .wert { color: var(--good); } .kpi.warn .wert { color: var(--warn); } .kpi.krit .wert { color: var(--crit); }

.hinweise { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.hinweise li { font-size: 13.5px; padding: 5px 10px; border-radius: 7px; background: var(--sunken); }
.hinweise .gut { background: var(--goodbg); color: var(--good); }
.hinweise .warn { background: var(--warnbg); color: var(--warn); }
.hinweise .krit { background: var(--critbg); color: var(--crit); }

.karte.schmal { max-width: 420px; }
.leer { color: var(--muted); padding: 22px 4px; text-align: center; }

/* ---------- Tabellen ---------- */
.tabelle-wrap { overflow-x: auto; margin: 0 -2px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
thead th { font-size: 12px; font-weight: 650; color: var(--ink2); border-bottom: 1px solid var(--line2); white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
td.z, th.z { text-align: right; white-space: nowrap; }
tr.summe td { font-weight: 700; border-top: 1px solid var(--line2); }
tr.leise td { color: var(--ink2); }
tbody tr.klick { cursor: pointer; }
tbody tr.klick:hover td { background: var(--sunken); }
td.pos { color: var(--good); } td.neg { color: var(--crit); }
td :is(span, div).klein, .klein-text { font-size: 12.5px; color: var(--muted); }
.aufstellung td:first-child { width: 100%; }

/* Objektliste */
.objekte td.bild { width: 58px; padding-right: 0; }
.daumen { width: 50px; height: 38px; border-radius: 5px; background: var(--sunken); object-fit: cover; display: block; }
.daumen.leer { display: grid; place-items: center; color: var(--muted); font-size: 11px; }
.objekte .titel { font-weight: 650; }
.objekte td.auswahl { width: 30px; }
.objekte input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); }
.fussleiste { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--raised); border-top: 1px solid var(--line); box-shadow: var(--shadow); padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0)); }
.fussleiste > div { max-width: 1320px; margin: 0 auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.fussleiste .rechts { margin-left: auto; display: flex; gap: 8px; }

@media (max-width: 720px) {
  .objekte thead { display: none; }
  .objekte tr { display: grid; grid-template-columns: 30px 58px minmax(0, 1fr) auto; grid-template-areas: "a b t s" "a b w w"; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .objekte td { border: 0; padding: 2px 6px; }
  .objekte td.auswahl { grid-area: a; } .objekte td.bild { grid-area: b; } .objekte td.titelzelle { grid-area: t; }
  .objekte td.statuszelle { grid-area: s; text-align: right; }
  .objekte td.werte { grid-area: w; display: flex !important; flex-wrap: wrap; gap: 2px 12px; font-size: 13px; color: var(--ink2); }
  .objekte td.nur-breit { display: none; }
}
.objekte td.werte { display: none; }

/* Status */
.chip { display: inline-block; font-size: 12px; font-weight: 650; padding: 2px 9px; border-radius: 999px; white-space: nowrap; background: var(--sunken); color: var(--ink2); }
.st-besichtigung { background: var(--infobg); color: var(--info); }
.st-angebot { background: var(--warnbg); color: var(--warn); }
.st-kauf { background: var(--accent-soft); color: var(--accent); }
.st-sanierung { background: var(--orangebg); color: var(--orange); }
.st-verkauf { background: var(--lilabg); color: var(--lila); }
.st-vermietet { background: var(--infobg); color: var(--info); }
.st-abgeschlossen { background: var(--goodbg); color: var(--good); }
.st-abgesagt { text-decoration: line-through; }
.chip.gut { background: var(--goodbg); color: var(--good); }
.chip.warn { background: var(--warnbg); color: var(--warn); }
.chip.krit { background: var(--critbg); color: var(--crit); }

.filter { display: flex; flex-wrap: wrap; gap: 5px; }
.filter button { font: inherit; font-size: 13px; border: 1px solid var(--line); background: var(--surface); color: var(--ink2); border-radius: 999px; padding: 4px 11px; cursor: pointer; }
.filter button.aktiv { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.filter button .n { opacity: .7; margin-left: 4px; }

.status-weg { display: flex; flex-wrap: wrap; gap: 4px; }
.status-weg button { font: inherit; font-size: 13px; border: 1px solid var(--line); background: var(--surface); color: var(--ink2); padding: 4px 10px; border-radius: 6px; cursor: pointer; }
.status-weg button.erledigt { color: var(--ink); border-color: var(--line2); }
.status-weg button.aktiv { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.status-weg .trenner { width: 1px; background: var(--line); margin: 0 4px; }
@media (max-width: 720px) {
  .status-weg { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
  .status-weg::-webkit-scrollbar { display: none; }
  .status-weg button { flex: none; }
}

/* Reiter */
.reiter { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.reiter a { text-decoration: none; color: var(--ink2); padding: 9px 13px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 550; }
.reiter a:hover { color: var(--ink); }
.reiter a.aktiv { color: var(--accent); border-bottom-color: var(--accent); }
.reiter .n { font-size: 12px; color: var(--muted); margin-left: 3px; }

.objektkopf { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.objektkopf .titelblock { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 4px; }
.objektkopf .adresse { color: var(--ink2); font-size: 14px; display: flex; gap: 10px; flex-wrap: wrap; }
.titelfoto { width: 120px; height: 84px; border-radius: 8px; object-fit: cover; background: var(--sunken); cursor: pointer; }
@media (max-width: 720px) { .titelfoto { width: 72px; height: 54px; } .objektkopf { flex-wrap: nowrap; } .objektkopf .titelblock { min-width: 0; } }

/* Speichern-Leiste */
.speicherleiste .zustand { font-weight: 600; }
.speicherleiste .fehler { color: var(--crit); }

/* Fotos */
.fotos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.foto { position: relative; aspect-ratio: 4 / 3; border-radius: 7px; overflow: hidden; background: var(--sunken); border: 0; padding: 0; cursor: pointer; }
.foto img { width: 100%; height: 100%; object-fit: cover; display: block; }
.foto .ohne { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; padding: 6px; text-align: center; word-break: break-all; }
.foto .marke-video { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.foto .marke-titel { position: absolute; right: 6px; top: 6px; background: var(--accent); color: var(--accent-ink); font-size: 11px; padding: 1px 6px; border-radius: 4px; font-weight: 700; }
@media (max-width: 480px) { .fotos { grid-template-columns: repeat(3, 1fr); gap: 4px; } }
.upload-liste { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.upload-liste .u { display: grid; grid-template-columns: minmax(0, 1fr) 90px; gap: 10px; align-items: center; }
.upload-liste .u span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-liste progress { width: 100%; accent-color: var(--accent); }
.upload-liste .fehl { color: var(--crit); }

/* Dialoge */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--raised); color: var(--ink); padding: 0; box-shadow: var(--shadow); width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: rgba(10, 14, 12, .45); }
dialog form, dialog .innen { display: flex; flex-direction: column; gap: 14px; padding: 18px; }
dialog .knoepfe { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
dialog .knoepfe .links { margin-right: auto; }
dialog .meldung { color: var(--crit); font-size: 14px; min-height: 1em; }

dialog.lightbox { width: 100vw; height: 100dvh; max-width: none; max-height: none; border: 0; border-radius: 0; background: #0b0d0c; color: #eef1ef; margin: 0; }
.lightbox .innen { height: 100%; padding: 0; gap: 0; }
.lightbox .bildflaeche { flex: 1; min-height: 0; display: grid; place-items: center; position: relative; }
.lightbox .bildflaeche img, .lightbox .bildflaeche video { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox .blaettern { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.12); color: #fff; border: 0; width: 44px; height: 64px; font-size: 26px; cursor: pointer; border-radius: 6px; }
.lightbox .blaettern:hover { background: rgba(255,255,255,.24); }
.lightbox .vor { right: 10px; } .lightbox .rueck { left: 10px; }
.lightbox .leiste-unten { display: flex; gap: 8px 12px; align-items: center; flex-wrap: wrap; padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0)); background: #151917; font-size: 13.5px; }
.lightbox .leiste-unten .btn { background: #262c29; color: #eef1ef; border-color: #3b433e; }
.lightbox .leiste-unten .info { flex: 1; min-width: 180px; color: #b9c1bc; }
.lightbox .leiste-unten input { background: #1f2421; color: #eef1ef; border-color: #3b433e; width: min(320px, 100%); }
.lightbox .schliessen { position: absolute; right: 12px; top: calc(12px + env(safe-area-inset-top, 0)); z-index: 2; background: rgba(255,255,255,.14); color: #fff; border: 0; width: 40px; height: 40px; border-radius: 50%; font-size: 22px; cursor: pointer; }

/* Meldungen */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom, 0)); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(560px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; display: flex; gap: 12px; align-items: center; }
.toast.fehler { background: var(--crit); color: #fff; }
.toast button { background: none; border: 1px solid currentColor; color: inherit; border-radius: 5px; padding: 3px 9px; font: inherit; font-size: 13px; cursor: pointer; }

/* Anmeldung */
.anmeldung { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.anmeldung form { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 24px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.anmeldung .marke { justify-content: center; font-size: 17px; margin-bottom: 4px; }
.anmeldung .marke svg { width: 34px; height: 34px; }
.anmeldung .meldung { color: var(--crit); font-size: 14px; min-height: 1.2em; }

/* Vergleich */
.vergleich-wahl { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.vergleich-wahl select { min-width: 180px; max-width: 100%; }
.vergleich th.objekt { min-width: 150px; text-align: right; }
.vergleich td:first-child, .vergleich th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.vergleich tr.gruppe td { font-size: 12px; font-weight: 700; color: var(--ink2); text-transform: uppercase; letter-spacing: .05em; padding-top: 16px; background: var(--surface); }
.vergleich td.best { font-weight: 700; background: var(--accent-soft); }
.check-rechts { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.verlauf { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.verlauf li { display: grid; grid-template-columns: 138px 110px minmax(0, 1fr); gap: 10px; padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.verlauf .wann { color: var(--muted); font-size: 13px; }
.verlauf .wer { font-weight: 600; }
.verlauf .diff { display: flex; flex-direction: column; gap: 1px; }
.verlauf .alt { color: var(--muted); text-decoration: line-through; }
@media (max-width: 600px) { .verlauf li { grid-template-columns: 1fr; gap: 2px; } }
