/* ==========================================================================
   Мобильный режим портала (телефоны). Действует только при body.is-mobile.
   Класс ставит /static/js/mobile.js; без него всё работает как раньше.
   Десктопная разметка не меняется: правила ниже её не задевают.
   ========================================================================== */

body.is-mobile {
  --header-h: 48px;
  --m-safe: env(safe-area-inset-bottom, 0px);
}

/* На мобильном свои шапка, меню и футер не нужен. */
body.is-mobile .site-header { display: none; }
body.is-mobile .site-footer { display: none; }
body.is-mobile .skip-link { display: none; }

/* ------------------------------------------------------------------ каркас */
/* Шапка фиксированная и выведена из потока — карту сдвигаем на её высоту. */
body.is-mobile .tool-main { padding: var(--header-h) 0 0; }

body.is-mobile .tool-layout,
body.is-mobile .preview-banner + .tool-main .tool-layout {
  display: block;
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  min-height: 0;
  overflow: hidden;
}

body.is-mobile .tool-map { height: 100%; min-height: 0; }

/* Мобильные элементы скрыты по умолчанию: на десктопе их просто нет. */
.m-topbar,
.m-icons,
.m-sheet-head,
.m-scrim,
.m-menu { display: none; }

body.is-mobile .m-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 950;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 0 12px;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}

.m-topbar-brand {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  text-decoration: none;
}
.m-topbar-brand img { width: 28px; height: 28px; border-radius: 7px; display: block; }

.m-topbar-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: .95rem;
  font-weight: 650;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.m-icon-btn:hover { background: var(--surface-2); }
.m-icon-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* --------------------------------------------------- карта: верхний и нижний края */
body.is-mobile .tool-topbar,
body.is-mobile .map-toggle,
body.is-mobile .tool-status,
body.is-mobile .reference-chip { display: none; }
body.is-mobile .map-toggle {
  padding: 5px 9px;
  font-size: .68rem;
}
body.is-mobile .tool-hint,
body.is-mobile .tool-note { display: none; }

/* Leaflet: зум ниже карточки, масштаб и атрибуция — над нижней панелью иконок. */
body.is-mobile .leaflet-top.leaflet-right { top: calc(var(--m-card-h, 170px) + 8px); }
body.is-mobile .leaflet-bottom.leaflet-right {
  bottom: calc(var(--m-panel-h, 140px) + 6px);
}

/* Сообщение об ошибке не должно прятаться за карточкой. */
body.is-mobile .tool-error {
  left: 8px;
  right: 8px;
  bottom: calc(var(--m-panel-h, 140px) + 8px);
}

/* Легенда: компактная карточка над нижней панелью. */
body.is-mobile .map-legend {
  left: 8px;
  bottom: calc(var(--m-panel-h, 140px) + 8px);
  width: min(232px, 64vw);
  max-height: 30dvh;
  font-size: .72rem;
  border-radius: 12px;
}
body.is-mobile .map-legend.is-collapsed { width: auto; }
body.is-mobile .map-legend.is-collapsed .legend-help { display: none; }

/* --------------------------------------------------- нижняя панель: карточка + иконки */
body.is-mobile .profile-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 900;
  display: flex;
  flex-direction: column;
  height: auto;
  max-height: none;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
  pointer-events: none;
  overscroll-behavior: contain;
}

/* Всё лишнее на экране не показываем: остаются карта, карточка и легенда. */
body.is-mobile .profile-head,
body.is-mobile .summary-block,
body.is-mobile .attribution-block,
body.is-mobile .panel-hint,
body.is-mobile .panel-block h2 { display: none; }

body.is-mobile .panel-block-head { justify-content: flex-end; }

/* Карточка балла — как на большом сайте, но плотнее. Живёт сверху карты,
   под мобильной шапкой; иконки параметров остаются внизу. */
body.is-mobile .profile-score {
  pointer-events: auto;
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  z-index: 900;
  margin: 0;
  padding: 8px 12px 10px;
  border: 0;
  border-radius: 0 0 16px 16px;
  background: linear-gradient(180deg, #ffffff 0%, #f4fbfe 100%);
  box-shadow: 0 8px 24px rgba(11, 95, 138, .18);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 2px 10px;
}

body.is-mobile .profile-score-label { font-size: .56rem; letter-spacing: .05em; }
body.is-mobile .profile-score-number strong { font-size: 1.75rem; }
body.is-mobile .profile-score-number small { font-size: .68rem; }

body.is-mobile .profile-score-caption {
  max-width: none;
  font-size: .63rem;
  line-height: 1.25;
  text-align: right;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

body.is-mobile .score-nearest {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 6px;
  margin-top: 2px;
}
body.is-mobile .score-nearest-label { font-size: .58rem; }
body.is-mobile .score-nearest strong { font-size: .74rem; }
body.is-mobile .score-nearest small { font-size: .68rem; }

body.is-mobile .score-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}
body.is-mobile .score-actions .button { font-size: .74rem; padding: 7px 10px; }
body.is-mobile .score-save-status { font-size: .62rem; }

body.is-mobile .housing-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}
body.is-mobile .housing-actions-label { display: none; }
body.is-mobile .housing-btn { font-size: .72rem; padding: 7px 10px; }

/* Иконки параметров. */
.m-icons { display: none; }

body.is-mobile .m-icons {
  pointer-events: auto;
  display: flex;
  gap: 6px;
  padding: 8px 8px 6px;
}

body.is-mobile[data-sheet] .m-icons { display: none; }

.m-icons button {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  padding: 7px 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 4px 14px rgba(11, 95, 138, .12);
  color: var(--ink-2);
  font: inherit;
  font-size: .62rem;
  font-weight: 600;
  cursor: pointer;
}
.m-icons button svg { display: block; width: 21px; height: 21px; }
.m-icons button:active { background: var(--brand-soft); }
.m-icons button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.m-icons button.is-active {
  border-color: var(--brand);
  color: var(--brand);
  background: #fff;
}

/* --------------------------------------------------- шторка параметров */
body.is-mobile .m-sheet-head { display: none; }

body.is-mobile[data-sheet] .profile-panel {
  pointer-events: auto;
  max-height: 88dvh;
  padding: 0 14px calc(16px + var(--m-safe));
  border-radius: 16px 16px 0 0;
  background: #fff;
  overflow-y: auto;
  box-shadow: 0 -12px 40px rgba(11, 95, 138, .28);
}

body.is-mobile[data-sheet] .profile-score { display: none; }

body.is-mobile[data-sheet] .m-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 3;
  margin: 0 -14px 6px;
  padding: 10px 8px 8px 14px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
body.is-mobile .m-sheet-head strong { font-size: .95rem; font-weight: 650; }

body.is-mobile .profile-panel > [data-group] { display: none; }

body.is-mobile[data-sheet="city"] [data-group="city"],
body.is-mobile[data-sheet="profile"] [data-group="profile"],
body.is-mobile[data-sheet="needs"] [data-group="needs"],
body.is-mobile[data-sheet="distance"] [data-group="distance"] { display: block; }

body.is-mobile[data-sheet="city"] .city-search {
  display: grid;
  grid-template-columns: 1fr;
  margin-top: 4px;
}

/* В шторке поля крупнее — удобнее попадать пальцем. */
body.is-mobile[data-sheet] .field select,
body.is-mobile[data-sheet] .field input { padding: 10px; font-size: .9rem; }
body.is-mobile[data-sheet] .age-btn { padding: 10px 8px; }
body.is-mobile[data-sheet] .need-row { padding: 9px 4px; }
body.is-mobile[data-sheet] .need-row input { width: 18px; height: 18px; }
body.is-mobile[data-sheet] .check-line input { width: 18px; height: 18px; }
body.is-mobile[data-sheet] .slider-block input[type="range"] { height: 28px; }

/* --------------------------------------------------- затемнение */
.m-scrim { display: none; }

body.is-mobile[data-sheet] .m-scrim {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 890;
  background: rgba(12, 32, 44, .42);
}

/* --------------------------------------------------- меню */
.m-menu { display: none; }

body.is-mobile[data-menu] .m-menu {
  display: flex;
  align-items: flex-end;
  position: fixed;
  inset: 0;
  z-index: 980;
  background: rgba(12, 32, 44, .42);
}

.m-menu-panel {
  width: 100%;
  max-height: 82dvh;
  overflow-y: auto;
  padding: 10px 16px calc(18px + var(--m-safe));
  border-radius: 16px 16px 0 0;
  background: #fff;
  box-shadow: 0 -12px 40px rgba(11, 95, 138, .28);
}

.m-menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -10px -16px 8px;
  padding: 10px 8px 8px 16px;
  border-bottom: 1px solid var(--line);
}
.m-menu-head strong { font-size: .95rem; }

.m-menu-links { display: grid; gap: 2px; margin: 6px 0 12px; }
.m-menu-links a {
  display: block;
  padding: 11px 8px;
  border-radius: 9px;
  color: var(--ink);
  text-decoration: none;
  font-size: .95rem;
  font-weight: 550;
}
.m-menu-links a:active { background: var(--surface-2); }
.m-menu-links a.is-active { color: var(--brand); background: var(--brand-soft); }

.m-menu-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.m-menu-meta .chip { font-size: .7rem; padding: 5px 9px; }
.m-menu-meta .chip-muted { display: inline-flex; }

.m-menu-attr { font-size: .72rem; color: var(--ink-2); line-height: 1.45; }
.m-menu-attr a { color: var(--brand); }
.m-menu-attr h2, .m-menu-attr .panel-hint { display: none; }

.m-menu-action {
  width: 100%;
  margin-top: 12px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
}
.m-menu-action:active { background: var(--surface-2); }

/* «Мобильная версия» на десктопе — только если пользователь её отключил. */
.m-desktop-return {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 6px 11px;
  font: inherit;
  font-size: .76rem;
  color: var(--ink-2);
  cursor: pointer;
}
.m-desktop-return:hover { background: var(--surface-2); color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  body.is-mobile .profile-panel,
  body.is-mobile .profile-score { transition: none !important; }
}
