:root {
  --bg: #FAFAFA; --surface: #FFFFFF; --text: #444444; --muted: #686868; --line: #EEEEEE; --line-strong: #D9D9D9;
  --primary: #437A1B; --primary-text: #FFFFFF; --primary-soft: #EFFAE6; --primary-ink: #2F5513; --link: #3C6A18;
  --warn-bg: #FCE3C2; --warn-ink: #7A4E15; --bad-bg: #F2C6C6; --bad-ink: #7A2222; --bad: #B43030;
  --info-bg: #C6D8F2; --info-ink: #2F4C75; --neutral-bg: #EEEEEE; --neutral-ink: #555555; --ok-bg: #D9F2C6;
  --mono: "Roboto Mono", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161816; --surface: #1F221F; --text: #E4E6E3; --muted: #A3A8A1; --line: #2E322D; --line-strong: #43483F;
    --primary: #5C9A2D; --primary-text: #FFFFFF; --primary-soft: #23331A; --primary-ink: #B9E39A; --link: #9FD172;
    --warn-bg: #4A3417; --warn-ink: #F3CC94; --bad-bg: #4A2020; --bad-ink: #F2B3B3; --bad: #F08A8A;
    --info-bg: #23344D; --info-ink: #B7CDEE; --neutral-bg: #2E322D; --neutral-ink: #C9CCC7; --ok-bg: #2A3F1E;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 Inter, system-ui, sans-serif; }
a { color: var(--link); }
h1 { margin: 0; font-size: 28px; line-height: 1.15; }
h2 { margin: 0; font-size: 16px; }
.shell { display: flex; min-height: 100vh; }
.side { flex: 0 0 220px; background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 10px 18px; }
.logo { width: 32px; height: 32px; border-radius: 8px; background: #6BB030; display: flex; align-items: center; justify-content: center; }
.navlink { padding: 10px 12px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 500; }
.navlink:hover { background: var(--line); }
.navlink.active { background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.side-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
main { flex: 1; min-width: 0; padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 20px; }
main:focus { outline: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 18px; display: flex; flex-direction: column; gap: 6px; }
.kpi b { font-family: var(--mono); font-size: 24px; font-weight: 500; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.card-pad { padding: 16px 20px; }
.bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; padding: 10px 20px 0; border-bottom: 1px solid var(--line); }
.tab { height: 40px; padding: 0 14px; border: 0; border-bottom: 3px solid transparent; background: none; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab[aria-selected="true"] { border-bottom-color: var(--primary); color: var(--primary-ink); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip-btn[aria-pressed="true"] { background: var(--primary-soft); border-color: #6BB030; color: var(--primary-ink); }
.btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 5px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.small { height: 30px; padding: 0 10px; font-size: 12px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .chip-btn:focus-visible, .tab:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
select, input[type=text], input[type=email], input[type=tel], input[type=number], input[type=password], input[type=search], textarea { height: 36px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface); color: var(--text); font: inherit; }
textarea { height: auto; padding: 10px; width: 100%; min-height: 220px; font-family: var(--mono); font-size: 12px; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 10px 8px; white-space: nowrap; }
td { padding: 12px 8px; border-top: 1px solid var(--line); vertical-align: top; }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
tr.details td { background: var(--bg); border-top: 0; }
.tag { display: inline-block; white-space: nowrap; font-size: 12px; font-weight: 600; border-radius: 4px; padding: 3px 8px; }
.tag.ok { background: var(--ok-bg); color: var(--primary-ink); }
.tag.green { background: var(--primary); color: var(--primary-text); }
.tag.warn { background: var(--warn-bg); color: var(--warn-ink); }
.tag.bad { background: var(--bad-bg); color: var(--bad-ink); }
.tag.info { background: var(--info-bg); color: var(--info-ink); }
.tag.neutral { background: var(--neutral-bg); color: var(--neutral-ink); }
.grade { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 6px; font-weight: 700; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 20px; align-items: start; }
.scorebar { display: grid; grid-template-columns: 90px 1fr 50px; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.scorebar span.track { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.scorebar span.fill { display: block; height: 8px; background: var(--primary); }
ul.plain { margin: 0; padding-left: 18px; }
.calc th { color: var(--text); font-weight: 500; font-size: 14px; white-space: normal; }
.calc td, .calc th { padding: 10px 20px; border-top: 1px solid var(--line); }
.calc tr.sum th, .calc tr.sum td { font-weight: 700; background: var(--primary-soft); }
.neg { color: var(--bad); }
.log { white-space: pre-wrap; font-family: var(--mono); font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; max-height: 360px; overflow: auto; }
dialog { border: 0; border-radius: 12px; padding: 0; width: min(760px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 8px 32px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(0,0,0,.3); }
.dlg { padding: 24px; display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 48px); overflow: auto; }
.req { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.drop { border: 2px dashed var(--line-strong); border-radius: 8px; padding: 28px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.drop.over { border-color: var(--primary); background: var(--primary-soft); }
.form { display: grid; gap: 14px; max-width: 560px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.form input { width: 100%; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #2F2F2F; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
.sr { position: absolute; left: -9999px; }
.navlinks { display: flex; flex-direction: column; gap: 4px; }
.navlink { display: flex; align-items: center; gap: 10px; }
.navlink .ni { flex: none; opacity: .8; }
.navlink.active .ni { opacity: 1; }

/* ---------------------------------------------------------------- Handy (Konzept: Navigation unten, Karten statt Tabellen) */
/* Nur Handy: Karten, „Mehr“, Auswahlleiste, ⋯-Knopf */
.navlink.mob, .mcards, #selbar, .more-btn { display: none; }
.actionbar .extra { display: contents; }
.more-list { display: flex; flex-direction: column; }
.more-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; padding: 10px 16px; border: 0; border-top: 1px solid var(--line); background: none; color: var(--text); text-decoration: none; text-align: left; font: inherit; cursor: pointer; }
.more-item:first-child { border-top: 0; }
.more-item > span { display: flex; flex-direction: column; gap: 2px; }
.pos { color: var(--link); }

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .side { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; gap: 10px; padding: 8px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0; gap: 0; font-size: 0; }
  #global-search { flex: 1; padding: 0 !important; }
  .side-foot { display: none; }
  .navlinks { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 4px 2px calc(4px + env(safe-area-inset-bottom)); }
  .navlink { flex-direction: column; justify-content: center; gap: 2px; min-height: 54px; padding: 4px 0; font-size: 10.5px; font-weight: 500; border-radius: 8px; text-align: center; color: var(--muted); }
  .navlink span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .navlink:hover { background: none; }
  .navlink.active { background: none; color: var(--primary-ink); font-weight: 600; }
  .navlink.active .ni { background: var(--primary-soft); border-radius: 14px; width: 48px; height: 26px; padding: 3px 0; }
  main { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); gap: 16px; }
  h1 { font-size: 24px; }
  select, input[type=text], input[type=email], input[type=tel], input[type=number], input[type=password], input[type=search], input[type=date] { height: 44px; font-size: 16px; }
  textarea { font-size: 14px; }
  .btn { height: 44px; }
  .btn.small { height: 36px; }
  .head { align-items: stretch; }
  .head .row-actions, .bar .row-actions { width: 100%; }
  .head .row-actions label, .bar .row-actions label { flex: 1 1 100%; display: flex; align-items: center; gap: 8px; }
  .head .row-actions select, .bar .row-actions select, .bar .row-actions input { flex: 1; width: auto !important; min-width: 0; }
  .head .row-actions .btn { flex: 1 1 auto; justify-content: center; }
  .kpis { display: flex; overflow-x: auto; gap: 10px; margin: 0 -16px; padding: 0 16px 2px; scroll-snap-type: x mandatory; scrollbar-width: none; }
  .kpi { flex: 0 0 72%; scroll-snap-align: start; padding: 12px 14px; }
  .kpi b { font-size: 22px; }
  .tabs { overflow-x: auto; padding: 6px 8px 0; scrollbar-width: none; }
  .tab { flex: none; white-space: nowrap; height: 44px; padding: 0 12px; }
  .bar { padding: 12px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; width: calc(100% + 24px); margin: 0 -12px; padding: 0 12px 2px; scrollbar-width: none; }
  .chip-btn { flex: none; height: 40px; }
  .card-pad { padding: 14px 16px; }
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  .card { min-width: 0; }
  .mono, .card-pad, .small { overflow-wrap: anywhere; }
  select { max-width: 100%; }
  .head .row-actions label, .bar .row-actions label { min-width: 0; }
  .form { max-width: none; }

  /* Tabellen werden Karten; Beschriftung je Feld kommt aus der Kopfzeile (data-label, gesetzt in app.js) */
  .tablewrap { overflow: visible; }
  main table:not(.calc), main table:not(.calc) > tbody, main table:not(.calc) > tbody > tr, main table:not(.calc) > tbody > tr > td { display: block; width: auto; }
  main table:not(.calc) > thead { display: none; }
  main table:not(.calc) > tbody > tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 10px 12px; padding: 6px 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
  main table:not(.calc) > tbody > tr > td { border-top: 0; padding: 6px 14px !important; min-width: 0; max-width: none !important; text-align: left; overflow-wrap: anywhere; }
  main table:not(.calc) > tbody > tr > td[data-label]::before { content: attr(data-label); display: block; font: 500 11px/1.4 Inter, system-ui, sans-serif; color: var(--muted); }
  main table:not(.calc) > tbody > tr > td.wide, main table:not(.calc) > tbody > tr > td[colspan] { grid-column: 1 / -1; }
  main table:not(.calc) > tbody > tr > td.mini { padding-bottom: 0 !important; }
  main table:not(.calc) > tbody > tr > td.mini + td.mini { text-align: right; }
  main table:not(.calc) > tbody > tr.details { display: block; margin-top: -8px; }
  main table:not(.calc) td input[type=text], main table:not(.calc) td input[type=number], main table:not(.calc) td input[type=date], main table:not(.calc) td select { width: 100% !important; }

  /* Rechenwege: Begriff links, Betrag rechts, Erläuterung darunter */
  .calc, .calc tbody { display: block; }
  .calc tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line); }
  .calc th, .calc td { padding: 0 !important; border: 0 !important; }
  .calc td:not(.num) { grid-column: 1 / -1; grid-row: 2; font-size: 12px; }
  .calc td:not(.num):empty { display: none; }
  .calc td.num { grid-column: 2; grid-row: 1; }
  .calc tr.sum { background: var(--primary-soft); }

  dialog { width: 100vw; max-width: 100vw; height: 100%; max-height: 100%; margin: 0; border-radius: 0; }
  .dlg { max-height: 100vh; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
  .drop { padding: 20px 16px; }
  #toast { bottom: calc(80px + env(safe-area-inset-bottom)); }

  /* Konzept „ImmoControl Mobile“: kompakter Kopf, 5 Ziele unten, Karten, Kennzahlen 2×2 */
  .side { flex: none; }
  .navlink.desk { display: none; }
  .navlink.mob { display: flex; }
  .navlinks { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; margin: 0; padding: 0; gap: 10px; }
  .kpis .kpi { flex: none; min-width: 0; overflow-wrap: anywhere; }
  .kpis .kpi b { font-size: 20px; }
  .kpis.scroll { display: flex; overflow-x: auto; margin: 0 -16px; padding: 0 16px 2px; }
  .kpis.scroll .kpi { flex: 0 0 140px; padding: 10px 12px; gap: 2px; }
  .kpis.scroll .kpi > span:last-child:not(:first-child) { display: none; }
  .head h1 { font-size: 22px; line-height: 1.25; }

  .tablewrap:has(+ .mcards) { display: none; }
  .mcards { display: flex; flex-direction: column; gap: 12px; list-style: none; margin: 0; padding: 12px; }
  .mcard { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; }
  .mcard.sel { border-color: #6BB030; }
  .mc-top { display: flex; gap: 12px; padding: 14px 14px 10px; }
  .mc-left { flex: none; display: flex; flex-direction: column; align-items: center; gap: 6px; }
  .ring { width: 44px; height: 44px; border-radius: 22px; border: 3px solid var(--primary); box-sizing: border-box; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-weight: 500; font-size: 15px; }
  .ring.mid { border-color: #EBA33B; }
  .mc-check { width: 44px; height: 28px; display: flex; align-items: center; justify-content: center; }
  .mc-check input { width: 20px; height: 20px; accent-color: var(--primary); }
  .mc-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
  .mc-title { color: var(--text); text-decoration: none; font-weight: 600; font-size: 15px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .mc-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 2px; }
  .mc-nums { margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); }
  .mc-nums > div { padding: 10px 12px; border-left: 1px solid var(--line); min-width: 0; }
  .mc-nums > div:first-child { border-left: 0; }
  .mc-nums dt { font-size: 11px; color: var(--muted); }
  .mc-nums dd { margin: 0; font-family: var(--mono); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mc-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 6px 2px 14px; border-top: 1px solid var(--line); }
  .mc-more { height: 44px; display: flex; align-items: center; gap: 4px; padding: 0 8px; font-weight: 600; font-size: 13px; text-decoration: none; flex: none; }

  #selbar { position: fixed; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 35; background: #2F2F2F; color: #FFFFFF; border-radius: 12px; padding: 8px 8px 8px 16px; align-items: center; gap: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.25); }
  #selbar.show { display: flex; }
  #selbar span { flex: 1; font-weight: 600; }

  /* Objekt-Detail: feste Aktionsleiste statt Navigation, höchstens zwei Aktionen + ⋯ */
  body.detail .navlinks { display: none; }
  body.detail main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .head .row-actions.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; width: auto; flex-wrap: nowrap; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
  .head .actionbar #contact-one { flex: 1; }
  .head .actionbar .more-btn { display: inline-flex; flex: none; width: 52px; justify-content: center; font-size: 20px; }
  .actionbar .extra { display: none; }
  .actionbar.open .extra { display: flex; flex-direction: column; gap: 10px; position: absolute; left: 16px; right: 16px; bottom: calc(100% + 8px); padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,0.18); }
  .actionbar.open .extra label { display: flex; align-items: center; gap: 8px; }
  .actionbar.open .extra select { flex: 1; }
  .actionbar.open .extra .btn { justify-content: center; }
}
