/* ================================================================
   RESPONSIVE LAYER — phones, tablets, and small laptops
   Loaded after page-specific styles.
   ================================================================ */

/* ── Global foundation ─────────────────────────────────────────── */
html {
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow-x: clip;
  min-width: 0;
}

/* Native momentum scroll on iOS — no smooth-scroll fighting touch */
@media (hover: none) and (pointer: coarse) {
  html,
  body {
    scroll-behavior: auto !important;
  }
}

/* Prevent iOS zoom-on-focus (inputs < 16px cause layout jump / "zoom out" feel) */
@media (max-width: 768px) {
  .search-input,
  .form-input,
  .collection-modal__search input,
  .planner-modal__search input,
  .modal__body input,
  .modal__body select,
  .modal__body textarea {
    font-size: 16px;
  }
}

/* Momentum scrolling inside nested lists */
.search-dropdown,
.ingredient-list,
.collection-modal__body,
.planner-modal__results,
.modal-body-scroll {
  -webkit-overflow-scrolling: touch;
}

html.yfc-scroll-locked:not(.capacitor-native),
html.yfc-scroll-locked:not(.capacitor-native) body {
  overflow: hidden !important;
  overscroll-behavior: none;
}

@media (max-width: 768px) {
  html:not(.capacitor-native),
  html:not(.capacitor-native) body {
    overflow-x: hidden;
  }

  html.capacitor-native body {
    overflow-x: hidden;
    overflow-y: scroll;
  }
}

img,
video,
svg {
  max-width: 100%;
  height: auto;
}

/* ── Container & spacing scale ───────────────────────────────── */
@media (max-width: 1024px) {
  .container {
    padding-left: var(--sp-5);
    padding-right: var(--sp-5);
  }
}

@media (max-width: 640px) {
  .container {
    padding-left: var(--sp-4);
    padding-right: var(--sp-4);
  }

  .section {
    padding: var(--sp-10) 0;
  }

  .section__header {
    margin-bottom: var(--sp-8);
  }
}

@media (max-width: 380px) {
  .container {
    padding-left: var(--sp-3);
    padding-right: var(--sp-3);
  }
}

/* ── Hero banner (index) ─────────────────────────────────────── */
@media (max-width: 768px) {
  .hero-banner__slide {
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    padding: 8px 0 52px;
  }

  /* Full-width bottom scrim — text readable across the banner */
  .hero-banner__overlay {
    background: linear-gradient(
      180deg,
      rgba(10, 28, 15, 0.25) 0%,
      rgba(10, 28, 15, 0.55) 38%,
      rgba(10, 28, 15, 0.88) 72%,
      rgba(10, 28, 15, 0.94) 100%
    );
  }

  .hero-banner__content {
    width: 100%;
    max-width: 100%;
    padding-bottom: 0;
    gap: 12px;
    justify-content: center;
  }

  .hero-banner__title {
    font-size: clamp(1.55rem, 5.2vw, 2.05rem);
    line-height: 1.22;
    max-width: 100%;
  }

  .hero-banner__desc {
    font-size: 0.9rem;
    line-height: 1.6;
    max-width: 100%;
    color: rgba(255, 255, 255, 0.88);
  }

  .hero-banner__actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    padding-top: 2px;
  }

  .hero-banner__actions .btn--lg {
    width: 100%;
    justify-content: center;
    padding: 0.6rem 0.75rem;
    font-size: var(--text-sm);
    white-space: normal;
    text-align: center;
    line-height: 1.25;
  }

  .hero-banner__stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px 10px;
    width: 100%;
    margin-top: 2px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
  }

  .hero-banner__stat {
    font-size: var(--text-xs);
    text-align: center;
    line-height: 1.35;
  }

  .hero-banner__stat-divider {
    display: none;
  }

  .hero-banner__dots {
    bottom: 14px;
  }
}

@media (max-width: 480px) {
  .hero-banner {
    height: 540px;
  }

  .hero-banner__slide {
    padding-bottom: 48px;
  }

  .hero-banner__content {
    gap: 10px;
  }

  .hero-banner__chip {
    font-size: 0.68rem;
    padding: 4px 12px;
  }

  .hero-banner__actions {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

@media (max-width: 380px) {
  .hero-banner {
    height: 520px;
  }

  .hero-banner__title {
    font-size: 1.45rem;
  }

  .hero-banner__stats {
    grid-template-columns: 1fr 1fr;
  }

  .hero-banner__stat:last-child {
    grid-column: 1 / -1;
  }
}

/* ── Site header (index) ─────────────────────────────────────── */
@media (max-width: 768px) {
  .header__inner {
    gap: var(--sp-3);
  }

  .header__brand {
    min-width: 0;
    flex: 1;
  }

  .header__logo-text {
    min-width: 0;
  }

  .hero__stats {
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--sp-3);
  }

  .hero__stat-divider {
    display: none;
  }

  .how-it-works__steps {
    flex-direction: column;
    align-items: stretch;
  }

  .step {
    min-width: 0;
    max-width: none;
    width: 100%;
  }
}

@media (max-width: 480px) {
  :root {
    --header-h: 60px;
  }

  .header__logo-name {
    font-size: var(--text-base);
    max-width: 52vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .header__inner {
    gap: var(--sp-2);
  }

  .header__nav.open {
    padding: var(--sp-4);
  }

  #nav-guest,
  #nav-user {
    flex-wrap: wrap !important;
    gap: var(--sp-2) !important;
  }
}

/* ── App headers (dashboard, planner, health, profile) ─────────── */
@media (max-width: 768px) {
  .dash-header__inner .header__brand {
    min-width: 0;
    flex: 1;
  }

  .dash-header__inner .header__logo-name {
    font-size: var(--text-sm);
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (max-width: 480px) {
  .dash-header__inner {
    height: 56px;
    padding-left: var(--sp-4);
    padding-right: var(--sp-4);
  }

  .dash-user {
    padding-left: 0;
    gap: var(--sp-2);
    border-left: none;
  }
}

/* ── Tabs & controls ─────────────────────────────────────────── */
@media (max-width: 640px) {
  .tabs {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tab {
    flex-shrink: 0;
  }
}

/* ── Meal carousel ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .meal-carousel,
  .recent-scroller,
  .tabs,
  .hh-week-scroll {
    scroll-behavior: auto;
    scroll-snap-type: x proximity;
    overscroll-behavior-x: contain;
    touch-action: auto;
    -webkit-overflow-scrolling: touch;
    scroll-padding-inline: 4px;
  }

  .meal-carousel .meal-card,
  .recent-scroller .recent-card {
    scroll-snap-stop: normal;
  }
}

@media (hover: none) and (pointer: coarse) {
  .meal-carousel .meal-card:hover {
    transform: none;
    box-shadow: var(--sh-sm);
  }

  .meal-carousel .food-card:hover .food-image {
    transform: scale(1.15);
  }
}

@media (max-width: 640px) {
  .meal-carousel .meal-card {
    width: min(78vw, 260px);
  }
}

@media (max-width: 380px) {
  .meal-carousel .meal-card {
    width: min(84vw, 240px);
  }
}

/* ── Calculator & results ────────────────────────────────────── */
@media (max-width: 768px) {
  .calculator-layout {
    gap: var(--sp-6);
  }

  .panel,
  .results {
    padding: var(--sp-5);
  }

  .calories-card__inner {
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .panel,
  .results {
    padding: var(--sp-4);
  }

  .micros-grid {
    grid-template-columns: 1fr;
    gap: var(--sp-3);
  }
}

/* ── Modals ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .modal {
    padding: 0;
    align-items: flex-end;
  }

  .modal__content {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
  }

  .modal__body,
  .modal-body-scroll {
    padding: var(--sp-4);
  }

  .modal-footer-btns {
    flex-direction: column;
    padding: var(--sp-4);
  }

  .collection-modal__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  #meal-detail-modal .modal__content {
    max-height: 94vh;
  }
}

@media (max-width: 380px) {
  .collection-modal__grid {
    grid-template-columns: 1fr;
  }
}

/* ── Dashboard layout ────────────────────────────────────────── */
@media (max-width: 768px) {
  .dash-main {
    padding: var(--sp-6) var(--sp-5);
  }

  .dash-card__header {
    flex-wrap: wrap;
    gap: var(--sp-2);
  }
}

@media (max-width: 640px) {
  .dash-main {
    padding: var(--sp-5) var(--sp-4);
  }

  .progress-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-3);
    padding: var(--sp-4);
  }

  .progress-ring {
    width: 72px;
    height: 72px;
  }
}

@media (max-width: 380px) {
  .progress-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-2);
  }
}

/* ── Footer ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .footer__brand-link {
    justify-content: center;
    width: 100%;
  }

  .footer__col {
    text-align: center;
  }

  .footer__nav {
    align-items: center;
  }
}

/* ── Touch-friendly targets ──────────────────────────────────── */
@media (max-width: 768px) {
  .btn,
  .header__nav-link,
  .dash-nav a,
  .planner-toggle-btn,
  .planner-tab {
    min-height: 44px;
  }

  .header__menu-btn,
  .dash-menu-btn {
    min-width: 44px;
    min-height: 44px;
  }
}