:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --text: #1f2421;
  --muted: #6b716d;
  --border: #e3e0d9;
  --accent: #2f5d50;
  --accent-hover: #244a40;
  --accent-soft: #e4eee9;
  --ok: #2e7d4f;
  --ok-soft: #e3f2e8;
  --warn: #a8640c;
  --warn-soft: #fbefd9;
  --danger: #b3261e;
  --danger-soft: #fbe5e3;
  --info: #2f5f8f;
  --info-soft: #e3edf7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(30, 30, 20, .06), 0 2px 8px rgba(30, 30, 20, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161917;
    --surface: #1f2321;
    --surface-2: #252a27;
    --text: #e8ebe9;
    --muted: #9aa29d;
    --border: #333a36;
    --accent: #7cc1a9;
    --accent-hover: #95d2bc;
    --accent-soft: #24362f;
    --ok: #7fcf9c;
    --ok-soft: #1f3327;
    --warn: #e7b25e;
    --warn-soft: #3a2f1c;
    --danger: #f08b83;
    --danger-soft: #3d2220;
    --info: #8db8e3;
    --info-soft: #1f2c3a;
    --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: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }
p { margin: 0 0 .75rem; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; font-size: .9em; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Kopfzeile ---------- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: .6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; display: flex; align-items: center; gap: .4rem; }
.brand:hover { text-decoration: none; }
.brand-icon {
  display: inline-grid; place-items: center;
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--accent); color: var(--surface); font-size: 1rem;
}
.mainnav { display: flex; gap: .25rem; flex-wrap: wrap; }
.mainnav a, .usernav a, .linklike {
  color: var(--muted);
  padding: .4rem .7rem;
  border-radius: 7px;
  font-weight: 500;
}
.mainnav a:hover, .usernav a:hover, .linklike:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.mainnav a.active, .usernav a.active { background: var(--accent-soft); color: var(--accent); }
.search { margin-left: auto; }
.search input { width: 220px; padding: .4rem .7rem; }
.usernav { display: flex; align-items: center; gap: .25rem; }
.usernav form { margin: 0; }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; }

/* ---------- Seite ---------- */

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

.crumbs { font-size: .875rem; color: var(--muted); margin-bottom: .5rem; }
.crumbs a { color: var(--muted); }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.page-head p { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1rem;
}
.card > h2 { display: flex; align-items: center; gap: .5rem; }
.card.notes, .notes { white-space: normal; color: var(--muted); }
.tenant .notes { margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--border); }
.table-card { padding: 0; overflow: hidden; }

.count {
  font-size: .75rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border);
  padding: 0 .45rem; border-radius: 99px;
}

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 0 1rem; }
.grid-nk { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, 1fr); gap: 1rem; align-items: start; }

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

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  display: flex; flex-direction: column; gap: .15rem;
  color: var(--text);
}
a.tile:hover { text-decoration: none; border-color: var(--accent); }
.tile-label { font-size: .8rem; color: var(--muted); font-weight: 500; }
.tile-value { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: .8rem; color: var(--muted); }

/* ---------- Objekt-Karten ---------- */

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1rem; }
.objekt-card { color: var(--text); margin: 0; transition: border-color .15s, transform .15s; }
.objekt-card:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-1px); }
.objekt-card h2 { font-size: 1.15rem; margin-bottom: .15rem; }
.occupancy { height: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; margin: .5rem 0 .75rem; }
.occupancy-bar { height: 100%; background: var(--ok); }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem 1rem; margin: 0; }
.facts dt { font-size: .75rem; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Haus-Ansicht ---------- */

.house { margin: 0 0 1.25rem; }
.house-roof {
  height: 34px;
  margin: 0 6px;
  background: var(--border);
  clip-path: polygon(4% 100%, 50% 0, 96% 100%);
}
.floor {
  display: grid;
  grid-template-columns: 80px 1fr;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 0;
}
.house-roof + .floor { border-top: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.floor:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.floor-label {
  display: grid; place-items: center;
  font-weight: 650; font-size: .85rem; color: var(--muted);
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  padding: .5rem;
  text-align: center;
}
.floor-units { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .6rem; padding: .6rem; }
.unit {
  display: flex; flex-direction: column; gap: .1rem;
  padding: .7rem .8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  color: var(--text);
  background: var(--surface);
  transition: background .15s;
}
.unit:hover { text-decoration: none; background: var(--surface-2); }
.unit-rented { border-left-color: var(--ok); }
.unit-free { border-left-color: var(--warn); background: var(--warn-soft); }
.unit-title { font-weight: 650; }
.unit-meta { font-size: .78rem; color: var(--muted); }
.unit-tenant { margin-top: .3rem; font-weight: 500; }
.unit-tenant.free { color: var(--warn); font-weight: 600; }
.unit-rent { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Mieter ---------- */

.tenant-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.tenant-head h2 { font-size: 1.25rem; margin: .4rem 0 0; }
.tenant-head p { margin: 0; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: .35rem 1rem; margin: 0 0 .5rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.empty-inline { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }

/* ---------- Listen & Tabellen ---------- */

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .55rem 0; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: .25rem .6rem; align-items: baseline; }
.list li:last-child { border-bottom: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tfoot th, tfoot td { border-top: 2px solid var(--border); border-bottom: 0; text-transform: none; font-size: .9rem; color: var(--text); }
.card:not(.table-card) table th { background: none; }
.card:not(.table-card) table th:first-child, .card:not(.table-card) table td:first-child { padding-left: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }

.tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tabs a {
  padding: .35rem .8rem; border-radius: 99px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); font-size: .9rem; font-weight: 500;
}
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.toolbar { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* ---------- Badges ---------- */

.badge {
  display: inline-block;
  font-size: .75rem; font-weight: 600;
  padding: .1rem .55rem; border-radius: 99px;
  background: var(--surface-2); color: var(--muted);
  white-space: nowrap;
}
.badge-ok, .status-erledigt { background: var(--ok-soft); color: var(--ok); }
.badge-warn, .status-entwurf { background: var(--warn-soft); color: var(--warn); }
.badge-info, .status-versendet { background: var(--info-soft); color: var(--info); }

.saldo { font-weight: 600; font-variant-numeric: tabular-nums; }
.saldo.pos { color: var(--ok); }
.saldo.neg { color: var(--danger); }

/* ---------- Formulare ---------- */

label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 500; color: var(--muted); }
input, select, textarea {
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: .5rem .65rem;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { resize: vertical; }
input.num { text-align: right; }

.form h2 { margin-top: 1.25rem; }
.form h2:first-of-type { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .9rem 1rem; }
.form-grid.tight { grid-template-columns: 1fr 1fr; gap: .75rem; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-full { grid-column: 1 / -1; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.hint { font-size: .8rem; color: var(--muted); font-weight: 400; margin: .4rem 0 0; }
.checkbox { flex-direction: row; align-items: center; gap: .5rem; margin-top: 1rem; color: var(--text); font-weight: 400; font-size: .95rem; }
.checkbox input { width: auto; }
.form-actions { display: flex; gap: .5rem; margin-top: 1.25rem; flex-wrap: wrap; }
.sticky-actions {
  position: sticky; bottom: 0;
  background: var(--bg);
  padding: .75rem 0;
  margin-top: 0;
  border-top: 1px solid var(--border);
}
.inline-form { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 0; }
.inline-form > div { flex: 1 1 300px; }
.inline-form p { margin: .15rem 0 0; }
.inline-form select { width: auto; }
.callout { background: var(--accent-soft); border-color: transparent; box-shadow: none; }

details.card > summary { cursor: pointer; list-style: revert; }
details.card[open] > summary { margin-bottom: 1rem; }

.positions th, .positions td { padding: .3rem .4rem; border-bottom: 0; }
.positions th:first-child, .positions td:first-child { padding-left: 0; }
.positions td:nth-child(2) { width: 140px; }
.positions td:last-child { width: 36px; }

.result { margin-top: 1.25rem; border-top: 1px solid var(--border); padding-top: .75rem; }
.result > div { display: flex; justify-content: space-between; padding: .25rem 0; font-variant-numeric: tabular-nums; }
.result span { color: var(--muted); }
.result-total { border-top: 1px solid var(--border); margin-top: .35rem; padding-top: .6rem !important; font-size: 1.1rem; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  font: inherit; font-weight: 550; font-size: .92rem;
  padding: .5rem .95rem;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-small { padding: .3rem .65rem; font-size: .82rem; }
.btn-danger-ghost { color: var(--danger); border-color: transparent; background: none; }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.icon-btn {
  border: 0; background: none; color: var(--muted);
  font-size: 1.2rem; line-height: 1; cursor: pointer;
  width: 30px; height: 30px; border-radius: 6px;
}
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }

.danger-zone { margin-top: 2rem; padding-top: 1rem; border-top: 1px dashed var(--border); }

/* ---------- Meldungen & Leerzustände ---------- */

.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-weight: 500; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--danger-soft); color: var(--danger); }

.empty { text-align: center; padding: 3rem 1rem; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); margin-bottom: 1rem; }
.empty-icon { font-size: 2.5rem; color: var(--accent); margin-bottom: .5rem; }
.empty p { color: var(--muted); }

.auth-box { max-width: 380px; margin: 8vh auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 2rem; box-shadow: var(--shadow); }
.auth-box h1 { text-align: center; margin-bottom: 1.25rem; }
.auth-box .btn { width: 100%; margin-top: .25rem; padding: .65rem; }
.auth-logo { width: 48px; height: 48px; margin: 0 auto .75rem; display: grid; place-items: center; border-radius: 12px; background: var(--accent); color: var(--surface); font-size: 1.6rem; }

/* ---------- Druckansicht ---------- */

.print-page { background: var(--bg); }
.print-toolbar { max-width: 210mm; margin: 1rem auto; display: flex; gap: .5rem; padding: 0 1rem; }
.sheet {
  max-width: 210mm;
  margin: 0 auto 2rem;
  background: #fff;
  color: #111;
  padding: 20mm 20mm 15mm;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.sheet a { color: inherit; }
.sheet-head { display: grid; grid-template-columns: 1fr auto; gap: 1rem; margin-bottom: 12mm; }
.sender { grid-column: 1 / -1; font-size: .8rem; color: #555; border-bottom: 1px solid #ccc; padding-bottom: .4rem; min-height: 1.2rem; }
.recipient { line-height: 1.5; }
.date { text-align: right; align-self: end; }
.sheet h1 { font-size: 1.35rem; margin-bottom: 1rem; }
.sheet-table { margin: 1.25rem 0; }
.sheet-table th { background: none; color: #111; border-bottom: 2px solid #111; text-transform: none; font-size: .9rem; letter-spacing: 0; padding-left: 0; }
.sheet-table td { border-bottom: 1px solid #ddd; padding-left: 0; }
.sheet-table tfoot th, .sheet-table tfoot td { border-top: 0; border-bottom: 1px solid #ddd; color: #111; padding-left: 0; }
.sheet-table tfoot tr:first-child th { border-top: 2px solid #111; }
.sheet-table .total th { font-size: 1.05rem; border-top: 2px solid #111; border-bottom: 3px double #111; }
.signature { margin-top: 2.5rem; }
.sheet-foot { margin-top: 3rem; padding-top: .5rem; border-top: 1px solid #ccc; font-size: .75rem; color: #555; }

@media print {
  @page { size: A4; margin: 0; }
  body, .print-page { background: #fff; }
  .no-print { display: none !important; }
  .sheet { box-shadow: none; border: 0; margin: 0; max-width: none; }
}

/* ---------- Mobil ---------- */

@media (max-width: 860px) {
  .grid-nk { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .span-3 { grid-column: 1 / -1; }
  .search { margin-left: 0; order: 10; width: 100%; }
  .search input { width: 100%; }
}

@media (max-width: 560px) {
  .container { padding: 1rem .75rem 3rem; }
  .topbar-inner { gap: .5rem; }
  .usernav { margin-left: auto; }
  .mainnav { order: 9; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .grid-2 { grid-template-columns: 1fr; }
  .floor { grid-template-columns: 1fr; }
  .floor-label { border-right: 0; border-bottom: 1px solid var(--border); place-items: start; padding: .35rem .7rem; }
  .kv { grid-template-columns: 120px 1fr; }
  h1 { font-size: 1.35rem; }
}
