:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #111111);
  --link: var(--tg-theme-link-color, #2563eb);
  --btn: var(--tg-theme-button-color, #2563eb);
  --btn-fg: var(--tg-theme-button-text-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f3f4f6);
  /* подписи: цвет hint из темы Telegram на белом даёт контраст 2.8, считаем свой от текста и фона (не ниже 5:1) */
  --hint: color-mix(in srgb, var(--fg) 64%, var(--bg));
  --line: color-mix(in srgb, var(--fg) 14%, transparent);
  /* основная кнопка: цвет кнопки темы, притемнённый до контраста с белым текстом от 4.5:1 */
  --osn: color-mix(in srgb, var(--btn) 88%, #000);
  --vazhno: #d98a00;
  --vazhno-bg: color-mix(in srgb, var(--vazhno) 16%, var(--bg));
  --vazhno-fg: color-mix(in srgb, var(--vazhno) 58%, var(--fg));
  --ten: 0 6px 24px rgba(0, 0, 0, .14);
  --verh: 64px;
  --ease: cubic-bezier(.22, 1, .36, 1);
}
html[data-tema="dark"] { --osn: color-mix(in srgb, var(--btn) 70%, #000); --ten: 0 6px 24px rgba(0, 0, 0, .45); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 16px/1.4 -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; -webkit-font-smoothing: antialiased; }
#map { position: fixed; inset: 0; z-index: 0; background: var(--bg2); }

/* ---- шапка: территория шире дня, текст не обрезается ---- */
#verh { position: fixed; top: 0; left: 0; right: 0; z-index: 500; display: flex; gap: 8px; align-items: center;
  padding: calc(env(safe-area-inset-top) + 8px) 8px 8px; background: var(--bg);
  box-shadow: 0 1px 0 var(--line), 0 4px 16px rgba(0, 0, 0, .06); }
select, button { font: inherit; color: var(--fg); min-height: 48px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg2); padding: 0 12px; }
#verh select { min-width: 0; padding: 0 6px 0 12px; font-weight: 500; text-overflow: ellipsis; }
#f-ter { flex: 1 1 auto; }
#f-den { flex: 0 0 104px; }
#b-dobavit { flex: 0 0 48px; width: 48px; padding: 0; font-size: 30px; font-weight: 400; line-height: 1;
  border-radius: 50%; background: var(--osn); color: var(--btn-fg); border-color: transparent;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--btn) 40%, transparent); transition: transform .25s var(--ease); }
#b-dobavit.vkl { background: var(--fg); color: var(--bg); transform: rotate(45deg); box-shadow: none; }

button { cursor: pointer; font-weight: 600; transition: transform .12s var(--ease), background-color .15s; }
button:active { transform: scale(.97); }
button.osn, button.vkl { background: var(--osn); color: var(--btn-fg); border-color: transparent; }
button:disabled { opacity: .45; }
button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--btn); outline-offset: 2px; }

/* ---- полоса под шапкой: «Без координат» и легенда цветов территорий ---- */
#polosa { position: fixed; top: calc(var(--verh) + env(safe-area-inset-top) + 8px); left: 0; right: 0; z-index: 450;
  display: flex; gap: 6px; padding: 0 8px; overflow-x: auto; scrollbar-width: none; pointer-events: none; }
#polosa::-webkit-scrollbar { display: none; }
#polosa > * { pointer-events: auto; flex: 0 0 auto; }
#list { min-height: 44px; font-size: 15px; font-weight: 600; color: var(--vazhno-fg); background: var(--vazhno-bg);
  border: 1px solid color-mix(in srgb, var(--vazhno) 45%, transparent); border-radius: 999px; padding: 0 14px;
  box-shadow: var(--ten); }
#list[hidden], #legenda[hidden] { display: none; }
#legenda { display: flex; gap: 6px; }
.ter { display: inline-flex; align-items: center; gap: 7px; min-height: 36px; margin-top: 4px; padding: 0 12px 0 9px;
  border-radius: 999px; background: var(--bg); color: var(--fg); font-size: 15px; font-weight: 500;
  border: 1px solid var(--line); box-shadow: var(--ten); white-space: nowrap; pointer-events: none; }
.ter i { width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(0, 0, 0, .25); }

/* ---- нижняя плашка: шапка, прокручиваемое тело, кнопки всегда видны ---- */
#plashka { position: fixed; left: 0; right: 0; bottom: 0; z-index: 600; background: var(--bg);
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(env(safe-area-inset-bottom) + 12px);
  max-height: 45vh; max-height: calc(var(--tg-viewport-stable-height, 100vh) * 0.45);
  display: flex; flex-direction: column; box-shadow: 0 -8px 32px rgba(0, 0, 0, .18);
  animation: vverh .28s var(--ease); }
@keyframes vverh { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
#plashka[hidden] { display: none; }
#plashka .sh { flex: 0 0 auto; }
#plashka .telo { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch; touch-action: pan-y; margin-top: 6px; }
#plashka .niz { flex: 0 0 auto; margin-top: 12px; }
#plashka h2 { margin: 0 0 6px; font-size: 20px; line-height: 1.25; font-weight: 700; letter-spacing: -.01em;
  overflow-wrap: anywhere; }
.stroka { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 9px 0;
  border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.stroka:last-child { border-bottom: 0; }
.stroka span:first-child { color: var(--hint); font-size: 15px; flex: 0 0 auto; }
.stroka span:last-child { text-align: right; font-weight: 500; }
/* кнопки делят строку по длине подписи и не переносят слова */
.knopki { display: flex; flex-wrap: wrap; gap: 8px; }
.knopki button { flex: 1 1 auto; padding: 0 14px; white-space: nowrap; }
.pole { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.pole > label { color: var(--hint); font-size: 15px; font-weight: 500; }
.pole input, .pole select { width: 100%; font: inherit; font-size: 16px; color: var(--fg); min-height: 48px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); padding: 0 12px; }
.pole input:focus { border-color: var(--btn); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--btn) 25%, transparent); }
.dni { display: flex; flex-wrap: wrap; gap: 6px; }
.dni button { min-width: 52px; min-height: 44px; padding: 0 10px; }
.metka { display: inline-flex; align-items: center; min-height: 30px; padding: 0 12px; border-radius: 999px;
  background: var(--bg2); border: 1px solid var(--line); font-size: 15px; font-weight: 500; margin: 4px 6px 0 0; }
.metka.vazhno { background: var(--vazhno-bg); color: var(--vazhno-fg);
  border-color: color-mix(in srgb, var(--vazhno) 45%, transparent); }
#toast { position: fixed; left: 12px; right: 12px; top: calc(var(--verh) + env(safe-area-inset-top) + 10px);
  z-index: 700; background: var(--fg); color: var(--bg); border-radius: 14px; padding: 14px 16px; font-weight: 500;
  box-shadow: var(--ten); animation: vverh .25s var(--ease); }
.punkt { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: left;
  min-height: 56px; padding: 10px 14px; margin-bottom: 6px; font-weight: 400; }
.punkt b { font-weight: 600; overflow-wrap: anywhere; }
.punkt span { color: var(--hint); font-size: 15px; overflow-wrap: anywhere; }

/* ---- маркеры ---- */
.nomer { width: 34px; height: 34px; border-radius: 50%; background: var(--osn); color: #fff;
  border: 2px solid #fff; display: flex; align-items: center; justify-content: center; font-weight: 700;
  font-size: 15px; box-shadow: 0 1px 4px rgba(0, 0, 0, .4); }
.gruppa { width: 38px; height: 38px; border-radius: 50%; color: #fff; border: 3px solid #fff; display: flex;
  align-items: center; justify-content: center; font-weight: 700; font-size: 16px; box-shadow: 0 1px 5px rgba(0, 0, 0, .45); }
.start { width: 34px; height: 34px; border-radius: 8px; background: #111; color: #fff; border: 2px solid #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4); }

/* ---- Leaflet под тему: кнопки масштаба 44 px, подпись OSM читается ---- */
.leaflet-container { font: inherit; }
.leaflet-touch .leaflet-bar { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--ten); }
.leaflet-touch .leaflet-bar a { width: 44px; height: 44px; line-height: 44px; font-size: 24px;
  background: var(--bg); color: var(--fg); border-bottom-color: var(--line); }
.leaflet-container .leaflet-control-attribution { font-size: 11px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  color: var(--hint); }
.leaflet-control-attribution a { color: var(--link); }

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