/* assets/css/layout.css */
/* Scope: containers + layout helpers (no colors, no components) */

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-4);
}
.container--narrow {
  max-width: 820px;
}
/* page shell */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.content {
  flex: 1;
}

/* keep content clear of bottom nav on mobile */
.safe-bottom {
  padding-bottom: calc(var(--space-6) + 72px);
}
/* vertical rhythm */
.stack > * + * {
  margin-top: var(--space-4);
}
.stack--sm > * + * {
  margin-top: var(--space-3);
}

.stack--lg > * + * {
  margin-top: var(--space-5);
}
/* horizontal row helper */
.row {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}
.row--nowrap {
  flex-wrap: nowrap;
}

.row--wrap {
  flex-wrap: wrap;
}
/* two-side layout (label/value, title/actions, etc.) */
.spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

/* responsive safety for mobile */
@media (max-width: 640px) {
  .container {
    padding: var(--space-3);
    /* جلوگیری از رفتن محتوا زیر bottom nav */
    padding-bottom: calc(var(--space-6) + 50px + env(safe-area-inset-bottom));
  }

  .row {
    flex-wrap: wrap;
  }

  .spread {
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .spread > * {
    width: 100%;
  }
}

/* App-shell pages handle bottom spacing via #app-content padding */
html.has-app-shell .container {
  padding-bottom: var(--space-4);
}
@media (max-width: 640px) {
  html.has-app-shell .container {
    padding-bottom: var(--space-3);
  }
}

/* -----------------------------
   App Shell + Soft Navigation
----------------------------- */
:root {
  --app-vh: 100vh;
  --app-nav-h: 0px;
  --app-nav-guard: 6px;
}

html.keyboard-open {
  --app-nav-h: 0px;
  --app-nav-guard: 0px;
}

@media (max-width: 900px) {
  :root {
    --app-nav-h: 72px;
  }
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Smooth zoom snap-back hint (app pages only) */
html.has-app-shell body {
  transition: opacity 0.2s ease;
}
html.zoom-resetting body {
  opacity: 0.98;
}

#app-content {
  flex: 1 1 auto;
  min-height: 0;
}

.app-shell.is-loading #app-content {
  opacity: 0.6;
  filter: saturate(0.96);
  transition: opacity 0.18s ease, filter 0.18s ease;
  pointer-events: none;
}

.app-shell.is-skeleton-active #app-content {
  opacity: 1;
  filter: none;
  pointer-events: none;
}

.app-soft-skeleton {
  position: absolute;
  inset: calc(var(--app-head-h, 0px) + 8px) 12px calc(var(--app-nav-h, 0px) + var(--app-nav-guard, 0px) + 12px) 12px;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.12s ease, transform 0.12s ease;
  display: grid;
  gap: 10px;
}

.app-soft-skeleton.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.app-soft-skeleton__block {
  border-radius: 14px;
  min-height: 16px;
  background: linear-gradient(90deg, rgba(240, 237, 228, 0.94), rgba(255, 255, 255, 0.95), rgba(240, 237, 228, 0.94));
  background-size: 220% 100%;
  animation: appSkeletonShimmer 1.1s linear infinite;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.app-soft-skeleton__block--hero {
  min-height: 86px;
}

.app-soft-skeleton__block--item {
  min-height: 56px;
}

.app-soft-skeleton__block--line {
  min-height: 14px;
  width: 72%;
}

.app-soft-skeleton__block--line-sm {
  min-height: 12px;
  width: 46%;
}

.app-soft-skeleton--list .app-soft-skeleton__block--line-sm {
  width: 56%;
}

.app-soft-skeleton--form .app-soft-skeleton__block--item {
  min-height: 48px;
}

.app-soft-skeleton--home .app-soft-skeleton__block--hero {
  min-height: 98px;
}

.app-soft-skeleton--ios-lite {
  gap: 8px;
}

.app-soft-skeleton--ios-lite .app-soft-skeleton__block {
  animation: none;
  background: rgba(243, 239, 229, 0.96);
  background-size: 100% 100%;
}

.app-soft-skeleton--ios-lite .app-soft-skeleton__block--hero {
  min-height: 72px;
}

.app-soft-skeleton--ios-lite .app-soft-skeleton__block--item {
  min-height: 46px;
}

.app-soft-skeleton--ios-lite .app-soft-skeleton__block--line {
  width: 68%;
}

.app-soft-skeleton--ios-lite .app-soft-skeleton__block--line-sm {
  width: 42%;
}

@keyframes appSkeletonShimmer {
  from { background-position: 100% 0; }
  to { background-position: -120% 0; }
}

#app-soft-body.is-soft-enter {
  animation: appContentFade 0.18s ease-out;
}

@keyframes appContentFade {
  from { opacity: 0.6; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

html.has-app-shell,
html.has-app-shell body {
  height: var(--app-vh, 100vh);
  overflow: hidden;
}

html.has-app-shell .app-shell {
  height: 100%;
}

html.has-app-shell #app-content {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding-bottom: calc(var(--app-nav-h, 0px) + var(--app-nav-guard, 0px) + var(--app-kb-h, 0px));
  scroll-padding-bottom: calc(var(--app-nav-h, 0px) + var(--app-nav-guard, 0px) + var(--app-kb-h, 0px));
  overscroll-behavior: contain;
}

/* Keyboard open (iOS): avoid gray overlay by letting body scroll */
html.has-app-shell.keyboard-open,
html.has-app-shell.keyboard-open body {
  height: var(--app-vh, 100vh);
  overflow: hidden;
}

html.has-app-shell.keyboard-open #app-content {
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  overscroll-behavior: contain;
  padding-bottom: calc(var(--app-kb-h, 0px) + env(safe-area-inset-bottom));
  scroll-padding-bottom: calc(var(--app-kb-h, 0px) + env(safe-area-inset-bottom));
}

/* Animate only dynamic body; keep scroll container stable (iOS guard) */
html.has-app-shell #app-soft-body.is-soft-enter {
  animation: appContentFadeNoMove 0.18s ease-out;
}

@keyframes appContentFadeNoMove {
  from { opacity: 0.6; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .app-soft-skeleton,
  .app-shell.is-loading #app-content,
  html.has-app-shell #app-soft-body.is-soft-enter {
    transition: none !important;
    animation: none !important;
  }
  .app-soft-skeleton__block {
    animation: none !important;
    background: rgba(243, 239, 229, 0.96);
  }
}

/* Fallback: if content scroll is locked, allow body scrolling */
html.has-app-shell.force-body-scroll,
html.has-app-shell.force-body-scroll body {
  overflow: auto;
  height: auto;
}

html.has-app-shell.force-body-scroll .app-shell {
  height: auto;
  min-height: var(--app-vh, 100vh);
}

html.has-app-shell.force-body-scroll #app-content {
  overflow: visible;
  height: auto;
  overscroll-behavior: auto;
}
