:root {
  color-scheme: light;
  --bg: #f4f7f8;
  --panel: #ffffff;
  --ink: #172126;
  --muted: #65757d;
  --line: #d9e2e5;
  --accent: #24786d;
  --accent-strong: #145c54;
  --danger: #9f3a32;
  --power: #de7b2c;
  --substation: #1672a4;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

button,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100vh;
  padding: 22px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.sidebar-header {
  display: grid;
  gap: 4px;
}

.eyebrow {
  margin: 0;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.15;
}

.control-section {
  display: grid;
  gap: 10px;
}

.section-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.select-control {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
}

.layer-controls,
.status-list,
.legend {
  display: grid;
  gap: 8px;
}

.layer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.layer-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.layer-name {
  font-size: 14px;
  font-weight: 700;
}

.layer-detail {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.button-pair {
  display: flex;
  gap: 6px;
}

.layer-button,
.icon-button,
.basemap-button {
  min-width: 38px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.layer-button.primary {
  min-width: 64px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.layer-button.cancel {
  min-width: 68px;
  color: var(--danger);
}

.layer-button.cancel:not(:disabled) {
  border-color: rgba(159, 58, 50, 0.42);
  background: #fff6f4;
}

.basemap-toggle {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 6px 18px rgba(32, 49, 57, 0.12);
}

.basemap-button {
  min-width: 54px;
  height: 28px;
  border-color: transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.basemap-button.is-active {
  background: var(--accent);
  color: #fff;
}

.layer-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
}

.layer-button.is-unavailable {
  filter: blur(0.35px);
  opacity: 0.42;
}

.layer-button.primary.is-unavailable {
  border-color: var(--line);
  background: #e9eef0;
  color: var(--muted);
}

.layer-row.is-loading {
  border-color: rgba(36, 120, 109, 0.45);
  background: #f4fbfa;
}

.layer-row.is-loaded {
  border-color: rgba(36, 120, 109, 0.3);
}

.status-item {
  display: grid;
  gap: 2px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.status-item:last-child {
  border-bottom: 0;
}

.status-title {
  font-size: 13px;
  font-weight: 700;
}

.status-message {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.legend > div {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot.power {
  background: var(--power);
}

.legend-dot.substation {
  background: var(--substation);
}

.map-panel {
  position: relative;
  min-width: 0;
  min-height: 100vh;
}

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

.topbar {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 600;
  display: flex;
  gap: 8px;
  align-items: center;
}

.summary {
  max-width: min(520px, calc(100vw - 390px));
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 13px;
  box-shadow: 0 6px 18px rgba(32, 49, 57, 0.12);
}

body.has-page-title-offset .leaflet-top {
  top: var(--page-title-offset, 230px);
}

body.has-page-title-offset .topbar {
  top: calc(var(--page-title-offset, 230px) + 14px);
}

.leaflet-popup-content {
  margin: 10px 12px;
  min-width: 220px;
}

.popup-title {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 800;
}

.popup-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.popup-table th,
.popup-table td {
  padding: 5px 0;
  border-top: 1px solid #edf1f2;
  text-align: left;
  vertical-align: top;
}

.popup-table th {
  width: 42%;
  color: var(--muted);
  font-weight: 700;
  padding-right: 10px;
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    max-height: 46vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .map-panel,
  #map {
    min-height: 54vh;
    height: 54vh;
  }

  .topbar {
    top: 10px;
    right: 10px;
    left: 54px;
    flex-wrap: wrap;
  }

  body.has-page-title-offset .leaflet-top {
    top: 0;
  }

  body.has-page-title-offset .topbar {
    top: 10px;
  }

  .summary {
    max-width: none;
    flex: 1;
    min-width: 160px;
  }
}

@media (max-width: 460px) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    left: 54px;
    gap: 6px;
  }

  .summary {
    grid-column: 1 / -1;
    width: 100%;
    padding: 7px 9px;
    font-size: 12px;
  }

  .icon-button {
    grid-column: 2;
    justify-self: end;
    min-width: 34px;
    padding: 0 8px;
  }

  .basemap-toggle {
    grid-column: 1;
    justify-self: start;
    order: 0;
  }

  .basemap-button {
    min-width: 50px;
  }
}
