:root {
  --bg: #eaf6fb;
  --surface: #ffffff;
  --surface-2: #f2f9fc;
  --border: #d5e7ef;
  --text: #123344;
  --muted: #5f7f8f;
  --accent: #ff6b35;
  --accent-2: #ff3d5a;
  --water: #7fd4ee;
  --water-2: #a8e4f5;
  --ok: #1e9e63;
  --err: #d64550;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  color: var(--text);
  background: linear-gradient(180deg, #f6fcff 0%, var(--bg) 55%, #d8f0f9 100%);
  min-height: 100vh;
}

/* ---------- Волны воды ---------- */
body::before, body::after {
  content: "";
  position: fixed;
  left: 0;
  bottom: var(--kb-gap, 0px);
  width: 200%;
  height: 180px;
  pointer-events: none;
  z-index: -1;
  background-repeat: repeat-x;
  background-size: 50% 100%;
}

body::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 180' preserveAspectRatio='none'%3E%3Cpath d='M0,90 C200,150 400,30 600,90 C800,150 1000,30 1200,90 L1200,180 L0,180 Z' fill='%23a8e4f5' fill-opacity='0.7'/%3E%3C/svg%3E");
  animation: drift 14s linear infinite;
}

body::after {
  height: 140px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 140' preserveAspectRatio='none'%3E%3Cpath d='M0,70 C150,20 350,120 600,70 C850,20 1050,120 1200,70 L1200,140 L0,140 Z' fill='%237fd4ee' fill-opacity='0.55'/%3E%3C/svg%3E");
  animation: drift 9s linear infinite reverse;
}

@keyframes drift {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

/* ---------- Кораблик на ближней волне (правый край) ---------- */
html::after {
  content: "";
  position: fixed;
  right: 6%;
  bottom: calc(34px + var(--kb-gap, 0px));  /* корпус погружён в ближнюю волну (body::after, h140) */
  width: 150px;
  height: 122px;
  z-index: -1;
  pointer-events: none;
  background-repeat: no-repeat;
  background-size: contain;
  transform-origin: 50% 78%;
  /* период качания = периоду дрейфа ближней волны (9s), чтобы кораблик шёл по гребню */
  animation: bob 9s ease-in-out infinite;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 368 300'%3E%3Cpath fill='%2357b0cd' d='M8 118 L120 140 L184 40 L248 140 L360 118 L312 250 L56 250 Z'/%3E%3Cpath fill='%23fff' d='M40 150 L165 205 L74 240 Z'/%3E%3Cpath fill='%23fff' d='M328 150 L203 205 L294 240 Z'/%3E%3Cpath fill='%23fff' d='M184 60 L184 195 L120 158 Z'/%3E%3Cpath fill='%23fff' d='M184 60 L184 195 L248 158 Z'/%3E%3Cpath fill='%23fff' d='M100 240 L184 200 L268 240 Z'/%3E%3Crect x='180' y='18' width='8' height='90' fill='%2357b0cd'/%3E%3Cpath fill='%23d85460' d='M180 20 Q150 30 128 40 Q150 50 180 60 Z'/%3E%3C/svg%3E");
}

/* поднимается на гребне + кренится, опускается во впадине — идёт по волне */
@keyframes bob {
  0%   { transform: translateY(4px)   rotate(-5deg); }
  25%  { transform: translateY(-10px) rotate(4deg); }
  50%  { transform: translateY(4px)   rotate(5deg); }
  75%  { transform: translateY(-10px) rotate(-4deg); }
  100% { transform: translateY(4px)   rotate(-5deg); }
}

@media (max-width: 600px) {
  html::after { right: 2%; bottom: calc(24px + var(--kb-gap, 0px)); width: 100px; height: 82px; }
}

/* ---------- Навигация ---------- */
nav {
  position: sticky;
  top: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .6rem 1.2rem;
  background: rgba(255, 255, 255, .75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-right: 1.2rem;
  font-weight: 700;
  letter-spacing: .02em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
}

.logo .flame {
  font-size: 1.15rem;
  -webkit-background-clip: initial;
  background: none;
  color: initial;
  animation: flicker 2.4s ease-in-out infinite;
}

@keyframes flicker {
  0%, 100% { transform: scale(1) rotate(0deg); opacity: 1; }
  30%      { transform: scale(1.12) rotate(-3deg); opacity: .85; }
  60%      { transform: scale(.95) rotate(2deg); opacity: 1; }
}

nav a {
  color: var(--muted);
  text-decoration: none;
  padding: .45rem .9rem;
  border-radius: 999px;
  font-size: .95rem;
  transition: color .2s, background .2s;
}

/* Меню скрыто, открывается кликом по логотипу с паролем (nav.js) */
nav:not(.menu-open) a { display: none; }
.logo { cursor: pointer; }

nav a:hover { color: var(--text); background: var(--surface-2); }

.nav-logout {
  width: auto;
  margin: 0 0 0 auto;
  padding: .45rem .9rem;
  font-size: .9rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}
.nav-logout:hover {
  color: var(--text);
  border-color: var(--accent);
  box-shadow: none;
  transform: none;
}

/* select — как input */
select {
  width: 100%;
  padding: .65rem .85rem;
  margin-top: .35rem;
  font-size: 1rem;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, .18);
}

nav a.active {
  color: #fff;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 2px 12px rgba(255, 90, 60, .35);
}

/* ---------- Контент ---------- */
main {
  max-width: 640px;
  margin: 2.5rem auto;
  padding: 0 1rem;
  animation: rise .45s cubic-bezier(.2, .7, .3, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

h1 { font-size: 1.5rem; margin: 0 0 1.2rem; }
h1 small { color: var(--muted); font-size: .95rem; font-weight: 400; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: 0 8px 30px rgba(18, 51, 68, .1);
}

/* ---------- Формы ---------- */
label { display: block; margin-top: 1rem; font-weight: 600; font-size: .9rem; }

input, button {
  width: 100%;
  padding: .65rem .85rem;
  margin-top: .35rem;
  font-size: 1rem;
  border-radius: 10px;
}

input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  transition: border-color .2s, box-shadow .2s;
}

input::placeholder { color: var(--muted); }

.copy-field { display: flex; gap: .4rem; align-items: center; }
.copy-field input { width: auto; flex: 1; }
.copy-field .copy-btn { width: auto; padding: .5rem .6rem; margin-top: .35rem; flex: 0 0 auto; }

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, .18);
}

input:disabled { opacity: .6; }

/* Подсветка ошибок — только после попытки отправки */
form.submitted input:invalid {
  border-color: var(--err);
  background: rgba(214, 69, 80, .06);
}

form.submitted input:invalid:focus {
  border-color: var(--err);
  box-shadow: 0 0 0 3px rgba(214, 69, 80, .18);
}

button {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff;
  border: 0;
  cursor: pointer;
  margin-top: 1.5rem;
  font-weight: 600;
  transition: transform .15s, box-shadow .2s, filter .2s;
}

button:hover {
  filter: brightness(1.06);
  box-shadow: 0 4px 18px rgba(255, 90, 60, .35);
  transform: translateY(-1px);
}

button:active { transform: translateY(0); }

/* Кнопка «Сохранить» — цвет морской волны */
#f button { background: linear-gradient(90deg, #06b6a4, #0e7490); }
#f button:hover { box-shadow: 0 4px 18px rgba(6, 182, 164, .35); }

#msg { min-height: 1.5em; margin-bottom: 0; }
.ok { color: var(--ok); }
.err { color: var(--err); }
.hint { display: block; margin-top: .35rem; color: var(--ok); font-weight: 400; font-size: .85rem; }

/* ---------- Настройки / Админ ---------- */
section.card h2 { font-size: 1.15rem; margin: 0 0 .8rem; }
section.card h3 { font-size: 1rem; margin: 1.2rem 0 .4rem; }
.row-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
  background: var(--surface-2);
}
.src-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .4rem 0;
  border-bottom: 1px solid var(--border);
}
.src-del, .e-copy, .e-save, .admin-act {
  width: auto;
  margin: .5rem .5rem 0 0;
  padding: .35rem .8rem;
  font-size: .85rem;
}
.src-del {
  background: transparent;
  border: 1px solid var(--err);
  color: var(--err);
  margin: 0;
}
.src-del:hover { background: var(--err); color: #fff; box-shadow: none; }

/* ---------- Таблица ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(18, 51, 68, .08);
}

th, td { text-align: left; padding: .6rem .85rem; border-bottom: 1px solid var(--border); }

th {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  background: var(--surface-2);
}

tbody tr { transition: background .15s; animation: rise .3s ease both; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }

td button {
  width: auto;
  margin: 0;
  padding: .3rem .75rem;
  font-size: .85rem;
  background: transparent;
  border: 1px solid var(--err);
  color: var(--err);
}

td button:hover {
  background: var(--err);
  color: #fff;
  box-shadow: 0 2px 12px rgba(214, 69, 80, .3);
}

/* Кнопка импорта — второстепенная */
button.secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  margin-top: 0;
}

button.secondary:hover { border-color: var(--accent); box-shadow: none; }

#importResult { color: var(--muted); font-size: .9rem; }
#importResult ul { margin: .4rem 0 0; padding-left: 1.2rem; }

/* ---------- Карта ---------- */
#map { height: calc(100vh - 57px); }

#total {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .5rem 1.1rem;
  border-radius: 999px;
  box-shadow: 0 4px 20px rgba(18, 51, 68, .15);
  font-weight: 600;
  animation: rise .5s ease both;
  white-space: nowrap;
}

#total b { color: var(--accent); }

.leaflet-container { background: var(--bg); }

.layer-picker {
  padding: .5rem .75rem;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(18, 51, 68, .15);
  cursor: pointer;
}

.layer-picker:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, .18);
}

.source-picker {
  padding: .5rem .75rem;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(18, 51, 68, .15);
}

.source-picker > summary {
  cursor: pointer;
  list-style: none;
}
.source-picker > summary::-webkit-details-marker { display: none; }
.source-picker > summary::after { content: " ▾"; }
.source-picker[open] > summary::after { content: " ▴"; }

.source-picker .opts {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .35rem;
  max-width: 260px;
  max-height: 260px;
  overflow-y: auto;
  margin-top: .5rem;
  padding-top: .5rem;
  border-top: 1px solid var(--border);
}

.source-picker label {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: .4rem;
  cursor: pointer;
  white-space: nowrap;
  width: 100%;
  text-align: left;
}

.leaflet-tooltip.hover-count {
  font-weight: 700;
  color: var(--text);
  border: 1px solid #e11;
  box-shadow: 0 2px 10px rgba(18, 51, 68, .2);
}

.leaflet-bottom.leaflet-right { bottom: 32px; margin-bottom: 0; }
.leaflet-bottom.leaflet-right .leaflet-control { margin-bottom: 0; }

.highlight-toggle {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(18, 51, 68, .15);
  cursor: pointer;
  user-select: none;
}

.highlight-toggle input { display: none; }

.highlight-toggle .track {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  transition: background .2s;
}

.highlight-toggle .track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}

.highlight-toggle input:checked + .track { background: var(--accent); }
.highlight-toggle input:checked + .track::after { transform: translateX(16px); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
