/* SENA Shop - Digikala style theme (mobile-first) */
:root {
  --dk-red: #e03d3d;
  --dk-red-dark: #c92c2c;
}

body {
  background: #f5f6fa;
  -webkit-font-smoothing: antialiased;
  font-family: "Segoe UI", "Helvetica Neue", Arial, Tahoma, sans-serif;
}

/* ---- professional footer (Digikala style) ---- */
.site-footer { background: #232933; color: #b7c0cd; margin-top: 48px; }
.site-footer a { color: #d7dee8; text-decoration: none; }
.site-footer a:hover { color: #fff; }
.sf-logo { height: 38px; width: auto; object-fit: contain; }
.sf-name { font-size: 1.05rem; font-weight: 800; color: #fff; }
.sf-title { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--dk-red); margin-bottom: 8px; }
.sf-line { font-size: .85rem; margin-bottom: 5px; }
.sf-line i { width: 18px; color: var(--dk-red); }
.sf-line a { border-bottom: 1px solid transparent; }
.sf-line a:hover { border-bottom-color: #fff; }
.sf-bottom { border-top: 1px solid #343b48; padding: 10px 0 14px; text-align: center; color: #7e8898; font-size: .78rem; }

/* ---- standard sign-in page (shared with ERP / finance) ---- */
.login-bg {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(150deg, #fdf2f2 0%, #f5f6fa 55%, #f0f2f7 100%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  border: 0;
  border-radius: 1rem;
  box-shadow: 0 24px 60px rgba(31, 41, 55, .14);
}
.login-icon {
  width: 64px; height: 64px; border-radius: 1rem;
  background: linear-gradient(135deg, var(--dk-red), var(--dk-red-dark));
  color: #fff; font-size: 30px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px;
  box-shadow: 0 10px 22px rgba(224, 61, 61, .35);
}
.login-title { font-weight: 800; font-size: 1.15rem; color: #1c2333; margin-bottom: 2px; }
.login-sub { color: #6b7484; font-size: .85rem; }
.login-lang { margin-top: 14px; font-size: .82rem; }
.login-lang a { color: #6b7484; text-decoration: none; margin: 0 6px; }
.login-lang a:hover { color: var(--dk-red); }

/* page headers: standard red accent bar */
h4.mb-3, h4.mb-4 { position: relative; padding-inline-start: .8rem; font-weight: 800; }
h4.mb-3::before, h4.mb-4::before { content: ''; position: absolute; inset-inline-start: 0; top: .2rem; bottom: .2rem; width: 4px; border-radius: 4px; background: var(--dk-red); }

/* ---- custom scrollbar (Digikala style) ---- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f1f2f4; }
::-webkit-scrollbar-thumb { background: #cfd3da; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--dk-red); }
* { scrollbar-width: thin; scrollbar-color: #cfd3da #f1f2f4; }

/* ---- responsive (mobile-first) ---- */
@media (max-width: 767px) {
  .card-body, .table-wrap { overflow-x: auto; }
  .table { font-size: .8rem; }
  .site-footer .row > div { text-align: start; }
}

/* ---- mobile-friendly tables: every table scrolls horizontally ---- */
.table-responsive { -webkit-overflow-scrolling: touch; }
.table-responsive .table { min-width: 560px; }

/* ---- touch-friendly controls on phones/tablets (field portal) ---- */
@media (max-width: 991px) {
  .form-control, .form-select, .btn { font-size: 1rem; }
  .form-control, .form-select { min-height: 44px; }
  .btn { padding-top: .5rem; padding-bottom: .5rem; }
  .btn-lg { padding: .7rem 1rem; font-size: 1.05rem; }
  .nav-link { font-size: .95rem; }
}

/* ---- delivery map: popup fits small screens ---- */
@media (max-width: 480px) {
  .leaflet-popup-content { max-width: 260px; min-width: 210px; }
  .pp-body { min-width: 200px; }
  .pp-grid { grid-template-columns: 1fr; }
  .pp-btn { white-space: normal; }
}

/* ---- responsive maps: popups + forms fit any phone/tablet ---- */
@media (max-width: 767px) {
  #pmap, #dmap { height: 55vh !important; }
  .leaflet-popup-content-wrapper { max-width: calc(100vw - 20px) !important; }
  .leaflet-popup-content { max-width: calc(100vw - 40px) !important; min-width: 0 !important; width: auto !important; max-height: 62vh !important; overflow-y: auto; }
  .pp-body { min-width: 0 !important; width: 100%; }
  .pp-head { flex-direction: column; align-items: flex-start; gap: 4px; }
  .pp-stats { grid-template-columns: 1fr 1fr; }
  .pp-grid { grid-template-columns: 1fr 1fr; }
  .pp-btn { white-space: normal; text-align: center; font-size: .74rem; }
  .pp-row { font-size: .76rem; flex-wrap: wrap; }
  .pf-items { overflow-x: auto; }
  .pf-items table { min-width: 340px; }
  .pf-calc { flex-direction: column; align-items: flex-start; gap: 3px; }
  #formModal .modal-dialog, #addModal .modal-dialog { margin: .5rem auto; max-width: calc(100vw - 12px); }
  #formModal .modal-body, #addModal .modal-body { padding: .8rem .9rem; max-height: 80vh; overflow-y: auto; }
  .input-group { flex-wrap: nowrap; }
  .input-group .form-select { max-width: 110px; }
}

/* ---- order form: stack qty/stock columns on small screens ---- */
@media (max-width: 767px) {
  #itemsTable { min-width: 640px; }
  #formModal .modal-dialog { margin: 1vh auto; max-width: calc(100vw - 16px); }
  #addModal .modal-dialog { margin: 1vh auto; max-width: calc(100vw - 16px); }
}

.navbar { background: var(--dk-red) !important; }
.navbar-brand { font-weight: 800; letter-spacing: .2px; }
.navbar .nav-link.active { color: #fff !important; font-weight: 600; }

.pmarker { background: transparent; }

.card { border: 0; border-radius: .6rem; }
.card-header { background: #fff; border-bottom: 1px solid #eee; font-weight: 600; }

.table > :not(caption) > * > * { padding: .55rem .6rem; }
[dir="rtl"] .text-end { text-align: left !important; }

/* ---- hero banner ---- */
.dk-hero {
  background: linear-gradient(135deg, var(--dk-red), #ff6b6b);
  color: #fff;
  border-radius: .9rem;
  padding: 1.6rem 1rem;
}
.dk-hero .form-control { border: 0; }

/* ---- product cards (Digikala style) ---- */
.p-card { transition: transform .18s ease, box-shadow .18s ease; overflow: hidden; }
.p-card:hover { transform: translateY(-4px); box-shadow: 0 12px 26px rgba(0,0,0,.16) !important; }
.p-img-wrap img { transition: transform .25s ease; }
.p-card:hover .p-img-wrap img { transform: scale(1.04); }

.p-img-wrap {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: #fff;
  border-bottom: 1px solid #f1f2f4;
}
.p-img-wrap img { width: 100%; height: 100%; object-fit: cover; }

.p-discount {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--dk-red);
  color: #fff;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 800;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
[dir="rtl"] .p-discount { right: auto; left: 8px; }

.p-name {
  color: #232933;
  text-decoration: none;
  font-size: .88rem;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.4em;
}
.p-name:hover { color: var(--dk-red); }

.p-price-new { color: var(--dk-red); font-weight: 800; font-size: 1.02rem; }
.p-price-old { color: #9ca3af; text-decoration: line-through; font-size: .8rem; }
.p-stock-ok { color: #18863b; font-size: .78rem; font-weight: 700; }
.p-stock-no { color: #9ca3af; font-size: .78rem; font-weight: 600; }

/* ---- detail page ---- */
.p-detail-img-wrap { position: relative; aspect-ratio: 1 / 1; overflow: hidden; }
.p-detail-img { width: 100%; height: 100%; object-fit: cover; }
.p-price-block { background: #fff5f5; border: 1px solid #ffe0e0; }

/* ---- compact map popups (field portal: sales rep + distributor) ---- */
.leaflet-popup-content-wrapper { border-radius: .75rem; box-shadow: 0 10px 28px rgba(0,0,0,.22); }
.leaflet-popup-content { margin: 12px 14px; line-height: 1.45; }
.pp-body { min-width: 250px; }
.pp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; font-size: .95rem; flex-wrap: wrap; }
.pp-head b { font-size: .92rem; }
.pp-badges { display: inline-flex; gap: 3px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.pp-type { font-size: .62rem; }
.pp-photo { width: 44px; height: 44px; object-fit: cover; border-radius: .5rem; border: 1px solid #eee; float: right; margin: 2px 0 4px 8px; }
[dir="rtl"] .pp-photo { float: left; margin: 2px 8px 4px 0; }
.pp-sub { color: #6c757d; font-size: .8rem; }
.pp-row { display: flex; align-items: center; gap: 6px; font-size: .78rem; color: #495057; margin-top: 2px; }
.pp-row i { color: var(--dk-red); width: 14px; text-align: center; }
.pp-row a { color: #0d6efd; text-decoration: none; }
.pp-warn { font-size: .78rem; margin-top: 3px; padding: 4px 8px; background: #fdeaea; color: #b02a37; border: 1px solid #f5c6cb; border-radius: .4rem; }
.pp-bal { font-size: .85rem; margin-top: 3px; padding: 4px 8px; background: #fff5f5; border-radius: .4rem; }
.pp-bal-del { background: #f0f7ff; }
.pp-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-top: 6px; }
.pp-stat b { font-size: .78rem; }
.pp-stat { background: #f8f9fa; border: 1px solid #eee; border-radius: .45rem; padding: 4px 2px; text-align: center; }
.pp-stat b { display: block; font-size: .82rem; color: #212529; }
.pp-stat span { font-size: .62rem; color: #6c757d; text-transform: uppercase; letter-spacing: .3px; }
.pp-title { font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.pp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-top: 8px; }
.pp-btn { font-size: .76rem; padding: .32rem .35rem; white-space: nowrap; }
.pp-order { border-top: 1px solid #eee; margin-top: 7px; padding-top: 6px; }
.pp-ono { font-weight: 600; font-size: .82rem; }
.pp-mini { font-size: .75rem; color: #6c757d; }
.pp-back { padding: 0; font-size: .8rem; margin-top: 4px; }
/* internal scroll areas: the popup / modal itself never scrolls, only these lists */
.pp-orders { max-height: 210px; overflow-y: auto; margin-top: 4px; }
.pf-items { max-height: 190px; overflow-y: auto; border: 1px solid #eee; border-radius: .45rem; padding: 4px 8px; margin-bottom: 6px; }
.pp-orders::-webkit-scrollbar, .pf-items::-webkit-scrollbar { width: 5px; }
.pp-orders::-webkit-scrollbar-thumb, .pf-items::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* ---- popup modal forms ---- */
.pf-title { font-weight: 700; color: #232933; border-bottom: 2px solid var(--dk-red); padding-bottom: 6px; }
.pf-calc { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: .8rem; background: #f8f9fa; border-radius: .45rem; padding: 5px 8px; }
.pf-balance { font-size: .8rem; background: #fff5f5; border: 1px solid #f5c6cb; border-radius: .4rem; padding: 5px 8px; margin-bottom: 8px; }
.pf-loans { font-size: .8rem; background: #fff8e6; border: 1px solid #f0d78c; border-radius: .4rem; padding: 5px 8px; margin-bottom: 8px; }
/* compact popup forms: no page/popup scrolling, forms fit the viewport */
#formModal .modal-body, #addModal .modal-body { padding: 1rem 1.15rem; }
#formModal .modal-dialog { margin-top: 2vh; margin-bottom: 2vh; }
#formModal .form-label { margin-bottom: 2px; }
#formModal .modal-content { border: 0; border-radius: .8rem; overflow: hidden; }
#formModal .modal-body { background: #fff; }
#addModal .modal-content { border: 0; border-radius: .8rem; overflow: hidden; }
#addModal .modal-header { background: var(--dk-red); color: #fff; }
#addModal .modal-header .btn-close { filter: invert(1); }
/* Dari (RTL): popup text aligns right, back arrow points right.
   Only the arrow glyph is mirrored - flipping the whole button (scaleX on
   .pp-back) used to mirror the Persian/English label too, making it unreadable. */
[dir="rtl"] .leaflet-popup-content { text-align: right; }
[dir="rtl"] .pp-back { transform: none; }
[dir="rtl"] .pp-back-arr { display: inline-block; transform: scaleX(-1); }
[dir="rtl"] .pp-grid .pp-btn { text-align: center; }
[dir="rtl"] .pf-calc { flex-direction: row-reverse; }

/* Dari (RTL): Vazirmatn - consistent, readable Persian/Dari typeface */
[dir="rtl"] body,
[dir="rtl"] .form-control,
[dir="rtl"] .form-select,
[dir="rtl"] .form-label,
[dir="rtl"] .btn,
[dir="rtl"] .nav-link,
[dir="rtl"] .dropdown-item,
[dir="rtl"] .table,
[dir="rtl"] .modal-title,
[dir="rtl"] .leaflet-popup-content,
[dir="rtl"] input,
[dir="rtl"] select,
[dir="rtl"] textarea { font-family: 'Vazirmatn', 'Segoe UI', 'Helvetica Neue', Arial, Tahoma, sans-serif; }

/* Dari (RTL): direction-aware icons point the natural way (forward = left) */
[dir="rtl"] .bi-arrow-right,
[dir="rtl"] .bi-box-arrow-right,
[dir="rtl"] .bi-box-arrow-in-right,
[dir="rtl"] .bi-sign-turn-right { display: inline-block; transform: scaleX(-1); }


/* delivery map popup tidy: never overflow, keep buttons wrapable */
.leaflet-popup-content { min-width: 230px; max-width: 300px; overflow-x: hidden; }
.pp-order { overflow-x: hidden; }
/* partial delivery rows: name on top, the two number inputs below on phones */
.pf-prow { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
@media (max-width: 767px) {
  .pf-prow { flex-direction: column; align-items: stretch; }
  .pf-pinputs { justify-content: space-between; }
  .pf-pinputs .form-control { flex: 1; }
}
.pp-mini { white-space: nowrap; }

/* route number badges on the sales-rep map: purely decorative, a click on
   them must pass through to the customer marker below (the full action
   popup - order / payment / loan / statement / visit - must still open) */
.shop-route-num { pointer-events: none; }

/* today's customer list: rows not yet visited stand out */
#tcTable tr.tc-unvisited { background-color: #fff3cd; }
#tcTable tr.tc-unvisited:hover { background-color: #ffe8a1; }
#tcTable tr.tc-focused { background-color: #f8d7da !important; box-shadow: inset 4px 0 0 #dc3545; }
