@charset "UTF-8";

/* ============================================================
   DESIGN TOKENS — Bochum Design Language
   ============================================================ */
:root {
  /* Bochum brand colors */
  --cyan: #0AB4FF;
  --blue: #0F2864;
  --orange: #F49100;
  --green: #76B729;
  --red: #E61937;
  --yellow: #EAB308;

  /* Surface & text */
  --bg: #F6F6F6;
  --card-bg: #FFFFFF;
  --surface: #FAFAFA;
  --text: #1A1A1A;
  --text-secondary: #4a5568;
  --text-muted: #94A3B8;
  --line: #E2E8F0;

  /* Shadows */
  --shadow-card: 0 2px 16px rgba(0, 0, 0, 0.08);
  --shadow-card-hover: 0 8px 32px rgba(0, 0, 0, 0.14);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.10);

  /* Radii */
  --radius-card: 10px;
  --radius-control: 8px;
  --radius-pill: 999px;

  /* Typography */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Migration aliases */
  --primary: var(--cyan);
  --primary-hover: #0099e0;
  --primary-light: rgba(0, 180, 255, 0.10);
  --border: var(--line);
  --border-light: #f1f5f9;
  --radius: var(--radius-card);
  --radius-sm: var(--radius-control);
  --radius-xs: 6px;
  --radius-full: var(--radius-pill);

  /* Status colors */
  --color-online: var(--green);
  --color-stale: var(--orange);
  --color-error: var(--red);
}

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 {
  font-family: var(--font-sans);
  font-weight: 700;
  line-height: 1.25;
}

a {
  color: var(--primary);
  text-decoration: none;
}

/* ============================================================
   APP SHELL
   ============================================================ */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  height: 70px;
  background: var(--cyan);
  border-bottom: 0;
  margin-bottom: 16px;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  width: 100vw;
  margin-left: calc(-50vw + 50%);
}

.header-inner {
  height: 70px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.header-logo {
  height: 36px;
  width: auto;
  display: block;
}

.header-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.header-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.header-dot--ok { background: #76B729; }
.header-dot--warn { background: #F49100; }

.header-inner h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #1A1A1A;
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-meta {
  font-size: 0.8rem;
  color: #1A1A1A;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  font-weight: 500;
}

/* Theme Toggle */
.theme-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-pill);
  background: rgba(26, 26, 26, 0.10);
  color: #1A1A1A;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.theme-toggle:hover { background: rgba(26, 26, 26, 0.18); }
.theme-icon { width: 20px; height: 20px; }

[data-theme="dark"] .theme-toggle {
  background: rgba(255, 255, 255, 0.15);
  color: #1A1A1A;
}
[data-theme="dark"] .theme-toggle:hover { background: rgba(255, 255, 255, 0.25); }

.header-loading {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ============================================================
   MAIN CONTENT — MAP + SIDEBAR GRID
   ============================================================ */
.main-content {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 16px;
  flex: 1;
  min-height: 480px;
}

/* ============================================================
   MAP
   ============================================================ */
#map {
  position: relative;
  height: 100%;
  min-height: 420px;
  max-height: calc(100vh - 240px);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  z-index: 1;
}

.leaflet-container {
  font-family: var(--font-sans);
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}

.leaflet-popup-content {
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 12px 16px;
}

.marker-popup strong {
  display: block;
  font-weight: 700;
  margin-bottom: 4px;
  font-size: 1rem;
}

.marker-popup div {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* Optional Baumkataster overlays — visually sit with Leaflet controls, not map data. */
.map-tree-controls {
  position: absolute;
  z-index: 800;
  top: 12px;
  right: 12px;
  min-width: 174px;
  padding: 10px;
  border: 1px solid rgba(10, 180, 255, 0.32);
  border-radius: var(--radius-control);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.map-tree-controls__title {
  margin: 0 0 6px 2px;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.map-layer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 3px 6px;
  border-radius: var(--radius-pill);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.map-layer-toggle:hover { background: var(--primary-light); color: var(--primary); }
.map-layer-toggle input { position: absolute; opacity: 0; pointer-events: none; }

.map-layer-toggle__indicator {
  width: 15px;
  height: 15px;
  border: 1.5px solid var(--cyan);
  border-radius: 50%;
  background: var(--card-bg);
  box-shadow: inset 0 0 0 3px var(--card-bg);
  transition: background 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}

.map-layer-toggle input:checked + .map-layer-toggle__indicator {
  background: var(--cyan);
  box-shadow: inset 0 0 0 3px var(--cyan);
}

.map-layer-toggle input:focus-visible + .map-layer-toggle__indicator {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  min-height: 420px;
  max-height: calc(100vh - 200px);
}

.sidebar-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.sidebar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.sidebar-title-row h2 {
  font-size: 1.05rem;
  font-weight: 600;
}

.station-count {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Filter controls */
.filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-input,
.filter-select {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.filter-input:focus,
.filter-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.filter-input::placeholder {
  color: var(--text-muted);
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Station list */
.station-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.station-list::-webkit-scrollbar {
  width: 6px;
}

.station-list::-webkit-scrollbar-track {
  background: transparent;
}

.station-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.station-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Station item */
.station-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  border-left: 3px solid transparent;
}

.station-item:hover {
  background: var(--surface);
}

.station-item.active {
  background: var(--primary-light);
  border-left-color: var(--primary);
}

.station-item.active .station-item-name {
  color: var(--primary);
}

/* Status dot */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
  box-shadow: 0 0 4px rgba(0,0,0,0.15);
}

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

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

.status-dot.offline,
.status-dot.error {
  background: var(--color-error);
}

/* Assessment dot in station list */
.assessment-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
  box-shadow: 0 0 4px rgba(0,0,0,0.2);
}
.assessment-red   { background: #DC2626; }
.assessment-yellow{ background: #D97706; }
.assessment-green { background: #16A34A; }
.assessment-gray  { background: #9CA3AF; }

/* Assessment badge in station detail header */
.asm-header-badge {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 3px 12px;
  border-radius: 12px;
  white-space: nowrap;
  margin-left: 8px;
}
.asm-header-badge.asm-red    { background: #FEE2E2; color: #DC2626; }
.asm-header-badge.asm-yellow { background: #FEF3C7; color: #D97706; }
.asm-header-badge.asm-green  { background: #DCFCE7; color: #16A34A; }
.asm-header-badge.asm-gray   { background: #F3F4F6; color: #6B7280; }

/* Assessment disclaimer */
.asm-disclaimer {
  font-size: 0.75rem;
  color: #9CA3AF;
  margin-top: 8px;
  margin-bottom: 16px;
  padding: 6px 12px;
  background: #F9FAFB;
  border-radius: 6px;
  line-height: 1.4;
}

/* Assessment badge in chart card */
.asm-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  margin-left: auto;
}
.asm-badge.asm-red    { background: #FEE2E2; color: #DC2626; }
.asm-badge.asm-yellow { background: #FEF3C7; color: #D97706; }
.asm-badge.asm-green  { background: #DCFCE7; color: #16A34A; }
.asm-badge.asm-gray   { background: #F3F4F6; color: #6B7280; }

/* Device parameter section */
.device-section {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid #E5E7EB;
}
.device-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #9CA3AF;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}
.chart-grid--device .chart-card {
  background: #FAFAFA;
}
.chart-grid--device .chart-card-name {
  color: #9CA3AF;
}

/* Station item info */
.station-item-info {
  flex: 1;
  min-width: 0;
}

.station-item-name {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-item-water {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.station-item-params {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.param-tag {
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  white-space: nowrap;
}
.param-tag--red    { background: #FEE2E2; color: #DC2626; }
.param-tag--yellow { background: #FEF3C7; color: #D97706; }
.param-tag--green  { background: #DCFCE7; color: #16A34A; }

/* ============================================================
   DETAIL SECTION
   ============================================================ */
.detail-section {
  margin-top: 16px;
  margin-bottom: 20px;
}

.detail-placeholder {
  text-align: center;
  padding: 60px 20px 48px;
  color: var(--text-muted);
}

.placeholder-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.6;
}

.placeholder-text {
  font-size: 1.05rem;
  font-weight: 500;
}

.detail-loading,
.detail-error {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.detail-error p {
  margin-bottom: 8px;
}

.detail-error-msg {
  font-size: 0.85rem;
  color: var(--color-error);
}

/* Detail header */
.detail-header {
  margin-bottom: 16px;
}

.detail-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.detail-title-row h2 {
  font-size: 1.3rem;
  font-weight: 700;
}

.thing-link {
  color: inherit;
  text-decoration: none;
  transition: color 0.15s;
}
.thing-link:hover {
  color: var(--primary);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-badge.online {
  background: rgba(76, 175, 80, 0.12);
  color: var(--color-online);
}

.status-badge.stale {
  background: rgba(255, 152, 0, 0.12);
  color: var(--color-stale);
}

.status-badge.online::before,
.status-badge.stale::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-badge.online::before {
  background: var(--color-online);
}

.status-badge.stale::before {
  background: var(--color-stale);
}

.detail-meta-row {
  display: flex;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 4px;
  flex-wrap: wrap;
}

.detail-water {
  color: var(--text-muted);
}

/* Time range pills */
.detail-ranges {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

.pill {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 7px 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: rgba(0, 180, 255, 0.12);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.pill:hover {
  background: rgba(0, 180, 255, 0.20);
}

.pill.active {
  background: var(--cyan);
  color: #1A1A1A;
}

/* ============================================================
   CHART GRID
   ============================================================ */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

/* Chart card */
.chart-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 18px 18px 12px;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s;
}

.chart-card:hover {
  box-shadow: var(--shadow-card-hover);
}

/* Grouped depth charts deliberately break out of the three-card grid. */
.chart-card--full {
  width: 100%;
  margin-top: 16px;
}

.chart-card--full .chart-card-body {
  height: 300px;
}

.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.chart-card-name {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.chart-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.chart-card-unit {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Data-source link below chart cards */
.chart-source {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 0;
  gap: 8px;
  font-size: 0.8rem;
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
  line-height: 1.3;
  margin-top: 10px;
}
.chart-source a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
  opacity: 0.75;
  flex-shrink: 0;
}
.chart-source a:hover {
  color: var(--primary);
  opacity: 1;
}

/* Download CSV button in chart-source (bottom-left) */
.chart-source .download-csv-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.chart-source .download-csv-btn:hover {
  background: var(--border-light);
  color: var(--primary);
}

.chart-source--group {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.chart-card-value {
  font-family: var(--font-sans);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.2;
}

.chart-card-body {
  position: relative;
  height: 200px;
  flex-shrink: 0;
}

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

.chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  padding: 20px;
}

/* ============================================================
   SPINNER
   ============================================================ */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner--small {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn--primary:hover {
  background: var(--primary-hover);
}

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer {
  margin-top: auto;
  padding: 24px 0;
  background: var(--cyan);
  border-top: 0;
  flex-shrink: 0;
  width: 100vw;
  margin-left: calc(-50vw + 50%);
}

.footer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.footer-main {
  font-size: 0.85rem;
  color: #1A1A1A;
  text-align: center;
}

.footer-brand {
  font-weight: 700;
}

.footer-data {
  display: block;
  font-size: 0.78rem;
  margin-top: 2px;
  color: rgba(26, 26, 26, 0.75);
}

.footer-links {
  margin-top: 4px;
}

.footer-links a {
  color: #1A1A1A;
  font-size: 0.78rem;
  text-decoration: underline;
}

.footer-links a:hover {
  color: rgba(26, 26, 26, 0.7);
}


/* Hint banner (in footer) */
.hint-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: #8D6E00;
  background: #FFF8E1;
  border: 1px solid #FFE082;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  max-width: 680px;
  line-height: 1.4;
}

.hint-icon {
  flex-shrink: 0;
  font-size: 0.9rem;
}

/* ============================================================
   LEGEND BUTTON + MODAL
   ============================================================ */

/* Utility */
.hidden { display: none !important; }

/* Legend trigger button — sits at bottom of filter controls */.filter-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 2px;
}

.legend-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--card-bg);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  line-height: 1;
}

.legend-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

/* Overlay backdrop — covers full viewport, semi-transparent */
.legend-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

/* Floating card */
.legend-modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.08);
  width: 92vw;
  max-width: 540px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: legend-in 0.2s ease-out;
}

@keyframes legend-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Header */
.legend-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.legend-modal-header h3 {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.legend-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  border-radius: var(--radius-xs);
  transition: background 0.15s, color 0.15s;
  line-height: 1;
  flex-shrink: 0;
}

.legend-close:hover {
  background: var(--surface);
  color: var(--text);
}

/* Scrollable body */
.legend-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 20px 8px;
}

.legend-modal-body::-webkit-scrollbar {
  width: 5px;
}

.legend-modal-body::-webkit-scrollbar-track {
  background: transparent;
}

.legend-modal-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Footer disclaimer */
.legend-modal-footer {
  padding: 10px 20px 14px;
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}

.legend-modal-footer p {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Legend content */
.legend-intro {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.legend-group {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
}

.legend-group:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.legend-group h4 {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.legend-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  line-height: 1.3;
}

/* Compact table */
.legend-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.legend-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 6px 3px 0;
  border-bottom: 1px solid var(--border-light);
}

.legend-table td {
  padding: 3px 6px 3px 0;
  color: var(--text-secondary);
  vertical-align: middle;
  line-height: 1.3;
}

.legend-range {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  font-size: 0.73rem;
}

.legend-note {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Colored dot */
.legend-color {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.15);
  vertical-align: middle;
}

.legend-red    { background: #DC2626; }
.legend-orange { background: #F97316; }
.legend-yellow { background: #D97706; }
.legend-green  { background: #16A34A; }
.legend-blue   { background: #0284C7; }
.legend-gray   { background: #9CA3AF; }

/* Subtle row tinting by level */
.legend-row--red td    { color: #991B1B; }
.legend-row--orange td { color: #9A3412; }
.legend-row--yellow td { color: #92400E; }
.legend-row--green td  { color: #166534; }
.legend-row--blue td   { color: #075985; }
.legend-row--gray td   { color: var(--text-muted); }

.legend-row--red .legend-range    { color: #DC2626; }
.legend-row--orange .legend-range { color: #F97316; }
.legend-row--yellow .legend-range { color: #D97706; }
.legend-row--green .legend-range  { color: #16A34A; }
.legend-row--blue .legend-range   { color: #0284C7; }

/* ============================================================
   RESPONSIVE: TABLET (<1024px)
   ============================================================ */
@media (max-width: 1024px) {
  .chart-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================================
   RESPONSIVE: MOBILE (<768px)
   ============================================================ */
@media (max-width: 768px) {
  #app {
    padding: 0 12px;
  }

  .header-inner h1 {
    font-size: 1.15rem;
  }

  .main-content {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  #map {
    height: 300px;
    min-height: 300px;
  }

  #sidebar {
    max-height: none;
    min-height: auto;
  }

  .station-list {
    max-height: 380px;
  }

  .chart-grid {
    grid-template-columns: 1fr;
  }

  .chart-card-body {
    height: 180px;
  }

  .chart-card--full .chart-card-body {
    height: 240px;
  }

  .detail-title-row h2 {
    font-size: 1.15rem;
  }

  .detail-ranges {
    flex-wrap: wrap;
  }

  .hint-banner {
    font-size: 0.72rem;
    padding: 6px 10px;
  }

  .legend-modal {
    width: 96vw;
    max-width: none;
    max-height: 75vh;
  }

  .legend-modal-header {
    padding: 12px 16px 10px;
  }

  .legend-modal-body {
    padding: 10px 16px 6px;
  }
}

/* ============================================================
   RESPONSIVE: TABLET (<640px)
   ============================================================ */
@media (max-width: 640px) {
  .header-inner { padding: 0 16px; }
  .header-logo { height: 28px; }
  .header-inner h1 { font-size: 1rem; }
  .header-left { gap: 12px; }
  .header-meta { font-size: 0.72rem; }
}

/* ============================================================
   RESPONSIVE: SMALL MOBILE (<480px)
   ============================================================ */
@media (max-width: 480px) {
  .header-inner {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    height: auto;
    padding: 8px 12px;
  }
  .app-header { height: auto; }
  .header-right { margin-left: auto; }

  .filter-row {
    grid-template-columns: 1fr;
  }

  #map {
    height: 240px;
    min-height: 240px;
  }

  .legend-modal {
    max-height: 80vh;
  }

  .legend-modal-header h3 {
    font-size: 0.85rem;
  }
}

/* ============================================================
   DARK MODE
   ============================================================ */
[data-theme="dark"] {
  --bg: #0B1220;
  --card-bg: #111827;
  --surface: #1A2332;
  --text: #F8FAFC;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --line: rgba(148, 163, 184, 0.22);
  --border-light: rgba(148, 163, 184, 0.14);
  --shadow-card: 0 2px 16px rgba(0, 0, 0, 0.35);
  --shadow-card-hover: 0 8px 32px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .app-header,
[data-theme="dark"] .app-footer,
[data-theme="dark"] .pill.active {
  color: #1A1A1A;
}

[data-theme="dark"] .chart-card,
[data-theme="dark"] #sidebar,
[data-theme="dark"] #map {
  border: 1px solid rgba(148, 163, 184, 0.14);
}

[data-theme="dark"] .leaflet-tile {
  filter: brightness(0.6) invert(1) contrast(3) hue-rotate(200deg) saturate(0.3) brightness(0.7);
}

[data-theme="dark"] .leaflet-container {
  background: #0B1220;
}

[data-theme="dark"] .map-tree-controls {
  border-color: rgba(10, 180, 255, 0.42);
  background: rgba(17, 24, 39, 0.92);
}

[data-theme="dark"] .chart-grid--device .chart-card {
  background: #1A2332;
}

[data-theme="dark"] .hint-banner {
  background: rgba(255, 200, 0, 0.1);
  border-color: rgba(255, 200, 0, 0.25);
  color: #FBBF24;
}
