@import url('../fonts/fonts.css');

/* =========================================================
   فواتيري — التنسيقات
   ========================================================= */

:root {
  --bg: #f2f5f7;
  --surface: #ffffff;
  --surface-2: #f7f9fa;
  --line: #e4eaee;
  --ink: #101828;
  --ink-2: #475467;
  --muted: #98a2b3;
  --primary: #0b6b5b;
  --primary-700: #08503f;
  --primary-50: #e8f4f1;
  --primary-100: #d3ece6;
  --accent: #f79009;
  --accent-50: #fff6e6;
  --danger: #d92d20;
  --danger-50: #fef3f2;
  --indigo: #3538cd;
  --indigo-50: #eef2ff;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 8px 24px -12px rgba(16, 24, 40, .22);
  --radius: 16px;
  --tabbar-h: 68px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Almarai', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

body { overscroll-behavior-y: none; }

h1, h2, h3, h4, p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
a { color: var(--primary); }

.num, .amount, .value { font-variant-numeric: tabular-nums; }

/* ---------------------------- الهيكل ---------------------------- */
.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
}

@media (min-width: 600px) {
  body { background: #dfe6ea; }
  .app { box-shadow: 0 0 0 1px rgba(16, 24, 40, .05), 0 30px 60px -30px rgba(16, 24, 40, .35); }
}

.appbar {
  background: linear-gradient(140deg, #0d7d68 0%, #0b6b5b 45%, #07463a 100%);
  color: #fff;
  padding: calc(14px + env(safe-area-inset-top)) 18px 30px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  position: relative;
  overflow: hidden;
}

.appbar::after {
  content: '';
  position: absolute;
  inset-inline-start: -60px;
  top: -70px;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .16), transparent 65%);
  pointer-events: none;
}

.appbar-main { flex: 1; min-width: 0; position: relative; z-index: 1; }
.appbar-kicker { font-size: 11.5px; font-weight: 700; opacity: .78; letter-spacing: .2px; min-height: 16px; }
.appbar-title { font-size: 21px; font-weight: 800; letter-spacing: -.2px; margin-top: 1px; }
.appbar-actions { display: flex; gap: 6px; position: relative; z-index: 1; padding-top: 4px; }

.appbar-actions button {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 0;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  display: grid;
  place-items: center;
}
.appbar-actions button:active { background: rgba(255, 255, 255, .26); }

.screen-host { padding: 0 14px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom)); }
.screen { animation: fade .18s ease; }
@keyframes fade { from { opacity: .4; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------------------------- الشريط السفلي ---------------------------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 520px;
  margin: 0 auto;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, .97);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 40;
}

.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 700;
  padding: 6px 2px;
  position: relative;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--primary); }
.tab.active::before {
  content: '';
  position: absolute;
  top: 0;
  width: 26px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--primary);
}

/* ---------------------------- بطاقات ---------------------------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(16, 24, 40, .05);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}
.card + .card { margin-top: 12px; }

.hero {
  margin-top: -18px;
  border-radius: 20px;
  padding: 18px;
  background: #fff;
  box-shadow: 0 10px 30px -16px rgba(16, 24, 40, .4);
  border: 1px solid rgba(16, 24, 40, .05);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: '';
  position: absolute;
  inset-inline-start: -40px;
  bottom: -60px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(11, 107, 91, .09), transparent 65%);
}
.hero-label { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.hero-value { font-size: 34px; font-weight: 800; letter-spacing: -1px; margin-top: 2px; line-height: 1.15; }
.hero-value small { font-size: 15px; font-weight: 700; color: var(--ink-2); margin-inline-start: 4px; letter-spacing: 0; }
.hero-foot {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  font-size: 12px;
  color: var(--ink-2);
  position: relative;
}
.hero-foot b { font-weight: 800; color: var(--ink); }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 22px 2px 10px;
}
.section-title { font-size: 15px; font-weight: 800; }
.section-link {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 12.5px;
  font-weight: 700;
  padding: 4px;
}

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.kpi {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 13px;
  position: relative;
  overflow: hidden;
}
.kpi .label { font-size: 11.5px; font-weight: 700; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.kpi .value { font-size: 19px; font-weight: 800; margin-top: 4px; letter-spacing: -.3px; }
.kpi .value small { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: 0; }
.kpi .hint { font-size: 11px; color: var(--muted); margin-top: 2px; }
.kpi .kpi-icon {
  position: absolute;
  inset-inline-end: 10px;
  top: 10px;
  width: 26px;
  height: 26px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--primary-50);
  color: var(--primary);
}
.kpi .kpi-icon svg { width: 15px; height: 15px; }
.kpi.accent .kpi-icon { background: var(--accent-50); color: #b54708; }
.kpi.indigo .kpi-icon { background: var(--indigo-50); color: var(--indigo); }
.kpi.danger .kpi-icon { background: var(--danger-50); color: var(--danger); }

/* ---------------------------- أزرار ---------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  border: 0;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  width: 100%;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.985); }
.btn svg { width: 18px; height: 18px; }
.btn.secondary { background: var(--primary-50); color: var(--primary); }
.btn.ghost { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.btn.danger { background: var(--danger-50); color: var(--danger); }
.btn.dark { background: var(--ink); }
.btn.sm { height: 38px; font-size: 13px; padding: 0 13px; border-radius: 11px; width: auto; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 21px; height: 21px; }

.fab {
  position: fixed;
  inset-inline-end: calc(50% - 260px + 16px);
  bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 19px;
  border: 0;
  background: linear-gradient(160deg, #0d8a72, #0b6b5b);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 14px 26px -10px rgba(11, 107, 91, .7);
  z-index: 30;
}
.fab svg { width: 26px; height: 26px; }
.fab:active { transform: scale(.95); }

@media (max-width: 551px) {
  .fab { inset-inline-end: 16px; }
}

/* ---------------------------- حقول ---------------------------- */
.field { display: block; margin-bottom: 13px; }
.field > span { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; }

.input, select.input, textarea.input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  padding: 0 14px;
  font-size: 15px;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}
textarea.input { height: auto; min-height: 84px; padding: 12px 14px; line-height: 1.6; }
select.input {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2398a2b3' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 14px center;
  padding-left: 38px;
}
.input:focus, select.input:focus, textarea.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 107, 91, .12);
}
.input[readonly] { background: var(--surface-2); color: var(--ink-2); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.segmented {
  display: flex;
  background: #e9eef1;
  border-radius: 13px;
  padding: 4px;
  gap: 4px;
}
.segmented button {
  flex: 1;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 700;
}
.segmented button.active { background: #fff; color: var(--primary); box-shadow: var(--shadow-sm); }

/* ---------------------------- قوائم ---------------------------- */
.list { display: flex; flex-direction: column; gap: 8px; }

.row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 12px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
  text-align: right;
  font: inherit;
  color: inherit;
}
.row:active { background: var(--surface-2); }
.row .avatar {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--primary-50);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 16px;
  flex: 0 0 auto;
}
.row .avatar.alt { background: var(--indigo-50); color: var(--indigo); }
.row .avatar.warn { background: var(--accent-50); color: #b54708; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-size: 14.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.row .end { text-align: left; flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.row .amount { font-size: 14.5px; font-weight: 800; }
.row .amount.pos { color: var(--primary); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 23px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--ink-2);
  white-space: nowrap;
}
.chip.ok { background: #e7f6f1; color: #0a7a62; }
.chip.low { background: var(--accent-50); color: #b54708; }
.chip.out { background: var(--danger-50); color: #b42318; }
.chip.sale { background: var(--primary-50); color: var(--primary); }
.chip.purchase { background: var(--indigo-50); color: var(--indigo); }
.chip.soft { background: #f0f2f5; color: var(--ink-2); }

.empty {
  text-align: center;
  padding: 34px 18px;
  color: var(--muted);
  font-size: 13.5px;
}
.empty .empty-icon {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: #fff;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  color: var(--muted);
}
.empty .empty-icon svg { width: 26px; height: 26px; }
.empty b { display: block; color: var(--ink-2); font-size: 14.5px; margin-bottom: 3px; }

.banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: #fff8ea;
  border: 1px solid #f6dcae;
  color: #8a4b00;
  border-radius: 14px;
  padding: 11px 12px;
  font-size: 12.5px;
  font-weight: 700;
  margin-top: 14px;
  line-height: 1.5;
}
.banner svg { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 1px; }
.banner .banner-actions { display: flex; gap: 6px; margin-top: 8px; }
.banner .banner-actions button {
  border: 1px solid #eecf9a;
  background: #fff;
  color: #8a4b00;
  border-radius: 9px;
  height: 30px;
  padding: 0 10px;
  font-size: 11.5px;
  font-weight: 700;
}

.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.quick {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  text-align: right;
  font: inherit;
  color: inherit;
  font-weight: 700;
  font-size: 13.5px;
}
.quick .q-icon {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: var(--primary-50);
  color: var(--primary);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.quick .q-icon svg { width: 19px; height: 19px; }
.quick.indigo .q-icon { background: var(--indigo-50); color: var(--indigo); }
.quick.accent .q-icon { background: var(--accent-50); color: #b54708; }
.quick.ink .q-icon { background: #eef0f3; color: var(--ink); }

/* ---------------------------- بحث ---------------------------- */
.searchbar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 6px 0 4px;
  height: 48px;
  margin-top: 12px;
}
.searchbar svg.leading { width: 19px; height: 19px; color: var(--muted); margin-inline-start: 8px; }
.searchbar input {
  flex: 1;
  border: 0;
  height: 100%;
  background: transparent;
  font-size: 15px;
  padding: 0 4px;
  color: var(--ink);
}
.searchbar input:focus { outline: none; }
.searchbar .scan-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: 0;
  background: var(--primary-50);
  color: var(--primary);
  display: grid;
  place-items: center;
}
.searchbar .scan-btn svg { width: 19px; height: 19px; }

/* ---------------------------- الشيت (نافذة كاملة) ---------------------------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  animation: sheetIn .2s ease;
  max-width: 520px;
  margin: 0 auto;
}
@keyframes sheetIn { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font-size: 16px; font-weight: 800; flex: 1; }
.sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(24px + env(safe-area-inset-bottom));
}
.sheet-body.has-foot { padding-bottom: 110px; }
.sheet-foot {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}

/* ---------------------------- نوافذ صغيرة ---------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .48);
  z-index: 110;
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fade .15s ease;
}
.modal {
  background: #fff;
  border-radius: 18px;
  padding: 18px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .45);
}
.modal h3 { font-size: 16px; font-weight: 800; margin-bottom: 6px; }
.modal p { font-size: 13.5px; color: var(--ink-2); line-height: 1.6; }
.modal .modal-actions { display: flex; gap: 8px; margin-top: 16px; }

.toast-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + 86px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 120;
  pointer-events: none;
  padding: 0 20px;
}
.toast {
  background: #101828;
  color: #fff;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 14px 30px -12px rgba(0, 0, 0, .55);
  max-width: 100%;
  animation: toastIn .2s ease;
  text-align: center;
}
.toast.ok { background: #0b6b5b; }
.toast.err { background: #b42318; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------------------- الفاتورة داخل التطبيق ---------------------------- */
.inv-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.inv-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 800;
}
.inv-type-badge.sale { background: var(--primary-50); color: var(--primary); }
.inv-type-badge.purchase { background: var(--indigo-50); color: var(--indigo); }

.inv-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin-top: 16px; }
.inv-meta .m-label { font-size: 11px; color: var(--muted); font-weight: 700; }
.inv-meta .m-value { font-size: 13.5px; font-weight: 700; margin-top: 1px; }

.inv-items { margin-top: 16px; border-top: 1px solid var(--line); }
.inv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.inv-item .ii-main { flex: 1; min-width: 0; }
.inv-item .ii-name { font-size: 13.5px; font-weight: 700; }
.inv-item .ii-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.inv-item .ii-total { font-size: 13.5px; font-weight: 800; }

.totals { margin-top: 14px; display: flex; flex-direction: column; gap: 7px; }
.totals .t-row { display: flex; justify-content: space-between; font-size: 13.5px; color: var(--ink-2); }
.totals .t-row.grand {
  border-top: 1px dashed var(--line);
  padding-top: 10px;
  margin-top: 3px;
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
}

/* ---------------------------- محرر الفاتورة ---------------------------- */
.editor-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 12px;
  margin-bottom: 8px;
}
.editor-item .ei-top { display: flex; align-items: flex-start; gap: 8px; }
.editor-item .ei-name { flex: 1; font-size: 13.5px; font-weight: 700; }
.editor-item .ei-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.editor-item .ei-controls { display: flex; align-items: center; gap: 8px; margin-top: 10px; }

.stepper {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  overflow: hidden;
  height: 40px;
  background: #fff;
}
.stepper button {
  width: 34px;
  height: 100%;
  border: 0;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.stepper input {
  width: 46px;
  height: 100%;
  border: 0;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  background: #fff;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.price-input { position: relative; flex: 1; }
.price-input input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0 34px 0 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  text-align: left;
  direction: ltr;
}
.price-input .cur {
  position: absolute;
  inset-inline-start: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}
.line-total { font-size: 13px; font-weight: 800; min-width: 62px; text-align: left; }

.summary-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin-top: 14px;
}
.summary-row { display: flex; justify-content: space-between; align-items: center; font-size: 13.5px; color: var(--ink-2); padding: 4px 0; }
.summary-row.grand { border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 10px; font-size: 18px; font-weight: 800; color: var(--ink); }
.summary-row .neg { color: var(--danger); }

/* ---------------------------- الماسح ---------------------------- */
.scan-stage {
  position: relative;
  background: #0b1210;
  border-radius: 16px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
}
.scan-stage video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute;
  inset: 18% 12%;
  border: 2px solid rgba(255, 255, 255, .8);
  border-radius: 14px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, .35);
}
.scan-frame::after {
  content: '';
  position: absolute;
  inset-inline: 8%;
  top: 50%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #4ade80, transparent);
  animation: scanline 2s ease-in-out infinite;
}
@keyframes scanline { 0%, 100% { top: 18%; } 50% { top: 82%; } }
.scan-hint {
  position: absolute;
  bottom: 10px;
  inset-inline: 0;
  text-align: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .6);
}
.scan-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  text-align: center;
  color: #cbd5e1;
  font-size: 12.5px;
  line-height: 1.7;
}

/* ---------------------------- التقارير ---------------------------- */
.presets { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; -webkit-overflow-scrolling: touch; }
.presets::-webkit-scrollbar { display: none; }
.preset {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 700;
}
.preset.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 116px;
  margin-top: 12px;
  padding-top: 6px;
}
.chart .bar-wrap { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 4px; }
.chart .bar {
  background: linear-gradient(180deg, #17a68c, #0b6b5b);
  border-radius: 5px 5px 2px 2px;
  min-height: 4px;
  transition: height .3s ease;
}
.chart .bar.zero { background: #e4eaee; }
.chart-x { display: flex; gap: 5px; margin-top: 6px; }
.chart-x span { flex: 1; text-align: center; font-size: 9.5px; color: var(--muted); font-weight: 700; }

.top-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.top-row:last-child { border-bottom: 0; }
.top-rank {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink-2);
  display: grid;
  place-items: center;
  font-size: 11.5px;
  font-weight: 800;
  flex: 0 0 auto;
}
.top-row:first-child .top-rank { background: var(--primary-50); color: var(--primary); }

/* ---------------------------- صفحة "المزيد" ---------------------------- */
.more-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 12px;
  text-align: right;
  font: inherit;
  color: inherit;
  margin-bottom: 8px;
}
.more-item .mi-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--primary-50);
  color: var(--primary);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.more-item .mi-icon svg { width: 19px; height: 19px; }
.more-item .mi-main { flex: 1; min-width: 0; }
.more-item .mi-title { font-size: 14px; font-weight: 700; }
.more-item .mi-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.more-item .chev { color: var(--muted); }
.more-item .chev svg { width: 18px; height: 18px; transform: scaleX(-1); }
.more-item.danger .mi-icon { background: var(--danger-50); color: var(--danger); }
.more-item.danger .mi-title { color: var(--danger); }
.more-item.indigo .mi-icon { background: var(--indigo-50); color: var(--indigo); }

.about-note { font-size: 12px; color: var(--muted); text-align: center; margin-top: 18px; line-height: 1.8; }

/* ---------------------------- الطباعة ---------------------------- */
.print-area { display: none; }

@media print {
  html, body { background: #fff !important; }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block !important; }
  @page { size: A4; margin: 12mm; }
}

.inv-print {
  direction: rtl;
  color: #000;
  font-family: 'Almarai', Tahoma, sans-serif;
  font-size: 12px;
  line-height: 1.6;
}
.inv-print .p-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #0b6b5b;
  padding-bottom: 12px;
  gap: 16px;
}
.inv-print .p-store { font-size: 20px;
  font-weight: 800;
  color: #0b6b5b;
}
.inv-print .p-store-meta { font-size: 11px; color: #444; margin-top: 4px; }
.inv-print .p-title { text-align: left; }
.inv-print .p-title .p-kind {
  font-size: 15px;
  font-weight: 800;
  border: 1.5px solid #0b6b5b;
  color: #0b6b5b;
  border-radius: 6px;
  padding: 3px 10px;
  display: inline-block;
}
.inv-print .p-num { font-size: 12px; font-weight: 700; margin-top: 6px; }
.inv-print .p-num span { color: #666; font-weight: 400; }

.inv-print .p-meta {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin: 14px 0 12px;
}
.inv-print .p-meta .pm-block { font-size: 11.5px; }
.inv-print .p-meta .pm-label { color: #666; font-size: 10.5px; }
.inv-print .p-meta .pm-value { font-weight: 700; font-size: 12.5px; }

.inv-print table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.inv-print th {
  background: #f0f6f4;
  color: #07463a;
  font-size: 11px;
  font-weight: 700;
  padding: 7px 8px;
  border: 1px solid #cfe0da;
  text-align: right;
}
.inv-print td { padding: 7px 8px; border: 1px solid #dfe7e4; font-size: 11.5px; }
.inv-print td.c { text-align: center; }
.inv-print td.l { text-align: left; }
.inv-print .p-totals { width: 46%; margin-inline-start: auto; margin-top: 10px; }
.inv-print .p-totals .pr { display: flex; justify-content: space-between; padding: 4px 2px; font-size: 11.5px; }
.inv-print .p-totals .pr.grand {
  border-top: 1.5px solid #0b6b5b;
  margin-top: 4px;
  padding-top: 7px;
  font-size: 14px;
  font-weight: 800;
  color: #07463a;
}
.inv-print .p-note { margin-top: 16px; font-size: 11px; color: #444; border-top: 1px dashed #ccc; padding-top: 8px; }
.inv-print .p-foot {
  margin-top: 26px;
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: #666;
}
.inv-print .p-sign { border-top: 1px solid #999; width: 150px; text-align: center; padding-top: 5px; }

/* ---------------------------- أدوات مساعدة ---------------------------- */
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack-8 > * + * { margin-top: 8px; }
