/* ===== متغیرها و پایه (تم تیره، الهام‌گرفته از داشبورد صنعتی با تأکید فیروزه‌ای) ===== */
:root {
  --primary: #14b8a6;
  --primary-light: #2dd4bf;
  --bg: #0a0f1e;
  --surface: #111a2e;
  --surface-2: #1a2540;
  --border: #24304a;
  --text: #e6ebf5;
  --text-muted: #8b96ac;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #38bdf8;
  --radius: 12px;
  --sidebar-w: 250px;
  --shadow: 0 6px 20px rgba(0,0,0,.45), 0 1px 3px rgba(0,0,0,.35);
  --toast-bg: #1c2a45;
  --btn-text: #05221d;
  --glass-blur: none;
  --glass-border-glow: 0 0 rgba(0,0,0,0);
  --input-bg: #0a0f1e;
}

/* ===== تم روشن: شیشه‌ای/گلس‌مورفیسم با تأکید فیروزه‌ای (با دکمه‌ی 🌓 در نوار کناری) ===== */
:root[data-theme="light"] {
  --primary: #0d9488;
  --primary-light: #14b8a6;
  --bg: radial-gradient(1100px 600px at 8% -10%, #ccfbf1 0%, transparent 55%),
        radial-gradient(900px 500px at 100% 0%, #dbeafe 0%, transparent 50%),
        linear-gradient(180deg, #f4f7fc 0%, #eef2fb 100%);
  --surface: rgba(255,255,255,.62);
  --surface-2: rgba(255,255,255,.4);
  --border: rgba(15,23,42,.09);
  --text: #0f172a;
  --text-muted: #5b6579;
  --success: #059669;
  --warning: #b45309;
  --danger: #dc2626;
  --info: #0284c7;
  --shadow: 0 12px 34px rgba(13,148,136,.14), 0 2px 8px rgba(15,23,42,.06);
  --toast-bg: rgba(255,255,255,.9);
  --btn-text: #ffffff;
  --glass-blur: blur(18px) saturate(1.4);
  --glass-border-glow: inset 0 1px 0 rgba(255,255,255,.6);
  --input-bg: rgba(255,255,255,.7);
}
:root[data-theme="light"] body { background-attachment: fixed; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Vazirmatn", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ===== چیدمان اصلی ===== */
#app-shell { display: flex; min-height: 100vh; }

#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-inline-end: 1px solid var(--border);
  color: var(--text);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  z-index: 50;
  transition: transform .25s ease;
}
#sidebar.collapsed { transform: translateX(100%); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 14px;
  border-bottom: 1px solid var(--border);
}
.brand-icon { width: 40px; height: 40px; }
.brand-title { font-weight: 700; font-size: 15px; color: var(--text); }
.brand-sub { font-size: 11px; opacity: .65; color: var(--text-muted); }

#main-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  border-inline-start: 3px solid transparent;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: rgba(20,184,166,.14);
  border-inline-start-color: var(--primary);
  color: var(--primary-light);
  font-weight: 600;
}
.nav-ic { font-size: 17px; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; flex: none; }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.net-online { color: var(--success); font-size: 12px; }
.net-offline { color: var(--danger); font-size: 12px; }

#main-area {
  flex: 1;
  margin-inline-start: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: margin .25s ease;
}
#main-area.expanded { margin-inline-start: 0; }

#topbar {
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  position: sticky;
  top: 0;
  z-index: 40;
}
#page-title { font-size: 17px; margin: 0; white-space: nowrap; color: var(--text); }

.topbar-search { flex: 1; position: relative; max-width: 560px; margin-inline-start: auto; }
#global-search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  background: var(--input-bg);
  color: var(--text);
}
#global-search-input::placeholder { color: var(--text-muted); }
#global-search-input:focus { outline: 2px solid var(--primary); background: var(--surface-2); }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline: 0;
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 420px;
  overflow-y: auto;
  z-index: 60;
}
.search-result-item {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
}
.search-result-item:hover { background: var(--surface-2); }
.search-result-item .sr-type { font-size: 11px; color: var(--primary-light); font-weight: 600; }
.search-result-item .sr-text { font-size: 13px; margin-top: 2px; }
.search-empty { padding: 14px; color: var(--text-muted); text-align: center; }

#page-container { padding: 18px; flex: 1; }

/* ===== کارت‌ها ===== */
.card {
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow), var(--glass-border-glow);
  padding: 16px;
  margin-bottom: 16px;
  transition: transform .2s ease, box-shadow .2s ease;
}
.card:hover { transform: translateY(-1px); }
.card-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--text);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow), var(--glass-border-glow);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: transform .2s ease;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-icon {
  font-size: 22px;
  width: 42px;
  height: 42px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(20,184,166,.12);
}
.stat-value { font-size: 20px; font-weight: 800; color: var(--text); }
.stat-label { font-size: 12px; color: var(--text-muted); }

/* ===== آیکون‌های شیشه‌ای/گرادیانت (SVG، از js/icons.js) با حرکت ملایم ===== */
.stat-icon:has(.gicon) { background: none; padding: 0; }
.gicon { display: block; filter: drop-shadow(0 4px 10px rgba(0,0,0,.35)); transition: transform .25s ease, filter .25s ease; }
.nav-item:hover .gicon { transform: translateY(-2px) scale(1.08); }
.stat-card:hover .gicon { transform: translateY(-3px) scale(1.1); filter: drop-shadow(0 8px 18px rgba(20,184,166,.5)); }
@keyframes icon-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.stat-icon .gicon { animation: icon-float 3.6s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) {
  .stat-icon .gicon { animation: none; }
}

/* ===== دکمه‌ها ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  background: var(--primary);
  color: var(--btn-text);
  font-weight: 600;
  transition: filter .15s, transform .15s;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.12); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { background: transparent; color: var(--text); border: none; font-size: 18px; padding: 4px 8px; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-success { background: var(--success); color: var(--btn-text); }
.btn-warning { background: var(--warning); color: var(--btn-text); }
.btn-danger { background: var(--danger); color: var(--btn-text); }
.btn-info { background: var(--info); color: var(--btn-text); }
.btn-muted { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ===== جدول ===== */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}
table.data th, table.data td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: center;
  white-space: nowrap;
}
table.data th { background: var(--surface-2); font-weight: 700; font-size: 12px; color: var(--text); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tfoot td { background: var(--surface-2); font-weight: 700; }
.row-actions { display: inline-flex; gap: 4px; }

/* ===== فیلتر ستون‌های جدول (اعمال یکسان روی همه ماژول‌ها) ===== */
table.data th.th-filtered { background: rgba(245,158,11,.22); color: #fcd34d; }
.tf-filter-btn { border: none; background: none; cursor: pointer; font-size: 11px; padding: 0 2px; opacity: .55; color: inherit; }
.tf-filter-btn.active { opacity: 1; color: var(--warning); }
.tf-popover { position: absolute; z-index: 200; background: var(--surface); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 10px; min-width: 220px; font-size: 13px; color: var(--text); }
.tf-popover select, .tf-popover input { width: 100%; margin-bottom: 6px; box-sizing: border-box; }
.tf-popover .tf-actions { display: flex; gap: 6px; margin-top: 4px; }
.tf-popover .tf-actions .btn { flex: 1; }

/* ===== جابه‌جایی ستون‌های جدول با کشیدن و رها کردن (اعمال یکسان روی همه ماژول‌ها) ===== */
table.data th[draggable="true"] { cursor: grab; }
table.data th.col-dragging { opacity: .4; }
table.data th.col-drag-over { box-shadow: inset 2px 0 0 var(--primary), inset -2px 0 0 var(--primary); }

/* سوییچ کروی (برای مثال: مرجوع‌شدن طاقه) */
.round-toggle { position: relative; display: inline-block; width: 38px; height: 20px; vertical-align: middle; }
.round-toggle input { opacity: 0; width: 0; height: 0; }
.round-toggle .slider { position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; cursor: pointer; transition: .2s; }
.round-toggle .slider::before { content: ''; position: absolute; width: 14px; height: 14px; right: 2px; top: 2px; background: var(--text-muted); border-radius: 50%; transition: .2s; }
.round-toggle input:checked + .slider { background: rgba(34,197,94,.2); border-color: var(--success); }
.round-toggle input:checked + .slider::before { transform: translateX(-18px); background: var(--success); }

/* ردیف باطل‌شده (ابطال به‌جای حذف، در همه ماژول‌ها) */
tr.row-voided { opacity: .5; }
tr.row-voided td:not(:last-child) { text-decoration: line-through; }
tr.row-unmatched td { background: rgba(245,158,11,.08); }

/* ردیف در صف ارسال آفلاین (هنوز به سرور نرسیده) */
tr.row-pending { background: rgba(245,158,11,.08); }
tr.row-pending td:first-child { border-right: 3px solid var(--warning); }

/* ===== انتخاب‌گر تقویم شمسی ===== */
.jalali-popover { position: absolute; z-index: 300; background: var(--surface); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 10px; width: 260px; color: var(--text); }
.jalali-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-weight: 700; }
.jalali-head .jalali-nav { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 6px; padding: 3px 8px; cursor: pointer; font-size: 12px; }
.jalali-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.jalali-weekdays { margin-bottom: 4px; font-size: 12px; color: var(--text-muted); font-weight: 700; }
.jalali-day { border: none; background: none; color: var(--text); padding: 6px 0; border-radius: 6px; cursor: pointer; font-size: 13px; }
.jalali-day:hover { background: rgba(20,184,166,.18); }

/* ===== فهرست کشویی شناور (مثل پیشنهاد پارچه) — برای رفع مشکل بریده‌شدن داخل جدول‌های اسکرول‌دار ===== */
.floating-suggest { position: absolute; z-index: 250; background: var(--surface); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur); border: 1px solid var(--border); border-radius: 0 0 12px 12px; max-height: 240px; overflow: auto; box-shadow: var(--shadow); }
.floating-suggest .fabric-suggest-item { padding: 10px 12px; cursor: pointer; border-top: 1px solid var(--border); color: var(--text); }
.floating-suggest .fabric-suggest-item:first-child { border-top: none; }
.floating-suggest .fabric-suggest-item:hover { background: var(--surface-2); }

/* ===== نشان‌ها ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-gray { background: rgba(139,150,172,.18); color: #c3cad9; }
.badge-blue { background: rgba(56,189,248,.16); color: #7dd3fc; }
.badge-yellow { background: rgba(245,158,11,.16); color: #fcd34d; }
.badge-purple { background: rgba(168,85,247,.16); color: #d8b4fe; }
.badge-green { background: rgba(34,197,94,.16); color: #86efac; }
.badge-red { background: rgba(239,68,68,.16); color: #fca5a5; }

/* نوار پیشرفت */
.progress { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; height: 10px; overflow: hidden; min-width: 90px; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--success)); border-radius: 999px; }

/* ===== فرم ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.form-field input, .form-field select, .form-field textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  background: var(--input-bg);
  color: var(--text);
}
.form-field input::placeholder, .form-field textarea::placeholder { color: var(--text-muted); }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: 2px solid var(--primary);
}
.form-hint { font-size: 11px; color: var(--text-muted); }

/* ===== مودال ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2,6,16,.65);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
  overflow-y: auto;
}
.modal-box {
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 720px;
  box-shadow: 0 20px 50px rgba(0,0,0,.55), var(--glass-border-glow);
  animation: modal-in .18s ease;
  color: var(--text);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; color: var(--text); }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 18px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}

/* ===== دکمه‌ی متنی داخل جدول (مثلاً باز کردن مقایسه‌ی ورود/خروج یک برش) ===== */
.link-btn {
  background: none; border: none; padding: 0; margin: 0; font: inherit; cursor: pointer;
  color: var(--primary-light); text-decoration: none;
}
.link-btn:hover { text-decoration: underline; }

/* ===== تب‌های ماژول (مثلاً سوابق/خدمات در خیاطی) ===== */
.mod-tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.mod-tab {
  background: none; border: none; padding: 10px 18px; font-size: 13px; font-weight: 700;
  color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.mod-tab.active { color: var(--primary-light); border-bottom-color: var(--primary); }
.mod-tab:hover { color: var(--primary-light); }

/* ===== ویجت به‌روزرسانی نسخه (کنار صفحه، قابل جمع/باز شدن، غیر مسدودکننده) ===== */
#update-banner {
  position: fixed;
  bottom: 20px;
  inset-inline-end: 20px;
  z-index: 210;
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 280px;
  max-width: calc(100vw - 40px);
  overflow: hidden;
  animation: toast-in .25s ease;
  color: var(--text);
}
#update-banner .ub-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
#update-banner .ub-toggle {
  background: none;
  border: none;
  color: var(--text);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}
#update-banner .ub-body {
  padding: 12px 14px;
  font-size: 13px;
}
#update-banner .ub-body p { margin: 0 0 10px; color: var(--text-muted); }
#update-banner.collapsed .ub-body { display: none; }
#update-banner.collapsed .ub-toggle { transform: rotate(180deg); }

/* ===== اعلان ===== */
#toast-container {
  position: fixed;
  bottom: 20px;
  inset-inline-start: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--toast-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in .2s ease;
  max-width: 340px;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.toast-success { background: rgba(34,197,94,.16); border-color: var(--success); color: #86efac; }
.toast-error { background: rgba(239,68,68,.16); border-color: var(--danger); color: #fca5a5; }
.toast-warning { background: rgba(245,158,11,.16); border-color: var(--warning); color: #fcd34d; }

/* ===== ابزارهای کمکی ===== */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.mt-2 { margin-top: 8px; }
.mb-2 { margin-bottom: 8px; }
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}
.empty-state .es-icon { font-size: 42px; margin-bottom: 8px; }

/* ===== واکنش‌گرا ===== */
@media (max-width: 900px) {
  #sidebar { transform: translateX(100%); }
  #sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  #main-area { margin-inline-start: 0; }
  #page-title { font-size: 15px; }
}

/* ===== چاپ ===== */
@media print {
  #sidebar, #topbar, #toast-container, .no-print { display: none !important; }
  #main-area { margin: 0; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: none; }
  table.data th { background: #eee !important; color: #000 !important; }
  table.data, table.data td, .card, .card-title { color: #000 !important; }
}
