/* ── FONTS ─────────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;600&family=IBM+Plex+Sans:ital,wght@0,300;0,400;0,500;1,300&display=swap');

/* ── VARIABLES ──────────────────────────────────────────────────────────────── */
:root {
  /* Strukturelle Tokens */
  --bg:      #f7f8fa;
  --bg2:     #ffffff;
  --border:  #e1e5eb;
  --border2: #c8cfd8;
  --text:    #1a2535;
  --muted:   #6b7a8d;
  --dim:     #a0aab8;
  --accent:    #2e8878;
  --active:   #d4a020;
  --archived: #888;
  --blue1:   #1a2535;
  --blue2:   #2d4a70;
  --blue3:   #3d6b9a;
  --blue4:   #5a8fb8;
  --blue5:   #83b0d0;
  --blue6:   #aecde2;

  /* Semantische Farben (Zustand/Ampel) */
  --col-ok:    #5acc7a;
  --col-warn:  #e07848;
  --col-err:   #b03030;
  --col-mid:   #d4a030;
  --col-info:  #7898b8;
  --col-empty: #d4dde5;

  /* Mietkomponenten-Palette (zentral für Charts) */
  --rent-kalt:     #2d4a70;
  --rent-nk:       #5a8fb8;
  --rent-hk:       #c87040;
  --rent-wbs:      #9a6810;
  --rent-wbs-warm: #d4a030;

  /* Tooltip */
  --tooltip-bg:   #1a2535;
  --tooltip-text: #e8edf4;

  /* WBG-Unternehmensfarben — Fallbacks für CSS-only-Kontexte (ohne constants.js).
     Autoritäre Quelle: COMPANY_COLORS / COMPANY_COLORS_DARK in constants.js — synchron halten. */
  --co-degewo:         #192e52;
  --co-howoge:         #1c6070;
  --co-gewobag:        #3260b0;
  --co-stadt-und-land: #2e8878;
  --co-gesobau:        #5e4ea8;
  --co-wbm:            #4e98cc;
  --co-berlinovo:      #558040;

  /* Moderner 3-Stop-Verlauf: GESOBAU-Lila → STADT UND LAND-Teal → WBM-Blau */
  --wbg-gradient-cool: linear-gradient(135deg, #5e4ea8 0%, #2e8878 50%, #4e98cc 100%);
  /* Logo, Seiten-Titel und Nav-Active teilen denselben Verlauf */
  --wbg-gradient: var(--wbg-gradient-cool);
}

/* ── DARK MODE ──────────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #0d1820;
    --bg2:     #121d2b;
    --border:  #1e3045;
    --border2: #3a5878;
    --text:    #f0f5fd;
    --muted:   #a0b8d0;
    --dim:     #6882a0;
    --accent:   #3aae98;
    --archived: #4a6070;
    --blue3:   #4a82b8;
    --blue4:   #6aaad0;
    --col-err:   #d04040;
    --col-mid:   #c8a030;
    --col-info:  #7aabb8;
    --col-empty: #1e3045;
    --tooltip-bg:   #07101a;
    --tooltip-text: #d8e8f8;
    --wbg-gradient-cool: linear-gradient(135deg, #8070d0 0%, #3aae98 50%, #6ab8e8 100%);
  }
  /* Leaflet-Karte invertieren für Dark Mode */
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.88); }
}
/* Manueller Toggle überschreibt immer die Media Query */
:root[data-theme="dark"] {
  --bg:      #0d1820;
  --bg2:     #121d2b;
  --border:  #1e3045;
  --border2: #3a5878;
  --text:    #f0f5fd;
  --muted:   #a0b8d0;
  --dim:     #6882a0;
  --accent:   #3aae98;
  --archived: #4a6070;
  --blue3:   #4a82b8;
  --blue4:   #6aaad0;
  --col-err:   #d04040;
  --col-mid:   #c8a030;
  --col-info:  #7aabb8;
  --col-empty: #1e3045;
  --tooltip-bg:   #07101a;
  --tooltip-text: #d8e8f8;
  --wbg-gradient-cool: linear-gradient(135deg, #8070d0 0%, #3aae98 50%, #6ab8e8 100%);
}
:root[data-theme="dark"] .leaflet-tile-pane  { filter: invert(1) hue-rotate(180deg) brightness(0.88); }
:root[data-theme="light"] .leaflet-tile-pane { filter: none; }
:root[data-theme="light"] {
  --bg:      #f7f8fa;
  --bg2:     #ffffff;
  --border:  #e1e5eb;
  --border2: #c8cfd8;
  --text:    #1a2535;
  --muted:   #6b7a8d;
  --dim:     #a0aab8;
  --accent:   #2e8878;
  --archived: #888;
  --blue3:   #3d6b9a;
  --blue4:   #5a8fb8;
  --col-err:   #b03030;
  --col-mid:   #d4a030;
  --col-info:  #7898b8;
  --col-empty: #d4dde5;
  --tooltip-bg:   #1a2535;
  --tooltip-text: #e8edf4;
}

/* ── RESET ──────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 300;
  line-height: 1.65;
  min-height: 100vh;
}

/* ── MOBILE TYPOGRAPHY ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Leicht größere Basis → alle rem-Werte skalieren mit */
  html { font-size: 17px; }
  /* Light (300) ist auf kleinen Displays schwer lesbar */
  body { font-weight: 400; }
}

/* ── HEADER ─────────────────────────────────────────────────────────────────── */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}
.site-title span {
  background: var(--wbg-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

header a.nav {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .68rem;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border2);
  border-radius: 3px;
  padding: .2rem .55rem;
  transition: border-color .12s;
  white-space: nowrap;
}
header a.nav:hover {
  color: var(--text);
  border-color: var(--muted);
}
header a.nav.nav-active {
  background-image: var(--wbg-gradient-cool);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  border-color: transparent;
  position: relative;
}
/* Gradient-Rahmen via Mask-Trick (erhält border-radius) */
header a.nav.nav-active::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 3px;
  padding: 1px;
  background: var(--wbg-gradient-cool);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: destination-out;
  mask-composite: exclude;
  pointer-events: none;
}

.db-status {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .65rem;
  color: var(--dim);
}

/* ── BUTTONS ────────────────────────────────────────────────────────────────── */
.btn-row {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: 1.2rem;
}

.btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .03em;
  padding: .5rem 1rem;
  border-radius: 4px;
  text-decoration: none;
  border: 1px solid;
  transition: all .12s;
  display: inline-block;
  cursor: pointer;
  background: transparent;
}

.btn-primary {
  background: var(--blue3);
  color: #ffffff;
  border-color: var(--blue3);
}
.btn-primary:hover { background: var(--blue2); border-color: var(--blue2); }
.btn-primary:disabled { opacity: .4; cursor: default; }

.btn-ghost {
  color: var(--muted);
  border-color: var(--border2);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text); }
.btn-ghost:disabled { opacity: .4; cursor: default; }

/* ── BAR CHART ──────────────────────────────────────────────────────────────── */
.bar-list {
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 130px 1fr auto;
  align-items: center;
  gap: .6rem;
}

.bar-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .7rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  background: var(--border);
  border-radius: 2px;
  height: 9px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 2px;
}

.bar-val {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .68rem;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}

/* ── STATS GRID ─────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

@media (max-width: 520px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

.stat-cell {
  background: var(--bg2);
  padding: .9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
  position: relative;
}

.stat-bar-wrap {
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  overflow: hidden;
  margin: .3rem 0 .05rem;
}
.stat-bar {
  height: 100%;
  border-radius: 1px;
  width: 0%;
  transition: width .5s ease;
}

.stat-val {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

.stat-key {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .58rem;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.stat-sub {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .56rem;
  color: var(--dim);
  opacity: .7;
  line-height: 1.3;
  margin-top: .1rem;
}

/* ── PANEL LABEL ────────────────────────────────────────────────────────────── */
.panel-label, .card-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .6rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
}
.panel-label::after, .card-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── META / NOTE ────────────────────────────────────────────────────────────── */
.meta, .chart-note {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .6rem;
  color: var(--dim);
  margin-top: .5rem;
  line-height: 1.6;
}

/* ── FOOTER ─────────────────────────────────────────────────────────────────── */
footer {
  max-width: 960px;
  margin: 1.5rem auto 0;
  padding: 0 1.5rem 2.5rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: .62rem;
  color: var(--dim);
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}
footer a { color: var(--dim); text-decoration: none; }
footer a:hover { color: var(--muted); }

/* ── MAP FRAME CONTAINER (lor-detail, bezirk-detail) ──────────────────────── */
.map-frame-container {
  position: relative;
  margin-bottom: .8rem;
}
.map-frame-container iframe {
  width: 100%; height: 380px; display: block;
  border: 1px solid var(--border); border-radius: 6px;
  transition: height .3s ease;
}
.map-frame-container.expanded iframe { height: 70vh; }
.map-expand-btn {
  position: absolute; bottom: -1px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: .3rem;
  background: var(--bg2); border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 8px 8px; padding: .22rem 1rem;
  cursor: pointer; font-family: 'IBM Plex Mono', monospace; font-size: .6rem;
  color: var(--dim); white-space: nowrap; line-height: 1;
}
.map-expand-btn:hover { color: var(--text); }
.map-expand-btn .arr { transition: transform .2s; display: flex; }
.map-frame-container.expanded .map-expand-btn .arr { transform: rotate(180deg); }

/* ── DUMBBELL ZOOM BUTTONS ─────────────────────────────────────────────────── */
.db-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .7rem;
  font-weight: 600;
  width: 22px;
  height: 22px;
  border: 1px solid var(--border2);
  border-radius: 3px;
  background: var(--bg2);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  opacity: .85;
}
.db-btn:hover { color: var(--text); border-color: var(--blue3); opacity: 1; }

.db-axis-lbl {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .55rem;
  font-weight: 600;
  color: var(--dim);
  line-height: 22px;
}

/* ── DATE FILTER INPUT (map.html sidebar) ──────────────────────────────────── */
.date-filter-wrap { display: flex; flex-direction: column; gap: .3rem; }
.date-filter-wrap label {
  font-family: 'IBM Plex Mono', monospace; font-size: .6rem; color: var(--dim);
}
.date-input {
  display: block; width: 100%; margin-top: .12rem;
  padding: .26rem .4rem;
  font-family: 'IBM Plex Mono', monospace; font-size: .67rem;
  border: 1px solid var(--border2); border-radius: 3px;
  background: var(--bg); color: var(--text); outline: none;
}
.date-input:focus { border-color: var(--blue3); }

/* ── CHART COMPONENTS (lor-charts.js) ──────────────────────────────────────── */
/* Donut */
.donut-wrap   { display:flex; align-items:center; gap:1rem; }
.donut-legend { flex:1; display:flex; flex-direction:column; gap:.3rem; }
.leg-row  { display:flex; align-items:center; gap:.4rem; font-family:'IBM Plex Mono',monospace; font-size:.62rem; color:var(--muted); }
.leg-dot  { width:10px; height:10px; border-radius:2px; flex-shrink:0; }

/* Room bars */
.room-chart { display:flex; flex-direction:column; gap:.32rem; }
.room-row   { display:flex; align-items:center; gap:.5rem; font-family:'IBM Plex Mono',monospace; font-size:.63rem; }
.room-lbl   { width:2.4rem; text-align:right; color:var(--muted); flex-shrink:0; }
.room-track { flex:1; display:flex; gap:2px; cursor:default; }
.room-seg   { height:13px; border-radius:2px; }
.room-count { color:var(--dim); font-size:.6rem; min-width:2.5rem; }

/* Chart container + legend */
.chart-wrap   { overflow-x:auto; margin-bottom:.8rem; }
.chart-legend { display:flex; flex-wrap:wrap; gap:.6rem; margin-top:.5rem; }
.leg-item     { display:flex; align-items:center; gap:.3rem; font-size:.6rem; color:var(--muted); font-family:'IBM Plex Mono',monospace; }

/* Mietspiegel comparison */
.ms-grid  { display:grid; grid-template-columns:1fr 1fr 1fr; gap:.6rem; }
@media (max-width:500px) { .ms-grid { grid-template-columns:1fr; } }
.ms-card  { background:var(--bg); border:1px solid var(--border); border-radius:6px; padding:.65rem .8rem; text-align:center; }
.ms-val   { font-family:'IBM Plex Mono',monospace; font-size:1.2rem; font-weight:700; }
.ms-lbl   { font-size:.6rem; color:var(--dim); margin-top:.15rem; }
.ms-sub   { font-size:.62rem; color:var(--muted); margin-top:.25rem; }
.ms-bar-wrap { height:5px; background:var(--border); border-radius:3px; margin:.45rem 0 .2rem; overflow:hidden; }
.ms-bar   { height:100%; border-radius:3px; }

/* ── LOADING / ERROR STATES ─────────────────────────────────────────────────── */
#loading {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--muted);
  font-family: 'IBM Plex Mono', monospace;
  font-size: .8rem;
}
#error {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--col-warn);
  font-family: 'IBM Plex Mono', monospace;
  font-size: .8rem;
  display: none;
}

/* ── DETAIL PAGE COMMONS ────────────────────────────────────────────────────── */
/* Gemeinsame Typografie-Bausteine für alle Detail- und Übersichtsseiten.
   Seiten können einzelne Eigenschaften per-page überschreiben. */

.page-lead {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .7rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: .7rem;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: .8rem;
}
.back-link:hover { color: var(--text); }

.section-head {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .65rem;
  font-weight: 600;
  color: var(--dim);
  letter-spacing: .1em;
  text-transform: uppercase;
  margin: 1.2rem 0 .6rem;
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--border);
}

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .9rem 1rem;
}

.card-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: .6rem;
  font-weight: 600;
  color: var(--dim);
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: .7rem;
}

.tile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .8rem;
  margin-bottom: .8rem;
}
@media (max-width: 600px) { .tile-grid { grid-template-columns: 1fr; } }

#wdt-tip .tip-sub { color: var(--col-info); font-size: .65rem; }

/* ── TOOLTIP (#wdt-tip) ────────────────────────────────────────────────────── */
#wdt-tip {
  position: fixed; z-index: 9999; display: none; pointer-events: none;
  background: var(--tooltip-bg); color: var(--tooltip-text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: .7rem; padding: .45rem .6rem; border-radius: 4px;
  border: 1px solid var(--border2);
  max-width: 220px; line-height: 1.5;
}
#wdt-tip b { color: var(--tooltip-text); font-size: .75rem; }

/* ── PAGE TITLE (alle Unterseiten) ────────────────────────────────────────── */
.page-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: .3rem;
}
.page-title span {
  background: var(--wbg-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* ── STORY HEAD HIGHLIGHT ──────────────────────────────────────────────────── */
.story-head .hl {
  background: var(--wbg-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* ── STAT PILL (Detail-Seiten) ─────────────────────────────────────────────── */
.stat-pill {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 6px;
  padding: .5rem .9rem; display: flex; flex-direction: column; align-items: center; min-width: 80px;
}
.stat-pill .val  { font-family: 'IBM Plex Mono', monospace; font-size: 1.05rem; font-weight: 600; color: var(--text); }
.stat-pill .lbl  { font-size: .58rem; color: var(--dim); margin-top: .1rem; text-align: center; line-height: 1.3; }
.stat-pill.hl  .val  { color: var(--blue3); }
.stat-pill.act .val  { color: var(--col-ok); }
.stat-pill.warn .val { color: var(--col-warn); }

/* ── ACTIVE CHIPS / TAB BUTTONS (alle Seiten) ─────────────────────────────── */
/* Gemeinsamer Gradient für alle generischen aktiven Tabs.
   .co-chip.active bleibt per-Seite mit var(--co) definiert. */
.chip.active,
.tb-btn.active,
.bez-tab.active {
  background: var(--wbg-gradient-cool);
  border-color: transparent;
  color: #fff;
}

/* ── THEME TOGGLE BUTTON ────────────────────────────────────────────────────── */
.theme-toggle {
  font-size: .85rem;
  background: none;
  border: 1px solid var(--border2);
  border-radius: 3px;
  padding: .1rem .35rem;
  cursor: pointer;
  line-height: 1.4;
  margin-left: auto;
  transition: border-color .12s, opacity .12s;
  flex-shrink: 0;
  opacity: .7;
}
.theme-toggle:hover { opacity: 1; border-color: var(--text); }
