* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #1a237e;
  --primary-light: #3949ab;
  --primary-dark: #0d1642;
  --accent: #ff6f00;
  --accent-light: #ffa040;
  --success: #2e7d32;
  --danger: #c62828;
  --warning: #f57f17;
  --bg: #f5f5f5;
  --card: #ffffff;
  --text: #212121;
  --text-secondary: #757575;
  --border: #e0e0e0;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --radius: 12px;
  --gender-women: #e91e63;
  --gender-dawa: #4caf50;
  --gender-communities: #9c27b0;
}

body {
  font-family: 'Tajawal', sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
  padding-bottom: 80px;
  -webkit-user-select: none;
  user-select: none;
  overflow-x: hidden;
}

.app-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  padding: 16px 20px;
  padding-top: max(env(safe-area-inset-top), 16px);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(26,35,126,0.3);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
}

.header-subtitle {
  font-size: 12px;
  opacity: 0.8;
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.header-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.header-btn:active {
  background: rgba(255,255,255,0.3);
}

.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 16px 20px 8px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--primary);
}

.stat-card.accent { border-top-color: var(--accent); }
.stat-card.success { border-top-color: var(--success); }

.stat-number {
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
}

.stat-card.accent .stat-number { color: var(--accent); }
.stat-card.success .stat-number { color: var(--success); }

.stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.search-container {
  padding: 12px 20px;
}

.search-box {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-family: 'Tajawal', sans-serif;
  font-size: 14px;
  background: var(--card);
  transition: border-color 0.2s;
  outline: none;
}

.search-input:focus {
  border-color: var(--primary);
}

.filter-btn {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 18px;
  cursor: pointer;
}

.filter-chips {
  display: flex;
  gap: 8px;
  padding: 0 20px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.filter-chips::-webkit-scrollbar { display: none; }

.chip {
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  border: 1.5px solid var(--border);
  background: var(--card);
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Tajawal', sans-serif;
}

.chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.section-title {
  padding: 8px 20px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.program-list {
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.program-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s;
}

.program-card:active {
  transform: scale(0.98);
}

.program-card-header {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid var(--border);
}

.program-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  margin-left: 8px;
}

.program-badge {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-women {
  background: #fce4ec;
  color: var(--gender-women);
}

.badge-dawa {
  background: #e8f5e9;
  color: var(--gender-dawa);
}

.badge-communities {
  background: #f3e5f5;
  color: var(--gender-communities);
}

.program-card-body {
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.program-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.program-info-icon {
  font-size: 14px;
  width: 20px;
  text-align: center;
}

.program-card-footer {
  padding: 10px 16px;
  background: #fafafa;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.program-budget {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
}

.program-target {
  font-size: 12px;
  color: var(--text-secondary);
}

.share-btn {
  background: var(--primary);
  color: white;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.share-btn:active {
  background: var(--primary-dark);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  padding-bottom: max(env(safe-area-inset-bottom), 8px);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.1);
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 12px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: 'Tajawal', sans-serif;
  color: var(--text-secondary);
  transition: color 0.2s;
}

.nav-item.active {
  color: var(--primary);
}

.nav-item-icon {
  font-size: 22px;
}

.nav-item-label {
  font-size: 11px;
  font-weight: 500;
}

.fab {
  position: fixed;
  bottom: 80px;
  left: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 28px;
  box-shadow: 0 4px 16px rgba(255,111,0,0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99;
  transition: transform 0.2s;
}

.fab:active {
  transform: scale(0.9);
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

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

.modal {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s;
  padding-bottom: max(env(safe-area-inset-bottom), 16px);
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto;
}

.modal-header {
  padding: 8px 20px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body {
  padding: 20px;
}

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-family: 'Tajawal', sans-serif;
  font-size: 14px;
  background: var(--bg);
  outline: none;
  transition: border-color 0.2s;
  direction: rtl;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--primary);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn {
  padding: 12px 24px;
  border-radius: 10px;
  font-family: 'Tajawal', sans-serif;
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity 0.2s;
  width: 100%;
}

.btn:active { opacity: 0.8; }

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-accent {
  background: var(--accent);
  color: white;
}

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

.detail-page {
  display: none;
}

.detail-page.active {
  display: block;
}

.home-page.hidden {
  display: none;
}

.detail-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  padding: 20px;
  padding-top: max(env(safe-area-inset-top), 20px);
  text-align: center;
}

.detail-back {
  position: absolute;
  right: 16px;
  top: max(env(safe-area-inset-top), 16px);
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.detail-name {
  font-size: 20px;
  font-weight: 800;
  margin-top: 8px;
}

.detail-section {
  background: var(--card);
  margin: 12px 16px;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.detail-section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-row-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.detail-row-value {
  font-size: 13px;
  font-weight: 600;
}

.detail-actions {
  padding: 16px;
  display: flex;
  gap: 12px;
}

.detail-actions .btn {
  flex: 1;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 12px;
}

.empty-text {
  font-size: 16px;
  font-weight: 500;
}

.empty-sub {
  font-size: 13px;
  margin-top: 4px;
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #323232;
  color: white;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 300;
  transition: transform 0.3s;
  white-space: nowrap;
  font-family: 'Tajawal', sans-serif;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.needs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 8px;
}

.needs-table th {
  background: var(--primary);
  color: white;
  padding: 8px 6px;
  font-weight: 600;
  font-size: 11px;
}

.needs-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.needs-table tr:nth-child(even) {
  background: #fafafa;
}

@media (min-width: 500px) {
  body {
    max-width: 500px;
    margin: 0 auto;
    box-shadow: -1px 0 0 var(--border), 1px 0 0 var(--border);
  }
  .bottom-nav {
    max-width: 500px;
    left: 50%;
    transform: translateX(-50%);
  }
  .fab {
    left: calc(50% - 230px);
  }
}