/* ====================================================
   МЕДСПРАОЧНИК v2 — MOBILE RESPONSIVE
   Breakpoints: 768px (tablet), 480px (small phone)
   ==================================================== */

/* ==================== HAMBURGER BUTTON ==================== */

.mobile-menu-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1.5px solid var(--color-border);
  background: none;
  cursor: pointer;
  gap: 5px;
  margin-left: auto;
  flex-shrink: 0;
  padding: 0;
}
.mobile-menu-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--color-text);
  border-radius: 2px;
  transition: all 0.25s cubic-bezier(0.16,1,0.3,1);
  transform-origin: center;
}
.mobile-menu-btn.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.mobile-menu-btn.open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.mobile-menu-btn.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Backdrop */
.mobile-nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 998;
  backdrop-filter: blur(2px);
}
.mobile-nav-backdrop.visible { display: block; }

/* Close button inside nav on mobile */
.mobile-nav-close {
  display: none;
  position: absolute;
  top: 14px;
  right: 16px;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

/* ==================== TABLET (≤ 768px) ==================== */

@media (max-width: 768px) {

  /* --- CONTAINER --- */
  .container { padding-inline: var(--space-4); }

  /* --- HAMBURGER --- */
  .mobile-menu-btn { display: flex; }

  /* --- HEADER --- */
  .header-search { display: none; }
  .header-clinic-btn { display: none; }
  .btn-appointment { display: none; }
  .header-actions .btn-icon { display: none; }
  .header-inner { gap: var(--space-3); padding-block: var(--space-3); }

  /* --- MAIN NAV → SLIDE-IN DRAWER --- */
  .main-nav {
    position: fixed !important;
    top: 0; left: 0; bottom: 0;
    width: min(320px, 85vw);
    z-index: 2147483647 !important; /* максимум — перекрывает всё */
    background: var(--color-primary-dark);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.16,1,0.3,1);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 64px 0 var(--space-10);
    isolation: isolate;
  }
  /* Перекрываем stacking context родителей */
  .site-header { z-index: auto !important; }
  .site-header,
  .site-header * {
    /* Убеждаемся что никто не создаёт transform-stacking */
  }
  .main-nav.mobile-open { transform: translateX(0); }
  .mobile-nav-close { display: flex; }

  .main-nav .container { padding-inline: 0; }

  .main-nav__inner {
    flex-direction: column !important;
    align-items: stretch !important;
    overflow: visible !important;
    gap: 0;
  }

  .main-nav__dropdown-wrap { position: relative; }

  .main-nav__link {
    padding: 14px 20px;
    font-size: 0.95rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    width: 100%;
    justify-content: space-between;
    white-space: normal;
  }

  /* Dropdown → inline accordion on mobile */
  .main-nav__dropdown {
    position: static !important;
    display: none;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    min-width: unset !important;
    background: rgba(0,0,0,0.2);
    padding: 10px 20px 14px 32px !important;
    grid-template-columns: 1fr !important;
  }
  .main-nav__dropdown-wrap.open > .main-nav__dropdown {
    display: grid !important;
  }
  /* Фолбэк — через :focus-within / :hover / активный state */
  .main-nav__dropdown-wrap:focus-within > .main-nav__dropdown {
    display: grid !important;
  }

  .main-nav__dropdown a {
    color: rgba(255,255,255,0.8) !important;
    padding: 7px 0;
    font-size: 0.87rem;
    border-bottom: none;
  }
  .main-nav__dropdown a:hover { color: #fff !important; }
  .main-nav__dropdown-heading {
    color: rgba(255,255,255,0.45) !important;
    border-bottom-color: rgba(255,255,255,0.12) !important;
    margin-top: 10px;
  }
  /* Second dropdown column on mobile — treat as continuation */
  .main-nav__dropdown-col:nth-child(2) { margin-top: 0; }

  /* --- HERO --- */
  .hero { padding-block: var(--space-12) var(--space-10); }
  .hero__title { max-width: 100%; }
  .hero__subtitle { font-size: var(--text-base); max-width: 100%; }
  .hero__search { max-width: 100%; }
  .hero__stats { gap: var(--space-6); flex-wrap: wrap; }
  .hero__stat { min-width: 120px; }

  /* --- PAGE HERO --- */
  .page-hero { padding-block: var(--space-8) var(--space-6) !important; }

  /* --- SECTIONS --- */
  .section { padding-block: var(--space-10); }
  .section-header { margin-bottom: var(--space-6); }

  /* --- DISEASE / ARTICLE LAYOUT --- */
  .disease-layout {
    grid-template-columns: 1fr !important;
    gap: var(--space-6);
    padding-block: var(--space-5);
  }
  /* На мобиле: сайдбар без order — DOM-порядок работает (article идёт первым в HTML) */
  .disease-sidebar { order: unset; }
  /* Sticky sidebar — не sticky на мобиле */
  .disease-sidebar > * { position: static !important; }
  /* Оглавление в сайдбаре скрыто — на мобиле есть inline TOC внутри статьи */
  .disease-sidebar .sidebar-toc { display: none; }
  /* Аналогично для drug-sidebar (симптомы, лекарства) */
  .drug-sidebar .drug-toc-box { display: none; }

  /* --- ARTICLE LAYOUT (article.html) --- */
  .art-layout {
    grid-template-columns: 1fr !important;
    gap: var(--space-6);
  }
  .art-sidebar { order: unset; }
  .art-sidebar > * { position: static !important; top: auto !important; }

  /* --- FOOTER --- */
  .footer-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-8);
  }
  .footer-brand { grid-column: 1 / -1; }
  .footer-brand__desc { max-width: 100%; }
  .footer-bottom { flex-direction: column; align-items: flex-start; gap: var(--space-3); }
  .footer-bottom__links { flex-wrap: wrap; gap: var(--space-4); }

  /* --- FEED WITH POPULAR --- */
  .feed-with-popular { grid-template-columns: 1fr !important; }
  .feed-with-popular .popular-now-box { position: static !important; }

  /* --- CLINIC SEARCH BAR --- */
  .clinic-search-bar { flex-direction: column; align-items: stretch; }
  .clinic-search-bar input { width: 100%; }
  .clinic-search-bar select { max-width: 100% !important; }
  .clinic-search-bar .btn { width: 100%; justify-content: center; }

  /* --- CLINICS CITY CHIPS → горизонтальная прокрутка --- */
  .clinics-city-chips {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
  }
  .clinics-city-chips::-webkit-scrollbar { display: none; }
  .city-chip { white-space: nowrap; flex-shrink: 0; }

  /* --- CLINICS GRID 2 → 1 col --- */
  .clinics-grid-2 { grid-template-columns: 1fr !important; }

  /* --- ARTICLES FILTER TABS → scroll --- */
  .articles-filter-tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .articles-filter-tabs::-webkit-scrollbar { display: none; }
  .art-tab { white-space: nowrap; flex-shrink: 0; }

  /* --- DISEASES TABS → scroll --- */
  .diseases-tabs-nav {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .diseases-tabs-nav::-webkit-scrollbar { display: none; }
  .diseases-tab-btn { white-space: nowrap; flex-shrink: 0; }

  /* --- SYMPTOMS TABS --- */
  .symptoms-tabs-nav {
    flex-wrap: nowrap !important;
    overflow-x: auto;
  }
  .symptoms-tabs-nav::-webkit-scrollbar { display: none; }
  .symptoms-tab-btn { white-space: nowrap; flex-shrink: 0; }

  /* --- ARTICLE AUTHOR BLOCK --- */
  .article-author { flex-direction: column; gap: var(--space-3); }
  .article-author__photo { width: 52px; height: 52px; font-size: var(--text-base); }

  /* --- ARTICLE CLINIC CARD --- */
  .article-clinic-card { flex-wrap: wrap; }
  .article-clinic-card__info { width: 100%; }
  .article-clinic-card .btn--sm {
    width: 100%;
    text-align: center;
    margin-top: var(--space-2);
    justify-content: center;
  }

  /* --- ART SHARE BUTTONS --- */
  .art-share { flex-wrap: wrap; gap: 8px; }

  /* --- ART STATS --- */
  .art-stats { grid-template-columns: 1fr !important; gap: var(--space-3) !important; }

  /* --- ARTICLE CLINICS BLOCK --- */
  .article-clinics-block__title { flex-wrap: wrap; gap: 8px; }
  .article-clinics-block__title select { margin-left: 0 !important; width: 100%; }

  /* --- TRUST SECTION --- */
  .trust-section { padding: var(--space-8) var(--space-5); border-radius: var(--radius-lg); }

  /* --- PRICE GRID --- */
  .price-grid { grid-template-columns: 1fr 1fr !important; }

  /* --- RELATED DISEASES SIDEBAR --- */
  .related-diseases__grid { grid-template-columns: 1fr !important; }
  .related-articles-block .related-articles-grid { grid-template-columns: 1fr 1fr !important; }

  /* --- CLINIC CARD HERO (clinic-card.html) --- */
  .clinic-hero__info { flex-direction: column; }

  /* --- DRUGS GRID --- */
  .drugs-grid { grid-template-columns: 1fr 1fr !important; }

  /* --- APPT CTA --- */
  .appt-cta-inner { flex-direction: column; gap: var(--space-5); }
  .appt-cta-inner__form { width: 100%; }
  .appt-cta-select { width: 100%; }
  .appt-cta-btn { width: 100%; justify-content: center; }
}

/* ==================== SMALL PHONE (≤ 480px) ==================== */

@media (max-width: 480px) {

  /* Single column everything */
  .footer-grid { grid-template-columns: 1fr !important; }
  .clinics-grid-3 { grid-template-columns: 1fr !important; }
  .clinics-grid-2 { grid-template-columns: 1fr !important; }
  .experts-grid { grid-template-columns: 1fr 1fr !important; }
  .trust-pillars { grid-template-columns: 1fr 1fr !important; }
  .price-grid { grid-template-columns: 1fr !important; }
  .related-articles-grid { grid-template-columns: 1fr !important; }
  .related-articles-block .related-articles-grid { grid-template-columns: 1fr !important; }
  .facts-box__grid { grid-template-columns: 1fr 1fr !important; }
  .complications-grid { grid-template-columns: 1fr !important; }
  .life-tips-grid { grid-template-columns: 1fr !important; }
  .symptoms-cards-grid { grid-template-columns: 1fr !important; }
  .drugs-grid { grid-template-columns: 1fr !important; }

  /* Hero adjustments */
  .hero { padding-block: var(--space-10) var(--space-8); }
  .hero__search { flex-wrap: wrap; gap: var(--space-2); }
  .hero__search-btn { width: 100%; justify-content: center; }

  /* Clinic card */
  .clinic-card__footer { flex-direction: column; align-items: flex-start; }
  .clinic-card__btn { width: 100%; text-align: center; justify-content: center; }

  /* Article author */
  .article-author__meta { flex-direction: column; gap: var(--space-2); }

  /* Symptom urgency chips */
  .symptoms-urgency-list { gap: var(--space-2); }
  .symptoms-urgency-chip { font-size: 0.78rem; }
}
