:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --border: #e0e0dc;
  --text: #2b2b28;
  --text-muted: #6b6b66;
  --accent: #3a6ea5;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-size: 17px;
  white-space: nowrap;
}

#controls {
  flex: 1 1 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px;
  min-width: 0;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

#threshold-input {
  width: 64px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
}

#marker-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 3px 6px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.legend-status {
  color: var(--text-muted);
  font-style: italic;
}

.legend-remove {
  flex: none;
  width: 14px;
  height: 14px;
  line-height: 14px;
  text-align: center;
  border-radius: 50%;
  color: #fff;
  background: #cc3333;
  cursor: pointer;
  font-size: 11px;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.1s ease, transform 0.1s ease;
}

.legend-item:hover .legend-remove {
  opacity: 1;
  transform: scale(1);
}

#main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: row;
  min-height: 0;
  overflow: hidden;
}

#map {
  flex: 1 1 50%;
  height: 100%;
  min-width: 0;
}

#charts {
  flex: 1 1 50%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 10px;
  overflow: hidden;
}

.chart-card {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px 8px;
}

.chart-card h2 {
  flex: 0 0 auto;
  font-size: 12px;
  margin: 3px 0 0;
  color: var(--text-muted);
}

.chart {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

@media (max-width: 800px) {
  html, body {
    overflow: auto;
    height: auto;
  }
  #main {
    flex-direction: column;
    height: auto;
  }
  #map {
    flex: 0 0 45vh;
    width: 100%;
    height: 45vh;
  }
  #charts {
    flex: none;
    overflow: visible;
  }
  .chart-card {
    flex: none;
    min-height: 260px;
  }
  #marker-legend {
    margin-left: 0;
  }
}

/* Leaflet marker pins */
.marker-pin {
  width: 20px;
  height: 20px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.marker-pin.status-loading {
  border-style: dashed;
  animation: pulse 1s infinite ease-in-out;
}

.marker-pin.status-error {
  background: #cc3333 !important;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Popup content */
.popup-content {
  font-size: 13px;
  min-width: 160px;
}

.popup-coords {
  font-weight: 600;
  margin-bottom: 4px;
}

.popup-status {
  color: var(--text-muted);
  margin-bottom: 6px;
}

.popup-status.error {
  color: #cc3333;
}

.popup-remove {
  background: #cc3333;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.popup-remove:hover {
  background: #a82929;
}
