/* ====================================================================
   Mahfazty (محفظتي) - Ultra Modern Design System & Mobile UX Engine
   Premium Palette, Glassmorphism, Native Bottom Navigation for Android
   ==================================================================== */

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

:root {
  /* Ultra-Premium Light Theme (Default) */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.94);
  --bg-hover: #f1f5f9;
  --bg-active: #e2e8f0;
  
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-light: #94a3b8;
  
  --border-color: #cbd5e1;
  --border-glass: rgba(203, 213, 225, 0.6);
  
  /* Curated Rich Colors */
  --brand-primary: #4338ca;         /* Deep Indigo */
  --brand-primary-hover: #3730a3;
  --brand-primary-light: #eef2ff;
  
  --brand-success: #059669;         /* Vibrant Emerald */
  --brand-success-light: #ecfdf5;
  
  --brand-danger: #dc2626;          /* Ruby Red */
  --brand-danger-light: #fef2f2;
  
  --brand-warning: #d97706;         /* Warm Amber */
  --brand-warning-light: #fffbeb;
  
  --brand-purple: #7c3aed;          /* Purple Accent */
  --brand-purple-light: #f5f3ff;
  
  /* Shadows & Elevation */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.03);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 24px -4px rgba(15, 23, 42, 0.12), 0 4px 8px -2px rgba(15, 23, 42, 0.04);
  --shadow-xl: 0 24px 48px -12px rgba(15, 23, 42, 0.18);
  
  --radius-sm: 0.5rem;
  --radius-md: 0.85rem;
  --radius-lg: 1.25rem;
  --radius-full: 9999px;
  
  --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: #1f2937;
  --bg-glass: rgba(31, 41, 55, 0.94);
  --bg-hover: #374151;
  --bg-active: #4b5563;
  
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-light: #6b7280;
  
  --border-color: #374151;
  --border-glass: rgba(55, 65, 81, 0.8);
  
  --brand-primary-light: rgba(99, 102, 241, 0.15);
  --brand-success-light: rgba(16, 185, 129, 0.15);
  --brand-danger-light: rgba(239, 68, 68, 0.15);
  --brand-warning-light: rgba(245, 158, 11, 0.15);
  --brand-purple-light: rgba(139, 92, 246, 0.15);
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 24px rgba(0,0,0,0.6);
  --shadow-xl: 0 24px 48px rgba(0,0,0,0.7);
}

/* Base Setup */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Tajawal', 'Cairo', system-ui, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  direction: rtl;
  text-align: right;
  line-height: 1.6;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-wrapper {
  display: flex;
  flex: 1;
  width: 100%;
}

.main-content {
  flex: 1;
  padding: 1.75rem;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

/* Header Navbar */
.navbar {
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 0.75rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  font-weight: 900;
  font-size: 1.4rem;
  color: var(--brand-primary);
  text-decoration: none;
}

.brand img {
  filter: drop-shadow(0 4px 8px rgba(67, 56, 202, 0.3));
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.theme-toggle-btn, .icon-btn {
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.theme-toggle-btn:hover, .icon-btn:hover {
  background: var(--bg-active);
  transform: translateY(-2px);
}

/* Desktop Sidebar */
.sidebar {
  width: 270px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0.85rem;
  gap: 0.6rem;
  transition: var(--transition);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.9rem 1.1rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.98rem;
  transition: var(--transition);
  cursor: pointer;
  border: 1px solid transparent;
}

.sidebar-link:hover {
  background-color: var(--bg-hover);
  color: var(--text-main);
}

.sidebar-link.active {
  background-color: var(--brand-primary-light);
  color: var(--brand-primary);
  border-color: rgba(67, 56, 202, 0.25);
  box-shadow: var(--shadow-sm);
}

/* Mobile Native Bottom Navigation Bar */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
  z-index: 95;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
  padding: 0 0.4rem;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-md);
  transition: var(--transition);
  flex: 1;
  text-align: center;
}

.mobile-nav-item.active {
  color: var(--brand-primary);
  background: var(--brand-primary-light);
  font-weight: 900;
}

/* Android & Mobile Conditional Visibility */
.android-only-qr {
  display: none;
}

@media (max-width: 900px) {
  .sidebar {
    display: none !important;
  }
  .mobile-bottom-nav {
    display: flex !important;
  }
  .main-content {
    padding: 1rem 1rem 80px 1rem !important;
  }
  .android-only-qr {
    display: block !important;
  }
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr !important;
  }
}

body.is-android-app .sidebar {
  display: none !important;
}

body.is-android-app .mobile-bottom-nav {
  display: flex !important;
}

body.is-android-app .main-content {
  padding: 1rem 1rem 80px 1rem !important;
}

body.is-android-app .android-only-qr {
  display: block !important;
}

/* Cards & Containers */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
  position: relative;
}

@media (max-width: 600px) {
  .card { padding: 1.25rem; }
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.grid-1 { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.5rem; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5rem; }

/* Stat Cards */
.stat-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 1.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

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

.stat-icon {
  width: 58px;
  height: 58px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-primary .stat-icon { background: var(--brand-primary-light); color: var(--brand-primary); }
.stat-success .stat-icon { background: var(--brand-success-light); color: var(--brand-success); }
.stat-danger .stat-icon { background: var(--brand-danger-light); color: var(--brand-danger); }
.stat-warning .stat-icon { background: var(--brand-warning-light); color: var(--brand-warning); }

.stat-val { font-size: 1.85rem; font-weight: 900; margin-top: 0.25rem; letter-spacing: -0.5px; }
.stat-lbl { font-size: 0.9rem; color: var(--text-muted); font-weight: 700; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.8rem 1.35rem;
  font-size: 0.98rem;
  font-weight: 800;
  font-family: inherit;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--brand-primary), #4f46e5);
  color: white;
  box-shadow: 0 4px 14px rgba(67, 56, 202, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(67, 56, 202, 0.4);
}

.btn-success {
  background: linear-gradient(135deg, var(--brand-success), #10b981);
  color: white;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.3);
}

.btn-danger {
  background: linear-gradient(135deg, var(--brand-danger), #ef4444);
  color: white;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.3);
}

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

.btn-secondary:hover {
  background: var(--bg-active);
  transform: translateY(-1px);
}

.btn-sm {
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

.btn-block { width: 100%; }

/* Forms & Inputs */
.form-group { margin-bottom: 1.35rem; }
.form-label { display: block; font-weight: 800; font-size: 0.92rem; margin-bottom: 0.55rem; color: var(--text-main); }
.form-control, .form-select {
  width: 100%;
  padding: 0.8rem 1.1rem;
  font-size: 0.98rem;
  font-family: inherit;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  transition: var(--transition);
}

.form-control:focus, .form-select:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(67, 56, 202, 0.2);
}

/* Tables */
.table-responsive { width: 100%; overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border-color); }
.table { width: 100%; border-collapse: collapse; text-align: right; font-size: 0.95rem; }
.table th { background: var(--bg-hover); padding: 0.95rem 1.1rem; font-weight: 800; color: var(--text-muted); border-bottom: 1px solid var(--border-color); white-space: nowrap; }
.table td { padding: 0.95rem 1.1rem; border-bottom: 1px solid var(--border-color); color: var(--text-main); white-space: nowrap; }
.table tbody tr:hover { background-color: var(--bg-hover); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.3rem 0.75rem; border-radius: var(--radius-full); font-size: 0.82rem; font-weight: 800; }
.badge-primary { background: var(--brand-primary-light); color: var(--brand-primary); }
.badge-success { background: var(--brand-success-light); color: var(--brand-success); }
.badge-danger { background: var(--brand-danger-light); color: var(--brand-danger); }
.badge-warning { background: var(--brand-warning-light); color: var(--brand-warning); }

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.65); backdrop-filter: blur(6px); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 1.25rem; animation: fadeIn 0.2s ease;
}
.modal-content {
  background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius-lg);
  width: 100%; max-width: 560px; box-shadow: var(--shadow-xl); overflow: hidden; animation: slideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-header { padding: 1.35rem 1.6rem; border-bottom: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 1.25rem; font-weight: 900; }
.modal-body { padding: 1.6rem; max-height: 80vh; overflow-y: auto; }
.modal-footer { padding: 1.1rem 1.6rem; background: var(--bg-hover); border-top: 1px solid var(--border-color); display: flex; align-items: center; justify-content: flex-end; gap: 0.75rem; }

.alert { padding: 1.1rem 1.35rem; border-radius: var(--radius-md); margin-bottom: 1.35rem; display: flex; align-items: center; gap: 0.85rem; font-size: 0.95rem; font-weight: 600; }
.alert-info { background: var(--brand-primary-light); color: var(--brand-primary); border: 1px solid rgba(67, 56, 202, 0.2); }
.alert-success { background: var(--brand-success-light); color: var(--brand-success); border: 1px solid rgba(5, 150, 105, 0.2); }
.alert-danger { background: var(--brand-danger-light); color: var(--brand-danger); border: 1px solid rgba(220, 38, 38, 0.2); }
.alert-warning { background: var(--brand-warning-light); color: var(--brand-warning); border: 1px solid rgba(217, 119, 6, 0.2); }

.qr-scanner-box { width: 100%; max-width: 350px; height: 350px; margin: 0 auto; border: 2px dashed var(--brand-primary); border-radius: var(--radius-md); overflow: hidden; position: relative; background: #000; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }
