:root {
  --ink: #0f2a33;
  --ink-2: #1c3d48;
  --teal: #0c7a7a;
  --teal-dark: #085e60;
  --lime: #d9f24f;
  --bg: #f1f5f4;
  --card: #ffffff;
  --line: #dde6e4;
  --text: #13262c;
  --muted: #5f7379;
  --problem: #e5484d;
  --repair: #f0a020;
  --good: #2f9e63;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(15, 42, 51, .14);
  --top-h: 68px;
  --tabs-h: 0px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }

/* ---------- Шапка ---------- */
.top {
  height: var(--top-h);
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  padding-top: env(safe-area-inset-top);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; flex-shrink: 0; }
.brand img { border-radius: 12px; display: block; }
.brand-text { display: grid; line-height: 1.15; }
.brand-text strong { font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
.brand-text small { color: #a9c3c6; font-size: 12.5px; }
.search {
  flex: 1; max-width: 560px; margin-left: 18px;
  display: flex; align-items: center; gap: 10px;
  background: var(--ink-2); border: 1px solid #2c5560; border-radius: 14px;
  padding: 0 14px; height: 44px;
}
.search:focus-within { border-color: var(--lime); }
.search svg { width: 18px; height: 18px; fill: none; stroke: #a9c3c6; stroke-width: 2; stroke-linecap: round; flex-shrink: 0; }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: #fff; font-size: 16px; }
.search input::placeholder { color: #8fabaf; }
.top .btn-ghost { margin-left: auto; }

.btn {
  border: 0; border-radius: 13px; height: 44px; padding: 0 18px;
  font-weight: 700; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .12s ease, background-color .15s ease;
}
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .6; cursor: default; }
.btn-accent { background: var(--lime); color: var(--ink); }
.btn-ghost { background: var(--ink-2); color: #fff; border: 1px solid #2c5560; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-plain { background: #e9efee; color: var(--text); }
.btn-danger { background: #fde8e8; color: #b42328; }
.link { background: none; border: 0; padding: 0; color: var(--teal); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

@media (hover: hover) {
  .btn-accent:hover { background: #e4f871; }
  .btn-primary:hover { background: var(--teal-dark); }
  .btn-plain:hover { background: #dde6e4; }
  .btn-ghost:hover { background: #24505c; }
}

/* ---------- Раскладка ---------- */
.layout {
  height: calc(100% - var(--top-h) - var(--tabs-h));
  display: grid;
  grid-template-columns: 420px 1fr;
}
.side {
  overflow-y: auto;
  padding: 18px;
  display: flex; flex-direction: column; gap: 16px;
  overscroll-behavior: contain;
}
.hero {
  background: linear-gradient(140deg, #0d5f66 0%, #0c7a7a 60%, #159a8c 100%);
  color: #fff; border-radius: 22px; padding: 22px;
}
.hero h1 { font-size: 25px; line-height: 1.15; font-weight: 800; letter-spacing: -.02em; }
.hero p { margin-top: 10px; color: #d6eeec; font-size: 14.5px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.stat b { display: block; font-size: 24px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12.5px; }
.stat--problem b { color: var(--problem); }
.stat--repair b { color: #c27a06; }

.filters-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.filters-head h2 { font-size: 18px; font-weight: 800; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  min-height: 40px; padding: 0 14px; font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; gap: 7px;
}
.chip.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot--problem { background: var(--problem); }
.dot--repair { background: var(--repair); }
.dot--good { background: var(--good); }
.select-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; font-size: 14px; color: var(--muted); }
.select-row select { height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); padding: 0 10px; color: var(--text); font-size: 15px; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card {
  width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: grid; grid-template-columns: auto 1fr; gap: 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.card.is-current { border-color: var(--teal); box-shadow: 0 0 0 2px rgba(12, 122, 122, .18); }
@media (hover: hover) { .card:hover { border-color: #b6c9c6; } }
.card-mark { width: 12px; border-radius: 6px; align-self: stretch; }
.card-mark--problem { background: var(--problem); }
.card-mark--repair { background: var(--repair); }
.card-mark--good { background: var(--good); }
.card-body { min-width: 0; display: grid; gap: 4px; }
.card-title { font-weight: 800; font-size: 15.5px; overflow-wrap: anywhere; }
.card-meta { color: var(--muted); font-size: 13px; }
.card-desc { font-size: 14px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.badge { font-size: 12px; font-weight: 700; border-radius: 999px; padding: 3px 9px; background: #eef3f2; color: #3d5258; }
.badge--problem { background: #fde8e8; color: #b42328; }
.badge--repair { background: #fdf0d5; color: #8a5a00; }
.badge--good { background: #dff3e7; color: #1c6b41; }
.badge--research { background: #e3eefc; color: #1f4f96; }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.side-foot { margin-top: auto; color: var(--muted); font-size: 13px; padding-top: 6px; }

/* ---------- Карта ---------- */
.mapwrap { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #e3ebe8; }
.leaflet-container { font: inherit; }
.layer-toggle {
  position: absolute; top: 14px; left: 14px; z-index: 500;
  background: #fff; border-radius: 14px; padding: 4px; display: flex; gap: 2px; box-shadow: var(--shadow);
}
.layer-toggle button { border: 0; background: none; height: 40px; padding: 0 14px; border-radius: 11px; font-weight: 700; }
.layer-toggle button.is-active { background: var(--ink); color: #fff; }
.loc-btn {
  position: absolute; top: 14px; right: 14px; z-index: 500;
  border: 0; background: #fff; border-radius: 14px; height: 48px; padding: 0 14px;
  font-weight: 700; display: inline-flex; align-items: center; gap: 8px; box-shadow: var(--shadow);
}
.loc-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--teal); stroke-width: 2; stroke-linecap: round; }
.legend {
  position: absolute; left: 14px; bottom: 26px; z-index: 500;
  background: #fff; border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow);
  display: grid; gap: 5px; font-size: 13.5px;
}
.legend span { display: flex; align-items: center; gap: 8px; }
.leaflet-bottom.leaflet-right { margin-bottom: 4px; }
.leaflet-control-zoom a { width: 40px !important; height: 40px !important; line-height: 40px !important; font-size: 22px !important; }
.leaflet-control-attribution { font-size: 11px; }

/* метки */
.pin-icon { background: none; border: 0; }
.pin {
  display: block; width: 30px; height: 30px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); transform-origin: center;
  border: 3px solid #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .35);
  position: relative; margin: 2px 0 0 0;
}
.pin::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: #fff; }
.pin--problem { background: var(--problem); }
.pin--repair { background: var(--repair); }
.pin--good { background: var(--good); }
.pin--pick { background: var(--ink); }
.pin--mini { width: 16px; height: 16px; border-width: 2px; background: var(--teal); margin: 0 4px 0 2px; flex-shrink: 0; box-shadow: none; }
.pin--mini::after { inset: 3px; }
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #2b7fff; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(43, 127, 255, .25); }

.crosshair {
  position: absolute; left: 50%; top: 50%; z-index: 600; pointer-events: none;
  width: 30px; height: 40px; margin: -40px 0 0 -15px; display: none;
}
.crosshair .pin { margin-top: 0; }
body.picking .crosshair { display: block; }
body.picking .legend, body.picking .layer-toggle { display: none; }
.pickbar {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 650;
  width: min(460px, calc(100% - 24px));
  background: #fff; border-radius: 20px; box-shadow: var(--shadow); padding: 14px; display: grid; gap: 12px;
}
.pickbar p { font-weight: 600; text-align: center; }
.pickbar-actions { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; }

/* всплывающая карточка */
.leaflet-popup-content-wrapper { border-radius: 18px; box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 14px 16px; width: 250px !important; font-size: 14px; line-height: 1.4; }
.pop { display: grid; gap: 7px; }
.pop-title { font-weight: 800; font-size: 16px; overflow-wrap: anywhere; padding-right: 14px; }
.pop-desc { overflow-wrap: anywhere; white-space: pre-line; }
.pop-photo { display: block; width: 100%; max-height: 170px; object-fit: cover; border-radius: 12px; background: #e9efee; }
.pop-meta { color: var(--muted); font-size: 12.5px; }

/* ---------- Окна ---------- */
.dlg {
  border: 0; border-radius: 22px; padding: 0; width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); color: var(--text);
}
.dlg--wide { width: min(720px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(15, 42, 51, .55); }
.dlg > form, .dlg > .about { padding: 0 22px 22px; }
.dlg-head {
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: #fff; z-index: 2; padding: 18px 0 12px;
}
.dlg > .dlg-head { padding: 18px 22px 12px; }
.dlg-head h2 { font-size: 21px; font-weight: 800; }
.x { border: 0; background: #e9efee; width: 40px; height: 40px; border-radius: 12px; font-size: 24px; line-height: 1; }
.point-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: #eef6f5; border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; font-size: 14px; }
.field { display: grid; gap: 6px; margin: 0 0 14px; border: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { font-weight: 700; font-size: 14px; padding: 0; }
.field > legend { margin-bottom: 6px; }
.field em { color: var(--problem); font-style: normal; }
.field input:not([type=radio]):not([type=file]), .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); background: #f8fbfa; border-radius: 13px;
  padding: 0 14px; height: 48px; font-size: 16px;
}
.field textarea { height: auto; padding: 12px 14px; resize: vertical; min-height: 84px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 0; border-color: var(--teal); background: #fff; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 48px; padding: 6px 8px; border-radius: 13px; border: 2px solid var(--line);
  font-weight: 700; font-size: 14px; background: #f8fbfa;
}
.seg input:checked + .seg--problem { border-color: var(--problem); background: #fde8e8; color: #b42328; }
.seg input:checked + .seg--repair { border-color: var(--repair); background: #fdf0d5; color: #8a5a00; }
.seg input:checked + .seg--good { border-color: var(--good); background: #dff3e7; color: #1c6b41; }
.seg input:focus-visible + span { outline: 3px solid var(--teal); outline-offset: 2px; }
.photo-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.photo-pick { cursor: pointer; }
#photoPreview { width: 72px; height: 54px; object-fit: cover; border-radius: 10px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.form-error { background: #fde8e8; color: #b42328; border-radius: 12px; padding: 10px 12px; font-weight: 600; margin-bottom: 10px; }
.form-note { font-size: 13px; margin-bottom: 12px; }
.dlg-actions { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; }

.about { display: grid; gap: 14px; }
.about .lead { font-size: 16px; font-weight: 600; }
.about h3 { font-size: 16px; font-weight: 800; margin-top: 4px; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.facts div { background: #eef6f5; border-radius: 16px; padding: 14px; }
.facts b { display: block; font-size: 24px; font-weight: 800; color: var(--teal-dark); }
.facts span { font-size: 13px; color: var(--muted); }
.chart { display: grid; gap: 7px; margin-bottom: 8px; }
.chart-row { display: grid; grid-template-columns: minmax(120px, 42%) 1fr 54px; gap: 10px; align-items: center; font-size: 14px; }
.bar { height: 12px; border-radius: 6px; background: #e3ebe8; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 6px; background: var(--teal); }
.chart-row b { text-align: right; font-variant-numeric: tabular-nums; }
.ways { margin: 0; padding-left: 20px; display: grid; gap: 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 22px); transform: translateX(-50%); z-index: 3000;
  background: var(--ink); color: #fff; border-radius: 14px; padding: 12px 18px; font-weight: 600;
  max-width: calc(100vw - 24px); text-align: center; box-shadow: var(--shadow);
}
.toast.is-error { background: #b42328; }

.tabs { display: none; }

/* ---------- Телефон ---------- */
@media (max-width: 860px) {
  :root { --top-h: calc(60px + env(safe-area-inset-top)); --tabs-h: calc(62px + env(safe-area-inset-bottom)); }
  .top { gap: 10px; padding-left: 12px; padding-right: 12px; }
  .brand-text, .top .btn { display: none; }
  .search { margin-left: 0; max-width: none; }
  .layout { display: block; position: relative; }
  .side { position: absolute; inset: 0; background: var(--bg); z-index: 1100; padding: 14px 12px 20px; }
  .mapwrap { position: absolute; inset: 0; }
  body[data-view="map"] .side { display: none; }
  .hero { padding: 18px; }
  .hero h1 { font-size: 22px; }
  .legend { bottom: 22px; font-size: 12.5px; padding: 10px 12px; }
  .leaflet-control-zoom { display: none; }
  .tabs {
    display: grid; grid-template-columns: 1fr 1.25fr 1fr; align-items: center;
    height: var(--tabs-h); padding: 6px 10px env(safe-area-inset-bottom);
    background: #fff; border-top: 1px solid var(--line); gap: 8px;
  }
  .tabs button {
    border: 0; background: none; height: 50px; border-radius: 14px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font-size: 12px; font-weight: 700; color: var(--muted);
  }
  .tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .tabs button.is-active { color: var(--teal); }
  .tabs .tab-add { background: var(--lime); color: var(--ink); flex-direction: row; gap: 6px; font-size: 15px; }
  body.picking .tabs { display: none; }
  body.picking { --tabs-h: 0px; }
  .grid2 { grid-template-columns: 1fr; gap: 0; }
  .facts { grid-template-columns: 1fr; }
  .dlg > form, .dlg > .about { padding: 0 16px 18px; }
  .dlg > .dlg-head { padding: 16px 16px 10px; }
  .chart-row { grid-template-columns: minmax(96px, 40%) 1fr 50px; font-size: 13px; }
}

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