/* ==========================================================================
   SudanCode Store — واجهة متجر إلكتروني
   بنية مستوحاة من متاجر التجزئة الكبرى (رأس ثابت بحث بارز، شبكة بطاقات،
   شريط سفلي على الهاتف) بهوية لونية خاصة بالمتجر.
   مكتوب mobile-first: القواعد الأساسية للهاتف، والتوسعة بـ min-width.
   ========================================================================== */

:root {
  --brand: #0d6e4f;
  --brand-dark: #094b36;
  --brand-light: #12a06f;
  --accent: #f2a71b;
  --accent-dark: #d9930f;

  --header: #10211c;        /* رأس داكن يبرز عليه اللون الذهبي */
  --header-2: #16302a;
  --ink: #1c2531;
  --ink-soft: #5b6673;
  --line: #e5e9ef;
  --page: #f2f4f7;
  --radius: 12px;
}

* { -webkit-tap-highlight-color: transparent; }

html, body {
  /* عناصر منزلقة خارج الشاشة (قائمة اللوحة الجانبية) يجب ألا تُنشئ تمريراً أفقياً */
  overflow-x: hidden;
  max-width: 100%;
}

body {
  font-family: 'Cairo', sans-serif;
  background: var(--page);
  color: var(--ink);
  /* مساحة للشريط السفلي الثابت على الهاتف */
  padding-bottom: env(safe-area-inset-bottom);
}

img { max-width: 100%; }

/* ============================ الرأس ============================ */

.app-navbar {
  background: var(--header);
  padding-top: .5rem;
  padding-bottom: .5rem;
}
.app-navbar .nav-link { color: rgba(255,255,255,.88); font-weight: 600; }
.app-navbar .nav-link:hover,
.app-navbar .nav-link:focus { color: #fff; }
.app-navbar .navbar-brand { color: #fff; font-size: 1.05rem; }

/* صف البحث — دائم الظهور على كل المقاسات، كما في متاجر التجزئة الكبرى */
.header-search { background: var(--header-2); }
.header-search .form-control {
  border: none;
  border-radius: 8px 0 0 8px;
  font-size: .95rem;
  padding: .55rem .9rem;
}
.header-search .form-control:focus { box-shadow: none; }
.header-search .btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #23180a;
  border-radius: 0 8px 8px 0;
  padding-inline: 1rem;
}
.header-search .btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

/* شريط التصنيفات الأفقي — يُمرَّر باللمس بدل أن ينكسر لأسطر */
.cat-strip {
  background: var(--brand-dark);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.cat-strip::-webkit-scrollbar { display: none; }
.cat-strip .cat-strip-inner { display: flex; gap: .25rem; white-space: nowrap; padding: .35rem .25rem; }
.cat-strip a {
  color: rgba(255,255,255,.9);
  text-decoration: none;
  font-size: .85rem;
  font-weight: 600;
  padding: .35rem .7rem;
  border-radius: 6px;
  flex: 0 0 auto;
}
.cat-strip a:hover, .cat-strip a.active { background: rgba(255,255,255,.15); color: #fff; }

.cart-badge {
  position: absolute; top: -2px; left: -8px;
  font-size: .62rem; padding: .2em .45em;
}

/* ====================== الشريط السفلي للهاتف ====================== */

.mobile-tabbar {
  position: fixed;
  bottom: 0; right: 0; left: 0;
  z-index: 1040;
  background: #fff;
  border-top: 1px solid var(--line);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(0,0,0,.06);
}
.mobile-tabbar a {
  flex: 1;
  text-align: center;
  padding: .45rem 0 .35rem;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: .68rem;
  font-weight: 600;
  position: relative;
}
.mobile-tabbar a i { display: block; font-size: 1.2rem; line-height: 1.3; }
.mobile-tabbar a.active { color: var(--brand); }
.mobile-tabbar .tab-badge {
  position: absolute; top: .2rem; inset-inline-start: 50%;
  margin-inline-start: .35rem;
  font-size: .6rem; padding: .15em .4em;
}
@media (min-width: 992px) {
  .mobile-tabbar { display: none; }
}
@media (max-width: 991.98px) {
  body { padding-bottom: calc(58px + env(safe-area-inset-bottom)); }
  .whatsapp-float { bottom: calc(70px + env(safe-area-inset-bottom)); }
}

/* ============================ البطل ============================ */

.hero {
  background: linear-gradient(120deg, var(--brand-dark), var(--brand) 60%, var(--brand-light));
  color: #fff;
  padding: 28px 0;
}
.hero h1 { font-weight: 800; font-size: 1.35rem; margin-bottom: .35rem; }
.hero p { font-size: .9rem; margin-bottom: .9rem; opacity: .92; }
@media (min-width: 768px) {
  .hero { padding: 46px 0; }
  .hero h1 { font-size: 2rem; }
  .hero p { font-size: 1rem; }
}

/* ===================== بطاقات التصنيفات ===================== */

.cat-tile {
  display: block;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .9rem .5rem;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
  height: 100%;
  transition: border-color .15s, transform .15s;
}
.cat-tile:hover { border-color: var(--brand); transform: translateY(-2px); color: var(--ink); }
.cat-tile i { font-size: 1.5rem; color: var(--brand); display: block; margin-bottom: .35rem; }
.cat-tile span { font-size: .8rem; font-weight: 700; display: block; line-height: 1.3; }

.category-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 30px;
  padding: 6px 14px; color: var(--ink); text-decoration: none;
  font-weight: 600; font-size: .85rem;
  transition: all .2s;
}
.category-pill:hover, .category-pill.active {
  background: var(--brand); color: #fff; border-color: var(--brand);
}

/* ======================= عناوين الأقسام ======================= */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .85rem;
}
.section-head h2 {
  font-weight: 800;
  font-size: 1.05rem;
  margin: 0;
  display: flex; align-items: center; gap: .5rem;
}
.section-head h2::before {
  content: "";
  width: 4px; height: 20px;
  background: var(--accent);
  border-radius: 4px;
}
.section-head .more-link {
  font-size: .82rem; font-weight: 700;
  color: var(--brand); text-decoration: none; white-space: nowrap;
}
.section-head .more-link:hover { text-decoration: underline; }
@media (min-width: 768px) {
  .section-head h2 { font-size: 1.3rem; }
}

/* الإبقاء على الصنف القديم حتى لا تفقد الصفحات التي ما زالت تستخدمه شكلها */
.section-title { font-weight: 800; font-size: 1.15rem; margin-bottom: 1rem; }

/* ======================= بطاقة المنتج ======================= */

.product-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  height: 100%;
  display: flex;
  flex-direction: column;
  transition: box-shadow .15s, border-color .15s;
}
.product-card:hover {
  border-color: #d3dae2;
  box-shadow: 0 6px 20px rgba(16,33,28,.10);
}

/* الصورة تُعرض كاملة دون قص: نسبة ثابتة + contain على خلفية بيضاء،
   وهي الطريقة التي تعرض بها متاجر التجزئة منتجاتها مهما اختلفت أبعاد الصور. */
.product-card .thumb {
  position: relative;
  background: #fff;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .6rem;
  overflow: hidden;
}
.product-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform .2s;
}
.product-card:hover .thumb img { transform: scale(1.04); }

.product-card .card-body-c { padding: .6rem .7rem .75rem; display: flex; flex-direction: column; flex: 1; }

.product-card .p-name {
  font-size: .85rem;
  font-weight: 700;
  line-height: 1.45;
  margin-bottom: .25rem;
  /* سطران ثم قص — يبقي كل البطاقات بنفس الارتفاع دون إخفاء الاسم كلياً */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.5em;
}
.product-card .p-desc {
  font-size: .75rem;
  color: var(--ink-soft);
  line-height: 1.4;
  margin-bottom: .35rem;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-card .p-rating { font-size: .75rem; margin-bottom: .3rem; }
.product-card .price-row { margin-top: auto; display: flex; align-items: baseline; flex-wrap: wrap; gap: .4rem; }
.product-card .price { font-weight: 800; color: var(--ink); font-size: 1rem; }
.product-card .price-old { color: var(--ink-soft); text-decoration: line-through; font-size: .78rem; }
.product-card .save-badge { font-size: .68rem; color: #c0392b; font-weight: 700; }

.type-badge, .type-badge-alt {
  position: absolute; top: 8px;
  font-size: .65rem; z-index: 2;
}
.type-badge { inset-inline-end: 8px; }
.type-badge-alt { inset-inline-start: 8px; }
.badge-featured { background: var(--accent); color: #23180a; }

@media (min-width: 768px) {
  .product-card .p-name { font-size: .92rem; }
  .product-card .price { font-size: 1.1rem; }
}

/* صفحة المنتج: الصورة الرئيسية بلا قص أيضاً */
.product-main-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #fff;
  border-radius: var(--radius);
  padding: .5rem;
}
.gallery-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
}

/* ============================ أزرار ============================ */

.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.btn-brand:hover, .btn-brand:focus { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-outline-brand { border: 1px solid var(--brand); color: var(--brand); background: transparent; font-weight: 700; }
.btn-outline-brand:hover { background: var(--brand); color: #fff; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #23180a; font-weight: 700; }
.btn-accent:hover, .btn-accent:focus { background: var(--accent-dark); border-color: var(--accent-dark); color: #23180a; }

/* ========================= بطاقات الثقة ========================= */

.trust-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.trust-item {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem .4rem; text-align: center;
}
.trust-item i { font-size: 1.3rem; color: var(--brand); }
.trust-item h6 { font-size: .78rem; font-weight: 700; margin: .35rem 0 0; }
.trust-item p { font-size: .7rem; color: var(--ink-soft); margin: .15rem 0 0; line-height: 1.35; }
@media (min-width: 768px) {
  .trust-row { gap: 1rem; }
  .trust-item { padding: 1.4rem .8rem; }
  .trust-item i { font-size: 1.9rem; }
  .trust-item h6 { font-size: .95rem; }
  .trust-item p { font-size: .8rem; }
}

.stat-box { border-radius: var(--radius); padding: 16px; color: #fff; }

/* ============================ التذييل ============================ */

.app-footer { background: #10141a; }
.app-footer .footer-links a { color: #c7ccd3; text-decoration: none; display: block; padding: 3px 0; font-size: .88rem; }
.app-footer .footer-links a:hover { color: #fff; }

/* ======================= صفحات الحساب ======================= */

.auth-card { max-width: 460px; margin: 32px auto; }
@media (min-width: 768px) { .auth-card { margin: 60px auto; } }

.payment-option { border: 2px solid var(--line); border-radius: var(--radius); padding: 12px; cursor: pointer; }
.payment-option.selected { border-color: var(--brand); background: #f1faf6; }

/* ===================== لوحة التحكم — الهيكل ===================== */

.admin-sidebar { background: #101826; min-height: 100vh; }
.admin-sidebar a {
  color: #b8c3d6; display: block; padding: 10px 16px;
  text-decoration: none; border-radius: 8px; margin: 2px 8px; font-size: .92rem;
}
.admin-sidebar a:hover, .admin-sidebar a.active { background: var(--brand); color: #fff; }

@media (max-width: 991.98px) {
  .admin-sidebar {
    position: fixed;
    top: 0; right: 0;
    width: 260px;
    height: 100vh;
    z-index: 1045;
    transform: translateX(100%);
    transition: transform .25s ease-in-out;
    overflow-y: auto;
  }
  .admin-sidebar.show { transform: translateX(0); box-shadow: -10px 0 30px rgba(0,0,0,.3); }
  .admin-sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1044;
  }
  .admin-sidebar-backdrop.show { display: block; }
}

/* حشو محتوى اللوحة: ضيق على الهاتف حتى لا تُهدر عرض الشاشة */
.admin-content { padding: .75rem; }
@media (min-width: 768px) { .admin-content { padding: 1.5rem; } }

/* ============ لوحة التحكم — الجداول على الهاتف ============
   الجدول ذو الأعمدة الكثيرة لا يُقرأ على شاشة صغيرة حتى مع التمرير الأفقي،
   فيتحول كل صف إلى بطاقة مستقلة، واسم العمود يظهر بجانب قيمته.
   يعتمد على سمة data-label في كل <td>. */

@media (max-width: 767.98px) {
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: .6rem;
    padding: .25rem .1rem;
    overflow: hidden;
  }
  .table-stack td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    padding: .5rem .75rem !important;
    border: none !important;
    border-bottom: 1px solid #f1f3f6 !important;
    text-align: start !important;
    min-height: 2.6rem;
  }
  .table-stack tr td:last-child { border-bottom: none !important; }
  .table-stack td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: .76rem;
    color: var(--ink-soft);
    flex: 0 0 auto;
  }
  /* الخلية التي لا تحمل عنواناً (أزرار الإجراءات) تأخذ العرض كاملاً */
  .table-stack td[data-label=""]::before,
  .table-stack td:not([data-label])::before { content: none; }
  .table-stack td[data-label=""],
  .table-stack td:not([data-label]) { justify-content: flex-start; flex-wrap: wrap; gap: .4rem; }

  /* داخل البطاقة لا يوجد مجال لأزرار متجاورة كثيرة */
  .table-stack .btn { font-size: .8rem; }
  .table-stack .btn-group { flex-wrap: wrap; gap: .3rem; }
  .table-stack .btn-group > .btn { border-radius: .375rem !important; }
}

/* شبكة إحصاءات اللوحة: عمودان على الهاتف بدل عمود واحد طويل */
@media (max-width: 575.98px) {
  .admin-stats > [class*="col-"] { width: 50%; }
  .stat-box { padding: 12px; }
  .stat-box .fs-1 { font-size: 1.5rem !important; }
  .stat-box h3 { font-size: 1.15rem; }
}

/* شبكة أمان عامة: صفوف مرنة ومجموعات أزرار تلتف بدل أن تتجاوز الشاشة */
@media (max-width: 575.98px) {
  .d-flex.justify-content-between { flex-wrap: wrap; row-gap: .5rem; }
  .btn-group[role="group"] { flex-wrap: wrap; }
  .btn-group[role="group"] > .btn { flex: 1 1 100%; border-radius: .375rem !important; }
  .card-body, .p-4 { padding: 1rem !important; }
}

/* ============================ الفاتورة ============================ */

.invoice-sheet { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
@media (min-width: 768px) { .invoice-sheet { padding: 2rem; } }

.invoice-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.invoice-head .inv-title { font-size: 1.1rem; font-weight: 800; }
.invoice-meta { font-size: .82rem; color: var(--ink-soft); }

.invoice-parties { display: grid; grid-template-columns: 1fr; gap: .75rem; }
@media (min-width: 576px) { .invoice-parties { grid-template-columns: 1fr 1fr; } }
.invoice-parties .party {
  background: #f8fafb; border: 1px solid var(--line);
  border-radius: 10px; padding: .7rem .85rem; font-size: .85rem;
}
.invoice-parties .party strong { display: block; font-size: .78rem; color: var(--ink-soft); margin-bottom: .25rem; }

/* بنود الفاتورة: جدول على الشاشات الواسعة، بطاقات على الهاتف */
.invoice-items { width: 100%; border-collapse: collapse; font-size: .88rem; }
.invoice-items th { background: #f1faf6; padding: .5rem .6rem; text-align: start; font-size: .8rem; }
.invoice-items td { padding: .55rem .6rem; border-bottom: 1px solid #eef1f4; }

@media (max-width: 575.98px) {
  .invoice-items thead { display: none; }
  .invoice-items, .invoice-items tbody, .invoice-items tr, .invoice-items td { display: block; width: 100%; }
  .invoice-items tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: .5rem; padding: .2rem 0; }
  .invoice-items td {
    display: flex; justify-content: space-between; gap: .75rem;
    border-bottom: 1px solid #f4f6f8; padding: .45rem .7rem;
  }
  .invoice-items tr td:last-child { border-bottom: none; }
  .invoice-items td::before {
    content: attr(data-label);
    font-weight: 700; font-size: .76rem; color: var(--ink-soft);
  }
  .invoice-items td[data-label="المنتج"] { display: block; font-weight: 700; background: #f8fafb; }
  .invoice-items td[data-label="المنتج"]::before { content: none; }
}

.invoice-totals { margin-top: .75rem; margin-inline-start: auto; width: 100%; max-width: 340px; font-size: .88rem; }
.invoice-totals .line { display: flex; justify-content: space-between; padding: .35rem 0; }
.invoice-totals .line.grand {
  border-top: 2px solid var(--brand);
  margin-top: .35rem; padding-top: .55rem;
  font-weight: 800; font-size: 1.05rem; color: var(--brand);
}
.invoice-totals .line .neg { color: #c0392b; }

@media print {
  .app-navbar, .header-search, .cat-strip, .app-footer,
  .whatsapp-float, .mobile-tabbar, .no-print { display: none !important; }
  body { background: #fff !important; padding-bottom: 0 !important; }
  .invoice-sheet { border: none; padding: 0; }
}

/* ============================ متفرقات ============================ */

.brand-logo { height: 32px; width: auto; object-fit: contain; }
.brand-logo-footer { height: 30px; }

.whatsapp-float {
  position: fixed; bottom: 24px; inset-inline-start: 20px; z-index: 1030;
  width: 52px; height: 52px; border-radius: 50%;
  background: #25D366; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; box-shadow: 0 6px 16px rgba(0,0,0,.25); text-decoration: none;
}
.whatsapp-float:hover { background: #1ebe57; color: #fff; }

.star-rating-input { display: inline-flex; gap: 4px; font-size: 1.4rem; }
.star-rating-input .star-btn { background: none; border: none; padding: 0; color: #d8dde3; cursor: pointer; line-height: 1; }
.star-rating-input .star-btn.active { color: var(--accent); }

.review-item { border-bottom: 1px solid #eef1f4; padding: 14px 0; }
.review-item:last-child { border-bottom: none; }
