:root {
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --bg: #f4f6f8;
  --card: #fff;
  --text: #222;
  --text-muted: #555;
  --border: #cbd5e1;
}

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

body {
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.nav {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0;
  height: 48px;
  flex-shrink: 0;

  & .nav__brand {
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent);
    margin-right: 2rem;
    white-space: nowrap;
  }

  & .nav__link {
    display: inline-flex;
    align-items: center;
    height: 100%;
    padding: 0 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    transition:
      color 0.15s,
      border-color 0.15s;

    &:hover {
      color: var(--text);
    }

    &.nav__link--active {
      color: var(--accent);
      border-bottom-color: var(--accent);
      font-weight: 500;
    }
  }

  & .nav__help-btn {
    margin-left: auto;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    background: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: border-color 0.15s, color 0.15s;

    &:hover {
      border-color: var(--accent);
      color: var(--accent);
    }
  }
}

.controls {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  flex-shrink: 0;

  & .controls__group {
    display: flex;
    align-items: center;
    gap: 0.5rem;

    & label {
      font-size: 0.8rem;
      font-weight: 500;
      color: var(--text-muted);
      white-space: nowrap;
    }

    & select {
      padding: 0.3rem 0.6rem;
      border: 1.5px solid var(--border);
      border-radius: 6px;
      font-size: 0.875rem;
      background: var(--bg);
      color: var(--text);
      cursor: pointer;

      &:focus {
        outline: none;
        border-color: var(--accent);
      }
    }

    & .controls__checkbox {
      display: flex;
      align-items: center;
      gap: 0.35rem;
      cursor: pointer;

      & input[type='checkbox'] {
        cursor: pointer;
        accent-color: var(--accent);
        width: 14px;
        height: 14px;
      }
    }
  }

  & .controls__timeline {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-top: 0.25rem;

    & #ctrl-timeline-label {
      font-size: 0.8rem;
      font-weight: 600;
      color: var(--text);
      min-width: 9rem;
    }

    & input[type="range"] {
      flex: 1;
      accent-color: var(--accent);
      cursor: pointer;
      height: 4px;
    }

    & .timelapse-btn {
      width: 28px;
      height: 28px;
      border-radius: 50%;
      border: 1.5px solid var(--border);
      background: var(--bg);
      color: var(--text-muted);
      font-size: 0.7rem;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: background 0.15s, color 0.15s, border-color 0.15s;

      &:hover {
        border-color: var(--accent);
        color: var(--accent);
      }

      &.active {
        background: var(--accent);
        color: #fff;
        border-color: var(--accent);
      }
    }
  }

  & .metric-toggle {
    display: flex;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    overflow: hidden;

    & button {
      padding: 0.3rem 0.75rem;
      font-size: 0.875rem;
      background: var(--bg);
      color: var(--text-muted);
      border: none;
      cursor: pointer;
      border-right: 1px solid var(--border);
      transition:
        background 0.15s,
        color 0.15s;

      &:last-child {
        border-right: none;
      }

      &:hover {
        background: #eff6ff;
        color: var(--text);
      }

      &.active {
        background: var(--accent);
        color: #fff;
      }
    }
  }

  & .metric-toggle--rows {
    flex-direction: column;
    border: none;
    border-radius: 0;
    overflow: visible;
    gap: 0.3rem;

    & .metric-toggle__row {
      display: flex;
      align-items: center;
      gap: 0.5rem;
    }

    & .metric-toggle__label {
      font-size: 0.75rem;
      color: var(--text-muted);
      white-space: nowrap;
      width: 6.5rem;
      text-align: right;
    }

    & .metric-toggle__buttons {
      display: flex;
      border: 1.5px solid var(--border);
      border-radius: 6px;
      overflow: hidden;

      & button {
        padding: 0.3rem 0.6rem;
        font-size: 0.8rem;
        border-right: 1px solid var(--border);

        &:last-child {
          border-right: none;
        }
      }
    }
  }
}

#map {
  flex: 1;
  min-height: 0;
}

/* ── Stationsvergleich ───────────────────────────────────────────────────── */

.controls__sep {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  margin-left: 0.5rem;

  &:hover {
    color: var(--text);
  }

  & input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
    cursor: pointer;
  }
}

.controls__group--full {
  width: 100%;
  align-items: flex-start;
}

#chart-area {
  flex: 1;
  min-height: 0;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;

  & .chart-wrapper {
    flex: 1;
    min-height: 0;
    position: relative;
  }

  & #chart-empty {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: auto;
  }
}

.station-selector {
  position: relative;
  flex: 1;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.station-open-btn {
  align-self: flex-start;
  padding: 0.3rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;

  &:hover {
    border-color: var(--accent);
    color: var(--accent);
  }
}


.station-modal {
  border: none;
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  padding: 0;
  width: min(860px, 95vw);
  max-height: 80vh;
  position: fixed;
  inset: 0;
  margin: auto;
  display: none;
  flex-direction: column;

  &[open] {
    display: flex;
  }

  &::backdrop {
    background: rgba(0, 0, 0, 0.35);
  }

  & .station-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem 0.75rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  & .station-modal__title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
  }

  & .station-modal__close {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    font-size: 1.4rem;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    line-height: 1;

    &:hover {
      background: var(--bg);
      color: var(--text);
    }
  }

  & .station-modal__toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  & .station-modal__year-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
  }

  & .station-modal__year-input {
    width: 4.5rem;
    padding: 0.3rem 0.4rem;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: 0.875rem;
    background: var(--bg);
    color: var(--text);
    text-align: center;

    &:focus {
      outline: none;
      border-color: var(--accent);
    }
  }

  & .station-modal__year-sep {
    color: var(--text-muted);
    font-size: 0.875rem;
  }

  & .station-modal__toolbar-sep {
    width: 1px;
    height: 1.5rem;
    background: var(--border);
    margin: 0 0.25rem;
    flex-shrink: 0;
  }

  & .station-modal__sel-btn {
    padding: 0.3rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: 0.8rem;
    background: var(--bg);
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;

    &:hover {
      border-color: var(--accent);
      color: var(--accent);
    }
  }

  & .station-modal__table-wrapper {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
  }

  & .station-modal__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;

    & th {
      position: sticky;
      top: 0;
      background: var(--bg);
      padding: 0;
      text-align: left;
      font-size: 0.75rem;
      font-weight: 600;
      color: var(--text-muted);
      border-bottom: 1.5px solid var(--border);

      &:first-child {
        padding: 0.5rem 0.75rem;
        width: 36px;
      }

      &.sortable {
        cursor: pointer;

        &:hover {
          background: #f0f4fa;
        }

        &.sort-active {
          color: var(--accent);
        }
      }

      & .th-inner {
        display: flex;
        flex-direction: column;
        gap: 0.3rem;
        padding: 0.5rem 0.75rem;
      }

      & .th-label {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.25rem;
        user-select: none;
        white-space: nowrap;
      }

      & .sort-icon {
        font-size: 0.6rem;
        opacity: 0;
        width: 0.8em;
        text-align: center;
        flex-shrink: 0;
      }

      &.sort-active .sort-icon {
        opacity: 1;
      }

      &[data-sort-dir="asc"] .sort-icon::before { content: "▲"; }
      &[data-sort-dir="desc"] .sort-icon::before { content: "▼"; }

      & .col-filter {
        width: 100%;
        padding: 0.2rem 0.4rem;
        border: 1px solid var(--border);
        border-radius: 4px;
        font-size: 0.75rem;
        font-weight: 400;
        background: var(--card);
        color: var(--text);

        &:focus {
          outline: none;
          border-color: var(--accent);
        }

        &::placeholder {
          color: #bbb;
        }
      }

      & .col-filter-range {
        display: flex;
        gap: 0.25rem;

        & .col-filter {
          width: 0;
          flex: 1;
          min-width: 0;
          appearance: textfield;

          &::-webkit-outer-spin-button,
          &::-webkit-inner-spin-button {
            appearance: none;
          }
        }
      }
    }

    & td {
      padding: 0.4rem 0.75rem;
      border-bottom: 1px solid #f0f0f0;
      color: var(--text);
    }

    & tr {
      cursor: pointer;

      &:hover {
        background: #f8faff;
      }

      &.selected {
        background: color-mix(in srgb, var(--accent) 7%, #fff);
      }

      & td:first-child {
        width: 36px;
        text-align: center;
      }

      & td:last-child {
        color: var(--text-muted);
        text-align: right;
        width: 6rem;
      }
    }

    & input[type="checkbox"] {
      width: 15px;
      height: 15px;
      accent-color: var(--accent);
      cursor: pointer;
    }
  }

  & .station-modal__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }

  & .station-modal__count {
    font-size: 0.85rem;
    color: var(--text-muted);
  }

  & .station-modal__done {
    padding: 0.4rem 1.25rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-weight: 500;

    &:hover {
      background: var(--accent-dark);
    }
  }
}

#ctrl-filter-value,
#ctrl-year-from,
#ctrl-year-to {
  width: 5rem;
  padding: 0.3rem 0.6rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  background: var(--bg);
  color: var(--text);

  &:focus {
    outline: none;
    border-color: var(--accent);
  }
}

/* ── Hilfe-Dialog ────────────────────────────────────────────────────────── */

.help-dialog {
  border: none;
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  padding: 0;
  width: min(560px, 95vw);
  max-height: 80vh;
  position: fixed;
  inset: 0;
  margin: auto;
  display: none;
  flex-direction: column;
  overflow: hidden;

  &[open] {
    display: flex;
  }

  &::backdrop {
    background: rgba(0, 0, 0, 0.35);
  }

  & .help-dialog__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem 0.75rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  & .help-dialog__title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
  }

  & .help-dialog__close {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    font-size: 1.4rem;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    line-height: 1;

    &:hover {
      background: var(--bg);
      color: var(--text);
    }
  }

  & .help-dialog__body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text);

    & h3 {
      font-size: 0.75rem;
      font-weight: 600;
      color: var(--text-muted);
      text-transform: uppercase;
      letter-spacing: 0.05em;
      margin-top: 1.1rem;
      margin-bottom: 0.4rem;

      &:first-child {
        margin-top: 0;
      }
    }

    & p {
      margin-bottom: 0.4rem;
      color: var(--text-muted);
    }

    & dl {
      display: grid;
      grid-template-columns: auto 1fr;
      gap: 0.15rem 0.75rem;
      margin-bottom: 0.4rem;
    }

    & dt {
      font-weight: 600;
      color: var(--text);
      white-space: nowrap;
    }

    & dd {
      color: var(--text-muted);
    }

    & .help-note {
      margin-top: 0.75rem;
      padding: 0.6rem 0.75rem;
      background: #eff6ff;
      border-left: 3px solid var(--accent);
      border-radius: 0 4px 4px 0;
      font-size: 0.82rem;
      color: var(--text);
    }
  }
}

#loading {
  position: fixed;
  inset: 0;
  background: rgba(244, 246, 248, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 9999;
  font-size: 0.9rem;
  color: var(--text-muted);

  &.hidden {
    display: none;
  }

  & .loading__spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
}

.station-marker {
  background: transparent !important;
  border: none !important;

  & div {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    border: 1.5px solid rgba(0, 0, 0, 0.22);
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
    cursor: default;
  }

  &--missing {
    opacity: 0.4;

    & div {
      background: transparent;
      border: 1.5px solid rgba(0, 0, 0, 0.5);
      box-shadow: none;
    }
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.map-legend {
  background: rgba(255, 255, 255, 0.92);
  padding: 0.75rem;
  border-radius: 8px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.15);
  min-width: 110px;

  & .map-legend__title {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  & .map-legend__bar {
    width: 18px;
    height: 140px;
    border-radius: 3px;
    margin: 0 auto 0.25rem;
  }

  & .map-legend__labels {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    gap: 0.15rem;
  }

  & .map-legend__bands {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
  }

  & .map-legend__band {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.7rem;
    color: var(--text-muted);
  }

  & .map-legend__swatch {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
  }
}

.footer {
  flex-shrink: 0;
  padding: 0.5rem 1.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--card);

  & a {
    color: var(--accent);
  }
}
