/* ==============================================================================
   DIRECT SELLING & MULTI-VENDOR E-COMMERCE PWA - MASTER STYLESHEET
   Design System: Arabic Typography, RTL Native, Modern Emerald & Dark Slate
   ============================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800;900&display=swap');

:root {
  --primary: #059669;
  --primary-hover: #047857;
  --primary-light: #d1fae5;
  --primary-glow: rgba(16, 185, 129, 0.25);
  
  --secondary: #d97706;
  --secondary-hover: #b45309;
  --secondary-light: #fef3c7;
  
  --accent: #8b5cf6;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --success: #10b981;
  --warning: #f59e0b;
  --info: #3b82f6;

  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --bg-surface: #1e293b;
  --border-color: #334155;
  --border-subtle: rgba(255, 255, 255, 0.08);

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(16, 185, 129, 0.35);

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* Light Mode Overrides if toggled */
body.theme-light {
  --bg-dark: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-surface: #ffffff;
  --border-color: #e2e8f0;
  --border-subtle: rgba(0, 0, 0, 0.06);
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;
  --shadow-md: 0 4px 15px rgba(0, 0, 0, 0.06);
}

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

html, body {
  width: 100%;
  min-height: 100vh;
  font-family: 'Cairo', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  direction: rtl;
  text-align: right;
  line-height: 1.6;
  overflow-x: hidden;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-dark);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* Typography & Utilities */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-main);
}
a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover {
  color: var(--primary-hover);
}

/* App Container Layout */
#app-root {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: 70px; /* Space for mobile bottom nav */
}

@media (min-width: 1024px) {
  #app-root {
    padding-bottom: 0;
  }
}

/* Top App Bar */
.top-navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.3rem;
  box-shadow: 0 4px 10px rgba(5, 150, 105, 0.3);
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #10b981, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-text span {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: block;
}

/* Role Switcher Simulator Badge (Top Bar) */
.role-simulator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(30, 41, 59, 0.9);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  font-size: 0.82rem;
}

.role-simulator select {
  background: transparent;
  border: none;
  color: #38bdf8;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.role-simulator select option {
  background: #1e293b;
  color: #fff;
}

/* Header Action Buttons */
.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.icon-btn {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary);
  transform: translateY(-1px);
}

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

/* Main Navigation Links (Desktop) */
.desktop-nav-links {
  display: none;
  align-items: center;
  gap: 0.5rem;
}

@media (min-width: 1024px) {
  .desktop-nav-links {
    display: flex;
  }
}

.nav-link {
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.nav-link:hover, .nav-link.active {
  color: #fff;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

/* Main Content Area */
.main-wrapper {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  flex: 1;
}

/* Glass Card */
.glass-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  transition: border-color var(--transition-normal);
  position: relative;
  overflow: hidden;
}

.glass-card:hover {
  border-color: rgba(16, 185, 129, 0.4);
}

/* Modern Gradient KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.kpi-card {
  background: linear-gradient(145deg, #1e293b, #172033);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-info h4 {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.kpi-info .kpi-value {
  font-size: 1.65rem;
  font-weight: 800;
  color: #ffffff;
}

.kpi-info .kpi-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

.kpi-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
}

.icon-emerald {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.icon-gold {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.icon-blue {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
}

.icon-purple {
  background: rgba(139, 92, 246, 0.15);
  color: #8b5cf6;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #fff;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #10b981, #059669);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card);
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.btn-gold {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

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

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-block {
  width: 100%;
}

/* Category Filters Bar */
.category-filter-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.75rem;
  margin-bottom: 1.5rem;
  -webkit-overflow-scrolling: touch;
}

.category-chip {
  padding: 0.5rem 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.category-chip:hover, .category-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 10px var(--primary-glow);
}

/* Product Catalog Grid */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: all var(--transition-normal);
  position: relative;
}

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

.product-img-wrap {
  width: 100%;
  height: 200px;
  background: #172033;
  position: relative;
  overflow: hidden;
}

.product-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}

.product-card:hover .product-img-wrap img {
  transform: scale(1.05);
}

.pv-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: linear-gradient(135deg, #f59e0b, #b45309);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.category-badge {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(4px);
  color: #94a3b8;
  font-size: 0.72rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.product-content {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.product-sku {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.product-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0.35rem 0 0.5rem;
  line-height: 1.4;
  color: var(--text-main);
  height: 48px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.price-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-top: auto;
  padding: 0.75rem 0 0.5rem;
  border-top: 1px solid var(--border-subtle);
}

.partner-price {
  font-size: 1.25rem;
  font-weight: 800;
  color: #34d399;
}

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

.card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-info {
  background: rgba(59, 130, 246, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Rank Badge */
.rank-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 700;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(217, 119, 6, 0.3));
  border: 1px solid #f59e0b;
  color: #fcd34d;
}

/* Target Progress Bar */
.target-progress-box {
  background: linear-gradient(145deg, #1e293b, #0f172a);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 2rem;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.progress-bar-wrap {
  width: 100%;
  height: 12px;
  background: #334155;
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, #10b981, #f59e0b);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.custom-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 0.88rem;
}

.custom-table th {
  background: #172033;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.custom-table td {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
  white-space: nowrap;
}

.custom-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* Network Downline Tree View */
.network-tree-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.tree-node {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all var(--transition-fast);
  position: relative;
}

.tree-node:hover {
  border-color: var(--primary);
  background: #243049;
}

.tree-node-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.tree-gen-tag {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
}

.tree-stats {
  display: flex;
  gap: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.tree-stats span strong {
  color: #fff;
}

/* Modals & Drawers */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.75rem;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  transition: transform var(--transition-normal);
}

.modal-overlay.active .modal-content {
  transform: scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

/* Cart Drawer */
.cart-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  z-index: 110;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.cart-drawer.active {
  transform: translateX(0);
}

.cart-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.cart-item {
  display: flex;
  gap: 1rem;
  background: #172033;
  padding: 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.cart-item img {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.cart-item-details {
  flex: 1;
}

.cart-item-title {
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.cart-footer {
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background: #172033;
}

.cart-summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

.cart-summary-row.total {
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
  border-top: 1px dashed var(--border-color);
  padding-top: 0.65rem;
  margin-top: 0.65rem;
}

/* Mobile Bottom Navigation Bar */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  padding: 0.5rem 0.5rem 0.65rem;
  z-index: 40;
}

@media (min-width: 1024px) {
  .bottom-nav {
    display: none;
  }
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  transition: color var(--transition-fast);
}

.bottom-nav-item.active, .bottom-nav-item:hover {
  color: #34d399;
}

.bottom-nav-item svg {
  width: 22px;
  height: 22px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 85px;
  left: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

@media (min-width: 768px) {
  .toast-container {
    left: auto;
    right: 25px;
    bottom: 25px;
    max-width: 380px;
  }
}

.toast {
  background: #1e293b;
  border: 1px solid var(--border-color);
  border-right: 4px solid var(--primary);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.25rem;
  box-shadow: var(--shadow-lg);
  color: #fff;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  pointer-events: auto;
  animation: slideIn 0.3s ease forwards;
}

.toast.toast-error {
  border-right-color: var(--danger);
}

.toast.toast-warning {
  border-right-color: var(--warning);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(15px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* PWA Install Banner */
.pwa-banner {
  background: linear-gradient(135deg, rgba(5, 150, 105, 0.9), rgba(15, 23, 42, 0.95));
  border: 1px solid rgba(16, 185, 129, 0.4);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-glow);
}

/* Form Controls */
.form-group {
  margin-bottom: 1.15rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.7rem 1rem;
  background: #172033;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
