:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: #334155;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --accent: #0ea5e9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.topbar {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #111827, #0f172a);
}

.title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

label {
  color: var(--muted);
  font-size: 13px;
}

input, select, button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 10px;
}

input, select { min-width: 90px; }

button {
  cursor: pointer;
  background: var(--accent);
  border-color: #0284c7;
  font-weight: 700;
}

button:hover { filter: brightness(1.08); }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}

.card {
  background: rgba(17, 24, 39, 0.95);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  min-height: 108px;
}

.card-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.15;
}

.card-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

.main {
  padding: 14px 18px 18px;
  min-height: 0;
}

#map {
  height: 720px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
}

.map-legend-overlay {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 500;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 12px;
  padding: 10px 12px;
  color: #e2e8f0;
  font-size: 12px;
  line-height: 1.45;
  max-width: 190px;
  backdrop-filter: blur(6px);
  pointer-events: none;
  box-shadow: 0 10px 24px rgba(0,0,0,0.28);
}

.map-legend-title {
  font-weight: 700;
  margin-bottom: 6px;
  font-size: 12px;
}

.map-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}

.map-legend-swatch {
  width: 18px;
  height: 4px;
  border-radius: 999px;
  display: inline-block;
  flex: 0 0 18px;
}

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

.status-pill {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(56, 189, 248, 0.12);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.status-error {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.3);
}

.trend-up { color: var(--good); }
.trend-down { color: var(--bad); }
.trend-steady { color: var(--warn); }

.trend-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.2em;
  margin-right: 6px;
  font-weight: 900;
}

@media (max-width: 900px) {
  .app {
    display: flex;
    flex-direction: column;
    min-height: 100svh;
  }

  .topbar {
    order: 1;
    padding: 8px 10px;
  }

  .title-row { display: block; }

  h1 { font-size: 18px; }

  .subtitle { display: none; }

  .controls {
    margin-top: 8px;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .control-group {
    padding: 6px;
    gap: 5px;
  }

  .control-group:first-child { grid-column: 1 / -1; }

  label { font-size: 11px; }

  input, select, button {
    padding: 6px 7px;
    font-size: 13px;
    min-width: 0;
    width: 100%;
  }

  button {
    grid-column: 1 / -1;
    padding: 7px;
  }

  .main {
    order: 2;
    padding: 0;
  }

  #map {
    height: calc(100svh - 160px);
    min-height: 540px;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .summary-grid {
    order: 3;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    padding: 8px 10px 16px;
    border-top: 1px solid var(--border);
    border-bottom: none;
  }

  .card {
    min-height: 0;
    padding: 8px;
    border-radius: 11px;
  }

  .card-label {
    font-size: 10px;
    margin-bottom: 4px;
  }

  .card-value { font-size: 16px; }

  .card-sub {
    font-size: 10px;
    line-height: 1.25;
  }

  .map-legend-overlay {
    left: 8px;
    bottom: 8px;
    max-width: 145px;
    padding: 7px 8px;
    font-size: 10px;
  }

  .map-legend-title {
    font-size: 10px;
    margin-bottom: 4px;
  }

  .map-legend-row {
    gap: 5px;
    margin: 2px 0;
  }

  .map-legend-swatch {
    width: 14px;
    flex-basis: 14px;
  }
}

@media (max-width: 430px) {
  #map {
    height: calc(100svh - 150px);
    min-height: 580px;
  }

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

  .card:nth-child(n+5) {
    display: none;
  }
}


.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  place-items: center;
  background: rgba(2, 6, 23, 0.72);
  padding: 18px;
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  background: #111827;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 25px 60px rgba(0,0,0,0.45);
  color: var(--text);
}

.modal-card h2 {
  margin: 0 0 12px;
}

.modal-card p {
  color: #cbd5e1;
  line-height: 1.55;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
}

.modal-backdrop.open {
  display: grid;
}
