* { box-sizing: border-box; min-width: 0; }

/* ===== نفس لوحة ألوان «لوحة القيادة التنفيذية» المعتمدة (2026-09-21) بكل
   برامج هذه العائلة: خلفية داكنة #0a0e17 / بطاقات #121829 / لون تمييز بنفسجي
   #8156f5 — والقواعد نفسها لمجموعات الفروع، أزرار الفترة، الجداول اللاصقة،
   النوافذ المنبثقة وشاشة الدخول (منقولة من "تحليل الأصناف"). ===== */
:root {
  --c-primary: #8156f5;
  --c-primary-dark: #6a44de;
  --c-bg: #0a0e17;
  --c-surface: #121829;
  --c-text: #e8ecf5;
  --c-muted: #a9b2c7;
  --c-muted2: #c9d0de;
  --c-muted3: #6e7a95;
  --c-muted4: #6e7a95;
  --c-muted5: #6e7a95;
  --c-border: rgba(255, 255, 255, .10);
  --c-border-light: rgba(255, 255, 255, .06);
  --c-chip-bg: #171e33;
  --c-row-alt: #151b2e;
  --c-thumb-bg: #171e33;
  --c-thumb-text: #6e7a95;
  --c-panel-shadow: none;
  --c-header-bg-1: #121829;
  --c-total-border: rgba(255, 255, 255, .13);
  --c-divider: rgba(255, 255, 255, .10);
  --c-sales: #4fa9f5;
  --c-stock: #74d39d;
  --c-wh: #e2b563;
  --c-price: #c3adff;
  color-scheme: dark;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--c-bg);
  color: var(--c-text);
  direction: rtl;
}
::selection { background: #8156f5; color: #fff; }
input, select, textarea { color-scheme: dark; font-family: inherit; }
input[type="checkbox"], input[type="radio"] { accent-color: #8156f5; }

/* ---------------- login ---------------- */
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: radial-gradient(1100px 620px at 50% -10%, #1d1740 0%, #0a0e17 62%);
}
.login-card {
  background: #121829; border: 1px solid rgba(255,255,255,.07); color: #e8ecf5;
  border-radius: 16px; padding: 32px 28px; width: 90%; max-width: 360px; text-align: center;
  box-shadow: 0 22px 60px rgba(0,0,0,.55);
}
.login-logo { font-size: 40px; color: #8156f5; }
.login-card h1 { margin: 6px 0 0; font-size: 22px; }
.login-card .subtitle { color: #6e7a95; margin: 2px 0 20px; }
.login-card form { text-align: right; }
.login-card label { display: block; font-size: 13px; color: #a9b2c7; margin: 12px 0 4px; }
.login-card input {
  width: 100%; padding: 12px; border-radius: 10px; font-size: 16px;
  background: #171e33; border: 1px solid rgba(255,255,255,.13); color: #e8ecf5;
}
.login-card input:focus { outline: 2px solid #8156f5; outline-offset: 1px; }
.login-card button {
  width: 100%; margin-top: 20px; padding: 13px; border: none; border-radius: 10px;
  background: #8156f5; color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
}
.error-box {
  background: rgba(192,69,63,.14); color: #f2a9a5; border: 1px solid rgba(192,69,63,.4);
  border-radius: 8px; padding: 10px; font-size: 14px; margin-bottom: 6px;
}

/* ---------------- app shell ---------------- */
.topbar {
  background: #121829; border-bottom: 1px solid rgba(255,255,255,.07);
  color: #fff; padding: 12px 18px; 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: 14px; letter-spacing: 1.1px; display: inline-flex; align-items: center; gap: 9px; flex-shrink: 0; }
.topbar .brand-cc::before {
  content: "◈"; color: #8156f5; background: rgba(129,86,245,.14); border-radius: 9px;
  width: 30px; height: 30px; display: inline-grid; place-items: center; font-size: 16px;
}
.topbar .brand-sub { color: #a9b2c7; font-weight: 500; letter-spacing: 0; }
.topbar .logout { color: #a9b2c7; text-decoration: none; font-size: 14px; flex-shrink: 0; }
.topbar .logout:hover { color: #fff; }

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

.search-card, .result-card {
  background: var(--c-surface); border: 1px solid rgba(255,255,255,.07); border-radius: 13px;
  padding: 14px; margin-bottom: 12px;
}
.field-row { margin-bottom: 12px; }
.field-row:last-child { margin-bottom: 0; }
.field-row label { display: block; font-size: 13px; color: var(--c-muted); margin-bottom: 6px; }
.field-row input[type="date"] {
  width: 100%; padding: 10px; border: 1px solid var(--c-border); border-radius: 10px; font-size: 14px;
  background: var(--c-surface); color: var(--c-text);
}
.date-pair { display: flex; gap: 10px; }
.date-pair > div { flex: 1 1 0; }
.options-row label.chk { color: var(--c-muted2); margin: 0; }
.hint { font-size: 12px; color: var(--c-muted4); margin: 6px 0 0; }

.link-btn {
  background: none; border: none; color: var(--c-primary); font-size: 12px; font-weight: 700;
  cursor: pointer; padding: 0; text-decoration: underline; font-family: inherit;
}
.link-btn.danger { color: #ef9e99; }

/* ---------------- منطقة رفع الملف ---------------- */
.drop-zone {
  border: 2px dashed rgba(129,86,245,.55); border-radius: 12px; padding: 18px 14px;
  background: rgba(129,86,245,.06); cursor: pointer; text-align: center; transition: background .15s, border-color .15s;
}
.drop-zone:hover, .drop-zone.drag { background: rgba(129,86,245,.16); border-color: #8156f5; }
.drop-zone-inner { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.drop-icon { font-size: 26px; }
#dropText { font-weight: 700; font-size: 14px; word-break: break-all; }
.file-summary { margin-top: 10px; }
.file-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--c-chip-bg); border: 1px solid var(--c-border); color: var(--c-muted2);
  border-radius: 999px; padding: 5px 11px; font-size: 12px;
}
.chip-ok { color: #74d39d; border-color: rgba(116,211,157,.35); }
.chip-warn { color: #e2b563; border-color: rgba(226,181,99,.35); }
.chip-info { color: #8cc8ff; border-color: rgba(79,169,245,.35); }
#dropText, #chipFile { unicode-bidi: isolate; }
.file-actions { display: flex; gap: 14px; margin-top: 8px; }
.not-found-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; max-height: 160px; overflow: auto; }
.code-pill { background: rgba(226,181,99,.12); color: #e2b563; border-radius: 6px; padding: 3px 7px; font-size: 12px; font-family: Consolas, monospace; }

/* ---------------- مجموعات الفروع (نفس المبيعات الحية) ---------------- */
.groups-checks {
  display: flex; flex-wrap: wrap; gap: 8px 14px; border: 1px solid var(--c-border-light);
  border-radius: 10px; padding: 10px;
}
.chk { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--c-text); }
.chk input { width: 17px; height: 17px; }
.group-info-btn {
  border: none; background: var(--c-chip-bg); color: var(--c-primary); 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 var(--c-border-light); 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 var(--c-primary); background: var(--c-surface); color: var(--c-primary);
  border-radius: 8px; padding: 8px 6px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.group-info-action-btn:active { background: var(--c-chip-bg); }
.status { font-size: 13px; min-height: 18px; margin-top: 8px; }
.status.err { color: #ef9e99; }

/* ---------------- نوافذ منبثقة ---------------- */
.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: var(--c-surface); border-radius: 14px; width: 100%; max-width: 460px; max-height: 85vh;
  overflow: hidden; display: flex; flex-direction: column; border: 1px solid rgba(255,255,255,.08);
}
.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 var(--c-border-light); font-weight: 700; color: var(--c-text); }
.scan-close { background: transparent; border: none; color: var(--c-muted); font-size: 18px; padding: 4px 8px; cursor: pointer; }
.branch-action-body { padding: 14px; overflow-y: auto; }

/* ---------------- أزرار الفترة ---------------- */
.period-tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.period-type-btn {
  flex: 1 1 auto; min-width: 70px; padding: 9px 10px; border: 1px solid var(--c-border); border-radius: 20px;
  background: var(--c-row-alt); color: var(--c-muted2); font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.period-type-btn.active { background: #8156f5; border-color: #8156f5; color: #fff; }

.status-box {
  background: var(--c-chip-bg); color: var(--c-primary); border-radius: 10px; padding: 12px; font-size: 13px;
  margin: 10px 0 12px; text-align: center;
}
.status-box.error { background: rgba(192,69,63,.14); color: #f2a9a5; }

/* ---------------- التقرير ---------------- */
.report-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.period-info { font-size: 13px; color: var(--c-muted); margin-bottom: 4px; }
.export-btn {
  border: none; border-radius: 10px; background: #8156f5; color: #fff; font-size: 14px; font-weight: 700;
  padding: 11px 16px; cursor: pointer; font-family: inherit; white-space: nowrap;
}
.export-btn:hover { background: var(--c-primary-dark); }
.export-btn:disabled { opacity: .6; cursor: default; }

.table-wrap { max-height: 75vh; overflow: auto; border: 1px solid var(--c-border-light); 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 var(--c-border-light); text-align: center; }
thead th {
  position: sticky; top: 0; background: var(--c-chip-bg); color: var(--c-primary); z-index: 3;
  border-bottom: 1px solid var(--c-border);
}
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: var(--c-surface); z-index: 2; font-weight: 700; text-align: right;
  min-width: 96px; font-family: Consolas, "Segoe UI", monospace;
}
th.sticky-col { right: 0; }
thead th.sticky-col { z-index: 4; background: var(--c-chip-bg); }
th.idx-col, td.idx-col { color: var(--c-muted3); font-size: 11px; min-width: 28px; }
td.zero { color: var(--c-muted3); }
td.neg { color: #ef9e99; font-weight: 700; }
td.total-cell { font-weight: 800; }
td.price-cell { font-variant-numeric: tabular-nums; }
td.wh-cell { color: var(--c-wh); font-weight: 700; }
td.name-cell { color: var(--c-muted2); }
td.codes-cell { color: var(--c-muted3); font-family: Consolas, monospace; font-size: 11px; }
th.grp-start, td.grp-start { border-right: 1px solid var(--c-divider); }
th.grp-sales { color: var(--c-sales); }
th.grp-stock { color: var(--c-stock); }
th.grp-wh { color: var(--c-wh); }
th.grp-price { color: var(--c-price); }
tr.total-row td { font-weight: 800; background: var(--c-row-alt); border-top: 2px solid var(--c-total-border); }
tr.total-row td.sticky-col { background: var(--c-row-alt); color: var(--c-muted2); }
tbody tr:hover td { background: var(--c-row-alt); }
tbody tr:hover td.sticky-col { background: var(--c-row-alt); }

td.img-cell { padding: 3px 6px; }
.item-thumb {
  width: 46px; height: 46px; border-radius: 8px; object-fit: cover; background: var(--c-thumb-bg);
  cursor: pointer; display: block; margin: 0 auto;
}
.item-thumb-empty {
  width: 46px; height: 46px; border-radius: 8px; background: var(--c-thumb-bg); display: flex;
  align-items: center; justify-content: center; color: var(--c-thumb-text); font-size: 18px; margin: 0 auto;
}

/* ---------------- تكبير الصورة (خلفية داكنة ثابتة) ---------------- */
.item-detail-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.78); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.item-detail-card {
  position: relative; width: 100%; max-width: 480px; max-height: 88vh; 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: 80vh; }
.item-detail-image-view img { display: block; max-width: 100%; max-height: 80vh; object-fit: contain; }
.lightbox-caption { padding: 10px 14px; color: #e8ecf5; font-size: 14px; font-weight: 700; text-align: center; background: #121829; }
.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);
}

@media (max-width: 600px) {
  .container { padding: 8px; }
  .report-head { flex-direction: column; align-items: stretch; }
  .export-btn { width: 100%; }
}
