* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; font-family: "Segoe UI", system-ui, -apple-system, sans-serif; }

:root {
  --bg: #1b2431;
  --bg2: #222d3d;
  --bg3: #2b384c;
  --line: #35455e;
  --text: #e8edf4;
  --muted: #93a3ba;
  --accent: #4da3ff;
  --accent2: #ffb454;
}

#app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- loader ---------- */
#loader {
  position: fixed; inset: 0; z-index: 5000;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
  transition: opacity .4s;
}
#loader.hide { opacity: 0; pointer-events: none; }
.loader-box { text-align: center; color: var(--text); }
.spinner {
  width: 46px; height: 46px; margin: 0 auto 18px;
  border: 4px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-title { font-size: 18px; font-weight: 600; }
.loader-sub { margin-top: 6px; color: var(--muted); font-size: 13px; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 380px; min-width: 380px; height: 100%;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
  box-shadow: 2px 0 12px rgba(0,0,0,.35); z-index: 1200;
  transition: margin-left .25s;
}
#sidebar.collapsed { margin-left: -380px; }

.sb-header { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.sb-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sb-header h1 { font-size: 17px; font-weight: 700; letter-spacing: .3px; }

.hdr-actions { display: flex; gap: 6px; align-items: center; }
.dl-wrap, .lang-dd { position: relative; }
#dlBtn {
  background: var(--accent); color: #06294d; border: none; border-radius: 7px;
  padding: 6px 10px; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
#dlBtn:hover { background: #66b2ff; }
#langBtn {
  background: var(--bg3); color: var(--text); border: 1px solid var(--line); border-radius: 7px;
  padding: 6px 8px; font-size: 12px; cursor: pointer; white-space: nowrap;
}
#langBtn:hover { border-color: var(--accent); }
#to3dLink {
  background: var(--accent2); color: #3d2600; border-radius: 7px;
  padding: 6px 9px; font-size: 12px; font-weight: 700; text-decoration: none; white-space: nowrap;
}
#to3dLink:hover { background: #ffc877; }
#langMenu { min-width: 120px; }
#langMenu button { display: block; width: 100%; text-align: left; padding: 7px 10px; background: none; border: none; border-radius: 7px; color: var(--text); font-size: 12.5px; cursor: pointer; }
#langMenu button:hover { background: var(--bg3); }
#langMenu button.on { color: var(--accent); font-weight: 600; }

.region-select {
  width: 100%; margin: 8px 0 2px; padding: 7px 8px;
  background: var(--bg3); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; font-size: 13px; outline: none; font-weight: 600;
}
.region-select.hidden { display: none; }

.dl-back { background: none; border: none; color: var(--accent); font-size: 16px; cursor: pointer; margin-right: 4px; padding: 0 4px; }
.dl-scroll { max-height: 320px; overflow-y: auto; }
.dl-scroll::-webkit-scrollbar { width: 8px; }
.dl-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.dl-menu {
  position: absolute; right: 0; top: 34px; z-index: 1400;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px; min-width: 230px; box-shadow: 0 6px 20px rgba(0,0,0,.5);
}
.dl-menu.hidden { display: none; }
.dl-menu button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; margin: 2px 0;
  background: none; border: none; border-radius: 7px; color: var(--text);
  font-size: 12.5px; cursor: pointer;
}
.dl-menu button:hover { background: var(--bg3); }
.dl-menu button small { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }
.dl-menu button.dl-hl { border: 1px solid var(--accent2); }
.dl-menu button.dl-hl:hover { background: rgba(255,180,84,.12); }
.dl-menu .dl-head { padding: 5px 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.dl-menu .dl-note { padding: 6px 10px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); margin-top: 4px; }
.sb-stats { margin-top: 6px; display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.sb-stats b { color: var(--accent); font-weight: 600; }

.sb-search { position: relative; padding: 10px 12px 4px; }
.sb-search input {
  width: 100%; padding: 9px 30px 9px 12px;
  background: var(--bg3); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); font-size: 13.5px; outline: none;
}
.sb-search input:focus { border-color: var(--accent); }
.sb-search input::placeholder { color: var(--muted); }
#searchClear {
  position: absolute; right: 20px; top: 15px;
  background: none; border: none; color: var(--muted);
  font-size: 18px; cursor: pointer; display: none;
}
#searchClear:hover { color: var(--text); }

.sb-filters { display: flex; gap: 6px; padding: 8px 12px; }
.sb-filters select {
  flex: 1; min-width: 0; padding: 6px 6px;
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; font-size: 12px; outline: none;
}
.sb-filters > button {
  width: 34px; background: var(--bg3); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; cursor: pointer; font-size: 14px;
}
.sb-filters button:hover, .sb-filters select:hover { border-color: var(--accent); }

.type-dd { position: relative; flex: 1; min-width: 0; display: flex; }
#typeBtn {
  flex: 1; min-width: 0; padding: 6px 6px; background: var(--bg3); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; cursor: pointer; font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#typeBtn.filtered { border-color: var(--accent2); color: var(--accent2); }
#typeMenu { left: 0; right: auto; top: 34px; min-width: 250px; }
#typeMenu label {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; margin: 1px 0;
  border-radius: 7px; cursor: pointer; font-size: 12.5px;
}
#typeMenu label:hover { background: var(--bg3); }
#typeMenu .sw { width: 16px; height: 4px; border-radius: 2px; }
#typeMenu .tm-actions { display: flex; gap: 6px; padding: 6px 8px 2px; }
#typeMenu .tm-actions button {
  flex: 1; padding: 5px; font-size: 11.5px; background: var(--bg3); color: var(--accent);
  border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
}
#typeMenu .tm-actions button:hover { border-color: var(--accent); }

.sb-breadcrumb { padding: 6px 14px; font-size: 12.5px; color: var(--muted); border-bottom: 1px solid var(--line); min-height: 30px; display: flex; align-items: center; flex-wrap: wrap; gap: 4px;}
.sb-breadcrumb a { color: var(--accent); cursor: pointer; text-decoration: none; }
.sb-breadcrumb a:hover { text-decoration: underline; }
.sb-breadcrumb .sep { color: var(--muted); margin: 0 2px; }

.sb-content { flex: 1; overflow-y: auto; padding: 6px 8px 20px; }
.sb-content::-webkit-scrollbar { width: 9px; }
.sb-content::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }
.sb-content::-webkit-scrollbar-track { background: transparent; }

.group-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); padding: 12px 8px 5px; font-weight: 600;
}
.count-badge { color: var(--accent); }

.item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 9px; margin: 2px 0; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent;
}
.item:hover { background: var(--bg3); }
.item.active { background: var(--bg3); border-color: var(--accent); }
.item .dot { width: 11px; height: 11px; min-width: 11px; border-radius: 3px; }
.item .dot.line { height: 4px; border-radius: 2px; width: 14px; min-width: 14px; }
.item .t { flex: 1; min-width: 0; }
.item .t .n { display: block; font-size: 13.5px; line-height: 1.25; }
.item .t .s { display: block; font-size: 11.5px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .v { font-size: 11.5px; color: var(--muted); text-align: right; white-space: nowrap; min-width: 46px; }
.item .v b { display: block; color: var(--text); font-weight: 600; }
.item .v .v2 { display: block; font-size: 10.5px; color: var(--muted); margin-top: 1px; }

.district-card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin: 8px 4px;
}
.district-card h3 { font-size: 15px; }
.district-card .meta { display: flex; gap: 14px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.district-card .meta b { color: var(--accent2); }

.btn-more {
  display: block; width: calc(100% - 8px); margin: 8px 4px; padding: 8px;
  background: var(--bg3); color: var(--accent); border: 1px dashed var(--line);
  border-radius: 8px; cursor: pointer; font-size: 12.5px;
}
.btn-more:hover { border-color: var(--accent); }

.empty { padding: 30px 10px; text-align: center; color: var(--muted); font-size: 13px; }

.mini-tabs { display: flex; gap: 6px; padding: 8px 4px 2px; }
.mini-tabs button {
  flex: 1; padding: 7px; font-size: 12.5px; cursor: pointer;
  background: var(--bg2); color: var(--muted); border: 1px solid var(--line); border-radius: 8px;
}
.mini-tabs button.on { color: var(--text); border-color: var(--accent); background: var(--bg3); }

/* ---------- map ---------- */
#mapwrap { flex: 1; position: relative; }
#map { height: 100%; width: 100%; background: #dfe6ee; }

#sbToggle {
  position: absolute; top: 12px; left: 12px; z-index: 1100;
  width: 38px; height: 38px; border-radius: 8px; border: none; cursor: pointer;
  background: var(--bg); color: var(--text); font-size: 17px;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

.map-panel {
  position: absolute; z-index: 1050;
  background: rgba(27,36,49,.92); color: var(--text);
  border-radius: 10px; padding: 10px 13px; font-size: 12.5px;
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
  max-width: 320px;
}
#legend { bottom: 22px; right: 12px; }
#legend .lg-title { font-weight: 600; font-size: 12px; margin-bottom: 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
#legend .lg-row { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
#legend .sw { width: 18px; height: 4px; border-radius: 2px; }
#legend .sw.poly { height: 12px; border-radius: 3px; opacity: .75; }

#infobox { top: 60px; right: 12px; min-width: 240px; }
#infobox.hidden { display: none; }
#infobox h3 { font-size: 14.5px; margin-bottom: 2px; padding-right: 20px; }
#infobox .sub { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
#infobox .row { display: flex; justify-content: space-between; gap: 14px; padding: 3px 0; border-top: 1px solid var(--line); }
#infobox .row span:first-child { color: var(--muted); }
#infobox .close { position: absolute; top: 8px; right: 10px; cursor: pointer; color: var(--muted); font-size: 16px; background: none; border: none;}
#infobox .close:hover { color: var(--text); }
#infobox .actions { margin-top: 9px; }
#infobox .actions button {
  width: 100%; padding: 7px; background: var(--bg3); color: var(--accent);
  border: 1px solid var(--line); border-radius: 7px; cursor: pointer; font-size: 12.5px;
}
#infobox .actions button:hover { border-color: var(--accent); }

.district-label {
  background: none; border: none; box-shadow: none;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none; overflow: hidden;
}
.district-label span {
  color: #1a2a40; font-weight: 700; text-align: center;
  text-transform: uppercase; letter-spacing: .8px; line-height: 1;
  text-shadow: 0 1px 2px rgba(255,255,255,.95), 0 0 7px rgba(255,255,255,.85), 0 0 2px rgba(255,255,255,1);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.mahalla-label {
  background: none; border: none; box-shadow: none;
  color: #1c2c42; font-weight: 600; font-size: 11px; text-align: center;
  text-shadow: 0 1px 2px rgba(255,255,255,.9), 0 0 5px rgba(255,255,255,.75);
  white-space: nowrap; pointer-events: none;
}

/* ---------- панель слоёв и редактирование ---------- */
#layersPanel { top: 60px; left: 12px; min-width: 200px; }
#layersPanel .lg-title { font-weight: 600; font-size: 12px; margin-bottom: 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.lyr { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; font-size: 12.5px; }
.lyr input { accent-color: var(--accent); cursor: pointer; }
.lyr-hint { font-size: 10.5px; color: var(--muted); padding: 3px 0; line-height: 1.45; }
.lyr-sep { border: none; border-top: 1px solid var(--line); margin: 7px 0; }
.edit-btn {
  display: block; width: 100%; margin: 3px 0; padding: 7px 9px; text-align: left;
  background: var(--bg3); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; cursor: pointer; font-size: 12px;
}
.edit-btn:hover { border-color: var(--accent); }
.edit-btn.on { border-color: var(--accent2); color: var(--accent2); }
.edit-btn.sub { font-size: 11.5px; padding: 6px 9px; }
.edit-btn.danger:hover { border-color: #e53935; color: #ef9a9a; }
#editPanel.hidden { display: none; }
.badge-edit { color: var(--accent2); font-size: 11px; }

/* тулбар Geoman — правее панели слоёв */
#mapwrap .leaflet-top.leaflet-left { left: 262px; }
/* переключатель подложек всегда выше инфопанели МФЙ */
#mapwrap .leaflet-top.leaflet-right { z-index: 1200; }

.leaflet-container { font: inherit; }
.leaflet-popup-content-wrapper { border-radius: 10px; }
.leaflet-popup-content { margin: 12px 16px; font-size: 13px; }
.popup-title { font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.popup-sub { color: #667; font-size: 12px; margin-bottom: 6px; }
.popup-kv { font-size: 12.5px; color: #334; line-height: 1.5; }

@media (max-width: 720px) {
  #sidebar { position: absolute; z-index: 1300; height: 100%; width: 85vw; min-width: 0; }
  #sidebar.collapsed { margin-left: -85vw; }
}
