/**
 * DEJOIY Mobile App Layout — native app feel on phones & tablets (≤1024px)
 *
 * Design principles:
 * - Bottom navigation persistent
 * - Sticky search bar
 * - Swipeable horizontal rails
 * - Full-width product cards (2-col grid)
 * - Touch-friendly 48px targets
 * - Safe area insets for notched devices
 * - Smooth micro-interactions
 * - No horizontal scroll on body
 */

/* ============================================
   BASE APP SHELL
   ============================================ */

@media (max-width: 1024px) {
  /* App-like body — no scroll bounce, smooth momentum */
  body.dejoiy-mobile-os {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    scroll-behavior: smooth;
  }

  /* Prevent text selection on interactive elements */
  .dm-bottom__item,
  .dm-modes__pill,
  .dm-catnav__item,
  .dm-mkt-cats__item,
  .du-card-v2__fav,
  .du-joi__chip {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
  }

  /* Ensure minimum touch targets: 48x48px */
  .dm-bottom__item,
  .dm-search__field,
  .dm-modes__pill,
  .dm-catnav__item {
    min-height: 48px;
    min-width: 48px;
  }
}

/* ============================================
   STICKY SEARCH BAR (app-style)
   ============================================ */

@media (max-width: 1024px) {
  /* Search bar stays visible while scrolling */
  .dm-search-row {
    position: sticky;
    top: 0;
    z-index: 9995;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    border-bottom: 1px solid rgba(15, 23, 42, 0.06);
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.04);
    transition: box-shadow 0.2s ease;
  }

  /* Enhanced search input — app-style */
  .dm-search__input {
    min-height: 44px;
    padding: 0.6rem 0.85rem 0.6rem 2.5rem;
    border-radius: 14px;
    border: 1.5px solid rgba(15, 23, 42, 0.08);
    background: #f8fafc;
    font-size: 0.95rem;
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  }

  .dm-search__input:focus {
    border-color: #7c3aed;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
    outline: none;
  }

  /* Search icon position */
  .dm-search__ico {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    pointer-events: none;
    z-index: 2;
    transition: color 0.2s ease;
  }

  .dm-search__input:focus ~ .dm-search__ico,
  .dm-search__field:focus-within .dm-search__ico {
    color: #7c3aed;
  }
}

/* ============================================
   PRODUCT CARDS — App-style grid
   ============================================ */

@media (max-width: 1024px) {
  /* Full-width 2-column grid */
  .du-shelf-v2 {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
    padding: 0 0.75rem;
  }

  /* Card styling — app-like flat design */
  .du-card-v2 {
    border-radius: 14px;
    overflow: hidden;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, 0.06);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
  }

  .du-card-v2:active {
    transform: scale(0.98);
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
  }

  /* Card media — square aspect ratio for app feel */
  .du-card-v2__media {
    aspect-ratio: 1;
    border-radius: 0;
  }

  .du-card-v2__img {
    transition: none;
  }

  .du-card-v2:hover .du-card-v2__img {
    transform: none;
  }

  /* Card body — compact padding */
  .du-card-v2__body {
    padding: 0.6rem 0.7rem 0.75rem;
  }

  .du-card-v2__title {
    font-size: 0.82rem;
    line-height: 1.3;
    -webkit-line-clamp: 2;
  }

  .du-card-v2__price {
    font-size: 0.85rem;
  }

  .du-card-v2__seller {
    font-size: 0.65rem;
  }

  .du-card-v2__delivery {
    font-size: 0.62rem;
  }

  .du-card-v2__rating {
    font-size: 0.65rem;
  }

  .du-card-v2__stars {
    font-size: 0.68rem;
  }

  .du-card-v2__fav {
    width: 1.75rem;
    height: 1.75rem;
    font-size: 0.85rem;
    top: 0.4rem;
    right: 0.4rem;
  }

  /* Discount badge — app-style */
  .du-card-v2__discount {
    font-size: 0.62rem;
    padding: 0.2rem 0.45rem;
    left: 0.4rem;
    top: 0.4rem;
  }

  .du-card-v2__eco {
    font-size: 0.58rem;
    padding: 0.2rem 0.4rem;
    left: 0.4rem;
    bottom: 0.4rem;
  }
}

/* ============================================
   HORIZONTAL SCROLL RAILS (app-style swipe)
   ============================================ */

@media (max-width: 1024px) {
  /* Make shelves horizontally scrollable on mobile */
  .du-shelf-v2 {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.5rem;
    gap: 0.65rem;
  }

  .du-shelf-v2::-webkit-scrollbar {
    display: none;
  }

  .du-card-v2 {
    flex: 0 0 45%;
    min-width: 155px;
    scroll-snap-align: start;
  }

  /* Hide empty state cards */
  .du-shelf-v2:empty {
    display: none;
  }
}

/* ============================================
   BOTTOM NAVIGATION — App-style
   ============================================ */

@media (max-width: 1024px) {
  .dm-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(20px) saturate(1.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    border-top: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.06);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* Bottom nav items — app-style */
  .dm-bottom__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.35rem 0;
    text-decoration: none;
    color: #94a3b8;
    font-size: 0.6rem;
    font-weight: 500;
    min-height: 52px;
    transition: color 0.15s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }

  .dm-bottom__item span:first-child {
    font-size: 1.2rem;
    line-height: 1;
    transition: transform 0.15s ease;
  }

  .dm-bottom__item:active span:first-child {
    transform: scale(0.85);
  }

  .dm-bottom__item.is-active {
    color: #2563eb;
    font-weight: 700;
  }

  .dm-bottom__item.is-active span:first-child {
    transform: scale(1.1);
  }

  /* Active indicator — top pill */
  .dm-bottom__item.is-active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 1.75rem;
    height: 3px;
    border-radius: 0 0 4px 4px;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
  }

  /* Cart badge — app-style */
  .dm-bottom__badge {
    position: absolute;
    top: 0.15rem;
    right: 50%;
    transform: translateX(calc(50% + 0.6rem));
    min-width: 1rem;
    height: 1rem;
    padding: 0 0.2rem;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.5rem;
    font-weight: 800;
    line-height: 1rem;
    border: 1.5px solid #fff;
  }
}

/* ============================================
   HERO SECTION — App-style compact
   ============================================ */

@media (max-width: 1024px) {
  .du-hero {
    padding: clamp(1.5rem, 5vw, 2.5rem) clamp(0.85rem, 3vw, 1.25rem) clamp(1.5rem, 4vw, 2rem);
  }

  .du-hero__title {
    font-size: clamp(1.75rem, 7vw, 2.5rem);
    letter-spacing: -0.02em;
  }

  .du-hero__lead {
    font-size: 0.92rem;
    margin-bottom: 1.5rem;
  }

  /* Gateway cards — 2-column app grid */
  .du-gates {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
  }

  .du-gate {
    min-height: 110px;
    padding: 0.85rem 0.75rem;
    border-radius: 14px;
  }

  .du-gate__icon {
    font-size: 1.15rem;
  }

  .du-gate__verb {
    font-size: 0.58rem;
  }

  .du-gate__label {
    font-size: 0.88rem;
  }

  .du-gate__tag {
    font-size: 0.7rem;
  }
}

/* ============================================
   JOI SECTION — App-style
   ============================================ */

@media (max-width: 1024px) {
  .du-joi {
    padding: clamp(1.5rem, 4vw, 2rem) clamp(0.75rem, 3vw, 1rem);
  }

  .du-joi__in {
    padding: clamp(1rem, 3vw, 1.5rem);
    border-radius: 18px;
  }

  .du-joi__title {
    font-size: clamp(1.5rem, 5vw, 2rem);
  }

  .du-joi__input {
    min-height: 48px;
    font-size: 0.95rem;
    border-radius: 12px;
  }

  .du-joi__submit {
    min-height: 48px;
    border-radius: 12px;
    font-size: 0.9rem;
  }

  /* JOI chips — horizontally scrollable */
  .du-joi__examples {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0.5rem;
    padding-bottom: 0.25rem;
  }

  .du-joi__examples::-webkit-scrollbar {
    display: none;
  }

  .du-joi__chip {
    flex: 0 0 auto;
    scroll-snap-align: start;
    font-size: 0.78rem;
    padding: 0.4rem 0.75rem;
    white-space: nowrap;
  }
}

/* ============================================
   WORLD SECTIONS — App-style
   ============================================ */

@media (max-width: 1024px) {
  .du-world {
    margin: clamp(1rem, 3vw, 1.5rem) clamp(0.5rem, 2vw, 0.75rem);
    border-radius: 18px;
  }

  .du-world__in {
    padding: clamp(1rem, 3vw, 1.5rem);
  }

  .du-world__title {
    font-size: clamp(1.15rem, 3vw, 1.5rem);
  }

  .du-world__desc {
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
  }

  .du-world__cta {
    font-size: 0.78rem;
    padding: 0.45rem 0.9rem;
  }

  /* World shelves — horizontal scroll */
  .du-shelf-v2--nexus,
  .du-shelf-v2--studio,
  .du-shelf-v2--quickmart,
  .du-shelf-v2--services {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0.65rem;
    padding: 0 0 0.5rem;
  }

  .du-shelf-v2--nexus::-webkit-scrollbar,
  .du-shelf-v2--studio::-webkit-scrollbar,
  .du-shelf-v2--quickmart::-webkit-scrollbar,
  .du-shelf-v2--services::-webkit-scrollbar {
    display: none;
  }

  .du-shelf-v2--nexus .du-card-v2,
  .du-shelf-v2--studio .du-card-v2,
  .du-shelf-v2--quickmart .du-card-v2,
  .du-shelf-v2--services .du-card-v2 {
    flex: 0 0 42%;
    min-width: 145px;
    scroll-snap-align: start;
  }
}

/* ============================================
   RECOMMENDATIONS — App-style tabs
   ============================================ */

@media (max-width: 1024px) {
  .du-reco {
    padding: clamp(1.5rem, 4vw, 2rem) clamp(0.75rem, 3vw, 1rem);
  }

  .du-reco__title {
    font-size: clamp(1.15rem, 3vw, 1.4rem);
  }

  .du-reco__tabs {
    display: flex;
    overflow-x: auto;
    scrollbar-width: none;
    gap: 0.4rem;
    margin-bottom: 1rem;
    padding-bottom: 0.25rem;
  }

  .du-reco__tabs::-webkit-scrollbar {
    display: none;
  }

  .du-reco__tab {
    flex: 0 0 auto;
    font-size: 0.78rem;
    padding: 0.4rem 0.85rem;
    white-space: nowrap;
  }
}

/* ============================================
   TRUST SIGNALS — App-style compact
   ============================================ */

@media (max-width: 1024px) {
  .du-trust {
    padding: clamp(1rem, 3vw, 1.5rem) clamp(0.75rem, 3vw, 1rem);
  }

  .du-trust__grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
  }

  .du-trust__item {
    padding: 0.85rem 0.5rem;
    border-radius: 12px;
  }

  .du-trust__icon {
    font-size: 1.35rem;
  }

  .du-trust__label {
    font-size: 0.72rem;
  }

  .du-trust__desc {
    font-size: 0.6rem;
    display: none;
  }
}

/* ============================================
   JOIN CTA — App-style
   ============================================ */

@media (max-width: 1024px) {
  .du-join {
    margin: clamp(1.5rem, 4vw, 2rem) clamp(0.75rem, 3vw, 1rem) 0;
    padding: clamp(1.5rem, 4vw, 2rem) clamp(1rem, 3vw, 1.5rem);
    border-radius: 20px;
  }

  .du-join__title {
    font-size: clamp(1.25rem, 4vw, 1.65rem);
  }

  .du-join__lead {
    font-size: 0.88rem;
  }

  .du-join__roles {
    gap: 0.4rem;
  }

  .du-join__roles span {
    font-size: 0.72rem;
    padding: 0.35rem 0.65rem;
  }

  .du-join__btn {
    padding: 0.75rem 1.5rem;
    font-size: 0.88rem;
  }
}

/* ============================================
   STORY SECTION — App-style
   ============================================ */

@media (max-width: 1024px) {
  .du-story {
    padding: clamp(2rem, 5vw, 3rem) clamp(0.85rem, 3vw, 1.25rem);
  }

  .du-story__formula {
    font-size: clamp(1.25rem, 4vw, 1.75rem);
  }

  .du-story__title {
    font-size: clamp(1.15rem, 3vw, 1.4rem);
  }

  .du-story__verbs {
    gap: 0.4rem 0.65rem;
  }

  .du-story__verbs li {
    font-size: 0.82rem;
    padding: 0.3rem 0.7rem;
  }
}

/* ============================================
   SKELETON LOADING STATES
   ============================================ */

@media (max-width: 1024px) {
  /* Skeleton card */
  .du-card-v2--skeleton {
    pointer-events: none;
  }

  .du-card-v2--skeleton .du-card-v2__media {
    background: linear-gradient(110deg, #f1f5f9 8%, #e2e8f0 18%, #f1f5f9 33%);
    background-size: 200% 100%;
    animation: du-skeleton-shimmer 1.5s linear infinite;
  }

  .du-card-v2--skeleton .du-card-v2__title,
  .du-card-v2--skeleton .du-card-v2__price,
  .du-card-v2--skeleton .du-card-v2__seller {
    background: linear-gradient(110deg, #f1f5f9 8%, #e2e8f0 18%, #f1f5f9 33%);
    background-size: 200% 100%;
    animation: du-skeleton-shimmer 1.5s linear infinite;
    border-radius: 6px;
    color: transparent;
    min-height: 1em;
  }

  @keyframes du-skeleton-shimmer {
    to { background-position-x: -200%; }
  }
}

/* ============================================
   PULL-TO-REFRESH FEEL
   ============================================ */

@media (max-width: 1024px) {
  /* Overscroll glow at top */
  body.dejoiy-mobile-os::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #7c3aed, #06b6d4, #ec4899);
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
  }

  body.dejoiy-mobile-os.dejoiy-pulling::before {
    opacity: 1;
  }
}

/* ============================================
   TABLET ENHANCEMENTS (768px–1024px)
   ============================================ */

@media (min-width: 768px) and (max-width: 1024px) {
  /* 3-column product grid on tablet */
  .du-shelf-v2 {
    grid-template-columns: repeat(3, 1fr);
  }

  .du-card-v2 {
    flex: 0 0 30%;
    min-width: 180px;
  }

  /* Larger gateway cards */
  .du-gates {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.85rem;
  }

  .du-gate {
    min-height: 130px;
    padding: 1rem 0.85rem;
  }

  /* Trust — full 6 columns on tablet landscape */
  .du-trust__grid {
    grid-template-columns: repeat(6, 1fr);
  }

  .du-trust__desc {
    display: block;
  }

  /* Larger search input */
  .dm-search__input {
    font-size: 1rem;
    padding: 0.7rem 1rem 0.7rem 2.75rem;
  }
}

/* ============================================
   VERY SMALL SCREENS (≤360px)
   ============================================ */

@media (max-width: 360px) {
  .du-shelf-v2 {
    gap: 0.5rem;
    padding: 0 0.5rem;
  }

  .du-card-v2 {
    flex: 0 0 44%;
    min-width: 140px;
  }

  .du-card-v2__body {
    padding: 0.5rem 0.6rem 0.65rem;
  }

  .du-card-v2__title {
    font-size: 0.78rem;
  }

  .du-gates {
    gap: 0.5rem;
  }

  .du-gate {
    min-height: 95px;
    padding: 0.7rem 0.6rem;
  }

  .du-gate__label {
    font-size: 0.82rem;
  }

  .du-trust__grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .du-trust__item {
    padding: 0.65rem 0.4rem;
  }

  .du-trust__icon {
    font-size: 1.15rem;
  }

  .du-trust__label {
    font-size: 0.65rem;
  }

  .dm-bottom__item {
    font-size: 0.55rem;
    min-height: 48px;
  }

  .dm-bottom__item span:first-child {
    font-size: 1.05rem;
  }
}

/* ============================================
   REDUCED MOTION SUPPORT
   ============================================ */

@media (max-width: 1024px) and (prefers-reduced-motion: reduce) {
  .du-card-v2,
  .du-gate,
  .dm-bottom__item span:first-child {
    transition: none !important;
  }

  .du-card-v2:active {
    transform: none;
  }

  .dm-bottom__item:active span:first-child {
    transform: none;
  }

  .du-card-v2--skeleton .du-card-v2__media,
  .du-card-v2--skeleton .du-card-v2__title,
  .du-card-v2--skeleton .du-card-v2__price,
  .du-card-v2--skeleton .du-card-v2__seller {
    animation: none;
  }
}

/* ============================================
   DARK MODE SUPPORT (future-ready)
   ============================================ */

@media (max-width: 1024px) and (prefers-color-scheme: dark) {
  /* Reserved for dark mode — currently using light theme only */
  /* Uncomment when dark mode is ready:
  .dm-bottom {
    background: rgba(15, 23, 42, 0.96);
    border-top-color: rgba(255, 255, 255, 0.08);
  }
  .dm-bottom__item {
    color: #64748b;
  }
  .dm-bottom__item.is-active {
    color: #60a5fa;
  }
  */
}
