/**
 * Общие правки мобильной вёрстки sad-365.ru
 * Подключается после стилей страницы (через ssr-inject).
 */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
  max-width: 100%;
}

img:not(.card__thumb-img),
picture img,
video,
canvas {
  max-width: 100%;
  height: auto;
  display: block;
}

svg {
  max-width: 100%;
  height: auto;
}

main,
header,
footer,
nav,
section,
article {
  max-width: 100%;
}

/* ── Карточки статей ── */
.card__thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--green-light, #e8f5e1);
  min-width: 0;
}

.card__thumb-img {
  width: 100%;
  max-width: 100%;
  height: 100% !important;
  min-height: 0;
  max-height: none;
  object-fit: cover;
  object-position: center;
  display: block;
}

.card__thumb-placeholder {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (hover: none) {
  .card:hover .card__thumb-img {
    transform: none;
  }
}

/* ── Иконки луны (не растягивать на всю ширину ячейки) ── */
img.lunar-phase-img {
  width: 28px;
  height: 28px;
  max-width: 28px;
  min-width: 28px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
  object-fit: contain;
}

.lunar-widget img.lunar-phase-img {
  width: 22px;
  height: 22px;
  max-width: 22px;
  min-width: 22px;
}

.lunar-phase-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* ── Страница статьи: без обрезания и с рабочими картинками ── */
.page-wrap,
.page-wrap .container {
  min-width: 0;
}

.article,
.article [itemprop="articleBody"] {
  min-width: 0;
  max-width: 100%;
}

.article h1,
.article h2,
.article h3,
.article p,
.article li {
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.article .article-body,
.article .article-body p,
.article .article-body li,
.article [itemprop="articleBody"].article-body,
.article [itemprop="articleBody"].article-body p,
.article [itemprop="articleBody"].article-body li {
  font-size: 18px;
  line-height: 1.75;
}

.article .article-body h2,
.article h2 {
  font-size: 24px;
}

.article .article-body h3,
.article h3 {
  font-size: 18px;
}

figure.article-img,
.article figure.article-img {
  max-width: 100%;
  margin: 16px 0;
  overflow: hidden;
}

.article img.article-img__photo,
figure.article-img img,
.article img:not(.lunar-phase-img):not(.card__thumb-img),
.article-body img,
.page-body img {
  display: block;
  max-width: 100% !important;
  width: 100% !important;
  height: auto !important;
  object-fit: contain;
}

/* ── Таблицы ── */
.article .cal-table,
.cal-table,
table {
  max-width: 100%;
}

.table-scroll,
.article .cal-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* ── Типографика / переносы ── */
h1,
h2,
h3,
.logo__name,
.card__title,
.nav__link {
  overflow-wrap: break-word;
  word-break: break-word;
}

p,
.card__excerpt,
.section-intro__desc,
.section-head__text p {
  overflow-wrap: break-word;
}

/* ── Контейнеры ── */
.container,
.wrap {
  width: 100%;
  max-width: 100%;
}

.page-content {
  min-width: 0;
}

/* ── Навигация: кнопка «Меню сайта» только на мобильных ── */
@media (min-width: 769px) {
  .nav__toggle {
    display: none !important;
    visibility: hidden !important;
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    pointer-events: none !important;
    border: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .nav__panel {
    display: contents;
  }
}

/* ── Навигация ── */
.nav {
  max-width: 100%;
  overflow: visible;
}

@media (max-width: 768px) {
  .nav {
    overflow-x: clip;
  }
}

.nav .container {
  min-width: 0;
}

.nav__list {
  min-width: 0;
}

/* ── Кнопки (тач) ── */
.btn,
.search-form button,
.search-form input {
  min-height: 44px;
}

@media (max-width: 768px) {
  .container,
  .page-content,
  .wrap,
  .header .container,
  .breadcrumb .container {
    padding-left: max(14px, env(safe-area-inset-left, 0px));
    padding-right: max(14px, env(safe-area-inset-right, 0px));
  }

  /* ── Лунный календарь (/lunar-calendar/) ── */
  .calendar-wrap {
    padding: 12px 8px;
    max-width: 100%;
    overflow: hidden;
  }

  .page-content {
    padding-top: 20px;
    padding-bottom: 48px;
  }

  .page-hero {
    padding: 24px 12px 20px;
  }

  .legend {
    gap: 10px;
    padding: 10px 12px;
  }

  .legend-item {
    font-size: 12px;
  }

  .legend-item[style*="margin-left:auto"] {
    margin-left: 0;
    width: 100%;
  }

  .month-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding-bottom: 4px;
  }

  .month-tabs .mtab {
    flex-shrink: 0;
    scroll-snap-align: start;
  }

  .week-labels,
  .cal-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 3px;
    max-width: 100%;
  }

  .wl {
    font-size: 10px;
    padding: 2px 0;
  }

  .dc {
    min-width: 0;
    min-height: 54px;
    padding: 4px 2px;
    gap: 2px;
  }

  .dm {
    font-size: 16px;
    line-height: 1;
  }

  .dn {
    font-size: 11px;
  }

  .dl {
    font-size: 8px;
    line-height: 1.15;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .sc {
    padding: 10px 6px;
    min-width: 0;
  }

  .sn {
    font-size: 22px;
  }

  .sl {
    font-size: 10px;
  }

  .cal-nav {
    gap: 8px;
    min-width: 0;
  }

  .cal-nav-title {
    font-size: 16px;
    min-width: 0;
    text-align: center;
    flex: 1;
  }

  .info-section {
    grid-template-columns: 1fr;
  }

  .lunar-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    margin-left: max(-4px, calc(-1 * env(safe-area-inset-left, 0px)));
    margin-right: max(-4px, calc(-1 * env(safe-area-inset-right, 0px)));
    padding-left: 4px;
    padding-right: 4px;
  }

  .lunar-table-wrap .cal-table {
    min-width: 0;
    width: 100%;
    font-size: 12px;
  }

  .lunar-table-wrap .cal-table th,
  .lunar-table-wrap .cal-table td {
    padding: 7px 6px;
    white-space: normal;
    word-break: break-word;
  }

  .nav .container {
    padding-left: 0;
    padding-right: 0;
  }

  .header .container {
    flex-wrap: wrap;
    height: auto;
    gap: 10px;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .search-form {
    flex: 1 1 100%;
    width: 100%;
    max-width: none;
    min-width: 0;
    order: 3;
  }

  .search-form input {
    min-width: 0;
    width: 100%;
  }

  .logo__tagline {
    font-size: 10px;
    line-height: 1.3;
  }

  .top-bar .container {
    flex-direction: column;
    height: auto;
    padding-top: 8px;
    padding-bottom: 8px;
    gap: 6px;
    text-align: center;
  }

  .top-bar__right {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
  }

  .top-bar__links {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
  }

  .hero {
    margin-left: 0;
    margin-right: 0;
    border-radius: 0;
  }

  .section-intro__card,
  .section-head,
  .section-intro__bottom {
    padding-left: 18px;
    padding-right: 18px;
  }

  .section-intro__top {
    gap: 16px;
  }

  .section-intro__bottom {
    grid-template-columns: 1fr;
  }

  .section-intro__actions {
    justify-content: stretch;
  }

  .section-intro__actions .btn {
    flex: 1;
    justify-content: center;
  }

  .article {
    padding: 20px 16px;
  }

  .page-body {
    padding-left: 14px;
    padding-right: 14px;
  }

  .footer__bottom {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
  }

  .articles-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .cal-year-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
}

@media (max-width: 430px) {
  .logo__name {
    font-size: 17px;
  }

  .logo__tagline {
    display: none;
  }

  .hero__title {
    font-size: clamp(22px, 6vw, 28px);
  }

  .section-intro h1,
  .section-head__text h1 {
    font-size: clamp(22px, 5.5vw, 28px);
  }

  .section-intro__card::before {
    display: none;
  }
}

@media (max-width: 380px) {
  .calendar-wrap {
    padding: 8px 4px;
  }

  .week-labels,
  .cal-grid {
    gap: 2px;
  }

  .dc {
    min-height: 46px;
    padding: 3px 1px;
  }

  .dm {
    font-size: 14px;
  }

  .dn {
    font-size: 10px;
  }

  .dl {
    display: none;
  }

  .plant-tag {
    font-size: 13px;
    padding: 7px 14px;
  }
}

@media (max-width: 320px) {
  .container,
  .page-content,
  .wrap {
    padding-left: max(10px, env(safe-area-inset-left, 0px));
    padding-right: max(10px, env(safe-area-inset-right, 0px));
  }

  .btn {
    padding: 10px 14px;
    font-size: 13px;
  }
}
