/* Motion — انتقال صفحات و تعاملات UI */

/* فضای ثابت اسکرول‌بار — جلوگیری از جابجایی layout هنگام تعویض صفحه */
html {
  scrollbar-gutter: stable;
}

@supports not (scrollbar-gutter: stable) {
  html {
    overflow-y: scroll;
  }
}

html.is-scroll-locked,
html.is-scroll-locked body {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ——— SPA page transition ——— */
#app-content,
#app-header-wrap {
  will-change: opacity, transform;
}

#app-content.page-enter-done,
#app-header-wrap.page-enter-done {
  will-change: auto;
  transform: none !important;
}

.page-exit {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.page-exit.page-exit-active {
  opacity: 0;
  transform: translateY(-8px);
}

.page-enter {
  opacity: 0;
  transform: translateY(10px);
}

.page-enter.page-enter-active {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.38s ease, transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
}

.page-loading {
  opacity: 0.45;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

/* ——— Staggered list / cards ——— */
@keyframes ui-fade-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ui-stagger > * {
  opacity: 0;
  animation: ui-fade-up 0.42s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.ui-stagger > *:nth-child(1) { animation-delay: 0ms; }
.ui-stagger > *:nth-child(2) { animation-delay: 40ms; }
.ui-stagger > *:nth-child(3) { animation-delay: 80ms; }
.ui-stagger > *:nth-child(4) { animation-delay: 120ms; }
.ui-stagger > *:nth-child(5) { animation-delay: 160ms; }
.ui-stagger > *:nth-child(6) { animation-delay: 200ms; }
.ui-stagger > *:nth-child(7) { animation-delay: 240ms; }
.ui-stagger > *:nth-child(8) { animation-delay: 280ms; }
.ui-stagger > *:nth-child(9) { animation-delay: 320ms; }
.ui-stagger > *:nth-child(10) { animation-delay: 360ms; }
.ui-stagger > *:nth-child(n+11) { animation-delay: 400ms; }

/* بدون انیمیشن stagger روی بار اول — جلوگیری از پرش */
.ui-stagger-noanim > * {
  opacity: 1;
  animation: none;
}

/* ——— Form sheet (teleport to body — بدون تأثیر transform والد) ——— */
.js-form-sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
}

.js-form-sheet .sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.28s ease;
}

.js-form-sheet.sheet-open .sheet-backdrop {
  opacity: 1;
}

.js-form-sheet .sheet-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 90vh;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #E5E7EB;
  border-radius: 1rem 1rem 0 0;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transform: translateY(100%);
  transition: opacity 0.3s ease, transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
}

@media (min-width: 640px) {
  .js-form-sheet .sheet-panel {
    bottom: auto;
    top: 50%;
    left: 50%;
    right: auto;
    width: 100%;
    max-width: 32rem;
    transform: translate(-50%, calc(-50% + 20px)) scale(0.97);
    border-radius: 1rem;
  }
}

.js-form-sheet.sheet-open .sheet-panel {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 640px) {
  .js-form-sheet.sheet-open .sheet-panel {
    transform: translate(-50%, -50%) scale(1);
  }
}

.inv-edit-btn {
  margin-top: 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-height: 2.25rem;
  padding: 0 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid #E5E7EB;
  border-radius: 0.375rem;
  color: #8B6914;
  background: #fff;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.inv-edit-btn:hover {
  background: rgba(184, 134, 11, 0.1);
  border-color: #B8860B;
}
.view-mode-toggle {
  display: inline-flex;
  padding: 3px;
  background: #FAF8F5;
  border: 1px solid #E5E7EB;
  border-radius: 0.625rem;
  gap: 2px;
}

.view-mode-toggle .js-view-mode {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  min-height: 2.25rem;
  padding: 0 0.625rem;
  border: none;
  border-radius: 0.5rem;
  background: transparent;
  color: #6B7280;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.view-mode-toggle .js-view-mode.is-active {
  background: #fff;
  color: #8B6914;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.view-mode-toggle .js-view-mode:hover:not(.is-active) {
  color: #1A1A1A;
}

/* ——— Dashboard charts ——— */
.chart-bar-row {
  display: grid;
  grid-template-columns: 3.5rem 1fr auto;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 0.625rem;
}

.chart-bar-label {
  font-size: 0.75rem;
  color: #6B7280;
  text-align: right;
}

.chart-bar-track {
  height: 0.5rem;
  background: #FAF8F5;
  border-radius: 9999px;
  overflow: hidden;
}

.chart-bar-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.chart-bar-value {
  font-size: 0.75rem;
  font-weight: 600;
  color: #8B6914;
  min-width: 4rem;
  text-align: left;
}

.chart-donut-wrap {
  position: relative;
  width: 9rem;
  height: 9rem;
  margin: 0 auto 1rem;
}

.chart-donut-svg {
  width: 100%;
  height: 100%;
}

.chart-donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-donut-total {
  font-size: 0.875rem;
  font-weight: 700;
  color: #8B6914;
}

.chart-legend {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.chart-legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
}

.chart-legend-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  flex-shrink: 0;
}

.chart-legend-label {
  flex: 1;
  color: #6B7280;
}

.chart-legend-val {
  font-weight: 600;
  color: #1A1A1A;
}

/* ——— Navigation ——— */
.nav-item {
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.nav-item:hover {
  transform: translateX(-2px);
}

.nav-item.is-active {
  transform: none;
}

.mobile-nav-item {
  transition: color 0.2s ease, transform 0.2s ease;
}

.mobile-nav-item:active {
  transform: scale(0.94);
}

/* ——— Interactive cards ——— */
.ui-card {
  transition: border-color 0.2s ease, box-shadow 0.25s ease, transform 0.25s ease;
}

.ui-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
}

/* ——— Buttons ——— */
.ui-press {
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.ui-press:active {
  transform: scale(0.97);
}

/* ——— User menu dropdown ——— */
#app-user-menu {
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

#app-user-menu.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

#app-user-menu.hidden {
  display: none !important;
}

#app-user-menu:not(.hidden) {
  display: block;
}
