html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: "Helvetica Neue", Arial, sans-serif;
}

body {
  overflow: hidden;
  position: relative;
  --accent-blue: #1f4d74;
  --map-control-edge: 14px;
  --time-control-bottom: 16px;
  --left-panel-left: 58px;
  --left-panel-width: 260px;
  --bottom-control-clearance: 138px;
}

#map {
  width: 100vw;
  height: 100vh;
}

.app-loading {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  background: rgba(244, 247, 250, 0.82);
  backdrop-filter: blur(3px);
}

.app-loading.is-hidden {
  display: none;
}

.app-loading__box {
  min-width: 260px;
  padding: 18px 20px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(0, 0, 0, 0.14);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.14);
  text-align: center;
}

.app-loading__box strong {
  display: block;
  margin-top: 10px;
  font-size: 15px;
}

.app-loading__box span {
  display: block;
  margin-top: 6px;
  color: #555;
  font-size: 13px;
}

.app-loading__spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto;
  border: 3px solid #c4ced8;
  border-top-color: #1f4d74;
  border-radius: 50%;
  animation: app-spin 0.8s linear infinite;
}

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

.leaflet-container {
  cursor: grab;
}

.leaflet-container:active {
  cursor: grabbing;
}

.leaflet-top,
.leaflet-bottom {
  z-index: 1100;
}

.leaflet-top.leaflet-left {
  top: var(--map-control-edge);
  left: var(--map-control-edge);
}

.leaflet-top.leaflet-right {
  top: var(--map-control-edge);
  right: var(--map-control-edge);
}

.leaflet-bottom {
  bottom: var(--bottom-control-clearance);
}

.leaflet-left {
  left: var(--map-control-edge);
}

.leaflet-left .leaflet-control {
  margin-left: 0;
}

.leaflet-top .leaflet-control {
  margin-top: 0;
}

.leaflet-right {
  right: var(--map-control-edge);
}

.leaflet-right .leaflet-control {
  margin-right: 0;
}

.leaflet-bottom .leaflet-control {
  margin-bottom: 0;
}

.leaflet-bottom.leaflet-right {
  right: var(--map-control-edge);
  bottom: var(--time-control-bottom);
}

.leaflet-bottom.leaflet-right .leaflet-control {
  clear: right;
  margin-right: 0;
  margin-bottom: 8px;
}

.leaflet-bottom.leaflet-right .leaflet-control:has(.map-legend) {
  margin-bottom: 8px;
}

.leaflet-bottom.leaflet-right .leaflet-control-attribution {
  clear: right;
  display: block;
  margin-right: 0;
  margin-bottom: 0;
  text-align: right;
}

.leaflet-control-layers {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(0, 0, 0, 0.18);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.10);
  font-size: 13px;
}

.leaflet-control-layers-expanded {
  padding: 8px 10px;
  min-width: 180px;
}

.time-control {
  position: absolute;
  left: 50%;
  bottom: var(--time-control-bottom);
  z-index: 1050;
  width: clamp(420px, 46vw, 680px);
  max-width: calc(100vw - 32px);
  padding: 9px 11px;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(0, 0, 0, 0.18);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.14);
}

.time-control__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.time-control__head strong {
  color: var(--accent-blue);
  font-size: 13px;
}

.time-control__head span {
  color: #475569;
  font-size: 12px;
  text-align: right;
}

.time-control__body {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 190px;
  gap: 10px;
  align-items: center;
}

.time-control__slider {
  width: 100%;
  accent-color: var(--accent-blue);
}

.time-control__input {
  box-sizing: border-box;
  width: 100%;
  padding: 7px 8px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #111827;
  font-size: 12px;
}

.map-legend {
  padding: 8px 10px;
  max-width: 240px;
  background: rgba(255, 255, 255, 0.92);
  color: #222;
  border: 1px solid rgba(0, 0, 0, 0.2);
  line-height: 1.4;
  font-size: 13px;
}

.map-legend strong {
  display: block;
  margin-bottom: 6px;
  color: var(--accent-blue);
}

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

.map-legend .legend-dot {
  width: 10px;
  height: 10px;
  background: var(--accent-blue);
  border: 1px solid #ffffff;
  border-radius: 50%;
}

.map-legend .legend-dot-muted {
  background: #7a8793;
}

.map-legend .legend-fill {
  width: 16px;
  height: 10px;
  border: 1px solid #1d4e89;
  background: rgba(219, 234, 254, 0.78);
}

.map-legend .legend-fill-outline {
  background: transparent;
}

.map-legend .legend-gradient {
  display: block;
  width: 100%;
  height: 10px;
  margin-top: 6px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: linear-gradient(90deg, #2c7bb6, #74add1, #ffffbf, #fdae61, #d73027);
}

.map-legend .legend-scale {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-top: 4px;
  font-size: 11px;
}

.map-legend .legend-scale span:nth-child(3) {
  text-align: center;
}

.map-legend .legend-scale span:nth-child(4),
.map-legend .legend-scale span:nth-child(5) {
  text-align: right;
}

.map-legend .legend-note {
  margin-top: 6px;
  font-size: 11px;
  color: #555;
}

.map-legend .legend-section-title {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.12);
  font-size: 12px;
  font-weight: 700;
}

.element-panel,
.idw-panel,
.import-panel {
  position: absolute;
  left: var(--left-panel-left);
  z-index: 1000;
  box-sizing: border-box;
  width: min(var(--left-panel-width), calc(100vw - 78px));
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(0, 0, 0, 0.16);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.10);
}

.element-panel {
  top: 14px;
}

.idw-panel {
  top: 124px;
}

.import-toggle {
  position: absolute;
  left: var(--map-control-edge);
  top: 90px;
  z-index: 1000;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: rgba(255, 255, 255, 0.95);
  color: var(--accent-blue);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.10);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.import-toggle.is-active {
  background: #1f4d74;
  color: #fff;
}

.import-panel {
  top: 90px;
  left: 58px;
  z-index: 1200;
  width: min(340px, calc(100vw - 78px));
  display: none;
}

.import-panel.is-open {
  display: block;
}

.import-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.import-panel__close {
  width: 26px;
  height: 26px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #334155;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.element-panel__title,
.idw-panel__title,
.import-panel__title {
  margin: 0;
  color: var(--accent-blue);
  font-size: 14px;
  font-weight: 600;
}

.element-panel__title,
.idw-panel__title {
  margin-bottom: 8px;
}

.control-field {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
}

.element-panel .control-field {
  margin-bottom: 0;
}

.control-field span {
  display: block;
  margin-bottom: 4px;
  color: #444;
}

.control-field select {
  width: 100%;
  font-size: 13px;
  padding: 5px 8px;
  border: 1px solid #c7ccd1;
  background: #fff;
}

.import-panel__db-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 0 8px;
  margin-bottom: 2px;
}

.import-panel__full-field {
  grid-column: 1 / -1;
}

.import-panel__input {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid #c7ccd1;
  background: #fff;
  color: #1f2933;
  font: inherit;
  font-size: 13px;
}

.import-panel__input[type="number"] {
  appearance: textfield;
}

.import-panel__input[type="number"]::-webkit-outer-spin-button,
.import-panel__input[type="number"]::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.import-panel__file {
  box-sizing: border-box;
  width: 100%;
  font-size: 12px;
}

.idw-panel__button,
.import-panel__button {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #1f4d74;
  background: #1f4d74;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

.idw-panel__button:disabled,
.import-panel__button:disabled {
  opacity: 0.6;
  cursor: default;
}

.idw-panel.is-calculating .idw-panel__button {
  position: relative;
}

.idw-panel__status,
.import-panel__status {
  margin: 8px 0 0;
  min-height: 28px;
  color: #555;
  font-size: 12px;
  line-height: 1.45;
}

.idw-panel.is-calculating .idw-panel__status {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.idw-panel.is-calculating .idw-panel__status::before,
.import-panel.is-importing .import-panel__status::before {
  content: "";
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  margin-top: 2px;
  border: 2px solid #c4ced8;
  border-top-color: #1f4d74;
  border-radius: 50%;
  animation: idw-spin 0.75s linear infinite;
}

.import-panel.is-importing .import-panel__status {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

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

.district-stats {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #e2e2e2;
}

.district-stats__placeholder,
.district-stats__summary {
  color: #555;
  font-size: 12px;
  line-height: 1.45;
}

.district-stats__summary strong {
  display: block;
  margin-bottom: 6px;
  color: #111;
  font-size: 13px;
}

.district-stats__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.district-stats__table th,
.district-stats__table td {
  padding: 3px 0;
  text-align: left;
  vertical-align: top;
}

.district-stats__table th {
  width: 78px;
  font-weight: 600;
}

.district-label {
  background: transparent;
  border: 0;
  box-shadow: none;
  color: #111;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
  padding: 0;
  text-align: center;
  text-shadow:
    -1px -1px 0 rgba(255, 255, 255, 0.9),
    1px -1px 0 rgba(255, 255, 255, 0.9),
    -1px 1px 0 rgba(255, 255, 255, 0.9),
    1px 1px 0 rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  pointer-events: none;
}

.district-label-marker {
  background: transparent;
  border: 0;
  box-shadow: none;
}

.info-panel {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 1300;
  width: min(420px, 36vw);
  height: 100vh;
  background: rgba(255, 255, 255, 0.97);
  border-left: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: -10px 0 24px rgba(0, 0, 0, 0.08);
  transform: translateX(100%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
}

.info-panel.is-open {
  transform: translateX(0);
}

.info-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #e5e5e5;
}

.info-panel__title {
  margin: 0;
  color: var(--accent-blue);
  font-size: 16px;
  font-weight: 600;
}

.info-panel__close {
  border: 0;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: #555;
}

.info-panel__body {
  flex: 1;
  overflow: auto;
  padding: 14px 16px 18px;
}

.info-panel__placeholder {
  color: #666;
  font-size: 14px;
  line-height: 1.5;
}

.station-panel h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.station-panel p {
  margin: 0;
}

.station-panel .meta {
  margin-bottom: 8px;
}

.station-panel .obs-table {
  border-collapse: collapse;
  width: 100%;
  margin-top: 6px;
  font-size: 12px;
}

.station-panel .obs-table th,
.station-panel .obs-table td {
  padding: 3px 0;
  text-align: left;
  vertical-align: top;
}

.station-panel .obs-table th {
  width: 108px;
  font-weight: 600;
}

.station-panel .status {
  margin-top: 6px;
  color: #555;
}

.station-panel .chart-block {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #e2e2e2;
}

.station-panel .chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.station-panel .chart-head strong,
.station-panel h3 {
  color: var(--accent-blue);
}

.station-panel .chart-head label {
  font-size: 12px;
}

.station-panel .chart-element-name {
  color: #555;
  font-size: 12px;
}

.station-panel .chart-head select {
  font-size: 12px;
}

.station-panel .chart-range-controls {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 7px;
  align-items: end;
  margin: 8px 0 6px;
}

.station-panel .chart-range-controls label {
  display: grid;
  gap: 3px;
  color: #64748b;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.station-panel .chart-range-input {
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
  padding: 6px 7px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #111827;
  font-size: 11px;
}

.station-panel .chart-range-apply {
  padding: 7px 10px;
  border: 1px solid var(--accent-blue);
  background: var(--accent-blue);
  color: #fff;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

.station-panel .chart-range-apply:hover {
  background: #286491;
}

.station-panel .chart-status {
  font-size: 12px;
  color: #666;
}

.station-panel .chart-status--error {
  color: #b91c1c;
}

.station-panel .mini-chart {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 6px;
}

.station-panel .chart-hover-zone {
  cursor: crosshair;
}

.station-panel .chart-cursor-line {
  pointer-events: none;
}

.station-panel .chart-caption {
  margin-top: 4px;
  font-size: 11px;
  color: #666;
}

.station-panel .chart-readout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 6px;
  min-height: 64px;
  color: #444;
  font-size: 12px;
  line-height: 1.4;
}

.station-panel .chart-readout.is-empty {
  display: flex;
  align-items: center;
  min-height: 42px;
}

.station-panel .chart-readout-placeholder {
  width: 100%;
  padding: 10px 11px;
  border: 1px dashed #cbd5e1;
  background: #f8fafc;
  color: #64748b;
  font-size: 12px;
}

.station-panel .chart-readout-card {
  padding: 8px 9px;
  border: 1px solid #d8dee6;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.station-panel .chart-readout-card--minutely {
  border-left: 4px solid #aeb8c2;
}

.station-panel .chart-readout-card--hourly {
  border-left: 4px solid var(--accent-blue);
}

.station-panel .chart-readout-label {
  color: #64748b;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1;
  text-transform: uppercase;
}

.station-panel .chart-readout-value {
  margin-top: 5px;
  color: #111827;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.1;
}

.station-panel .chart-readout-time {
  margin-top: 5px;
  color: #475569;
  font-size: 11px;
  line-height: 1.25;
}

@media (max-width: 1200px) {
  body {
    --map-control-edge: 12px;
    --time-control-bottom: 12px;
    --left-panel-left: 54px;
    --left-panel-width: 240px;
    --bottom-control-clearance: 132px;
  }

  .leaflet-control-layers {
    font-size: 12px;
  }

  .leaflet-control-layers-expanded {
    padding: 6px 8px;
    min-width: 155px;
  }

  .map-legend {
    max-width: 220px;
    padding: 7px 9px;
    font-size: 12px;
  }

  .map-legend .legend-section-title {
    margin-top: 8px;
    padding-top: 6px;
    font-size: 11px;
  }

  .map-legend .legend-note,
  .map-legend .legend-scale {
    font-size: 10px;
  }

  .element-panel,
  .idw-panel {
    padding: 9px 10px;
  }

  .import-toggle {
    top: 86px;
    width: 32px;
    height: 32px;
  }

  .import-panel {
    top: 86px;
    left: 54px;
    width: min(320px, calc(100vw - 72px));
    padding: 9px 10px;
  }

  .element-panel__title,
  .idw-panel__title {
    margin-bottom: 8px;
    font-size: 14px;
  }

  .control-field {
    margin-bottom: 8px;
    font-size: 11px;
  }

  .control-field select {
    padding: 5px 7px;
    font-size: 12px;
  }

  .import-panel__input {
    padding: 5px 7px;
    font-size: 12px;
  }

  .idw-panel {
    top: 116px;
  }

  .idw-panel__button {
    padding: 7px 9px;
    font-size: 12px;
  }

  .idw-panel__status,
  .district-stats__placeholder,
  .district-stats__summary {
    font-size: 11px;
    line-height: 1.35;
  }

  .time-control {
    width: clamp(360px, 44vw, 520px);
    padding: 8px 10px;
  }

  .time-control__head {
    gap: 8px;
    margin-bottom: 6px;
  }

  .time-control__head strong {
    font-size: 12px;
  }

  .time-control__head span {
    overflow: hidden;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .time-control__body {
    grid-template-columns: minmax(130px, 1fr) 170px;
    gap: 8px;
  }

  .time-control__input {
    padding: 6px 7px;
    font-size: 11px;
  }
}

@media (max-width: 900px) {
  body {
    --bottom-control-clearance: 132px;
  }

  .leaflet-bottom.leaflet-right {
    bottom: var(--bottom-control-clearance);
  }

  .leaflet-bottom.leaflet-right .leaflet-control-attribution {
    margin-right: 0;
    margin-bottom: 0;
  }

  .element-panel,
  .idw-panel {
    left: 54px;
    width: min(240px, calc(100vw - 66px));
  }

  .element-panel {
    top: 12px;
  }

  .idw-panel {
    top: 132px;
  }

  .import-toggle {
    left: 12px;
    top: 86px;
  }

  .import-panel {
    left: 54px;
    top: 86px;
    width: min(320px, calc(100vw - 66px));
  }

  .info-panel {
    width: 100%;
    max-width: none;
    height: min(54vh, 480px);
    top: auto;
    bottom: 0;
    border-left: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.12);
    box-shadow: 0 -10px 24px rgba(0, 0, 0, 0.08);
    transform: translateY(100%);
  }

  .info-panel.is-open {
    transform: translateY(0);
  }

  .station-panel .chart-range-controls {
    grid-template-columns: 1fr;
  }

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

  .time-control {
    bottom: 10px;
    width: calc(100vw - 20px);
    padding: 8px;
  }

  .time-control__head {
    display: block;
  }

  .time-control__head span {
    display: block;
    margin-top: 3px;
    text-align: left;
  }

  .time-control__body {
    grid-template-columns: 1fr;
  }
}
