/* =========================================================
   سامانه مدیریت کارخانه - استایل اصلی
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap');

:root {
  --color-primary: #0071e3;
  --color-primary-dark: #0077ed;
  --color-primary-light: #e8f2fd;
  --color-success: #34c759;
  --color-success-light: #e5f9ec;
  --color-warning: #ff9f0a;
  --color-warning-light: #fff4e0;
  --color-danger: #ff3b30;
  --color-danger-light: #ffe9e7;
  --color-info: #0891b2;
  --color-info-light: #cffafe;
  --color-purple: #7c3aed;
  --color-purple-light: #ede9fe;

  --bg-body: #f5f5f7;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --text-main: #1d1d1f;
  --text-muted: #6e6e73;
  --border-color: #d2d2d7;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.12);

  --sidebar-width: 260px;
  --topbar-height: 60px;

  /* -------- توکن‌های تکمیلی Design System (افزایشی - هیچ‌کدام از موارد بالا حذف نشده) -------- */

  /* فاصله‌گذاری: مقیاس استاندارد برای margin/padding صفحات و Componentهای جدید */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* تایپوگرافی: اندازه فونت (اعداد قبلی مثل 15px/13.5px در قوانین موجود دست‌نخورده باقی مانده‌اند) */
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14.5px;
  --text-md: 15px;
  --text-lg: 16px;
  --text-xl: 19px;
  --text-2xl: 24px;

  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
  --font-extrabold: 800;

  --radius-lg: 16px;
  --radius-full: 999px;

  --text-subtle: #aeaeb2;
  --text-inverse: #ffffff;
  --border-color-strong: #c7c7cc;

  /* -------- Branding/Theme (Stage: Branding) --------
     این دو متغیر جدید، هدف مستقیم رنگ‌های «ثانویه» و «تأکیدی» Theme هستند.
     مقدار پیش‌فرض اینجا دقیقاً باید با DEFAULT_THEME.colors در server.js
     یکی باشد؛ در Runtime توسط applyTheme() در app.js Override می‌شود. */
  --color-secondary: #6e6e73;
  --color-accent: #0071e3;
  /* -------- Branding گسترش‌یافته: سایدبار/تاپبار/منوی فعال -------- */
  --bg-topbar: #fbfbfd;
  --text-sidebar: #424245;
  --text-topbar: #1d1d1f;
  --color-menu-active: #0071e3;
}

/* =========================================================
   Dark Mode - فقط زیرساخت (غیرفعال، هیچ Toggle ای به آن وصل نیست)
   =========================================================
   با افزودن data-theme="dark" به <html> (که فعلاً هیچ‌جا انجام نمی‌شود)
   این مقادیر جایگزین می‌شوند. برای فعال‌سازی واقعی در آینده، کافی است:
   ۱) یک کلید ذخیره ترجیح کاربر (localStorage یا فیلد کاربر) اضافه شود
   ۲) در app.js: document.documentElement.setAttribute('data-theme','dark')
   هیچ تغییر دیگری در معماری لازم نیست. */
html[data-theme="dark"] {
  --bg-body: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #0b1120;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --border-color: #334155;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  background: var(--bg-body);
  color: var(--text-main);
  direction: rtl;
  font-size: 15px;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ================= صفحه ورود ================= */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-body);
  padding: 16px;
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 26px 26px 22px;
  width: 100%;
  max-width: 360px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  text-align: center;
  margin: auto 0;
  border: 1px solid var(--border-color);
}

.login-logo { font-size: 64px; margin-bottom: 4px; }
.login-logo img { max-height: 150px; max-width: 100%; }

.sidebar-logo {
  text-align: center;
  font-size: 26px;
  padding: var(--space-4) 0 var(--space-2);
}
.sidebar-logo img { max-height: 150px; max-width: 80%; }

.login-card h1 { font-size: 18px; margin: 0 0 2px; }

.login-sub { color: var(--text-muted); margin: 0 0 16px; font-size: 13px; }

.login-card form { text-align: right; }

#login-form .form-group { margin-bottom: 8px; }
#login-form button[type="submit"] { margin-top: 2px; }
.remember-row { margin-bottom: 8px; }
.remember-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  margin-bottom: 0;
}
.remember-label input { width: auto; }
.remember-label input[type="checkbox"] {
  width: auto;
  flex-shrink: 0;
  padding: 0;
  border: none;
  margin: 0;
  accent-color: var(--color-primary);
}
.login-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 12px;
  margin: 14px 0 10px;
}
.login-divider::before, .login-divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--border-color);
}
#fingerprint-login-btn { margin-top: 0; }
.fp-hint { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 10px; line-height: 1.9; }

.password-wrap { position: relative; }
.password-wrap input { width: 100%; padding-left: 42px; }
.password-toggle {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  font-size: 17px;
  line-height: 1;
  padding: 4px 6px;
  opacity: 0.65;
}
.password-toggle:hover { opacity: 1; }
.caps-hint { font-size: 12px; color: #b45309; margin-top: 6px; }
.btn-loading { opacity: 0.7; pointer-events: none; }

/* ================= فرم‌ها ================= */

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-main);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  background: #fff;
  transition: border-color .15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.form-group textarea { resize: vertical; min-height: 80px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
}

.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ================= دکمه‌ها ================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 14px;
  font-weight: 600;
  transition: filter .15s, transform .1s;
  min-height: 40px;
}

.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }

.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { filter: brightness(1.08); }

.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }

.btn-warning { background: var(--color-warning); color: #fff; }
.btn-warning:hover { filter: brightness(1.08); }

.btn-secondary { background: #e2e8f0; color: var(--text-main); border: 1.5px solid var(--color-secondary); }
.btn-secondary:hover { filter: brightness(0.97); }

.btn-ghost { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,0.25); }

.btn-sm { padding: 6px 12px; min-height: 32px; font-size: 13px; }

.btn-block { width: 100%; }

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ================= آلارم / پیام ================= */

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 14px;
}
.alert-error { background: var(--color-danger-light); color: #991b1b; }
.alert-success { background: var(--color-success-light); color: #166534; }
.alert-info { background: var(--color-info-light); color: #155e75; }

/* ================= چیدمان اصلی ================= */

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

.topbar {
  height: var(--topbar-height);
  background: var(--bg-topbar);
  color: var(--text-topbar);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow);
  border-bottom: 1px solid var(--border-color);
}
.topbar .btn-ghost { border-color: var(--border-color); }

.topbar-title { font-weight: 700; font-size: 16px; flex: 1; }

.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }

.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: transparent;
  border: none;
  width: 36px;
  height: 36px;
}
.hamburger-btn span {
  display: block;
  height: 2.5px;
  width: 100%;
  background: var(--text-topbar);
  border-radius: 2px;
}

.app-body { flex: 1; display: flex; min-height: calc(100vh - var(--topbar-height)); }

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  flex-shrink: 0;
  padding: 14px 0;
  overflow-y: auto;
  border-left: 1px solid var(--border-color);
}

.menu-list { list-style: none; margin: 0; padding: 0; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  margin: 1px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  transition: background .15s;
}
.menu-item:hover { background: rgba(0, 0, 0, 0.045); }
.menu-item.active {
  background: color-mix(in srgb, var(--color-menu-active) 12%, transparent);
  color: var(--color-menu-active);
  font-weight: 600;
}
.menu-icon { font-size: 16px; width: 20px; text-align: center; }

.menu-section-label {
  padding: 14px 20px 6px;
  font-size: 11px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ---------- Menu Group (Accordion) - برای ساختار Main Menu مبتنی بر واحدهای سازمانی ---------- */

.menu-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  cursor: pointer;
  font-size: 14px;
  transition: background .15s;
}
.menu-group-header:hover { background: rgba(255,255,255,0.06); }
.menu-group-label { flex: 1; }
.menu-chevron {
  font-size: 10px;
  color: #64748b;
  transition: transform .15s;
}
.menu-group.open .menu-chevron { transform: rotate(-90deg); }

.menu-group-items {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height .2s ease;
}
.menu-group.open .menu-group-items { max-height: 900px; }

.menu-subitem {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px 8px 30px;
  margin: 1px 10px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--text-sidebar);
  cursor: pointer;
  flex-wrap: wrap;
  row-gap: 4px;
}
.menu-subitem:hover:not(.disabled) { background: rgba(0, 0, 0, 0.045); }
.menu-subitem.active {
  background: color-mix(in srgb, var(--color-menu-active) 12%, transparent);
  color: var(--color-menu-active);
  font-weight: 600;
}
.menu-subitem.disabled { color: #aeaeb2; cursor: not-allowed; }

.dev-badge {
  font-size: 10px;
  background: rgba(0, 113, 227, 0.12);
  color: var(--color-primary);
  padding: 2px 6px;
  border-radius: var(--radius-full, 999px);
  white-space: nowrap;
  flex-shrink: 0;
}

.sidebar-overlay {
  display: none;
}

.main-content {
  flex: 1;
  padding: 22px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* ================= کارت‌ها ================= */

.page-title {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}

/* کارت‌های انتخاب فرم عمومی درخواست */
.form-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.form-card {
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 16px;
  background: #f8fafc;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow);
}
.form-card-title { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.form-card-desc { font-size: 12px; color: var(--text-muted); line-height: 1.9; }
.form-card-meta { font-size: 11px; color: var(--text-muted); margin-top: 8px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

@media (max-width: 1000px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  border-right: 4px solid var(--color-primary);
}
.stat-card .stat-value { font-size: 26px; font-weight: 800; }
.stat-card .stat-label { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }

.stat-card.c-success { border-right-color: var(--color-success); }
.stat-card.c-warning { border-right-color: var(--color-warning); }
.stat-card.c-info { border-right-color: var(--color-info); }
.stat-card.c-danger { border-right-color: var(--color-danger); }
.stat-card.c-purple { border-right-color: var(--color-purple); }

/* ================= جدول ================= */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 560px; }

thead th {
  text-align: right;
  padding: 11px 12px;
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12.5px;
  border-bottom: 1.5px solid var(--border-color);
  white-space: nowrap;
}

tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

tbody tr:hover { background: #f8fafc; }

.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ================= Autocomplete مستر کالا (فاز ۳) ================= */

.master-autocomplete {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--color-border, var(--border));
  border-radius: 8px;
  background: var(--color-surface, var(--surface));
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  display: none;
}
.master-autocomplete.open { display: block; }
.master-autocomplete .ac-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}
.master-autocomplete .ac-item:hover { background: rgba(0, 0, 0, 0.04); }
.master-autocomplete .ac-item .ac-code { color: var(--text-muted); font-size: 12px; }
.master-autocomplete .ac-item .ac-kind {
  font-size: 11px;
  background: var(--color-success-light);
  color: #166534;
  padding: 2px 8px;
  border-radius: 12px;
  white-space: nowrap;
}
.master-autocomplete .ac-item .ac-grade {
  margin-left: auto;
  font-size: 11px;
  background: var(--color-purple-light);
  color: #5b21b6;
  padding: 2px 8px;
  border-radius: 12px;
}
.master-autocomplete .ac-item.ac-empty { cursor: default; color: var(--text-muted); font-style: italic; }

/* فیلدهایی که از مستر کالا خودکار پر شده‌اند — غیرقابل ویرایش */
input.locked-by-master {
  background: #f1f5f9;
  color: var(--text-muted);
  font-weight: 600;
}
.form-group { position: relative; }

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ================= Badge وضعیت ================= */

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-pending { background: var(--color-warning-light); color: #92400e; }
.badge-ready { background: var(--color-success-light); color: #166534; }
.badge-referred { background: var(--color-info-light); color: #155e75; }
.badge-approved { background: var(--color-purple-light); color: #5b21b6; }
.badge-rejected { background: var(--color-danger-light); color: #991b1b; }
.badge-active { background: var(--color-success-light); color: #166534; }
.badge-inactive { background: #e2e8f0; color: #475569; }

/* Badgeهای عمومی وضعیت Workflow Engine (Stage 4/5) - برای صفحات آینده Timeline/Instance */
.badge-running { background: var(--color-info-light); color: #155e75; }
.badge-completed { background: var(--color-success-light); color: #166534; }
.badge-correction { background: var(--color-warning-light); color: #92400e; }

/* ================= Modal ================= */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.55);
  display: flex; align-items: flex-start; justify-content: center;
  z-index: 100;
  padding: 24px 16px;
  overflow-y: auto;
}

/* ================= فرم پیشنهاد تأمین‌کننده (استعلام قیمت) ================= */

.inq-sel-supplier { width: 100%; min-width: 200px; }
.inq-custom-supplier { width: 100%; }
.inq-unit-price { width: 110px; }
td.inq-supplier-cell { vertical-align: top; min-width: 240px; }

.modal {
  background: #fff;
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal.modal-wide { max-width: 980px; }

/* فرم‌ساز: پنل ابزار + بوم */
.builder-layout { display: flex; gap: 14px; align-items: flex-start; }
.builder-toolbox {
  flex: 0 0 190px;
  background: #f1f5f9;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px;
  position: sticky;
  top: 0;
}
.builder-toolbox h5 { margin: 0 0 10px; font-size: 13px; }
.builder-tool {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 9px 10px;
  font-size: 12.5px;
  background: #475569;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
}
.builder-tool:hover { background: var(--color-primary); }
.builder-canvas { flex: 1; min-width: 0; }
.builder-canvas .item-row {
  border-style: dashed;
  border-width: 2px;
}
.builder-field-actions { display: flex; gap: 4px; }

/* گرید داینامیک فرم شروع/پیش‌نمایش (نصف‌عرض / تمام‌عرض) */
.dyn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.dyn-full { grid-column: 1 / -1; }
@media (max-width: 640px) { .dyn-grid { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .builder-layout { flex-direction: column; }
  .builder-toolbox { flex: none; width: 100%; position: static; }
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}
.modal-header h3 { margin: 0; font-size: 16px; }

.modal-close {
  background: transparent; border: none; font-size: 22px;
  color: var(--text-muted); line-height: 1;
}

.modal-body { padding: 20px; overflow-y: auto; }

.modal-footer {
  display: flex; gap: 10px; justify-content: flex-start;
  margin-top: 8px;
}

/* ================= آیتم‌های چند-ردیفه فرم درخواست کالا ================= */

.item-row {
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 12px;
  position: relative;
  background: #f8fafc;
}
.item-row-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px; font-weight: 700; font-size: 13px; color: var(--color-primary);
}

/* ================= Toast ================= */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 12px 22px;
  border-radius: 10px;
  font-size: 13.5px;
  z-index: 200;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  text-align: center;
}
.toast.error { background: var(--color-danger); }
.toast.success { background: var(--color-success); }
.toast.info { background: var(--color-info); }

/* ================= واکنش‌گرا: موبایل ================= */

@media (max-width: 768px) {
  .hamburger-btn { display: flex; }

  .sidebar {
    position: fixed;
    top: var(--topbar-height);
    right: 0;
    bottom: 0;
    z-index: 60;
    transform: translateX(100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay.open {
    display: block;
    position: fixed;
    top: var(--topbar-height);
    left: 0; right: 0; bottom: 0;
    background: rgba(15,23,42,0.5);
    z-index: 50;
  }

  .main-content { padding: 14px; }

  .topbar-user span { display: none; }

  .form-row { grid-template-columns: 1fr; }

  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  table { min-width: 0; }
  tbody tr {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    padding: 8px 12px;
  }
  tbody td {
    border-bottom: none;
    padding: 6px 0;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    text-align: left;
  }
  tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    text-align: right;
  }

  /* مودال روی گوشی: تمام‌عرض، دکمه‌های بزرگ */
  .modal-overlay { padding: 10px 8px; }
  .modal-body { padding: 14px; }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer .btn { flex: 1 1 140px; }

  /* جمع جدول (tfoot) هم مثل بدنه، کارتی شود */
  tfoot, tfoot tr, tfoot td { display: block; width: 100%; }
  tfoot td { border-bottom: none; padding: 6px 0; }

  /* ستون عملیات: دکمه‌ها زیر هم و تمام‌عرض */
  tbody td[data-label="عملیات"] { flex-direction: column; align-items: stretch; }
  tbody td[data-label="عملیات"]::before { margin-bottom: 4px; }
  .table-actions .btn { flex: 1 1 auto; }

  /* فرم استعلام روی گوشی از کادر بیرون نزند */
  td.inq-supplier-cell { min-width: 0; }
  .inq-sel-supplier { min-width: 0; }
  .inq-unit-price { width: 100%; }

  /* توپ‌بار جمع‌وجور */
  .topbar { gap: 8px; padding: 0 10px; }
  .topbar-title { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-user { gap: 6px; }

  .page-title { font-size: 16px; }
}

@media (min-width: 769px) {
  .sidebar-overlay { display: none !important; }
}

/* =========================================================
   Design System - Componentهای مشترک برای صفحات آینده
   =========================================================
   این بخش هیچ قانون بالا را تغییر نمی‌دهد؛ فقط Componentهای
   جدید و عمومی اضافه می‌کند تا صفحات آینده (Workflow, Request
   جزئیات، خرید، تعمیرات، Quality و ...) یک زبان بصری مشترک
   داشته باشند. استفاده از این کلاس‌ها اختیاری و تدریجی است؛
   صفحات فعلی بدون این کلاس‌ها هم دقیقاً مثل قبل کار می‌کنند. */

/* ---------- Page Header (عنوان صفحه + زیرعنوان + دکمه‌های عملیات) ---------- */
/* جایگزین اختیاری و غنی‌تر برای .page-title موجود؛ .page-title همچنان معتبر و بدون تغییر است. */

.page-header { margin-bottom: var(--space-5); }

.page-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.page-header-titles h1 {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
}

.page-header-subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.page-header-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ---------- Section Header (عنوان داخل یک Card) ---------- */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.section-header h2,
.section-header h3 {
  margin: 0;
  font-size: var(--text-md);
  font-weight: var(--font-bold);
}

/* ---------- Breadcrumb ---------- */

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.breadcrumb a,
.breadcrumb button.breadcrumb-link {
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}

.breadcrumb a:hover,
.breadcrumb button.breadcrumb-link:hover {
  color: var(--color-primary);
}

.breadcrumb-sep { color: var(--border-color-strong); }

.breadcrumb-current {
  color: var(--text-main);
  font-weight: var(--font-semibold);
}

/* ---------- Search Box ---------- */

.search-box { position: relative; }

.search-box input {
  padding-inline-end: 38px;
}

.search-box .search-icon {
  position: absolute;
  inset-inline-end: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  font-size: 15px;
  pointer-events: none;
}

/* ---------- Select: فلش سفارشی سبک (بدون تغییر رفتار input/textarea موجود) ---------- */

.form-group select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%2364748b'/></svg>");
  background-repeat: no-repeat;
  background-position: left 14px center;
  padding-left: 32px;
}

/* ---------- Pagination ---------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: var(--space-4);
  flex-wrap: wrap;
}

.pagination button {
  min-width: 34px;
  height: 34px;
  border: 1px solid var(--border-color);
  background: #fff;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--text-main);
}

.pagination button:hover:not(:disabled) { background: #f8fafc; }

.pagination button.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--text-inverse);
  font-weight: var(--font-semibold);
}

.pagination button:disabled { opacity: .4; cursor: not-allowed; }

.pagination-info {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-inline-start: var(--space-2);
}

/* ---------- Timeline (برای نمایش Trace/Workflow Events) ---------- */

.timeline {
  position: relative;
  padding-inline-start: 28px;
}

.timeline::before {
  content: '';
  position: absolute;
  inset-inline-start: 9px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--border-color);
}

.timeline-item {
  position: relative;
  padding-bottom: var(--space-5);
}

.timeline-item:last-child { padding-bottom: 0; }

.timeline-dot {
  position: absolute;
  inset-inline-start: -28px;
  top: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--color-accent);
}

.timeline-item.success .timeline-dot { border-color: var(--color-success); }
.timeline-item.danger .timeline-dot { border-color: var(--color-danger); }
.timeline-item.warning .timeline-dot { border-color: var(--color-warning); }

.timeline-time {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.timeline-title {
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  margin: 2px 0;
}

.timeline-desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.timeline-meta {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  font-size: var(--text-xs);
  color: var(--text-subtle);
  margin-top: 4px;
}

/* ---------- Workflow Stepper (نمایش افقی پیشرفت مراحل یک Instance) ---------- */

.workflow-steps {
  display: flex;
  align-items: flex-start;
  gap: 0;
  overflow-x: auto;
  padding: var(--space-2) 0;
}

.workflow-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 96px;
  position: relative;
}

.workflow-step:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 14px;
  inset-inline-start: 50%;
  width: 100%;
  height: 2px;
  background: var(--border-color);
  z-index: 0;
}

.workflow-step .step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: var(--font-bold);
  color: var(--text-muted);
  z-index: 1;
}

.workflow-step .step-label {
  margin-top: 6px;
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-align: center;
}

.workflow-step.done .step-dot { background: var(--color-success); border-color: var(--color-success); color: #fff; }
.workflow-step.current .step-dot { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.workflow-step.rejected .step-dot { background: var(--color-danger); border-color: var(--color-danger); color: #fff; }

/* ---------- Loading State ---------- */

.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--border-color);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  display: inline-block;
  animation: spin .7s linear infinite;
}

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

.loading-block {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: var(--space-8) 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.skeleton {
  background: linear-gradient(90deg, #eef1f5 25%, #e4e8ee 37%, #eef1f5 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-loading {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

.skeleton-line { height: 14px; margin-bottom: 8px; }
.skeleton-line:last-child { width: 70%; }

/* ---------- State Block: حالت عمومی خالی/خطا (نسخه غنی‌تر .empty-state موجود) ---------- */
/* .empty-state قدیمی دست‌نخورده باقی مانده و همچنان کار می‌کند. */

.state-block {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--text-muted);
}

.state-block .state-icon {
  font-size: 34px;
  margin-bottom: var(--space-3);
  opacity: .7;
}

.state-block .state-title {
  font-size: var(--text-md);
  font-weight: var(--font-semibold);
  color: var(--text-main);
  margin-bottom: 4px;
}

.state-block .state-desc {
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}

.state-block.state-error .state-icon { color: var(--color-danger); }

/* ---------- Detail Grid (برای صفحات جزئیات: محتوای اصلی + ستون اطلاعات کناری) ---------- */

.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-5);
  align-items: start;
}

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.detail-meta-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.detail-meta-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-sm);
  padding: 6px 0;
  border-bottom: 1px dashed var(--border-color);
}

.detail-meta-row:last-child { border-bottom: none; }

.detail-meta-label { color: var(--text-muted); }
.detail-meta-value { font-weight: var(--font-semibold); }
/* زنگوله اعلان‌ها */
.notif-bell { position: relative; background: transparent; border: none; font-size: 20px; cursor: pointer; padding: 4px 8px; line-height: 1; }
.notif-badge {
  position: absolute; top: 0; right: 0;
  background: var(--color-danger); color: #fff;
  font-size: 11px; font-weight: 700; min-width: 18px; height: 18px;
  border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.notif-dropdown {
  position: fixed; top: calc(var(--topbar-height) + 6px); left: 12px;
  width: min(370px, 94vw); max-height: 70vh; overflow-y: auto;
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg);
  z-index: 300; padding: 8px;
}
.notif-dropdown h4 { margin: 4px 8px 8px; font-size: 14px; }
.notif-item {
  display: block; width: 100%; text-align: right;
  padding: 9px 10px; border: none; background: transparent;
  border-radius: 8px; cursor: pointer; font-size: 13px; line-height: 1.9;
}
.notif-item:hover { background: #f1f5f9; }
.notif-item small { color: var(--text-muted); }
.notif-empty { padding: 16px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* هایلایت ردیف نیازمند اقدام من */
tbody tr.row-attention { border-right: 3px solid var(--color-warning); background: #fffbeb; }
.attention-badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  background: var(--color-warning); color: #fff;
  border-radius: 10px; padding: 1px 8px; margin-right: 6px; white-space: nowrap;
}
/* کارت‌های داشبورد قابل کلیک */
.stat-clickable { cursor: pointer; transition: transform 0.12s ease, box-shadow 0.12s ease; }
.stat-clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

/* ماتریس دسترسی واحدها */
.perm-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.perm-chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 14px;
  border: 1.5px solid var(--border-color);
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
}
.perm-chip.on {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: #fff;
}

/* -------- تقویم شمسی popup (انتخاب تاریخ بدون تایپ دستی) -------- */
#jalali-picker {
  position: fixed;
  z-index: 9999;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 10px;
  width: 268px;
  font-size: 13px;
  color: var(--text-main);
}
#jalali-picker .jp-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
#jalali-picker .jp-head select { flex: 1; padding: 6px 4px; font-size: 12.5px; }
#jalali-picker .jp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
#jalali-picker .jp-dow { color: var(--text-muted); font-size: 11px; padding: 4px 0; }
#jalali-picker .jp-day {
  padding: 6px 0;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  background: none;
  font: inherit;
  color: inherit;
}
#jalali-picker .jp-day:hover { background: var(--color-primary-light); }
#jalali-picker .jp-day.today { border-color: var(--color-primary); }
#jalali-picker .jp-day.selected { background: var(--color-primary); color: #fff; }
#jalali-picker .jp-foot { display: flex; gap: 6px; justify-content: space-between; margin-top: 8px; }
#jalali-picker .jp-foot .btn { flex: 1; }
input.jdate[readonly] { cursor: pointer; background: #fff; }
