/* ============================================================
   خزنة — نظام التصميم
   ============================================================
   رموز هذا الملف مأخوذة من الصفحة العامة khaznah.store كما هي،
   ليكون الانتقال من الإعلان إلى النظام بلا قطيعة بصرية.

   الخصائص المنطقية (inline-start / inline-end) مستخدمة في كل
   مكان، فالتبديل إلى الإنجليزية لاحقًا لا يحتاج ورقة أنماط ثانية.

   لا خطّ خارجي ولا سكربت خارجي: الصفحة العامة تُحمّل صفر ملفات
   خارجية ولهذا تبدو سريعة، وهذا النظام يلتزم بالانضباط نفسه.

   تذكير: applyTheme() في index.html يكتب بعض هذه المتغيّرات
   مباشرةً على documentElement من إعدادات المتجر، فتعلو على ما
   هنا. أسماء المتغيّرات هنا هي نفسها التي تكتبها، عمدًا.
   ============================================================ */

/* ---------- السمة الداكنة: الأصل ---------- */
:root {
  --bg:          #0a0a14;
  --bg2:         #13131f;
  --card:        #13131f;
  --surface:     rgba(255,255,255,.04);
  --surface2:    rgba(255,255,255,.06);
  --border:      rgba(255,255,255,.08);
  --line2:       rgba(255,255,255,.14);

  --text:        #f0f0f5;
  --muted:       #a0a0b0;

  --accent:      #2dd4bf;
  --accent-ink:  #04201c;   /* النصّ فوق لون التمييز */
  --accent-soft: rgba(45,212,191,.12);
  --accent2:     #f59e0b;
  --accent2-ink: #2a1a00;

  --ok:          #22c55e;
  --danger:      #ef4444;
  --warn:        #f59e0b;
  --info:        #3b82f6;

  --ok-bg:       rgba(34,197,94,.14);
  --err-bg:      rgba(239,68,68,.14);
  --warn-bg:     rgba(245,158,11,.14);
  --warn-bd:     rgba(245,158,11,.34);

  --radius:      14px;
  --radius-sm:   10px;
  --radius-lg:   20px;
  --shadow:      0 1px 2px rgba(0,0,0,.30), 0 8px 28px rgba(0,0,0,.26);
  --shadow-lg:   0 18px 48px rgba(0,0,0,.45);

  --side-w:      248px;
  --topbar-h:    58px;

  --font: "Segoe UI", Tajawal, Cairo, system-ui, -apple-system, sans-serif;

  color-scheme: dark;
}

/* ---------- السمة الفاتحة ---------- */
:root[data-mode="light"] {
  --bg:          #f4f6fa;
  --bg2:         #ffffff;
  --card:        #ffffff;
  --surface:     rgba(10,10,20,.03);
  --surface2:    rgba(10,10,20,.05);
  --border:      rgba(10,10,20,.11);
  --line2:       rgba(10,10,20,.18);

  --text:        #12131c;
  --muted:       #5b6478;

  --accent:      #0f766e;
  --accent-ink:  #ffffff;
  --accent-soft: rgba(15,118,110,.10);
  --accent2:     #b45309;
  --accent2-ink: #ffffff;

  --ok:          #15803d;
  --danger:      #b91c1c;
  --warn:        #b45309;
  --info:        #1d4ed8;

  --ok-bg:       rgba(21,128,61,.10);
  --err-bg:      rgba(185,28,28,.09);
  --warn-bg:     rgba(180,83,9,.10);
  --warn-bd:     rgba(180,83,9,.26);

  --shadow:      0 1px 2px rgba(7,11,58,.06), 0 6px 22px rgba(7,11,58,.07);
  --shadow-lg:   0 20px 50px rgba(7,11,58,.16);

  color-scheme: light;
}

/* ============================================================
   الأساس
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

img, video, svg { max-width: 100%; }

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { opacity: .85; }

h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.3; font-weight: 800; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: .98rem; margin-top: 1.1em; }
p  { margin: 0 0 .8em; }

code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  background: var(--surface2);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: .9em;
}

/* حلقة التركيز ظاهرة دائمًا: لوحة المفاتيح وحدها وسيلة بعض المستخدمين */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.hidden { display: none !important; }

/* من يفضّل تقليل الحركة لا تُفرض عليه */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* ============================================================
   القشرة: شريط علوي + تنقّل جانبي/سفلي
   ============================================================ */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  padding: 0 18px;
  min-height: var(--topbar-h);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 40;
}
header h1 { font-size: 15.5px; margin: 0; font-weight: 800; }
header .who { font-size: 12.5px; color: var(--muted); }

/* زرّ تبديل السمة */
.mode-btn {
  margin: 0;
  width: 36px; height: 36px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
}
.mode-btn:hover { background: var(--surface2); }

/* ---------- شريط التنقّل ---------- */
/* في الشاشة الكبيرة عمود جانبي، وفي الجوال شريط سفلي يُمرَّر أفقيًا */
.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.tabs button {
  margin: 0;
  padding: 8px 14px;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.tabs button:hover { background: var(--surface2); color: var(--text); }
.tabs button.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 700;
}

/* شريط التنقّل الرئيسي يلتصق أسفل الشريط العلوي ويُمرَّر أفقيًا
   في الجوال بدل أن يلتفّ إلى أربعة صفوف تأكل الشاشة */
#mainTabs {
  position: sticky;
  top: var(--topbar-h);
  z-index: 30;
  background: var(--bg);
  margin: 0 -16px 18px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
#mainTabs::-webkit-scrollbar { height: 4px; }
#mainTabs::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 2px; }

main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 16px 90px;
}

/* ---------- الشاشة الكبيرة: الشريط عمود جانبي ---------- */
/* لا يحتاج هذا تغييرًا في الترميز ولا في JS: نفس أزرار التبويب
   تُعاد ترتيبها. تسعة عشر تبويبًا في شريط أفقي تعني تمريرًا للوصول
   إلى الإعدادات — وفي عمود تُرى كلّها دفعةً واحدة. */
@media (min-width: 1024px) {
  #appView main {
    display: grid;
    grid-template-columns: var(--side-w) minmax(0, 1fr);
    gap: 26px;
    align-items: start;
  }
  /* اللافتات تمتدّ على العمودين فوق الشبكة */
  #mustChangeBanner, #expiryBanner { grid-column: 1 / -1; }

  #mainTabs {
    flex-direction: column;
    flex-wrap: nowrap;
    overflow: visible;
    gap: 3px;
    position: sticky;
    top: calc(var(--topbar-h) + 18px);
    margin: 0;
    padding: 10px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  #mainTabs button {
    width: 100%;
    text-align: start;
    border-radius: var(--radius-sm);
    padding: 9px 13px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
  #mainTabs button.active {
    /* شريط رفيع عند الحافّة الداخلية يُثبّت العين على الموضع */
    box-shadow: inset 3px 0 0 var(--accent-ink);
  }
  [dir="rtl"] #mainTabs button.active { box-shadow: inset -3px 0 0 var(--accent-ink); }

  #views { min-width: 0; }
}

/* شاشة الدخول: البطاقة في وسط الشاشة لا معلّقة في أعلاها */
#loginView main {
  min-height: 100vh;
  display: grid;
  align-content: center;
  margin-top: 0 !important;
  padding-block: 32px;
}

/* ============================================================
   البطاقات
   ============================================================ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.card h2 {
  font-size: 1.05rem;
  margin: 0 0 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.card h2:only-child { border: 0; padding: 0; margin: 0; }

.sub-box {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-top: 10px;
  background: var(--surface);
}

.cards { display: grid; gap: 14px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
}
.grid .card { margin-bottom: 0; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 150px; }

.note {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.75;
  margin: 4px 0 0;
}

/* ============================================================
   الأزرار
   ============================================================ */
button {
  font: inherit;
  font-weight: 700;
  padding: 11px 20px;
  margin-top: 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  transition: filter .15s, background .15s;
  /* هدف لمس مريح: الإبهام لا يصيب 28 بكسل */
  min-height: 42px;
}
button:hover:not(:disabled) { filter: brightness(1.08); }
button:active:not(:disabled) { filter: brightness(.94); }
button:disabled { opacity: .5; cursor: not-allowed; }

button.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
button.secondary:hover:not(:disabled) { background: var(--surface2); filter: none; }

button.danger { background: var(--danger); color: #fff; }

button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}
button.ghost:hover:not(:disabled) { background: var(--surface); color: var(--text); }

/* ============================================================
   الحقول
   ============================================================ */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 12px 0 5px;
  color: var(--text);
}

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 11px 13px;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 42px;
  transition: border-color .15s, box-shadow .15s;
}
:root[data-mode="light"] input,
:root[data-mode="light"] select,
:root[data-mode="light"] textarea { background: #fff; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .75; }
input:disabled, select:disabled, textarea:disabled {
  background: var(--surface);
  color: var(--muted);
  cursor: not-allowed;
}
textarea { min-height: 72px; line-height: 1.7; resize: vertical; }

input[type=color] {
  padding: 3px;
  height: 42px;
  cursor: pointer;
}
input[type=checkbox], input[type=radio] {
  width: auto;
  min-height: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
input[type=file] { padding: 9px; background: var(--surface); }

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 10px 0;
}
.toggle-row input { width: auto; min-height: 0; }
.toggle-row label { margin: 0; font-weight: 500; }

/* ============================================================
   الجداول
   ============================================================ */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  margin-top: 10px;
}
th, td {
  padding: 10px 12px;
  text-align: start;
  border-bottom: 1px solid var(--border);
}
th {
  font-weight: 700;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface);
  white-space: nowrap;
}
tbody tr:hover td { background: var(--surface); }
tr:last-child td { border-bottom: 0; }

/* الجدول العريض يُمرَّر داخل حدوده بدل أن يمدّ الصفحة كلها */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-inline: -4px;
  padding-inline: 4px;
}

/* ============================================================
   الرسائل والشارات
   ============================================================ */
.msg {
  display: none;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
}
.msg.ok, .msg.err { display: block; }
.msg.ok  { background: var(--ok-bg);  color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.msg.err { background: var(--err-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

.banner {
  background: var(--warn-bg);
  border: 1px solid var(--warn-bd);
  color: var(--warn);
  padding: 12px 15px;
  border-radius: var(--radius-sm);
  margin-bottom: 15px;
  font-size: 13.5px;
  font-weight: 600;
}

.notice {
  background: var(--warn-bg);
  border: 1px solid var(--warn-bd);
  color: var(--warn);
  padding: 12px 15px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 13.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.notice button {
  margin: 0;
  padding: 5px 12px;
  min-height: 0;
  background: transparent;
  color: inherit;
  border: 1px solid currentColor;
  font-size: 12px;
}

.dismiss-note { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dismiss-note button { margin: 0; min-height: 0; padding: 5px 12px; font-size: 12px; }

.badge-count, .tab-badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  margin-inline-start: 6px;
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}
.tabs button.active .badge-count,
.tabs button.active .tab-badge { background: var(--accent-ink); color: var(--accent); }

/* شارة حالة */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  background: var(--surface2);
  color: var(--muted);
}
.badge.ok   { background: var(--ok-bg);   color: var(--ok); }
.badge.bad  { background: var(--err-bg);  color: var(--danger); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

/* ============================================================
   مؤشّرات ومجاميع
   ============================================================ */
.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi .lbl { font-size: 12.5px; color: var(--muted); display: block; margin-bottom: 6px; }
.kpi .val, .kpi .num {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
  display: block;
}
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }

.sum-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  font-size: 14px;
  border-bottom: 1px dashed var(--border);
}
.sum-line:last-of-type { border-bottom: 0; }
.sum-total {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 0 4px;
  margin-top: 6px;
  border-top: 2px solid var(--accent);
  font-size: 1.22rem;
  font-weight: 800;
  color: var(--accent);
}

.sec {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: none;
  margin: 18px 0 8px;
}

/* ============================================================
   نافذة البيع — أهداف أكبر لأنها تُستخدم مئات المرات يوميًا
   ============================================================ */
.pick-row {
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .12s;
}
.pick-row:hover { background: var(--accent-soft); border-color: var(--accent); }

#tab-pos .sum-total { font-size: 1.45rem; }
#tab-pos button[onclick*="checkout"], #tab-pos .pay-btn {
  min-height: 52px;
  font-size: 1rem;
}

/* ============================================================
   النوافذ المنبثقة
   ============================================================ */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 100;
}
.modal-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

/* ============================================================
   اختيار ألوان المتجر
   ============================================================ */
.theme-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.theme-dot {
  width: 38px; height: 38px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  padding: 0;
  margin: 0;
  min-height: 0;
}
.theme-dot.on { border-color: var(--text); }

/* ============================================================
   الشاشات الصغيرة
   ============================================================ */
@media (max-width: 720px) {
  /* الشريط العلوي يلتفّ إلى سطرين في الجوال، فيصير ارتفاعه أكبر من
     --topbar-h ويركبه شريط التبويبات اللاصق عند التمرير. الحلّ:
     الشريط العلوي يمرّ مع الصفحة، والتبويبات وحدها تلتصق بالأعلى. */
  header { position: static; }
  #mainTabs { top: 0; }
  header #verTag { display: none; }

  body { font-size: 14.5px; }
  main { padding: 14px 14px 90px; }
  .card { padding: 16px; border-radius: var(--radius-sm); }
  header { padding: 0 14px; }
  header h1 { font-size: 14.5px; }
  .row > * { min-width: 100%; }
  .grid { grid-template-columns: 1fr; }
  #mainTabs { margin-inline: -14px; padding-inline: 14px; }
  .kpi .val, .kpi .num { font-size: 1.3rem; }
}

/* ============================================================
   الطباعة — الورق أبيض دائمًا مهما كانت السمة على الشاشة
   ============================================================ */
@media print {
  /* الورق أبيض مهما كانت السمة على الشاشة */
  :root, :root[data-mode="light"] {
    --bg: #fff; --bg2: #fff; --card: #fff;
    --text: #000; --muted: #444;
    --border: #ccc; --surface: #fff; --surface2: #f5f5f5;
  }
  body { background: #fff !important; color: #000 !important; }

  /* ---------- آليّة طباعة الفاتورة ---------- */
  /* إخفاء كل شيء عدا منطقة الطباعة. نستخدم display لا visibility:
     الأخيرة تُبقي العناصر شاغلة لمساحتها، فتظهر الفاتورة في ركن
     الورقة على الجوال بدل أن تملأها. */
  body > *:not(.modal-bg) { display: none !important; }
  .modal-bg {
    position: static !important; display: block !important;
    background: none !important; backdrop-filter: none !important; padding: 0 !important;
  }
  .modal-box {
    max-width: 100% !important; width: 100% !important; max-height: none !important;
    overflow: visible !important; padding: 0 !important;
    box-shadow: none !important; border: 0 !important; border-radius: 0 !important;
  }
  #printArea { width: 100%; color: #000; }
  #printArea * { color: #000 !important; }
  .no-print, .noprint { display: none !important; }
  @page { margin: 10mm; }
}
