:root {
  --accent: #e63946;
  --accent-dark: #c1121f;
  --ink: #1d3557;
  --muted: #66738c;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #dbe2ec;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------- карта ---------- */
.map-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
  background: #dfe6ee;
}

.stats {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 18px;
  font-size: 20px;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(29, 53, 87, 0.12);
  pointer-events: none;
}

/* цифра внутри точки (видна при увеличении) */
.leaflet-tooltip.dot-count {
  background: transparent;
  border: none;
  box-shadow: none;
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.75);
  padding: 0;
  pointer-events: none;
}
.leaflet-tooltip.dot-count::before { display: none; }

/* появление новой точки */
.pop {
  animation: pop-in 0.45s cubic-bezier(0.2, 1.6, 0.4, 1);
  transform-box: fill-box;
  transform-origin: center;
}
@keyframes pop-in {
  0%   { transform: scale(0.1); opacity: 0.4; }
  100% { transform: scale(1);   opacity: 1; }
}

.popup-count { color: var(--muted); font-size: 12px; margin: 2px 0 6px; }
.popup-people { margin: 0; padding-left: 18px; font-size: 13px; }
.popup-people li { margin: 1px 0; }

/* ---------- форма ---------- */
.panel {
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 16px clamp(12px, 4vw, 28px) 12px;
  box-shadow: 0 -6px 18px rgba(29, 53, 87, 0.08);
  font-size: 24px; /* базовый 16px × 1.5 — крупные шрифты основного экрана */
}

#point-form {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 200px;
}

.field.grow { flex: 1 1 320px; }

/* город фиксированной ширины, не на всю строку */
.field-city { flex: 0 1 340px; min-width: 270px; }

/* дата рождения — неразрывный блок: при нехватке ширины
   переносится на новую строку целиком, поля не разъезжаются */
.field-group.birth {
  display: flex; /* без внутреннего переноса — минимальная ширина = три поля в ряд */
  gap: 14px;
  flex: 0 1 auto;
}
.field-year { flex: 0 1 230px; min-width: 195px; }
.field-bmonth { flex: 0 1 185px; min-width: 155px; }
.field-bday { flex: 0 1 110px; min-width: 90px; position: relative; }
/* список годов: своя панель от поля вверх на всю высоту экрана
   (нативный список в Opera открывается ограниченной высоты) */
.year-dd {
  position: fixed; /* координаты считает app.js при открытии */
  z-index: 6000;
  overflow-y: auto;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.year-dd[hidden] { display: none; }
.year-dd button {
  font: inherit;
  padding: 5px 0;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  text-align: center; /* годы — по центру, а не прижаты к краю */
  cursor: pointer;
}
.year-dd button:hover { background: #fdeeef; }
.year-dd button.clear { color: var(--muted); }
.year-dd button.sel {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

/* день рождения — кнопка, открывающая календарик */
.day-field {
  font: inherit;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.day-field:disabled { color: var(--muted); cursor: not-allowed; }
.day-field:not(.filled):not(:disabled) { color: var(--muted); }
.day-field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(230, 57, 70, 0.15);
  background: #fff;
}
/* календарик дня: та же панель, что у годов и месяцев, только сетка 7×N */
.day-cal {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 6000;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(7, 40px);
  gap: 2px;
}
.day-cal[hidden] { display: none; }
.day-cal button {
  font: inherit;
  font-size: 20px;
  padding: 6px 0;
  border: none;
  border-radius: 6px;
  background: none;
  cursor: pointer;
}
.day-cal button:hover { background: #fdeeef; }
.day-cal button.cal-clear {
  grid-column: 1 / -1; /* «—» на всю ширину сетки — сброс выбора */
  color: var(--muted);
  margin-bottom: 2px;
}
.day-cal button.sel {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

/* населённый пункт — ключевое поле формы, выделен оранжевым */
/* оранжевый — пока населённый пункт не выбран из подсказок;
   после корректного выбора поле становится обычным */
#city:not(.filled) {
  border-color: #f08c00;
  background: #fffaf3;
}
#city:not(.filled):focus {
  border-color: #d97706;
  box-shadow: 0 0 0 3px rgba(240, 140, 0, 0.18);
  background: #fff;
}
/* ошибка валидации остаётся видимой поверх оранжевой обводки */
#city.invalid { border-color: var(--accent-dark); }

.field .hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.field input {
  font: inherit;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(230, 57, 70, 0.15);
  background: #fff;
}

.field input.invalid { border-color: var(--accent-dark); }

/* поле «Год рождения» — кнопка, выглядящая как поле ввода */
#submit-btn {
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, var(--accent), var(--accent-dark));
  border: none;
  border-radius: 10px;
  padding: 14px 36px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(230, 57, 70, 0.4);
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
}

#submit-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(230, 57, 70, 0.5);
}

#submit-btn:active:not(:disabled) { transform: translateY(1px); }

#submit-btn:disabled {
  filter: saturate(0.4) brightness(0.95);
  cursor: wait;
}

/* подсказки автокомплита */
.ac-wrap { position: relative; }

.ac-list {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(29, 53, 87, 0.18);
  overflow: hidden;
  z-index: 2000;
  max-height: 380px;
  overflow-y: auto;
}

.ac-item {
  padding: 11px 14px;
  cursor: pointer;
  font-size: 21px;
  line-height: 1.35;
}

.ac-item b { font-size: 21px; }

.ac-item .sub {
  display: block;
  color: var(--muted);
  font-size: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ac-item.active,
.ac-item:hover { background: #fdecee; }

.ac-empty { padding: 12px 14px; color: var(--muted); font-size: 20px; }

.status {
  min-height: 30px;
  margin-top: 6px;
  font-size: 20px;
  color: var(--muted);
}

.status.error { color: var(--accent-dark); font-weight: 600; }

/* ---------- кнопки-утилиты под формой ---------- */
.tools {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.tool-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.tool-btn:hover:not(:disabled) { border-color: var(--ink); background: #f6f8fb; }

.tool-btn.danger { color: var(--accent-dark); }
.tool-btn.danger:hover:not(:disabled) { border-color: var(--accent-dark); background: #fdf1f2; }

.tool-btn:disabled { opacity: 0.5; cursor: wait; }

/* подпись «ТЕСТОВЫЕ ДАННЫЕ. Сгенерировано …» вместо кнопок генерации */
.test-data-note {
  font-size: 20px;
  color: var(--muted);
}
.test-data-note b {
  color: var(--ink);
  letter-spacing: 0.02em;
}

.scroll-hint {
  margin-left: auto;
  font-size: 20px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
}
.scroll-hint:hover { color: var(--ink); }

/* ---------- статистика ниже первого экрана ---------- */
.stats-section {
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px clamp(12px, 4vw, 28px) 60px;
}

.stats-section h2 {
  font-size: 36px;
  margin: 0 0 24px;
  padding-left: 16px;
  border-left: 6px solid var(--accent);
  line-height: 1.15;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: 0 2px 10px rgba(29, 53, 87, 0.06);
}

/* топы и диаграмма — на всю ширину сетки */
.card.wide, .card.full { grid-column: 1 / -1; }

.card h3 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}

.big-num { text-align: center; padding: 28px 12px; }
.big-num .num {
  font-size: 58px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.1;
}
.big-num .cap { color: var(--muted); font-size: 20px; margin-top: 6px; }

/* топ без полосок: название слева, число справа */
.bars { display: flex; flex-direction: column; }

.top-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 21px;
  /* в полном топе 45 тысяч строк — браузер красит только видимые */
  content-visibility: auto;
  contain-intrinsic-size: auto 42px;
}
.top-row:last-child { border-bottom: none; }

.top-label {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-num { font-weight: 700; font-variant-numeric: tabular-nums; }
.top-row[hidden] { display: none; } /* скрытые уровни списка */

.more-btn {
  margin-top: 12px;
  font: inherit;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: none;
  padding: 2px 0;
  cursor: pointer;
}
.more-btn:hover { text-decoration: underline; }
.more-btn + .more-btn { margin-left: 22px; } /* «Свернуть» — на расстоянии от «Показать ещё» */

/* столбчатая диаграмма годов рождения */
.no-year {
  margin: -6px 0 12px;
  font-size: 17px;
  font-weight: 500;
  color: var(--muted);
}
.chart-wrap { position: relative; }
.chart-wrap canvas { display: block; }

.chart-tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  transform: translate(-50%, -140%);
  background: #1d3557;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 7px;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .card.wide, .card.full { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr; }
  .card.wide, .card.full { grid-column: 1 / -1; }
}

/* тост */
#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 5000;
  background: var(--ink);
  color: #fff;
  font-size: 21px;
  font-weight: 600;
  padding: 12px 24px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.3s ease;
  pointer-events: none;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* летящая копия кнопки */
.flying-btn {
  will-change: transform;
  box-shadow: 0 4px 14px rgba(230, 57, 70, 0.4) !important;
}

@media (max-width: 640px) {
  .app { height: auto; min-height: 100dvh; }
  .map-wrap { flex: none; height: 55dvh; }
  /* на телефоне шрифт компактнее: 24px десктопа раздували поля в столбик.
     16px — минимум, при котором iOS не зумит поле при фокусе */
  .panel { font-size: 16px; }
  #point-form { gap: 10px; }
  .field { min-width: 0; }
  .field input, .day-field { padding: 10px; }
  /* ФИО — на всю строку */
  .field.grow { flex: 1 1 100%; }
  /* город + страна — в один ряд */
  .field-city { flex: 1 1 58%; }
  .field-country { flex: 1 1 38%; }
  /* год + месяц + день — в один ряд, пропорции подобраны так,
     чтобы «Год рождения» и «Сентябрь» помещались без обрезки */
  .field-group.birth { flex: 1 1 100%; gap: 8px; }
  .field-year { flex: 1 1 42%; min-width: 0; }
  .field-bmonth { flex: 1 1 31%; min-width: 0; }
  .field-bday { flex: 1 1 23%; min-width: 0; }
  #submit-btn { width: 100%; padding: 12px; }
  .ac-list { bottom: auto; top: calc(100% + 6px); }
  .ac-item { font-size: 16px; }
  .ac-sub { font-size: 13px; }
  .day-cal { grid-template-columns: repeat(7, 38px); }
  .day-cal button { font-size: 17px; }
  .status, .test-data-note, .scroll-hint { font-size: 15px; }
}

/* расходящееся кольцо вместо «прыжка» точки (маркеры на canvas) */
.pop-ring {
  animation: popring 0.9s ease-out forwards;
}
@keyframes popring {
  from { stroke-width: 6px; stroke-opacity: 0.9; }
  to   { stroke-width: 0.5px; stroke-opacity: 0; }
}

/* боковой попап (раскрыт влево/вправо от точки): хвостик снизу спрятан —
   вместо него стрелка на боковой грани, указывающая на точку */
.leaflet-popup.side .leaflet-popup-tip-container {
  display: none;
}
.leaflet-popup.side .leaflet-popup-content-wrapper {
  position: relative;
}
.leaflet-popup.side .leaflet-popup-content-wrapper::before {
  content: '';
  position: absolute;
  width: 17px;
  height: 17px;
  background: #fff;
  left: 0; /* центр ромба на боковом краю обёртки */
  top: var(--arrow-y, 50%);
  transform: translate(-50%, -50%) rotate(45deg);
  pointer-events: none;
}
.leaflet-popup.arrow-right .leaflet-popup-content-wrapper::before {
  left: 100%;
}

/* диалог «Вы уже добавлены, добавляете другого человека?» */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 33, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 11000;
  padding: 16px;
}
/* display:flex выше перебивает hidden из браузерных стилей —
   без этого диалог висел бы на странице сразу после загрузки */
.modal-backdrop[hidden] {
  display: none;
}
.modal {
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
  max-width: 680px;
  width: 100%;
  padding: 32px 40px;
  text-align: center;
}
.modal-title {
  font-weight: 700;
  font-size: 26px;
  color: var(--ink);
}
.modal-title.error { color: var(--accent-dark); }
.modal-text {
  margin-top: 14px;
  font-size: 21px;
  line-height: 1.45;
  color: var(--ink);
}
.modal-actions {
  margin-top: 28px;
  display: flex;
  gap: 16px;
  justify-content: center;
}

.modal-btn {
  font: inherit;
  font-size: 20px;
  font-weight: 600;
  padding: 14px 32px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.modal-btn:hover { border-color: var(--ink); }
.modal-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.modal-btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
