/* ========================================
   style.css — متجر إلكتروني احترافي
   نظام ألوان + تجاوب + RTL
   ======================================== */

/* ===== المتغيرات (CSS Variables) ===== */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #3b82f6;
  --secondary: #f59e0b;
  --secondary-dark: #d97706;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --bg: #f8fafc;
  --bg-alt: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --header-h: 64px;
  --max-width: 1280px;
}

/* ===== إعادة الضبط (Reset) ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: 'Cairo', 'Tajawal', 'Noto Sans Arabic', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  direction: rtl;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  text-decoration: none;
  color: inherit;
}

img {
  max-width: 100%;
  display: block;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, textarea, select {
  font-family: inherit;
  font-size: 1rem;
}

ul {
  list-style: none;
}

/* ===== الهيدر (Header) ===== */
.site-header {
  background: var(--card-bg);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 1000;
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--primary);
  white-space: nowrap;
}

.logo svg {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cart-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-alt);
  color: var(--text);
  font-weight: 600;
  transition: var(--transition);
}

.cart-link:hover {
  background: var(--primary);
  color: #fff;
}

.cart-link svg {
  width: 22px;
  height: 22px;
}

.cart-badge {
  position: absolute;
  top: -6px;
  left: -6px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ===== الحاوي الرئيسي (Container) ===== */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 20px;
  width: 100%;
  flex: 1;
}

/* ===== شريط البحث ===== */
.search-bar {
  margin-bottom: 20px;
  position: relative;
}

.search-bar input {
  width: 100%;
  padding: 12px 44px 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: var(--transition);
  background: var(--card-bg);
}

.search-bar input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-bar .search-icon {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  color: var(--text-light);
  pointer-events: none;
}

/* ===== الفئات (Categories) ===== */
.categories-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0 16px;
  margin-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}

.categories-bar::-webkit-scrollbar {
  height: 4px;
}

.categories-bar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.cat-btn {
  padding: 8px 18px;
  border-radius: 50px;
  background: var(--bg-alt);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: var(--transition);
  border: 1px solid transparent;
}

.cat-btn:hover {
  background: var(--primary-light);
  color: #fff;
}

.cat-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-dark);
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 12px;
}

/* ===== شبكة المنتجات (Products Grid) ===== */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
  margin-top: 16px;
}

/* ===== بطاقة المنتج ===== */
.product-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-light);
}

.product-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-4px);
  border-color: var(--primary-light);
}

.product-image {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: var(--transition);
}

.product-card:hover .product-image img {
  transform: scale(1.06);
}

.product-image.no-image img {
  display: none;
}

.no-image-icon {
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-info {
  padding: 14px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.product-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.7em;
}

.product-price-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.product-price {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary);
}

.old-price {
  font-size: 0.85rem;
  color: var(--text-light);
  text-decoration: line-through;
}

.btn-view {
  margin: 0 16px 16px;
  text-align: center;
}

/* ===== الأزرار (Buttons) ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.9rem;
  transition: var(--transition);
  border: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
  background: var(--secondary);
  color: #fff;
}

.btn-secondary:hover {
  background: var(--secondary-dark);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline:hover {
  background: var(--primary);
  color: #fff;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 1rem;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn.loading {
  pointer-events: none;
}

/* ===== زر "تحميل المزيد" ===== */
.load-more-wrapper {
  text-align: center;
  margin-top: 32px;
}

#load-more-btn {
  display: none;
}

/* ===== مؤشر التحميل (Spinner) ===== */
#loading-indicator {
  display: none;
  text-align: center;
  padding: 40px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Skeleton Loading ===== */
.skeleton-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.skeleton-img,
.skeleton-line,
.skeleton-btn {
  background: linear-gradient(90deg, var(--bg-alt) 25%, var(--border-light) 50%, var(--bg-alt) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-img {
  width: 100%;
  aspect-ratio: 1;
}

.skeleton-line {
  height: 14px;
  margin: 12px 16px;
  border-radius: 4px;
}

.skeleton-line.short {
  width: 50%;
}

.skeleton-btn {
  height: 38px;
  margin: 12px 16px 16px;
  border-radius: var(--radius-sm);
}

/* ===== رسائل الحالات ===== */
.message-box {
  display: none;
  padding: 16px 20px;
  border-radius: var(--radius-sm);
  margin: 16px 0;
  font-weight: 600;
  text-align: center;
}

.message-error {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid #fecaca;
}

.message-success {
  background: var(--success-light);
  color: var(--success);
  border: 1px solid #bbf7d0;
}

.message-info {
  background: var(--bg-alt);
  color: var(--text-muted);
}

#no-results {
  display: none;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

#no-results svg {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  color: var(--text-light);
}

/* ===== صفحة تفاصيل المنتج ===== */
.product-detail-wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-bottom: 32px;
}

.product-detail-gallery {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.main-image-container {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg-alt);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
}

.main-image-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.no-image-large {
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-thumbs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.gallery-thumbs .thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
}

.gallery-thumbs .thumb:hover,
.gallery-thumbs .thumb.active {
  border-color: var(--primary);
}

.product-detail-info {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.product-category-tag {
  display: inline-block;
  padding: 4px 14px;
  background: var(--bg-alt);
  color: var(--text-muted);
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 600;
  width: fit-content;
}

.product-detail-name {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.3;
}

.product-detail-price {
  display: flex;
  align-items: center;
  gap: 12px;
}

.price-current {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary);
}

.old-price-lg {
  font-size: 1.1rem;
  color: var(--text-light);
  text-decoration: line-through;
}

.quantity-selector {
  display: flex;
  align-items: center;
  gap: 12px;
}

.quantity-selector label {
  font-weight: 700;
  color: var(--text);
}

.qty-controls {
  display: flex;
  align-items: center;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.qty-btn {
  width: 40px;
  height: 40px;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--bg-alt);
  transition: var(--transition);
}

.qty-btn:hover {
  background: var(--primary);
  color: #fff;
}

.qty-controls input {
  width: 56px;
  height: 40px;
  text-align: center;
  border: none;
  border-right: 1px solid var(--border);
  border-left: 1px solid var(--border);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  background: var(--card-bg);
}

.qty-controls input:focus {
  outline: none;
}

/* إخفاء أسهم input number */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.product-detail-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.product-description {
  margin-top: 8px;
  padding: 24px;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.product-description h3 {
  font-size: 1.2rem;
  margin-bottom: 12px;
  color: var(--text);
  border-bottom: 2px solid var(--primary);
  padding-bottom: 8px;
  display: inline-block;
}

.product-description p {
  color: var(--text-muted);
  line-height: 1.8;
  white-space: pre-wrap;
}

/* ===== صفحة السلة ===== */
.cart-page-title {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 24px;
  color: var(--text);
}

.cart-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}

#cart-items {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cart-item {
  display: grid;
  grid-template-columns: 80px 1fr auto auto auto;
  gap: 16px;
  align-items: center;
  background: var(--card-bg);
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.cart-item-image {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-alt);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cart-item-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cart-item-noimg {
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cart-item-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cart-item-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.cart-item-price {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.cart-item-qty {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.qty-btn-sm {
  width: 28px;
  height: 28px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--bg-alt);
  border-radius: 4px;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.qty-btn-sm:hover {
  background: var(--primary);
  color: #fff;
}

.qty-display {
  min-width: 30px;
  text-align: center;
  font-weight: 700;
  color: var(--text);
}

.cart-item-total {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary);
  white-space: nowrap;
}

.cart-item-remove {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--danger);
  background: var(--danger-light);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.cart-item-remove:hover {
  background: var(--danger);
  color: #fff;
}

/* ملخص السلة */
#cart-summary {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: calc(var(--header-h) + 20px);
}

.summary-title {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  color: var(--text-muted);
}

.summary-row strong {
  color: var(--text);
}

.summary-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 16px 0;
  padding-top: 16px;
  border-top: 2px solid var(--border);
}

.summary-total .label {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.summary-total .value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
}

/* نموذج الطلب */
.checkout-form {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 2px solid var(--border);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.form-group label .required {
  color: var(--danger);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  transition: var(--transition);
  background: var(--card-bg);
  color: var(--text);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

#empty-cart {
  display: none;
  text-align: center;
  padding: 60px 20px;
}

#empty-cart svg {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  color: var(--text-light);
}

#empty-cart h2 {
  font-size: 1.4rem;
  color: var(--text);
  margin-bottom: 8px;
}

#empty-cart p {
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* ===== Toast Notification ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 50%;
  transform: translateX(50%) translateY(100px);
  background: var(--text);
  color: #fff;
  padding: 14px 28px;
  border-radius: 50px;
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  opacity: 0;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.toast.show {
  transform: translateX(50%) translateY(0);
  opacity: 1;
}

/* ===== الفوتر (Footer) ===== */
.site-footer {
  background: var(--text);
  color: var(--text-light);
  text-align: center;
  padding: 24px 20px;
  margin-top: auto;
}

.site-footer p {
  font-size: 0.9rem;
}

.site-footer a {
  color: var(--primary-light);
  font-weight: 600;
}

/* ===== بreadcrumbs ===== */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.breadcrumb a {
  color: var(--primary);
  font-weight: 600;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

.breadcrumb span.separator {
  color: var(--text-light);
}

/* ===== التجاوب (Responsive) ===== */
@media (max-width: 900px) {
  .product-detail-wrapper {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .cart-layout {
    grid-template-columns: 1fr;
  }

  #cart-summary {
    position: static;
  }
}

@media (max-width: 768px) {
  .products-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
  }

  .header-inner {
    padding: 0 14px;
  }

  .logo {
    font-size: 1.1rem;
  }

  .cart-link span {
    display: none;
  }

  .container {
    padding: 16px 14px;
  }

  .product-detail-name {
    font-size: 1.3rem;
  }

  .price-current {
    font-size: 1.5rem;
  }

  .product-detail-actions {
    flex-direction: column;
  }

  .product-detail-actions .btn {
    width: 100%;
  }

  .cart-item {
    grid-template-columns: 64px 1fr auto;
    grid-template-rows: auto auto;
    gap: 10px;
  }

  .cart-item-image {
    width: 64px;
    height: 64px;
    grid-row: span 2;
  }

  .cart-item-qty {
    grid-column: 2;
    grid-row: 2;
  }

  .cart-item-total {
    grid-column: 3;
    grid-row: 2;
    font-size: 1rem;
  }

  .cart-item-remove {
    grid-column: 3;
    grid-row: 1;
  }

  .form-row-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .products-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .product-info {
    padding: 10px 12px;
  }

  .product-name {
    font-size: 0.85rem;
  }

  .product-price {
    font-size: 1rem;
  }

  .btn-view {
    margin: 0 12px 12px;
    padding: 8px 14px;
    font-size: 0.85rem;
  }

  .cart-page-title {
    font-size: 1.4rem;
  }
}
