* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: #0f1115;
  color: #e8eaed;
  overflow: hidden;
}

#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: rgba(15, 17, 21, 0.92);
  flex-wrap: wrap;
}
#topbar > * { margin: 4px; }

.brand { font-weight: 700; font-size: 18px; margin-right: 8px; white-space: nowrap; }

#search {
  flex: 1;
  min-width: 160px;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid #3c4048;
  border-radius: 10px;
  background: #1a1d23;
  color: #e8eaed;
  outline: none;
}
#search:focus { border-color: #4c8dff; }

button, .btn-link {
  padding: 12px 16px;
  font-size: 15px;
  border: 1px solid #3c4048;
  border-radius: 10px;
  background: #23272f;
  color: #e8eaed;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  white-space: nowrap;
}
button:active, .btn-link:active { transform: scale(0.97); }
button.primary, .btn-link.primary {
  background: #1a73e8;
  border-color: #1a73e8;
  color: #fff;
  font-weight: 600;
}

#map {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1;
}

#panel {
  position: absolute;
  top: 70px;
  right: 12px;
  width: 340px;
  max-height: calc(100% - 90px);
  overflow-y: auto;
  z-index: 1100;
  background: rgba(23, 26, 32, 0.97);
  border: 1px solid #3c4048;
  border-radius: 14px;
  padding: 18px;
}
#panel h2 { margin: 0 28px 8px 0; font-size: 19px; }
#panel-close {
  position: absolute;
  top: 10px; right: 10px;
  padding: 6px 10px;
  border: none;
  background: transparent;
  font-size: 18px;
}
.muted { color: #9aa0a6; font-size: 13px; margin: 6px 0; }
#p-connectors { margin: 10px 0; }
#p-connectors .plug {
  display: inline-block;
  margin: 3px 5px 3px 0;
  padding: 6px 10px;
  background: #26303c;
  border-radius: 8px;
  font-size: 13px;
}
.actions { display: flex; flex-direction: column; margin-top: 14px; }
.actions button, .actions .btn-link { width: 100%; text-align: center; margin: 5px 0; }
#p-status { margin-top: 10px; font-size: 14px; min-height: 18px; }
#p-status.ok { color: #34a853; }
#p-status.err { color: #f28b82; }

.hidden { display: none !important; }

#legend {
  position: absolute;
  left: 12px;
  bottom: 24px;
  z-index: 1000;
  background: rgba(23, 26, 32, 0.92);
  border: 1px solid #3c4048;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.7;
}
#legend .l-title { font-weight: 600; margin-bottom: 4px; }
#legend i {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  margin-right: 8px;
  border: 1px solid #fff;
  vertical-align: middle;
}

/* ночной режим: инверсия обычной OSM-карты */
#map.night .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(0.82) saturate(0.7);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-box {
  width: min(420px, 92vw);
  background: #1a1d23;
  border: 1px solid #3c4048;
  border-radius: 14px;
  padding: 22px;
  display: flex;
  flex-direction: column;
}
.modal-box > * { margin: 6px 0; }
.modal-box h3 { margin: 0; }
.modal-box label { display: flex; flex-direction: column; font-size: 14px; }
.modal-box label input { margin-top: 6px; }
.modal-box input {
  padding: 12px;
  font-size: 15px;
  border: 1px solid #3c4048;
  border-radius: 10px;
  background: #0f1115;
  color: #e8eaed;
}

/* Leaflet popup on dark */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: #1a1d23;
  color: #e8eaed;
}
.leaflet-popup-content { margin: 12px 16px; }
.leaflet-popup-content a { color: #8ab4f8; }

@media (max-width: 720px) {
  .brand { display: none; }
  #topbar { padding: 8px; gap: 6px; }
  button { padding: 11px 12px; font-size: 14px; }
  #panel {
    top: auto;
    left: 0; right: 0; bottom: 0;
    width: 100%;
    max-height: 55%;
    border-radius: 16px 16px 0 0;
  }
}
