/**
 * سامانه مدیریت انبار و حسابداری هوشمند
 * استایل‌های پایه، متغیرهای CSS، تم تاریک/روشن و چیدمان ریسپانسیو (style.css)
 * طراحی Mobile-First با الهام از استانداردهای مدرن iOS و Material 3
 */

:root {
  /* پالت رنگی اختصاصی تم روشن */
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-hover: #e2e8f0;
  --bg-glass: rgba(255, 255, 255, 0.88);

  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --border-color: #e2e8f0;
  --border-subtle: #cbd5e1;
  --border-focus: #3b82f6;

  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #eff6ff;
  --color-primary-border: #bfdbfe;

  --color-success: #10b981;
  --color-success-hover: #059669;
  --color-success-light: #ecfdf5;
  --color-success-border: #a7f3d0;

  --color-warning: #f59e0b;
  --color-warning-hover: #d97706;
  --color-warning-light: #fffbeb;
  --color-warning-border: #fde68a;

  --color-danger: #ef4444;
  --color-danger-hover: #dc2626;
  --color-danger-light: #fef2f2;
  --color-danger-border: #fecaca;

  --color-purple: #8b5cf6;
  --color-purple-light: #f5f3ff;

  /* ابعاد و حاشیه‌های امن */
  --header-height: 60px;
  --bottom-nav-height: 66px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  /* گوشه‌ها و سایه‌ها */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 24px -4px rgba(15, 23, 42, 0.12), 0 4px 12px -2px rgba(15, 23, 42, 0.06);
  --shadow-fab: 0 10px 25px -3px rgba(37, 99, 235, 0.4), 0 4px 10px -2px rgba(37, 99, 235, 0.2);

  --font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --transition-fast: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-normal: 260ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* پالت رنگی غنی و چشم‌نواز تم تاریک (Dark Mode) */
[data-theme="dark"] {
  --bg-primary: #090d16;
  --bg-surface: #111827;
  --bg-subtle: #1f2937;
  --bg-hover: #374151;
  --bg-glass: rgba(17, 24, 39, 0.88);

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-inverse: #090d16;

  --border-color: #1f2937;
  --border-subtle: #374151;
  --border-focus: #60a5fa;

  --color-primary: #3b82f6;
  --color-primary-hover: #60a5fa;
  --color-primary-light: #1e3a8a;
  --color-primary-border: #1e40af;

  --color-success: #10b981;
  --color-success-hover: #34d399;
  --color-success-light: #064e3b;
  --color-success-border: #065f46;

  --color-warning: #f59e0b;
  --color-warning-hover: #fbbf24;
  --color-warning-light: #78350f;
  --color-warning-border: #92400e;

  --color-danger: #ef4444;
  --color-danger-hover: #f87171;
  --color-danger-light: #7f1d1d;
  --color-danger-border: #991b1b;

  --color-purple: #a855f7;
  --color-purple-light: #581c87;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 14px -2px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 14px 28px -4px rgba(0, 0, 0, 0.55);
  --shadow-fab: 0 10px 25px -3px rgba(59, 130, 246, 0.45);
}

/* ریست و پایه‌های تایپوگرافی */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-family: var(--font-family);
  direction: rtl;
  text-align: right;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.55;
  font-size: 14.5px;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  background-color: var(--bg-primary);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.modal-open {
  overflow: hidden;
}

/* لودر اولیه بسیار شیک */
.app-loader {
  position: fixed;
  inset: 0;
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.loader-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--bg-subtle);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.75s cubic-bezier(0.68, -0.55, 0.27, 1.55) infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loader-text {
  margin-top: 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: -0.01em;
}

/* اسکلت کلی اپلیکیشن */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 840px;
  margin: 0 auto;
  position: relative;
  background-color: var(--bg-primary);
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.04);
}

/* هدر ثابت با افکت گلس‌مورفیسم */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-height);
  background-color: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  padding-top: var(--safe-top);
  box-shadow: var(--shadow-sm);
  transition: background-color var(--transition-fast);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo-icon {
  font-size: 1.6rem;
  filter: drop-shadow(0 2px 4px rgba(37, 99, 235, 0.2));
}

.header-title-box {
  display: flex;
  flex-direction: column;
}

.header-app-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.25;
}

.header-page-title {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ناوبری مخصوص دسکتاپ و تبلت عریض */
.desktop-nav-links {
  display: none;
  align-items: center;
  gap: 6px;
}

.desktop-nav-link {
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.desktop-nav-link:hover {
  background-color: var(--bg-subtle);
  color: var(--text-primary);
}

.desktop-nav-link.nav-active {
  background-color: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: 800;
}

@media (min-width: 769px) {
  .desktop-nav-links {
    display: flex;
  }
  .bottom-nav {
    display: none !important;
  }
  .app-main {
    padding-bottom: 32px !important;
  }
  .fab-btn {
    bottom: 28px !important;
  }
}

/* محتوای اصلی صفحات */
.app-main {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 24px);
}

.page-content {
  width: 100%;
}

.page-header-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.page-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.015em;
}

/* نوار تب‌بار پایین صفحه با گلس‌مورفیسم */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 840px;
  margin: 0 auto;
  height: calc(var(--bottom-nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background-color: var(--bg-glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 60;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.04);
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text-muted);
  height: 100%;
  transition: all var(--transition-fast);
  padding: 6px 0;
  position: relative;
}

.bottom-nav-item:active {
  transform: scale(0.92);
}

.nav-icon {
  font-size: 1.4rem;
  line-height: 1.2;
  margin-bottom: 2px;
  transition: transform var(--transition-fast);
}

.nav-label {
  font-size: 11px;
  font-weight: 500;
}

.bottom-nav-item.nav-active {
  color: var(--color-primary);
  font-weight: 800;
}

.bottom-nav-item.nav-active .nav-icon {
  transform: translateY(-2px) scale(1.1);
}

.bottom-nav-item.nav-active::before {
  content: '';
  position: absolute;
  top: 0;
  width: 28px;
  height: 3px;
  background-color: var(--color-primary);
  border-radius: 0 0 4px 4px;
}

/* دکمه شناور FAB */
.fab-btn {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 16px);
  left: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 300;
  line-height: 1;
  box-shadow: var(--shadow-fab);
  cursor: pointer;
  z-index: 70;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.fab-btn:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 14px 30px -4px rgba(37, 99, 235, 0.5);
}

.fab-btn:active {
  transform: scale(0.92) rotate(90deg);
}

@media (min-width: 841px) {
  .fab-btn {
    left: calc(50% - 420px + 24px);
  }
}

/* شبکه کارت‌های آماری (Stats Grid) */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

@media (min-width: 600px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-icon-blue { background-color: var(--color-primary-light); color: var(--color-primary); }
.stat-icon-green { background-color: var(--color-success-light); color: var(--color-success); }
.stat-icon-purple { background-color: var(--color-purple-light); color: var(--color-purple); }
.stat-icon-red { background-color: var(--color-danger-light); color: var(--color-danger); }

.stat-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.stat-value {
  font-size: 15.5px;
  font-weight: 800;
  color: var(--text-primary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.stat-value small {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

/* چیپ‌های افقی دسته‌بندی با اسکرول نرم */
.categories-chips-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 12px 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.categories-chips-scroll::-webkit-scrollbar {
  display: none;
}

.chip-item {
  flex-shrink: 0;
  padding: 7px 15px;
  border-radius: var(--radius-full);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chip-item:hover {
  background-color: var(--bg-hover);
}

.chip-item.chip-active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

/* شبکه محصولات و کارت‌ها */
.products-subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 12.5px;
}

.products-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 580px) {
  .products-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.product-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 15px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.product-card:hover {
  border-color: var(--color-primary-border);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.product-card-head {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.product-thumb {
  width: 68px;
  height: 68px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.product-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-img-placeholder {
  font-size: 2rem;
}

.product-head-details {
  flex: 1;
  min-width: 0;
}

.product-category-tag {
  font-size: 11px;
  color: var(--color-primary);
  font-weight: 700;
  display: inline-block;
  margin-bottom: 2px;
}

.product-title {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-codes {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.product-code-pill {
  font-size: 11px;
  background-color: var(--bg-subtle);
  padding: 2px 7px;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  font-weight: 500;
}

.product-price-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  background-color: var(--bg-subtle);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}

.price-item {
  display: flex;
  flex-direction: column;
}

.price-label {
  font-size: 11px;
  color: var(--text-muted);
}

.price-value {
  font-size: 13.5px;
}

.product-stock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.stock-pill {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  gap: 6px;
}

.stock-badge-ok {
  background-color: var(--color-success-light);
  color: var(--color-success);
}

.stock-badge-low {
  background-color: var(--color-warning-light);
  color: var(--color-warning);
}

.stock-badge-out {
  background-color: var(--color-danger-light);
  color: var(--color-danger);
}

.min-stock-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.product-card-footer {
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
}

/* استایل جدول‌ها */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: right;
}

.data-table th {
  background-color: var(--bg-subtle);
  padding: 11px 14px;
  font-weight: 700;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.data-table tr:last-child td {
  border-bottom: none;
}

.table-row-clickable {
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.table-row-clickable:hover {
  background-color: var(--bg-subtle);
}

/* نوار جستجو */
.search-bar-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-input-box {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  right: 14px;
  font-size: 15px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 44px;
  padding: 0 40px 0 38px;
  border-radius: var(--radius-md);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13.5px;
  transition: all var(--transition-fast);
}

.search-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

.search-clear-btn {
  position: absolute;
  left: 12px;
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}

/* انیمیشن‌ها */
.animate-fade-in {
  animation: fadeIn 220ms ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-slide-down {
  animation: slideDown 260ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideDown {
  from { opacity: 0; transform: translate(-50%, -18px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.animate-slide-up {
  animation: slideUp 260ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

/* تایم‌لاین کاردکس کالا */
.timeline {
  position: relative;
  padding-right: 20px;
  border-right: 2px solid var(--border-color);
  margin-top: 14px;
}

.timeline-item {
  position: relative;
  margin-bottom: 16px;
}

.timeline-dot {
  position: absolute;
  right: -26px;
  top: 5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--text-muted);
}

.timeline-in .timeline-dot { background-color: var(--color-success); }
.timeline-out .timeline-dot { background-color: var(--color-danger); }
.timeline-adjust .timeline-dot { background-color: var(--color-warning); }

.timeline-content {
  background-color: var(--bg-subtle);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  margin-bottom: 4px;
}

.timeline-tag {
  font-weight: 700;
}

.timeline-in .timeline-tag { color: var(--color-success); }
.timeline-out .timeline-tag { color: var(--color-danger); }
.timeline-adjust .timeline-tag { color: var(--color-warning); }

.timeline-date {
  font-size: 11px;
  color: var(--text-muted);
}

.timeline-body {
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* دسته‌بندی درختی */
.categories-list {
  display: flex;
  flex-direction: column;
}

.category-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-color);
  transition: background-color var(--transition-fast);
}

.category-row:hover {
  background-color: var(--bg-subtle);
}

.category-row.level-1 {
  padding-right: 36px;
  background-color: rgba(0, 0, 0, 0.015);
}

.category-row.level-2 {
  padding-right: 58px;
}

.category-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.category-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* اکشن شیت */
.quick-action-sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.quick-action-backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}

.quick-action-content {
  position: relative;
  background-color: var(--bg-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px;
  padding-bottom: calc(24px + var(--safe-bottom));
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
