:root {
  --bg-primary: #0b0f19;
  --bg-card: #131b2e;
  --bg-card-elevated: #1a2540;
  --border-subtle: rgba(148, 163, 184, 0.14);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;

  /* Klassifizierungs-Farben */
  --color-low: #10b981;
  --color-low-bg: rgba(16, 185, 129, 0.14);
  --color-mid: #f59e0b;
  --color-mid-bg: rgba(245, 158, 11, 0.14);
  --color-high: #ef4444;
  --color-high-bg: rgba(239, 68, 68, 0.16);

  /* Zeitreihen & Fallback-Hervorhebung */
  --color-today: #38bdf8;
  --color-forecast: #f43f5e;
  --color-lastweek: #a855f7;
  --color-historical: #fbbf24;
  --color-outage-border: #f59e0b;
  --color-outage-glow: rgba(245, 158, 11, 0.25);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  max-width: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Mobile-First App Shell
   ========================================================================== */
.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 100dvh;
  padding: 0.75rem;
  gap: 0.75rem;
}

/* Header */
.top-bar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  flex-shrink: 0;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.14);
  color: var(--color-today);
  flex-shrink: 0;
}

.app-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.controls-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.control-select {
  background: var(--bg-card-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.42rem 0.65rem;
  font-size: 0.82rem;
  font-weight: 500;
  max-width: 100%;
  cursor: pointer;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.38rem 0.7rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}

.status-pill.status-ok {
  background: rgba(16, 185, 129, 0.14);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.status-pill.status-warn {
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
  border: 1px solid #f59e0b;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.3);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.42rem 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card-elevated);
  color: var(--text-main);
}

.btn:hover {
  border-color: var(--color-today);
  background: rgba(56, 189, 248, 0.12);
}

.btn.btn-active-outage {
  background: rgba(245, 158, 11, 0.22);
  border-color: #f59e0b;
  color: #fde68a;
}

.btn-icon {
  padding: 0.42rem 0.55rem;
}

/* ==========================================================================
   Warnbanner bei fehlenden Live-Daten (Farbliche Hervorhebung)
   ========================================================================== */
.outage-banner {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
  min-width: 0;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.22), rgba(239, 68, 68, 0.18));
  border: 2px solid var(--color-outage-border);
  color: #fef3c7;
  font-size: 0.82rem;
  box-shadow: 0 4px 18px var(--color-outage-glow);
  flex-shrink: 0;
}

.outage-banner-icon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #f59e0b;
  color: #0b0f19;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.outage-banner-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

/* ==========================================================================
   Dashboard Grid (Mobile-First -> Fullscreen Desktop)
   ========================================================================== */
.dashboard-grid {
  display: grid;
  /* minmax(0, 1fr) verhindert, dass Canvas oder Heatmap das Grid über den Viewport hinaus aufblähen */
  grid-template-columns: minmax(0, 1fr);
  gap: 0.75rem;
  width: 100%;
  min-width: 0;
  flex: 1;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
  min-width: 0;
  flex-shrink: 0;
}

.eyebrow {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
}

.target-time-title {
  font-size: 1.2rem;
  font-weight: 800;
}

.fallback-tag {
  background: #f59e0b;
  color: #0b0f19;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  letter-spacing: 0.04em;
}

/* ==========================================================================
   Hero Prediction Element (HOCH / MITTEL / NIEDRIG)
   ========================================================================== */
.classification-display {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0.35rem 0;
  padding: 1rem 0.75rem;
  border-radius: 14px;
  text-align: center;
  transition: all 0.25s ease;
  border: 2px solid transparent;
  min-width: 0;
}

.classification-display[data-level="NIEDRIG"] {
  background: var(--color-low-bg);
  border-color: var(--color-low);
  color: #34d399;
}

.classification-display[data-level="MITTEL"] {
  background: var(--color-mid-bg);
  border-color: var(--color-mid);
  color: #fbbf24;
}

.classification-display[data-level="HOCH"] {
  background: var(--color-high-bg);
  border-color: var(--color-high);
  color: #f87171;
}

.classification-ring {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-width: 0;
}

.classification-label {
  font-size: clamp(1.85rem, 3.2vw, 2.75rem);
  font-weight: 900;
  letter-spacing: 0.05em;
  line-height: 1.05;
}

.classification-share {
  font-size: clamp(1.25rem, 2vw, 1.65rem);
  font-weight: 800;
  color: var(--text-main);
}

.classification-caption {
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Schwellen-Skala */
.scale-bar-wrapper {
  margin: 0.4rem 0 0.6rem;
  min-width: 0;
}

.scale-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  gap: 0.25rem;
}

.scale-track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  display: flex;
  overflow: visible;
  background: var(--bg-card-elevated);
}

.scale-zone {
  height: 100%;
}

.zone-low {
  width: 33.33%;
  background: var(--color-low);
  border-radius: 999px 0 0 999px;
  opacity: 0.75;
}

.zone-mid {
  width: 33.34%;
  background: var(--color-mid);
  opacity: 0.75;
}

.zone-high {
  width: 33.33%;
  background: var(--color-high);
  border-radius: 0 999px 999px 0;
  opacity: 0.75;
}

.scale-marker {
  position: absolute;
  top: -4px;
  width: 6px;
  height: 18px;
  border-radius: 3px;
  background: #ffffff;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.8);
  transform: translateX(-50%);
  transition: left 0.3s ease;
}

/* Kennzahlen-Kacheln */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
}

.metric-box {
  background: var(--bg-card-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  transition: all 0.2s ease;
}

/* Farbliche Hervorhebung bei fehlenden Live-Daten */
.metric-box.highlight-fallback {
  border: 2px solid var(--color-historical);
  background: rgba(251, 191, 36, 0.16);
  box-shadow: 0 0 14px rgba(251, 191, 36, 0.22);
}

.metric-box.highlight-missing {
  border: 1px dashed #ef4444;
  background: rgba(239, 68, 68, 0.12);
}

.metric-label {
  font-size: 0.67rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-value-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem;
  min-width: 0;
}

.metric-value {
  font-size: 1rem;
  font-weight: 800;
}

.metric-sub {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.hero-footer {
  margin-top: 0.55rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.74rem;
  color: var(--text-muted);
  text-align: center;
}

/* ==========================================================================
   Chart Card (Heute vs. Letzte Woche & Historisches Mittel)
   ========================================================================== */
.chart-legend-Badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-item.legend-highlight {
  color: #fde68a;
  font-weight: 700;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-today {
  background: var(--color-today);
}

.dot-forecast {
  background: var(--color-forecast);
}

.dot-lastweek {
  background: var(--color-lastweek);
}

.dot-historical {
  background: var(--color-historical);
}

.chart-container {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 0;
  height: clamp(200px, 32vh, 280px);
  flex: 1 1 auto;
  overflow: hidden;
}

.chart-container canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

/* ==========================================================================
   Heatmap Card (7 Wochentage x 24 Stunden)
   ========================================================================== */
.heatmap-info-bar {
  font-size: 0.72rem;
  color: var(--color-today);
  background: rgba(56, 189, 248, 0.1);
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  max-width: 100%;
}

.heatmap-scroll-container {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  padding: 2px 0;
}

.heatmap-grid {
  display: grid;
  grid-template-columns: 36px repeat(24, minmax(18px, 1fr));
  gap: 3px;
  width: 100%;
  min-width: 520px;
}

.hm-header-cell {
  font-size: 0.64rem;
  color: var(--text-muted);
  text-align: center;
  padding-bottom: 2px;
}

.hm-day-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
}

.hm-cell {
  height: clamp(20px, 2.5vh, 30px);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  font-weight: 700;
  color: #0b0f19;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  user-select: none;
}

.hm-cell:hover {
  transform: scale(1.12);
  z-index: 3;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.hm-cell.hm-target-next {
  outline: 2px solid #ffffff;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.85);
  z-index: 2;
}

.heatmap-scale-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.4rem;
  font-size: 0.68rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.heatmap-gradient-bar {
  width: 110px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #10b981 0%, #fbbf24 55%, #ef4444 100%);
}

/* ==========================================================================
   Desktop / Tablet Layout
   ========================================================================== */
@media (min-width: 768px) {
  .top-bar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

@media (min-width: 1080px) {
  .dashboard-grid {
    grid-template-columns: minmax(310px, 365px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    min-height: 0;
  }

  .hero-card {
    grid-column: 1 / 2;
    grid-row: 1 / 3;
  }

  .chart-card {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
  }

  .heatmap-card {
    grid-column: 2 / 3;
    grid-row: 2 / 3;
  }

  .chart-container {
    height: 100%;
    min-height: 160px;
  }
}

/* Bildschirmfüllend ohne Scrollbar, sobald sowohl Breite als auch Höhe ausreichen */
@media (min-width: 1080px) and (min-height: 680px) {
  html,
  body {
    height: 100dvh;
    overflow: hidden;
  }

  .app-shell {
    height: 100dvh;
    padding: 0.75rem 1rem;
  }
}
