* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: system-ui, "Segoe UI", Roboto, sans-serif; }
#map { position: absolute; inset: 0; z-index: 1; }

#panel {
  position: absolute; top: 12px; left: 12px; z-index: 1000;
  width: 320px; max-height: calc(100% - 24px); overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: rgba(255,255,255,.95); backdrop-filter: blur(4px);
  border: 1px solid #cfcfcf; border-radius: 10px; padding: 12px 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.18); font-size: 13px; color: #222;
}
#panel.hidden { display: none; }

/* drawer toggle buttons */
#openPanel {
  position: absolute; top: 12px; left: 12px; z-index: 1000;
  display: none; align-items: center; gap: 4px;
  padding: 10px 14px; font-size: 15px; font-weight: 600;
  background: #fff; color: #2e7d32; border: 1px solid #bbb; border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,.2); cursor: pointer;
}
#closePanel {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  width: 34px; height: 34px; border: 1px solid #ccc; border-radius: 8px;
  background: #f4f4f4; color: #444; font-size: 17px; line-height: 1; cursor: pointer;
  display: none;
}
#panel h1 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 7px; }
#panel h1 .logo { flex: 0 0 auto; }
#helpBtn {
  margin-left: auto; flex: 0 0 auto;
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid #9cc79f; background: #eef6ee; color: #2e7d32;
  font-size: 15px; font-weight: 700; text-decoration: none;
}
#helpBtn:hover { background: #2e7d32; color: #fff; }
#panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: #666; margin: 14px 0 6px; }
section { border-top: 1px solid #eee; padding-top: 4px; }
section:first-of-type { border-top: none; }

.btnrow { display: flex; flex-wrap: wrap; gap: 6px; }
.btnrow button {
  flex: 1 1 auto; padding: 6px 8px; border: 1px solid #bbb; background: #f7f7f7;
  border-radius: 7px; cursor: pointer; font-size: 12px; white-space: nowrap;
}
.btnrow button.active { background: #2e7d32; color: #fff; border-color: #2e7d32; }
.btnrow button:hover { border-color: #2e7d32; }
button.toggle { width: 100%; }
button.toggle.active { background: #b8860b; border-color: #b8860b; color:#fff; }

label.ov { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.ov-ico { flex: 0 0 18px; width: 18px; height: 18px; color: #2e7d32;
  display: inline-flex; align-items: center; justify-content: center; }
.ov-ico svg { display: block; }
.slider { display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; color: #666; font-size: 11px; }
.slider[hidden] { display: none; }   /* иначе .slider перебивает атрибут hidden (как у .gate/.account) */
.slider input { flex: 1; }
#rainPlay { flex: 0 0 auto; width: 24px; height: 22px; padding: 0; border: 1px solid #bbb;
  background: #f2f6ff; border-radius: 6px; cursor: pointer; font-size: 11px;
  display: inline-flex; align-items: center; justify-content: center; color: #2e6fd6; }
#rainPlay:hover { border-color: #2e6fd6; }
.rainlabel { flex: 0 0 auto; min-width: 92px; text-align: right; color: #2e6fd6; font-variant-numeric: tabular-nums; }

.hint { font-size: 11px; color: #888; margin: 4px 0 0; line-height: 1.35; }
.muted { color: #999; font-weight: normal; text-transform: none; letter-spacing: 0; }
.credit { font-size: 10px; color: #999; margin-top: 14px; line-height: 1.4; }

#candLegend { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.clsub { display: flex; flex-direction: column; gap: 3px; margin: 0 0 6px 26px; }
.clrow { display: flex; align-items: center; gap: 8px; font-size: 11px; line-height: 1.25; }
.clrow .sw { flex: 0 0 14px; width: 14px; height: 14px; border: 1px solid #999; border-radius: 3px; }
/* простой / эксперт режим панели: #expert виден только в экспертном */
#expert { display: none; }
#panel.expertMode #expert { display: block; }
#modeToggle { margin-top: 10px; }
#legend { display: flex; flex-direction: column; gap: 3px; }
.legrow { display: grid; grid-template-columns: 16px 42px 1fr auto; gap: 7px;
  align-items: center; padding: 2px 3px; border-radius: 5px; cursor: pointer; }
.legrow:hover { background: #f0f0f0; }
.legrow.dim { opacity: .32; }
.legrow .sw { width: 14px; height: 14px; border: 1px solid #999; border-radius: 3px; }
.legrow .code { font-family: ui-monospace, monospace; font-size: 11px; color: #444; }
.legrow .name { font-size: 11px; line-height: 1.25; }
.legrow .n { font-size: 11px; color: #999; }
.legrow.star .name { font-weight: 600; }
.star-badge { color: #b8860b; }

.soil-popup b { font-size: 13px; }
.soil-popup .rating { display:inline-block; margin-top:4px; font-weight:600; }
.navlinks { margin-top: 8px; padding-top: 6px; border-top: 1px solid #eee; font-size: 12px; }
.coordline { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.coord { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; color: #333; user-select: all; }
.copybtn {
  flex: 0 0 auto; padding: 3px 8px; font-size: 11px; cursor: pointer;
  color: #2e7d32; background: #f4f9f4; border: 1px solid #bcd6bd; border-radius: 6px; white-space: nowrap;
}
.copybtn:hover { background: #eef6ee; }
.navrow { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 4px; line-height: 1.6; }
.navrow a {
  color: #2e7d32; text-decoration: none; font-weight: 600;
  padding: 3px 7px; border: 1px solid #bcd6bd; border-radius: 6px; white-space: nowrap;
}
.navrow a:hover { background: #eef6ee; }

/* ---------- OpenLayers controls ---------- */
.ol-zoom { top: 8px; right: 8px; left: auto; }
.ol-attribution { font-size: 10px; }

/* geolocation button */
#locate {
  position: absolute; top: 74px; right: 8px; z-index: 5;
  width: 40px; height: 40px; padding: 0; cursor: pointer; color: #333;
  background: rgba(255,255,255,.95); border: 1px solid #cfcfcf; border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  display: flex; align-items: center; justify-content: center;
}
#locate.active { background: #e3f0ff; color: #1a73e8; border-color: #9ec3f5; }

/* ---------- OpenLayers popup ---------- */
#popup {
  position: absolute; z-index: 4; min-width: 180px; max-width: 260px;
  transform: translate(-50%, calc(-100% - 14px));
  background: #fff; border-radius: 8px; padding: 10px 12px;
  box-shadow: 0 2px 14px rgba(0,0,0,.3); font-size: 13px; color: #222;
}
#popup[hidden] { display: none; }
#popup::after {   /* хвостик-указатель вниз */
  content: ''; position: absolute; left: 50%; top: 100%;
  transform: translateX(-50%); border: 8px solid transparent; border-top-color: #fff;
}
.popup-close {
  position: absolute; top: 3px; right: 6px; width: 22px; height: 22px;
  border: none; background: none; color: #999; font-size: 17px; line-height: 1; cursor: pointer;
}
.popup-close:hover { color: #444; }
#popupBody { padding-right: 14px; }

/* ---------- mobile ---------- */
@media (max-width: 640px) {
  #panel {
    top: 0; left: 0; right: 0; width: auto;
    max-height: 82vh; border-radius: 0 0 14px 14px;
    padding: 12px 16px 18px; font-size: 14px;
  }
  #closePanel { display: block; }
  #panel h1 { font-size: 16px; padding-right: 40px; }
  #helpBtn { width: 32px; height: 32px; font-size: 17px; }
  #panel h2 { font-size: 12px; margin: 16px 0 8px; }

  /* bigger touch targets */
  label.ov { min-height: 44px; margin: 2px 0; }
  label.ov input[type=checkbox] { width: 20px; height: 20px; flex: 0 0 20px; }
  .btnrow button { padding: 11px 10px; font-size: 14px; }
  button.toggle { padding: 13px 10px; }
  .slider input[type=range] { height: 26px; }
  .legrow { padding: 6px 3px; }
  #baseLayers button { flex: 1 1 44%; }

  #popup { font-size: 14px; }
  .navrow a, .copybtn { padding: 7px 10px; font-size: 13px; }
  .coord { font-size: 13px; }
}

#openPanel.show { display: inline-flex; }

/* ---------- auth gate (платный слой) ---------- */
.lockbadge {
  margin-left: auto; font-size: 10px; font-weight: 600; color: #b8860b;
  border: 1px solid #e0cfa0; background: #fff8e6; border-radius: 6px; padding: 1px 6px;
}
.gate {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(20,20,20,.55); backdrop-filter: blur(3px);
}
.gate[hidden] { display: none; }
.gate-box {
  position: relative; width: 100%; max-width: 340px;
  background: #fff; border-radius: 14px; padding: 22px 22px 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
.gate-box h2 { margin: 0 0 8px; font-size: 17px; }
.gate-lead { margin: 0 0 14px; font-size: 13px; color: #444; line-height: 1.4; }
.gate-hint { margin: 12px 0 0; font-size: 11px; color: #888; line-height: 1.4; }
.gate-error { margin: 8px 0 0; font-size: 12px; color: #c0392b; min-height: 14px; }
.gate-close {
  position: absolute; top: 8px; right: 8px; width: 32px; height: 32px;
  border: 1px solid #ddd; border-radius: 8px; background: #f5f5f5; color: #555;
  font-size: 18px; line-height: 1; cursor: pointer;
}
.gate-btn {
  display: block; width: 100%; text-align: center; text-decoration: none;
  padding: 12px 14px; margin: 8px 0; border-radius: 9px; font-size: 14px; font-weight: 600;
  cursor: pointer; border: 1px solid transparent;
}
.gate-ya { background: #fc3f1d; color: #fff; }   /* Яндекс */
.gate-ya:hover { background: #e63612; }
.gate-vk { background: #0077ff; color: #fff; }   /* VK */
.gate-vk:hover { background: #0062d6; }
.gate-primary { background: #2e7d32; color: #fff; }
.gate-primary:hover { background: #276b2a; }
.gate-primary:disabled { opacity: .6; cursor: default; }
.account {
  display: flex; align-items: center; gap: 8px; margin: -4px 0 10px;
  font-size: 12px; color: #555;
}
.account[hidden] { display: none; }
.account a { margin-left: auto; color: #2e7d32; font-weight: 600; text-decoration: none; }
.account a:hover { text-decoration: underline; }
.gate-hint a { color: #2e7d32; }
#keyInput {
  width: 100%; padding: 11px 12px; font-size: 15px; letter-spacing: .04em;
  border: 1px solid #bbb; border-radius: 9px; font-family: ui-monospace, monospace;
}
#keyInput:focus { outline: none; border-color: #2e7d32; }
