/* ============ فونت ============ */
@font-face {
  font-family: 'Vazirmatn';
  src: url('../assets/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('../assets/Vazirmatn-Medium.woff2') format('woff2');
  font-weight: 500; font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('../assets/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700; font-display: swap;
}

/* ============ پایه ============ */
:root {
  --green: #15803d; --green-dark: #14532d; --green-light: #dcfce7;
  --red: #dc2626; --red-light: #fee2e2;
  --blue: #2563eb; --teal: #0f766e;
  --bg: #f1f5f9; --card: #ffffff; --line: #e2e8f0;
  --text: #0f172a; --muted: #64748b;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Vazirmatn', Tahoma, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.7;
}
h1,h2,h3,h4 { margin: 0; font-weight: 700; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 13px; }

/* ============ هدر ============ */
.topbar {
  display: flex; align-items: center; gap: 18px;
  background: linear-gradient(135deg, #14532d, #166534 60%, #0f766e);
  color: #fff; padding: 10px 18px; position: sticky; top: 0; z-index: 900;
  box-shadow: 0 2px 10px rgba(0,0,0,.25); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { font-size: 30px; }
.brand h1 { font-size: 17px; line-height: 1.3; }
.brand small { font-size: 11.5px; opacity: .85; }
.city-legend { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.city-chip {
  font-size: 11.5px; padding: 3px 11px; border-radius: 999px;
  background: rgba(255,255,255,.13); border: 1px solid rgba(255,255,255,.25);
  white-space: nowrap;
}
.city-chip.on { background: #16a34a; border-color: #22c55e; font-weight: 700; }
.city-chip.off { background: rgba(220,38,38,.35); border-color: rgba(248,113,113,.6); }
.city-chip.more { opacity: .8; }
.top-actions { display: flex; gap: 8px; }

/* ============ دکمه‌ها ============ */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-size: 13px;
  transition: .15s; text-decoration: none; display: inline-flex; align-items: center; gap: 5px;
}
.btn:hover { background: #f8fafc; transform: translateY(-1px); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 700; }
.btn.primary:hover { background: #166534; }
.btn.ghost { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.3); }
.topbar .btn.ghost:hover { background: rgba(255,255,255,.22); }
.modal .btn.ghost { background: #f1f5f9; color: var(--text); border-color: var(--line); }
.btn.small { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn.big { width: 100%; justify-content: center; padding: 14px; font-size: 15.5px; margin-top: 4px; }
.btn.danger { color: var(--red); border-color: #fecaca; background: #fff5f5; }
.btn.danger:hover { background: var(--red-light); }
.btn.pdf, .pdf-all { background: #b91c1c; border-color: #b91c1c; color: #fff; font-weight: 700; }
.btn.pdf:hover, .pdf-all:hover { background: #991b1b; }
.file-btn { cursor: pointer; }

/* ============ چیدمان ============ */
.layout { display: grid; grid-template-columns: 390px 1fr; gap: 14px; padding: 14px; align-items: start; }
.panel { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 76px; max-height: calc(100vh - 90px); overflow-y: auto; padding-left: 4px; }
.card { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 14px; border: 1px solid var(--line); }
.card-title { font-size: 14px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; color: var(--green-dark); }
.step-no {
  background: var(--green); color: #fff; width: 24px; height: 24px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700;
}
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 9px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea,
.modal input[type="text"], .modal input[type="date"], .modal input[type="time"],
.modal input[type="number"], .modal select, .modal textarea,
.start-search input {
  border: 1px solid #cbd5e1; border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%;
  outline: none; transition: .15s;
}
.field input:focus, .field select:focus, .modal input:focus, .modal select:focus, .modal textarea:focus {
  border-color: var(--green); box-shadow: 0 0 0 3px rgba(21,128,61,.12);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 7px; font-size: 12.5px; margin: 5px 0; cursor: pointer; color: #334155; }
.check input { width: 16px; height: 16px; accent-color: var(--green); }
/* فهرست زنجیره‌ها: ستونی، راست‌چین، الفبایی، یک مورد در هر ردیف */
.chain-box {
  border: 1px solid var(--line) !important;
  border-radius: 8px;
  padding: 6px !important;
  max-height: 240px;
  overflow-y: auto;
  background: #f8fafc;
  display: flex !important;
  flex-direction: column !important;
  flex-wrap: nowrap !important;
  align-items: stretch !important;
  gap: 2px !important;
  grid-template-columns: none !important;
  direction: rtl !important;
  text-align: right !important;
}
.chain-box label.chain-row,
.chain-box label.chain-all-row {
  display: flex !important;
  flex: 0 0 auto !important;
  width: 100% !important;
  align-items: center !important;
  gap: 8px !important;
  font-size: 12px !important;
  line-height: 1.8;
  padding: 5px 8px !important;
  margin: 0 !important;
  cursor: pointer;
  border-radius: 6px;
  text-align: right !important;
  direction: rtl !important;
  white-space: nowrap;
  box-sizing: border-box;
}
.chain-box label.chain-row-alt { background: #f1f5f9; }
.chain-box label.chain-row:hover { background: #dcfce7 !important; }
.chain-box input[type="checkbox"] {
  accent-color: var(--green);
  margin: 0 !important;
  flex: 0 0 auto !important;
  width: 15px !important;
  height: 15px !important;
}
.chain-box .chain-name {
  flex: 1 1 auto !important;
  text-align: right !important;
  direction: rtl !important;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chain-box .chain-count {
  flex: 0 0 auto !important;
  color: #64748b;
  font-size: 11px;
  background: #e2e8f0;
  border-radius: 999px;
  padding: 0 8px;
  min-width: 24px;
  text-align: center;
}
.chain-box label.chain-all-row {
  font-weight: 700 !important;
  color: var(--green-dark);
  background: var(--green-light) !important;
  border-bottom: 1px solid #86efac !important;
  border-radius: 6px 6px 0 0 !important;
  margin-bottom: 3px !important;
  position: sticky;
  top: -6px;
  z-index: 1;
}
.chain-box label.chain-all-row .chain-count { background: #bbf7d0; color: #14532d; }
.start-search { display: flex; gap: 6px; margin-bottom: 6px; }
.start-coords { font-size: 11.5px; color: var(--teal); background: #f0fdfa; border: 1px dashed #99f6e4; border-radius: 7px; padding: 5px 8px; }
.form-msg { color: var(--red); font-size: 12px; margin-top: 6px; min-height: 16px; }
.form-msg.ok { color: var(--green); }

/* گزینه غیرفعال قرمز در سلکت‌ها */
select option.off { color: var(--red); font-weight: 700; background: var(--red-light); }
select option.on { color: var(--green); font-weight: 700; }

/* ============ نقشه ============ */
.workspace { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.map-toolbar { display: flex; gap: 10px; align-items: center; }
.route-banner {
  flex: 1; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 14px; font-size: 12.5px; box-shadow: var(--shadow);
}
.route-banner.live { border-color: #22c55e; background: #f0fdf4; color: #166534; font-weight: 500; }
.route-banner.est { border-color: #f59e0b; background: #fffbeb; color: #92400e; }
#map { height: 64vh; min-height: 380px; border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); z-index: 1; }

/* نشانگرهای شماره‌دار */
.v-marker { display: flex; align-items: center; justify-content: center; }
.v-pin {
  width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
}
.v-pin b { transform: rotate(45deg); color: #fff; font-size: 12px; font-weight: 700; }
.v-pin.start { background: #0f172a; width: 26px; height: 26px; }
.v-pin.visited { box-shadow: 0 0 0 3px rgba(34,197,94,.45); }
.leaflet-popup-content { font-family: inherit; font-size: 12.5px; margin: 12px 14px; direction: rtl; }
.popup-name { font-weight: 700; margin-bottom: 3px; }
.popup-row { color: #475569; margin: 2px 0; }
.popup-links { margin-top: 7px; display: flex; gap: 6px; }
.popup-links a { font-size: 11px; text-decoration: none; padding: 3px 8px; border-radius: 6px; color: #fff; }
.popup-links a.g { background: #16a34a; } .popup-links a.n { background: #2563eb; } .popup-links a.b { background: #ea580c; }

/* ============ نتایج ============ */
.results { display: flex; flex-direction: column; gap: 14px; }
.summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat {
  background: #fff; border-radius: 12px; padding: 13px 15px; border: 1px solid var(--line);
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat .v { font-size: 22px; font-weight: 700; color: var(--green-dark); }
.stat .l { font-size: 11.5px; color: var(--muted); }
.stat::before { content: ''; position: absolute; right: 0; top: 0; bottom: 0; width: 4px; background: var(--green); }
.stat.blue::before { background: var(--blue); } .stat.orange::before { background: #ea580c; }
.stat.purple::before { background: #9333ea; } .stat.teal::before { background: var(--teal); }
.results-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.results-actions .btn.ghost { background: #fff; color: var(--text); border-color: var(--line); }

.empty-state { background: #fff; border: 2px dashed #cbd5e1; border-radius: 14px; padding: 50px 20px; text-align: center; color: var(--muted); }
.empty-icon { font-size: 48px; }
.empty-state h3 { color: #334155; margin: 8px 0 4px; }

/* کارت مسیر */
.route-card { background: #fff; border-radius: 12px; border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 14px; }
.route-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: #fff; flex-wrap: wrap;
}
.route-head h3 { font-size: 15px; }
.route-head .stat-pill { background: rgba(255,255,255,.18); border-radius: 999px; padding: 3px 11px; font-size: 11.5px; white-space: nowrap; }
.route-head .spacer { flex: 1; }
.route-progress-wrap { padding: 8px 16px 0; }
.route-progress { height: 8px; background: #e2e8f0; border-radius: 99px; overflow: hidden; }
.route-progress i { display: block; height: 100%; background: linear-gradient(90deg, #22c55e, #16a34a); transition: width .3s; }
.route-progress-label { font-size: 11px; color: var(--muted); margin: 3px 0 6px; }

table.stops { width: 100%; border-collapse: collapse; }
table.stops th, table.stops td { padding: 9px 10px; border-bottom: 1px solid #f1f5f9; text-align: right; vertical-align: top; font-size: 12.3px; }
table.stops th { background: #f8fafc; color: #475569; font-weight: 700; font-size: 11.5px; white-space: nowrap; }
table.stops tr:hover td { background: #f8fffa; }
.idx-badge { color: #fff; border-radius: 7px; min-width: 26px; height: 24px; display: inline-flex; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 700; padding: 0 6px; }
.chain-badge { display: inline-block; font-size: 10.5px; background: #f1f5f9; color: #475569; border-radius: 6px; padding: 1px 7px; margin-top: 2px; }
.stop-name { font-weight: 700; }
.stop-meta { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.mini-links { display: flex; gap: 4px; margin-top: 5px; flex-wrap: wrap; }
.mini-links a, .mini-links button { font-size: 10.5px; padding: 2px 7px; border-radius: 6px; text-decoration: none; border: 1px solid var(--line); background: #fff; color: #334155; cursor: pointer; }
.mini-links a.g { color: #16a34a; border-color: #86efac; }
.mini-links a.n { color: #2563eb; border-color: #93c5fd; }
.mini-links a.b { color: #ea580c; border-color: #fdba74; }
.status-sel { font-size: 11px; padding: 3px 6px; border-radius: 6px; border: 1px solid #cbd5e1; }
.arrival { font-weight: 700; color: var(--teal); white-space: nowrap; }
.leg-info { color: var(--muted); font-size: 10.5px; white-space: nowrap; }
.route-foot { display: flex; gap: 8px; padding: 10px 16px; background: #f8fafc; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* ============ مودال ============ */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 1200;
  display: none; align-items: flex-start; justify-content: center; padding: 30px 14px; overflow-y: auto;
}
.modal-mask.open { display: flex; }
.modal {
  background: #fff; border-radius: 14px; padding: 22px; width: 480px; max-width: 100%;
  position: relative; box-shadow: 0 20px 60px rgba(0,0,0,.35); animation: pop .18s ease;
}
.modal.wide { width: 720px; }
@keyframes pop { from { transform: translateY(14px); opacity: 0; } }
.modal h2 { font-size: 17px; margin-bottom: 14px; color: var(--green-dark); }
.modal-close { position: absolute; left: 14px; top: 12px; border: none; background: #f1f5f9; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.modal-section { border: 1px solid var(--line); border-radius: 10px; padding: 13px 15px; margin-bottom: 13px; }
.modal-section h4 { font-size: 13px; margin-bottom: 7px; }
.hint { font-size: 11.8px; color: var(--muted); margin: 4px 0 9px; }
.hint a, .modal-note a { color: var(--blue); }
.inline-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.inline-actions.wrap { flex-wrap: wrap; }
.key-status { font-size: 12px; font-weight: 700; }
.key-status.ok { color: var(--green); } .key-status.bad { color: var(--red); }
.modal-note { background: #fffbeb; border: 1px solid #fde68a; color: #78350f; border-radius: 10px; padding: 10px 13px; font-size: 12px; }
.geo-results { max-height: 170px; overflow-y: auto; margin-bottom: 8px; }
.geo-item { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; margin-bottom: 6px; cursor: pointer; font-size: 12px; }
.geo-item:hover { background: #f0fdf4; border-color: #86efac; }
.geo-item small { color: var(--muted); display: block; }

.help-list { padding-right: 20px; font-size: 13px; line-height: 2; }
.custom-types { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.type-chip {
  background: var(--green-light); color: var(--green-dark); border: 1px solid #86efac;
  border-radius: 999px; padding: 3px 8px 3px 12px; font-size: 12px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.type-chip-x { border: none; background: #16a34a; color: #fff; border-radius: 50%; width: 18px; height: 18px; cursor: pointer; font-size: 10px; line-height: 1; }

/* ============ Toast ============ */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: #0f172a; color: #fff; padding: 11px 22px; border-radius: 99px; font-size: 13px;
  z-index: 2000; transition: .3s; box-shadow: 0 8px 24px rgba(0,0,0,.3); max-width: 92vw; text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { background: #b91c1c; } #toast.ok { background: #15803d; }

/* ============ گزارش A4 ============ */
#pdf-root { position: absolute; left: -10000px; top: 0; }
.pdf-page {
  background: #fff; padding: 0; position: relative; overflow: hidden;
  font-family: 'Vazirmatn', Tahoma, sans-serif; color: #111;
  border-bottom: 1px dashed #ccc;
}
.pdf-header { padding: 18px 26px 10px; border-bottom: 3px solid #15803d; }
.pdf-company { font-size: 13px; color: #15803d; font-weight: 700; }
.pdf-title { font-size: 17px; font-weight: 700; margin: 2px 0 6px; }
.pdf-meta { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 11.5px; color: #334155; }
.pdf-meta b { color: #000; }
.pdf-route-band { color: #fff; font-weight: 700; font-size: 13px; padding: 7px 26px; margin: 10px 0 0; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.pdf-route-band span { font-weight: 400; font-size: 10.8px; opacity: .95; }
.pdf-map-wrap { padding: 10px 26px 0; }
.pdf-map { width: 100%; height: 240px; object-fit: cover; border: 1px solid #cbd5e1; border-radius: 6px; }
.pdf-table { width: calc(100% - 52px); margin: 10px 26px 0; border-collapse: collapse; font-size: 10.3px; }
.pdf-table th { background: #f1f5f9; border: 1px solid #cbd5e1; padding: 5px 4px; font-size: 10px; text-align: right; }
.pdf-table td { border: 1px solid #cbd5e1; padding: 5px 5px; vertical-align: top; line-height: 1.45; }
.pdf-table td.c, .pdf-table th.c { text-align: center; }
.pdf-table .sub { color: #64748b; font-size: 9px; }
.ltr-cell { direction: ltr; text-align: left !important; white-space: nowrap; }
.sign-cell { height: 34px; }
.pdf-footer {
  position: absolute; bottom: 46px; left: 26px; right: 26px;
  display: flex; gap: 10px 22px; flex-wrap: wrap; font-size: 10.8px; border-top: 1px solid #94a3b8; padding-top: 8px;
}
.pdf-footer .sig { margin-right: auto; min-width: 130px; border-bottom: 1px dotted #64748b; height: 20px; }
.pdf-legend { position: absolute; bottom: 18px; left: 26px; right: 26px; font-size: 9px; color: #64748b; }

/* ============ چاپ ============ */
body.printing #pdf-root { position: static; left: 0; }
body.printing .topbar, body.printing .layout, body.printing .modal-mask, body.printing #toast { display: none !important; }
body.printing { background: #fff; }
.pdf-page { page-break-after: always; border: none; }

@media print {
  #pdf-root { position: static !important; left: 0 !important; }
  .pdf-page { page-break-after: always; }
  @page { size: A4 portrait; margin: 0; }
}

/* ============ واکنش‌گرا ============ */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
  #map { height: 52vh; }
  .topbar { gap: 10px; }
  .city-legend { order: 3; flex: 1 1 100%; }
  table.stops th:nth-child(4), table.stops td:nth-child(4) { display: none; }
}
