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

:root {
  --bg: #F4F8FD;
  --card: #FFFFFF;
  --tx: #1E293B;
  --tx2: #64748B;
  --pri: #2563EB;
  --pri-light: #EFF6FF;
  --ln: #E2E8F0;
  --tile-bg: #FFFFFF;
  --tile-border: #F1F5F9;
  --sh: 0 4px 20px rgba(0, 0, 0, 0.04);
  --sh-lg: 0 10px 30px rgba(37, 99, 235, 0.12);
  
  /* ألوان ثابتة ذات دلالات موحدة */
  --c-profit: #10B981;  /* أخضر: ربح / قبض / متوفر */
  --c-loss: #EF4444;    /* أحمر: خسارة / دين علي للموردين / حذف */
  --c-warn: #F59E0B;    /* برتقالي: تنبيه مخزون منخفض / تحذيرات */
  --c-debt: #8B5CF6;    /* بنفسجي: ديون الزبائن لي */
}

.dark {
  --bg: #0B132B;
  --card: #1E293B;
  --tx: #F8FAFC;
  --tx2: #94A3B8;
  --pri: #3B82F6;
  --pri-light: rgba(59, 130, 246, 0.15);
  --ln: #334155;
  --tile-bg: #182236;
  --tile-border: #2A3854;
  --sh: 0 4px 20px rgba(0, 0, 0, 0.4);
  --sh-lg: 0 10px 30px rgba(0, 0, 0, 0.6);
}

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

body {
  font-family: 'Cairo', system-ui, -apple-system, sans-serif;
  font-weight: 500;
  background: var(--bg);
  color: var(--tx);
  padding: env(safe-area-inset-top) 0 calc(115px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

#app {
  padding: 0 14px;
  max-width: 540px;
  margin: auto;
}

/* ===== تذكير النسخ الاحتياطي الأسبوعي ===== */
.backup-reminder {
  background: linear-gradient(135deg, #FEF3C7, #FDE68A);
  color: #92400E;
  border: 1px solid #FCD34D;
  border-radius: 18px;
  padding: 12px 14px;
  margin: 10px auto;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--sh);
}
.backup-reminder button {
  background: #D97706;
  color: #fff;
  border: 0;
  padding: 6px 12px;
  border-radius: 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

/* ===== الشريط العلوي العائم ===== */
.top-nav {
  position: sticky;
  top: 8px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-radius: 9999px;
  padding: 6px 10px;
  margin: 6px auto 14px;
  max-width: 520px;
  box-shadow: var(--sh);
  border: 1px solid var(--ln);
}
.tn-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn-scanner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--ln);
  background: var(--bg);
  color: var(--tx2);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-create {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #EFF6FF;
  color: #2563EB;
  border: 1px solid #DBEAFE;
  border-radius: 9999px;
  padding: 7px 15px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.dark .btn-create {
  background: rgba(37, 99, 235, 0.2);
  color: #93C5FD;
  border-color: rgba(37, 99, 235, 0.4);
}
.btn-create:active, .btn-scanner:active { transform: scale(0.95); }

.tn-left {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--bg);
  border: 1px solid var(--ln);
  border-radius: 9999px;
  padding: 3px 6px;
}
.tn-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--tx2);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}
.tn-icon-btn:hover { color: var(--tx); background: rgba(0,0,0,0.05); }
.dark .tn-icon-btn:hover { background: rgba(255,255,255,0.08); }

.avatar-badge {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1E9BE0, #2563EB);
  color: #fff;
  font-size: 13.5px;
  font-weight: 700;
  display: grid;
  place-items: center;
  cursor: pointer;
  margin-left: 2px;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

/* ===== ترويسة الترحيب ===== */
.welcome-hero {
  text-align: center;
  margin: 12px 0 16px;
}
.welcome-title {
  font-size: 23px;
  font-weight: 800;
  color: var(--tx);
  letter-spacing: -0.3px;
  margin-bottom: 2px;
}
.welcome-sub {
  font-size: 14px;
  font-weight: 600;
  color: #0284C7;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.dark .welcome-sub { color: #38BDF8; }

/* ===== بطاقة الملخص السريع KPI ===== */
.hero-summary {
  background: linear-gradient(135deg, #0F172A, #1E3A8A 65%, #0284C7);
  color: #fff;
  border-radius: 26px;
  padding: 18px 20px;
  margin: 6px 0 16px;
  box-shadow: 0 12px 30px rgba(30, 58, 138, 0.25);
  position: relative;
  overflow: hidden;
}
.hero-summary::after {
  content: "";
  position: absolute;
  width: 170px;
  height: 170px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  left: -40px;
  top: -50px;
  pointer-events: none;
}
.hs-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.hs-title { font-size: 13px; color: rgba(255, 255, 255, 0.85); font-weight: 600; }
.hs-profit { font-size: 32px; font-weight: 800; margin: 4px 0 12px; letter-spacing: -0.5px; }
.hs-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.hs-box {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 8px 10px;
  font-size: 11.5px;
  backdrop-filter: blur(6px);
}
.hs-box small { display: block; color: rgba(255, 255, 255, 0.8); }
.hs-box b { display: block; font-size: 14px; margin-top: 2px; }

/* بطاقات المؤشرات الملونة */
.kpi {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.kpi div {
  background: var(--card);
  border-radius: 18px;
  padding: 13px;
  box-shadow: var(--sh);
  border: 1px solid var(--ln);
}
.kpi small, small { color: var(--tx2); }
.kpi b { display: block; font-size: 18px; font-weight: 800; margin-top: 3px; }
.kpi-cs { border-inline-start: 5px solid var(--c-debt) !important; }
.kpi-ss { border-inline-start: 5px solid var(--c-loss) !important; }
.kpi-stock { border-inline-start: 5px solid var(--c-warn) !important; }
.kpi-net { border-inline-start: 5px solid var(--c-profit) !important; }

/* ===== بطاقات الأقسام الملونة (هوية التصميم المرجعي) ===== */
.section-card {
  background: var(--card);
  border-radius: 26px;
  box-shadow: var(--sh);
  margin-bottom: 16px;
  overflow: hidden;
  border: 1px solid var(--ln);
}
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  color: #fff;
  font-weight: 700;
}
.section-header.sales { background: linear-gradient(90deg, #60A5FA, #2563EB); }
.section-header.buy { background: linear-gradient(90deg, #FBBF24, #F59E0B); }
.section-header.stock { background: linear-gradient(90deg, #34D399, #10B981); }
.section-header.debt { background: linear-gradient(90deg, #A78BFA, #7C3AED); }

.sh-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
}
.sh-icon-box {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  color: #fff;
}
.sh-icon-box img, .sh-icon-box svg {
  width: 24px;
  height: 24px;
  object-fit: contain;
  display: block;
}
.sh-link {
  color: rgba(255, 255, 255, 0.95);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 4px;
  background: none;
  border: 0;
  font-family: inherit;
}

.tiles-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px;
}
.action-tile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--tile-bg);
  border: 1.5px solid var(--tile-border);
  border-radius: 18px;
  padding: 12px 14px;
  font: inherit;
  font-weight: 700;
  color: var(--tx);
  cursor: pointer;
  text-align: right;
  min-height: 58px;
  transition: transform 0.12s, border-color 0.15s, box-shadow 0.15s;
}
.action-tile:hover { border-color: var(--pri); }
.action-tile:active { transform: scale(0.97); }
.tile-label { font-size: 14.5px; font-weight: 700; color: var(--tx); }
.tile-icon-img {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.tile-icon-img img, .tile-icon-img svg {
  width: 38px;
  height: 38px;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
  display: block;
}

/* تنبيه المخزون */
.alert-low-stock {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #FFFBEB;
  border: 1.5px solid #FCD34D;
  color: #B45309;
  border-radius: 18px;
  padding: 12px 16px;
  margin-bottom: 14px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
}
.dark .alert-low-stock {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.35);
  color: #FDE68A;
}

/* ===== عناصر عامة ومربعات الحوار ===== */
h2 { font-size: 21px; font-weight: 800; margin: 8px 0 14px; }
h3 { font-weight: 700; margin-bottom: 8px; font-size: 16.5px; }
.card {
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--sh);
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--ln);
}
input, select {
  width: 100%;
  font: inherit;
  color: var(--tx);
  background: var(--bg);
  border: 1.5px solid var(--ln);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 5px 0;
  font-size: 15px;
}
input:focus, select:focus {
  border-color: var(--pri);
  outline: none;
}
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.row > button { flex: none; }
.btn {
  font: inherit;
  font-weight: 700;
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  color: #fff;
  background: linear-gradient(135deg, #1E9BE0, #2563EB);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 15px;
  min-height: 48px;
}
.btn:active { transform: scale(0.97); }
.btn.g { background: var(--bg); color: var(--tx); border: 1.5px solid var(--ln); }
.btn.r { background: var(--c-loss); color: #fff; }
.btn.success { background: var(--c-profit); color: #fff; }
.btn.warn { background: var(--c-warn); color: #fff; }
.btn.purple { background: var(--c-debt); color: #fff; }
.w { width: 100%; margin-top: 10px; }
.qb {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1.5px solid var(--ln);
  background: var(--bg);
  color: var(--tx);
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.bad { color: var(--c-loss); }
.ok { color: var(--c-profit); }
.warn-tx { color: var(--c-warn); }
.purple-tx { color: var(--c-debt); }
.li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--ln);
  cursor: pointer;
}
.li:last-child { border: 0; }
.pill { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: var(--bg); }

/* صور الأصناف المصغرة */
.item-thumb {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--bg);
  border: 1px solid var(--ln);
  flex-shrink: 0;
}

/* النافذة المنبثقة Modal */
.mb {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 40, 0.58);
  backdrop-filter: blur(4px);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.18s ease;
}
.mc {
  background: var(--card);
  width: 100%;
  max-width: 540px;
  margin: auto;
  border-radius: 28px 28px 0 0;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow: auto;
  box-shadow: 0 -10px 40px rgba(0,0,0,0.18);
  animation: slideUp 0.22s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* نافذة قائمة الإجراء السريع */
.quick-menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}
.quick-menu-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--ln);
  background: var(--bg);
  color: var(--tx);
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
}
.quick-menu-btn:hover { border-color: var(--pri); }
.quick-menu-btn img, .quick-menu-btn svg, .quick-menu-icon svg { width: 44px; height: 44px; object-fit: contain; }

/* كاميرا الماسح الضوئي */
#sc {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: #000;
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding: 16px;
}
#reader {
  width: 100%;
  max-width: 480px;
  margin: auto;
  border-radius: 20px;
  overflow: hidden;
}

/* Toast */
.toast {
  position: fixed;
  top: 65px;
  left: 50%;
  transform: translateX(-50%);
  background: #10B981;
  color: #fff;
  padding: 11px 22px;
  border-radius: 16px;
  z-index: 100;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.4);
  animation: fadeIn 0.2s ease;
}

/* ===== الرسوم البيانية البسيطة للتقارير ===== */
.chart-card {
  background: var(--card);
  border-radius: 20px;
  border: 1px solid var(--ln);
  padding: 16px;
  margin-bottom: 14px;
}
.chart-title {
  font-size: 14.5px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--tx);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chart-bars-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 140px;
  padding-top: 15px;
  border-bottom: 1.5px solid var(--ln);
}
.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}
.chart-bar-fill {
  width: 100%;
  max-width: 32px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, #38BDF8, #2563EB);
  transition: height 0.3s ease;
  min-height: 4px;
}
.chart-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--tx2);
  margin-top: 6px;
  text-align: center;
}
.chart-val {
  font-size: 10px;
  font-weight: 700;
  color: var(--tx2);
  margin-bottom: 3px;
}

/* شريط أفقي لأكثر الأصناف ربحاً */
.h-chart-row {
  margin-bottom: 10px;
}
.h-chart-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 700;
  margin-bottom: 4px;
}
.h-chart-bar-bg {
  background: var(--bg);
  border-radius: 8px;
  height: 10px;
  overflow: hidden;
  border: 1px solid var(--ln);
}
.h-chart-bar-fill {
  background: linear-gradient(90deg, #10B981, #059669);
  height: 100%;
  border-radius: 8px;
}

/* ===== شاشة قفل PIN ===== */
.pin-lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 280px;
  margin-top: 24px;
}
.pin-key {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 1.5px solid var(--ln);
  background: var(--card);
  color: var(--tx);
  font: inherit;
  font-size: 24px;
  font-weight: 800;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: var(--sh);
}
.pin-key:active { transform: scale(0.92); }
.pin-dots {
  display: flex;
  gap: 14px;
  margin: 18px 0;
}
.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--pri);
  background: transparent;
}
.pin-dot.filled {
  background: var(--pri);
}

/* ===== شريط التنقل السفلي العائم (Dock Bar) ===== */
.bottom-dock {
  position: fixed;
  inset: auto 12px calc(10px + env(safe-area-inset-bottom)) 12px;
  max-width: 520px;
  margin: auto;
  background: var(--card);
  border-radius: 34px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.09);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 6px 10px;
  z-index: 50;
  border: 1px solid var(--ln);
}
.dock-btn {
  background: none;
  border: 0;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--tx2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 10px;
  cursor: pointer;
  position: relative;
  border-radius: 20px;
  transition: color 0.15s;
}
.dock-btn.active {
  color: var(--pri);
  font-weight: 800;
}
.dock-btn.active::before {
  content: '';
  position: absolute;
  top: 1px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--pri);
}
.dock-btn img, .dock-btn svg {
  width: 24px;
  height: 24px;
  object-fit: contain;
  display: block;
}

/* زر الكاشير العائم بالوسط */
.dock-fab-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}
.dock-fab {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  margin-top: -32px;
  background: linear-gradient(135deg, #00A3FF, #0084E8);
  box-shadow: 0 8px 22px rgba(0, 163, 255, 0.45);
  color: #fff;
  border: 4px solid var(--card);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.dock-fab:active {
  transform: scale(0.92);
  box-shadow: 0 4px 12px rgba(0, 163, 255, 0.3);
}
.dock-fab img, .dock-fab svg {
  width: 34px;
  height: 34px;
  object-fit: contain;
  display: block;
}

/* ===== طباعة ملصق الباركود ===== */
#printArea {
  display: none;
}
@media print {
  body * { visibility: hidden !important; }
  #printArea, #printArea * { visibility: visible !important; }
  #printArea {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 50mm;
    padding: 2mm;
    margin: 0;
    text-align: center;
    font-family: 'Cairo', sans-serif;
  }
  .print-label {
    width: 48mm;
    border: 1px dashed #ccc;
    padding: 2mm;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .print-shop { font-size: 10pt; font-weight: 700; margin-bottom: 1mm; }
  .print-name { font-size: 11pt; font-weight: 800; max-width: 44mm; word-break: break-word; }
  .print-price { font-size: 14pt; font-weight: 800; margin-top: 1mm; }
  .print-svg { max-width: 44mm; height: 16mm; }
}

/* ===== أيقونة وحالة Firebase Cloud ===== */
.fb-cloud-btn {
  position: relative;
}
.fb-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--bg);
  background: #94A3B8;
  transition: all 0.3s ease;
}
.fb-dot.fb-connected {
  background: #10B981;
  box-shadow: 0 0 6px #10B981;
}
.fb-dot.fb-syncing {
  background: #F59E0B;
  box-shadow: 0 0 6px #F59E0B;
  animation: fbPulse 1s infinite alternate;
}
.fb-dot.fb-offline {
  background: #F59E0B;
}
.fb-dot.fb-error {
  background: #EF4444;
  box-shadow: 0 0 6px #EF4444;
}
.fb-dot.fb-disconnected {
  background: #94A3B8;
}

@keyframes fbPulse {
  0% { transform: scale(0.9); opacity: 0.7; }
  100% { transform: scale(1.2); opacity: 1; }
}

.fb-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 11.5px;
  font-weight: 700;
}
.fb-badge.fb-connected {
  background: #D1FAE5;
  color: #065F46;
}
.dark .fb-badge.fb-connected {
  background: rgba(16, 185, 129, 0.2);
  color: #6EE7B7;
}
.fb-badge.fb-syncing, .fb-badge.fb-connecting {
  background: #FEF3C7;
  color: #92400E;
}
.dark .fb-badge.fb-syncing, .dark .fb-badge.fb-connecting {
  background: rgba(245, 158, 11, 0.2);
  color: #FDE68A;
}
.fb-badge.fb-offline {
  background: #FEF3C7;
  color: #92400E;
}
.fb-badge.fb-error {
  background: #FEE2E2;
  color: #991B1B;
}
.dark .fb-badge.fb-error {
  background: rgba(239, 68, 68, 0.2);
  color: #FCA5A5;
}
.fb-badge.fb-disconnected {
  background: #E2E8F0;
  color: #475569;
}
.dark .fb-badge.fb-disconnected {
  background: #334155;
  color: #94A3B8;
}
