/* ══════════════════════════════════════════════════════════
   أظلال لوجستيات — Design System (shared with أظلال AI)
   ══════════════════════════════════════════════════════════ */

/* ─── Tokens ─── */
:root {
  /* Brand */
  --accent:        #16a34a;
  --accent-2:      #22c55e;
  --accent-mid:    #15803d;
  --accent-strong: #166534;
  --accent-soft:   #dcfce7;
  --accent-glow:   rgba(22,163,74,.15);

  /* Surface */
  --bg:      #f8fafc;
  --panel:   #ffffff;
  --panel-2: #f1f5f9;
  --panel-3: #e8f0fe;
  --border:  #e2e8f0;
  --border-2:#cbd5e1;

  /* Text */
  --text:        #0f172a;
  --text-2:      #334155;
  --muted:       #64748b;
  --muted-light: #94a3b8;

  /* Feedback */
  --error:      #dc2626;
  --error-soft: #fee2e2;
  --warn:       #d97706;
  --warn-soft:  #fef3c7;
  --info:       #0284c7;
  --info-soft:  #e0f2fe;

  /* Shadows */
  --shadow-sm:   0 1px 2px rgba(0,0,0,.06);
  --shadow-md:   0 4px 12px rgba(0,0,0,.08);
  --shadow-card: 0 2px 8px rgba(0,0,0,.07), 0 0 0 1px rgba(0,0,0,.04);
  --shadow-lg:   0 8px 24px rgba(0,0,0,.12);
  --shadow-xl:   0 20px 48px rgba(0,0,0,.18);

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Layout */
  --topbar-h: 56px;

  /* Transition */
  --tr: .18s ease;
}

[data-theme="dark"] {
  --accent:        #22c55e;
  --accent-2:      #4ade80;
  --accent-mid:    #16a34a;
  --accent-strong: #4ade80;
  --accent-soft:   rgba(22,163,74,.2);
  --accent-glow:   rgba(34,197,94,.12);

  --bg:      #0d1117;
  --panel:   #161b22;
  --panel-2: #1c2230;
  --panel-3: #1e2d3d;
  --border:  #30363d;
  --border-2:#404040;

  --text:        #e6edf3;
  --text-2:      #b1bac4;
  --muted:       #8b949e;
  --muted-light: #656d76;

  --error-soft: rgba(220,38,38,.18);
  --warn-soft:  rgba(217,119,6,.18);
  --info-soft:  rgba(2,132,199,.18);

  --shadow-sm:   0 1px 2px rgba(0,0,0,.3);
  --shadow-md:   0 4px 12px rgba(0,0,0,.4);
  --shadow-card: 0 2px 8px rgba(0,0,0,.3), 0 0 0 1px rgba(255,255,255,.04);
  --shadow-lg:   0 8px 24px rgba(0,0,0,.5);
  --shadow-xl:   0 20px 48px rgba(0,0,0,.6);
}

/* ─── Reset / Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 15px;
  overflow-x: hidden;
}

body {
  font-family: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  height: 100dvh;
  overflow: hidden;
  overflow-x: hidden;
  max-width: 100vw;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }
input, textarea { font-family: inherit; }

/* ─── Scrollbars ─── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 9px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted-light); }

.hidden { display: none !important; }


/* ══════════════════════════════════════════════════════════
   LOGIN SCREEN
   ══════════════════════════════════════════════════════════ */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 60% 40%, var(--accent-glow) 0%, var(--bg) 70%);
  z-index: 200;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: 40px 36px;
  width: min(400px, 92vw);
  display: flex; flex-direction: column; gap: 18px;
}

.login-logo-wrap { display: flex; justify-content: center; margin-bottom: 4px; }
.login-logo { width: 64px; height: 64px; object-fit: contain; border-radius: var(--radius-md); }

.login-title {
  font-size: 22px; font-weight: 700;
  text-align: center; color: var(--text);
}

.login-subtitle {
  font-size: 13px; color: var(--muted);
  text-align: center; margin-top: -10px;
}

.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.form-field input {
  padding: 10px 14px;
  border: 1.5px solid var(--border-2);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  transition: border-color var(--tr), box-shadow var(--tr);
  outline: none;
}
.form-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
/* منتقي لون أصلي — مربع مدمج بدل حشو حقل نصي الذي يجعله ممطوطاً بشكل غريب */
.form-field input.color-input {
  padding: 3px; width: 56px; height: 40px; cursor: pointer;
}

#login-btn {
  padding: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 15px; font-weight: 700;
  border-radius: var(--radius-md);
  transition: background var(--tr), transform var(--tr);
  margin-top: 4px;
  border: none; cursor: pointer;
}
#login-btn:hover { background: var(--accent-mid); transform: translateY(-1px); }
#login-btn:active { transform: translateY(0); }
#login-btn:disabled { opacity: .6; cursor: default; transform: none; }

.login-error {
  color: var(--error);
  font-size: 13px;
  text-align: center;
  min-height: 20px;
}


/* ══════════════════════════════════════════════════════════
   APP SHELL
   ══════════════════════════════════════════════════════════ */
.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
  overflow-x: hidden;
  max-width: 100vw;
}

.main-col {
  flex: 1; min-width: 0; height: 100dvh;
  display: flex; flex-direction: column; overflow: hidden;
  overflow-x: hidden;
  max-width: 100vw;
}


/* ─── Topbar ─── */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky; top: 0; z-index: 10;
}

.topbar-title {
  display: flex; align-items: center; gap: 10px;
  min-width: 0; flex: 1;
}
.header-logo { width: 30px; height: 30px; border-radius: 7px; object-fit: contain; flex-shrink: 0; }
.topbar-text { min-width: 0; }
.topbar-text h2 { font-size: 14px; font-weight: 700; color: var(--text); }

.conn-status {
  font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 20px;
  flex-shrink: 0;
}
.conn-status.checking { background: var(--panel-2); color: var(--muted); }
.conn-status.online   { background: var(--accent-soft); color: var(--accent-strong); }
.conn-status.offline  { background: var(--error-soft); color: var(--error); }

.user-block {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.user-info { display: flex; align-items: center; gap: 8px; }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong);
  font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; }
.user-role {
  font-size: 11px; color: var(--muted);
  background: var(--panel-2);
  padding: 1px 6px; border-radius: 3px;
}
.user-actions {
  display: flex; align-items: center; gap: 6px; justify-content: flex-end;
}

.icon-btn {
  width: 30px; height: 30px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  transition: background var(--tr), color var(--tr);
  font-size: 14px; border: none; cursor: pointer; background: none;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

.btn-logout {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: 6px;
  font-size: 12px; color: var(--muted);
  border: 1px solid var(--border);
  background: none; cursor: pointer;
  transition: all var(--tr);
}
.btn-logout:hover { border-color: var(--error); color: var(--error); background: var(--error-soft); }


/* ══════════════════════════════════════════════════════════
   MAIN CONTENT
   ══════════════════════════════════════════════════════════ */
.main-content {
  flex: 1; min-height: 0; overflow: auto;
  display: flex; flex-direction: column;
}

.view-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 14px 18px; overflow: auto; }
.view-panel.hidden { display: none; }
/* شاشة المصنع فقط: تبقى اللوحة نفسها بلا تمرير (بخلاف بقية الشاشات)، وبدلها
   يُمرَّر داخلياً فقط .factory-list أو .factory-cal-wrap (أيهما ظاهر) — هذا ما
   يجعل رأس العمود يلتصق بأعلى القائمة فوراً بدل الانتظار حتى تمرّ الفلاتر
   أعلاه خارج الشاشة. انظر .factory-list وقواعد #factory-list-wrap/.factory-cal-wrap. */
#view-factory.view-panel { overflow: hidden; }

.section-title { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 8px; }


/* ══════════════════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════════════════ */
.btn-primary {
  padding: 9px 22px; background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius-md);
  font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: background var(--tr);
}
.btn-primary:hover { background: var(--accent-mid); }


/* ══════════════════════════════════════════════════════════
   TOASTS
   ══════════════════════════════════════════════════════════ */
.toasts {
  position: fixed; bottom: 20px; left: 20px;
  z-index: 2100; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
[dir="rtl"] .toasts { left: auto; right: 20px; }
.toast {
  padding: 12px 18px; border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg);
  animation: toastIn .25s ease; pointer-events: auto;
  max-width: 320px; line-height: 1.4;
}
@keyframes toastIn {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
.toast.success { background: var(--accent-soft); color: var(--accent-strong); border: 1px solid rgba(22,163,74,.3); }
.toast.error   { background: var(--error-soft); color: var(--error); border: 1px solid #fca5a5; }
.toast.info    { background: var(--info-soft); color: var(--info); border: 1px solid #7dd3fc; }


/* ══════════════════════════════════════════════════════════
   VIEWS NAV
   ══════════════════════════════════════════════════════════ */
.views-nav {
  display: flex; gap: 4px; padding: 8px 14px 0;
  background: var(--panel); border-bottom: 1px solid var(--border);
  overflow-x: auto; flex-shrink: 0;
}
.view-tab {
  padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--muted);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  white-space: nowrap; transition: all var(--tr);
}
.view-tab:hover { background: var(--panel-2); color: var(--text); }
.view-tab.active { color: var(--accent-strong); background: var(--accent-soft); }

/* عدد الطلبات المعلَّقة على تبويب طلبات الأقمشة — نفس شكل status-badge لكن
   دائري صغير يلتصق بنص التبويب مباشرة بدل صف كامل. */
.nav-badge {
  display: inline-block; min-width: 16px; padding: 1px 5px; margin-inline-start: 4px;
  border-radius: 999px; font-size: 10px; font-weight: 700; line-height: 1.4;
  background: var(--error); color: #fff; text-align: center;
}


/* ══════════════════════════════════════════════════════════
   TOOLBAR / FILTERS
   ══════════════════════════════════════════════════════════ */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; padding: 10px 0;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cal-filters-row { padding-top: 0; border-top: 1px dashed var(--border); }
.map-legend-row { padding-top: 0; border-top: 1px dashed var(--border); }

.search-input, .filter-select {
  padding: 7px 12px; border: 1.5px solid var(--border-2); border-radius: var(--radius-md);
  background: var(--panel); color: var(--text); font-size: 13px; font-family: inherit;
  outline: none; transition: border-color var(--tr);
}
.search-input { min-width: 240px; }
.search-input:focus, .filter-select:focus { border-color: var(--accent); }

.btn-ghost-sm {
  padding: 7px 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: none; color: var(--text-2); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all var(--tr);
}
.btn-ghost-sm:hover { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft); }

.btn-ghost {
  padding: 9px 20px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: none; color: var(--text-2); font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-ghost:hover { border-color: var(--text-2); }

.saved-views { display: flex; gap: 6px; flex-wrap: wrap; padding-bottom: 10px; }
.view-chip {
  padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); color: var(--text-2); background: var(--panel);
  transition: all var(--tr);
}
.view-chip:hover, .view-chip.active { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft); }


/* ══════════════════════════════════════════════════════════
   ORDERS TABLE (Excel-like)
   ══════════════════════════════════════════════════════════ */
.table-wrap { flex: 1; min-height: 0; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
.orders-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.orders-table th {
  position: sticky; top: 0; z-index: 2;
  background: var(--panel-2); color: var(--text-2); font-weight: 700;
  text-align: right; padding: 9px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.orders-table td {
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap; color: var(--text);
}
.orders-table tbody tr:hover { background: var(--panel-2); cursor: pointer; }

.col-freeze, .col-freeze2 { position: sticky; background: var(--panel); z-index: 1; }
.col-freeze { right: 0; }
.col-freeze2 { right: var(--freeze2-offset, 140px); }
.orders-table th.col-freeze, .orders-table th.col-freeze2 { background: var(--panel-2); z-index: 3; }
.orders-table tbody tr:hover td.col-freeze,
.orders-table tbody tr:hover td.col-freeze2 { background: var(--panel-2); }

.table-empty { text-align: center; padding: 30px; color: var(--muted); }

/* عمود الملاحظات في آخر الجدول — عريض ويسمح بالالتفاف بخلاف بقية الأعمدة
   (nowrap افتراضياً)، لأن الملاحظات الحرة قد تطول ولا داعي لدفع الجدول أفقياً */
.col-notes { min-width: 220px; max-width: 340px; white-space: normal; word-break: break-word; }

.factory-note-icon { margin-inline-start: 5px; cursor: help; font-size: 13px; }

.status-badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
.status-new              { background: var(--panel-2); color: var(--muted); }
.status-ready_for_scheduling { background: var(--info-soft); color: var(--info); }
.status-scheduled        { background: #ccfbf1; color: #0f766e; }
[data-theme="dark"] .status-scheduled { background: rgba(15,118,110,.25); color: #5eead4; }
.status-in_installation  { background: var(--warn-soft); color: var(--warn); }
.status-completed        { background: var(--accent-soft); color: var(--accent-strong); }
.status-needs_second_visit { background: #ffedd5; color: #c2410c; }
[data-theme="dark"] .status-needs_second_visit { background: rgba(194,65,12,.22); color: #fdba74; }
.status-postponed        { background: #f3e8ff; color: #7e22ce; }
[data-theme="dark"] .status-postponed { background: rgba(126,34,206,.22); color: #d8b4fe; }
.status-cancelled        { background: var(--error-soft); color: var(--error); }

/* حالات طلب القماش — نفس آلية status-badge أعلاه، بادئة fo- لتمييزها عن
   حالات طلب التركيب (منعاً لتصادم لو تشابهت الأسماء مستقبلاً). */
.fo-status-pending   { background: var(--warn-soft); color: var(--warn); }
.fo-status-accepted  { background: var(--info-soft); color: var(--info); }
.fo-status-rejected  { background: var(--error-soft); color: var(--error); }
.fo-status-delivered { background: var(--accent-soft); color: var(--accent-strong); }

.priority-badge { font-size: 11px; font-weight: 700; }
.priority-urgent { color: var(--error); }
.priority-high { color: var(--warn); }
.priority-normal { color: var(--muted); }

.sales-dot {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  margin-inline-end: 5px; vertical-align: middle; flex-shrink: 0;
}

.row-overdue td { background: var(--error-soft); }
.row-overdue:hover td { filter: brightness(0.97); }

/* طلب "تم التركيب نهائياً" — قفل كامل أمام غير الإدارة؛ رمادي باهت بصرياً في
   كل مكان يظهر فيه (الجدول والتقويم) حتى يُميَّز فوراً كطلب مغلق/منتهٍ. */
.row-installed td { background: var(--panel-2); opacity: .65; }
.row-installed:hover td { filter: brightness(0.97); }

.row-open-btn {
  width: 26px; height: 26px; border-radius: 6px; color: var(--muted);
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.row-open-btn:hover { background: var(--panel-3); color: var(--accent-strong); }


/* ══════════════════════════════════════════════════════════
   ORDER DETAIL PANEL (slide-over)
   ══════════════════════════════════════════════════════════ */
.panel-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 2000;
}
.order-panel {
  position: fixed; top: 0; bottom: 0; left: 0;
  width: min(440px, 92vw); background: var(--panel);
  box-shadow: var(--shadow-xl); z-index: 2001;
  display: flex; flex-direction: column;
  animation: panelIn .2s ease;
}
@keyframes panelIn { from { transform: translateX(-100%); } to { transform: translateX(0); } }

.order-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.order-panel-head h3 { font-size: 15px; font-weight: 700; }
.order-panel-body { flex: 1; overflow-y: auto; padding: 16px 18px 30px; }

.order-summary { display: flex; flex-direction: column; gap: 2px; }
.confirmed-banner {
  background: var(--accent-soft); color: var(--accent-strong); font-weight: 700; font-size: 13px;
  text-align: center; padding: 10px; border-radius: var(--radius-md); margin-bottom: 10px;
  border: 1px solid rgba(22,163,74,.3);
}
.summary-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 2px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.summary-label { color: var(--muted); font-weight: 600; flex-shrink: 0; }
.summary-row > span:last-child { color: var(--text); font-weight: 600; text-align: left; }
.summary-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.summary-actions .btn-primary { width: 100%; }
.summary-actions .btn-ghost-sm { width: 100%; text-align: center; padding: 9px; font-size: 13px; }
.sum-cancel-btn:hover { border-color: var(--error); color: var(--error); background: var(--error-soft); }

/* ─── تحصيل الطلب (لوحة الطلب الجانبية) ─── */
.order-collections-section { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.oc-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.oc-schedule-list, .oc-entries-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.oc-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 12px;
}
.oc-row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.oc-row-label { font-weight: 600; }
.oc-row-meta { font-size: 11px; color: var(--muted); }
.oc-row-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.oc-row-amount { font-weight: 700; }
.oc-status-badge { font-size: 10px; padding: 2px 8px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.oc-status-paid { background: var(--accent-soft); color: var(--accent-strong); }
.oc-status-partial { background: var(--warn-soft); color: var(--warn); }
.oc-status-pending { background: var(--panel-2); color: var(--muted); }
.oc-status-overdue { background: var(--error-soft); color: var(--error); }
.oc-row-delete { cursor: pointer; color: var(--muted); background: none; border: none; font-size: 13px; }
.oc-row-delete:hover { color: var(--error); }
.oc-totals-row { display: flex; flex-direction: column; gap: 3px; font-size: 12px; padding-top: 6px; border-top: 1px dashed var(--border); margin-top: 4px; }
.oc-totals-row .oc-total-row { display: flex; justify-content: space-between; }
.oc-totals-row .oc-total-remaining { font-weight: 700; }
.oc-empty-note { font-size: 11px; color: var(--muted); padding: 4px 0; }

.order-form { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; gap: 10px; }
.form-row .form-field { flex: 1; min-width: 0; }
.order-form select, .order-form textarea {
  padding: 9px 12px; border: 1.5px solid var(--border-2); border-radius: var(--radius-md);
  background: var(--bg); color: var(--text); font-size: 13px; font-family: inherit; outline: none;
}
.order-form textarea { resize: vertical; }
.form-checkbox { display: flex; align-items: center; gap: 6px; font-size: 13px; margin: 8px 0; }
.field-hint { font-size: 11px; color: var(--muted); margin-top: -6px; }
.quotation-import-row { display: flex; align-items: center; gap: 8px; }
.quotation-preview {
  border: 1.5px dashed var(--border-2); border-radius: var(--radius-md);
  padding: 8px 10px; font-size: 12px; background: var(--bg-soft, var(--bg));
}
.quotation-preview-title { font-weight: 600; margin: 8px 0 4px; }
.quotation-preview-title:first-child { margin-top: 0; }
.quotation-preview ul { margin: 0; padding-inline-start: 18px; }
.quotation-preview li { margin: 2px 0; }
.quotation-preview-warning { color: var(--warning, #b45309); margin-top: 4px; }
.quotation-preview-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 3px 0; font-size: 12px;
}
.quotation-preview-row > span:first-child { color: var(--muted); }
.quotation-preview-row > span:last-child { font-weight: 600; text-align: left; }

#items-modal {
  left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(480px, 92vw);
}
.items-modal-list { display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow-y: auto; }
.items-modal-item {
  border: 1px solid var(--border-2); border-radius: var(--radius-md); padding: 8px 10px; font-size: 13px;
}
.items-modal-item-title { font-weight: 600; margin-bottom: 2px; }
.items-modal-item-meta { color: var(--muted); font-size: 12px; }

/* مولّد العروض */
.proposal-section-card {
  border: 1.5px solid var(--border-2); border-radius: var(--radius-md); padding: 14px 16px; margin-bottom: 14px;
}
.proposal-section-card .form-row { align-items: flex-end; }
.proposal-section-card .ps-delete { flex-shrink: 0; }
.proposal-section-card .table-wrap { margin: 10px 0; }
.proposal-section-card td input {
  width: 100%; padding: 5px 7px; border: 1.5px solid var(--border-2); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font-size: 12px; font-family: inherit; outline: none;
}
.pe-stat-row { align-items: center; margin-bottom: 6px; }
.pe-stat-row .icon-btn { flex-shrink: 0; }
#proposal-editor-wrap input:disabled, #proposal-editor-wrap textarea:disabled { opacity: .6; cursor: not-allowed; }
.permissions-grid { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; }
.permissions-grid .form-checkbox { margin: 4px 0; }

/* أوامر الشراء */
.po-meta-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.po-meta-item {
  flex: 1 1 150px; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 8px 12px;
}
.po-meta-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.po-meta-value { font-size: 13px; font-weight: 700; color: var(--text); margin-top: 3px; }
.po-totals { display: flex; justify-content: flex-end; gap: 18px; margin-top: 12px; font-size: 14px; font-weight: 700; }
.po-totals .muted { font-weight: 500; color: var(--muted); margin-left: 6px; }

.team-hint {
  font-size: 12px; color: var(--info); background: var(--info-soft);
  padding: 6px 10px; border-radius: var(--radius-sm);
}

.order-panel-extra { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 16px; }

.note-form { display: flex; gap: 6px; margin-bottom: 10px; }
.note-form input {
  flex: 1; padding: 8px 12px; border: 1.5px solid var(--border-2); border-radius: var(--radius-md);
  background: var(--bg); color: var(--text); font-size: 13px; outline: none;
}

.activity-list { display: flex; flex-direction: column; gap: 8px; max-height: 220px; overflow-y: auto; }
.activity-item {
  font-size: 12px; padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--panel-2); border-inline-start: 3px solid var(--border-2);
}
.activity-item.act-note { border-inline-start-color: var(--info); }
.activity-item.act-status_change { border-inline-start-color: var(--accent); }
.activity-item.act-created { border-inline-start-color: var(--muted); }
.activity-item.act-rescheduled, .activity-item.act-reassigned { border-inline-start-color: var(--warn); }
.activity-item.act-confirmed { border-inline-start-color: var(--accent-strong); }
.activity-item.act-unconfirmed { border-inline-start-color: var(--error); }
.activity-meta { color: var(--muted); font-size: 11px; margin-top: 2px; }

.attach-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.attachments-list { display: flex; flex-direction: column; gap: 6px; }
.attachment-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-sm); background: var(--panel-2); font-size: 12px;
}
.attachment-kind { font-size: 10px; font-weight: 700; padding: 1px 7px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-strong); }


/* ══════════════════════════════════════════════════════════
   TEAM MODAL
   ══════════════════════════════════════════════════════════ */
.team-modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 2001; background: var(--panel); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl); padding: 24px; width: min(360px, 90vw);
}
.team-modal h3 { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.team-modal form { display: flex; flex-direction: column; gap: 12px; }
.team-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }


/* ══════════════════════════════════════════════════════════
   TEAMS LIST
   ══════════════════════════════════════════════════════════ */
.teams-list { display: flex; flex-direction: column; gap: 8px; }
.team-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--panel);
}
.team-row-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.team-row-sub { font-size: 12px; color: var(--muted); margin-top: 3px; padding-inline-start: 18px; }
.team-row-load { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.team-inactive-badge { font-size: 10px; padding: 1px 8px; border-radius: 10px; background: var(--error-soft); color: var(--error); }


/* ══════════════════════════════════════════════════════════
   DASHBOARD KPIs
   ══════════════════════════════════════════════════════════ */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px;
}
.kpi-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px; box-shadow: var(--shadow-sm);
}
.kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kpi-value { font-size: 26px; font-weight: 700; color: var(--text); }
.kpi-warn .kpi-value { color: var(--warn); }
.kpi-good .kpi-value { color: var(--accent-strong); }

.workload-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.workload-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--panel);
}
.workload-bar-wrap { flex: 1; height: 8px; background: var(--panel-2); border-radius: 8px; overflow: hidden; }
.workload-bar { height: 100%; background: var(--accent); }


/* ══════════════════════════════════════════════════════════
   CALENDAR
   ══════════════════════════════════════════════════════════ */
.mode-toggle { display: flex; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.mode-btn { padding: 7px 14px; font-size: 12px; font-weight: 700; color: var(--muted); background: var(--panel); }
.mode-btn:hover { background: var(--panel-2); }
.mode-btn.active { background: var(--accent); color: #fff; }

.cal-range-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.calendar-wrap { flex: 1; min-height: 0; overflow: auto; }
.calendar-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.calendar-table th {
  background: var(--panel-2); padding: 8px; font-size: 12px; font-weight: 700;
  border: 1px solid var(--border); text-align: center;
}
.calendar-table td {
  border: 1px solid var(--border); vertical-align: top; padding: 6px;
  height: 110px; width: calc(100% / 8);
}
.cal-team-label { font-size: 12px; font-weight: 700; color: var(--text-2); background: var(--panel-2); padding: 8px; }
.cal-day-overloaded { background: var(--warn-soft); }

.cal-card {
  background: var(--accent-soft); color: var(--accent-strong);
  border-radius: 6px; padding: 4px 7px; font-size: 11px; margin-bottom: 4px;
  cursor: grab; line-height: 1.4;
}
.cal-card.cal-status-cancelled { background: var(--error-soft); color: var(--error); text-decoration: line-through; }
.cal-card.cal-status-completed { opacity: .6; }
.cal-card.cal-status-needs_second_visit { background: #ffedd5; color: #c2410c; }
[data-theme="dark"] .cal-card.cal-status-needs_second_visit { background: rgba(194,65,12,.22); color: #fdba74; }
.cal-card-dragover { outline: 2px dashed var(--accent); }

/* ─── Day timeline (time slots × teams, team-colored) ─── */
.team-legend { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.team-legend-item { display: flex; align-items: center; gap: 5px; cursor: default; position: relative; padding: 3px 2px; }
/* كُبِّرت من 10px وأُضيف حد خفيف — 10px بلا حد كانت تضيع وسط جدول مليء
   بالطلبات الحقيقية؛ var(--border-2) متكيّف مع الوضع الداكن تلقائياً بلا
   الحاجة لتجاوز منفصل، ويعمل عبر كل السياقات الأربعة المشتركة لهذا الصف. */
.team-legend-dot { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; border: 1.5px solid var(--border-2); }
/* فرق إضافية على طلب واحد — أصغر من نقطة الشرح العادية (تظهر عدة نقاط معاً)،
   وحدّها أبيض شفاف (بدل --border-2) لأنها غالباً تظهر فوق خلفية ملوّنة لكتلة التقويم */
.extra-team-dot { width: 10px; height: 10px; border: 1.5px solid rgba(255,255,255,.85); margin-inline-start: 3px; }
.team-legend-vehicle { color: var(--muted); font-weight: 500; }
.legend-divider { display: inline-block; width: 1px; height: 14px; background: var(--border-2); margin: 0 4px; vertical-align: middle; }
.legend-group-label { font-size: 11px; color: var(--muted); font-weight: 600; margin-inline-end: 2px; }

.legend-tooltip {
  display: none; position: absolute; top: 100%; right: 0; margin-top: 4px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); padding: 8px 10px; z-index: 60; white-space: nowrap;
  direction: rtl; text-align: right;
}
.team-legend-item:hover .legend-tooltip { display: block; }
.lgt-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text); padding: 2px 0; }
.lgt-icon { flex-shrink: 0; }

.timeline-table th.col-overtime { background: var(--warn-soft); }
.timeline-table td.col-overtime { background: var(--panel-3); }
[data-theme="dark"] .timeline-table td.col-overtime { background: rgba(217,119,6,.08); }
.timeline-slot-sub { display: block; font-size: 10px; font-weight: 500; opacity: .75; }

.cal-card-team {
  color: #fff; border-radius: 6px; padding: 5px 8px; font-size: 11px;
  margin-bottom: 4px; cursor: grab; line-height: 1.45; box-shadow: var(--shadow-sm);
}
.cal-card-team.cal-status-cancelled { opacity: .5; text-decoration: line-through; }
.cal-card-team.cal-status-completed { opacity: .55; }
.cal-card-team-unslotted { background: var(--panel-2) !important; color: var(--text-2) !important; border: 1px dashed var(--border-2); }

/* ─── Week timeline: hour rows × 7 day columns, absolutely-positioned blocks ─── */
.week-timeline { display: flex; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; background: var(--panel); }
.week-hour-rail { flex-shrink: 0; width: 52px; border-inline-end: 1px solid var(--border); }
.week-hour-rail-head { height: 40px; border-bottom: 1px solid var(--border); background: var(--panel-2); }
.week-hour-label {
  height: 44px; font-size: 10px; color: var(--muted); text-align: center;
  border-bottom: 1px solid var(--border); padding-top: 3px; box-sizing: border-box;
}
.week-hour-label.overtime-label { background: var(--warn-soft); }

.week-days { flex: 1; display: flex; min-width: 0; }
.week-day-col { flex: 1; min-width: 0; border-inline-end: 1px solid var(--border); }
.week-day-col:last-child { border-inline-end: none; }
.week-day-head {
  height: 40px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: var(--text-2); background: var(--panel-2);
  border-bottom: 1px solid var(--border);
}
.week-day-head.is-today { color: var(--accent-strong); background: var(--accent-soft); }

/* الجمعة — يوم عطلة، تمييز رمادي واضح */
.week-day-col.is-off-day .week-day-head { background: var(--border-2); color: var(--muted); }
.week-day-col.is-off-day .week-day-untimed,
.week-day-col.is-off-day .week-day-track { background-color: var(--panel-2); }
[data-theme="dark"] .week-day-col.is-off-day .week-day-head { background: #2a2f38; color: var(--muted); }
[data-theme="dark"] .week-day-col.is-off-day .week-day-untimed,
[data-theme="dark"] .week-day-col.is-off-day .week-day-track { background-color: #1a1f28; }

.week-day-track { position: relative; background-image: repeating-linear-gradient(to bottom, var(--border) 0, var(--border) 1px, transparent 1px, transparent 44px); }

.week-block {
  position: absolute; border-radius: 5px; color: #fff; font-size: 10px; line-height: 1.35;
  padding: 3px 5px; overflow: hidden; cursor: grab; box-shadow: var(--shadow-sm);
  border: 1px solid rgba(255,255,255,.25); direction: rtl; text-align: right;
}
.week-block.cal-status-cancelled { opacity: .5; text-decoration: line-through; }
.week-block.cal-status-completed { opacity: .6; }
/* "تم التركيب نهائياً" — إشارة أقوى من مجرد حالة "مكتمل" (تلك يبلغها أي دور،
   هذه تخص الإدارة حصراً وتعني قفلاً فعلياً) — تدرج رمادي كامل + مؤشر قفل. */
.week-block-installed, .cal-card-team-unslotted.week-block-installed {
  filter: grayscale(85%); opacity: .6; cursor: not-allowed;
}
.week-block-installed::before { content: "🔒 "; }
.move-armed, .cal-card-team.move-armed {
  outline: 3px solid var(--accent-strong, #16a34a); outline-offset: 1px;
  animation: move-armed-pulse 1s ease-in-out infinite;
}
@keyframes move-armed-pulse { 0%, 100% { outline-color: var(--accent-strong, #16a34a); } 50% { outline-color: transparent; } }
.week-block-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.block-sales-dot {
  display: inline-block; width: 18px; height: 18px; border-radius: 50%;
  margin-inline-end: 4px; border: 2px solid rgba(255,255,255,.85); vertical-align: middle; flex-shrink: 0;
}
.block-confirmed-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 13px; height: 13px; border-radius: 50%; background: rgba(255,255,255,.95); color: #16a34a;
  font-size: 9px; font-weight: 900; margin-inline-end: 4px; vertical-align: middle; flex-shrink: 0;
}
.block-measurement-badge {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; margin-inline-end: 4px; vertical-align: middle; flex-shrink: 0;
}
.row-measurement-badge {
  font-size: 12px; margin-inline-start: 4px; vertical-align: middle;
}
.block-repair-badge {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; margin-inline-end: 4px; vertical-align: middle; flex-shrink: 0;
}
.row-repair-badge {
  font-size: 12px; margin-inline-start: 4px; vertical-align: middle;
}
.week-block-sub { opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.week-day-track.dragover-track { background-color: var(--accent-glow); }
.drop-preview {
  position: absolute; inset-inline: 2px; border: 2px dashed var(--accent);
  background: var(--accent-glow); border-radius: 5px; pointer-events: none; z-index: 6;
}
.drop-preview-h { inset-inline: auto; top: 1px; bottom: 1px; }
.week-day-untimed {
  min-height: 22px; padding: 2px 3px; display: flex; flex-direction: column; gap: 2px;
  border-bottom: 1px dashed var(--border-2); background: var(--panel-2);
}
.week-day-untimed.dragover-track { background-color: var(--accent-glow); }
.week-day-untimed .cal-card-team-unslotted { margin: 0; font-size: 10px; padding: 2px 5px; }


/* ─── Day timeline: hour columns × team rows.
   المسار الزمني بأكمله LTR (سلوك تمرير أفقي متوقع/موحّد بين المتصفحات)،
   والنصوص العربية داخل الأعمدة الثابتة تُعاد لـ RTL صراحةً. ─── */
.day-timeline { direction: ltr; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: auto; background: var(--panel); }
.day-hour-header { display: flex; position: sticky; top: 0; z-index: 2; background: var(--panel-2); border-bottom: 1px solid var(--border); }
.day-row-label-head { width: 90px; flex-shrink: 0; border-inline-end: 1px solid var(--border); }
.day-untimed-head {
  width: 110px; flex-shrink: 0; font-size: 11px; font-weight: 700; color: var(--text-2);
  display: flex; align-items: center; justify-content: center; border-inline-end: 1px solid var(--border);
  direction: rtl;
}
.day-hours-head { display: flex; flex-shrink: 0; }
.day-hour-col-label {
  flex-shrink: 0; font-size: 10px; color: var(--muted); text-align: center; padding: 6px 0;
  border-inline-end: 1px solid var(--border); box-sizing: border-box;
}
.day-hour-col-label.overtime-label { background: var(--warn-soft); }

.day-rows { display: flex; flex-direction: column; }
.day-row { display: flex; border-bottom: 1px solid var(--border); }
.day-row-label {
  width: 90px; flex-shrink: 0; display: flex; align-items: center; padding: 0 10px;
  font-size: 12px; font-weight: 700; color: var(--text-2); background: var(--panel-2);
  border-inline-end: 1px solid var(--border); direction: rtl; text-align: right;
}
.day-untimed-cell {
  width: 110px; flex-shrink: 0; padding: 3px; display: flex; flex-direction: column; gap: 2px;
  border-inline-end: 1px solid var(--border); background: var(--panel-2); overflow-y: auto;
  direction: rtl;
}
.day-untimed-cell .cal-card-team-unslotted { margin: 0; font-size: 10px; padding: 2px 5px; }
.day-row-track { position: relative; background-image: repeating-linear-gradient(to right, var(--border) 0, var(--border) 1px, transparent 1px, transparent 64px); }
.day-row-track.dragover-track { background-color: var(--accent-glow); }
.day-untimed-cell.dragover-track { background-color: var(--accent-glow); }



/* ─── Quick-add popup ─── */
.quickadd-popup {
  position: fixed; z-index: 2001; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-xl); width: min(320px, 92vw);
  padding: 14px 16px; max-height: calc(100vh - 20px); overflow-y: auto;
}
/* نوافذ تسجيل الدفعة/إضافة القسط: بلا نقطة نقر مرجعية (خلافاً لـ quickadd-popup
   التي يُحسَب موضعها من إحداثيات النقر عبر openQuickAdd) — تُمركَز بالشاشة مباشرةً. */
#log-payment-modal, #add-installment-modal { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.quickadd-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.quickadd-head h4 { font-size: 14px; font-weight: 700; }
#quickadd-form { display: flex; flex-direction: column; gap: 10px; }
#quickadd-form input, #quickadd-form select {
  padding: 8px 10px; border: 1.5px solid var(--border-2); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font-size: 13px; font-family: inherit; outline: none;
}


/* ══════════════════════════════════════════════════════════
   PRINT SHEET
   ══════════════════════════════════════════════════════════ */
.print-sheet { padding: 10px 0; }
.print-team-block { margin-bottom: 26px; }
.print-team-title { font-size: 16px; font-weight: 700; margin-bottom: 8px; border-bottom: 2px solid var(--accent); padding-bottom: 4px; }
.print-day-block { margin-bottom: 14px; break-inside: avoid; }
.print-day-title { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.print-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.print-table th, .print-table td { border: 1px solid var(--border-2); padding: 6px 8px; text-align: right; }
.print-extra-teams { color: var(--muted); font-size: 11px; }
.print-table th { background: var(--panel-2); }

@media print {
  body * { visibility: hidden; }
  #print-sheet, #print-sheet * { visibility: visible; }
  #print-sheet { position: absolute; top: 0; right: 0; left: 0; }
  .no-print { display: none !important; }
}


/* ══════════════════════════════════════════════════════════
   RESPONSIVE — no horizontal scroll at 360–412px
   ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .topbar { padding: 0 10px; gap: 6px; }
  .user-name, .user-role { display: none; }
  .order-panel { width: 100%; }

  /* العرض الأسبوعي: ٧ أعمدة ما تتسع بوضوح على شاشة جوال — بدل ما تنكمش لحد التداخل،
     نديها عرض أدنى ونخلي .calendar-wrap (اللي أصلاً overflow:auto) يعرض تمرير أفقي. */
  .week-day-col { min-width: 92px; }
  .week-timeline { width: max-content; min-width: 100%; }

  /* شاشة دور المصنع غالباً تُستخدم من جهاز لوحي/جوال في أرض المصنع — أهداف لمس
     أوسع من الحشو (padding) وحده على الشاشات الضيقة. */
  .factory-cal-cell { min-height: 64px; }
  .factory-summary { gap: 4px 10px; font-size: 12px; }
  .factory-card-status, .factory-card-date, .factory-card-note, .factory-card-save { min-height: 40px; }
}

@media (max-width: 480px) {
  .login-card { padding: 28px 20px; }
  .topbar-text h2 { font-size: 13px; }
}


/* ══════════════════════════════════════════════════════════
   MAP VIEW
   ══════════════════════════════════════════════════════════ */
.map-container { flex: 1; min-height: 0; border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border); }
.map-nolocation-count { font-size: 12px; color: var(--muted); font-weight: 600; }

.map-marker-wrap { position: relative; width: 22px; height: 22px; }
.map-marker-pin {
  width: 22px; height: 22px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.map-marker-badge {
  position: absolute; top: -6px; left: -6px; min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 50%; background: #fff; color: #1e293b; font-size: 10px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; border: 1.5px solid rgba(0,0,0,.25);
  box-shadow: 0 1px 3px rgba(0,0,0,.35); line-height: 1;
}
.map-marker-badge-start { background: #16a34a; color: #fff; border-color: #16a34a; }

.map-suggestions-panel {
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--panel);
  margin-bottom: 10px; max-height: 220px; display: flex; flex-direction: column;
}
.map-suggestions-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.map-suggestions-head h4 { font-size: 13px; font-weight: 700; }
.map-suggestions-list { overflow-y: auto; padding: 8px 12px; display: flex; flex-direction: column; gap: 8px; }
.map-suggestion-item {
  font-size: 12px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--panel-2);
  border-inline-start: 3px solid var(--accent);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.map-suggestion-item.suggestion-team_swap { border-inline-start-color: #f59e0b; }
.map-suggestion-text { flex: 1; }
.map-suggestion-savings { font-weight: 700; color: var(--accent-strong); margin-inline-start: 4px; }
.map-suggestion-apply-btn {
  flex-shrink: 0; padding: 6px 10px; border-radius: var(--radius-sm); border: none;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; cursor: pointer;
}
.map-suggestion-apply-btn:disabled { opacity: 0.6; cursor: default; }
.map-popup { font-family: inherit; font-size: 13px; display: flex; flex-direction: column; gap: 4px; min-width: 180px; }
.map-popup-title { font-weight: 700; font-size: 13px; }
.map-popup-row { display: flex; justify-content: space-between; gap: 10px; color: var(--text-2); font-size: 12px; }
.map-popup-row span:last-child { font-weight: 600; color: var(--text); }
.map-popup-open-btn {
  margin-top: 4px; padding: 6px 10px; border-radius: var(--radius-sm); border: none;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; cursor: pointer;
}

.location-field-row { display: flex; gap: 8px; }
.location-field-row input { flex: 1; }
.location-pin-status { font-size: 11px; color: var(--accent-strong); font-weight: 600; margin-top: -6px; }

.location-modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 2002; background: var(--panel); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl); padding: 24px; width: min(560px, 92vw);
}
.location-modal h3 { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.location-picker-map { height: 360px; width: 100%; border-radius: var(--radius-md); margin: 12px 0; border: 1px solid var(--border); }
#location-modal-backdrop { z-index: 2000; }


/* ══════════════════════════════════════════════════════════
   جاهزية المصنع — علم التعارض + شارات الجدول + شاشة دور factory
   ══════════════════════════════════════════════════════════ */
.factory-conflict-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-inline-start: 5px; vertical-align: middle; flex-shrink: 0;
  background: var(--error); box-shadow: 0 0 0 2px var(--error-soft);
}
.factory-nodata-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-inline-start: 5px; vertical-align: middle; flex-shrink: 0;
  background: var(--muted-light); box-shadow: 0 0 0 2px var(--panel-2);
}
.factory-conflict-banner {
  background: var(--warn-soft); color: var(--warn); font-weight: 700; font-size: 13px;
  text-align: center; padding: 10px; border-radius: var(--radius-md); margin-bottom: 10px;
  border: 1px solid rgba(217,119,6,.35);
}
.factory-status-badge { font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 20px; }
/* جديد (رمادي) → قيد التصنيع (أزرق) → جاهز للاستلام (أخضر) — تسلسل واضح؛
   متأخر يبقى أحمر منفصلاً، يمكن تعيينه في أي مرحلة */
.factory-status-new { background: var(--panel-2); color: var(--muted); }
.factory-status-in_production { background: var(--info-soft); color: var(--info); }
.factory-status-ready { background: var(--accent-soft); color: var(--accent-strong); }
.factory-status-delayed { background: var(--error-soft); color: var(--error); }

/* الجولة الثانية: تدرّج ثلاثي (أحمر/أصفر/بلا) بدل التعارض الثنائي — يطابق
   factory_conflict_severity القادم من الخادم. أحمر = --error (تعارض فعلي)،
   أصفر = --warn (تحذير قريب، نفس اللون المستخدم أصلاً لـ factory-conflict-banner). */
.factory-warning-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-inline-start: 5px; vertical-align: middle; flex-shrink: 0;
  background: var(--warn); box-shadow: 0 0 0 2px var(--warn-soft);
}
.factory-finish-date { font-variant-numeric: tabular-nums; }
.factory-finish-date.severity-red { color: var(--error); font-weight: 700; }
.factory-finish-date.severity-yellow { color: var(--warn); font-weight: 700; }
.factory-severity-banner.severity-red { background: var(--error-soft); color: var(--error); border-color: rgba(220,38,38,.35); }
.factory-severity-banner.severity-yellow { background: var(--warn-soft); color: var(--warn); border-color: rgba(217,119,6,.35); }

.factory-search {
  width: 100%; padding: 9px 12px; margin-bottom: 12px; border: 1.5px solid var(--border-2);
  border-radius: var(--radius-md); background: var(--bg); color: var(--text); font-size: 13px;
}
/* حاويتا وضعَي القائمة/التقويم — flex:1/min-height:0 حتى يملأ أيّهما الظاهر
   المساحة المتبقية تحت الفلاتر داخل #view-factory (الآن overflow:hidden أعلاه)،
   والتمرير الفعلي يقع داخل .factory-list أو .factory-cal-wrap نفسه. */
#factory-list-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.factory-cal-wrap { flex: 1; min-height: 0; overflow-y: auto; }
/* ─── قائمة المصنع — صفوف أفقية مضغوطة أشبه بجدول إكسل، بدل بطاقات رأسية
   كبيرة، حتى يرى موظف المصنع أكبر عدد من الطلبات دفعة واحدة بلا تمرير كثير.
   نفس أسماء الأصناف التفاعلية القديمة (.factory-card-status/.factory-card-date/
   .factory-card-note/.factory-card-save) أُبقيت كما هي — منطق الحفظ في app.js
   (event delegation عبر closest(".factory-card")) يعمل دون أي تعديل. */
/* .factory-list هو حاوية التمرير المستقلة للصفوف (نفس فكرة .table-wrap لجدول
   الطلبات) — flex:1/min-height:0/overflow-y:auto حتى يبقى رأس العمود (المُلصَق
   top:0 أدناه) ملتصقاً بأعلى القائمة فوراً عند التمرير، بدل الاعتماد على تمرير
   اللوحة كاملة (بما فيها الفلاتر أعلاه)؛ انظر أيضاً #view-factory وrap# factory-list-wrap
   لبقية سلسلة flex التي تجعل هذا ممكناً. */
.factory-list { display: flex; flex-direction: column; flex: 1; min-height: 0; padding: 4px 0; border: 1px solid var(--border); border-radius: var(--radius-md); overflow-y: auto; }
.factory-row {
  display: grid;
  grid-template-columns: 110px 130px 110px minmax(90px, 1fr) 90px 130px 150px minmax(120px, 1fr) 64px;
  grid-template-areas: "job customer salesperson product schedule status date note save";
  align-items: center; gap: 8px; padding: 6px 10px;
  border-bottom: 1px solid var(--border); font-size: 12.5px;
}
.factory-row:last-child { border-bottom: none; }
.factory-card:hover { background: var(--panel-2); }
.factory-row.is-conflict, .factory-row.severity-red { border-inline-start: 3px solid var(--error); }
.factory-row.severity-yellow { border-inline-start: 3px solid var(--warn); }
.factory-row-header {
  font-weight: 700; font-size: 11px; color: var(--muted); background: var(--panel-2);
  border-bottom: 2px solid var(--border-2); position: sticky; top: 0; z-index: 2;
}
/* حساب مصنع مقيّد فعلياً: الخادم أصلاً لا يُعيد customer_name/salesperson_name
   لهذا الحساب (GET /logistics/factory/orders)، وهذا فقط يُخفي عمودَيهما بصرياً
   ويُرجع الشبكة لقالبها الأصلي بسبعة أعمدة — انظر applyRoleVisibility في app.js
   لتبديل صنف factory-only. */
.factory-list.factory-only .factory-row {
  grid-template-columns: 110px minmax(90px, 1fr) 90px 130px 150px minmax(120px, 1fr) 64px;
  grid-template-areas: "job product schedule status date note save";
}
.factory-list.factory-only .factory-col-customer,
.factory-list.factory-only .factory-col-salesperson { display: none; }
.factory-row-job { grid-area: job; font-weight: 800; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.factory-row-customer, .factory-row-salesperson {
  color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px;
}
.factory-row-customer { grid-area: customer; }
.factory-row-salesperson { grid-area: salesperson; }
.factory-row-product { grid-area: product; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.factory-row-schedule { grid-area: schedule; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.factory-row-schedule.severity-red { color: var(--error); }
.factory-row-schedule.severity-yellow { color: var(--warn); }
.factory-card-status { grid-area: status; }
.factory-row-date-wrap { grid-area: date; display: flex; align-items: center; gap: 4px; min-width: 0; }
.factory-row-lock { flex-shrink: 0; font-size: 12px; cursor: help; }
.factory-card-note { grid-area: note; }
.factory-card-save { grid-area: save; }
.factory-card-status, .factory-card-date, .factory-card-note {
  width: 100%; padding: 5px 8px; border: 1.5px solid var(--border-2); border-radius: var(--radius-sm, 6px);
  background: var(--bg); color: var(--text); font-size: 12px; font-family: inherit;
}
/* لون خلفية خفيف لخانة الحالة يطابق ألوان الشارة القديمة — إشارة سريعة دون فتح القائمة */
.factory-card-status.status-new { background: var(--panel-2); }
.factory-card-status.status-in_production { background: var(--info-soft); color: var(--info); }
.factory-card-status.status-ready { background: var(--accent-soft); color: var(--accent-strong); }
.factory-card-status.status-delayed { background: var(--error-soft); color: var(--error); }
.factory-card-save { flex-shrink: 0; padding: 5px 8px; font-size: 12px; }
/* وميض قصير حول الصف عند الحفظ الناجح — مؤشر إضافي لا يعتمد فقط على التوست */
.factory-card-saved-flash { outline: 2px solid var(--accent); outline-offset: -1px; transition: outline-color .5s ease; }

/* الصفوف المضغوطة أشبه بإكسل مفيدة على شاشة عريضة فقط — على الجوال ٧ أعمدة ما
   تتسع، فترجع لتكديس رأسي مقروء (نفس فكرة .week-day-col)، ورأس الأعمدة يُخفى
   لأنه بلا معنى بعد التكديس. هذا القالب يجب أن يأتي بعد تعريف .factory-row
   الأساسي أعلاه في ترتيب الملف — نفس الخصوصية (class واحد)، فالأحدث بالترتيب
   يفوز داخل media query المطابقة، بغض النظر عن ترتيب الـ media query نفسها. */
@media (max-width: 768px) {
  .factory-row-header { display: none; }
  .factory-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "job status"
      "customer customer"
      "salesperson salesperson"
      "product product"
      "schedule schedule"
      "date date"
      "note note"
      "save save";
    row-gap: 8px; padding: 12px;
  }
  .factory-list.factory-only .factory-row {
    grid-template-areas:
      "job status"
      "product product"
      "schedule schedule"
      "date date"
      "note note"
      "save save";
  }
}

.factory-summary {
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center;
  padding: 10px 14px; margin-bottom: 12px; background: var(--panel-2);
  border-radius: var(--radius-md); font-size: 13px; color: var(--text);
}
.factory-summary-item { font-weight: 600; }
.factory-summary-item.severity-red { color: var(--error); }
.factory-summary-item.severity-yellow { color: var(--warn); }
.factory-summary-sep { color: var(--border-2); }

.factory-filter-row { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.factory-filter-chip {
  padding: 6px 14px; border-radius: 20px; border: 1.5px solid var(--border-2);
  background: var(--bg); color: var(--muted); font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.factory-filter-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.factory-filter-chip[data-filter="red"].active { background: var(--error); border-color: var(--error); }
.factory-filter-chip[data-filter="yellow"].active { background: var(--warn); border-color: var(--warn); }

/* ─── إشارة "هل حُدِّد factory_finish_date؟" (رمادي/أخضر) — منفصلة تماماً عن
   severity (أحمر/أصفر). .factory-nodata-dot رمادية موجودة أصلاً (تُستخدم أيضاً
   في الجدول الرئيسي)، تُعاد هنا كحالة "لم يُحدَّد بعد"؛ الأخضر جديد. */
.factory-dateset-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-inline-start: 5px; vertical-align: middle; flex-shrink: 0;
  background: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft);
}
.factory-summary-item.factory-summary-dateset { color: var(--accent-strong); }
.factory-summary-item.factory-summary-dateunset { color: var(--muted); }

.factory-search-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.factory-search-row .factory-search { flex: 1; margin-bottom: 0; min-width: 160px; }
.factory-date-filter-chip {
  flex-shrink: 0; padding: 7px 12px; border-radius: 20px; border: 1.5px solid var(--accent);
  background: var(--accent-soft); color: var(--accent-strong); font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.factory-date-range-label { font-size: 12px; color: var(--muted); font-weight: 600; flex-shrink: 0; }
#factory-date-from, #factory-date-to { flex-shrink: 0; width: auto; }

/* ─── تقويم شهري لدور المصنع — شبكة أيام بسيطة (لا شبكة ساعات)، منظَّمة حسب
   موعد التركيب. تستهلك نفس _factoryOrdersCache التي تغذّي وضع القائمة. ─── */
.factory-cal-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.factory-cal-nodata-note { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.factory-cal-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px;
  font-size: 11px; font-weight: 700; color: var(--muted); text-align: center;
}
.factory-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.factory-cal-cell {
  min-height: 84px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--panel); padding: 4px; display: flex; flex-direction: column; gap: 3px;
  cursor: pointer; transition: border-color var(--tr);
}
.factory-cal-cell:hover { border-color: var(--accent); }
.factory-cal-cell.is-other-month { opacity: .4; }
.factory-cal-cell.is-today { border-color: var(--accent); border-width: 1.5px; background: var(--accent-soft); }
.factory-cal-cell-num { font-size: 11px; font-weight: 700; color: var(--text-2); }
.factory-cal-chip {
  display: flex; align-items: center; gap: 3px; font-size: 10px; padding: 2px 5px;
  border-radius: 5px; background: var(--panel-2); border-inline-start: 2px solid transparent; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.factory-cal-chip .factory-dateset-dot, .factory-cal-chip .factory-nodata-dot { margin-inline-start: 0; }
.factory-cal-chip.severity-red { border-inline-start-color: var(--error); }
.factory-cal-chip.severity-yellow { border-inline-start-color: var(--warn); }
.factory-cal-chip-more { font-size: 10px; color: var(--muted); font-weight: 600; padding: 2px 5px; }

/* ─── تقويم التحصيل — يعيد استخدام .factory-cal-wrap/grid/cell كاملةً، فقط
   محتوى الرقاقة يختلف (مبالغ متوقعة/محصَّلة بدل أرقام طلبات). ─── */
.coll-cal-chip {
  display: block; font-size: 10px; padding: 2px 5px; border-radius: 5px; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600;
}
.coll-cal-chip-expected { background: var(--panel-2); color: var(--text-2); }
.coll-cal-chip-collected { background: var(--accent-soft); color: var(--accent-strong); }

/* ══════════════════════════════════════════════════════════
   MYJOBS (عرض مبسّط للجوال)
   ══════════════════════════════════════════════════════════ */
.myjobs-list { display: flex; flex-direction: column; gap: 10px; padding: 4px 0; }
.myjob-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px 14px; cursor: pointer;
}
.myjob-card:hover { border-color: var(--accent); }
/* بطاقة طلب قماش — تُعيد استخدام .myjob-card بالكامل لكنها غير قابلة للنقر
   (لا لوحة تفاصيل منفصلة لها)، فتُلغى مؤشرة "قابل للنقر" الموروثة. */
.fabric-order-card { cursor: default; }
.fabric-order-card:hover { border-color: var(--border); }
.fabric-order-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.fabric-order-actions input[type="date"] {
  padding: 5px 8px; border: 1.5px solid var(--border-2); border-radius: var(--radius-sm);
  font-size: 12px; background: var(--panel); color: var(--text);
}

/* صفوف الألوان القابلة للتكرار داخل مودال الكتالوج */
.fo-color-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.fo-color-row input { flex: 1; min-width: 0; padding: 6px 8px; border: 1.5px solid var(--border-2); border-radius: var(--radius-sm); font-size: 13px; background: var(--panel); color: var(--text); }
.myjob-card-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; margin-bottom: 6px; gap: 6px; }
.myjob-participating-badge {
  font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 20px;
  background: var(--info-soft); color: var(--info); flex-shrink: 0;
}
.myjob-card-name { font-weight: 700; font-size: 15px; }
.myjob-card-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.myjob-card-factory {
  display: flex; align-items: center; gap: 6px; margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--border-2); font-size: 12px; flex-wrap: wrap;
}
.myjob-card-factory-label { color: var(--muted); font-weight: 600; }

/* قائمة مضغوطة اختيارية لسطح المكتب — نفس فلسفة صفوف المصنع (.factory-row):
   صف أفقي واحد لكل طلب بدل بطاقة رأسية، حتى يمسح مندوب المبيعات مهامه
   وملاحظاتها بسرعة دون فتح كل طلب على حدة. */
.myjobs-rows-wrap { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.myjob-row {
  display: grid;
  grid-template-columns: 100px minmax(110px, 1fr) minmax(90px, 1fr) 110px 170px minmax(140px, 1.4fr);
  align-items: center; gap: 10px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); font-size: 12.5px; cursor: pointer;
}
.myjob-row:last-child { border-bottom: none; }
.myjob-row:hover { background: var(--panel-2); }
.myjob-row-header {
  font-weight: 700; font-size: 11px; color: var(--muted); background: var(--panel-2);
  border-bottom: 2px solid var(--border-2); cursor: default;
}
.myjob-row-date { font-variant-numeric: tabular-nums; white-space: nowrap; }
.myjob-row-customer { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.myjob-row-product { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.myjob-row-factory { display: flex; align-items: center; gap: 4px; flex-wrap: nowrap; white-space: nowrap; }
.myjob-row-note {
  color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* الجوال: ٦ أعمدة ما تتسع، فترجع القائمة لتكديس رأسي مقروء — البطاقات تبقى
   الوضع الافتراضي أصلاً على الجوال، لكن إن بدّل المستخدم لوضع القائمة يدوياً
   يجب ألا تنكسر. هذا الـ media query يأتي بعد تعريف .myjob-row الأساسي أعلاه
   في ترتيب الملف عمداً — نفس الخصوصية (class واحد)، فالأحدث بالترتيب يفوز. */
@media (max-width: 768px) {
  .myjob-row-header { display: none; }
  .myjob-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "date status"
      "customer customer"
      "product product"
      "factory factory"
      "note note";
    row-gap: 6px; padding: 12px;
  }
  .myjob-row-date { grid-area: date; }
  .myjob-row .status-badge { grid-area: status; justify-self: start; }
  .myjob-row-customer { grid-area: customer; white-space: normal; }
  .myjob-row-product { grid-area: product; white-space: normal; }
  .myjob-row-factory { grid-area: factory; }
  .myjob-row-note { grid-area: note; white-space: normal; }
}
