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

:root {
  --bg: #0F1420;
  --panel: #161C2A;
  --panel-raised: #1C2436;
  --border: #262E40;
  --text: #E8ECF4;
  --text-muted: #8A94A6;
  --accent: #FF8A3D;
  --accent-dim: #7A4321;
  --online: #3ECF8E;
  --busy: #FF8A3D;
  --offline: #4A5568;
  --danger: #FF5C5C;
  --font-ui: 'Vazirmatn', Tahoma, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 10% 0%, rgba(255,138,61,0.05), transparent 40%),
    radial-gradient(circle at 90% 20%, rgba(62,207,142,0.04), transparent 40%);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100vh;
}

/* چیدمان کلی: سایدبار + محتوای اصلی */
.app-shell { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--panel); border-inline-start: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 24px 18px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 20px; margin-bottom: 16px; border-bottom: 1px solid var(--border);
}
.brand-mark {
  font-size: 26px;
  color: var(--accent);
  filter: drop-shadow(0 0 8px rgba(255,138,61,0.5));
}
.brand h1 { font-size: 16px; margin: 0; font-weight: 700; letter-spacing: -0.2px; }
.brand-sub { margin: 2px 0 0; color: var(--text-muted); font-size: 12px; }

.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }
.session-bar { display: flex; flex-direction: column; align-items: stretch; gap: 8px; color: var(--text-muted); font-size: 13px; }
.btn-logout { width: 100%; }

.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(5,7,12,0.6); z-index: 55;
}

.menu-toggle {
  display: none; background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; width: 38px; height: 38px; font-size: 16px; cursor: pointer;
  margin-bottom: 14px;
}

.main-content { flex: 1; min-width: 0; max-width: 1180px; padding: 28px 24px 60px; }

/* Tabs (حالا داخل سایدبار، به‌صورت عمودی) */
.tabs { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.tab-btn {
  background: none; border: none; border-inline-end: 3px solid transparent; color: var(--text-muted);
  font-family: var(--font-ui); font-size: 14px; font-weight: 500; text-align: start;
  padding: 10px 14px; border-radius: 8px; cursor: pointer;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.tab-btn.active { color: var(--accent); background: rgba(255,138,61,0.08); border-inline-end-color: var(--accent); }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.panel-toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.panel-toolbar h2 { font-size: 16px; font-weight: 600; margin: 0; }
.panel-note { color: var(--text-muted); font-size: 13px; }
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar-search {
  background: var(--panel-raised); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; color: var(--text); font-family: var(--font-ui); font-size: 13px;
}

/* نوار فیلتر/جست‌وجو بالای جدول‌ها — برای فیلتر کردن اطلاعات همان بخش بر اساس فیلدهای خودش */
.filter-bar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 14px;
}
.filter-bar select {
  background: var(--panel-raised); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; color: var(--text); font-family: var(--font-ui); font-size: 13px;
}
.filter-date-label {
  display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 12.5px;
}
.filter-date-label input[type="date"],
.filter-date-label input.jalali-date-input {
  background: var(--panel-raised); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 8px; color: var(--text); font-family: var(--font-ui); font-size: 12.5px;
}
.filter-date-label input.jalali-date-input {
  width: 100px; cursor: pointer; text-align: center;
}
.filter-date-label input.jalali-date-input:focus { outline: none; border-color: var(--accent); }

/* تقویم شمسی سفارشی (جایگزین date picker بومی مرورگر) */
.jalali-picker-backdrop {
  display: none; position: fixed; inset: 0; z-index: 70; background: transparent;
}
.jalali-picker-backdrop.active { display: block; }
.jalali-picker-popup {
  display: none; position: absolute; z-index: 71; width: 280px;
  background: var(--panel-raised); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); font-family: var(--font-ui);
}
.jalali-picker-popup.active { display: block; }
.jalali-picker-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
}
.jalali-picker-title { font-size: 13.5px; font-weight: 600; color: var(--text); }
.jalali-nav {
  background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text-muted);
  width: 26px; height: 26px; font-size: 15px; cursor: pointer; line-height: 1;
}
.jalali-nav:hover { color: var(--accent); border-color: var(--accent); }
.jalali-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); text-align: center;
  color: var(--text-muted); font-size: 11px; margin-bottom: 4px;
}
.jalali-days-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.jalali-day {
  background: none; border: none; border-radius: 6px; color: var(--text);
  font-family: var(--font-ui); font-size: 12.5px; padding: 6px 0; cursor: pointer;
}
.jalali-day:hover { background: rgba(255,138,61,0.12); }
.jalali-day-empty { cursor: default; }
.jalali-day-empty:hover { background: none; }
.jalali-day-today { color: var(--accent); font-weight: 600; }
.jalali-day-selected { background: var(--accent); color: #1a1200; font-weight: 600; }
.jalali-picker-footer {
  display: flex; justify-content: space-between; gap: 8px; margin-top: 10px;
  padding-top: 10px; border-top: 1px solid var(--border);
}
.jalali-picker-btn {
  flex: 1; background: none; border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 0; color: var(--accent); font-family: var(--font-ui); font-size: 12px; cursor: pointer;
}
.jalali-picker-btn-muted { color: var(--text-muted); }
.jalali-picker-btn:hover { border-color: var(--accent); }

@media (max-width: 480px) {
  .jalali-picker-popup--sheet {
    position: fixed; inset-inline: 0; bottom: 0; top: auto; left: 0; right: 0;
    width: 100%; border-radius: 16px 16px 0 0; padding: 16px;
  }
}

/* موبایل و تبلت: سایدبار به منوی کشویی تبدیل می‌شود */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; inset-inline-start: 0; top: 0; height: 100vh; width: 270px; max-width: 82vw;
    z-index: 60; transform: translateX(100%); transition: transform 0.25s ease;
    box-shadow: -8px 0 24px rgba(0,0,0,0.35);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .main-content { padding: 18px 14px 40px; }
}

.btn-primary {
  background: var(--accent); color: #1a1200; border: none; border-radius: 8px;
  padding: 9px 16px; font-family: var(--font-ui); font-weight: 600; font-size: 13px;
  cursor: pointer; transition: filter 0.15s;
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-secondary {
  background: var(--panel-raised); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 12px; font-family: var(--font-ui); font-size: 12px;
  cursor: pointer; margin-inline-end: 6px;
}
.btn-secondary:hover { border-color: var(--accent); }
.btn-secondary.danger:hover { border-color: var(--danger); color: var(--danger); }

/* Table */
.table-wrap {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; min-width: 560px; }
thead th {
  text-align: right; font-size: 12px; color: var(--text-muted); font-weight: 500;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--panel-raised);
}
tbody td {
  padding: 13px 16px; font-size: 13px; border-bottom: 1px solid var(--border);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.02); }

/* ردیف جمع کل — خط بالایی پررنگ‌تر و پس‌زمینه‌ی متفاوت تا از ردیف‌های داده جدا دیده شود.
   چون داخل همان <table> است، ستون‌هایش خودکار با ستون‌های بالا هم‌تراز می‌مانند، حتی وقتی
   .table-wrap روی موبایل افقی اسکرول می‌خورد. */
tfoot td {
  padding: 13px 16px; font-size: 13px; font-weight: 600; color: var(--text);
  background: var(--panel-raised); border-top: 2px solid var(--border);
}
tfoot td.mono { color: var(--text); font-size: 13px; font-weight: 600; }

.mono { font-family: var(--font-mono); color: var(--text-muted); font-size: 12.5px; }

/* Status badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500;
  padding: 4px 10px; border-radius: 100px;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.badge.online { color: var(--online); background: rgba(62,207,142,0.1); }
.badge.online::before { background: var(--online); box-shadow: 0 0 6px var(--online); }
.badge.busy { color: var(--busy); background: rgba(255,138,61,0.1); }
.badge.busy::before { background: var(--busy); }
.badge.offline { color: var(--offline); background: rgba(74,85,104,0.15); }
.badge.offline::before { background: var(--offline); }

.badge.pending { color: var(--busy); background: rgba(255,138,61,0.1); }
.badge.pending::before { background: var(--busy); }
.badge.in_progress { color: #5B9CFF; background: rgba(91,156,255,0.1); }
.badge.in_progress::before { background: #5B9CFF; }
.badge.done { color: var(--online); background: rgba(62,207,142,0.1); }
.badge.done::before { background: var(--online); }

/* فاکتور «پرداخت معوق» که هنوز از موعد نگذشته — بنفش، عمداً رنگی جدا از «pending» (که همان نارنجیِ
   «در انتظار پذیرش» است) تا این دو با یک نگاه با هم اشتباه نشوند؛ اگر از موعد گذشت، قرمز می‌شود */
.badge.payment-pending { color: #B968FF; background: rgba(185,104,255,0.12); }
.badge.payment-pending::before { background: #B968FF; }
.badge.payment-overdue { color: var(--danger); background: rgba(255,92,92,0.1); }
.badge.payment-overdue::before { background: var(--danger); }

/* نوع کار (گارانتی جدید / گارانتی مجدد / آزاد) — ستون جدا از وضعیت، رنگ‌بندی مستقل */
.badge.job-warranty-new { color: var(--accent); background: rgba(255,138,61,0.1); }
.badge.job-warranty-new::before { background: var(--accent); }
.badge.job-warranty-repeat { color: var(--online); background: rgba(62,207,142,0.1); }
.badge.job-warranty-repeat::before { background: var(--online); }
.badge.job-free { color: var(--text-muted); background: rgba(138,148,166,0.12); }
.badge.job-free::before { background: var(--text-muted); }

/* دلیل بازدید/تعمیر مجدد (فقط برای «مشتری قبلی») — رنگ جدا تا با نوع کار اشتباه نشود */
.badge.revisit-inspection { color: #5B9CFF; background: rgba(91,156,255,0.1); }
.badge.revisit-inspection::before { background: #5B9CFF; }
.badge.revisit-broken { color: var(--danger); background: rgba(255,92,92,0.1); }
.badge.revisit-broken::before { background: var(--danger); }

.priority-high { color: var(--danger); font-weight: 600; }
.priority-normal { color: var(--text-muted); }
.priority-low { color: var(--text-muted); }

.empty-row td { text-align: center; color: var(--text-muted); padding: 30px; }

/* Modal */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(5,7,12,0.7);
  align-items: center; justify-content: center; z-index: 50; backdrop-filter: blur(2px);
  padding: 20px; overflow-y: auto;
}
.modal-overlay.active { display: flex; }
/* عرض مودال عمداً بزرگ‌تر از قبل (۴۲۰ پیکسل قبلی) است تا محتوای عریض‌تر مثل جدول ۸ستونی فاکتور
   یا جدول‌های تاریخچه مشتری بدون اسکرول افقی جا شوند — width: fit-content امتحان شد ولی چون
   .table-wrap داخلش overflow-x:auto دارد، محاسبه‌ی عرض طبیعی مرورگر (شرینک‌تو‌فیت) به‌جای عرض
   واقعی جدول تقریباً صفر می‌شد؛ به همین دلیل یک عدد ثابت امن‌تر است */
.modal {
  background: var(--panel-raised); border: 1px solid var(--border); border-radius: 14px;
  padding: 24px; width: 760px; max-width: min(92vw, 900px);
  max-height: 90vh; overflow-y: auto;
  margin: auto;
}

@media (max-width: 480px) {
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { width: 100%; min-width: 0; max-width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; }
}

.incoming-call-banner {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 60; width: 360px; max-width: calc(100vw - 24px);
  background: var(--panel-raised); border: 1px solid var(--accent); border-radius: 14px;
  padding: 16px; box-shadow: 0 8px 28px rgba(0,0,0,0.45);
}
.incoming-call-banner h4 { margin: 0 0 6px; font-size: 14px; color: var(--accent); }
.incoming-call-banner p { margin: 2px 0; font-size: 13.5px; }
.incoming-call-banner .modal-actions { margin-top: 10px; }

@media (max-width: 480px) {
  .incoming-call-banner { top: 0; left: 0; transform: none; width: 100%; max-width: 100%; border-radius: 0 0 14px 14px; }
}
.modal h3 { margin: 0 0 16px; font-size: 16px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 7px;
  padding: 9px 12px; color: var(--text); font-family: var(--font-ui); font-size: 13px;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--accent);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.btn-ghost {
  background: none; border: none; color: var(--text-muted); font-family: var(--font-ui);
  font-size: 13px; cursor: pointer; padding: 9px 14px;
}

.call-btn {
  background: rgba(62,207,142,0.12); color: var(--online); border: 1px solid rgba(62,207,142,0.3);
  border-radius: 6px; padding: 5px 10px; font-size: 12px; cursor: pointer; font-family: var(--font-ui);
}
.call-btn:hover { background: rgba(62,207,142,0.2); }

/* صفحه ورود */
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 36px 32px; width: 360px; max-width: 90vw;
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.login-brand h1 { font-size: 17px; margin: 0; }
.login-sub { color: var(--text-muted); font-size: 13px; margin: 0 0 22px; }
.login-btn { width: 100%; padding: 11px; font-size: 14px; margin-top: 6px; }
.login-error { color: var(--danger); font-size: 12.5px; min-height: 16px; margin-bottom: 4px; }

/* نوار بالای صفحه اصلی برای خروج */
.session-bar {
  display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 13px;
}
.btn-logout {
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  border-radius: 6px; padding: 6px 12px; font-size: 12.5px; cursor: pointer; font-family: var(--font-ui);
}
.btn-logout:hover { border-color: var(--danger); color: var(--danger); }

/* صفحه موبایل تکنسین */
.tech-console { max-width: 480px; margin: 0 auto; padding: 20px 16px 60px; }
.tech-sub { color: var(--text-muted); font-size: 13px; margin: 2px 0 0; }

.tech-top-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 16px;
}
.tech-top-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.tech-top-row h1 { font-size: 18px; margin: 0; }
.tech-top-row .btn-logout { width: auto; flex-shrink: 0; }
.tech-top-divider { height: 1px; background: var(--border); margin: 12px 0; }
.tech-status-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--text-muted); }

.tech-status-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 16px; font-size: 13px; color: var(--text-muted);
}
/* دکمه کشویی روشن/خاموش برای وضعیت آنلاین/آفلاین تکنسین */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; inset: 0; cursor: pointer;
  background-color: var(--panel-raised); border: 1px solid var(--border);
  border-radius: 999px; transition: background-color 0.2s, border-color 0.2s;
}
.switch-slider::before {
  content: ""; position: absolute; height: 20px; width: 20px; inset-inline-start: 2px; top: 2px;
  background-color: var(--offline); border-radius: 50%; transition: inset-inline-start 0.2s, background-color 0.2s;
}
.switch input:checked + .switch-slider { background-color: rgba(62,207,142,0.15); border-color: var(--online); }
.switch input:checked + .switch-slider::before { inset-inline-start: 22px; background-color: var(--online); box-shadow: 0 0 6px var(--online); }
.switch input:focus-visible + .switch-slider { outline: 2px solid var(--accent); outline-offset: 2px; }

.tech-tasks-list { display: flex; flex-direction: column; gap: 12px; }
.tech-task-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px;
}
.tech-task-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.tech-priority { font-size: 12.5px; color: var(--text-muted); }
.tech-task-card h3 { font-size: 15px; margin: 0 0 6px; }
.tech-desc { font-size: 13px; color: var(--text-muted); margin: 0 0 8px; }
.tech-customer { font-size: 13px; margin: 2px 0; color: var(--text); }
.tel-link {
  display: inline-block; text-decoration: none; color: var(--accent); font-weight: 600;
  padding: 2px 0;
}
.tel-link:active { opacity: 0.7; }
p.tel-link, a.tech-customer.tel-link { display: block; }

/* تسک‌ها — یادداشت/پیگیری شخصی (کارت‌ها همان .tech-task-card را با هم به اشتراک می‌گذارند، فقط حاشیه قرمز برای گذشته از موعد اضافه می‌شود) */
.personal-task-card.personal-task-overdue { border-color: var(--danger); }
.tech-task-actions { margin-top: 12px; }
.tech-task-actions select {
  width: 100%; background: var(--panel-raised); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 10px 12px; font-family: var(--font-ui); font-size: 13px;
}
.tech-empty { text-align: center; color: var(--text-muted); padding: 40px 20px; font-size: 13px; }

.status-btn-group { display: flex; flex-wrap: wrap; gap: 6px; }
.status-btn-group .btn-secondary { flex: 1 1 auto; }
.status-btn-group .btn-secondary.active { background: var(--accent); color: #1a1200; border-color: var(--accent); font-weight: 600; }

/* بلوک «هماهنگی تماس با مشتری» روی کارت کار تکنسین + صف پیگیری منشی */
.tech-coord-box {
  margin-top: 12px; padding: 12px; border-radius: 10px; font-size: 13px;
  background: var(--panel-raised); border: 1px dashed var(--border);
}
.tech-coord-box.scheduled { border-style: solid; border-color: rgba(62,207,142,0.4); }
.tech-coord-box.waiting { border-style: solid; border-color: rgba(255,193,7,0.4); }
.tech-coord-badge {
  display: inline-block; margin-inline-start: 6px; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; background: rgba(255,193,7,0.12); color: #e0a800; border: 1px solid rgba(255,193,7,0.35);
}
.tech-coord-badge.ok { background: rgba(62,207,142,0.12); color: var(--online); border-color: rgba(62,207,142,0.35); }
.tech-coord-returned {
  margin-bottom: 8px; padding: 8px 10px; border-radius: 8px; font-size: 12.5px;
  background: rgba(255,107,107,0.1); border: 1px solid rgba(255,107,107,0.3);
}
.coord-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .coord-columns { grid-template-columns: 1fr; } }
.coord-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 10px;
}
.coord-card p { margin: 3px 0; font-size: 13px; }
.coord-card .coord-actions { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }

.role-radio-group { display: flex; flex-direction: column; gap: 8px; }
.role-radio-option {
  display: flex; align-items: center; gap: 10px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; cursor: pointer; font-size: 13px;
}
.role-radio-option:has(input:checked) { border-color: var(--accent); background: rgba(255,138,61,0.06); }
.role-radio-option input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

/* یک ردیف به‌ازای هر ماژول در ماتریس دسترسی نقش‌ها — چیپ اصلی (دسترسی پایه) به‌همراه
   چیپ‌های زیربخش‌ها (اگر ماژول زیربخش داشته باشد) همه در همان ردیف، به‌جای لیست عمودی تورفته */
.role-permission-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.role-permission-chip {
  display: flex; align-items: center; gap: 6px; background: var(--panel-raised); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 12.5px; white-space: nowrap;
}
.role-permission-chip:has(input:checked) { border-color: var(--accent); background: rgba(255,138,61,0.12); }
.role-permission-chip input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.role-permission-chip-main { font-weight: 600; font-size: 13px; flex: 0 0 auto; }
.role-permission-subchips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1 1 auto; }

@media (max-width: 480px) {
  .role-permission-row { flex-direction: column; align-items: stretch; }
  .role-permission-chip-main { width: 100%; }
}

.task-address { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.device-row { display: flex; align-items: center; gap: 6px; }
.device-delete-btn {
  border: none; background: none; color: var(--text-muted); cursor: pointer;
  font-size: 11px; padding: 0 3px; line-height: 1;
}
.device-delete-btn:hover { color: var(--danger); }

.catalog-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 720px) { .catalog-columns { grid-template-columns: 1fr; } }

/* تب پیام‌ها */
.messaging-layout {
  display: grid; grid-template-columns: 260px 1fr; gap: 0;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; height: 62vh; min-height: 440px;
}
@media (max-width: 720px) {
  .messaging-layout { grid-template-columns: 1fr; height: auto; }
  .messaging-thread-list { max-height: 220px; }
}
.messaging-thread-list { border-inline-end: 1px solid var(--border); overflow-y: auto; }
.messaging-thread-item { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.messaging-thread-item:hover { background: rgba(255,255,255,0.03); }
.messaging-thread-item.active { background: rgba(255,138,61,0.08); }
.messaging-thread-name { font-weight: 600; font-size: 13.5px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.messaging-unread-badge { background: var(--accent); color: #1a1200; border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.messaging-thread-preview { color: var(--text-muted); font-size: 12px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.messaging-chat-pane { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.messaging-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.messaging-bubble { max-width: 75%; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.6; }
.messaging-bubble.mine { align-self: flex-start; background: var(--accent); color: #1a1200; }
.messaging-bubble.theirs { align-self: flex-end; background: var(--panel-raised); border: 1px solid var(--border); }
.messaging-bubble-meta { font-size: 10.5px; opacity: 0.75; margin-top: 4px; }
.messaging-input-row { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.messaging-input-row input { flex: 1; }

/* پیام‌ها در نمای تکنسین (بدون لیست ترد کناری، فقط یک ترد خودش) */
.tech-messages-panel {
  display: flex; flex-direction: column; height: calc(100vh - 260px); min-height: 320px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
}

/* فرم یکپارچه ثبت کار: سوییچ حالت، جست‌وجوی مشتری */
.segmented {
  display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 3px; margin-bottom: 14px;
}
.seg-btn {
  flex: 1; background: none; border: none; color: var(--text-muted); font-family: var(--font-ui);
  font-size: 12.5px; padding: 7px 0; border-radius: 6px; cursor: pointer;
}
.seg-btn.active { background: var(--accent); color: #1a1200; font-weight: 600; }

.search-results { margin-bottom: 10px; }
.search-result-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 7px;
  padding: 9px 12px; margin-bottom: 6px; cursor: pointer; font-size: 12.5px;
}
.search-result-item:hover { border-color: var(--accent); }
.search-empty { color: var(--text-muted); font-size: 12.5px; padding: 8px 0; }
.text-muted { color: var(--text-muted); }

/* جدول اقساط ماهانه وام — هر خانه یک ماه؛ رنگ پرداخت‌شده/پرداخت‌نشده/عقب‌افتاده را نشان می‌دهد */
.loan-months-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 8px; margin: 10px 0 18px;
}
.loan-month-card {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px;
  text-align: center; background: var(--panel); display: flex; flex-direction: column; gap: 4px;
}
.loan-month-index { font-size: 11.5px; color: var(--text-muted); }
.loan-month-total { font-size: 15px; }
.loan-month-paid { background: rgba(62,207,142,0.12); border-color: var(--online); }
.loan-month-unpaid { background: var(--panel); }
.loan-month-overdue { background: rgba(255,92,92,0.1); border-color: var(--danger); }
.loan-month-card .btn-secondary { margin-top: 4px; width: 100%; font-size: 11.5px; padding: 6px 8px; }
.loan-month-card a { font-size: 11.5px; }
/* خانه‌های ماهی که ریز پرداختی دارند (چند واریز جزئی یا عکس رسید) عریض‌تر می‌شوند تا شلوغ/فشرده نشوند */
.loan-month-card-wide { grid-column: span 2; text-align: right; }
.loan-month-payments { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.loan-month-payment { border-top: 1px dashed var(--border); padding-top: 6px; }
.loan-month-payment-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; }
.loan-month-payment-date { color: var(--text-muted); font-size: 11.5px; }
.loan-month-payment-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.loan-receipt-thumb { display: inline-block; line-height: 0; }
.loan-receipt-thumb img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }

/* صف واریزی‌های در انتظار تایید منشی (تب «در انتظار تایید» زیر وام‌ها) — یک کارت به‌ازای هر واریزی */
.pending-deposits-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px; margin-top: 14px;
}
.pending-deposit-card {
  border: 1px solid var(--busy); border-radius: 10px; padding: 12px;
  background: rgba(255,138,61,0.06);
}
.pending-deposit-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.pending-deposit-photo-link { display: inline-block; margin-top: 6px; font-size: 12.5px; color: var(--accent); }

/* فرم فشرده (مثل فرم ثبت/ویرایش وام) — فیلدهای کوچک‌تر و دو-ستونه تا کل فرم بدون اسکرول جا شود */
.form-compact .form-group { margin-bottom: 8px; }
.form-compact .form-group label { margin-bottom: 3px; font-size: 11px; }
.form-compact .form-group input,
.form-compact .form-group select,
.form-compact .form-group textarea {
  padding: 6px 9px; font-size: 12.5px;
}
.form-compact .form-group .panel-note { font-size: 10.5px; margin-top: 2px; display: block; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
@media (max-width: 480px) { .form-row-2 { grid-template-columns: 1fr; } }

.selected-customer-card {
  background: rgba(255,138,61,0.06); border: 1px solid var(--accent); border-radius: 8px;
  padding: 12px; margin-bottom: 12px; font-size: 13px;
}

.invoice-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 6px; margin-bottom: 10px; align-items: center;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px;
}
.invoice-row input, .invoice-row select {
  background: var(--panel-raised); border: 1px solid var(--border); border-radius: 6px; color: var(--text);
  padding: 8px; font-family: var(--font-ui); font-size: 12px; width: 100%;
}
.invoice-row input:disabled { color: var(--text-muted); }

.invoice-photos-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.invoice-photo-thumb {
  position: relative; width: 76px; height: 76px; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border); display: block;
}
.invoice-photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.invoice-photo-remove {
  position: absolute; top: 2px; inset-inline-end: 2px; background: rgba(5,7,12,0.75); color: #fff;
  border: none; border-radius: 50%; width: 20px; height: 20px; font-size: 12px; line-height: 1;
  cursor: pointer;
}

/* کارت مشخصات مشتری/دستگاه در بالای مودال فاکتور — با auto-fit خودش روی موبایل تک‌ستونه می‌شود */
.invoice-customer-box {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 4px 18px;
  background: var(--panel-raised); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 12px; font-size: 12.5px; line-height: 1.9;
}
.invoice-customer-box .invoice-customer-address { grid-column: 1 / -1; }
.invoice-customer-label { color: var(--text-muted); margin-left: 6px; }

.signature-consent-text {
  color: var(--text-muted); font-size: 12.5px; margin-bottom: 8px; line-height: 1.7;
}
.signature-pad-wrap {
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 8px; line-height: 0;
}
.signature-pad-canvas {
  display: block; width: 100%; height: 160px; touch-action: none; cursor: crosshair; background: #ffffff;
}
.settings-textarea {
  width: 100%; min-height: 120px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 7px; color: var(--text); padding: 9px 12px; font-family: var(--font-ui); font-size: 13px;
  resize: vertical;
}
.settings-textarea:focus { outline: none; border-color: var(--accent); }

/* کارت‌های بکاپ و بازگردانی در تب تنظیمات */
.backup-card {
  background: var(--panel-raised); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; margin-top: 22px; max-width: 720px;
}
.backup-card h3 { margin: 0 0 6px; font-size: 15px; }
.backup-card h4 { margin: 0 0 4px; font-size: 13px; }
.backup-status {
  margin: 12px 0; padding: 10px 12px; border-radius: 8px; font-size: 13px; line-height: 1.9;
  background: var(--panel); border: 1px solid var(--border);
}
.backup-status .ok { color: var(--online); }
.backup-status .err { color: var(--danger); }
.backup-status .muted { color: var(--text-muted); }
.backup-fields {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; margin-bottom: 12px;
}
.backup-fields .form-group { margin: 0; }
.backup-fields input[type="number"] {
  width: 100%; background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 8px 10px; font-family: var(--font-ui); font-size: 13px;
}
.backup-enabled {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer;
}
.backup-enabled input { width: 16px; height: 16px; }
.backup-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.danger-note { color: var(--danger) !important; }
.restore-block {
  border-top: 1px solid var(--border); padding-top: 14px; margin-top: 14px;
}
.restore-block code {
  background: var(--panel); padding: 1px 5px; border-radius: 4px; font-size: 12px;
}
.restore-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.restore-row input[type="file"] { font-size: 12.5px; color: var(--text-muted); max-width: 100%; }
.snapshot-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.snapshot-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px;
}
.snapshot-row .snap-name { font-size: 12.5px; }
.snapshot-row .snap-size { color: var(--text-muted); font-size: 11.5px; }

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

@media (max-width: 640px) {
  .invoice-row { grid-template-columns: 1fr 1fr; }
  table { min-width: 640px; }
  .modal { padding: 18px; }
  .toolbar-search { flex: 1; min-width: 0; }
  .signature-pad-canvas { height: 140px; }
}

/* بورد تقسیم کار (دراگ‌اند‌دراپ کارها بین ستون‌های تکنسین) */
.dispatch-board {
  display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px;
  scroll-snap-type: x proximity; align-items: flex-start;
}
.dispatch-column {
  flex: 0 0 280px; max-width: 280px; scroll-snap-align: start;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  display: flex; flex-direction: column; max-height: 72vh;
  transition: border-color 0.12s, background-color 0.12s;
}
.dispatch-column.drag-over { border-color: var(--accent); background: rgba(255,138,61,0.05); }
.dispatch-column-header {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600;
  position: sticky; top: 0; background: inherit; border-radius: 12px 12px 0 0;
}
.dispatch-column-header .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dispatch-column-header .dot.online { background: var(--online); box-shadow: 0 0 6px var(--online); }
.dispatch-column-header .dot.busy { background: var(--busy); }
.dispatch-column-header .dot.offline { background: var(--offline); }
.dispatch-column-header span:nth-child(2) { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dispatch-count {
  background: var(--panel-raised); color: var(--text-muted); font-size: 11px;
  padding: 2px 8px; border-radius: 100px; font-family: var(--font-mono); flex-shrink: 0;
}
.dispatch-column-body { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.dispatch-empty { text-align: center; color: var(--text-muted); font-size: 12px; padding: 20px 0; }

.dispatch-card {
  background: var(--panel-raised); border: 1px solid var(--border); border-inline-start: 3px solid var(--offline);
  border-radius: 10px; padding: 10px 10px 10px 6px; display: flex; gap: 6px; align-items: flex-start;
}
.dispatch-card-dragging { opacity: 0.35; }
.dispatch-drag-handle {
  cursor: grab; touch-action: none; color: var(--text-muted); font-size: 16px;
  padding: 2px 6px; line-height: 1; user-select: none; flex-shrink: 0;
}
.dispatch-drag-handle:active { cursor: grabbing; }
.dispatch-card-body { flex: 1; min-width: 0; }
.dispatch-card-title { font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.dispatch-card-footer { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 11.5px; }
.dispatch-card-ghost {
  position: fixed; z-index: 200; pointer-events: none; box-shadow: 0 12px 28px rgba(0,0,0,0.45);
  border-radius: 10px; opacity: 0.95; transform: rotate(-1deg);
}

@media (max-width: 900px) {
  .dispatch-column { flex: 0 0 82vw; max-width: 82vw; }
}

/* ---------- تب هوش مصنوعی ---------- */
.ai-alerts { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.ai-alert {
  background: var(--panel-raised); border: 1px solid var(--border);
  border-inline-start: 3px solid var(--offline);
  border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px;
}
.ai-alert strong { font-size: 13.5px; }
.ai-alert span { font-size: 12px; color: var(--text-muted); line-height: 1.8; }
.ai-alert-danger { border-inline-start-color: var(--danger); }
.ai-alert-warn { border-inline-start-color: var(--busy); }
.ai-alert-info { border-inline-start-color: #4C8DFF; }
.ai-alert-ok { border-inline-start-color: var(--online); }

.ai-kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px; margin: 14px 0;
}
.ai-kpi-grid-small { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.ai-kpi {
  background: var(--panel-raised); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; display: flex; flex-direction: column; gap: 5px;
}
.ai-kpi-label { font-size: 11.5px; color: var(--text-muted); }
.ai-kpi-value { font-size: 16px; font-weight: 700; }
.ai-negative { color: var(--danger); }

.ai-section { margin-top: 26px; }
.ai-section h3 { margin: 0 0 8px; font-size: 15px; }
.ai-flag-list { margin: 10px 0 0; padding-inline-start: 20px; font-size: 13px; line-height: 2.1; }

/* پرسش‌وپاسخ */
.ai-suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.ai-suggestion {
  background: var(--panel-raised); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 5px 12px; font-size: 12px; font-family: inherit; cursor: pointer;
}
.ai-suggestion:hover { border-color: var(--accent); color: var(--accent); }
.ai-chat-log {
  display: flex; flex-direction: column; gap: 12px;
  min-height: 220px; max-height: 55vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px;
}
.ai-chat-empty { color: var(--text-muted); font-size: 13px; text-align: center; padding: 40px 10px; }
.ai-msg { border-radius: 12px; padding: 10px 13px; max-width: 88%; font-size: 13px; line-height: 2; }
.ai-msg-user { align-self: flex-start; background: var(--accent-dim); border: 1px solid var(--accent); }
.ai-msg-bot { align-self: flex-end; background: var(--panel-raised); border: 1px solid var(--border); max-width: 100%; width: 100%; }
.ai-msg-bot h3, .ai-msg-bot h4 { margin: 10px 0 6px; font-size: 14px; }
.ai-msg-bot p { margin: 6px 0; }
.ai-msg-bot ul { margin: 6px 0; padding-inline-start: 20px; }
.ai-msg-bot blockquote {
  margin: 8px 0; padding: 6px 10px; border-inline-start: 3px solid var(--busy);
  background: var(--panel); border-radius: 6px; color: var(--text-muted); font-size: 12px;
}
.ai-msg-meta { margin-top: 8px; font-size: 11px; color: var(--text-muted); }
.ai-typing { color: var(--text-muted); font-size: 12.5px; }
.ai-chat-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 12px; }
.ai-chat-form textarea {
  flex: 1; resize: vertical; min-height: 46px; font-family: inherit; font-size: 13px;
  background: var(--panel-raised); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px;
}
.ai-chat-form button { white-space: nowrap; }

/* گزارش‌ها */
.ai-report-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ai-reports-layout { display: grid; grid-template-columns: 300px 1fr; gap: 16px; margin-top: 14px; align-items: start; }
/* min-width:0 لازم است وگرنه ستون grid به‌اندازه‌ی محتوای پهنش (جدول‌های گزارش) باز می‌شود و صفحه در موبایل افقی اسکرول می‌خورد */
.ai-reports-list { display: flex; flex-direction: column; gap: 8px; max-height: 70vh; overflow-y: auto; min-width: 0; }
.ai-report-item {
  text-align: start; background: var(--panel-raised); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; cursor: pointer; color: var(--text);
  font-family: inherit; display: flex; flex-direction: column; gap: 4px;
}
.ai-report-item:hover { border-color: var(--accent); }
.ai-report-item.active { border-color: var(--accent); background: var(--accent-dim); }
.ai-report-item strong { font-size: 13px; }
.ai-report-item span { font-size: 11.5px; color: var(--text-muted); }
.ai-report-item.active span { color: var(--text); }
.ai-report-view {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; min-height: 200px; min-width: 0;
}
.ai-report-view h3 { margin: 0 0 12px; font-size: 16px; }
.ai-markdown { font-size: 13px; line-height: 2.1; }
.ai-markdown h3, .ai-markdown h4 { margin: 16px 0 8px; font-size: 14px; }
.ai-markdown p { margin: 8px 0; }
.ai-markdown ul { margin: 8px 0; padding-inline-start: 20px; }
.ai-markdown blockquote {
  margin: 10px 0; padding: 8px 12px; border-inline-start: 3px solid var(--busy);
  background: var(--panel-raised); border-radius: 6px; color: var(--text-muted); font-size: 12px;
}

@media (max-width: 900px) {
  .ai-reports-layout { grid-template-columns: 1fr; }
  .ai-reports-list { max-height: 260px; }
  .ai-msg { max-width: 100%; }
  .ai-chat-form { flex-direction: column; align-items: stretch; }
}
