/* ==========================================================================
   Kombinierte Widgets (js/dash/kombi.js): ein Leitwert, Grafik, Nebenwerte.
   Drei Darstellungen je nach Platz, nur über Container Queries (nicht über Größenklassen):
   - kompakt: Wert und Mini-Verlauf
   - normal: Wert, Nebenwerte, Grafik
   - groß: Wert, Nebenwerte, Grafik links, Detailtabelle rechts
   Lädt nach css/system.css.
   ========================================================================== */
.dw-body.kb { container: kb / size; gap: 10px; min-width: 0; }
.kb .wk-kopf { flex: none; }
/* Kopfzeile: Titel bleibt lesbar, Zeitraum und Pfeil erscheinen beim Darüberfahren oder Fokus */
@media (hover: hover) and (pointer: fine) {
  .dw .kb .wk-zeit, .dw .kb .wk-link { opacity: 0; transition: opacity var(--dauer-1) ease; }
  .dw:hover .kb .wk-zeit, .dw:hover .kb .wk-link, .dw:focus-within .kb .wk-zeit, .dw:focus-within .kb .wk-link { opacity: 1; }
}
.kb-haupt { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.kb-haupt > * { flex: none; }
.kb-haupt > .kb-grafik { flex: 1 1 0; }
.kb-leit { display: flex; align-items: center; gap: 14px; min-width: 0; }
.kb-leit-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.kb .kb-wert { font-size: clamp(26px, 8cqw, 40px); font-weight: var(--w-mittel); letter-spacing: -.03em; }
.kb .wk-von { font-size: .46em; font-weight: var(--w-normal); letter-spacing: -.005em; color: var(--ink-3); }
.kb-unter { font-size: var(--t-label); color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kb-chips { display: flex; gap: 6px; flex-wrap: wrap; min-height: 20px; }
.kb-chip {
  display: inline-flex; align-items: center; gap: 3px; height: 20px; padding: 0 7px; border-radius: var(--r-rund);
  background: var(--inset); color: var(--ink-2); font-size: 11.5px; font-weight: var(--w-mittel); font-variant-numeric: tabular-nums; white-space: nowrap; text-decoration: none;
}
.kb-chip.gut { color: var(--pos); background: var(--pos-soft); }
.kb-chip.schlecht { color: var(--neg); background: var(--neg-soft); }
.kb-mini { display: none; flex: 0 1 46%; min-width: 0; height: 44px; }
.kb-mini .spark { width: 100%; height: 100%; display: block; }
.kb-neben { display: flex; gap: 8px 20px; flex-wrap: wrap; margin: 0; }
.kb-neben > div { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.kb-neben dt { font-size: var(--t-label); color: var(--ink-3); white-space: nowrap; }
.kb-neben dd { margin: 0; font-size: var(--t-text); font-weight: var(--w-mittel); color: var(--ink); white-space: nowrap; }
.kb-grafik { min-height: 0; min-width: 0; position: relative; }
.kb-grafik-text { display: flex; flex-direction: column; gap: 10px; overflow: hidden; }
.kb-grafik-liste { gap: 8px; }
.kb-detail { display: none; min-height: 0; min-width: 0; overflow: hidden; }
.kb-sub { margin: 0 0 6px; }
.kb-leer { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; min-height: 0; overflow: hidden; }
.kb-leer .label { margin: 0; }
.kb-hinweis { margin: 0; align-self: center; }

.kb-mit-titel { display: flex; flex-direction: column; gap: 4px; }
.kb-grafik-flaeche { flex: 1 1 0; min-height: 0; position: relative; }
/* kleine Bausteine */
.kb-ring { position: relative; flex: none; display: inline-grid; place-items: center; }
.kb-ring svg { display: block; }
.kb-ring-mitte { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; color: var(--ink); }
.kb-ring-mitte b { font-weight: var(--w-mittel); }
.kb-balken-kopf { display: flex; justify-content: space-between; gap: 8px; }
.kb-balken-kopf b { font-weight: var(--w-mittel); color: var(--ink); }
.kb-balken { height: 6px; border-radius: var(--r-rund); background: var(--track); overflow: hidden; }
.kb-balken i { display: block; height: 100%; border-radius: var(--r-rund); background: var(--chart-farbe, var(--reihe-1)); transform-origin: left; animation: kb-wachsen var(--dauer-3) var(--ease-out) both; }
@keyframes kb-wachsen { from { transform: scaleX(.2); opacity: .4; } }
.kb-balken-fuss { color: var(--ink-3); }

/* Zeitleiste */
.kb-zl-titel { margin: 0; }
.kb-zl { display: flex; flex-direction: column; gap: 6px; padding-top: 6px; }
.kb-zl-achse { position: relative; height: 2px; margin: 6px 6px; border-radius: var(--r-rund); background: var(--track); }
.kb-zl-punkt {
  position: absolute; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: var(--r-rund);
  background: var(--reihe-1); box-shadow: 0 0 0 2px var(--card); transition: transform var(--dauer-1) var(--ease-out);
}
.kb-zl-punkt::after { content: ""; position: absolute; inset: -8px; }
.kb-zl-punkt.warn { background: var(--warn-fill); }
.kb-zl-punkt.ueber { background: var(--neg-fill); }
@media (hover: hover) and (pointer: fine) { .kb-zl-punkt:hover { transform: scale(1.3); } }
.kb-zl-punkt:focus-visible { outline: none; box-shadow: var(--ring); }
.kb-zl-heute { position: absolute; top: -4px; width: 1px; height: 10px; background: var(--ink-3); }
.kb-zl-text { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* Tabellen in Widgets */
.kb-tab { display: flex; flex-direction: column; min-width: 0; }
.kb-tab-kopf, .kb .kb-tab-zeile { display: grid; grid-template-columns: minmax(0, 1.25fr) repeat(calc(var(--sp) - 1), minmax(0, 1fr)); gap: 8px; align-items: center; }
.kb-tab-kopf { padding-bottom: 4px; font-size: 11px; color: var(--ink-3); }
.kb .kb-tab-zeile { min-height: 30px; padding: 0; border-top: 1px solid var(--line); color: var(--ink); font-size: 12.5px; text-decoration: none; }
.kb-tab-kopf span:not(:first-child), .kb-tab-zeile > span:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.kb-tab-zeile > span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.kb-tab-zeile b { font-weight: var(--w-mittel); }
.kb-tab-zeile .chip { float: right; }
@media (hover: hover) and (pointer: fine) { a.kb-tab-zeile:hover, a.kb-immo:hover { background: var(--hover); } }
.kb-spark { display: inline-block; width: 100%; max-width: 80px; height: 22px; }
.kb-spark .spark { width: 100%; height: 100%; display: block; }

/* Portfolio */
.kb-immo-kopf, .kb .kb-immo { display: grid; grid-template-columns: minmax(0, 1fr) 80px 64px 64px; gap: 12px; align-items: center; }
.kb-immo-kopf { font-size: 11px; color: var(--ink-3); }
.kb-immo-kopf span:nth-child(n+3), .kb-immo-wert, .kb-immo-cf { text-align: right; }
.kb .kb-immo { flex: none; min-height: 40px; padding: 4px 0; border-top: 1px solid var(--line); color: var(--ink); font-size: var(--t-klein); text-decoration: none; }
.kb-immo-text { display: flex; flex-direction: column; min-width: 0; }
.kb-immo-text b { font-weight: var(--w-mittel); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.kb-immo-text .label { font-size: 11.5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.kb-immo-wert { font-weight: var(--w-mittel); }
.kb-immo-cf { color: var(--ink-2); }
.kb-immo-cf.neg { color: var(--neg); }

/* Score */
.kb-aspekte { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px 16px; }
.kb-aspekt { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kb-aspekt .label { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kb-aspekt-bar { display: block; height: 3px; border-radius: var(--r-rund); background: var(--track); overflow: hidden; }
.kb-aspekt-bar i { display: block; height: 100%; border-radius: var(--r-rund); background: var(--chart-farbe, var(--reihe-1)); }
.kb .kb-hinweis-zeile { display: flex; align-items: center; justify-content: flex-start; gap: 10px; min-height: 32px; font-size: var(--t-klein); cursor: pointer; }
.kb .kb-hinweis-zeile .wk-reihe-name { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kb-hinweis-zeile input { flex: none; width: 16px; height: 16px; accent-color: var(--accent); }

/* Kacheln (Treemap): Tönung nach Anteil */
.kb-treemap { position: relative; width: 100%; height: 100%; min-height: 0; overflow: hidden; }
.kb-kachel {
  position: absolute; display: flex; flex-direction: column; gap: 1px; padding: 8px 10px; overflow: hidden; border-radius: var(--r-klein);
  background: color-mix(in srgb, var(--kachel-farbe) var(--ton, 40%), var(--inset)); color: var(--ink); text-decoration: none;
  transition: filter var(--dauer-1) ease;
}
@media (hover: hover) and (pointer: fine) { a.kb-kachel:hover { filter: brightness(1.08); } }
.kb-kachel:focus-visible { outline: none; box-shadow: var(--ring); }
.kb-kachel.ein { animation: kachel-ein var(--dauer-3) var(--ease-out) both; }
@keyframes kachel-ein { from { opacity: 0; transform: scale(.97); } }
.kb-kachel-name { font-size: 12px; font-weight: var(--w-mittel); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kb-kachel-wert { font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--ink); }
.kb-kachel.klein { padding: 4px 6px; }
.kb-kachel.klein .kb-kachel-wert { display: none; }

/* ---------- Normal, aber wenig Höhe: die Nebenwerte weichen zuerst ---------- */
@container kb (max-height: 250px) {
  .kb-haupt { gap: 8px; }
  .kb .kb-wert { font-size: clamp(24px, 7cqw, 32px); }
  .kb-neben { font-size: var(--t-klein); }
  .kb-immo-kopf { display: none; }
  .kb-grafik-liste .kb-zl { display: none; }
}
/* ---------- Kompakt: Wert und Mini-Verlauf ---------- */
@container kb (max-height: 170px) {
  .kb-haupt { flex-direction: row; align-items: center; }
  .kb-haupt > .kb-leit { flex: 1 1 0; }
  .kb-neben, .kb-grafik, .kb-detail { display: none; }
  .kb-mini { display: block; }
  .kb-ring { display: none; }
}
@container kb (max-height: 170px) and (min-width: 460px) {
  .kb-neben { display: flex; flex-wrap: nowrap; }
}
@container kb (max-width: 300px) and (max-height: 340px) {
  .kb-grafik { display: none; }
  .kb-mini { display: block; flex-basis: 100%; }
  .kb-leit { flex-wrap: wrap; }
  .kb-ring { display: none; }
}
@container kb (max-width: 300px) {
  .kb-immo-kopf, .kb .kb-immo { grid-template-columns: minmax(0, 1fr) 64px; }
  .kb-immo-kopf span:nth-child(2), .kb-immo-kopf span:nth-child(4), .kb .kb-immo .kb-spark, .kb .kb-immo .kb-immo-cf { display: none; }
}
/* Kompakt bleibt immer einzeilig: Wert links, Mini-Verlauf rechts */
@container kb (max-height: 170px) {
  .kb-leit { flex-wrap: nowrap; }
  .kb-mini { flex: 0 1 42%; }
  .kb-unter { display: none; }
}
@container kb (max-height: 110px) { .kb-chips { display: none; } }
/* ---------- Breit und niedrig: links Wert und Nebenwerte, rechts die Grafik ---------- */
@container kb (min-width: 560px) and (min-height: 171px) and (max-height: 280px) {
  .kb-haupt { display: grid; grid-template-columns: minmax(240px, 2fr) minmax(0, 3fr); grid-template-rows: auto minmax(0, 1fr); column-gap: 20px; }
  .kb-leit { grid-column: 1; grid-row: 1; }
  .kb-neben { grid-column: 1; grid-row: 2; align-self: end; }
  .kb-grafik { grid-column: 2; grid-row: 1 / -1; }
}
/* ---------- Groß: Grafik und Detailtabelle nebeneinander ---------- */
@container kb (min-width: 680px) and (min-height: 281px) {
  .kb-haupt:has(> .kb-detail) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 40%); grid-template-rows: auto auto minmax(0, 1fr); column-gap: 28px; }
  .kb-haupt:has(> .kb-detail) > .kb-leit { grid-column: 1; grid-row: 1; }
  .kb-haupt:has(> .kb-detail) > .kb-neben { grid-column: 1; grid-row: 2; }
  .kb-haupt:has(> .kb-detail) > .kb-grafik { grid-column: 1; grid-row: 3; }
  .kb-detail { display: block; grid-column: 2; grid-row: 1 / -1; }
  .kb .kb-wert { font-size: clamp(32px, 4.6cqw, 44px); }
}
/* ---------- Listen-Widgets (Portfolio, Fristen): kleiner Leitwert, die Liste ist der Inhalt ---------- */
.kb-liste .kb-wert { font-size: clamp(24px, 5cqw, 30px); }
.kb-liste .kb-leit-text { flex-direction: row; align-items: center; gap: 10px; flex-wrap: wrap; }
.kb-liste .kb-haupt { gap: 8px; }
.kb-liste .kb-neben { display: none; }
@container kb (min-height: 400px) { .kb-liste .kb-neben { display: flex; } }
.kb .kb-fristen { gap: 2px; }
/* ---------- Score: die Hinweise stehen darunter, sobald Platz ist ---------- */
@container kb (min-height: 240px) and (max-width: 679px) {
  .kb-unten .kb-haupt > .kb-grafik { flex: none; }
  .kb-unten .kb-detail { display: block; flex: 1 1 0; }
}
/* ---------- Handy: Höhe aus dem Inhalt (kein Leerraum, nichts abgeschnitten), Diagramme bekommen feste Höhe ---------- */
@media (max-width: 760px) {
  #dashGrid > .dw:has(> .kb) { min-height: 0; }
  #dashGrid .dw-body.kb { container: kb / inline-size; }
  #dashGrid .kb-haupt > .kb-grafik { flex: none; }
  #dashGrid .kb-grafik:not(.kb-grafik-text) { height: 200px; }
  #dashGrid .kb-unten .kb-detail { display: block; }
  #dashGrid .kb-fristen .wk-frist:nth-child(n+5) { display: none; }
  #dashGrid .kb .kb-treemap { height: 220px; }
  /* Miniaturen und Vorschauen zeigen auch am Handy das Computer-Raster */
  .tpl-buehne .dash2.raster { grid-template-columns: repeat(24, minmax(0, 1fr)); grid-auto-rows: 16px; gap: 12px; }
  .tpl-buehne .dash2.raster > .dw { min-height: 0; padding: 18px 20px; }
}
@container kb (max-width: 420px) {
  .kb-immo-kopf, .kb .kb-immo { grid-template-columns: minmax(0, 1fr) 64px 56px; gap: 8px; }
  .kb-immo-kopf span:nth-child(2), .kb .kb-immo .kb-spark { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .kb-balken i, .kb-kachel.ein { animation: none; }
  .kb-zl-punkt { transition: none; }
}
html.ohne-bewegung .kb-balken i, html.ohne-bewegung .kb-kachel.ein { animation: none; }

/* ---------- Skelett: Form des späteren Inhalts mit ruhigem Schimmer ---------- */
.skelett { position: relative; display: flex; flex-direction: column; gap: 10px; width: 100%; height: 100%; padding: 2px; overflow: hidden; }
.skelett i { display: block; height: 10px; border-radius: var(--r-klein); background: var(--inset); }
.skelett i:nth-child(1) { width: 40%; }
.skelett i:nth-child(2) { width: 62%; height: 22px; }
.skelett i:nth-child(3) { flex: 1; width: 100%; min-height: 20px; }
.skelett::after {
  content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 20%, var(--hover) 50%, transparent 80%);
  transform: translateX(-100%); animation: schimmer 1.6s linear infinite;
}
@keyframes schimmer { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .skelett::after { animation: none; display: none; } }
html.ohne-bewegung .skelett::after { display: none; }

/* ---------- Vorlagen: echte Miniaturen (views/dashboard.js miniPlan), Inhalt verkleinert, unten weich ausgeblendet ---------- */
.tpl-echt { position: relative; height: 188px; padding: 0; background: var(--page); overflow: hidden; display: block; pointer-events: none; -webkit-mask-image: linear-gradient(180deg, #000 72%, transparent); mask-image: linear-gradient(180deg, #000 72%, transparent); }
.tpl-buehne { position: absolute; left: 8px; top: 8px; transform-origin: 0 0; }
.tpl-buehne .dash2.raster { margin: 0; }
.tpl-buehne .dw-mehr { display: none; }

/* ---------- Monatskalender (C.monatKalender) in „Fristen und Aufgaben“: dezent, Markierungen als Punkte ---------- */
.kb-mk-kopf { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 6px; }
.kb-kal-legende { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; }
.kb-kal-legende .mk-p { margin-left: 6px; }
.mk { margin-bottom: 10px; width: 100%; }
.mk-kopf, .mk-tage { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.mk-kopf span { font-size: 11px; color: var(--ink-3); text-align: center; padding-bottom: 2px; }
.mk-tag { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 30px; padding: 4px 0 3px; border-radius: var(--r-klein); font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.mk-tag b { font-weight: var(--w-normal); }
.mk-tag.mit { background: var(--inset); color: var(--ink); }
.mk-tag.heute { box-shadow: inset 0 0 0 1px var(--accent); }
.mk-tag.heute b { color: var(--akzent-schrift); font-weight: var(--w-fett); }
.mk-punkte { display: flex; gap: 2px; font-style: normal; }
.mk-p { display: inline-block; width: 6px; height: 6px; border-radius: var(--r-rund); background: var(--ink-2); }
.mk-p.aufgabe { background: transparent; box-shadow: inset 0 0 0 1.5px var(--ink-2); }
.mk-p.miete { border-radius: 0; background: var(--pos); }
.mk-p.warn { background: var(--warn); }
.mk-p.ueber { border-radius: 0; background: var(--crit); transform: rotate(45deg) scale(.9); }
/* Größe S (kompakt): nur der nächste Termin, die Anzahl tritt zurück */
@container kb (max-height: 170px) {
  .kb-fristen-w .kb-anzahl { display: none; }
  .kb-fristen-w .kb-unter { display: block; }
  .kb-fristen-w .kb-unter { font-size: 14px; color: var(--ink); }
  .kb-fristen-w .kb-naechster b { font-size: 18px; font-weight: var(--w-mittel); }
}
.kb-naechster { display: inline; }
/* Betrieb: offene Punkte als Liste */
.kb-betrieb-zeile { display: flex; align-items: center; justify-content: space-between; gap: 10px; text-decoration: none; color: var(--ink); }
.kb-betrieb-verbrauch { display: flex; flex-direction: column; min-height: 0; height: 100%; }
