/* ── Status Pill ────────────────────────────────────────────────────────── */
.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  background: var(--surf);
  border: 1px solid var(--bdr);
  border-radius: var(--r-pill);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
  transition: border-color 0.4s;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  transition: background 0.5s, box-shadow 0.5s;
  flex-shrink: 0;
}

.status-dot.live {
  background: var(--kfw-g-acc);
  box-shadow: 0 0 5px rgba(183, 249, 170, 0.45);
}

.status-dot.stale {
  background: var(--kfw-yel);
  box-shadow: 0 0 5px rgba(234, 200, 11, 0.4);
}

/* ── Poll Countdown ─────────────────────────────────────────────────────── */
.poll-countdown {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--faint);
  min-width: 90px;
  justify-content: flex-end;
}

.poll-countdown__lbl { white-space: nowrap; }

.poll-countdown__val {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 22px;
  text-align: right;
}

/* ── Pause Button ───────────────────────────────────────────────────────── */
.btn-pause {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--bdr);
  border-radius: var(--r-sm);
  background: var(--surf);
  color: var(--muted);
  font-size: 13px;
  transition: all 0.18s;
}

.btn-pause:hover {
  background: var(--surf-h);
  border-color: var(--bdr-b);
  color: var(--text);
}

.btn-pause.paused {
  background: rgba(183, 249, 170, 0.08);
  border-color: rgba(183, 249, 170, 0.28);
  color: var(--kfw-g-acc);
}

/* ── Settings Toggle Button ─────────────────────────────────────────────── */
.btn-settings {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 14px;
  height: 32px;
  border: 1px solid var(--bdr);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.1px;
  transition: all 0.18s;
  white-space: nowrap;
}

.btn-settings:hover {
  background: var(--surf-h);
  border-color: var(--bdr-b);
  color: var(--text);
}

.btn-settings.active {
  background: rgba(96, 165, 250, 0.1);
  border-color: rgba(96, 165, 250, 0.28);
  color: var(--kfw-400);
}

.btn-settings svg {
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.btn-settings.active svg {
  transform: rotate(45deg);
}

/* ── KPI Cards ──────────────────────────────────────────────────────────── */
.kpi-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kpi-card {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(
      155deg,
      color-mix(in srgb, var(--kpi-glow, #60a5fa) 10%, transparent) 0%,
      color-mix(in srgb, var(--kpi-glow, #60a5fa) 3%, transparent) 58%,
      transparent 100%
    ),
    var(--surf);
  border: 1px solid color-mix(in srgb, var(--kpi-glow, #60a5fa) 16%, var(--bdr));
  border-radius: var(--r);
  transition: border-color 0.2s, background 0.2s;
}

/* Soft inner aura + tinted rim on value increase (opacity-only = smooth) */
.kpi-card.kpi-glow-run::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 6;
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--kpi-glow, #60a5fa) 48%, transparent),
    inset 0 0 18px 1px color-mix(in srgb, var(--kpi-glow, #60a5fa) 18%, transparent),
    inset 0 0 8px 0 color-mix(in srgb, var(--kpi-glow, #60a5fa) 10%, transparent);
  opacity: 0;
  animation: a-kpi-inner-glow 2.4s ease-out forwards;
}

.kpi-card:hover {
  background:
    linear-gradient(
      155deg,
      color-mix(in srgb, var(--kpi-glow, #60a5fa) 14%, transparent) 0%,
      color-mix(in srgb, var(--kpi-glow, #60a5fa) 5%, transparent) 58%,
      transparent 100%
    ),
    var(--surf-h);
  border-color: color-mix(in srgb, var(--kpi-glow, #60a5fa) 24%, var(--bdr-b));
}

.kpi-body {
  padding: 10px 13px;
  transition: background 0.6s ease;
  border-radius: var(--r);
}

.kpi-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
  min-height: 1.2em; /* reserve space so delta show/hide doesn't shift the number */
}

.kpi-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);  /* overridden inline per group */
  letter-spacing: 0.1px;
  min-width: 0;
}

.kpi-num-row {
  display: flex;
  align-items: baseline;
}

.kpi-num {
  font-size: 28px;
  font-weight: 600;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  /* Inline layout — avoids baseline recalculation during reel animation */
  white-space: nowrap;
  overflow: hidden;         /* clip digit reels that extend beyond 1em */
}

/* Comparison chip — right-aligned, same size as kpi-num so row height never changes */
.kpi-cmp {
  margin-left: auto;
  font-size: 28px;
  font-weight: 600;
  line-height: 1.15; /* identical to kpi-num so baseline stays locked */
  color: rgba(255, 255, 255, 0.28);
  white-space: nowrap;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.kpi-cmp.visible { opacity: 1; }
/* Keep the ↩ arrow small so only the number reads as a "big figure" */
.kpi-cmp::before {
  content: '↩ ';
  font-size: 0.45em;
  font-weight: 500;
  opacity: 0.6;
  vertical-align: middle;
}

/* Delta badge — sits on the label row, right-aligned */
.kpi-delta {
  flex-shrink: 0;
  margin-left: auto;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  white-space: nowrap;
  pointer-events: none;
}
.kpi-delta.visible {
  opacity: 1;
  transform: translateY(0);
}
.kpi-delta.hiding {
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Each animated digit position */
.slot-char {
  display: inline-block;
  overflow: hidden;
  height: 1em;
  vertical-align: bottom;
}

/* Soft fade mask — only on the large KPI numbers (28 px), not summary cells */
.kpi-num .slot-char {
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent  0%,
    black       18%,
    black       82%,
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent  0%,
    black       18%,
    black       82%,
    transparent 100%
  );
}

/* Vertical reel — CSS transition drives movement */
.slot-reel {
  display: block;
  will-change: transform;
  transform: translateY(0);   /* explicit initial state so reflow-trick works */
}

.slot-reel span {
  display: block;
  height: 1em;
  line-height: 1;
}

/* Thousand-separator / decimal point — not clipped */
.slot-sep {
  display: inline-block;
  height: 1em;
  line-height: 1;
  vertical-align: middle;
  opacity: 0.55;
}

.kpi-sub {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--faint);
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  transition: max-height 0.35s ease, opacity 0.3s ease, margin-top 0.35s ease;
}

#kpi-grid.show-genutzt .kpi-sub {
  max-height: 28px;
  opacity: 1;
  margin-top: 5px;
}

.kpi-sub-val {
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.kpi-pct {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 600;
  /* background and color set inline per group */
}

/* ── Summary Table ──────────────────────────────────────────────────────── */
.summary-table {
  width: 100%;
  border-collapse: collapse;
}

.summary-table tr          { border-bottom: 1px solid var(--bdr); }
.summary-table tr:last-child { border-bottom: none; }

.summary-table td {
  padding: 8px 3px;
  font-size: 13px;
}

.summary-table td:first-child { color: rgba(255, 255, 255, 0.68); }

.summary-table td:last-child {
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
  min-width: 7.5rem; /* room for delta badge + large NGF values */
}

/* Keeps delta badge + number on one line (critical for Nettogrundfläche) */
.sum-val {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0;
  white-space: nowrap;
  max-width: 100%;
}

/* ── Summary slot — inline-block odometer container inside each value cell ── */
/* The container fixes height to 1 em and clips the vertical reel via        */
/* overflow:hidden. Individual slot-chars inside don't need their own clip.  */
.sum-slot {
  display: inline-block;
  height: 1em;
  /* line-height:1 makes the internal IFC exactly 1em tall, so slot-chars
     with vertical-align:bottom sit flush — no inherited 1.4 line-height offset. */
  line-height: 1;
  /* Vertical clipping is handled by each .slot-char child (overflow:hidden + height:1em).
     Do NOT add overflow:hidden here — it would clip long numbers horizontally. */
  overflow: visible;
  vertical-align: middle;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* slot-chars inside sum-slot keep overflow:hidden for per-digit clipping.
   The mask (which caused the original "cut off" issue) only applies to
   .kpi-num .slot-char — so summary digits are fully visible within 1em. */

/* Animated wrapper for the "davon genutzt" table row content */
.genutzt-wrap {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.35s ease, opacity 0.3s ease;
}

.sum-genutzt-row.genutzt-visible .genutzt-wrap {
  max-height: 36px;
  opacity: 1;
}

/* Genutzt percentage — hidden, shown only as native tooltip (title attr) */
.sum-pct { display: none; }

/* Hide the row border when "davon genutzt" row is collapsed */
.summary-table tr.sum-genutzt-row:not(.genutzt-visible) { border-bottom: none; }

/* Summary delta badge — left of the number; fixed width so rows don't jump */
.sum-delta {
  display: inline-block;
  box-sizing: border-box;
  min-width: 3.6rem; /* room for "+1.807" / "+12" without shifting the value */
  margin-right: 6px;
  text-align: right;
  font-size: 10.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: rgba(183, 249, 170, 0.7);
  opacity: 0;
  vertical-align: middle;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.35s ease;
}
.sum-delta.visible { opacity: 1; }

.sum-divider td {
  padding-top: 12px;
  padding-bottom: 2px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  text-align: left !important;   /* override td:last-child rule (colspan=2 bug) */
  color: var(--faint) !important;
  font-variant-numeric: normal !important;
}

/* ── Controls Area ──────────────────────────────────────────────────────── */
.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 24px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(4, 14, 28, 0.78);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.45), 0 1px 0 rgba(255, 255, 255, 0.06);
}

.controls-top {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* One logical row — wraps naturally, no forced separators */
.ctrl-row {
  display: flex;
  align-items: flex-end;  /* align on button baseline */
  gap: 24px;
  flex-wrap: wrap;
  row-gap: 12px;
}

/* Subtle divider between groups within a row */
.ctrl-sep {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 1px;
}

/* Slider row — always first inside .controls; label stacked above the track */
.controls-top-slider {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

/* Adaptive presets + date fields — shown when data span > 30 days */
.range-adaptive-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}

.range-adaptive-bar[hidden] {
  display: none !important;
}

.range-dates {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.range-date-lbl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.2px;
}

.range-date-lbl > span {
  text-transform: uppercase;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.8px;
  color: var(--faint);
}

.range-date-input {
  appearance: none;
  -webkit-appearance: none;
  padding: 5px 10px;
  border: 1px solid var(--bdr);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  letter-spacing: 0.1px;
  outline: none;
  transition: all 0.16s;
  color-scheme: dark;
}

.range-date-input:hover {
  background: var(--surf-h);
  border-color: var(--bdr-b);
  color: var(--text);
}

.range-date-input:focus {
  border-color: rgba(96, 165, 250, 0.5);
  color: var(--text);
}

.range-date-input::-webkit-calendar-picker-indicator {
  opacity: 0.55;
  cursor: pointer;
  filter: invert(1);
}

/* Button rows — below the slider */
.controls-bottom {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Each control block: label stacked above buttons */
.ctrl-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
}

/* Compare block body: toggle + optional date input in a row */
.ctrl-block--compare .ctrl-block__body {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.compare-date-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
}

.compare-date-wrap[hidden] {
  display: none !important;
}

.compare-date-lbl {
  font-size: 10px;
  font-weight: 600;
  color: var(--faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ctrl-lbl {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--faint);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Aggregation Buttons ────────────────────────────────────────────────── */
.agg-row { display: flex; gap: 4px; }

.agg-btn {
  padding: 5px 13px;
  border: 1px solid var(--bdr);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.1px;
  transition: all 0.16s;
}

.agg-btn:hover {
  background: var(--surf-h);
  color: var(--text);
  border-color: var(--bdr-b);
}

.agg-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  pointer-events: none;
}

.cumul-row--locked {
  opacity: 0.55;
}

.agg-btn.active {
  background: var(--kfw-600);
  border-color: var(--kfw-500);
  color: #fff;
}

/* ── Group Toggles ──────────────────────────────────────────────────────── */
.group-row {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
}

.grp-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--r-pill);
  border: 1px solid var(--bdr);
  background: var(--surf);
  color: var(--faint);
  font-size: 12.5px;
  font-weight: 500;
  transition: all 0.18s;
  user-select: none;
}

.grp-btn:hover { color: var(--muted); background: var(--surf-h); }
.grp-btn.active { color: var(--text); }

.grp-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Range Slider ───────────────────────────────────────────────────────── */
.slider-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 6px;
}

/* Wrapper that lets the comparison band overlay the track */
.slider-track-wrap {
  position: relative;
  padding-bottom: 2px;
}

/* Permanent axis end labels (full effective data range) */
.slider-extent-labels {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-top: 22px; /* clear space below handle tooltips */
  pointer-events: none;
}

.slider-extent-labels span {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.slider-extent-labels #slider-extent-max {
  text-align: right;
}

/* Comparison period band — draggable, fixed width = main range duration */
.slider-cmp-band {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 8px;
  border-radius: 3px;
  background: rgba(183, 249, 170, 0.22);
  border: 1px solid rgba(183, 249, 170, 0.5);
  pointer-events: none;
  transition: left 0.12s ease, width 0.12s ease, opacity 0.2s ease;
  opacity: 0;
  z-index: 2;
  cursor: grab;
  user-select: none;
}

.slider-cmp-band.visible {
  opacity: 1;
  pointer-events: auto;
}

.slider-cmp-band.dragging {
  cursor: grabbing;
  transition: width 0.12s ease, opacity 0.2s ease; /* no left transition while dragging */
  background: rgba(183, 249, 170, 0.35);
  border-color: rgba(183, 249, 170, 0.75);
}

/* noUiSlider dark-theme overrides
   IMPORTANT: selectors must match or exceed noUiSlider specificity.
   noUiSlider uses `.noUi-horizontal { height:18px }` and
   `.noUi-horizontal .noUi-handle { width:34px; height:28px }`.
   Our CSS loads after noUiSlider so equal-specificity rules win by cascade. */

/* Track */
.noUi-target {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  box-shadow: none;
  border-radius: 2px;
}

.noUi-horizontal {
  height: 3px;
}

.noUi-connects { border-radius: 2px; }
.noUi-connect  { background: var(--kfw-500); }

/* Handles — compact discs, quiet enough for the settings glass */
.noUi-horizontal .noUi-handle {
  width: 14px;
  height: 14px;
  top: -6px;
  right: -7px;
  border: 1.5px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  background: rgba(236, 244, 252, 0.95);
  box-shadow:
    0 0 0 1px rgba(0, 90, 140, 0.22),
    0 1px 4px rgba(0, 0, 0, 0.35);
  cursor: grab;
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
}

.noUi-horizontal .noUi-handle::before,
.noUi-horizontal .noUi-handle::after {
  display: none;
}

.noUi-horizontal .noUi-handle:hover {
  transform: scale(1.12);
  border-color: #fff;
  box-shadow:
    0 0 0 1px rgba(84, 179, 226, 0.4),
    0 2px 6px rgba(0, 0, 0, 0.38);
}

.noUi-horizontal .noUi-handle:active,
.noUi-horizontal .noUi-handle.noUi-active {
  cursor: grabbing;
  transform: scale(1.06);
  border-color: var(--kfw-g-acc);
  box-shadow:
    0 0 0 1px rgba(183, 249, 170, 0.35),
    0 1px 4px rgba(0, 0, 0, 0.35);
}

/* Tooltip — pill chip below the handle, moves with the drag */
.noUi-horizontal .noUi-tooltip {
  /* Override default above-track position */
  bottom: auto;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  /* Pill styling matching the dark theme */
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--r-pill);
  color: var(--muted);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  padding: 2px 9px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* When both chips would overlap, hide the left one and show a combined label
   on the right chip (centered between the handles via inline transform). */
.noUi-horizontal .noUi-tooltip.noUi-tooltip-hidden {
  opacity: 0;
  pointer-events: none;
}

.noUi-horizontal .noUi-tooltip.noUi-tooltip-combined {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.10);
  font-variant-numeric: tabular-nums;
}

/* slider-range-lbl removed — date chips are now the noUi-tooltip pills */


/* ── Chart Type Dropdown ────────────────────────────────────────────────── */
.chart-type-select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.chart-type-select {
  appearance: none;
  -webkit-appearance: none;
  padding: 5px 32px 5px 13px;
  border: 1px solid var(--bdr);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  letter-spacing: 0.1px;
  cursor: pointer;
  outline: none;
  transition: all 0.16s;
  min-width: 148px;
}

.chart-type-select:hover {
  background: var(--surf-h);
  border-color: var(--bdr-b);
  color: var(--text);
}

.chart-type-select:focus {
  border-color: rgba(96, 165, 250, 0.5);
  color: var(--text);
}

/* Native <select> option list — inherits from OS; force dark where supported */
.chart-type-select option {
  background: #0b1d38;
  color: var(--text);
}

.chart-type-select-chevron {
  position: absolute;
  right: 10px;
  width: 10px;
  height: 6px;
  color: var(--faint);
  pointer-events: none;
  transition: color 0.16s;
}

.chart-type-select-wrap:hover .chart-type-select-chevron,
.chart-type-select:focus + .chart-type-select-chevron {
  color: var(--muted);
}

