/* ===== Home Skeleton Loading ===== */
@keyframes home-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.home-sk-base {
  background: linear-gradient(90deg, #e8e8e8 0%, #f3f3f3 45%, #e8e8e8 90%);
  background-size: 200% 100%;
  animation: home-shimmer 1.35s ease-in-out infinite;
}

#page-home.home-loading .home-skeleton-block:not(.home-sk-hidden) {
  display: block !important;
}

#page-home.home-loading .home-skeleton-block.home-sk-hidden {
  display: none !important;
}

#page-home.home-loading .home-loaded-block:not(.home-reveal) {
  display: none !important;
}

#page-home.home-loading .home-loaded-block.home-reveal {
  display: block !important;
}

#page-home.home-loading #home-sticky-tags {
  display: block !important;
}

#page-home.home-loading #home-sk-categories .category-scroll,
#page-home.home-loading #home-content-categories .category-scroll {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  gap: 5px;
  padding: 0 0 12px;
  scrollbar-width: none;
}

#page-home.home-loading #home-sk-categories .category-scroll::-webkit-scrollbar,
#page-home.home-loading #home-content-categories .category-scroll::-webkit-scrollbar {
  display: none;
}

#page-home.home-loading .home-sk-tags-scroll,
#page-home.home-loading .home-sk-rest-scroll {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
}

#page-home.home-loading .home-sk-product-grid {
  display: grid !important;
}

#page-home.home-loading .home-sk-features-grid {
  display: grid !important;
}

#page-home:not(.home-loading) .home-skeleton-block {
  display: none !important;
}

#page-home.home-loading #home-scroll,
#page-home.home-load-finishing #home-scroll,
#home-scroll {
  overflow-anchor: none;
}

/* Tags skeleton */
.home-sk-tags {
  padding: 0 var(--content-padding);
  padding-top: 4px;
  padding-bottom: 2px;
}

.home-sk-tags-scroll {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  padding: 2px 0 4px;
  touch-action: pan-x;
}

.home-sk-pill {
  flex-shrink: 0;
  height: 32px;
  border-radius: 8px;
}

.home-sk-pill.sm { width: 40px; }
.home-sk-pill.md { width: 56px; }
.home-sk-pill.lg { width: 72px; }

/* Banner skeleton — match live banner + dots height (prevents jump on reveal) */
.home-sk-banner {
  margin-top: 4px;
  min-height: calc(var(--hero-banner-h, 160px) + 32px);
}

.home-sk-banner-box {
  height: var(--hero-banner-h, 160px);
  border-radius: 18px;
}

.home-sk-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 8px 0 6px;
}

.home-sk-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.home-sk-dot.wide {
  width: 18px;
  border-radius: 3px;
}

/* Categories skeleton — horizontal row via .category-scroll */
.home-sk-categories .category-scroll,
.home-sk-categories-scroll {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 5px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 0 12px;
  scrollbar-width: none;
}

.home-sk-categories .category-scroll::-webkit-scrollbar,
.home-sk-categories-scroll::-webkit-scrollbar {
  display: none;
}

.home-sk-categories {
  padding: 0;
  overflow: visible;
}

.home-sk-cat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 72px;
  flex-shrink: 0;
}

.home-sk-cat-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
}

.home-sk-cat-label {
  width: 58px;
  height: 11px;
  border-radius: 5px;
}

/* Restaurants skeleton */
.home-sk-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.home-sk-title {
  width: 140px;
  height: 18px;
  border-radius: 6px;
}

.home-sk-see-all {
  width: 56px;
  height: 12px;
  border-radius: 6px;
}

.home-sk-rest-scroll {
  display: flex;
  gap: 12px;
  overflow: hidden;
  padding-bottom: 4px;
  margin-bottom: 18px;
}

.home-sk-rest-card {
  flex-shrink: 0;
  width: 168px;
}

.home-sk-rest-img {
  width: 100%;
  height: 96px;
  border-radius: 14px;
  margin-bottom: 8px;
}

.home-sk-rest-line {
  height: 12px;
  border-radius: 6px;
  margin-bottom: 6px;
}

.home-sk-rest-line.w80 { width: 80%; }
.home-sk-rest-line.w60 { width: 60%; }
.home-sk-rest-line.w45 { width: 45%; }

/* Category cards skeleton */
.home-sk-category-cards {
  margin-bottom: 18px;
}

/* Product skeleton */
.home-sk-product-section {
  margin-bottom: 18px;
}

.home-sk-product-section.home-sk-compact,
#page-home .home-sk-restaurants.home-sk-compact {
  margin-bottom: 2px;
}

.home-sk-product-section.home-sk-compact .home-sk-section-head,
#page-home .home-sk-restaurants.home-sk-compact .home-sk-section-head {
  display: none;
}

.home-sk-product-grid {
  display: grid;
  grid-template-columns: repeat(var(--product-grid-cols), minmax(0, 1fr));
  gap: var(--product-gap);
}

.home-sk-product-card {
  border-radius: 12px;
  padding: 8px;
  background: var(--white);
  border: 1px solid var(--border);
}

.home-sk-product-img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  margin-bottom: 8px;
}

.home-sk-product-line {
  height: 10px;
  border-radius: 5px;
  margin-bottom: 6px;
}

.home-sk-product-line.w70 { width: 70%; }
.home-sk-product-line.w40 { width: 40%; }
.home-sk-product-line.w50 { width: 50%; }

.home-sk-product-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.home-sk-price {
  width: 36px;
  height: 12px;
  border-radius: 6px;
}

.home-sk-add {
  width: 28px;
  height: 28px;
  border-radius: 8px;
}

/* Features skeleton */
.home-sk-features {
  margin-bottom: 8px;
}

.home-sk-features-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.home-sk-feature-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.home-sk-feature-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex-shrink: 0;
}

.home-sk-feature-text {
  flex: 1;
  min-width: 0;
}

.home-sk-feature-line {
  height: 10px;
  border-radius: 5px;
  margin-bottom: 6px;
}

.home-sk-feature-line:last-child {
  margin-bottom: 0;
}

.home-sk-feature-line.w60 { width: 60%; }
.home-sk-feature-line.w80 { width: 80%; }

/* Inline section loader — overlay only (no layout shift) */
.home-section-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
  min-height: 0;
  width: 100%;
  flex-shrink: 0;
  pointer-events: none;
  z-index: 4;
}

#home-loader-after-tags {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
}

/* Pull-to-refresh — slides up below tags, no layout shift */
#home-loader-after-tags.home-pull-loader {
  transform: translateY(100%);
  opacity: 0;
  padding: 6px 0 10px;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

#home-loader-after-tags.home-pull-loader .home-ios-spinner::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 36px;
  height: 36px;
  transform: translate(-50%, -50%);
  background: #ffffff;
  border-radius: 50%;
  box-shadow:
    0 3px 10px rgba(0, 0, 0, 0.1),
    0 1px 4px rgba(0, 0, 0, 0.06);
  z-index: -1;
}

#home-loader-after-tags.home-pull-loader.is-refreshing .home-ios-spinner::before {
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.11),
    0 2px 5px rgba(0, 0, 0, 0.07);
}

#home-loader-after-tags.home-pull-loader.is-pulling {
  transform: translateY(calc(100% - var(--home-pull-offset, 0px)));
  opacity: 1;
}

#home-loader-after-tags.home-pull-loader.is-refreshing {
  transform: translateY(0);
  opacity: 1;
  transition: transform 0.22s cubic-bezier(0.22, 0.61, 0.36, 1), opacity 0.18s ease;
}

/* Pull spinner only during user refresh — never over app-open skeleton */
#page-home.home-loading:not([data-home-refresh="1"]) #home-loader-after-tags.home-pull-loader {
  display: none !important;
  visibility: hidden !important;
}

#page-home[data-home-refresh="1"] #home-loader-after-tags.home-pull-loader.is-refreshing {
  display: flex !important;
  z-index: 12;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  transform: translateY(0) !important;
  opacity: 1 !important;
}

.home-section-loader:not(#home-loader-after-tags) {
  display: none !important;
}

.home-section-loader[hidden] {
  display: none !important;
}

/* Page-end scroll loader — overlay at bottom, does not change scroll height */
.home-scroll-load {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0;
  min-height: 0;
  width: 100%;
  flex-shrink: 0;
  pointer-events: none;
  z-index: 4;
}

.home-scroll-load[hidden] {
  display: none !important;
}

.home-ios-spinner {
  position: relative;
  width: 36px;
  height: 36px;
}

.home-ios-spinner span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 9px;
  margin-left: -1.5px;
  margin-top: -14px;
  border-radius: 2px;
  background: #c62828;
  transform-origin: center 14px;
  opacity: 0.15;
  animation: home-spinner-bar 1s linear infinite;
}

.home-ios-spinner span:nth-child(1)  { transform: rotate(0deg);   animation-delay: -0.916s; }
.home-ios-spinner span:nth-child(2)  { transform: rotate(30deg);  animation-delay: -0.833s; }
.home-ios-spinner span:nth-child(3)  { transform: rotate(60deg);  animation-delay: -0.75s; }
.home-ios-spinner span:nth-child(4)  { transform: rotate(90deg);  animation-delay: -0.666s; }
.home-ios-spinner span:nth-child(5)  { transform: rotate(120deg); animation-delay: -0.583s; }
.home-ios-spinner span:nth-child(6)  { transform: rotate(150deg); animation-delay: -0.5s; }
.home-ios-spinner span:nth-child(7)  { transform: rotate(180deg); animation-delay: -0.416s; }
.home-ios-spinner span:nth-child(8)  { transform: rotate(210deg); animation-delay: -0.333s; }
.home-ios-spinner span:nth-child(9)  { transform: rotate(240deg); animation-delay: -0.25s; }
.home-ios-spinner span:nth-child(10) { transform: rotate(270deg); animation-delay: -0.166s; }
.home-ios-spinner span:nth-child(11) { transform: rotate(300deg); animation-delay: -0.083s; }
.home-ios-spinner span:nth-child(12) { transform: rotate(330deg); animation-delay: 0s; }

@keyframes home-spinner-bar {
  0% { opacity: 1; }
  100% { opacity: 0.15; }
}

/* Fade-in loaded sections — disabled during batch swap to prevent jump */
.home-loaded-block.home-reveal {
  animation: home-fade-in 0.3s ease forwards;
}

#page-home.home-load-finishing .home-loaded-block.home-reveal {
  animation: none !important;
}

/* Stable banner slot during home-loading (skeleton + content same flow height) */
#page-home.home-loading #home-sk-banner:not(.home-sk-hidden),
#page-home.home-loading #home-content-banner.home-reveal {
  min-height: calc(var(--hero-banner-h, 160px) + 32px);
}

/* Inline card skeletons inside revealed sections */
.home-card-sk {
  pointer-events: none;
}

.home-tags-scroll .home-sk-pill.home-card-sk {
  flex-shrink: 0;
  display: inline-block;
}

.category-scroll .home-sk-cat-item.home-card-sk {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.restaurant-scroll .home-sk-rest-card.home-card-sk {
  flex-shrink: 0;
  width: 170px;
  min-width: 170px;
}

@media (min-width: 480px) {
  .restaurant-scroll .home-sk-rest-card.home-card-sk {
    width: 200px;
    min-width: 200px;
  }
}

.product-scroll .home-sk-product-card.home-card-sk {
  min-width: 0;
}

#page-home.home-loading .home-loaded-block.home-reveal .home-card-sk {
  display: block;
}

#page-home.home-loading .category-scroll .home-sk-cat-item.home-card-sk {
  display: flex;
}

#page-home.home-loading .restaurant-scroll .home-sk-rest-card.home-card-sk {
  display: block;
}

@keyframes home-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ===== Page navigation loader (clone of home scroll-end spinner) ===== */
.page {
  position: relative;
}

.page-nav-loader-global {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  min-height: 0;
  background: transparent;
  pointer-events: none;
}

.page-nav-loader-global.page-nav-loader-in-page {
  position: absolute;
  left: 0;
  right: 0;
  width: auto;
  background: rgba(255, 255, 255, 0.72);
}

.page-nav-loader-global[hidden] {
  display: none !important;
}

body.page-nav-loading-active .page-nav-loader-global {
  display: flex !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

.page.page-nav-loading > .page-nav-body-load {
  opacity: 0 !important;
  pointer-events: none !important;
}

.page.page-nav-loading > .page-nav-header-keep {
  opacity: 1 !important;
  pointer-events: auto !important;
}

.page.page-nav-reveal > .page-nav-body-load {
  animation: home-fade-in 0.32s ease forwards;
}

@media (min-width: 768px) {
  .home-sk-rest-card {
    width: 200px;
  }

  .home-sk-rest-img {
    height: 110px;
  }
}
