/* ============================================================
   sypuchie-theme — MOBILE ADAPTIVE LAYER (v2 — clean rebuild)
   Грузится ПОСЛЕ main.css. Цель: всё помещается в экран.
   ============================================================ */

/* ---------- ГЛОБАЛЬНЫЕ СБРОСЫ (все экраны) ---------- */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
  /* НЕ ИСПОЛЬЗУЕМ 100vw — в webview включает scrollbar */
  width: 100%;
  max-width: 100%;
}

body {
  overflow-x: hidden;
  /* width НЕ 100vw — используем 100% от html */
  width: 100%;
  max-width: 100%;
  margin: 0;
  position: relative;
}

/* Все картинки не вылезают */
img, video, iframe, canvas, svg, embed, object {
  max-width: 100%;
  height: auto;
}
/* Карты Яндекса — исключение */
#map img, #map svg, #map canvas,
[class*="ymaps"] img, [class*="ymaps"] canvas, [class*="ymaps"] svg {
  max-width: none !important;
}

/* ============================================================
   MOBILE (≤ 767px) — всё компактно и в пределах экрана
   ============================================================ */
@media screen and (max-width: 767px) {

  /* ----- БАЗА: всё в пределах экрана ----- */
  html, body {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  /* Wrapper всей страницы */
  #page,
  .site,
  main,
  .site-main {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden;
  }

  /* Контейнер с отступами по бокам */
  .container,
  .calc-section > .container,
  section > .container {
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  /* Секции — без боковых отступов (отступы в container) */
  section,
  .calc-section,
  .hero,
  .features,
  .footer-section {
    padding-left: 0 !important;
    padding-right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden;
  }

  /* ----- КАЛЬКУЛЯТОР ----- */
  .calc {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 14px;
    overflow: hidden;
  }
  .calc__body {
    display: block !important;
    grid-template-columns: none !important;
    width: 100% !important;
  }
  .calc__form,
  .calc__result {
    width: 100% !important;
    max-width: 100% !important;
    padding: 14px !important;
    border-right: none !important;
    box-sizing: border-box !important;
  }
  .calc__form { border-bottom: 1px solid var(--border); }

  .calc__head {
    padding: 16px 14px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }
  .calc__head h2,
  .calc__title { font-size: 1.15rem !important; line-height: 1.25 !important; }

  /* ----- ПОЛЯ ----- */
  .field {
    margin-bottom: 14px !important;
    width: 100% !important;
  }
  .field__label {
    font-size: 0.9rem !important;
    margin-bottom: 6px !important;
    display: block;
  }
  .field input[type="text"],
  .field input[type="number"],
  .field input[type="tel"],
  .field input[type="email"],
  .field select,
  .field textarea {
    width: 100% !important;
    max-width: 100% !important;
    padding: 12px !important;
    font-size: 16px !important;
    border-radius: 10px !important;
    box-sizing: border-box !important;
  }

  /* Поле "Материал" — select на всю ширину */
  #material-select,
  select#material-select {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* ----- ЧИСЛОВОЕ ПОЛЕ С +/- (объём) ----- */
  .amount {
    display: grid !important;
    grid-template-columns: 56px 1fr 56px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    border-radius: 10px !important;
    overflow: hidden;
  }
  .amount button {
    width: 56px !important;
    height: 52px !important;
    font-size: 1.4rem !important;
    padding: 0 !important;
    flex: 0 0 56px !important;
  }
  .amount input {
    width: 100% !important;
    min-width: 0 !important;
    text-align: center !important;
    font-size: 18px !important;
    padding: 12px 8px !important;
    box-sizing: border-box !important;
  }

  /* ----- ПОЛЕ АДРЕСА ----- */
  .address-search {
    display: flex !important;
    gap: 6px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  .address-search__input {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    padding: 12px 38px 12px 36px !important;
    font-size: 16px !important;
    background-position: 10px center !important;
    background-size: 16px 16px !important;
    border-radius: 10px !important;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
  }
  .address-search__input:not(:focus):not(:placeholder-shown) {
    font-size: 14px !important;
  }
  .address-search__btn {
    flex: 0 0 48px !important;
    width: 48px !important;
    min-width: 48px !important;
    padding: 0 !important;
    border-radius: 10px !important;
  }
  .address-search__btn-text { display: none !important; }
  .address-search__btn-icon { font-size: 18px !important; }
  .address-search__clear {
    right: 60px !important;
    width: 26px !important;
    height: 26px !important;
    font-size: 18px !important;
  }

  /* Подсказки Яндекса */
  .ymaps-suggest,
  ymaps[class*="-suggest"] {
    width: 100% !important;
    max-width: calc(100% - 4px) !important;
    box-sizing: border-box !important;
  }
  .ymaps-suggest-item,
  ymaps[class*="-suggest-item"] {
    white-space: normal !important;
    word-break: break-word !important;
    padding: 10px 12px !important;
    line-height: 1.35 !important;
    height: auto !important;
    font-size: 14px !important;
  }

  /* ----- КАРТА ----- */
  #map {
    width: 100% !important;
    max-width: 100% !important;
    height: 280px !important;
    border-radius: 10px !important;
    box-sizing: border-box !important;
  }

  /* ----- КАРТОЧКИ МАШИН ----- */
  .trucks-list,
  .trucks,
  .truck-cards {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  .truck-card {
    width: 100% !important;
    max-width: 100% !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 10px !important;
    padding: 10px !important;
    box-sizing: border-box !important;
    border-radius: 10px;
  }
  .truck-card img,
  .truck-card__img {
    width: 70px !important;
    height: 50px !important;
    max-width: 70px !important;
    flex: 0 0 70px !important;
    object-fit: contain !important;
  }
  .truck-card__body,
  .truck-card__info {
    flex: 1 1 auto !important;
    min-width: 0 !important;
  }
  .truck-card__title { font-size: 0.95rem !important; line-height: 1.2; }
  .truck-card__meta  { font-size: 0.78rem !important; line-height: 1.3; }
  .truck-card__price { font-size: 0.9rem !important; margin-top: 2px; }

  /* ----- СВОДКА "ВАШ ЗАКАЗ" ----- */
  .result-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 6px !important;
    margin-bottom: 12px !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  .result-cell {
    width: 100% !important;
    min-width: 0 !important;
    padding: 8px 10px !important;
    overflow: hidden !important;
    border-radius: 10px !important;
    box-sizing: border-box !important;
  }
  .result-cell.is-hidden { display: none !important; }
  .result-cell__label {
    font-size: 0.7rem !important;
    margin-bottom: 2px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .result-cell__value {
    font-size: 0.92rem !important;
    line-height: 1.2 !important;
    word-break: break-word;
    overflow-wrap: anywhere;
    font-weight: 700;
  }
  .result-cell--big { grid-column: 1 / -1 !important; }
  .result-cell--accent .result-cell__value { font-size: 1.2rem !important; }

  /* ----- КНОПКИ ----- */
  .btn,
  button.btn,
  .calc__actions .btn,
  .result-actions .btn {
    width: 100% !important;
    max-width: 100% !important;
    padding: 14px 16px !important;
    font-size: 0.95rem !important;
    border-radius: 10px !important;
    min-height: 48px !important;
    box-sizing: border-box !important;
  }
  .calc__actions,
  .result-actions {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    margin-top: 12px !important;
    width: 100% !important;
  }

  /* ----- ХЕДЕР ----- */
  .site-header {
    width: 100% !important;
    padding: 10px 0 !important;
    position: static !important;
  }
  .site-header > .container,
  .site-header .container {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  .site-logo, .logo {
    font-size: 1rem !important;
    max-width: 55%;
    line-height: 1.2;
  }
  .site-phone, .header-phone {
    font-size: 0.95rem !important;
    white-space: nowrap;
  }
  .site-nav, .main-menu, .nav-primary {
    display: none !important;
  }

  /* ----- HERO ----- */
  .hero {
    padding: 30px 0 24px !important;
    min-height: 0 !important;
    height: auto !important;
    text-align: center;
  }
  .hero h1 {
    font-size: 1.6rem !important;
    line-height: 1.2 !important;
  }
  .hero p { font-size: 0.95rem !important; }
  .hero .btn { width: 100% !important; }

  /* ----- ФУТЕР ----- */
  .site-footer {
    width: 100% !important;
    padding: 24px 0 !important;
    text-align: center;
  }
  .footer-grid,
  .footer__grid {
    display: block !important;
  }
  .footer-grid > *,
  .footer__grid > * {
    width: 100% !important;
    margin-bottom: 16px !important;
  }

  /* ----- ОБЩИЕ ИСТОЧНИКИ OVERFLOW ----- */
  table { display: block; max-width: 100%; overflow-x: auto; }
  pre, code { max-width: 100%; overflow-x: auto; word-break: break-word; }
  blockquote { max-width: 100%; }

  /* Любой блок с inline-style width: 100% / max-width — резать */
  [style*="width: 100vw"],
  [style*="width:100vw"] {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* ============================================================
   УЗКИЕ ЭКРАНЫ (≤ 380px)
   ============================================================ */
@media screen and (max-width: 380px) {
  .container { padding-left: 10px !important; padding-right: 10px !important; }
  .calc__form, .calc__result { padding: 12px !important; }
  .calc__head { padding: 14px 12px !important; }
  .amount { grid-template-columns: 48px 1fr 48px !important; }
  .amount button { width: 48px !important; flex: 0 0 48px !important; }
  .result-cell { padding: 7px 9px !important; }
  .result-cell__label { font-size: 0.65rem !important; }
  .result-cell__value { font-size: 0.85rem !important; }
  .result-cell--accent .result-cell__value { font-size: 1.05rem !important; }
  .truck-card img, .truck-card__img { width: 60px !important; max-width: 60px !important; flex: 0 0 60px !important; height: 44px !important; }
  #map { height: 240px !important; }
  h1, h2 { font-size: 1.25rem !important; }
}

/* ============================================================
   ПЛАНШЕТЫ (768–1023px)
   ============================================================ */
@media screen and (min-width: 768px) and (max-width: 1023px) {
  .container { padding-left: 20px; padding-right: 20px; }
  .calc__body { display: block; }
  .calc__form, .calc__result { padding: 20px; border-right: none; }
  .calc__form { border-bottom: 1px solid var(--border); }
  .result-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  #map { height: 360px; }
}

/* ============================================================
   WEBVIEW: VK, TELEGRAM (через data-webview из JS)
   ============================================================ */

/* Общее для всех webview — отключить position:fixed */
html.is-webview .site-header { position: static !important; top: auto !important; }
html.is-webview body,
html.is-webview body > * { max-width: 100% !important; }

/* VK */
html[data-webview="vk"] { font-size: 15px; }
html[data-webview="vk"] body { font-size: 14px !important; }
html[data-webview="vk"] .calc__head h2 { font-size: 1.05rem !important; }
html[data-webview="vk"] .result-cell__value { font-size: 0.88rem !important; }
html[data-webview="vk"] .result-cell--accent .result-cell__value { font-size: 1.1rem !important; }
html[data-webview="vk"] select {
  -webkit-appearance: none !important;
  appearance: none !important;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'><path d='M1 1L6 6L11 1' stroke='%231A1F2E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>") !important;
  background-repeat: no-repeat !important;
  background-position: right 12px center !important;
  background-color: #fff !important;
  padding-right: 36px !important;
}

/* Telegram */
html[data-webview="telegram"] { --tg-bottom-safe: 70px; }
html[data-webview="telegram"] body { padding-bottom: var(--tg-bottom-safe); }
html[data-webview="telegram"] .site-footer {
  padding-bottom: calc(24px + var(--tg-bottom-safe)) !important;
}

/* iOS Safe Area */
@supports (padding: max(0px)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}
