/* ============================================================
   سیستم طراحی — کنترل نمایندگی
   پالت: سرمه‌ای/آبی شرکتی + طلایی
   ============================================================ */

@import url('https://db.onlinewebfonts.com/c/1605a655ba0a3246ce5eca3eaff6c5c2?family=B+Lotus');
@import url('https://db.onlinewebfonts.com/c/705f6e31755b0e44e007d99a5f634f4d?family=B+Lotus+Bold');
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css');

:root {
  --navy-950: #071a3f;
  --navy-900: #0c2454;
  --navy-800: #123168;
  --navy-700: #1c4184;

  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --border: #dde3ec;
  --border-soft: #e7ebf1;

  --gold: #cf9b3f;
  --gold-bright: #e0ac4c;
  --gold-soft: #f6ead1;

  --text: #16233f;
  --muted: #64708a;
  --muted-2: #97a1b6;

  --green: #1f9d67;
  --green-soft: #e2f6ec;
  --amber: #c9840f;
  --amber-soft: #fbedd3;
  --red: #c14a3f;
  --red-soft: #fbe6e3;
  --blue-soft: #e4ecfb;

  --font-body: 'B Lotus', 'Vazirmatn', Tahoma, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-tag: 'B Lotus Bold', 'B Lotus', 'Vazirmatn', Tahoma, sans-serif;

  --radius: 6px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; overflow-x: hidden; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.65;
  overflow-x: hidden;
  max-width: 100vw;
}

img, video, canvas, svg { max-width: 100%; height: auto; }

a { color: var(--navy-700); }

/* ---------- پوسته اصلی ---------- */
.shell {
  display: grid;
  grid-template-columns: 1fr 240px;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(185deg, var(--navy-900), var(--navy-950));
  padding: 26px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  color: #dbe4f5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 30px;
  padding: 0 6px;
}
.brand .mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(224,172,76,0.5);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand .mark svg { width: 21px; height: 21px; }
.brand .name { font-size: 13.5px; font-weight: 700; line-height: 1.3; color: #fff; }
.brand .sub { font-size: 10px; color: var(--gold-bright); font-family: var(--font-tag); letter-spacing: 1px; }

.navlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.navlist a {
  display: flex; align-items: center; gap: 11px;
  color: rgba(219,228,245,0.75);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: var(--radius);
  border-right: 2px solid transparent;
  transition: background .15s, color .15s;
}
.navlist a .ic {
  font-family: var(--font-tag); font-size: 10.5px; color: rgba(219,228,245,0.45);
  width: 20px; height: 20px; text-align: center; line-height: 20px;
  background: rgba(255,255,255,0.06); border-radius: 5px;
}
.navlist a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.navlist a.active {
  background: rgba(224,172,76,0.14);
  color: #fff;
  border-color: var(--gold-bright);
}
.navlist a.active .ic { color: var(--navy-950); background: var(--gold-bright); }

.sidebar-foot {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 11px;
  color: rgba(219,228,245,0.4);
  font-family: var(--font-tag);
  letter-spacing: 0.3px;
}

.content { padding: 36px 42px; max-width: 900px; }
.content.wide { max-width: 1120px; }

.page-head { margin-bottom: 26px; }
.eyebrow {
  font-family: var(--font-tag);
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--gold);
  text-transform: uppercase;
  margin-bottom: 7px;
  font-weight: 600;
}
.page-head h1 { margin: 0 0 6px; font-size: 25px; font-weight: 800; color: var(--navy-950); }
.page-head p { margin: 0; color: var(--muted); font-size: 13.5px; }

/* ---------- کارت‌ها ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(15,30,65,0.04);
}
.panel h2 {
  font-size: 15px; margin: 0 0 16px; font-weight: 700; color: var(--navy-950);
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 14px; border-bottom: 1px solid var(--border-soft);
}
.panel h3 { font-size: 12px; margin: 20px 0 10px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; font-family: var(--font-tag); }

/* ---------- فرم‌ها ---------- */
label { display: block; font-size: 12.5px; color: var(--muted); margin: 14px 0 6px; font-weight: 500; }
input, select, textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
  background: var(--surface-2);
  color: var(--text);
}
input::placeholder { color: var(--muted-2); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); background: #fff; box-shadow: 0 0 0 3px rgba(207,155,63,0.15); }

button {
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 700;
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 11px 20px;
  background: var(--gold);
  color: #fff;
  margin-top: 16px;
  transition: filter .15s, box-shadow .15s;
}
button:hover { filter: brightness(1.06); box-shadow: 0 2px 8px rgba(207,155,63,0.35); }
button.secondary { background: var(--surface); color: var(--navy-800); border-color: var(--border); }
button.secondary:hover { border-color: var(--navy-700); box-shadow: none; }
button.small { padding: 7px 14px; font-size: 12.5px; margin-top: 0; }
button:disabled { opacity: .4; cursor: not-allowed; filter: none; box-shadow: none; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--red); font-size: 13px; margin-top: 10px; }
.success { color: var(--green); font-size: 13px; margin-top: 10px; }

/* ---------- نشان وضعیت ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  font-family: var(--font-tag);
  letter-spacing: .3px;
  border: 1px solid transparent;
}
.badge.blue { background: var(--blue-soft); color: var(--navy-700); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.gray { background: var(--surface-2); color: var(--muted); border-color: var(--border); }

/* ---------- جدول ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px; border-bottom: 1px solid var(--border-soft); text-align: right; }
th { color: var(--muted-2); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; font-family: var(--font-tag); }
tr:last-child td { border-bottom: none; }
.mono { font-family: var(--font-mono); direction: ltr; text-align: left; unicode-bidi: plaintext; }

/* ---------- بستهٔ اسکرول افقی جدول (برای موبایل) ---------- */
/* وقتی عرض جدول از عرض صفحه بیشتر شود، به‌جای بر هم خوردن چیدمان کل
   صفحه، فقط همین جدول به‌صورت کنترل‌شده اسکرول افقی پیدا می‌کند. */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
.table-wrap table { min-width: 560px; }

/* ---------- QR ---------- */
.qr-box { text-align: center; padding: 22px; background: var(--surface-2); border-radius: var(--radius-lg); border: 1.5px dashed var(--border); }
.qr-code-text { font-family: var(--font-mono); font-size: 20px; letter-spacing: 2px; margin-top: 12px; color: var(--navy-800); direction: ltr; font-weight: 600; }

/* ---------- خط زمانی ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative;
  padding: 0 26px 20px 0;
  border-right: 2px solid var(--border);
  margin-right: 6px;
}
.timeline li::before {
  content: "";
  position: absolute; right: -6px; top: 2px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted-2);
  border: 2px solid var(--surface);
}
.timeline li.done::before { background: var(--gold); }
.timeline li:last-child { border-color: transparent; padding-bottom: 0; }

/* ---------- ستاره نظرسنجی ---------- */
.stars { display: flex; gap: 6px; direction: ltr; justify-content: flex-end; }
.stars button { background: none; border: none; color: var(--border); font-size: 27px; padding: 2px 4px; margin: 0; }
.stars button.active { color: var(--gold); }

video, canvas.scanner { width: 100%; border-radius: var(--radius-lg); background: #000; border: 1px solid var(--border); }

/* ---------- گام‌های شماره‌دار ---------- */
.steprow { display: flex; align-items: flex-start; gap: 12px; }
.stepnum {
  flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%;
  background: var(--gold); color: #fff; font-family: var(--font-tag); font-weight: 600;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.stepnum.done { background: var(--green); }
.stepnum.pending { background: var(--border); color: var(--muted); }

/* ---------- بازرسی ظاهری ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.photo-slot {
  aspect-ratio: 1;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  background: var(--surface-2);
  cursor: pointer;
  overflow: hidden;
  position: relative;
  text-align: center;
}
.photo-slot span.lbl { font-size: 11px; color: var(--muted); font-weight: 600; }
.photo-slot span.ic { font-size: 20px; color: var(--muted-2); }
.photo-slot.filled { border-style: solid; border-color: var(--green); }
.photo-slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-slot input { display: none; }
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); border-radius: 999px; padding: 7px 14px;
  font-size: 12.5px; cursor: pointer; background: var(--surface-2); color: var(--muted);
  user-select: none;
}
.chip.active { background: var(--red-soft); border-color: var(--red); color: var(--red); font-weight: 600; }

/* ---------- دوربین زنده ---------- */
.camfeed {
  position: relative;
  aspect-ratio: 16/10;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.025) 0px, rgba(255,255,255,0.025) 1px, transparent 1px, transparent 3px),
    radial-gradient(ellipse at center, #22303f 0%, #101823 75%, #0a0f17 100%);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid #26313f;
}
.camfeed .grid-overlay {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px);
  background-size: 12.5% 12.5%;
}
.camfeed .carsil { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.camfeed .carsil svg { width: 46%; opacity: .35; stroke: #8fa5bd; }
.camfeed .cam-top {
  position: absolute; top: 0; right: 0; left: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  font-family: var(--font-mono); font-size: 11px; color: #dfe6ef;
  background: linear-gradient(to bottom, rgba(0,0,0,0.55), transparent);
}
.camfeed .live-pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(214,73,60,0.9); color: #fff; padding: 3px 9px; border-radius: 4px;
  font-family: var(--font-tag); font-size: 10.5px; letter-spacing: 1px;
}
.camfeed .live-dot { width: 6px; height: 6px; border-radius: 50%; background: #fff; animation: pulseDot 1.4s infinite; }
@keyframes pulseDot { 0%,100% { opacity: 1; } 50% { opacity: .25; } }
.camfeed .cam-bottom {
  position: absolute; bottom: 0; right: 0; left: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  font-family: var(--font-mono); font-size: 11px; color: #cfd8e3;
  background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
}
.camfeed .corner { position: absolute; width: 16px; height: 16px; border-color: rgba(224,172,76,0.55); }
.camfeed .corner.tl { top: 30px; right: 10px; border-top: 2px solid; border-right: 2px solid; }
.camfeed .corner.tr { top: 30px; left: 10px; border-top: 2px solid; border-left: 2px solid; }
.camfeed .corner.bl { bottom: 30px; right: 10px; border-bottom: 2px solid; border-right: 2px solid; }
.camfeed .corner.br { bottom: 30px; left: 10px; border-bottom: 2px solid; border-left: 2px solid; }
.camfeed.offline { display: flex; align-items: center; justify-content: center; }
.camfeed.offline .msg { color: var(--muted-2); font-family: var(--font-tag); font-size: 12px; letter-spacing: .5px; z-index: 2; }
.camfeed.offline .grid-overlay, .camfeed.offline .carsil { opacity: .3; }

/* ---------- تابلوی وضعیت زنده ---------- */
.flipboard {
  background: var(--navy-950);
  border-radius: var(--radius-lg);
  padding: 6px 0;
  overflow: hidden;
}
.flip-row {
  display: grid;
  grid-template-columns: 100px 1fr 130px 150px;
  align-items: center;
  gap: 14px;
  padding: 14px 22px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-family: var(--font-mono);
}
.flip-row:last-child { border-bottom: none; }
.flip-row.head {
  font-family: var(--font-tag);
  font-size: 10.5px;
  color: rgba(219,228,245,0.4);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding-top: 8px;
  padding-bottom: 10px;
}
.flip-cell { font-size: 15px; letter-spacing: 1.5px; color: #eaeff8; }
.flip-cell.plate { color: var(--gold-bright); font-weight: 600; direction: ltr; text-align: left; }
.flip-cell.status { font-family: var(--font-body); letter-spacing: 0; font-size: 12.5px; }
.flip-empty { padding: 34px; text-align: center; color: rgba(219,228,245,0.4); font-family: var(--font-tag); font-size: 12px; letter-spacing: .5px; }

/* ============================================================
   بهبودهای مخصوص موبایل
   ============================================================ */

@media (max-width: 860px) {
  .shell {
    display: flex;
    flex-direction: column;
  }
  
  .content {
    order: 2;
    padding: 14px 12px 30px;
    max-width: 100%;
  }
  
  .content.wide {
    max-width: 100%;
  }
  
  .sidebar {
    order: 1;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 10px 12px;
    gap: 6px;
    align-items: center;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
  }
  
  .brand {
    margin-bottom: 0;
    flex: 0 0 auto;
    gap: 8px;
  }
  
  .brand .mark {
    width: 32px;
    height: 32px;
  }
  
  .brand .mark svg {
    width: 18px;
    height: 18px;
  }
  
  .brand .name {
    font-size: 12px;
  }
  
  .brand .sub {
    font-size: 8px;
  }
  
  .navlist {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 2px;
    flex: 1;
    justify-content: flex-end;
  }
  
  .navlist a {
    padding: 6px 10px;
    font-size: 11px;
    gap: 4px;
    min-height: 36px;
    border-right: none;
    border-bottom: 2px solid transparent;
    border-radius: 4px;
  }
  
  .navlist a .ic {
    width: 28px;
    height: 28px;
    line-height: 28px;
    font-size: 12px;
  }
  
  .sidebar-foot {
    display: none;
  }
  
  .page-head h1 {
    font-size: 20px;
  }
  
  .page-head p {
    font-size: 12px;
  }
  
  .panel {
    padding: 16px;
    margin-bottom: 14px;
  }
  
  .panel h2 {
    font-size: 14px;
    flex-wrap: wrap;
    gap: 6px;
  }
  
  .row {
    flex-direction: column;
    gap: 0;
  }
  
  .row > * {
    flex: none;
  }
  
  button {
    min-height: 48px;
    padding: 12px 16px;
    font-size: 14px;
    width: 100%;
  }
  
  button.small {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 12px;
    width: auto;
  }
  
  input, select, textarea {
    font-size: 16px !important;
    padding: 12px 12px;
    min-height: 48px;
  }
  
  /* جدول‌ها با اسکرول */
  .panel table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 12px;
  }
  
  .panel table tbody,
  .panel table thead,
  .panel table tr {
    display: table;
    width: 100%;
  }
  
  th, td {
    padding: 8px 6px;
    font-size: 11px;
  }
  
  /* تابلوی زنده */
  .flip-row {
    grid-template-columns: 70px 1fr 80px 90px;
    gap: 6px;
    padding: 10px 12px;
  }
  
  .flip-cell {
    font-size: 11px;
  }
  
  .flip-cell.plate {
    font-size: 12px;
  }
  
  .flip-row.head {
    font-size: 9px;
    padding: 6px 12px;
  }
  
  /* عکس‌های بازرسی */
  .photo-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  
  .photo-slot {
    min-height: 100px;
    aspect-ratio: 4/3;
  }
  
  .photo-slot span.lbl {
    font-size: 10px;
  }
  
  .photo-slot span.ic {
    font-size: 18px;
  }
  
  /* QR */
  .qr-box {
    padding: 16px;
  }
  
  .qr-code-text {
    font-size: 16px;
    word-break: break-all;
  }
  
  /* چپ‌ها */
  .chip {
    font-size: 11px;
    padding: 6px 12px;
    min-height: 36px;
  }
  
  .badge {
    font-size: 10px;
    padding: 3px 8px;
  }
  
  /* دوربین */
  .camfeed {
    aspect-ratio: 16/9;
  }
  
  .camfeed .cam-top,
  .camfeed .cam-bottom {
    font-size: 9px;
    padding: 6px 8px;
  }
  
  .camfeed .live-pill {
    font-size: 9px;
    padding: 2px 6px;
  }
  
  .camfeed .corner {
    width: 12px;
    height: 12px;
  }
  
  /* نظرسنجی */
  .stars button {
    font-size: 30px;
    padding: 4px 6px;
  }
  
  /* ورود */
  .login-card {
    margin: 12px;
    padding: 20px;
  }
  
  .role-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }
  
  .role-btn {
    padding: 10px 6px;
    font-size: 11px;
    min-height: 56px;
  }
  
  .role-btn i {
    font-size: 16px;
  }
  
  /* صفحه رهگیری */
  .track-wrap {
    padding: 12px 10px 30px;
  }
  
  /* دکمه‌های عملیاتی در کارت جک */
  #jobCard .row {
    flex-direction: row;
    gap: 6px;
  }
  
  #jobCard .row button {
    flex: 1;
    min-height: 44px;
  }
  
  /* پیام‌ها */
  .error, .success {
    font-size: 13px;
    padding: 6px 0;
  }
  
  /* گام‌های شماره‌دار */
  .steprow {
    gap: 10px;
  }
  
  .stepnum {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .flip-row {
    grid-template-columns: 50px 1fr 60px 70px;
    gap: 4px;
    padding: 6px 8px;
  }
  
  .flip-cell {
    font-size: 9px;
  }
  
  .flip-cell.plate {
    font-size: 10px;
  }
  
  .photo-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }
  
  .photo-slot {
    min-height: 70px;
  }
  
  .page-head h1 {
    font-size: 17px;
  }
  
  .panel {
    padding: 12px;
  }
  
  .navlist a {
    font-size: 10px;
    padding: 4px 6px;
    min-height: 30px;
  }
  
  .navlist a .ic {
    width: 24px;
    height: 24px;
    line-height: 24px;
    font-size: 10px;
  }
  
  .brand .name {
    font-size: 10px;
  }
  
  .brand .mark {
    width: 28px;
    height: 28px;
  }
  
  .brand .mark svg {
    width: 16px;
    height: 16px;
  }
  
  .role-btn {
    font-size: 10px;
    padding: 8px 4px;
    min-height: 48px;
  }
  
  .role-btn i {
    font-size: 14px;
  }
}

/* جلوگیری از زوم خودکار در iOS */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  select,
  textarea,
  input {
    font-size: 16px !important;
  }
}

/* بهبود اسکرول */
* {
  -webkit-overflow-scrolling: touch;
}

/* بهبود لمس */
a, button, .clickable, .chip, .photo-slot, .role-btn {
  touch-action: manipulation;
}