* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: #f4f6f9;
  color: #222;
  min-height: 100vh;
}

.app-header {
  background: #263238;
  color: #fff;
  text-align: center;
  padding: 28px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
}

.app-header h1 { font-size: 2rem; }

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: 20px;
  max-width: 1100px;
  margin: 40px auto;
  padding: 0 20px;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 180px;
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  color: #fff;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
  transition: transform .15s, box-shadow .15s;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, .25);
}

.icon { font-size: 3rem; }
.label { font-size: 1.5rem; font-weight: 700; }

.customers { background: #1e88e5; }
.sales     { background: #2e7d32; }
.purchases { background: #ef6c00; }
.accounts  { background: #8e24aa; }

/* الموبايل: بطاقتان في كل صف، بنفس الحجم والمسافات */
@media (max-width: 700px) {
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 24px auto;
    padding: 0 14px;
  }
  .app-header h1 { font-size: 1.5rem; }
  .card { min-height: 0; }
  .icon { font-size: 2.4rem; }
  .label { font-size: 1.2rem; }
}

/* صفحة الزبائن */
.app-header { position: relative; }
.back-btn {
  position: absolute;
  inset-inline-start: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: #fff;
  text-decoration: none;
  background: rgba(255, 255, 255, .15);
  padding: 8px 14px;
  border-radius: 8px;
}
.back-btn:hover { background: rgba(255, 255, 255, .28); }

.page { max-width: 700px; margin: 32px auto; padding: 0 20px; }

.btn {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  padding: 12px 22px;
  background: #cfd8dc;
  color: #222;
}
.btn.primary { background: #1e88e5; color: #fff; font-weight: 700; }
.btn:hover { filter: brightness(.95); }

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #fff;
  padding: 20px;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .1);
}
.form[hidden], #empty[hidden], #addBtn[hidden] { display: none; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.form input, .form textarea {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid #b0bec5;
  border-radius: 8px;
}
.form input:focus, .form textarea:focus { outline: 2px solid #1e88e5; border-color: transparent; }
.form-actions { display: flex; gap: 10px; }

.list-title { margin: 28px 0 12px; font-size: 1.2rem; }
.customer-list { list-style: none; display: flex; flex-direction: column; gap: 12px; }
.customer {
  background: #fff;
  border-inline-start: 6px solid #1e88e5;
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 12px;
}
.customer .phone { color: #555; }
.customer p { flex-basis: 100%; color: #444; white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { color: #777; text-align: center; padding: 24px 0; }

@media (max-width: 700px) {
  .back-btn { padding: 6px 10px; font-size: .9rem; inset-inline-start: 10px; }
}

/* البحث والفلتر */
.toolbar { display: flex; gap: 10px; margin-top: 24px; }
.toolbar input, .toolbar select {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid #b0bec5;
  border-radius: 8px;
  background: #fff;
}
.toolbar input { flex: 1; min-width: 0; }

.error { color: #c62828; font-weight: 600; }
.error[hidden] { display: none; }

/* قسم الحسابات */
.accounts { flex-basis: 100%; border-top: 1px solid #eceff1; padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.accounts h3 { font-size: 1rem; display: flex; align-items: center; gap: 10px; }
.badge { font-size: .8rem; padding: 2px 10px; border-radius: 999px; color: #fff; }
.badge.ok { background: #2e7d32; }
.badge.due { background: #c62828; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { background: #f4f6f9; border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; align-items: center; }
.stat-label { font-size: .8rem; color: #666; }
.stat.due strong { color: #c62828; }
.stat.ok strong { color: #2e7d32; }
.btn.small { padding: 8px 14px; font-size: .9rem; }
.inline-form { box-shadow: none; background: #f9fafb; border: 1px solid #eceff1; }

/* قسم الحسابات داخل بطاقة الزبون: خلفية كحلية (كانت تأخذ بنفسجي بطاقة الرئيسية بالخطأ) */
.customer .accounts { background: #0f1b3d; color: #fff; border-top: 0; border-radius: 12px; padding: 14px; }
.customer .accounts h3 { color: #fff; }
.customer .accounts .inline-form { color: #222; }
/* الإجمالي (الأول) داكن، والمدفوع (الثاني) أخضر غامق؛ الباقي (الثالث) بلا تغيير */
.customer .stats .stat:nth-child(1) strong { color: #0f1b3d; }
.customer .stats .stat:nth-child(2) strong { color: #1b5e20; }

/* زر الإعدادات (ترس) في رأس الرئيسية */
.gear-btn {
  position: absolute; inset-inline-end: 12px; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; line-height: 1; color: #fff; text-decoration: none;
  background: rgba(255, 255, 255, .12); border-radius: 50%;
}
.gear-btn:hover { background: rgba(255, 255, 255, .28); }

/* صفحة الإعدادات */
.settings-section { margin-bottom: 16px; }
.settings-section h2 { font-size: 1.1rem; }
.settings-row { display: flex; flex-direction: column; gap: 4px; }
.settings-label { font-size: .85rem; color: #666; }
.settings-value { font-weight: 700; overflow-wrap: anywhere; }
.ok-msg { color: #2e7d32; font-weight: 600; }
.ok-msg[hidden] { display: none; }
.btn.danger { background: #c62828; color: #fff; }

/* سطر الزبون المختصر */
.customer-head {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  font: inherit;
  text-align: start;
  background: none;
  border: 0;
  padding: 4px 0;
  min-height: 44px;
  cursor: pointer;
  color: inherit;
}
.cust-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.customer-head .phone { white-space: nowrap; }
.rem-badge { margin-inline-start: auto; white-space: nowrap; font-size: .85rem; font-weight: 700; padding: 3px 12px; border-radius: 999px; color: #fff; background: #78909c; }
.rem-badge.due { background: #c62828; }
.rem-badge.ok { background: #2e7d32; }
.chev { color: #607d8b; }

.payments summary { cursor: pointer; color: #fff; font-size: 1.1rem; font-weight: 700; padding: 6px 0; }
.payments ul { list-style: none; margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.payments li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 1.05rem; font-weight: 600; padding: 10px 0; border-bottom: 1px dashed rgba(255, 255, 255, .25); color: #fff; }
.pay-amount { font-weight: 800; font-size: 1.15rem; color: #fff; }
.pay-date { color: #e8eaf6; }
.pay-note { flex: 1 1 100%; color: #e8eaf6; overflow-wrap: anywhere; }
.link-btn { font: inherit; background: none; border: 0; color: #c62828; cursor: pointer; }
.link-btn.edit { color: #1e88e5; }
/* أزرار الدفعات: ذهبي بنص كحلي، بحجم مناسب للمس */
.payments .link-btn {
  background: #f5c542;
  color: #0f1b3d;
  font-weight: 700;
  font-size: .95rem;
  min-height: 40px;
  padding: 6px 16px;
  border: 1px solid #c99a14;
  border-radius: 8px;
}
.payments .link-btn:hover { filter: brightness(.95); }
.payments li.archived .pay-amount { text-decoration: line-through; color: #b0bec5; }
.confirm-dialog { border: 0; border-radius: 12px; padding: 18px; max-width: 340px; width: calc(100% - 32px); }
.confirm-dialog::backdrop { background: rgba(0, 0, 0, .5); }
.confirm-dialog p { margin-bottom: 14px; }
.confirm-dialog .form-actions { flex-wrap: wrap; }

/* صفحة الحسابات */
.summary .list-title:first-child { margin-top: 0; }
.hint { color: #777; font-size: .85rem; margin-top: 6px; }
.stat strong.neg, #netSum.neg { color: #c62828; }
.toolbar.wrap { flex-wrap: wrap; align-items: center; }
.date-filter { display: flex; align-items: center; gap: 6px; }
.form select {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid #b0bec5;
  border-radius: 8px;
  background: #fff;
}

.tx-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.tx {
  background: #fff;
  border-inline-start: 6px solid #2e7d32;
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
}
.tx.expense { border-inline-start-color: #c62828; }
.tx-type { font-size: .8rem; color: #fff; padding: 2px 10px; border-radius: 999px; background: #2e7d32; }
.tx.expense .tx-type { background: #c62828; }
.tx-desc { flex: 1; min-width: 120px; overflow-wrap: anywhere; }
.tx-date { color: #666; font-size: .9rem; }
.tx.income .tx-amount { color: #2e7d32; }
.tx.expense .tx-amount { color: #c62828; }

@media (max-width: 700px) {
  .toolbar.wrap > * { flex: 1 1 100%; }
  .stats { gap: 6px; }
}

/* شارات البطاقات في الرئيسية */
.card { position: relative; }
.card-badge {
  position: absolute;
  top: 12px;
  inset-inline-start: 12px;
  background: #fff;
  color: #263238;
  font-size: .9rem;
  font-weight: 700;
  padding: 3px 12px;
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
}
.card-badge.neg { color: #c62828; }

@media (max-width: 700px) {
  .card-badge { top: 8px; inset-inline-start: 8px; font-size: .8rem; padding: 2px 9px; }
}

/* الصفحة الرئيسية: خلفية متدرجة، شعار، حركة */
html.home {
  min-height: 100%;
  background: linear-gradient(to bottom, #eceff1 0%, #b3bcc3 100%) fixed;
}
.home body { background: transparent; }

.home .app-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.logo { width: 44px; height: 44px; flex-shrink: 0; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(24px) scale(.96); }
  to   { opacity: 1; transform: none; }
}
.home .card {
  animation: card-in .5s ease-out backwards;
  transition: transform .2s ease, box-shadow .2s ease;
}
.home .card:nth-child(1) { animation-delay: .05s; }
.home .card:nth-child(2) { animation-delay: .15s; }
.home .card:nth-child(3) { animation-delay: .25s; }
.home .card:nth-child(4) { animation-delay: .35s; }
.home .card:hover {
  transform: translateY(-6px) scale(1.03);
  box-shadow: 0 12px 24px rgba(0, 0, 0, .28);
}
.home .card .icon { transition: transform .2s ease; }
.home .card:hover .icon { transform: scale(1.15) rotate(-6deg); }

@media (max-width: 700px) {
  .logo { width: 34px; height: 34px; }
}
@media (prefers-reduced-motion: reduce) {
  .home .card { animation: none; transition: none; }
  .home .card .icon { transition: none; }
}

/* الصفحة الرئيسية: خلفية كحلية، ساعة، ملخص الدفعات (مدمج) */
html.home { background: linear-gradient(to bottom, #1d2b53 0%, #0a1226 100%) fixed; }
.home .app-header { background: #0d1630; border-bottom: 1px solid rgba(255, 255, 255, .08); padding: 12px 16px; }
.home .logo { width: 38px; height: 38px; }
.home .cards { margin: 16px auto; gap: 16px; }
.home .card { box-shadow: 0 6px 18px rgba(0, 0, 0, .45); }

.home-extra { max-width: 1100px; margin: 0 auto 12px; padding: 0 20px; display: flex; flex-direction: column; gap: 10px; color: #64ffda; }

.clock {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 20px;
  padding: 8px 14px; border-radius: 12px;
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .1);
}
.clock-time { font-family: "Consolas", "Courier New", monospace; font-size: 1.9rem; font-weight: 700; color: #f5c542; letter-spacing: 1px; text-shadow: 0 0 12px rgba(245, 197, 66, .35); }
.clock-ampm { font-size: 1rem; margin-inline-start: 4px; }
.clock-date { font-size: 1rem; color: #e8eaf6; }

.pay-summary { padding: 10px 14px 12px; border-radius: 12px; background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .1); }
.pay-summary h2 { font-size: 1.05rem; margin-bottom: 8px; color: #64ffda; }
.pay-summary h3 { font-size: .9rem; margin-bottom: 6px; color: #64ffda; }
.pay-grid { display: grid; grid-template-columns: 1fr 1fr 2fr; gap: 10px; align-items: stretch; }
.pay-summary .stat { background: rgba(100, 255, 218, .08); border: 1px solid rgba(100, 255, 218, .25); justify-content: center; padding: 6px 8px; }
.pay-summary .stat-label { color: #64ffda; font-size: .8rem; text-align: center; }
.pay-summary .stat strong { color: #64ffda; font-size: 1.5rem; }
.recent-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.recent-list li { display: flex; align-items: center; gap: 10px; padding: 3px 10px; border-radius: 8px; font-size: .85rem; background: rgba(100, 255, 218, .08); color: #64ffda; }
.recent-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-date { font-size: .8rem; }
.recent-list strong { color: #64ffda; }
.recent-empty { color: #64ffda; font-size: .85rem; }
.recent-empty[hidden] { display: none; }

/* تكبير سلس عند تمرير الماوس على عناصر الملخص */
.pay-summary .stat, .recent-list li, .pay-summary h2, .pay-summary h3, .recent-empty {
  position: relative;
  transition: transform .2s ease, box-shadow .2s ease;
}
.pay-summary h2, .pay-summary h3 { width: fit-content; transform-origin: right center; }
.pay-summary .stat:hover { transform: scale(1.06); z-index: 1; box-shadow: 0 4px 14px rgba(0, 0, 0, .4); }
.recent-list li:hover { transform: scale(1.03); z-index: 1; box-shadow: 0 3px 10px rgba(0, 0, 0, .4); }
.pay-summary h2:hover, .pay-summary h3:hover { transform: scale(1.08); }
.recent-empty { width: fit-content; transform-origin: right center; }
.recent-empty:hover { transform: scale(1.06); }

/* شاشات اللابتوب القصيرة: بطاقات أقل ارتفاعًا ليبقى كل شيء بدون تمرير */
@media (min-width: 701px) and (max-height: 720px) {
  .home .card { aspect-ratio: auto; min-height: 0; height: 140px; gap: 6px; }
  .home .card .icon { font-size: 2.2rem; }
  .home .card .label { font-size: 1.25rem; }
}

@media (max-width: 700px) {
  .home .logo { width: 32px; height: 32px; }
  .home .cards { margin: 14px auto; gap: 12px; }
  .clock-time { font-size: 1.6rem; }
  .clock-date { font-size: .9rem; }
  .home-extra { padding: 0 14px; }
  .pay-grid { grid-template-columns: 1fr 1fr; }
  .recent { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
  .pay-summary .stat, .recent-list li, .pay-summary h2, .pay-summary h3, .recent-empty { transition: none; }
}
/* ---------- الزبائن: سطر الرابط وصفحة الزبون والنوافذ ---------- */
a.customer-head { text-decoration: none; }
a.btn { display: inline-block; text-align: center; text-decoration: none; }
.customer-title { flex-basis: 100%; display: flex; align-items: center; gap: 10px; min-height: 36px; }
.new-invoice { display: block; margin-top: 14px; padding: 14px 22px; font-size: 1.05rem; }

.choice-list { display: flex; flex-direction: column; gap: 10px; }
.pick-search { width: 100%; font: inherit; padding: 10px 12px; border: 1px solid #b0bec5; border-radius: 8px; margin-bottom: 8px; }
.pick-list { list-style: none; max-height: 40vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.pick-item { width: 100%; display: flex; justify-content: space-between; gap: 10px; font: inherit; text-align: start; background: #f4f6f9; border: 0; border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.pick-item:hover { background: #e3eaf2; }

/* ---------- الفواتير ---------- */
.invoice-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.invoice-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: #fff; border-radius: 12px; padding: 12px 14px; box-shadow: 0 2px 8px rgba(0, 0, 0, .08); color: inherit; text-decoration: none; }
.invoice-row .inv-net { margin-inline-start: auto; font-weight: 700; }

.items { display: flex; flex-direction: column; gap: 10px; }
.item-row { display: flex; flex-direction: column; gap: 6px; padding: 10px; background: #f9fafb; border: 1px solid #eceff1; border-radius: 10px; }
.item-row input { font: inherit; padding: 10px 12px; border: 1px solid #b0bec5; border-radius: 8px; min-width: 0; }
.item-nums { display: grid; grid-template-columns: 1fr 2fr 2fr; gap: 8px; align-items: center; }
.item-nums .it-total { text-align: center; font-weight: 700; }
.item-row .link-btn { align-self: flex-start; }

.print-form { display: flex; flex-direction: column; gap: 14px; }
.print-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.print-form input[type="text"], .print-form input[type="tel"] { font: inherit; padding: 10px 12px; border: 1px solid #b0bec5; border-radius: 8px; }
.logo-box { display: flex; align-items: center; gap: 14px; }
.logo-box img { max-width: 160px; max-height: 80px; object-fit: contain; border: 1px solid #eceff1; border-radius: 8px; padding: 4px; background: #fff; }
.totals { display: flex; flex-direction: column; gap: 12px; padding-top: 8px; border-top: 1px solid #eceff1; }
.totals-row { display: flex; justify-content: space-between; align-items: center; font-size: 1.05rem; }
.totals-row.remaining { font-size: 1.2rem; font-weight: 700; border-top: 2px solid #263238; padding-top: 8px; }
.totals-row strong.neg { color: #c62828; }

/* ---------- التنقل: شريط سفلي (موبايل) وزر الرئيسية (لابتوب) ---------- */
.bottom-nav { display: none; }
.home-btn {
  position: absolute; inset-inline-end: 16px; top: 50%; transform: translateY(-50%);
  width: 42px; height: 42px; display: flex; align-items: center; justify-content: center;
  color: #fff; text-decoration: none; background: rgba(255, 255, 255, .15); border-radius: 8px;
}
.home-btn:hover { background: rgba(255, 255, 255, .28); }
.home-btn svg { width: 22px; height: 22px; }

@media (max-width: 700px) {
  .home-btn { display: none; }
  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: flex;
    background: #0f1b3d; border-top: 1px solid rgba(255, 255, 255, .14);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bn-item {
    flex: 1; min-width: 0; min-height: 58px; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px; padding: 6px 2px;
    color: #b8c1ec; text-decoration: none; font-size: .72rem;
  }
  .bn-item svg { width: 24px; height: 24px; }
  .bn-item.active { color: #64ffda; }
  .bn-item.disabled { opacity: .4; }
  body.has-bottom-nav { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
}
@media print {
  .bottom-nav, .home-btn { display: none !important; }
  body.has-bottom-nav { padding-bottom: 0; }
}

/* ---------- زر إخفاء/إظهار آخر الدفعات (الرئيسية) ---------- */
.recent-head { display: flex; align-items: center; justify-content: flex-start; gap: 6px; margin-bottom: 6px; }
.recent-head h3 { margin-bottom: 0; }
.eye-toggle { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; background: none; border: 0; color: #64ffda; cursor: pointer; border-radius: 6px; }
.eye-toggle:hover { background: rgba(100, 255, 218, .12); }
.eye-toggle svg { width: 22px; height: 22px; }
.eye-toggle [hidden] { display: none; }
.collapsible { display: grid; grid-template-rows: 1fr; opacity: 1; transition: grid-template-rows .3s ease, opacity .25s ease; }
.collapsible > .collapsible-inner { overflow: hidden; min-height: 0; }
.collapsible.collapsed { grid-template-rows: 0fr; opacity: 0; }
.collapsible.collapsed > .collapsible-inner { visibility: hidden; transition: visibility 0s .3s; }
@media (prefers-reduced-motion: reduce) { .collapsible { transition: none; } }

/* ---------- إعدادات الفاتورة ---------- */
.inv-set-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 1000px) {
  .inv-set-page { max-width: 1100px; }
  .inv-set-grid { grid-template-columns: minmax(0, 420px) minmax(0, 1fr); align-items: start; }
  .inv-preview-wrap { position: sticky; top: 12px; }
}
.tpl-choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tpl-choice { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px; border: 2px solid #cfd8dc; border-radius: 10px; cursor: pointer; text-align: center; font-weight: 600; font-size: .9rem; }
.tpl-choice input { position: absolute; opacity: 0; pointer-events: none; }
.tpl-choice:has(input:checked) { border-color: #1e88e5; background: #e8f1fc; }
.tpl-choice:has(input:focus-visible) { outline: 2px solid #1e88e5; }
.accent-row { display: flex; align-items: center; gap: 10px; }
.accent-row input[type="color"] { width: 52px; height: 40px; padding: 2px; border: 1px solid #b0bec5; border-radius: 8px; background: #fff; }
.switch-list { display: flex; flex-direction: column; gap: 4px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid #eceff1; font-weight: 600; cursor: pointer; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch-row .sw { position: relative; flex: none; width: 44px; height: 24px; border-radius: 999px; background: #b0bec5; transition: background .2s; }
.switch-row .sw::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: inset-inline-start .2s; }
.switch-row input:checked + .sw { background: #2e7d32; }
.switch-row input:checked + .sw::after { inset-inline-start: 23px; }
.switch-row input:focus-visible + .sw { outline: 2px solid #1e88e5; }
.inv-preview { background: #e9edf1; border-radius: 12px; padding: 12px; overflow-x: auto; }
.inv-preview .invoice-sheet { margin-top: 0; }
.set-link { display: block; }.form .switch-row { flex-direction: row; position: relative; }
.form .tpl-choice { position: relative; }
/* ---------- الاختصارات السريعة ---------- */
.quick-rail, .fab-wrap { display: none; }

/* شاشات كبيرة: شريط عمودي ثابت على اليمين */
@media (min-width: 1200px) {
  .quick-rail {
    display: flex; flex-direction: column; gap: 8px; position: fixed; right: 0; top: 50%;
    transform: translateY(-50%); z-index: 40; padding: 10px 8px;
    background: #0f1b3d; border: 1px solid rgba(255, 255, 255, .14); border-right: 0;
    border-radius: 14px 0 0 14px; box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
  }
  .qr-btn {
    width: 76px; display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 10px 4px; font: inherit; font-size: .72rem; line-height: 1.25; text-align: center;
    color: #e8eaf6; background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 10px; cursor: pointer;
  }
  .qr-btn svg { width: 24px; height: 24px; }
  .qr-btn:hover { background: rgba(255, 255, 255, .16); }
  .qr-btn.primary { background: #64ffda; color: #0f1b3d; border-color: #64ffda; font-weight: 700; }
  .qr-btn.primary:hover { background: #8affe6; }
}

/* بقية الشاشات: زر عائم دائري بقائمة صغيرة */
@media (max-width: 1199px) {
  .fab-wrap { display: block; position: fixed; inset-inline-end: 14px; bottom: 20px; z-index: 60; }
}
@media (max-width: 700px) {
  .fab-wrap { bottom: calc(70px + env(safe-area-inset-bottom)); } /* فوق الشريط السفلي مباشرة */
}
.fab {
  width: 52px; height: 52px; border-radius: 50%; border: 0; display: flex; align-items: center; justify-content: center;
  background: #64ffda; color: #0f1b3d; box-shadow: 0 4px 14px rgba(0, 0, 0, .4); cursor: pointer;
}
.fab svg { width: 26px; height: 26px; }
.fab-menu { position: absolute; bottom: 62px; inset-inline-end: 0; display: flex; flex-direction: column; gap: 8px; min-width: 200px; }
.fab-menu[hidden] { display: none; }
.fab-item {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 10px 14px; font: inherit;
  color: #e8eaf6; background: #0f1b3d; border: 1px solid rgba(255, 255, 255, .18); border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4); cursor: pointer; text-align: start;
}
.fab-item svg { width: 22px; height: 22px; flex: none; }
.fab-item.primary { background: #64ffda; color: #0f1b3d; border-color: #64ffda; font-weight: 700; }
@media print { .quick-rail, .fab-wrap { display: none !important; } }

/* نافذة الاختصارات (تسديد فاتورة / اختيار زبون) */
.quick-dialog { border: 0; padding: 0; border-radius: 14px; background: #0f1b3d; color: #e8eaf6; width: calc(100% - 20px); max-width: 520px; max-height: 88vh; }
.quick-dialog[open] { display: flex; flex-direction: column; }
.quick-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.qd-box { display: flex; flex-direction: column; gap: 12px; padding: 14px; flex: 1; min-height: 0; border: 1px solid rgba(100, 255, 218, .25); border-radius: 14px; }
.qd-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.qd-head h3 { color: #64ffda; font-size: 1.1rem; }
.qd-close { font: inherit; min-height: 40px; padding: 8px 14px; cursor: pointer; border-radius: 8px; border: 1px solid rgba(100, 255, 218, .4); background: rgba(100, 255, 218, .12); color: #64ffda; }
.qd-body { display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.qd-input { width: 100%; min-width: 0; font: inherit; font-size: 1rem; padding: 12px; border-radius: 10px; border: 1px solid rgba(100, 255, 218, .3); background: rgba(255, 255, 255, .08); color: #fff; }
.qd-field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; color: #64ffda; }
.qd-list, .qd-invs { list-style: none; display: flex; flex-direction: column; gap: 8px; max-height: 42vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.qd-item { width: 100%; min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 10px; font: inherit; text-align: start; color: #e8eaf6; background: rgba(100, 255, 218, .08); border: 1px solid transparent; border-radius: 10px; padding: 12px; cursor: pointer; }
.qd-item:hover { background: rgba(100, 255, 218, .16); }
.qd-inv { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 10px; background: rgba(100, 255, 218, .08); border: 1px solid transparent; cursor: pointer; }
.qd-inv:has(input:checked) { border-color: #64ffda; background: rgba(100, 255, 218, .18); }
.qd-inv input { width: 22px; height: 22px; accent-color: #64ffda; flex: none; }
.qd-inv-info { display: flex; flex-wrap: wrap; gap: 4px 14px; flex: 1; }
.qd-rem { color: #64ffda; font-weight: 700; }
.qd-who { color: #64ffda; font-weight: 700; }
.qd-msg { color: #b8c1ec; text-align: center; }
.qd-error { color: #ff8a80; font-weight: 600; }
.qd-error[hidden] { display: none; }
.qd-btn { font: inherit; font-size: 1rem; min-height: 48px; padding: 10px 16px; cursor: pointer; border-radius: 10px; border: 1px solid rgba(100, 255, 218, .4); background: rgba(100, 255, 218, .1); color: #64ffda; }
.qd-btn.primary { background: #64ffda; color: #0f1b3d; border-color: #64ffda; font-weight: 700; }
.qd-btn:disabled { opacity: .6; cursor: default; }
.qd-toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 100; padding: 12px 20px; border-radius: 999px; background: #0f1b3d; color: #64ffda; border: 1px solid rgba(100, 255, 218, .45); box-shadow: 0 4px 14px rgba(0, 0, 0, .4); font-weight: 600; }
/* ---------- الأرشفة والنسخ المحفوظة والرمز ---------- */
.plain-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.row-item { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; padding: 10px 12px; background: #f9fafb; border: 1px solid #eceff1; border-radius: 10px; }
.row-item .btn { margin-inline-start: auto; }
.row-sub { color: #666; font-size: .9rem; }
.confirm-dialog.wide { max-width: 420px; }
.dlg-form { display: flex; flex-direction: column; gap: 12px; }
.dlg-form h3 { font-size: 1.1rem; }
.dlg-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.dlg-form input { font: inherit; padding: 10px 12px; border: 1px solid #b0bec5; border-radius: 8px; }

/* الأرشفة في صفحة الزبون: قسم هادئ في أسفل الصفحة */
.advanced { margin-top: 32px; padding-top: 14px; border-top: 1px solid #dfe3e8; color: #78909c; }
.advanced h3 { font-size: .95rem; font-weight: 600; margin-bottom: 8px; }
.advanced p { font-size: .85rem; margin-bottom: 10px; }
.btn.subtle { background: transparent; border: 1px solid #b0bec5; color: #607d8b; }
.btn.subtle:hover { background: #eceff1; }
.archived-note { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: #fff8e1; color: #6d4c00; font-size: .9rem; }
/* ---------- المستندات المطبوعة بالقالب (وصل القبض، كشف الحساب) تُطبع وحدها ---------- */
.receipt-print { display: none; }
@media print {
  body:has(> .receipt-print) > *:not(.receipt-print) { display: none !important; }
  body:has(> .receipt-print) { padding: 0 !important; background: #fff !important; }
  .receipt-print { display: block; margin: 0; }
  .receipt-print .invoice-sheet { min-height: 0 !important; margin: 0; }
}

/* أزرار صفحة الزبون: وصل بيع جديد + طباعة كشف حساب */
.cust-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.cust-actions .new-invoice { flex: 1 1 200px; margin-top: 0; }
.cust-actions .statement-btn { flex: 1 1 160px; padding: 14px 22px; font-size: 1.05rem; }
/* ---------- ترتيب أقسام الفاتورة وعناوين مجموعات المفاتيح (إعدادات الفاتورة) ---------- */
.order-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.order-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid #cfd8dc; border-radius: 8px; font-weight: 600; background: #fff; }
.order-list li span { flex: 1; }
.order-btn { width: 38px; height: 34px; border: 1px solid #b0bec5; border-radius: 8px; background: #f5f7f9; font: inherit; font-size: 1.1rem; cursor: pointer; }
.order-btn:disabled { opacity: .35; cursor: default; }
.switch-group { font-size: .95rem; margin: 14px 0 2px; color: #455a64; }

/* المخزن */
.inv-tabs { display: flex; gap: 6px; margin-bottom: 16px; overflow-x: auto; }
.inv-tab { flex: 1; min-width: max-content; font: inherit; text-align: center; padding: 10px 14px; border: 0; border-radius: 10px; background: #e3eaf2; color: #263238; cursor: pointer; white-space: nowrap; }
.inv-tab.active { background: #ef6c00; color: #fff; font-weight: 700; }
.inv-tab.disabled { opacity: .5; cursor: default; }
.check { display: flex; align-items: center; gap: 6px; font-size: .95rem; }
.toolbar.wrap { margin-top: 12px; }
.item-head { gap: 12px; }
.item-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.item-sub { font-size: .8rem; color: #607d8b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-code { color: #555; font-size: .85rem; white-space: nowrap; }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.qty-badge { font-size: .85rem; font-weight: 700; padding: 3px 12px; border-radius: 999px; color: #fff; background: #2e7d32; white-space: nowrap; }
.qty-badge.low { background: #c62828; }
.customer.archived { opacity: .6; border-inline-start-color: #90a4ae; }
.row-item .cat-btn { margin-inline-start: 0; }
.row-item .cat-btn.first { margin-inline-start: auto; }
.wrap-actions { flex-wrap: wrap; }
.mv-qty { font-weight: 700; margin-inline-start: auto; }
.mv-qty.in { color: #2e7d32; }
.mv-qty.out { color: #c62828; }
.mv-note { flex-basis: 100%; }
.card-badge[hidden] { display: none; }
.card-badge.warn { color: #c62828; }

/* فاتورة الشراء */
.new-link { display: block; text-align: center; text-decoration: none; }
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 600; }
.pick-btn { width: 100%; text-align: start; background: #f4f6f9; border: 1px solid #b0bec5; }
.pick-btn.chosen { font-weight: 700; background: #e8f5e9; border-color: #81c784; }
.pur-money { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pur-lines { display: flex; flex-direction: column; gap: 10px; }
.pur-line { background: #f9fafb; border: 1px solid #eceff1; border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.pur-line-head { display: flex; align-items: center; gap: 10px; }
.pur-line-fields { display: grid; grid-template-columns: 1fr 1.4fr 1.4fr; gap: 8px; align-items: end; }
.pur-line-fields input { width: 100%; min-width: 0; }
.pur-totals { display: flex; flex-direction: column; gap: 10px; background: #f4f6f9; border-radius: 10px; padding: 12px; }
.pur-sum { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.pur-sum span { color: #607d8b; }
.pd-actions { margin: 12px 0; }
@media (max-width: 520px) {
  .pur-money { grid-template-columns: 1fr; }
  .pur-line-fields { grid-template-columns: 1fr 1fr; }
  .pur-line-fields .pur-sum { grid-column: 1 / -1; }
}

.cur-title { font-size: 1rem; margin: 10px 0 6px; color: #455a64; }
.supplier-due { white-space: nowrap; }
