:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --text: #1d2420;
  --muted: #66706b;
  --border: #dde3ec;
  --brand: #1d4f91;
  --brand-ink: #ffffff;
  --brand-soft: #e3ecf8;
  --accent: #f28c28;
  --accent-ink: #ffffff;
  --accent-soft: #fdebd8;
  --ok: #2c7a4b;
  --ok-soft: #e1f2e7;
  --warn: #9a5b00;
  --warn-soft: #fbefd9;
  --bad: #b3261e;
  --bad-soft: #fbe3e1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111620;
    --surface: #18202c;
    --surface-2: #1f2836;
    --text: #e8ece9;
    --muted: #9aa49f;
    --border: #2c3746;
    --brand: #7aa7e6;
    --brand-ink: #0c1a2e;
    --brand-soft: #1b2a40;
    --accent: #f5a04b;
    --accent-ink: #2a1500;
    --accent-soft: #3a2614;
    --ok: #6fcf97;
    --ok-soft: #1c3326;
    --warn: #f2b45a;
    --warn-soft: #3a2d17;
    --bad: #f28b82;
    --bad-soft: #3d1f1d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
body.plain { padding-bottom: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 0; }
.muted { color: var(--muted); }
small { font-size: .85rem; }
img { max-width: 100%; }

/* Kopfzeile */
.topbar {
  border-bottom: 3px solid var(--accent);
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: #1d4f91; color: #ffffff;
}
.brand { display: flex; align-items: center; gap: 8px; color: inherit; font-weight: 700; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { border-radius: 6px; background: #fff; }
.mainnav { display: none; gap: 4px; }
.mainnav a { color: inherit; opacity: .85; padding: 6px 10px; border-radius: 8px; }
.mainnav a.active, .mainnav a:hover { opacity: 1; background: rgba(255,255,255,.15); text-decoration: none; }
.mainnav a.active { box-shadow: inset 0 -3px 0 var(--accent); }
.topsearch { margin-left: auto; flex: 1; max-width: 320px; }
.topsearch input { width: 100%; border: 0; border-radius: 8px; padding: 7px 10px; font-size: 15px; background: rgba(255,255,255,.18); color: inherit; }
.topsearch input::placeholder { color: inherit; opacity: .7; }
.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; font-size: 1.3rem; padding: 2px 6px; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu .menu {
  position: absolute; right: 0; top: 36px; min-width: 200px; padding: 8px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.15);
  display: flex; flex-direction: column;
}
.usermenu .menu a, .usermenu .menu .linklike { padding: 8px 10px; border-radius: 8px; color: var(--text); text-align: left; }
.usermenu .menu a:hover, .usermenu .menu .linklike:hover { background: var(--surface-2); text-decoration: none; }
.usermenu .menu small { padding: 6px 10px 2px; color: var(--muted); border-top: 1px solid var(--border); margin-top: 4px; word-break: break-all; }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; width: 100%; }

/* Untere Leiste (Handy) */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; padding: 8px 0 6px; font-size: .72rem; color: var(--muted); }
.tabbar a:hover { text-decoration: none; }
.tabbar a.active { color: var(--brand); font-weight: 600; box-shadow: inset 0 3px 0 var(--accent); }
.tabbar .ico { font-size: 1.25rem; line-height: 1.2; }
.tabbar .cam .ico { background: var(--accent); color: var(--accent-ink); border-radius: 50%; width: 44px; height: 44px; display: grid; place-items: center; margin-top: -18px; box-shadow: 0 2px 8px rgba(0,0,0,.2); }

@media (min-width: 900px) {
  .mainnav { display: flex; }
  .tabbar { display: none; }
  body { padding-bottom: 32px; }
}

/* Inhalt */
.container { max-width: 1100px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.page-head p { margin: 4px 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.crumbs { font-size: .9rem; margin-bottom: 4px; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.card.empty { text-align: center; padding: 32px 16px; }
.card-head h2 .count { background: var(--accent-soft); color: var(--accent); }
.count { display: inline-block; min-width: 1.6em; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .8rem; text-align: center; font-weight: 500; }
.two-col { display: grid; gap: 0 16px; }
@media (min-width: 800px) { .two-col { grid-template-columns: 1fr 1fr; } }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: .95rem; cursor: pointer;
  min-height: 40px; white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.accent:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: .85rem; }
.btn.big { padding: 14px 18px; font-size: 1.05rem; }
.iconbtn { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 1.1rem; padding: 4px 8px; border-radius: 8px; }
.iconbtn:hover { background: var(--surface-2); color: var(--bad); }
.iconbtn.ok { color: var(--ok); font-size: 1.2rem; border: 1px solid var(--border); }
.iconbtn.ok:hover { background: var(--ok-soft); color: var(--ok); }
form.inline { display: inline; }
.danger-zone { margin: 24px 0 8px; text-align: right; }

/* Pills */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; vertical-align: middle; }
.pill.ok, .unit-vermietet, .status-erledigt, .tenancy-aktuell { background: var(--ok-soft); color: var(--ok); }
.pill.warn, .unit-renovierung, .status-beauftragt, .tenancy-zukünftig { background: var(--warn-soft); color: var(--warn); }
.pill.bad, .unit-leer, .status-offen { background: var(--bad-soft); color: var(--bad); }
.unit-eigennutzung, .tenancy-ehemalig { background: var(--surface-2); color: var(--muted); }
.urgent, .warn-text { color: var(--bad); font-weight: 600; }

/* Kennzahlen */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat a { color: inherit; display: block; }
.stat a:hover { text-decoration: none; }
.stat .num { display: block; font-size: 1.5rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: .85rem; }
.stat.warn .num { color: var(--warn); }

.property-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); margin-bottom: 16px; }
.property-card { padding: 0; overflow: hidden; color: var(--text); margin: 0; }
.property-card:hover { text-decoration: none; border-color: var(--accent); }
.property-card img, .property-card .ph { width: 100%; height: 130px; object-fit: cover; display: block; }
.property-card .ph { display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-size: 2.5rem; }
.property-card .body { padding: 12px 14px; }
.property-card .meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: .88rem; }

/* Listen */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.list > li > a { display: flex; align-items: center; gap: 10px; color: var(--text); flex: 1; min-width: 0; }
.list > li > a:hover { text-decoration: none; }
.list > li > a:hover strong { color: var(--brand); }
.list > li > a > span:last-child, .list > li > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.list .meter.inactive { opacity: .6; }
.contact { flex-wrap: wrap; }
.contact > div:first-child { display: flex; flex-direction: column; }
.contact-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.docicon { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 8px; background: var(--brand-soft); color: var(--brand); font-size: .7rem; font-weight: 700; }

/* Tabellen */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table tr[data-href] { cursor: pointer; }
.table tr[data-href]:hover td { background: var(--surface-2); }
img.mini { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }
@media (max-width: 640px) {
  .table.units thead { display: none; }
  .table.units tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .table.units tr:last-child { border-bottom: 0; }
  .table.units td { border: 0; padding: 0; }
  .table.units td:nth-child(3) { display: none; }
  .table.units td:nth-child(2) { grid-column: 1; color: var(--muted); font-size: .9rem; }
  .table.units td:nth-child(4) { grid-column: 2; grid-row: 2; }
  .table.units td:nth-child(5) { grid-column: 2; grid-row: 1; text-align: right; }
}

/* Fakten */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
@media (min-width: 700px) { .facts.cols { grid-template-columns: repeat(2, max-content 1fr); } }
.notes { white-space: normal; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin-top: 8px; }
.tenant { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.tenant h3 { font-size: 1.2rem; }
.tenant p { margin: 2px 0; }
.docs-inline { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; }

/* Galerie */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 12px; }
.gallery figure { margin: 0; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.gallery img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.gallery figcaption { display: flex; justify-content: space-between; align-items: center; gap: 4px; padding: 2px 4px 2px 8px; font-size: .8rem; color: var(--muted); }
.gallery figcaption span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; padding-top: 12px; border-top: 1px dashed var(--border); }
.upload-row input[type=text], .upload-row select { flex: 1; min-width: 160px; }

/* Lightbox */
.lb { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.92); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.lb img { max-width: 100%; max-height: calc(100vh - 90px); object-fit: contain; }
.lb p { color: #ddd; margin: 10px 0 0; text-align: center; }
.lb button { position: absolute; top: 12px; right: 12px; background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 50%; width: 44px; height: 44px; font-size: 1.4rem; cursor: pointer; }
.lb a { color: #9fd; font-size: .9rem; }

/* Formulare */
input[type=text], input[type=email], input[type=tel], input[type=date], input[type=search], input[type=password], select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
label { font-weight: 500; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label { display: flex; flex-direction: column; gap: 4px; }
.row { display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap; }
.grid-form { display: grid; gap: 14px 16px; }
@media (min-width: 700px) { .grid-form { grid-template-columns: 1fr 1fr; } .grid-form .wide { grid-column: 1 / -1; } }
.grid-form > label { display: flex; flex-direction: column; gap: 4px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field .help { color: var(--muted); }
.field .error { color: var(--bad); font-weight: 600; }
.field.has-error input, .field.has-error select { border-color: var(--bad); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; padding-top: 28px; }
.check input { width: 20px; height: 20px; }
.req { color: var(--bad); }
.upload-field { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-actions { display: flex; gap: 8px; }
.searchbox { display: flex; gap: 8px; }
.status-switch { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs a { padding: 6px 14px; border-radius: 999px; color: var(--muted); }
.tabs a.active { background: var(--brand); color: var(--brand-ink); }
.tabs a:hover { text-decoration: none; }
.timeline { list-style: none; padding: 0; margin: 16px 0 0; border-left: 2px solid var(--border); }
.timeline li { padding: 0 0 12px 14px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.quick-photo .cam-buttons { display: grid; gap: 8px; }
@media (min-width: 600px) { .quick-photo .cam-buttons { grid-template-columns: 1fr 1fr; } }

/* Hinweise */
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-weight: 500; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--bad-soft); color: var(--bad); }

/* Login */
.auth { max-width: 420px; margin: 0 auto; padding: 48px 16px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; justify-content: center; }
.auth-brand img { border-radius: 10px; }
.auth-brand h1 { font-size: 1.4rem; }
.auth .card { padding: 24px; }
.auth h2 { font-size: 1.25rem; }

/* Korrekturen */
.list > li { flex-wrap: wrap; }
.list > li > a.btn { flex: none; color: var(--text); }
.list > li > a:not(.btn) { min-width: 220px; }
.contact-actions, .tenant { align-items: flex-start; }
.contact-actions .btn { min-height: 32px; }
.auth .card .card { border: 0; padding: 0; margin: 0; background: none; box-shadow: none; }
.code-input { font-size: 1.6rem !important; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.suggest { position: absolute; top: 100%; left: 0; right: 0; z-index: 30; margin-top: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); overflow: hidden; }
.suggest button { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; border-top: 1px solid var(--border); background: none; color: var(--text); font: inherit; cursor: pointer; }
.suggest button:first-child { border-top: 0; }
.suggest button:hover, .suggest button:focus { background: var(--brand-soft); }
.map { height: 260px; border-radius: 10px; overflow: hidden; z-index: 0; }
.map.big { height: 340px; }
.map-links { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.map { isolation: isolate; }
/* Verdeckte Beträge */
.money { cursor: pointer; white-space: nowrap; }
.money .m-real { display: none; }
.show-money .money .m-real { display: inline; }
.show-money .money .m-hidden { display: none; }
.money .m-hidden { letter-spacing: .05em; }
.money-toggle { background: none; border: 0; color: inherit; cursor: pointer; padding: 4px 6px; border-radius: 8px; display: grid; place-items: center; }
.money-toggle:hover { background: rgba(255,255,255,.15); }
.money-toggle .eye-open { display: none; }
.show-money .money-toggle .eye-open { display: block; }
.show-money .money-toggle .eye-closed { display: none; }
