/* ==========================================================================
   MG Business Platform - Complete Redesign Design System
   Colors: Primary (#117f9e), Accent (#c31254)
   Font: Tajawal
   ========================================================================== */

:root {
  /* Brand Colors */
  --primary: #117f9e;
  --primary-hover: #0e6b85;
  --primary-light: rgba(17, 127, 158, 0.1);
  --primary-gradient: linear-gradient(135deg, #117f9e 0%, #0c5b72 100%);
  
  --accent: #c31254;
  --accent-hover: #a10f45;
  --accent-light: rgba(195, 18, 84, 0.1);
  --accent-gradient: linear-gradient(135deg, #c31254 0%, #8f0d3e 100%);

  /* Sidebar Theme (Dark Primary) */
  --sidebar-bg: #0d4b5e; 
  --sidebar-hover: rgba(255, 255, 255, 0.08);
  --sidebar-active: rgba(255, 255, 255, 0.15);
  --sidebar-border: rgba(255, 255, 255, 0.05);

  /* Functional Colors */
  --success: #10b981;
  --success-light: #d1fae5;
  --success-dark: #047857;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --warning-dark: #b45309;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --danger-dark: #b91c1c;
  --info: #3b82f6;
  --info-light: #dbeafe;

  /* Neutrals & Surfaces - Dark Theme */
  --page-bg: #0b1121;
  --surface: #151e32;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #2a374a;
  --border-light: rgba(255, 255, 255, 0.05);

  /* Shadows - Dark Mode */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 15px rgba(17, 127, 158, 0.4);

  /* Border Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Transitions */
  --trans-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --trans-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --trans-bounce: 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* =========================================
   RESET & BASE
   ========================================= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html, body {
  font-family: 'Tajawal', sans-serif;
  background-color: var(--page-bg);
  color: var(--text-main);
  line-height: 1.6;
  font-size: 15px;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5, h6,
.page-title, .section-title, .brand-name, .modal-title, .auth-logo h1 {
  font-family: 'Cairo', sans-serif;
}
a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; border: none; outline: none; background: none; }
input, textarea, select { font-family: inherit; outline: none; }

/* Clickable cursors globally */
a, button, input[type="button"], input[type="submit"], input[type="reset"], input[type="checkbox"], input[type="radio"], select, .toggle-slider, .nav-item, .team-check-item, label, summary, .btn {
  cursor: pointer;
}

/* Text Utilities */
.text-primary { color: var(--primary); }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-muted { color: var(--text-muted); }

/* =========================================
   LAYOUT
   ========================================= */
.app-layout {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 260px;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, #082f3c 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; right: 0;
  z-index: 50;
  box-shadow: 4px 0 15px rgba(0,0,0,0.05);
}
.sidebar-logo-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-logo {
  flex-shrink: 0;
  height: 40px;
  width: auto;
  max-width: 140px;
  object-fit: contain;
}
.brand-name {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #fff;
}
.sidebar-nav {
  flex: 1;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  color: rgba(255,255,255,0.6);
  font-weight: 500;
  transition: var(--trans-normal);
  position: relative;
  overflow: hidden;
}
.nav-item i {
  font-size: 1.15rem;
  width: 24px;
  text-align: center;
  transition: var(--trans-bounce);
}
.nav-item:hover {
  color: #fff;
  background: var(--sidebar-hover);
}
.nav-item:hover i {
  transform: scale(1.1);
}
.nav-item.active {
  color: #fff;
  background: var(--sidebar-active);
  font-weight: 700;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  right: 0; top: 50%;
  transform: translateY(-50%);
  height: 60%;
  width: 4px;
  background: var(--accent);
  border-radius: 4px 0 0 4px;
  box-shadow: 0 0 10px var(--accent);
}
.nav-item.active i {
  color: var(--accent);
}
.nav-divider {
  height: 1px;
  background: var(--sidebar-border);
  margin: 12px 0;
}
.sidebar-footer {
  padding: 20px;
  border-top: 1px solid var(--sidebar-border);
}
.sidebar-user {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.6);
  margin-bottom: 12px;
  word-break: break-all;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-user::before {
  content: '';
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 5px var(--success);
}
.btn-logout {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.2);
  color: rgba(255,255,255,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: var(--trans-fast);
}
.btn-logout:hover {
  background: var(--danger);
  color: #fff;
}

.main-content {
  flex: 1;
  min-width: 0; /* Prevents flex horizontal blowout */
  margin-right: 260px;
  padding: 32px 40px;
  max-width: 1400px;
}

/* Header */
.page-header {
  margin-bottom: 24px;
}
.page-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}
.page-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* =========================================
   COMPONENTS
   ========================================= */

/* Stat Cards */
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  border-top: 3px solid transparent; /* controlled via inline styles or classes later */
  transition: var(--trans-bounce);
  position: relative;
  overflow: hidden;
}
.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}
/* Subtle gradient background on hover */
.stat-card::after {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0) 0%, rgba(17, 127, 158, 0.03) 100%);
  opacity: 0;
  transition: var(--trans-normal);
  pointer-events: none;
}
.stat-card:hover::after { opacity: 1; }

.stat-label {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 8px;
}
.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}
.stat-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

/* Cards & Panels */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  padding: 20px;
  margin-bottom: 20px;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-title i {
  color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.9rem;
  transition: var(--trans-fast);
  justify-content: center;
}
.btn-primary {
  background: var(--primary-gradient);
  color: #fff;
  box-shadow: 0 4px 10px var(--primary-light);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(17, 127, 158, 0.3);
}
.btn-primary:active {
  transform: translateY(0);
}
.btn-accent {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 10px var(--accent-light);
}
.btn-accent:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(195, 18, 84, 0.3);
}
.btn-outline {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-main);
}
.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}
.btn-danger {
  background: var(--danger-light);
  color: var(--danger-dark);
}
.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: var(--border-light);
  color: var(--text-muted);
}
.btn-icon:hover {
  background: var(--primary-light);
  color: var(--primary);
}
.btn-cancel {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-main);
}
.btn-cancel:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-light);
}
.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.badge-new { background: var(--info-light); color: var(--info); }
.badge-progress { background: var(--warning-light); color: var(--warning-dark); }
.badge-done { background: var(--success-light); color: var(--success-dark); }
.badge-active { background: var(--success-light); color: var(--success-dark); }
.badge-expired { background: var(--danger-light); color: var(--danger-dark); }
.badge-manager { background: var(--primary-light); color: var(--primary); }
.badge-admin { background: var(--accent-light); color: var(--accent); }
.badge-readonly { background: var(--border-light); color: var(--text-muted); }

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
}
table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  min-width: 800px;
}
thead th {
  background: #0f172a;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 14px 20px;
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: var(--trans-fast);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}
td {
  padding: 16px 20px;
  font-size: 0.9rem;
  color: var(--text-main);
  vertical-align: middle;
}
.amount-paid { color: var(--success-dark); font-weight: 700; }
.amount-remain { color: var(--warning-dark); font-weight: 700; }
.amount-zero { color: var(--text-muted); }

/* Forms & Inputs */
.form-group {
  margin-bottom: 20px;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 8px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  color: var(--text-main);
  background: var(--surface);
  transition: var(--trans-fast);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-light);
}
.form-textarea {
  min-height: 100px;
  resize: vertical;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: var(--trans-normal);
}
.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px) scale(0.95);
  transition: var(--trans-bounce);
}
.modal-overlay.open .modal-box {
  transform: translateY(0) scale(1);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px;
  border-bottom: 1px solid var(--border-light);
}
.modal-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--primary);
}
.modal-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--border-light);
  color: var(--text-muted);
  transition: var(--trans-fast);
}
.modal-close:hover {
  background: var(--danger-light);
  color: var(--danger);
  transform: rotate(90deg);
}
#projectForm, #memberForm, #subForm, #userForm {
  padding: 24px;
  overflow-y: auto;
}

/* Empty States */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state i {
  font-size: 3rem;
  color: var(--border);
  margin-bottom: 16px;
  opacity: 0.5;
}
.empty-state p {
  font-size: 1rem;
  font-weight: 500;
}

/* Toolbar (Search & Filter) */
.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.search-wrap {
  flex: 1;
  min-width: 250px;
  position: relative;
}
.search-icon {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}
.search-wrap input {
  width: 100%;
  padding: 12px 14px 12px 40px; /* Arabic padding adjust */
  padding-right: 40px;
  padding-left: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--page-bg);
  transition: var(--trans-fast);
}
.search-wrap input:focus {
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-light);
}
.filter-select {
  width: auto;
  min-width: 150px;
  background: var(--page-bg);
}

/* Toggle Switch */
.toggle-wrap {
  display: flex; align-items: center; gap: 12px;
}
.toggle {
  position: relative;
  display: inline-block;
  width: 44px; height: 24px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--border);
  transition: .4s;
  border-radius: 24px;
}
.toggle-slider:before {
  position: absolute; content: "";
  height: 18px; width: 18px;
  left: 3px; bottom: 3px;
  background-color: var(--text-main);
  transition: .4s;
  border-radius: 50%;
}
input:checked + .toggle-slider { background-color: var(--primary); }
input:checked + .toggle-slider:before { transform: translateX(20px); }
.toggle-label { font-size: 0.9rem; font-weight: 600; }

/* Custom Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--page-bg); }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Team Check List (Modal) */
.team-check-list {
  display: flex; flex-direction: column; gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  background: var(--page-bg);
}
.team-check-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px; border-radius: 4px; cursor: pointer;
}
.team-check-item:hover { background: var(--border); }

/* Auth Page Specifics */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--sidebar-bg) 0%, #03141a 100%);
  position: relative;
  overflow: hidden;
}
/* Subtle background shapes for auth */
.auth-page::before, .auth-page::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  z-index: 1;
}
.auth-page::before {
  top: -100px; right: -100px;
  width: 400px; height: 400px;
  background: rgba(17, 127, 158, 0.4);
}
.auth-page::after {
  bottom: -100px; left: -100px;
  width: 300px; height: 300px;
  background: rgba(195, 18, 84, 0.3);
}

.auth-card {
  background: rgba(21, 30, 50, 0.85); /* Dark surface */
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 40px;
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255,255,255,0.08);
  z-index: 2;
  animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.auth-logo { margin-bottom: 30px; text-align: center; }
.auth-logo img {
  height: 60px;
  width: auto;
  max-width: 180px;
  object-fit: contain;
  margin-bottom: 16px;
}
.auth-logo h1 { font-size: 1.6rem; color: var(--text-main); font-weight: 800; margin-bottom: 4px; }
.auth-logo p { color: var(--text-muted); font-size: 0.95rem; }

.auth-error {
  background: var(--danger-light); color: var(--danger-dark);
  padding: 12px; border-radius: var(--radius-md); font-size: 0.85rem; font-weight: 600;
  display: flex; align-items: center; gap: 8px; margin-bottom: 20px;
  display: none;
}
.auth-error.show { display: flex; animation: slideUp 0.3s; }

/* Responsive adjustments */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(100%); transition: var(--trans-normal); }
  .sidebar.open { transform: translateX(0); box-shadow: -4px 0 25px rgba(0,0,0,0.5); }
  .main-content { margin-right: 0; padding: 20px; padding-top: 75px; }
  
  .mobile-menu-btn {
    display: flex; position: fixed; top: 15px; right: 15px; z-index: 40;
    width: 44px; height: 44px; border-radius: var(--radius-md);
    background: var(--surface); color: var(--primary);
    box-shadow: var(--shadow-sm); align-items: center; justify-content: center;
    border: 1px solid var(--border);
  }
  .sidebar-close-btn {
    display: flex; position: absolute; top: 15px; left: 15px; z-index: 60;
    width: 40px; height: 40px; border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.1); color: #fff;
    align-items: center; justify-content: center; border: none;
  }
}

@media (max-width: 768px) {
  /* Stack elements gracefully */
  .mobile-stack {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 15px !important;
  }
  .mobile-stack > button, .mobile-stack > .btn {
    width: 100%;
    justify-content: center;
  }
  
  .search-wrap, .toolbar select {
    width: 100% !important;
    max-width: 100% !important;
  }
  
  /* Form layout & Global Grid override */
  .form-row, .grid, [style*="display:grid"], [style*="display: grid"] {
    grid-template-columns: 1fr !important;
  }
  .stat-card, .card {
    padding: 15px !important;
  }
  
  /* Table optimization */
  table th, table td {
    white-space: nowrap !important;
    padding: 12px 15px !important;
  }
  .table-wrap {
    border-radius: var(--radius-md) !important;
    -webkit-overflow-scrolling: touch;
    width: 100%; max-width: 100vw;
  }
}
@media (min-width: 1025px) {
  .mobile-menu-btn, .sidebar-close-btn { display: none !important; }
}