/* Farben als Variablen: hell als Standard, dunkel per System oder Umschalter */
:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface2: #f0f2f5; --border: #dde1e7;
  --text: #1c2430; --muted: #6a7482; --accent: #2563eb; --accent-soft: #dbe6fd;
  --good: #15803d; --good-soft: #dcf3e3; --warn: #b45309; --warn-soft: #fdf0d5;
  --bad: #b91c1c; --bad-soft: #fbe1e1; --grey: #9aa3ae;
  --c1: #2563eb; --c2: #d97706; --c3: #059669; --c4: #9333ea; --c5: #dc2626;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --surface: #171b21; --surface2: #1f242c; --border: #2c333d;
    --text: #e6e9ee; --muted: #8b95a3; --accent: #5b8cff; --accent-soft: #1d2a4a;
    --good: #4ade80; --good-soft: #14301f; --warn: #fbbf24; --warn-soft: #3a2c10;
    --bad: #f87171; --bad-soft: #3d1a1a; --grey: #6b7480;
    --c1: #5b8cff; --c2: #f59e0b; --c3: #34d399; --c4: #c084fc; --c5: #f87171;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --surface: #171b21; --surface2: #1f242c; --border: #2c333d;
  --text: #e6e9ee; --muted: #8b95a3; --accent: #5b8cff; --accent-soft: #1d2a4a;
  --good: #4ade80; --good-soft: #14301f; --warn: #fbbf24; --warn-soft: #3a2c10;
  --bad: #f87171; --bad-soft: #3d1a1a; --grey: #6b7480;
  --c1: #5b8cff; --c2: #f59e0b; --c3: #34d399; --c4: #c084fc; --c5: #f87171;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 15px; line-height: 1.45;
  overflow-x: hidden;
}
a { color: var(--accent); }
.muted { color: var(--muted); }
.note { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
#topbar h1 { font-size: 17px; margin: 0; }
#topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
#arrange-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Anordnen-Modus (layout.js): Griff ⠿ + gestrichelter Rahmen; Bedienelemente im Inneren ruhen, damit Ziehen überall greift */
body.arrange .tab > *, body.arrange .tiles > * { position: relative; outline: 2px dashed var(--accent); outline-offset: 2px; cursor: grab; touch-action: pan-y; }
body.arrange .tab > *::after, body.arrange .tiles > *::after {
  content: '⠿'; position: absolute; top: 4px; right: 6px; font-size: 16px; line-height: 1; color: var(--accent);
  background: var(--accent-soft); border-radius: 6px; padding: 2px 4px; pointer-events: none; z-index: 500;
}
body.arrange .tab :is(a, button, input, select, textarea, summary, label, canvas, table, .leaflet-container) { pointer-events: none; }
body.arrange .tab .tiles > * { outline-color: var(--c2); }
.dnd-ghost { opacity: .35; }
.dnd-chosen { box-shadow: 0 6px 20px rgba(0, 0, 0, .18); }
#rent-table tr.editing td, #cost-table tr.editing td { background: var(--accent-soft); }
#scan-info { color: var(--muted); font-size: 12px; }
#logout-btn { text-decoration: none; font-size: 18px; color: var(--muted); }

button, .btn {
  background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
input, select {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 8px; font: inherit; font-size: 13px; max-width: 100%;
}

.banner { padding: 8px 16px; font-size: 13px; border-bottom: 1px solid var(--border); }
.banner.ok { background: var(--good-soft); }
.banner.warn { background: var(--warn-soft); }
.banner.bad { background: var(--bad-soft); }
.banner ul { margin: 4px 0 0; padding-left: 18px; }

#tabs {
  display: flex; gap: 4px; padding: 8px 16px 0; overflow-x: auto; background: var(--surface);
  border-bottom: 1px solid var(--border); scrollbar-width: thin;
}
#tabs button {
  border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none;
  padding: 8px 10px; white-space: nowrap; color: var(--muted); font-size: 14px;
}
#tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

#filterbar {
  display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 10px 16px;
  font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border);
}
#filterbar label { display: flex; align-items: center; gap: 6px; }

main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.tab { display: flex; flex-direction: column; gap: 16px; }
.tab[hidden] { display: none; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; min-width: 0; }
.card h2 { font-size: 15px; margin: 0 0 12px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.tile .label { font-size: 12px; color: var(--muted); }
.tile .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile.warn { border-color: var(--warn); }

.verdict { border-radius: 14px; padding: 20px; border: 1px solid var(--border); background: var(--surface); }
.verdict .head { font-size: 13px; color: var(--muted); }
.verdict .big { font-size: 28px; font-weight: 700; margin: 4px 0 6px; line-height: 1.2; }
.verdict .text { font-size: 15px; }
.verdict.good { background: var(--good-soft); border-color: var(--good); }
.verdict.warn { background: var(--warn-soft); border-color: var(--warn); }
.verdict.bad { background: var(--bad-soft); border-color: var(--bad); }
.verdict.unknown { background: var(--surface2); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--surface2); border: 1px solid var(--border); white-space: nowrap; }
.pill.good { color: var(--good); border-color: var(--good); }
.pill.warn { color: var(--warn); border-color: var(--warn); }
.pill.bad { color: var(--bad); border-color: var(--bad); }

/* Preisband-Leiste */
.bandbar { position: relative; height: 74px; margin: 6px 4px 0; }
.bandbar .track { position: absolute; top: 30px; left: 0; right: 0; height: 10px; background: var(--surface2); border-radius: 5px; }
.bandbar .band { position: absolute; top: 26px; height: 18px; background: var(--good-soft); border: 1px solid var(--good); border-radius: 5px; }
.bandbar .tick { position: absolute; top: 22px; width: 2px; height: 26px; background: var(--good); }
.bandbar .own { position: absolute; top: 14px; width: 3px; height: 42px; background: var(--accent); border-radius: 2px; }
.bandbar .lbl { position: absolute; font-size: 12px; color: var(--muted); transform: translateX(-50%); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bandbar .lbl.top { top: 0; color: var(--accent); font-weight: 600; }
.bandbar .lbl.bot { top: 54px; }

.chart-wrap { position: relative; height: 300px; }
.chart-wrap.short { height: 180px; }
.chart-wrap.tall { height: 420px; }
.empty { color: var(--muted); font-size: 14px; padding: 24px 8px; text-align: center; }

.caveats { margin: 0; padding-left: 18px; }
.caveats li { margin: 4px 0; }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; font-size: 13px; }
.controls + .controls { margin-top: 10px; }
.controls label { display: flex; align-items: center; gap: 6px; }
.seg { display: flex; gap: 0; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 8px 0 0 8px; }
.seg button:last-child { border-radius: 0 8px 8px 0; }
.seg button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.table-wrap { overflow-x: auto; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-weight: 600; color: var(--muted); white-space: nowrap; }
table.sortable th[data-key] { cursor: pointer; user-select: none; }
table.sortable th[data-key]:hover { color: var(--text); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface2); }
tr.own td { background: var(--accent-soft); }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 12px; font-size: 13px; }

#comp-map { height: 380px; border-radius: 10px; border: 1px solid var(--border); z-index: 0; }

.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.feed li { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; cursor: pointer; }
.feed .when { color: var(--muted); font-size: 12px; min-width: 92px; }
.feed .what { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px 16px; margin-bottom: 12px; }
.settings-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

#drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1000; }
#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--surface);
  border-left: 1px solid var(--border); z-index: 1001; overflow-y: auto; padding: 16px;
}
#drawer-close { position: absolute; top: 12px; right: 12px; }
#drawer h3 { margin: 0 40px 4px 0; font-size: 16px; }
#drawer .facts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; font-size: 13px; margin: 12px 0; }
#drawer .timeline { list-style: none; padding: 0; margin: 0; font-size: 13px; }
#drawer .timeline li { padding: 6px 0; border-bottom: 1px solid var(--border); }

/* Login */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { font-size: 18px; margin: 0 0 4px; text-align: center; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input { padding: 8px 10px; font-size: 15px; }
.login-error { background: var(--bad-soft); color: var(--bad); padding: 8px; border-radius: 8px; font-size: 13px; }

@media (max-width: 640px) {
  #topbar h1 { font-size: 15px; }
  #scan-info { display: none; }
  .verdict .big { font-size: 22px; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile .value { font-size: 18px; }
  .chart-wrap { height: 260px; }
  #filterbar input[type="date"] { width: 130px; }
}

/* Stadtauswahl, Preisfaktoren-Regler, Städtevergleich */
#city-wrap { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.sub-h { margin: 16px 0 6px; font-size: 15px; }
.stmt { margin: 0 0 8px; font-weight: 600; }
.sliders { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 20px; margin-top: 12px; }
.range2 { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.range2 b { color: var(--text); font-weight: 600; }
.range2 .rr { position: relative; height: 26px; }
.range2 .rr input[type=range] { position: absolute; left: 0; right: 0; width: 100%; top: 4px; margin: 0; padding: 0; border: none; background: none; pointer-events: none; -webkit-appearance: none; appearance: none; }
.range2 .rr input[type=range]::-webkit-slider-thumb { pointer-events: auto; -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); cursor: pointer; }
.range2 .rr input[type=range]::-moz-range-thumb { pointer-events: auto; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: none; cursor: pointer; }
.range2 .rr::before { content: ''; position: absolute; left: 0; right: 0; top: 11px; height: 4px; border-radius: 2px; background: var(--border); }
td.low { color: var(--muted); font-style: italic; }
/* K27 Vermietbarkeit: Heatmap-Zellen nach Urteil */
.sd-table td.sd { vertical-align: top; font-size: 13px; line-height: 1.35; min-width: 120px; }
.sd-table td.sd-good { background: var(--good-soft); }
.sd-table td.sd-medium { background: var(--warn-soft); }
.sd-table td.sd-weak { background: var(--bad-soft); }
.sd-table td.sd-insufficient { background: var(--surface2); }

/* Ankaufsrechner */
.ac-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 16px; }
.ac-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); min-width: 0; }
.ac-grid label.chk { flex-direction: row; align-items: center; align-self: end; padding-bottom: 6px; }
.ac-row { display: flex; gap: 6px; }
.ac-row input { flex: 1; min-width: 0; }
#ac-map { height: 260px; border-radius: 10px; border: 1px solid var(--border); margin-top: 8px; z-index: 0; }
.ac-assume { margin-top: 12px; }
.ac-assume summary { cursor: pointer; font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.ac-table td:nth-child(2) { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; font-weight: 600; }
.ac-table td:nth-child(3) { color: var(--muted); font-size: 12px; }
.ac-table tr.sum td { border-top: 2px solid var(--border); font-size: 14px; }
.ac-table tr.grp td { background: var(--surface2); font-weight: 600; color: var(--text); font-size: 12px; }
.verdict .kpis { display: flex; flex-wrap: wrap; gap: 8px 28px; margin-top: 10px; }
.verdict .kpis div { font-size: 13px; color: var(--muted); }
.verdict .kpis b { display: block; font-size: 22px; color: var(--text); font-variant-numeric: tabular-nums; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* Quelle (Wunderflats / Housing Anywhere) */
.pill.src-wf { background: color-mix(in srgb, var(--c1) 18%, transparent); color: var(--c1); }
.pill.src-ha { background: color-mix(in srgb, var(--c3) 22%, transparent); color: var(--c3); }
#stock-info { font-size: 12px; }
.radius-controls { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-top: 6px; }
.radius-controls input[type="range"] { width: min(260px, 60vw); vertical-align: middle; }

/* ── Standard- vs. Experten-Ansicht (Stand 18.10.2026) ── */
body:not(.expert) .expert-only { display: none !important; }
body.expert .simple-only { display: none !important; }
#expert-wrap { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.tiles4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.tile .expl { margin-top: 6px; font-size: 12px; color: var(--muted); line-height: 1.35; }
abbr.tip { text-decoration: underline dotted; cursor: help; }
details.explain { padding: 10px 16px; }
details.explain summary, #gap-details summary, #ac-detail summary { cursor: pointer; font-weight: 600; font-size: 14px; }
details.explain p { font-size: 14px; line-height: 1.5; margin: 8px 0 0; }
#ac-detail { margin-bottom: 12px; }
.verdict .big.sentence { font-size: 19px; line-height: 1.4; }
@media (max-width: 600px) {
  .tiles4 { grid-template-columns: 1fr 1fr; }
  .verdict .big.sentence { font-size: 16px; }
  #tabs { overflow-x: auto; flex-wrap: nowrap; }
}

/* Eigene Objekte (Stand 18.10.2026): Objektwahl, Objekt ohne Preis/Inserat blendet Urteil bzw. Kalender-Karten aus */
.unit-bar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 10px 14px; }
.unit-bar select { font-weight: 600; }
#tab-own.no-price .needs-price, #tab-own.no-listing .needs-listing { display: none !important; }
.units-table input[type="text"], .units-table input[type="number"] { padding: 3px 5px; }

/* Einnahmen, Kosten, Gewinn (Stand 18.10.2026) */
#profit-table td.pos { color: var(--good, #1a7f37); }
#profit-table td.neg { color: var(--bad, #c62828); }
#profit-table tr.planned td { opacity: .65; font-style: italic; }
#profit-table tr.sum td { font-weight: 600; border-top: 2px solid var(--border, #ccc); }
#profit-tiles .tile.bad .value { color: var(--bad); }
#profit-tiles .tile.good .value { color: var(--good); }
