/* =========================================
   1. CSS VARIABLES & THEME
   ========================================= */
:root {
  /* Colors */
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #64748b;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  
  /* Backgrounds & Text */
  --bg: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  
  /* Spacing & sizing */
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  
  /* Transitions */
  --transition-fast: 150ms ease-in-out;
  --transition: 300ms ease;
}

/* =========================================
   2. RESET & BASE STYLES
   ========================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  direction: rtl; /* Right-to-Left for Arabic */
}

body {
  font-family: 'Segoe UI', 'Tahoma', 'Geneva', 'Verdana', sans-serif;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg-secondary);
  min-height: 100vh;
  overflow-x: hidden;
}

img, svg {
  max-width: 100%;
  display: block;
}

/* Fix for your huge icons issue */
svg {
  width: 100%;
  height: 100%;
}

a {
  text-decoration: none;
  color: inherit;
  transition: color var(--transition-fast);
}

ul, ol {
  list-style: none;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* =========================================
   3. LAYOUT UTILITIES
   ========================================= */
.container {
  width: 100%;
  max-width: 1280px;
  margin-inline: auto;
  padding-inline: 1rem;
}

.hidden { display: none !important; }
.flex { display: flex; }
.grid { display: grid; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-4 { gap: 1rem; }

/* =========================================
   4. BUTTONS
   ========================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
  font-size: 0.95rem;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
}

.btn-primary:hover {
  background-color: var(--primary-dark);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background-color: white;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background-color: var(--bg-tertiary);
  border-color: var(--text-light);
}

.btn-success {
  background-color: var(--success);
  color: white;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* =========================================
   5. HEADER
   ========================================= */
.header {
  background-color: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-content {
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
}

.logo img {
  height: 40px;
  width: auto;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.cart-toggle {
  position: relative;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  transition: var(--transition-fast);
}

.cart-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.cart-count {
  background-color: var(--danger);
  color: white;
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-full);
  min-width: 1.25rem;
  text-align: center;
}

/* =========================================
   6. PRODUCT GRID
   ========================================= */
.main-content {
  padding-block: 2rem;
  min-height: 80vh;
}

.loading, .error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  text-align: center;
  gap: 1rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.5rem;
}

.product-card {
  background: var(--bg);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  cursor: pointer;
}

.product-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.product-image-wrapper {
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--bg-tertiary);
  position: relative;
}

.product-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition);
}

.product-card:hover .product-image {
  transform: scale(1.05);
}

.product-info {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-grow: 1;
}

.product-title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-price-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: auto;
}

.price-current {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
}

.price-old {
  font-size: 0.875rem;
  color: var(--text-light);
  text-decoration: line-through;
}

.btn-add-cart {
  margin-top: 0.75rem;
  width: 100%;
}

/* =========================================
   7. MODALS & DRAWERS
   ========================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: var(--bg);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  transform: scale(0.95);
  transition: transform var(--transition);
  box-shadow: var(--shadow-xl);
}

.modal-overlay.active .modal-content {
  transform: scale(1);
}

.modal-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.close-btn {
  background: var(--bg-tertiary);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--text-secondary);
  transition: var(--transition-fast);
}

.close-btn:hover {
  background: var(--border);
  color: var(--danger);
}

/* Product Modal Specifics */
.product-modal-body {
  padding: 0;
}

.product-modal-grid {
  display: grid;
  grid-template-columns: 1fr;
}

@media (min-width: 768px) {
  .product-modal-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.product-modal-image {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.product-modal-details {
  padding: 1.5rem;
}

.product-modal-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.product-modal-price {
  font-size: 1.5rem;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 1rem;
}

.product-modal-desc {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  line-height: 1.7;
}

/* =========================================
   8. CART DRAWER
   ========================================= */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1001;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.drawer-overlay.active {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0; /* RTL: Drawer comes from left in Arabic */
  bottom: 0;
  width: 100%;
  max-width: 400px;
  background: var(--bg);
  z-index: 1002;
  transform: translateX(-100%); /* RTL: Hidden to the left */
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
}

.drawer.active {
  transform: translateX(0);
}

.drawer-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.drawer-footer {
  padding: 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* Cart Items */
.cart-item {
  display: flex;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.cart-item-image {
  width: 80px;
  height: 80px;
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--bg-tertiary);
}

.cart-item-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.cart-item-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
}

.cart-item-price {
  color: var(--primary);
  font-weight: 600;
}

.cart-item-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.qty-control {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.qty-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border: none;
  cursor: pointer;
  font-size: 1rem;
}

.qty-btn:hover {
  background: var(--border);
}

.qty-value {
  width: 30px;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
}

.remove-item {
  margin-right: auto; /* Push to left in RTL */
  color: var(--danger);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.25rem;
}

.cart-total-row {
  display: flex;
  justify-content: space-between;
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

/* =========================================
   9. CHECKOUT FORM
   ========================================= */
.checkout-form {
  padding: 1.5rem;
}

.form-section {
  margin-bottom: 2rem;
}

.form-section-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.form-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 640px) {
  .form-grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-input, .form-select, .form-textarea {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  transition: var(--transition-fast);
  background: var(--bg);
  text-align: right; /* RTL inputs */
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

/* Radio Buttons (Delivery Type) */
.radio-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition-fast);
}

.radio-label:has(input:checked) {
  border-color: var(--primary);
  background-color: var(--primary-light);
}

/* Order Summary in Checkout */
.order-summary-box {
  background: var(--bg-tertiary);
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  font-size: 0.9rem;
}

.summary-row.total {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
  padding-top: 0.75rem;
}

/* Coupon */
.coupon-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.coupon-row .form-input {
  flex: 1;
}

/* =========================================
   10. SUCCESS MODAL
   ========================================= */
.success-content {
  text-align: center;
  padding: 2rem;
}

.success-icon {
  width: 80px;
  height: 80px;
  background: var(--success);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  margin: 0 auto 1.5rem;
}

.success-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.success-message {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.order-id-box {
  background: var(--bg-tertiary);
  padding: 1rem;
  border-radius: var(--radius);
  font-family: monospace;
  font-size: 1.1rem;
  margin-bottom: 1.5rem;
  display: inline-block;
}

/* =========================================
   11. FOOTER & SOCIAL ICONS (FIXED)
   ========================================= */
.footer {
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 3rem 0 2rem;
  margin-top: 4rem;
}

.footer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  text-align: center;
}

.social-links {
  display: flex;
  gap: 1rem;
}

.social-link {
  width: 44px;  /* Fixed size */
  height: 44px; /* Fixed size */
  background: var(--bg-tertiary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: var(--transition-fast);
  border: 1px solid var(--border);
}

.social-link:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: translateY(-2px);
}

/* IMPORTANT FIX FOR SVGs inside social links */
.social-link svg {
  width: 24px;
  height: 24px;
}

.footer-copy {
  color: var(--text-light);
  font-size: 0.875rem;
}

/* =========================================
   12. FLOATING WHATSAPP BUTTON (FIXED)
   ========================================= */
.whatsapp-float {
  position: fixed;
  bottom: 2rem;
  left: 2rem; /* Left side for Arabic */
  width: 60px;
  height: 60px;
  background-color: #25d366;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  z-index: 999;
  transition: transform var(--transition-fast);
}

.whatsapp-float:hover {
  transform: scale(1.1);
}

/* IMPORTANT FIX FOR SVG inside WhatsApp button */
.whatsapp-float svg {
  width: 32px;
  height: 32px;
}

/* =========================================
   13. TOAST NOTIFICATIONS
   ========================================= */
.toast-container {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
  pointer-events: auto;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}