/* ── Переменные ── */
:root {
  --g: #16a34a; --y: #d97706; --r: #dc2626; --b: #2563eb; --p: #7c3aed; --gas: #0891b2;
  --bg: #f3f4f6; --panel: #ffffff; --panel2: #f9fafb;
  --ink: #111827; --muted: #6b7280; --line: #e5e7eb;
  --head-bg: rgba(255,255,255,.92);
  --shadow-sm: 0 1px 4px rgba(0,0,0,.1);
  --shadow: 0 4px 20px rgba(0,0,0,.13), 0 1px 4px rgba(0,0,0,.07);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.18);
  --radius: 14px; --radius-sm: 8px;
  --header-h: 58px;
  --search-w: 300px;
  --card-w: 380px;
  --safe-top: 0px; /* было env(safe-area-inset-top) — в обычной вкладке Safari (не standalone-PWA) это создавало необъяснимый пустой отступ над шапкой */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
body.dark {
  --g: #22c55e; --y: #fbbf24; --r: #f87171; --b: #60a5fa; --p: #a78bfa; --gas: #22d3ee;
  --bg: #0f1117; --panel: #1a1d27; --panel2: #20242f;
  --ink: #f1f5f9; --muted: #94a3b8; --line: #2d3348;
  --head-bg: rgba(26,29,39,.94);
  --shadow: 0 4px 20px rgba(0,0,0,.5);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100vh; height: 100dvh; width: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px; color: var(--ink); background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
}
.mono { font-family: 'PT Mono', 'Menlo', 'Consolas', monospace; }
.hidden { display: none !important; }

/* ── Карта ── */
#map {
  position: fixed; inset: 0; z-index: 0;
  background: var(--bg);
}
/* тёмная тема для обычных (светлых) тайлов OSM — отдельного тёмного источника тайлов нет,
   инвертируем цвета фильтром поверх схемы; спутник (фото) фильтром не трогаем — иначе
   цвета снимка станут неестественными, поэтому фильтр отключается классом .sat-mode */
body.dark #map:not(.sat-mode) .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.88) saturate(0.85);
}

/* ── Экран загрузки ── */
.loading-overlay {
  position: fixed; inset: 0; z-index: 3000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  transition: opacity .25s ease, visibility .25s ease;
}
.loading-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--g);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.leaflet-control-zoom { display: none; }
.leaflet-control-attribution {
  font-size: 9px; line-height: 1.3;
  background: rgba(0,0,0,.25); color: rgba(255,255,255,.55);
  padding: 1px 5px; border-radius: 4px 0 0 0;
  opacity: .55; transition: opacity .15s;
}
.leaflet-control-attribution a { color: inherit; }
.leaflet-control-attribution:hover { opacity: 1; }

/* ── Шапка ── */
.ui-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1100;
  height: calc(var(--header-h) + var(--safe-top));
  background: var(--head-bg);
  backdrop-filter: blur(14px) saturate(1.6);
  -webkit-backdrop-filter: blur(14px) saturate(1.6);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
  padding: var(--safe-top) calc(14px + var(--safe-right)) 0 calc(14px + var(--safe-left));
}
.ui-brand {
  display: flex; align-items: center; gap: 9px;
  text-decoration: none; color: inherit; flex-shrink: 0;
}
.ui-brand-icon {
  width: 32px; height: 32px; flex-shrink: 0;
  object-fit: contain;
}
.ui-brand-title {
  font-size: 14px; font-weight: 700; line-height: 1.1; white-space: nowrap;
}
.ui-brand-sub {
  font-size: 11px; font-weight: 400; color: var(--muted); margin-top: 1px;
  white-space: nowrap;
}
.ui-header-center {
  flex: 1; display: flex; align-items: center; gap: 5px;
  overflow-x: auto; scrollbar-width: none; padding: 0 6px;
  min-width: 0;
}
.ui-header-center::-webkit-scrollbar { display: none; }
/* пустой legendStrip (вне направления АЗС) не должен отжирать половину ширины у directionStrip */
.ui-header-center:empty { flex: 0; padding: 0; }

.ui-header-right {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
}
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink); font-size: 14px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn:hover { background: var(--line); }
.btn-labeled {
  height: 34px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink); font: inherit; font-size: 12.5px; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; gap: 5px; white-space: nowrap;
  transition: background .15s;
}
.btn-labeled:hover { background: var(--line); }
.btn-login {
  height: 34px; padding: 0 16px; border-radius: 9px;
  border: none; background: var(--g); color: #fff;
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: opacity .15s;
}
.btn-login:hover { opacity: .88; }
.user-area { display: flex; align-items: center; gap: 7px; }
.user-name {
  font-size: 12.5px; color: var(--ink); font-weight: 600;
  white-space: nowrap; max-width: 160px;
  overflow: hidden; text-overflow: ellipsis;
}
.role-badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: 2px 7px; border-radius: 20px; white-space: nowrap;
  background: color-mix(in srgb, var(--g) 15%, transparent); color: var(--g);
}

/* ── Чипы-легенда ── */
.legend-chip {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 9px 3px 6px; border-radius: 20px;
  background: var(--panel2); border: 1px solid var(--line);
  font-size: 11px; font-weight: 600; cursor: pointer;
  white-space: nowrap; transition: opacity .15s, background .15s;
  user-select: none; flex-shrink: 0;
}
.legend-chip .chip-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.legend-chip .chip-check { font-weight: 700; }
.legend-chip.off { opacity: .4; }
.legend-chip.sel { background: var(--panel); border-width: 2px; font-weight: 700; }
.legend-chip:hover { background: var(--line); }
.legend-chip.legend-all {
  background: var(--g); border-color: var(--g); color: #fff;
}
.legend-chip.legend-all:hover { opacity: .88; background: var(--g); }
.legend-chip.legend-all:not(.on) { opacity: .55; background: var(--panel2); border-color: var(--line); color: var(--ink); }

.mobile-tabs { display: none; } /* только на мобильном — на десктопе поиск и настройки карты видны одновременно */

/* ── Поиск ── */
.left-col {
  position: fixed; top: calc(var(--header-h) + var(--safe-top) + 10px); left: calc(12px + var(--safe-left));
  width: var(--search-w); z-index: 1000;
  display: flex; flex-direction: column; gap: 10px;
  height: calc(100vh - var(--header-h) - var(--safe-top) - var(--safe-bottom) - 22px);
  height: calc(100dvh - var(--header-h) - var(--safe-top) - var(--safe-bottom) - 22px);
  overflow-y: auto; overflow-x: visible;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  pointer-events: none;
}
.left-col::-webkit-scrollbar { display: none; }
.left-col > * { pointer-events: auto; flex-shrink: 0; }
.left-col > .ui-search { flex-shrink: 1; }

.ui-search {
  width: 100%;
  flex: 1 1 auto; min-height: 0;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex; flex-direction: column;
}
.search-input-wrap {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.search-icon { width: 16px; height: 16px; color: var(--muted); flex-shrink: 0; }
#q {
  flex: 1; font: inherit; font-size: 13px;
  border: none; outline: none; background: transparent; color: var(--ink);
}
#q::placeholder { color: var(--muted); }
.search-clear {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 13px; padding: 2px 4px; line-height: 1;
}
.station-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.station-list:empty::after {
  content: 'Нет результатов';
  display: block; padding: 16px; text-align: center;
  color: var(--muted); font-size: 12px;
}

/* ── Инфо-блок главы округа ── */
.ui-info {
  width: 100%; background: var(--panel);
  border-radius: var(--radius); border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
  display: flex; flex-direction: column; gap: 10px;
  font-size: 12px; line-height: 1.5; color: var(--ink);
}
.info-head { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.info-photo {
  width: 52px; height: 52px; border-radius: 50%; object-fit: cover;
  flex-shrink: 0; border: 2px solid var(--line);
}
.info-head-text { flex: 1; min-width: 0; }
.info-name { font-size: 12.5px; font-weight: 700; }
.info-role { font-size: 10.5px; color: var(--muted); line-height: 1.35; margin-top: 2px; }
.info-chevron {
  flex-shrink: 0; align-self: flex-end;
  color: var(--g); font-size: 20px; font-weight: 700; line-height: 1;
}
.ui-info.collapsed .info-chevron { animation: chevronBounceUp 1.2s ease-in-out infinite; }
.ui-info:not(.collapsed) .info-chevron { animation: chevronBounceDown 1.2s ease-in-out infinite; }
@keyframes chevronBounceUp {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
@keyframes chevronBounceDown {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(6px); }
}
.ui-info.collapsed .info-body { display: none; }
.info-body { display: flex; flex-direction: column; gap: 10px; }
.info-contacts {
  font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; gap: 2px;
}
.info-contacts a { color: inherit; }
.info-message p { margin-bottom: 8px; }
.info-message p:last-child { margin-bottom: 0; }
.info-dev {
  display: flex; flex-direction: column; gap: 8px;
  padding-top: 10px; border-top: 1px solid var(--line);
  font-size: 10.5px; color: var(--muted);
}
.dev-links { display: flex; align-items: center; gap: 16px; }
.dev-link {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--muted); text-decoration: none;
}
.dev-link:hover { color: var(--ink); }
.dev-link svg { width: 13px; height: 13px; flex-shrink: 0; }
.dev-link .max-logo { width: 13px; height: 13px; flex-shrink: 0; }
body.dark .dev-link .max-logo { filter: invert(1); }

/* строка списка */
.srow {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 12px; cursor: pointer;
  border-bottom: 1px solid var(--line);
  transition: background .12s;
}
.srow:last-child { border-bottom: none; }
.srow:hover { background: var(--panel2); }
.srow.active { background: var(--panel2); }
.pin-wrap { position: relative; flex-shrink: 0; }
.srow-pin {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; letter-spacing: -.3px;
  border: 2.5px solid transparent;
  overflow: hidden;
}
.srow-info { flex: 1; min-width: 0; }
.srow-name {
  font-size: 12.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.srow-addr {
  font-size: 11px; color: var(--muted); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.srow-stale { font-size: 10px; color: var(--y); }
.srow-dist {
  flex-shrink: 0; font-size: 11px; font-weight: 700; color: var(--muted);
  padding-left: 8px; white-space: nowrap;
}

/* ── Карточка АЗС ── */
.station-card {
  position: fixed; top: calc(var(--header-h) + var(--safe-top)); right: 0; bottom: 0;
  width: var(--card-w); z-index: 1050;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: var(--safe-right);
  animation: slideIn .2s ease;
}
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
.card-close {
  position: absolute; top: 10px; right: calc(10px + var(--safe-right)); z-index: 2;
  width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel2); color: var(--muted);
  font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.card-close:hover { background: var(--line); color: var(--ink); }
.card-body { padding: 14px calc(16px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(16px + var(--safe-left)); }

/* карточка — шапка станции */
.card-brand-row {
  display: flex; align-items: center; gap: 12px; margin-bottom: 10px;
  padding-right: 30px; /* место под крестик закрытия в углу */
}
.logo-wrap { position: relative; flex-shrink: 0; }
.card-logo {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; letter-spacing: -.3px;
  border: 3px solid transparent;
  overflow: hidden;
}
.card-title { font-size: 15px; font-weight: 700; line-height: 1.2; }
.card-num { font-size: 11px; color: var(--muted); margin-top: 2px; }
.card-addr {
  font-size: 12px; color: var(--muted); margin-bottom: 6px;
  line-height: 1.4;
}
.card-price-status {
  display: inline-flex; align-items: center; gap: 4px; width: fit-content;
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 20px;
  margin-bottom: 10px;
}
.card-price-status.is-paid { background: color-mix(in srgb, var(--y) 20%, transparent); color: var(--y); }
.card-price-status.is-free { background: color-mix(in srgb, var(--g) 16%, transparent); color: var(--g); }
.card-info-rows { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.card-info-row { display: flex; align-items: flex-start; gap: 7px; font-size: 12.5px; color: var(--ink); line-height: 1.4; }
.cir-icon { flex-shrink: 0; font-size: 12px; line-height: 1.4; }
.card-contact-link {
  color: var(--g); text-decoration: none;
}
.card-contact-link:hover { text-decoration: underline; }
.card-desc {
  font-size: 12.5px; color: var(--ink); line-height: 1.5; margin-bottom: 10px;
}
.route-btn {
  display: flex; align-items: center; justify-content: center;
  height: 38px; border-radius: var(--radius-sm);
  background: #fc3f1d; color: #fff;
  font-size: 13px; font-weight: 700; text-decoration: none;
  margin-bottom: 14px; transition: opacity .15s;
}
.route-btn:hover { opacity: .88; }
.card-route-row { display: flex; gap: 8px; margin-bottom: 14px; }
.card-route-row .route-btn { flex: 1; margin-bottom: 0; }
.share-btn {
  flex: 1; height: 38px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--panel2); color: var(--ink);
  font-size: 13px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: border-color .15s;
}
.share-btn:hover { border-color: var(--muted); }

/* фото АЗС — карусель */
.card-photo-wrap {
  margin-bottom: 10px; border-radius: var(--radius-sm); overflow: hidden;
  background: var(--panel2);
}
.card-photo-wrap:empty { display: none; }
.photo-viewport { position: relative; }
.card-photo { width: 100%; height: 160px; object-fit: cover; display: block; cursor: zoom-in; }
.photo-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; border-radius: 50%; border: none;
  background: rgba(0,0,0,.45); color: #fff; font-size: 15px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .12s;
}
.photo-arrow:hover { background: rgba(0,0,0,.65); }
.photo-prev { left: 8px; }
.photo-next { right: 8px; }
.photo-dots {
  position: absolute; left: 0; right: 0; bottom: 8px;
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
.photo-dot { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.5); }
.photo-dot.active { background: #fff; }
.photo-del-current {
  position: absolute; top: 8px; right: 8px;
  width: 24px; height: 24px; border-radius: 50%; border: none;
  background: rgba(0,0,0,.45); color: #fff; font-size: 11px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .12s;
}
.photo-del-current:hover { background: var(--r); }
.photo-actions { display: flex; gap: 7px; margin-bottom: 14px; }
.photo-upload-label {
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex: 1;
}

/* полноэкранный просмотр фото */
.photo-lightbox {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,.9);
  display: flex; align-items: center; justify-content: center;
}
.lightbox-viewport {
  position: relative; width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-viewport img {
  max-width: calc(100% - 80px); max-height: calc(100% - 80px);
  object-fit: contain;
}
.lightbox-close {
  position: absolute; top: calc(14px + var(--safe-top)); right: calc(14px + var(--safe-right));
  z-index: 2001; width: 36px; height: 36px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.12); color: #fff; font-size: 16px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.lightbox-close:hover { background: rgba(255,255,255,.22); }
.photo-lightbox .photo-arrow { width: 40px; height: 40px; font-size: 20px; background: rgba(255,255,255,.12); }
.photo-lightbox .photo-arrow:hover { background: rgba(255,255,255,.22); }
.photo-lightbox .photo-prev { left: calc(10px + var(--safe-left)); }
.photo-lightbox .photo-next { right: calc(10px + var(--safe-right)); }
.photo-lightbox .photo-dots { bottom: calc(20px + var(--safe-bottom)); }
.photo-lightbox .photo-dot { width: 7px; height: 7px; }

/* карточка — топливо */
.card-section-label {
  font-size: 10px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted);
  margin-bottom: 7px;
}
.fuel-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 14px;
}
.fuel-cell {
  border-radius: var(--radius-sm); border: 1.5px solid var(--line);
  padding: 8px 6px 6px; cursor: pointer;
  transition: border-color .15s, transform .1s;
  position: relative;
  min-width: 0;
}
.fuel-cell:hover { transform: translateY(-1px); }
.fuel-cell.active-available { border-color: var(--g); background: color-mix(in srgb, var(--g) 8%, transparent); }
.fuel-cell.active-unavailable { border-color: var(--r); background: color-mix(in srgb, var(--r) 8%, transparent); }
.fuel-cell.active-unknown { border-color: var(--muted); }
.fuel-cell-type { font-size: 10px; font-weight: 600; color: var(--muted); margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fuel-cell-status { font-size: 13px; font-weight: 700; }
.fuel-cell-status.s-available { color: var(--g); }
.fuel-cell-status.s-unavailable { color: var(--r); }
.fuel-cell-status.s-unknown { color: var(--muted); }
.fuel-cell-time { font-size: 10px; color: var(--muted); margin-top: 3px; font-family: 'PT Mono', monospace; }
.fuel-cell-time.stale { color: var(--y); }

/* редактирование статуса топлива */
.fuel-edit-btns { display: flex; gap: 3px; margin-top: 6px; }
.fst-btn {
  flex: 1; min-width: 0; height: 24px; border-radius: 5px; border: 1.5px solid var(--line);
  background: var(--panel2); font-size: 10px; font-weight: 600; cursor: pointer;
  transition: all .12s; color: var(--muted);
  padding: 0 2px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.fst-btn:hover { border-color: var(--muted); color: var(--ink); }
.fst-btn.sel-available { border-color: var(--g); background: var(--g); color: #fff; }
.fst-btn.sel-unavailable { border-color: var(--r); background: var(--r); color: #fff; }
.fst-btn.sel-unknown { border-color: var(--muted); background: var(--muted); color: #fff; }

/* флаг станции */
.flag-row { display: flex; gap: 6px; margin-bottom: 14px; }
.flag-btn {
  flex: 1; height: 32px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--line); background: var(--panel2);
  font-size: 11px; font-weight: 600; cursor: pointer; color: var(--muted);
  transition: all .12s;
}
.flag-btn:hover { border-color: var(--muted); color: var(--ink); }
.flag-btn.active-normal { border-color: var(--g); color: var(--g); background: color-mix(in srgb, var(--g) 8%, transparent); }
.flag-btn.active-repair { border-color: var(--b); color: var(--b); background: color-mix(in srgb, var(--b) 8%, transparent); }
.flag-btn.active-legal_only { border-color: var(--p); color: var(--p); background: color-mix(in srgb, var(--p) 8%, transparent); }
.flag-btn.active-gas_only { border-color: var(--gas); color: var(--gas); background: color-mix(in srgb, var(--gas) 8%, transparent); }
.gas-only-note { font-size: 12px; color: var(--muted); margin-bottom: 14px; padding: 8px 10px; background: var(--panel2); border-radius: var(--radius-sm); }

/* заметка */
.note-area {
  width: 100%; font: inherit; font-size: 12.5px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--line); background: var(--panel2);
  color: var(--ink); outline: none; resize: none;
  transition: border-color .15s; margin-bottom: 14px;
}
.note-area:focus { border-color: var(--g); }

/* история */
.history-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; cursor: pointer;
  border-top: 1px solid var(--line); margin-bottom: 0;
  font-size: 12px; font-weight: 600; color: var(--muted);
  user-select: none;
}
.history-toggle:hover { color: var(--ink); }
.history-body { margin-top: 8px; }
.h-row {
  font-size: 11px; color: var(--muted); margin-bottom: 5px; line-height: 1.4;
}
.h-row b { color: var(--ink); }

/* кнопки действий */
.card-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.action-btn {
  flex: 1 1 auto; min-width: 84px; height: 32px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--panel2);
  font: inherit; font-size: 11.5px; color: var(--ink); cursor: pointer;
  transition: all .12s;
}
.action-btn:hover { border-color: var(--muted); }
.action-btn.danger:hover { border-color: var(--r); color: var(--r); }
.action-btn.armed { background: var(--b); color: #fff; border-color: var(--b); }

/* ── Кнопки карты ── */
.map-controls {
  position: fixed; bottom: calc(24px + var(--safe-bottom)); right: calc(14px + var(--safe-right)); z-index: 1000;
}
.map-controls-list {
  display: flex; flex-direction: column; gap: 0;
  background: var(--panel); border-radius: 10px;
  border: 1px solid var(--line); box-shadow: var(--shadow);
  overflow: hidden;
}
.mbtn {
  width: 40px; height: 40px; background: var(--panel); border: none;
  border-bottom: 1px solid var(--line); color: var(--ink);
  font-size: 16px; cursor: pointer; transition: background .12s;
}
.mbtn:last-child { border-bottom: none; }
.mbtn:hover { background: var(--panel2); }
.mbtn.active { background: var(--g); color: #fff; }
.mbtn-label { display: none; } /* видна только в мобильном выпадающем меню */
#mcLoginBtn { display: none; } /* показывается только на мобильном (см. адаптив ниже) — на десктопе «Войти» уже есть в шапке */
#mcInstallBtn { display: none; } /* установка на телефон актуальна только на мобильном (см. адаптив ниже) */
.mc-divider, .mc-legend-section { display: none; } /* только в мобильном выпадающем меню */

/* ── Toast ── */
.toast {
  position: fixed; bottom: calc(24px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  z-index: 2000; background: var(--ink); color: var(--panel);
  font-family: 'PT Mono', monospace; font-size: 12px;
  padding: 8px 18px; border-radius: 20px;
  opacity: 0; transition: opacity .25s; pointer-events: none;
  white-space: nowrap; max-width: 320px; text-align: center;
}
.toast.show { opacity: 1; }

/* ── Подсказка добавления ── */
.add-hint {
  position: fixed; top: calc(var(--header-h) + var(--safe-top) + 12px); left: 50%;
  transform: translateX(-50%); z-index: 1200;
  background: var(--b); color: #fff;
  font-family: 'PT Mono', monospace; font-size: 12px;
  padding: 8px 18px; border-radius: 20px; white-space: nowrap;
}

/* ── Маркеры ── */
.bp-wrap {
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.bp {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid transparent;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; letter-spacing: -.3px;
  box-shadow: 0 2px 8px rgba(0,0,0,.35), 0 0 0 1.5px rgba(255,255,255,.5);
  cursor: pointer; transition: transform .15s, box-shadow .15s;
  user-select: none;
  overflow: hidden;
}
.bp-sel {
  transform: scale(1.3);
  box-shadow: 0 4px 16px rgba(0,0,0,.45), 0 0 0 2px rgba(255,255,255,.9);
}
.bp.dim { opacity: .3; }

/* ── Бейдж статуса (галочка/крестик/иконка поверх лого) ── */
.status-badge {
  position: absolute; right: -2px; bottom: -2px; z-index: 2;
  width: 16px; height: 16px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; line-height: 1; color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.45);
  pointer-events: none;
}
.pin-wrap .status-badge {
  width: 13px; height: 13px; font-size: 7px; border-width: 1.5px;
  right: -1px; bottom: -1px;
}
.brand-logo {
  width: 88% !important; height: 88% !important; object-fit: contain !important;
  max-width: 88% !important; max-height: 88% !important;
  pointer-events: none;
}
.brand-logo.brand-logo-cover {
  width: 100% !important; height: 100% !important; object-fit: cover !important;
  max-width: 100% !important; max-height: 100% !important;
}

/* ── Модалки ── */
.modal {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative; z-index: 1;
  background: var(--panel); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 22px 24px;
  width: 340px; max-width: 100%;
  max-height: 90vh; max-height: 90dvh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-wide { width: 440px; }
.modal-admin { width: 880px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h2 { font-size: 17px; }
.modal-sub { font-size: 12px; color: var(--muted); }
.field-group { display: flex; flex-direction: column; gap: 8px; }
.field-group input, .field-group select {
  font: inherit; font-size: 13.5px; padding: 9px 11px;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink); outline: none;
}
.field-group input:focus { border-color: var(--g); }
.btn-primary {
  width: 100%; height: 40px; border-radius: var(--radius-sm);
  border: none; background: var(--g); color: #fff;
  font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: opacity .15s; margin-top: 4px;
}
.btn-primary:hover { opacity: .9; }
.form-error { font-size: 12px; color: var(--r); padding: 4px 0; }

/* вкладки в «Управление» */
.admin-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.admin-tab {
  height: 34px; padding: 0 14px; border: none; border-radius: var(--radius-sm);
  background: var(--panel2); color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .12s, color .12s;
}
.admin-tab:hover { background: var(--line); }
.admin-tab.active { background: var(--g); color: #fff; }
.admin-panel { display: flex; flex-direction: column; gap: 12px; }

/* таблица станций — быстрое редактирование всех АЗС разом */
.stations-toolbar { display: flex; justify-content: flex-end; }
.stations-table-wrap { overflow-x: auto; max-height: 55vh; max-height: 55dvh; }
.stations-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.stations-table th {
  position: sticky; top: 0; background: var(--panel);
  text-align: left; font-size: 10px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--muted);
  padding: 6px 8px; border-bottom: 1px solid var(--line);
}
.stations-table td { padding: 4px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.stations-table tr:last-child td { border-bottom: none; }
.stations-table tr.row-dirty td { background: color-mix(in srgb, var(--y) 10%, transparent); }
.stations-table tr.row-dirty td:first-child { box-shadow: inset 3px 0 0 var(--y); }
.st-logo-cell { width: 34px; }
.st-num { font-family: 'PT Mono', monospace; color: var(--muted); white-space: nowrap; }
.stations-table input, .stations-table select {
  font: inherit; font-size: 12.5px; padding: 6px 7px;
  border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink); outline: none;
  width: 100%; box-sizing: border-box;
}
.stations-table input:focus, .stations-table select:focus { border-color: var(--g); }
.stations-table select:disabled { opacity: .4; cursor: not-allowed; }
.st-name { min-width: 140px; }
.st-name-ro { display: block; padding: 6px 7px; min-width: 140px; font-weight: 600; }
.st-note { min-width: 120px; }
.st-del {
  width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--muted); cursor: pointer; font-size: 11px;
}
.st-del:hover { border-color: var(--r); color: var(--r); }

.stations-save-bar {
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  padding-top: 10px; border-top: 1px solid var(--line);
}
.stations-save-bar #stationsSaveCount { font-size: 12px; color: var(--muted); }
.btn-save-primary { background: var(--g); color: #fff; border-color: var(--g); }
.btn-save-primary:hover { opacity: .9; background: var(--g); }

/* экспорт: список с подписями назначения формата */
.export-list { display: flex; flex-direction: column; gap: 10px; }
.export-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.export-row .btn-sm { flex-shrink: 0; }
.export-hint { font-size: 11.5px; color: var(--muted); line-height: 1.4; }

/* admin sections */
.admin-panel .admin-section:first-child { border-top: none; padding-top: 0; }
.admin-section { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.section-label {
  font-size: 10px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted);
}
.date-row { display: flex; gap: 8px; align-items: center; }
.date-row input {
  flex: 1; font: inherit; font-family: 'PT Mono', monospace; font-size: 13px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--panel2); color: var(--ink); outline: none;
}
.date-row input:focus { border-color: var(--g); }
.btn-sm {
  height: 32px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--panel2);
  font: inherit; font-size: 12px; cursor: pointer; color: var(--ink);
  transition: background .12s;
}
.btn-sm:hover { background: var(--line); }

/* пользователи */
.users-list { display: flex; flex-direction: column; gap: 6px; }
.u-row {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.u-info { flex: 1; min-width: 0; }
.u-name { font-size: 12.5px; font-weight: 600; }
.u-login { font-size: 10.5px; color: var(--muted); font-family: 'PT Mono', monospace; }
.u-row select {
  font: inherit; font-size: 11px; padding: 3px 6px;
  border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink); outline: none;
}
.u-role-ro { font-size: 11px; color: var(--muted); padding: 3px 6px; }
.u-del {
  font: inherit; font-size: 11px; padding: 4px 8px;
  border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--muted); cursor: pointer;
}
.u-del:hover { border-color: var(--r); color: var(--r); }
.user-form { display: flex; flex-direction: column; gap: 8px; }

/* слои направлений (админка) */
.layers-cat-row { display: flex; flex-wrap: wrap; gap: 6px; }
.layers-draw-row { display: flex; flex-wrap: wrap; gap: 8px; }
.layers-draw-row .btn-sm:disabled { opacity: .45; cursor: not-allowed; }

/* значок «платно» на объектах направлений (лыжи/рыбалка) */
.paid-badge {
  display: inline-block; font-size: 10px; font-weight: 700; line-height: 1;
  padding: 2px 4px; border-radius: 5px;
  background: color-mix(in srgb, var(--y) 22%, transparent);
  color: var(--y);
  vertical-align: middle;
}

/* пустой список (нет объектов направления / направление не выбрано) */
.empty-hint { padding: 22px 12px; color: var(--muted); font-size: 12.5px; text-align: center; line-height: 1.5; }

/* попап зоны/маршрута на карте */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--ink); }
.layer-popup-actions { display: flex; gap: 6px; margin-top: 8px; }
.layer-popup-actions button {
  font: inherit; font-size: 11px; padding: 4px 9px;
  border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink); cursor: pointer;
}
.layer-popup-actions button.lp-danger:hover { border-color: var(--r); color: var(--r); }
.layer-photo-wrap { position: relative; margin-top: 8px; }
.layer-photo { display: block; width: 100%; max-width: 220px; border-radius: 8px; }
.lp-photo-del {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%;
  border: none; background: rgba(0,0,0,.55); color: #fff; cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.lp-photo-upload {
  display: inline-block; margin-top: 6px; font-size: 11px; padding: 4px 9px;
  border-radius: 6px; border: 1px solid var(--line); background: var(--panel2); color: var(--ink); cursor: pointer;
}

/* подсказка редактирования контура — те же стили, что .add-hint, плюс кнопки */
#layerEditHint { display: flex; align-items: center; gap: 8px; }
#layerEditHint button {
  font: inherit; font-size: 11px; padding: 4px 10px; border-radius: 20px;
  border: 1px solid rgba(255,255,255,.4); background: transparent; color: #fff; cursor: pointer;
}
#layerEditHint button:hover { background: rgba(255,255,255,.15); }

/* ── Адаптив ── */
@media (max-width: 700px) {
  /* кнопки режима карты больше не плавают отдельно (теперь вкладка внутри той же колонки),
     поэтому ширину справа больше не нужно урезать под них — только симметричные отступы */
  :root { --search-w: calc(100vw - 24px - var(--safe-left) - var(--safe-right)); --card-w: 100vw; }
  .ui-header-center { display: none; }
  .ui-header-right { margin-left: auto; }
  .user-name, .role-badge { display: none; }
  #authArea { display: none; } /* на мобильном «Войти» переехало во вкладку «Настройка карты» */
  #mcLoginBtn { display: flex; }
  #mcInstallBtn { display: flex; }

  .ui-search.bar-hidden { display: none; }

  .station-card {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%; max-height: 60vh; max-height: 60dvh;
    border-left: none; border-top: 1px solid var(--line);
    border-radius: var(--radius) var(--radius) 0 0;
    padding-right: 0;
    animation: slideUp .2s ease;
  }
  .card-body {
    padding: 4px calc(16px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(16px + var(--safe-left));
  }
  @keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }
  /* блок главы округа — растянут на всю ширину внизу экрана, отдельно от узкой колонки поиска */
  .ui-info {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 990;
    width: auto; border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: none;
    font-size: 11.5px;
    padding: 12px calc(14px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(14px + var(--safe-left));
  }
  .info-photo { width: 44px; height: 44px; }

  /* Две вкладки сверху: «Поиск АЗС» / «Настройка карты» — переключают, что показано ниже.
     Grid вместо flex — гарантированно ровно 50/50, независимо от длины текста. */
  .mobile-tabs {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
    width: 100%; box-sizing: border-box;
    background: var(--panel); border-radius: var(--radius);
    border: 1px solid var(--line); box-shadow: var(--shadow);
    padding: 4px;
  }
  .mobile-tab {
    width: 100%; min-width: 0; height: 38px; border: 1px solid transparent; border-radius: 9px;
    background: var(--panel2); color: var(--muted);
    font: inherit; font-size: 12.5px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    cursor: pointer; touch-action: manipulation; transition: background .12s, color .12s;
  }
  /* .active теперь отражает реально открытую панель (см. syncMobileTabButtons в app.js),
     а не «текущий таб» вообще — поэтому «Поиск АЗС» не зелёная, пока строка поиска скрыта */
  .mobile-tab.active { background: var(--g); color: #fff; border-color: var(--g); }

  /* по умолчанию вкладка «Поиск» активна — панель карты скрыта, и наоборот */
  #leftCol[data-tab="search"] .map-controls { display: none; }
  #leftCol[data-tab="map"] .ui-search { display: none; }

  /* запас снизу у всей прокручиваемой колонки — чтобы содержимое (список АЗС ИЛИ настройка
     карты, что бы сейчас ни было открыто) не пряталось под плавающим блоком главы округа;
     раньше запас был только у списка АЗС, из-за чего в Safari (там меньше видимая высота,
     чем в Chrome) в панель настройки карты стало наезжать после добавления кнопки установки */
  .left-col { padding-bottom: 100px; }

  /* панель «Настройка карты» — карточка на всю ширину (как поиск), не плавающая */
  .map-controls {
    position: static; width: 100%;
    background: var(--panel); border-radius: var(--radius);
    border: 1px solid var(--line); box-shadow: var(--shadow);
    overflow: hidden;
  }
  .map-controls-list {
    flex-direction: column;
    background: none; border: none; box-shadow: none; border-radius: 0;
  }
  .map-controls-list .mbtn {
    width: 100%; height: 44px;
    display: flex; align-items: center; gap: 10px;
    justify-content: flex-start; padding: 0 14px;
  }
  .mbtn-icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }
  .mbtn-label { display: inline; font-size: 13px; font-weight: 600; }

  .mc-divider { display: block; height: 1px; background: var(--line); margin: 4px 0; }
  .mc-legend-section {
    display: flex; flex-direction: column;
    padding: 8px 6px;
  }
  /* пустая секция (например, легенда топлива вне направления «АЗС») не должна оставлять пустой отступ */
  .mc-legend-section:empty { display: none; padding: 0; }
  .mc-legend-row {
    display: flex; align-items: center; gap: 10px;
    height: 38px; padding: 0 10px; border-radius: 8px;
    font-size: 13px; font-weight: 600; cursor: pointer; touch-action: manipulation;
  }
  .mc-legend-row:hover { background: var(--panel2); }
  .mc-legend-row.off { opacity: .45; }
  .mc-legend-row.sel { background: var(--panel2); font-weight: 700; }
  .mc-legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
  .mc-legend-label { flex: 1; }
  .chip-check { color: var(--g); }

  /* по умолчанию список свёрнут, чтобы карта была видна сразу; разворачивается по фокусу на поиске.
     Пока свёрнут — карточка поиска не растягивается на всю высоту (иначе выглядит как пустой блок). */
  .station-list { transition: max-height .18s ease; }
  .ui-search.list-collapsed { flex-grow: 0; }
  .ui-search.list-collapsed .station-list { max-height: 0; }

  /* тач-таргеты (мин. 44px по HIG Apple) и запрет авто-зума iOS при фокусе на инпутах (нужен font-size >= 16px) */
  .icon-btn { width: 44px; height: 44px; }
  .card-close { width: 40px; height: 40px; }
  .mbtn { width: 44px; height: 44px; }
  .btn-labeled { height: 40px; padding: 0 12px; }
  #q, .field-group input, .field-group select, .note-area, .date-row input {
    font-size: 16px;
  }
  .btn-login, .icon-btn, .card-close, .mbtn, .legend-chip, .srow, .btn-labeled,
  .fst-btn, .flag-btn, .action-btn, .btn-sm, .u-del, .info-head, .history-toggle,
  .photo-arrow, .photo-del-current, .share-btn {
    touch-action: manipulation;
  }
}

@media (max-width: 420px) {
  /* подстраховка на очень узких экранах: не скрываем текст бренда, но не даём ему выталкивать шапку */
  .ui-brand-title, .ui-brand-sub { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
  /* «Управление»/«Выйти» — на совсем узких экранах оставляем только иконки, иначе шапка не влезает */
  .btn-labeled .bl-text { display: none; }
  .btn-labeled { padding: 0 10px; }
}
