* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
  background: #f4f6f5;
  color: #1c1c1c;
  direction: rtl;
}

/* ---------------- login ---------------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(160deg, #0a5 0%, #063 100%);
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 32px 28px;
  width: 90%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.login-logo { font-size: 40px; }
.login-card h1 { margin: 6px 0 0; font-size: 22px; }
.login-card .subtitle { color: #666; margin: 2px 0 20px; }
.login-card form { text-align: right; }
.login-card label { display: block; font-size: 13px; color: #555; margin: 12px 0 4px; }
.login-card input {
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 16px;
}
.login-card button {
  width: 100%;
  margin-top: 20px;
  padding: 13px;
  border: none;
  border-radius: 10px;
  background: #0a5;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}
.error-box {
  background: #fdecea;
  color: #b3261e;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  margin-bottom: 6px;
}

/* ---------------- app shell ---------------- */
.topbar {
  background: #0a5;
  color: #fff;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { font-weight: 700; font-size: 17px; flex-shrink: 0; }
.topbar .logout { color: #eafff2; text-decoration: none; font-size: 14px; flex-shrink: 0; }
.topbar-select {
  flex: 1;
  max-width: 220px;
  margin: 0 8px;
  padding: 9px 10px;
  border: none;
  border-radius: 20px;
  font-size: 14px;
  background: #fff;
  color: #1c1c1c;
}

.container { padding: 12px; max-width: 700px; margin: 0 auto; }

.search-card, .result-card {
  background: #fff;
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.field-row { margin-bottom: 10px; }
.field-row label { display: block; font-size: 13px; color: #555; margin-bottom: 4px; }
.field-hint { font-size: 11px; color: #999; margin-top: 5px; }
select, input[type=text] {
  width: 100%;
  padding: 11px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 16px;
  background: #fff;
}
.search-input-row { display: flex; gap: 8px; }
.search-input-row input { flex: 1; }
.search-input-row button {
  padding: 0 18px;
  border: none;
  border-radius: 10px;
  background: #0a5;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}
.search-input-row button:active { background: #084; }
.search-input-row #scanBtn {
  background: #f4f6f5;
  color: #1c1c1c;
  padding: 0 14px;
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
}
.search-input-row #scanBtn:active { background: #e5e9e7; }

/* ---------------- barcode scanner modal ---------------- */
.scan-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.85);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}
.scan-modal-inner {
  background: #111;
  border-radius: 14px;
  width: 100%;
  max-width: 420px;
  overflow: hidden;
}
.scan-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  color: #fff;
  font-size: 14px;
}
.scan-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 18px;
  padding: 4px 8px;
  cursor: pointer;
}
#scanReader { width: 100%; background: #000; }
#scanReader video { width: 100%; display: block; }
.scan-status {
  color: #ddd;
  font-size: 13px;
  text-align: center;
  padding: 10px;
}

/* ---------------- خيارات التواصل مع الفرع ---------------- */
.branch-action-inner { background: #fff; }
.branch-action-inner .scan-modal-header { color: #1c1c1c; border-bottom: 1px solid #eee; }
.branch-action-inner .scan-close { color: #666; }
.branch-action-body { display: flex; flex-direction: column; gap: 10px; padding: 16px; }
.branch-action-btn {
  display: block;
  text-align: center;
  padding: 13px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
}
.branch-action-btn.call { background: #eaf2ff; color: #0a58ca; }
.branch-action-btn.whats { background: #e7f9ee; color: #128c3e; }
.branch-action-btn.mail { background: #fff3e0; color: #b45c00; }
.branch-action-btn.group {
  background: #f1eefc; color: #5b3fb5;
  border: none; font-family: inherit; width: 100%;
}
.branch-action-note { font-size: 12px; color: #999; text-align: center; padding: 0 4px; }

/* أزرار الكميات القابلة للضغط داخل جدول الفروع */
.qty-btn {
  border: none;
  background: #eef6f0;
  color: #0a5;
  font-weight: 700;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.qty-btn:active { background: #d8ede0; }

.inline-checks { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 10px; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 14px; color: #333; }
.chk input { width: 17px; height: 17px; }
#groupsChecks { display: inline-flex; gap: 10px 16px; flex-wrap: wrap; }

/* ---------------- زر إظهار/إخفاء مجموعات الفروع + بيانات إضافية ---------------- */
.toggle-btn {
  width: 100%;
  padding: 11px;
  border: 1px dashed #0a5;
  border-radius: 12px;
  background: #eef6f0;
  color: #0a5;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.toggle-btn.active { background: #0a5; color: #fff; border-style: solid; }
.toggle-arrow {
  display: inline-block;
  margin-inline-start: 4px;
  transition: transform .2s;
}
.toggle-btn.active .toggle-arrow { transform: rotate(180deg); }
.groups-section { padding-top: 4px; }

/* ---------------- زر ⓘ بجانب كل مجموعة تصفية ---------------- */
.group-info-btn {
  border: none;
  background: #eef6f0;
  color: #0a5;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  line-height: 18px;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}
.group-info-list { list-style: none; margin: 0; padding: 0; }
.group-info-list li {
  padding: 10px 4px;
  border-bottom: 1px solid #eee;
  font-size: 14px;
  color: #333;
  text-align: right;
}
.group-info-list li:last-child { border-bottom: none; }

/* ---------------- مبيعات الصنف حسب الفرع ---------------- */
.item-sales-section { margin-top: 16px; }
.item-sales-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.item-sales-title { font-size: 14px; font-weight: 700; color: #1c1c1c; }
.item-sales-period-select {
  width: auto;
  padding: 6px 8px;
  font-size: 13px;
  border-radius: 8px;
}
.item-sales-custom-dates {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  color: #666;
}
.item-sales-custom-dates input[type=date] {
  flex: 1;
  padding: 8px;
  font-size: 14px;
  border-radius: 8px;
}
#itemSalesTableBody tr { cursor: pointer; }
#itemSalesTableBody tr:active { background: #eef6f0; }
#itemSalesTableWrap { max-height: 50vh; overflow-y: auto; }

/* جدول ترتيب الألوان/المقاسات داخل نافذة منبثقة قد يحتوي عشرات الصفوف
   (خصوصًا مع فترة "كل الفترة") — لازم يكون له ارتفاع أقصى وتمرير داخلي
   خاص به، وإلا تكبر النافذة كاملة خارج الشاشة ويصعب التحكم بها. */
#branchColorSizeTableWrap { max-height: 55vh; overflow-y: auto; }

.status { font-size: 13px; min-height: 18px; margin-top: 4px; }
.status.err { color: #b3261e; }
.status.ok { color: #0a5; }
.status.loading { color: #06c; }

/* ---------------- result ---------------- */
.spec-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  font-size: 13px;
  margin-top: 16px;
}
.spec-item { display: flex; justify-content: space-between; gap: 4px; }
.spec-item .k { color: #777; }
.spec-item .v { font-weight: 600; }
.desc { font-size: 13px; color: #444; margin-top: 10px; line-height: 1.5; }

.prices {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.price-tile {
  background: #f4f6f5;
  border-radius: 10px;
  padding: 8px 3px;
  text-align: center;
  flex: 1 1 0;
  min-width: 52px;
}
.price-tile .lbl { font-size: 9.5px; color: #777; white-space: nowrap; }
.price-tile .val { font-weight: 700; font-size: 12.5px; margin-top: 2px; }

@media (min-width: 400px) {
  .price-tile { padding: 10px 6px; }
  .price-tile .lbl { font-size: 11px; }
  .price-tile .val { font-size: 14px; }
}

.image-box-large {
  width: 78%;
  max-width: 320px;
  min-height: 260px;
  margin: 0 auto 16px;
  background: #f2f2f2;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.image-box-large img { width: 100%; height: auto; max-height: 420px; object-fit: contain; display: block; }
.no-image { font-size: 13px; color: #999; text-align: center; padding: 4px; }

.table-wrap {
  margin-top: 14px;
  overflow-x: auto;
  border: 1px solid #eee;
  border-radius: 10px;
  -webkit-overflow-scrolling: touch;
}
table { border-collapse: collapse; width: 100%; font-size: 13px; white-space: nowrap; }
th, td { padding: 8px 10px; text-align: center; border-bottom: 1px solid #f0f0f0; }
th { background: #f7f9f8; color: #444; font-weight: 700; }
/* ملاحظة: position: sticky على عنصر <th> منفردًا لا يعمل بشكل موثوق في بعض
   إصدارات كروميوم داخل الجداول؛ الطريقة الموثوقة هي تثبيت <thead> نفسه. */
thead { position: sticky; top: 0; z-index: 1; }
tr.footer-row { background: #e8f3e8; font-weight: 700; }

/* جدول نتائج البحث الرئيسي قد يحتوي عشرات صفوف الباركود — لازم يكون له
   ارتفاع أقصى وتمرير رأسي داخلي خاص به حتى تعمل رؤوس الأعمدة اللاصقة
   (position: sticky) فعليًا وتبقى ظاهرة أثناء النزول لباقي الصفوف، بدل أن
   تختفي مع تمرير الصفحة كاملة. */
#branchTableWrap { max-height: 65vh; overflow-y: auto; }
.table-summary { font-size: 13px; color: #0a5; font-weight: 600; margin-top: 8px; text-align: left; }

@media (min-width: 480px) {
  .spec-grid { font-size: 14px; }
}
