/* ====================================================================
   Mahfazty (محفظتي) - الهوية البصرية الإسلامية المصرية والعربية الفاخرة
   Royal Islamic Emerald & Egyptian Gold Heritage Design System
   ==================================================================== */

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

:root {
  /* الوضع الفاتح: حجر رملي دافئ ولون البردي المصري مع الزمرد والتبر الذهبي */
  --bg-primary: #fbf9f4;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.95);
  --bg-hover: #f5f0e5;
  --bg-active: #ece5d6;
  
  --text-main: #0f241d;
  --text-muted: #3d5a50;
  --text-light: #708c82;
  
  --border-color: #e2d9c8;
  --border-glass: rgba(226, 217, 200, 0.7);
  --border-gold: rgba(217, 119, 6, 0.35);
  
  /* الألوان التراثية الملكية */
  --brand-primary: #065f46;         /* أخضر زمردي إسلامي ملكي */
  --brand-primary-hover: #044e3a;
  --brand-primary-light: #ecfdf5;
  
  --brand-gold: #d97706;            /* ذهب فاطمي وتبر مصري أصيل */
  --brand-gold-hover: #b45309;
  --brand-gold-light: #fef3c7;
  
  --brand-turquoise: #0f766e;       /* فيروز النيل التراثي */
  --brand-turquoise-light: #f0fdfa;
  
  --brand-success: #059669;         /* أخضر النماء المالي */
  --brand-success-light: #ecfdf5;
  
  --brand-danger: #b91c1c;          /* أحمر قرمزي */
  --brand-danger-light: #fef2f2;
  
  --brand-warning: #d97706;         /* كهرمان دافئ */
  --brand-warning-light: #fffbeb;
  
  /* ظلال ناعمة مستوحاة من العمارة التراثية */
  --shadow-sm: 0 1px 3px rgba(6, 95, 70, 0.06), 0 1px 2px rgba(6, 95, 70, 0.04);
  --shadow-md: 0 4px 14px -2px rgba(6, 95, 70, 0.08), 0 2px 6px -1px rgba(217, 119, 6, 0.06);
  --shadow-lg: 0 12px 28px -4px rgba(6, 95, 70, 0.12), 0 4px 10px -2px rgba(217, 119, 6, 0.08);
  --shadow-xl: 0 24px 48px -12px rgba(6, 95, 70, 0.2);
  --shadow-gold: 0 4px 16px rgba(217, 119, 6, 0.25);
  
  --radius-sm: 0.5rem;
  --radius-md: 0.9rem;
  --radius-lg: 1.35rem;
  --radius-full: 9999px;
  
  --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  /* الوضع الليلي: ليل القاهرة الفاطمية ورخام المساجد الداكن */
  --bg-primary: #061913;
  --bg-secondary: #0b241c;
  --bg-card: #102e24;
  --bg-glass: rgba(16, 46, 36, 0.94);
  --bg-hover: #163d30;
  --bg-active: #1d4e3d;
  
  --text-main: #f2f9f5;
  --text-muted: #9fbfb3;
  --text-light: #6a8c80;
  
  --border-color: #1e4537;
  --border-glass: rgba(30, 69, 55, 0.8);
  --border-gold: rgba(245, 158, 11, 0.35);
  
  --brand-primary-light: rgba(5, 150, 105, 0.2);
  --brand-success-light: rgba(16, 185, 129, 0.2);
  --brand-danger-light: rgba(239, 68, 68, 0.2);
  --brand-warning-light: rgba(245, 158, 11, 0.2);
  --brand-gold-light: rgba(245, 158, 11, 0.2);
  --brand-turquoise-light: rgba(20, 184, 166, 0.2);
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.5);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.6);
  --shadow-lg: 0 12px 28px rgba(0,0,0,0.7);
  --shadow-xl: 0 24px 48px rgba(0,0,0,0.8);
  --shadow-gold: 0 4px 18px rgba(245, 158, 11, 0.2);
}

/* ====================================================================
   Scrollbar & Layout Stability - Royal Islamic Emerald & Gold
   ==================================================================== */
html {
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 9999px;
  border: 2px solid var(--bg-primary);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--brand-gold);
}

[data-theme="dark"] ::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: #1d4e3d;
  border: 2px solid var(--bg-primary);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: var(--brand-gold);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) var(--bg-primary);
}

[data-theme="dark"] * {
  scrollbar-color: #1d4e3d var(--bg-primary);
}

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

body {
  font-family: 'Cairo', 'Tajawal', system-ui, -apple-system, 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;
  background-image: radial-gradient(var(--border-gold) 0.75px, transparent 0.75px), radial-gradient(var(--border-color) 0.75px, var(--bg-primary) 0.75px);
  background-size: 36px 36px;
  background-position: 0 0, 18px 18px;
}

@keyframes pulseUrgent {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(185, 28, 28, 0.7); }
  70% { transform: scale(1.02); box-shadow: 0 0 0 8px rgba(185, 28, 28, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(185, 28, 28, 0); }
}

.urgent-task-card {
  border: 2px solid var(--brand-danger) !important;
  animation: pulseUrgent 2s infinite;
  background: var(--brand-danger-light) !important;
}

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

.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
}

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

/* Header Navbar */
.navbar {
  background: var(--bg-glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1.5px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 0.85rem 1.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  border-image: linear-gradient(to left, transparent, var(--border-gold), transparent) 1;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  font-weight: 900;
  font-size: 1.45rem;
  color: var(--brand-primary);
  text-decoration: none;
  font-family: 'Cairo', sans-serif;
  letter-spacing: -0.3px;
}

[data-theme="dark"] .brand {
  color: #34d399;
}

.brand img {
  filter: drop-shadow(0 4px 10px rgba(6, 95, 70, 0.35));
}

.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);
  border-color: var(--brand-gold);
  transform: translateY(-2px);
}

/* Desktop Sidebar */
.sidebar {
  width: 275px;
  background: var(--bg-secondary);
  border-left: 1.5px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1.75rem 0.95rem;
  gap: 0.65rem;
  transition: var(--transition);
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.02);
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  flex-shrink: 0;
}

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

.sidebar-link:hover {
  background-color: var(--bg-hover);
  color: var(--brand-primary);
  border-color: rgba(6, 95, 70, 0.15);
}

.sidebar-link.active {
  background: linear-gradient(135deg, var(--brand-primary-light), rgba(217, 119, 6, 0.08));
  color: var(--brand-primary);
  border-color: var(--brand-gold);
  box-shadow: var(--shadow-sm);
  font-weight: 900;
}

[data-theme="dark"] .sidebar-link.active {
  color: #34d399;
}

/* Mobile Native Bottom Navigation Bar */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 66px;
  background: var(--bg-glass);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border-top: 1.5px solid var(--border-color);
  z-index: 95;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -4px 24px rgba(6, 95, 70, 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.74rem;
  font-weight: 800;
  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;
  border-top: 2px solid var(--brand-gold);
}

[data-theme="dark"] .mobile-nav-item.active {
  color: #34d399;
}

/* 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: 1.1rem 1.1rem 86px 1.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: 1.1rem 1.1rem 86px 1.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.3rem; }
}

.card:hover {
  box-shadow: var(--shadow-lg);
  border-color: rgba(217, 119, 6, 0.25);
}

/* بطاقة المحفظة الإسلامية الملكية (Islamic Luxury Wallet Card) */
.islamic-wallet-card {
  background: linear-gradient(135deg, #064e3b 0%, #065f46 50%, #047857 100%);
  color: #ffffff;
  border-radius: 1.5rem;
  padding: 2rem;
  box-shadow: var(--shadow-xl), 0 0 24px rgba(217, 119, 6, 0.15);
  border: 1.5px solid rgba(245, 158, 11, 0.45);
  position: relative;
  overflow: hidden;
}

.islamic-wallet-card::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.2) 0%, transparent 70%);
  pointer-events: none;
}

.islamic-wallet-card::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(to right, transparent, #fbbf24, #f59e0b, transparent);
}

.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);
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
  transition: var(--transition);
}

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

.stat-primary::after { background: linear-gradient(to right, transparent, var(--brand-primary), transparent); }
.stat-success::after { background: linear-gradient(to right, transparent, var(--brand-success), transparent); }
.stat-danger::after { background: linear-gradient(to right, transparent, var(--brand-danger), transparent); }
.stat-warning::after { background: linear-gradient(to right, transparent, var(--brand-gold), transparent); }

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

.stat-primary .stat-icon { background: var(--brand-primary-light); color: var(--brand-primary); border-color: rgba(6, 95, 70, 0.2); }
.stat-success .stat-icon { background: var(--brand-success-light); color: var(--brand-success); border-color: rgba(5, 150, 105, 0.2); }
.stat-danger .stat-icon { background: var(--brand-danger-light); color: var(--brand-danger); border-color: rgba(185, 28, 28, 0.2); }
.stat-warning .stat-icon { background: var(--brand-gold-light); color: var(--brand-gold); border-color: rgba(217, 119, 6, 0.2); }

.stat-val { font-size: 1.85rem; font-weight: 900; margin-top: 0.25rem; letter-spacing: -0.5px; font-family: 'Cairo', sans-serif; }
.stat-lbl { font-size: 0.92rem; color: var(--text-muted); font-weight: 800; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.8rem 1.45rem;
  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, #065f46 0%, #047857 100%);
  color: white;
  box-shadow: 0 4px 14px rgba(6, 95, 70, 0.35);
  border-bottom: 2px solid rgba(217, 119, 6, 0.5);
}

.btn-primary:hover {
  transform: translateY(-2px);
  background: linear-gradient(135deg, #044e3a 0%, #065f46 100%);
  box-shadow: 0 6px 20px rgba(6, 95, 70, 0.45);
}

.btn-gold {
  background: linear-gradient(135deg, #d97706 0%, #f59e0b 100%);
  color: white;
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.35);
}

.btn-gold:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(217, 119, 6, 0.45);
}

.btn-turquoise {
  background: linear-gradient(135deg, #0f766e 0%, #0d9488 100%);
  color: white;
  box-shadow: 0 4px 14px rgba(15, 118, 110, 0.35);
}

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

.btn-danger {
  background: linear-gradient(135deg, #b91c1c 0%, #dc2626 100%);
  color: white;
  box-shadow: 0 4px 14px rgba(185, 28, 28, 0.3);
}

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

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

.btn-sm {
  padding: 0.48rem 0.95rem;
  font-size: 0.86rem;
  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.94rem; margin-bottom: 0.55rem; color: var(--text-main); }
.form-control, .form-select {
  width: 100%;
  padding: 0.85rem 1.15rem;
  font-size: 0.98rem;
  font-family: inherit;
  background-color: var(--bg-secondary);
  border: 1.5px 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(6, 95, 70, 0.18), 0 0 0 1px var(--brand-gold);
}

/* Tables */
.table-responsive { width: 100%; overflow-x: auto; border-radius: var(--radius-md); border: 1.5px solid var(--border-color); background: var(--bg-card); }
.table { width: 100%; border-collapse: collapse; text-align: right; font-size: 0.96rem; }
.table th { background: var(--bg-hover); padding: 1rem 1.15rem; font-weight: 900; color: var(--brand-primary); border-bottom: 1.5px solid var(--border-color); white-space: nowrap; font-family: 'Cairo', sans-serif; }
.table td { padding: 1rem 1.15rem; 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.35rem 0.85rem; border-radius: var(--radius-full); font-size: 0.82rem; font-weight: 800; border: 1px solid transparent; }
.badge-primary { background: var(--brand-primary-light); color: var(--brand-primary); border-color: rgba(6, 95, 70, 0.2); }
.badge-gold { background: var(--brand-gold-light); color: var(--brand-gold); border-color: var(--brand-gold); }
.badge-success { background: var(--brand-success-light); color: var(--brand-success); border-color: rgba(5, 150, 105, 0.2); }
.badge-danger { background: var(--brand-danger-light); color: var(--brand-danger); border-color: rgba(185, 28, 28, 0.2); }
.badge-warning { background: var(--brand-warning-light); color: var(--brand-warning); border-color: rgba(217, 119, 6, 0.2); }

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(7, 25, 19, 0.72); backdrop-filter: blur(8px); 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: 1.5px solid var(--border-gold); border-radius: var(--radius-lg);
  width: 100%; max-width: 560px; box-shadow: var(--shadow-xl), 0 0 32px rgba(6, 95, 70, 0.2); overflow: hidden; animation: slideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-header { padding: 1.35rem 1.6rem; border-bottom: 1.5px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; background: var(--bg-hover); }
.modal-title { font-size: 1.3rem; font-weight: 900; color: var(--brand-primary); font-family: 'Cairo', sans-serif; }
.modal-body { padding: 1.6rem; max-height: 80vh; overflow-y: auto; }
.modal-footer { padding: 1.1rem 1.6rem; background: var(--bg-hover); border-top: 1.5px 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: 700; }
.alert-info { background: var(--brand-primary-light); color: var(--brand-primary); border: 1px solid rgba(6, 95, 70, 0.25); }
.alert-success { background: var(--brand-success-light); color: var(--brand-success); border: 1px solid rgba(5, 150, 105, 0.25); }
.alert-danger { background: var(--brand-danger-light); color: var(--brand-danger); border: 1px solid rgba(185, 28, 28, 0.25); }
.alert-warning { background: var(--brand-gold-light); color: var(--brand-gold); border: 1px solid rgba(217, 119, 6, 0.3); }

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

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