:root {
  --bg: #f5f7f9;
  --panel: #ffffff;
  --text: #16202a;
  --muted: #65717d;
  --line: #d9e0e7;
  --green: #18864b;
  --grey: #5d6875;
  --yellow: #d89b12;
  --orange: #d96d1c;
  --red: #be2e2e;
  --blue: #1e6fb8;
  --shadow: 0 16px 40px rgba(18, 31, 44, 0.16);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(245, 247, 249, 0.92), rgba(245, 247, 249, 0.88)),
    url("tiles/osm/10/598/297.png") center / 320px repeat;
}

.login-screen.hidden {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 4px 0 8px;
  font-size: 28px;
  line-height: 1.15;
}

.eyebrow {
  margin: 0;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.login-note,
.login-error {
  margin: 0;
  color: var(--muted);
}

.login-error {
  min-height: 18px;
  color: var(--red);
}

.login-card label,
.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-card input,
.field input,
.field select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
}

.login-card button,
.button-row button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--blue);
  font-weight: 700;
}

.app {
  display: none;
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.app.ready {
  display: block;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.leaflet-control-attribution,
.leaflet-attribution-flag {
  display: none !important;
}

.leaflet-top.leaflet-right {
  top: 78px;
  right: 12px;
}

.leaflet-control-layers {
  border: 1px solid rgba(217, 224, 231, 0.92) !important;
  border-radius: 8px !important;
  background: rgba(255, 255, 255, 0.96) !important;
  box-shadow: 0 8px 26px rgba(18, 31, 44, 0.14) !important;
}

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

.leaflet-control-layers label {
  margin: 4px 0;
  color: var(--text);
  font-size: 13px;
}

.topbar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 600;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 54px;
  padding: 8px 10px;
  border: 1px solid rgba(217, 224, 231, 0.85);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 26px rgba(18, 31, 44, 0.14);
}

.topbar-title {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}

.topbar-title strong,
.topbar-title span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.topbar-title span {
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
  font-size: 20px;
  line-height: 1;
}

.panel {
  position: absolute;
  z-index: 550;
  border: 1px solid rgba(217, 224, 231, 0.92);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--shadow);
}

.filters-panel {
  top: 82px;
  left: 12px;
  bottom: 16px;
  width: 360px;
  display: grid;
  grid-template-rows: auto auto auto auto auto auto 1fr;
  gap: 12px;
  padding: 16px;
}

.details-panel {
  top: 82px;
  right: 12px;
  bottom: 16px;
  width: 420px;
  display: none;
  overflow: auto;
}

.details-panel.open {
  display: block;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel h2 {
  margin: 0;
  font-size: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stats-grid div {
  min-height: 66px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.stats-grid span {
  display: block;
  font-size: 22px;
  font-weight: 700;
}

.stats-grid small {
  color: var(--muted);
}

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

.button-row button:first-child {
  color: var(--text);
  background: #edf2f6;
}

.object-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 2px;
}

.object-item {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  text-align: left;
}

.object-item.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(30, 111, 184, 0.16);
}

.object-item strong {
  display: block;
  font-size: 13px;
  line-height: 1.25;
}

.object-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.25;
}

.status-dot {
  width: 12px;
  height: 12px;
  margin-top: 3px;
  border-radius: 50%;
  background: var(--grey);
}

.details-content {
  padding: 18px;
}

.object-heading {
  display: grid;
  gap: 8px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.object-heading h2 {
  line-height: 1.2;
}

.details-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.details-top h2 {
  margin: 0;
  font-size: 18px;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  color: #fff;
  background: var(--grey);
  font-size: 12px;
  font-weight: 700;
}

.section-title {
  margin: 18px 0 10px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
}

.metrics {
  display: grid;
  gap: 8px;
}

.metric {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--text);
  text-align: left;
}

.metric:hover,
.metric.active {
  border-color: var(--blue);
  background: #eef6ff;
}

.metric.active {
  box-shadow: 0 0 0 2px rgba(30, 111, 184, 0.14);
}

.metric span:first-child {
  min-width: 0;
  line-height: 1.25;
}

.metric strong {
  white-space: nowrap;
}

.chart-box {
  position: relative;
  height: 250px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.chart-box svg {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-point {
  cursor: pointer;
  outline: none;
}

.chart-hit {
  fill: transparent;
}

.chart-dot {
  fill: var(--blue);
}

.chart-point:hover .chart-dot,
.chart-point:focus .chart-dot {
  r: 5;
  fill: #124f86;
}

.chart-tooltip {
  position: absolute;
  z-index: 3;
  min-width: 120px;
  max-width: 180px;
  padding: 7px 9px;
  border-radius: 6px;
  color: #fff;
  background: rgba(18, 31, 44, 0.94);
  box-shadow: 0 10px 24px rgba(18, 31, 44, 0.22);
  font-size: 12px;
  line-height: 1.25;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -100%);
  transition: opacity 120ms ease;
}

.chart-tooltip.visible {
  opacity: 1;
}

.chart-tooltip strong,
.chart-tooltip span {
  display: block;
}

.chart-tooltip span {
  margin-top: 2px;
  color: #d9e7f5;
}

.source-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.monitor-marker {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 50%;
  color: #fff;
  box-shadow: 0 3px 10px rgba(18, 31, 44, 0.35);
  font-size: 11px;
  font-weight: 700;
}

.marker-green {
  background: var(--green);
}

.marker-grey {
  background: var(--grey);
}

.marker-yellow {
  background: var(--yellow);
}

.marker-orange {
  background: var(--orange);
}

.marker-red {
  background: var(--red);
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 700;
  max-width: min(520px, calc(100% - 32px));
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 6px;
  color: #fff;
  background: rgba(22, 32, 42, 0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.toast.show {
  opacity: 1;
}

.mobile-only {
  display: none;
}

@media (max-width: 980px) {
  .filters-panel {
    width: calc(100% - 24px);
    max-width: 460px;
  }

  .filters-panel {
    transform: translateX(calc(-100% - 24px));
    transition: transform 0.2s ease;
  }

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

  .details-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: min(48dvh, 430px);
    border-radius: 8px 8px 0 0;
    overflow: auto;
  }

  .mobile-only {
    display: grid;
  }
}

@media (max-width: 640px) {
  .topbar {
    top: 8px;
    left: 8px;
    right: 8px;
    height: 52px;
    gap: 8px;
  }

  .topbar-title strong {
    font-size: 13px;
  }

  .topbar-title span {
    font-size: 11px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
  }

  .filters-panel {
    top: 68px;
    left: 8px;
    bottom: 8px;
    width: calc(100% - 16px);
    padding: 12px;
  }

  .details-content {
    padding: 14px;
  }

  .chart-box {
    height: 220px;
  }

  .login-card {
    padding: 22px;
  }

  .login-card h1 {
    font-size: 24px;
  }
}
