* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: #0e1621;
  color: #e8edf2;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  background: #072732; /* цвет океана Realmap */
  cursor: grab;
}
#map.tool-active { cursor: crosshair; }
#map.tool-eraser { cursor: none; }

/* Кисть ластика — сама служит курсором */
.load-error {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1600;
  max-width: min(560px, 92vw);
  background: rgba(120, 25, 20, 0.95);
  border: 1px solid rgba(255, 107, 107, 0.6);
  color: #ffe0e0;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
}

.eraser-cursor {
  position: fixed;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px;
  border: 2px solid rgba(255,255,255,0.95);
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 0 8px rgba(0,0,0,0.4);
  pointer-events: none;
  z-index: 1500;
}

.hidden { display: none !important; }

/* ---------- Верхняя панель ---------- */
.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 10px 16px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.btn {
  background: rgba(14, 22, 33, 0.9);
  border: 1px solid rgba(255,255,255,0.12);
  color: #e8edf2;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: rgba(35, 48, 68, 0.95); border-color: rgba(255,255,255,0.25); }
.btn-primary { background: #2f7ef7; border-color: #2f7ef7; font-weight: 600; }
.btn-primary:hover { background: #1f6ce0; border-color: #1f6ce0; }
.btn-small { padding: 4px 10px; font-size: 12px; }

.admin-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(14, 22, 33, 0.9);
  border: 1px solid rgba(46, 204, 113, 0.4);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
}
.admin-badge .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #2ecc71;
  box-shadow: 0 0 6px #2ecc71;
}

.save-status {
  background: rgba(14, 22, 33, 0.85);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: #9fb3c8;
}
.save-status.saved { color: #2ecc71; }

/* ---------- Единая боковая панель (инструменты + фильтр меток) ---------- */
.side-panel {
  position: absolute;
  top: 70px;
  left: 12px;
  z-index: 1000;
  width: 220px;
  background: rgba(14, 22, 33, 0.92);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  max-height: calc(100vh - 90px);
  overflow-y: auto;
}

/* разделитель между секцией инструментов и фильтром */
.tools-section + .filter-section { border-top: 1px solid rgba(255,255,255,0.1); }

/* Единый переключатель показа всех меток */
.markers-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  cursor: pointer;
  user-select: none;
}
.markers-toggle-label { flex: 1; font-weight: 700; font-size: 14px; }
.markers-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  width: 42px;
  height: 24px;
  border-radius: 12px;
  background: rgba(255,255,255,0.18);
  flex-shrink: 0;
  transition: background 0.15s;
  position: relative;
}
.switch-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.markers-toggle input:checked + .switch-track { background: #2f7ef7; }
.markers-toggle input:checked + .switch-track .switch-thumb { transform: translateX(18px); }

.markers-toggle + .markers-toggle { border-top: 1px solid rgba(255,255,255,0.07); }
.kind-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 7px;
  border: 1px solid rgba(255,255,255,0.4);
  vertical-align: middle;
}

/* Надписи видны только при приближении — на обзорной карте их нет */
body.hide-text .map-text-label { display: none !important; }

/* ---------- Зоны: капты и дропы ---------- */
.zone-label {
  background: transparent;
  border: none;
  pointer-events: none;
}
.zone-label span {
  display: inline-block;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.3px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9), 0 0 8px rgba(0,0,0,0.6);
}
.zone-kind {
  font-size: 12px;
  color: #9fb3c8;
  margin-top: 2px;
}

/* ---------- Попап метки ---------- */
.leaflet-popup-content-wrapper {
  background: #16202e !important;
  color: #e8edf2 !important;
  border-radius: 10px !important;
  border: 1px solid rgba(255,255,255,0.1);
}
.leaflet-popup-tip { background: #16202e !important; }
.leaflet-popup-content { margin: 12px 14px !important; }
.marker-popup b { display: block; font-size: 14px; margin-bottom: 4px; }
.marker-link {
  display: inline-block;
  margin-top: 4px;
  color: #5da1ff;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}
.marker-link:hover { text-decoration: underline; }
.leaflet-popup-close-button { color: #9fb3c8 !important; }

/* ---------- Секция инструментов внутри единой панели ---------- */
.tools-section { padding: 10px; }

.tool-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}
.tool {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  color: #e8edf2;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.12s;
}
.tool:hover { background: rgba(255,255,255,0.08); }
.tool.active {
  background: #2f7ef7;
  border-color: #5da1ff;
  box-shadow: 0 0 10px rgba(47, 126, 247, 0.5);
}

.swatches {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 5px;
  margin-bottom: 8px;
}
.swatch {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.25);
  transition: transform 0.1s;
}
.swatch:hover { transform: scale(1.15); }
.swatch.active { outline: 2px solid #fff; outline-offset: 1px; }

.tool-hint {
  font-size: 11px;
  line-height: 1.35;
  color: #7d8fa3;
  margin: 2px 0 8px;
}
.tool-controls { display: flex; align-items: center; gap: 8px; }
#color-custom {
  width: 40px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
}
#width-slider { flex: 1; cursor: pointer; }

/* ---------- Текстовые метки на карте ---------- */
.map-text-label {
  background: transparent;
  border: none;
  box-shadow: none;
}
/* Надписи не мешают двигать карту; у админа их можно хватать в обычном режиме, тексте и ластике */
body.admin .map-text-label { pointer-events: none; }
body.admin.tool-pan .map-text-label,
body.admin.tool-text .map-text-label,
body.admin.tool-eraser .map-text-label { pointer-events: auto; }
body.admin.tool-pan .map-text-label,
body.admin.tool-text .map-text-label { cursor: grab; }
body.admin.tool-pan .map-pin,
body.admin.tool-text .map-pin { cursor: grab; }
body.rotating, body.rotating * { cursor: grabbing !important; }
body.moving, body.moving * { cursor: move !important; }

.map-text-label span {
  display: inline-block;
  white-space: nowrap;
  font-weight: 700;
  font-size: 15px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8), 0 0 6px rgba(0,0,0,0.5);
  transform: translate(-50%, -50%);
}

.map-pin {
  background: transparent;
  border: none;
}
.map-pin svg { filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5)); }

/* ---------- Модальное окно ---------- */
.modal {
  position: absolute;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-box {
  background: #16202e;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 26px;
  width: min(380px, 90vw);
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}
.modal-box h2 { font-size: 18px; margin-bottom: 8px; }
.modal-hint { font-size: 13px; color: #9fb3c8; margin-bottom: 16px; line-height: 1.45; }
.modal-box input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  background: #0e1621;
  color: #e8edf2;
  font-size: 15px;
  margin-bottom: 12px;
}
.modal-box input[type="password"]:focus { outline: none; border-color: #2f7ef7; }
.login-error { color: #ff6b6b; font-size: 13px; margin-bottom: 10px; }
.modal-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.modal-spacer { flex: 1; }

.field-label {
  display: block;
  font-size: 12px;
  color: #9fb3c8;
  margin: 10px 0 4px;
}
.modal-box input[type="text"] {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  background: #0e1621;
  color: #e8edf2;
  font-size: 14px;
}
.modal-box input[type="text"]:focus { outline: none; border-color: #2f7ef7; }
.marker-swatches { grid-template-columns: repeat(9, 18px); gap: 6px; margin-top: 4px; }
.marker-swatches .swatch { width: 18px; height: 18px; }
.btn-danger { background: rgba(255,59,48,0.15); border-color: rgba(255,59,48,0.5); color: #ff6b6b; }
.btn-danger:hover { background: rgba(255,59,48,0.28); }

/* ---------- Редактор текста ---------- */
.modal-wide { width: min(440px, 92vw); }
.text-preview-wrap {
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(45deg, #1b2836 25%, transparent 25%, transparent 75%, #1b2836 75%) 0 0/20px 20px,
    linear-gradient(45deg, #1b2836 25%, #0e1621 25%, #0e1621 75%, #1b2836 75%) 10px 10px/20px 20px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 12px;
}
#text-preview {
  display: inline-block;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0,0,0,0.85), 0 0 6px rgba(0,0,0,0.5);
  transition: transform 0.08s;
}
.modal-box textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  background: #0e1621;
  color: #e8edf2;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.modal-box textarea:focus { outline: none; border-color: #2f7ef7; }

.text-align-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 4px;
}
.align-btn {
  padding: 8px 4px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  background: #0e1621;
  color: #e8edf2;
  cursor: pointer;
  font-size: 13px;
  transition: border-color 0.12s, background 0.12s;
}
.align-btn:hover { background: rgba(255,255,255,0.06); }
.align-btn.active { border-color: #2f7ef7; background: rgba(47,126,247,0.18); }

.text-styles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 4px;
}
.text-style-btn {
  padding: 8px 6px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  background: #0e1621;
  color: #e8edf2;
  cursor: pointer;
  font-size: 14px;
  text-align: center;
  transition: border-color 0.12s, background 0.12s;
}
.text-style-btn:hover { background: rgba(255,255,255,0.06); }
.text-style-btn.active { border-color: #2f7ef7; background: rgba(47,126,247,0.18); }

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.slider-row label { width: 90px; font-size: 13px; color: #9fb3c8; flex-shrink: 0; }
.slider-row input[type="range"] { flex: 1; cursor: pointer; accent-color: #2f7ef7; }
.slider-val { width: 42px; text-align: right; font-size: 13px; color: #cdd8e4; }

.text-flip-row { display: flex; gap: 8px; margin-top: 12px; }
.text-flip-row .btn { flex: 1; }

/* ---------- Leaflet тёмная тема ---------- */
.leaflet-control-layers,
.leaflet-control-zoom a {
  background: rgba(14, 22, 33, 0.92) !important;
  color: #e8edf2 !important;
  border-color: rgba(255,255,255,0.15) !important;
}
.leaflet-control-zoom a:hover { background: rgba(35, 48, 68, 0.95) !important; }
.leaflet-control-layers-expanded { color: #e8edf2; }
.leaflet-control-attribution {
  background: rgba(14, 22, 33, 0.7) !important;
  color: #7d8fa3 !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: #9fb3c8 !important; }

@media (max-width: 600px) {
  .btn { font-size: 12px; padding: 6px 10px; }
}
