* { box-sizing: border-box; min-width: 0; }
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 {
  padding: 9px 10px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 14px;
  background: #fff;
  color: #1c1c1c;
}

.container { padding: 12px; max-width: 1100px; 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: 12px; }
.field-row:last-child { margin-bottom: 0; }
.field-row label { display: block; font-size: 13px; color: #555; margin-bottom: 6px; }
.field-row input[type="month"], .field-row input[type="number"], .field-row select {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 14px;
  background: #fff;
  color: #1c1c1c;
}

.link-btn {
  background: none;
  border: none;
  color: #0a5;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

.branch-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid #eee;
  border-radius: 10px;
  padding: 10px;
}
.branch-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

/* ---------------- مجموعات الفروع — بنفس منهج المبيعات الحية: سطر واحد من
   مربعات اختيار (مجموعة كاملة) + زر ⓘ صغير بجانب كل اسم يفتح نافذة لاختيار
   فروع محددة من داخل هذه المجموعة فقط ---------------- */
.groups-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  border: 1px solid #eee;
  border-radius: 10px;
  padding: 10px;
}
.chk { display: flex; align-items: center; gap: 6px; font-size: 14px; color: #333; }
.chk input { width: 17px; height: 17px; }
.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 { margin: 0; padding: 0; }
.group-info-list .chk {
  padding: 10px 4px;
  border-bottom: 1px solid #eee;
  font-size: 14px;
  justify-content: flex-start;
}
.group-info-list .chk:last-child { border-bottom: none; }
.group-info-actions {
  display: flex;
  gap: 10px;
  margin: 6px 0 10px;
}
.group-info-action-btn {
  flex: 1 1 0;
  border: 1px solid #0a5;
  background: #fff;
  color: #0a5;
  border-radius: 8px;
  padding: 8px 6px;
  font-size: 13px;
  cursor: pointer;
}
.group-info-action-btn:active { background: #eef6f0; }

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

/* ---------------- نوافذ منبثقة عامة (فروع المجموعة / أصناف الفئة) ---------------- */
.scan-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}
.scan-modal-inner {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 460px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.scan-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  font-size: 14px;
  flex-shrink: 0;
}
.branch-action-inner .scan-modal-header { border-bottom: 1px solid #eee; font-weight: 700; color: #1c1c1c; }
.scan-close {
  background: transparent;
  border: none;
  color: #666;
  font-size: 18px;
  padding: 4px 8px;
  cursor: pointer;
}
.branch-action-body { padding: 14px; overflow-y: auto; }

/* ---------------- نافذة أفضل الأصناف الفردية داخل فئة ---------------- */
.year-btn { flex: 1 1 0; }
#itemsYearTabs { margin-bottom: 8px; }
.metric-tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.metric-btn {
  flex: 1 1 0;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 20px;
  background: #f7f9f8;
  color: #444;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.metric-btn.active { background: #0a5; color: #fff; border-color: #0a5; }

#itemsModalTableWrap { max-height: 55vh; overflow-y: auto; }
#itemsModalTable td:first-child, #itemsModalTable th:first-child { text-align: right; }
.item-name-cell { display: flex; align-items: center; gap: 6px; justify-content: flex-start; }
.item-rank { color: #999; font-size: 11px; }
.item-thumb {
  width: 44px; height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background: #f2f2f2;
  flex-shrink: 0;
  cursor: pointer;
}
.item-thumb-empty {
  width: 44px; height: 44px;
  border-radius: 8px;
  background: #f2f2f2;
  display: flex; align-items: center; justify-content: center;
  color: #bbb;
  font-size: 18px;
  flex-shrink: 0;
}
.load-more-btn {
  width: 100%;
  margin-top: 10px;
  padding: 11px;
  border: 1px solid #ddd;
  border-radius: 12px;
  background: #f7f9f8;
  color: #0a5;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.load-more-btn:disabled { opacity: .6; cursor: default; }

/* ---------------- تكبير صورة الصنف (صورة كبيرة بخلفية داكنة) ---------------- */
.item-detail-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.item-detail-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  border-radius: 16px;
  overflow: hidden;
  background: #222;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.item-detail-image-view {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  min-height: 240px;
  max-height: 85vh;
}
.item-detail-image-view img {
  display: block;
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
}
.item-detail-btn {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 3;
  background: rgba(0,0,0,.45);
  border: none;
  color: #fff;
  font-size: 20px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 6px rgba(0,0,0,.35);
}

/* ---------------- جدول ملخص الأصناف (قابل للضغط لفتح أصنافه الفردية) ---------------- */
#summaryTableBody tr { cursor: pointer; }
#summaryTableBody tr:hover td { background: #f7f9f8; }
#summaryTableBody tr.total-row { cursor: default; }
#summaryTableBody tr.total-row:hover td { background: #f7f9f8; }

/* ---------------- أزرار الفترة الزمنية (نوع الفترة + نوع الشهر) ---------------- */
.period-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.period-type-btn, .calendar-btn {
  flex: 1 1 auto;
  min-width: 70px;
  padding: 9px 10px;
  border: 1px solid #ddd;
  border-radius: 20px;
  background: #f7f9f8;
  color: #444;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.period-type-btn.active, .calendar-btn.active {
  background: #0a5;
  color: #fff;
  border-color: #0a5;
}

#monthSubFields { margin-top: 12px; }

.primary-btn {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 10px;
  background: #0a5;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.primary-btn:disabled { opacity: .6; cursor: default; }

.hint { font-size: 12px; color: #888; margin: 6px 0 0; }

.status-box {
  background: #eef6f0;
  color: #0a5;
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  margin-bottom: 12px;
  text-align: center;
}
.status-box.error { background: #fdecea; color: #b3261e; }

.period-info { font-size: 13px; color: #555; margin-bottom: 8px; }

.section-title { font-size: 15px; margin: 18px 0 8px; }

/* ---------------- الجدول الرئيسي (مصفوفة الأصناف اليومية) ---------------- */
.table-wrap {
  max-height: 70vh;
  overflow: auto;
  border: 1px solid #eee;
  border-radius: 10px;
}
table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 12px;
  white-space: nowrap;
}
th, td {
  padding: 6px 8px;
  border-bottom: 1px solid #eee;
  text-align: center;
}
thead th {
  position: sticky;
  top: 0;
  background: #eef6f0;
  color: #0a5;
  z-index: 3;
  border-bottom: 1px solid #dde;
}
thead tr:first-child th { top: 0; }
thead tr:last-child th.sub-th { top: 30px; font-weight: 600; font-size: 11px; }
th.sticky-col, td.sticky-col {
  position: sticky;
  right: 0;
  background: #fff;
  z-index: 2;
  font-weight: 700;
  text-align: right;
  min-width: 110px;
}
thead th.sticky-col { z-index: 4; background: #eef6f0; }

tr.future-row td { color: #bbb; }
tr.total-row td { font-weight: 800; background: #f7f9f8; border-top: 2px solid #e2e6e4; }
tr.total-row td.sticky-col { background: #f7f9f8; color: #444; }

td.pos { color: #0a5; font-weight: 700; }
td.neg { color: #b3261e; font-weight: 700; }

/* خط عامودي رمادي خفيف يفصل بين كل مجموعتَي أعمدة (2025/2026/الفرق/النسبة) */
th.grp-start, td.grp-start { border-right: 1px solid #dcdcdc; }

/* ---------------- شريط أزرار الأصناف (قابل للسحب أفقيًا) ---------------- */
.cat-bar-wrap { margin-bottom: 8px; }
.cat-bar {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding: 4px 2px 10px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.cat-btn {
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 9px 14px;
  border: 1px solid #ddd;
  border-radius: 20px;
  background: #f7f9f8;
  color: #444;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.cat-btn.active {
  background: #0a5;
  color: #fff;
  border-color: #0a5;
}
.cat-btn-special { border-color: #c9a227; color: #8a6d00; }
.cat-btn-special.active { background: #c9a227; border-color: #c9a227; color: #fff; }
.cat-btn-grand { font-weight: 800; border-color: #0a5; }

/* ---------------- زرا الفضة/الاكسسوار — صف خاص فوق شريط أزرار الأصناف ---------------- */
.special-cat-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.cat-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.nav-btn {
  flex: 0 0 auto;
  padding: 10px 16px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #f7f9f8;
  color: #444;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.nav-btn.primary { background: #0a5; color: #fff; border-color: #0a5; }
.nav-btn:disabled { opacity: .45; cursor: default; }
.cat-position { font-size: 13px; color: #666; flex: 1 1 auto; text-align: center; }

.share-line {
  background: #fff9e6;
  color: #8a6d00;
  border: 1px solid #f0e0a8;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 10px;
  text-align: center;
}
