/* === Base Reset === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #1a1a1a;
  background: #f5f7fa;
  overflow: hidden;
}

/* === Header === */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 16px;
  background: #003064;
  color: #fff;
  flex-shrink: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

#app-header h1 {
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
}

.header-subtitle {
  font-size: 13px;
  opacity: 0.7;
  white-space: nowrap;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.param-label {
  font-size: 13px;
  opacity: 0.8;
}

#param-select {
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 8px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  min-width: 160px;
}

#param-select:focus {
  border-color: rgba(255,255,255,0.6);
}

#param-select option {
  background: #003064;
  color: #fff;
}

/* === Main Container === */
#app-container {
  position: relative;
  height: calc(100% - 56px);
  display: flex;
}

#map {
  flex: 1;
  height: 100%;
}

/* === Legend === */
#legend {
  position: absolute;
  bottom: 24px;
  left: 12px;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(8px);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  z-index: 5;
}

.legend-title {
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 13px;
  color: #003064;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
  line-height: 1.6;
}

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

.legend-dot.gruen { background: #22a352; }
.legend-dot.gelb { background: #e8a317; }
.legend-dot.rot { background: #d32f2f; }
.legend-dot.grau { background: #9e9e9e; }

.legend-note {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #e0e0e0;
  font-size: 11px;
  color: #888;
  font-style: italic;
}

/* === Side Panel === */
#panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 380px;
  height: 100%;
  background: #fff;
  box-shadow: -2px 0 12px rgba(0,0,0,0.12);
  z-index: 8;
  overflow-y: auto;
  transition: transform 0.25s ease;
}

#panel.panel-hidden {
  transform: translateX(100%);
}

#panel-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  font-size: 24px;
  color: #666;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  z-index: 1;
}

#panel-close:hover {
  background: #f0f0f0;
  color: #333;
}

#panel-content {
  padding: 16px;
}

/* Panel: Station Header */
.station-header {
  padding-bottom: 12px;
  border-bottom: 2px solid #003064;
  margin-bottom: 16px;
}

.station-name {
  font-size: 16px;
  font-weight: 600;
  color: #003064;
  line-height: 1.3;
  padding-right: 28px;
}

.station-meta {
  font-size: 12px;
  color: #666;
  margin-top: 4px;
}

.station-meta span {
  display: inline-block;
  margin-right: 12px;
}

/* Panel: Measurement Table */
.messwerte-title {
  font-size: 13px;
  font-weight: 600;
  color: #003064;
  margin-bottom: 8px;
}

.messwerte-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 20px;
}

.messwerte-table th {
  text-align: left;
  font-weight: 600;
  padding: 6px 8px;
  border-bottom: 2px solid #e0e0e0;
  color: #003064;
  font-size: 12px;
}

.messwerte-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}

.messwerte-table tr:hover {
  background: #f8f9fb;
}

.messwerte-table tr.active-row {
  background: #e8f0fe;
}

.messwerte-table tr {
  cursor: pointer;
}

/* Status Ampel */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge.gruen {
  background: #e6f4ea;
  color: #137333;
}

.status-badge.gelb {
  background: #fef3e0;
  color: #a65d00;
}

.status-badge.rot {
  background: #fde7e7;
  color: #c62828;
}

.status-badge.keine-daten {
  background: #f0f0f0;
  color: #888;
}

/* Trend Arrow */
.trend {
  font-size: 13px;
  display: inline-block;
  margin-left: 2px;
}

.trend.steigend { color: #c62828; }
.trend.fallend { color: #137333; }
.trend.stabil { color: #888; }

/* Chart Section */
.chart-section {
  margin-bottom: 16px;
}

.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: #003064;
  margin-bottom: 8px;
}

.chart-container {
  position: relative;
  height: 180px;
  background: #fafbfc;
  border-radius: 8px;
  padding: 8px;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

.chart-info {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: #888;
}

/* Click hint on map */
.click-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255,255,255,0.9);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  color: #003064;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  opacity: 1;
  transition: opacity 0.5s ease;
}

.click-hint.hidden {
  opacity: 0;
}

/* === Cluster Marker === */
.cluster-count {
  background: #003064;
  color: #fff;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  font-family: system-ui, sans-serif;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  border: 2px solid rgba(255,255,255,0.5);
}

/* === MapLibre Overrides === */
.maplibregl-popup-content {
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.maplibregl-ctrl-attrib {
  font-size: 10px !important;
}

/* === Responsive: Mobile === */
@media (max-width: 640px) {
  #app-header {
    height: 48px;
    padding: 0 10px;
  }

  #app-header h1 {
    font-size: 15px;
  }

  .header-subtitle {
    display: none;
  }

  .param-label {
    display: none;
  }

  #param-select {
    min-width: 130px;
    font-size: 13px;
  }

  #app-container {
    height: calc(100% - 48px);
    flex-direction: column;
  }

  /* Bottom sheet on mobile */
  #panel {
    position: absolute;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 55%;
    max-height: 65%;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.15);
    transition: transform 0.3s ease;
  }

  #panel.panel-hidden {
    transform: translateY(100%);
  }

  #panel::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: #ccc;
    border-radius: 2px;
    margin: 8px auto 4px;
  }

  #legend {
    bottom: 12px;
    left: 8px;
    padding: 8px 10px;
    font-size: 11px;
  }

  .legend-title {
    font-size: 12px;
  }

  .chart-container {
    height: 140px;
  }
}

@media (max-width: 380px) {
  #param-select {
    min-width: 110px;
  }
}

/* === Help Button === */
.help-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  border-radius: 50%;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; margin-left: 8px;
  transition: background 0.15s;
}
.help-btn:hover { background: rgba(255,255,255,0.25); }

/* === Onboarding Tour === */
.onboarding-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 16, 36, 0.65);
  z-index: 3000;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.3s ease;
}
.onboarding-overlay.visible { opacity: 1; }

.onboarding-card {
  background: #fff; border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  padding: 32px 36px 24px; max-width: 500px; width: 92vw;
  transform: translateY(20px) scale(0.97); opacity: 0;
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.onboarding-card.visible { transform: translateY(0) scale(1); opacity: 1; }

.onboarding-icon { margin-bottom: 10px; }
.onboarding-title { font-size: 1.15rem; font-weight: 600; color: #003064; margin-bottom: 10px; }
.onboarding-text { font-size: 0.88rem; line-height: 1.65; color: #333; margin-bottom: 18px; }
.onboarding-text strong { color: #003064; }

.onboarding-illustration {
  background: #f0f4f8; border-radius: 8px; padding: 16px;
  margin-bottom: 16px; display: flex; align-items: center; justify-content: center;
}

.onboarding-progress {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid #e0e0e0;
}
.onboarding-dots { display: flex; gap: 6px; }
.onboarding-dot { width: 8px; height: 8px; border-radius: 50%; background: #ddd; transition: all 0.2s; }
.onboarding-dot.active { background: #003064; transform: scale(1.25); }
.onboarding-step-label { font-size: 0.8rem; color: #888; }

.onboarding-actions { display: flex; align-items: center; justify-content: space-between; }
.onboarding-nav { display: flex; gap: 8px; }

.onboarding-skip {
  background: none; border: none; color: #888;
  font-size: 0.78rem; cursor: pointer; padding: 6px 0;
}
.onboarding-skip:hover { color: #333; }

.onboarding-prev {
  background: none; border: 1px solid #ddd; color: #555;
  padding: 7px 16px; border-radius: 8px; font-size: 0.82rem; cursor: pointer;
}
.onboarding-prev:hover { background: #f5f5f5; }

.onboarding-next {
  background: #003064; color: #fff; border: none;
  padding: 8px 22px; border-radius: 8px; font-size: 0.85rem;
  font-weight: 500; cursor: pointer;
}
.onboarding-next:hover { background: #0066CC; }

.onboarding-highlight {
  outline: 4px solid rgba(0, 102, 204, 0.7) !important;
  outline-offset: 2px;
  position: relative !important;
  z-index: 3001 !important;
}
