/* ============================================================
   CAMP MANAGEMENT SYSTEM - مَخْيَمْ بَالْخَيْر نُحْيِيهَا
   Professional, High-Performance Arabic RTL Stylesheet
   ============================================================ */

:root {
  --primary: #059669;
  --primary-hover: #047857;
  --primary-light: #ecfdf5;
  --primary-dark: #064e3b;
  --secondary: #0284c7;
  --secondary-light: #f0f9ff;
  --accent: #d97706;
  --accent-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --warning: #ea580c;
  --warning-light: #fff7ed;
  --info: #2563eb;
  --info-light: #eff6ff;

  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --border-focus: #10b981;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

/* Base RTL setup */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Cairo', 'Tajawal', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  direction: rtl;
  text-align: right;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* Navigation & Header */
.main-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: 1300px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  flex-wrap: wrap;
}

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

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

.brand-info h1 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1.2;
}

.brand-info p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.25);
}

.btn-secondary {
  background-color: white;
  border-color: var(--border);
  color: var(--text-main);
}
.btn-secondary:hover {
  background-color: #f8fafc;
  border-color: #cbd5e1;
}

.btn-admin {
  background-color: #1e293b;
  color: white;
}
.btn-admin:hover {
  background-color: #0f172a;
}

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

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

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 1.05rem;
  border-radius: var(--radius-lg);
}

.btn-block {
  width: 100%;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-emerald { background: var(--primary-light); color: var(--primary-dark); }
.badge-blue { background: var(--secondary-light); color: var(--secondary); }
.badge-amber { background: var(--accent-light); color: #92400e; }
.badge-red { background: var(--danger-light); color: var(--danger); }
.badge-slate { background: #f1f5f9; color: #475569; }

/* Main Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
  flex: 1;
}

/* Announcements Bar */
.announcement-banner {
  background: linear-gradient(90deg, #ecfdf5, #eff6ff);
  border: 1px solid #a7f3d0;
  border-radius: var(--radius-md);
  padding: 14px 20px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}

.announcement-icon {
  font-size: 22px;
  color: var(--primary);
  flex-shrink: 0;
}

.announcement-content {
  flex: 1;
  font-size: 0.92rem;
  color: #065f46;
}

/* Views wrapper */
.view-section {
  display: none;
  animation: fadeIn 0.3s ease;
}
.view-section.active {
  display: block;
}

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

/* Cards & Layout */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  margin-bottom: 24px;
}

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

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Login Card Specific */
.login-hero {
  text-align: center;
  max-width: 650px;
  margin: 30px auto;
  padding: 40px 24px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}

.login-badge {
  display: inline-block;
  padding: 6px 16px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 700;
  border-radius: 9999px;
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.login-hero h2 {
  font-size: 1.8rem;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 10px;
}

.login-hero p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 28px;
}

.login-form-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: right;
  margin-bottom: 20px;
}

/* Form Controls */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 700;
  color: #334155;
  margin-bottom: 6px;
}

.form-label .required {
  color: var(--danger);
  margin-right: 4px;
}

.form-label .locked-badge {
  background: #f1f5f9;
  color: #64748b;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: normal;
  margin-right: 6px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.95rem;
  color: var(--text-main);
  background-color: #ffffff;
  border: 1.5px solid #cbd5e1;
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
  outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.form-input.input-locked {
  background-color: #f1f5f9;
  color: #64748b;
  cursor: not-allowed;
  border-color: #e2e8f0;
}

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.form-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Form Sections within Resident View */
.section-badge-header {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  border-right: 4px solid var(--primary);
  padding: 10px 14px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 16px;
}

.section-badge-header h4 {
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
}

/* Stats Grid in Admin */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 10px;
}

.stat-number {
  font-size: 1.6rem;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  background: white;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.search-box-wrapper {
  flex: 1;
  min-width: 250px;
  position: relative;
}

.search-input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border-radius: var(--radius-md);
  border: 1px solid #cbd5e1;
  font-size: 0.92rem;
  outline: none;
}
.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.search-clear-btn {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 16px;
}

.filter-pills {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.filter-pill {
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  background: #f1f5f9;
  color: #475569;
  border: 1px solid transparent;
  white-space: nowrap;
  transition: all 0.2s ease;
}
.filter-pill.active {
  background: var(--primary);
  color: white;
}
.filter-pill:hover:not(.active) {
  background: #e2e8f0;
}

/* Table responsive */
.table-wrapper {
  overflow-x: auto;
  background: #ffffff;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

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

.data-table th {
  background: #f8fafc;
  color: #475569;
  font-weight: 700;
  padding: 12px 14px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:hover {
  background-color: #f8fafc;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

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

.modal-card {
  background: white;
  border-radius: var(--radius-lg);
  max-width: 700px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: white;
  z-index: 10;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
}
.modal-close:hover {
  color: var(--danger);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: #f8fafc;
}

/* Digital Family Card (Modal Content) */
.digital-id-card {
  background: linear-gradient(135deg, #064e3b, #047857);
  color: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
  margin: 0 auto;
}

.digital-id-card::before {
  content: '';
  position: absolute;
  top: -50px;
  left: -50px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
}

.digital-id-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  padding-bottom: 14px;
  margin-bottom: 16px;
}

.digital-id-title h4 {
  font-size: 1.25rem;
  font-weight: 800;
}

.digital-id-title p {
  font-size: 0.85rem;
  opacity: 0.85;
}

.digital-id-qr-box {
  background: white;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.digital-id-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  font-size: 0.9rem;
}

.id-field-group {
  margin-bottom: 6px;
}

.id-field-label {
  font-size: 0.75rem;
  opacity: 0.75;
}

.id-field-val {
  font-size: 1.05rem;
  font-weight: 700;
}

/* Print Styles for Delivery Sheet */
@media print {
  body * {
    visibility: hidden;
  }
  #print-area, #print-area * {
    visibility: visible;
  }
  #print-area {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    margin: 0;
    padding: 10px;
    background: white;
  }
  .no-print {
    display: none !important;
  }
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: #1e293b;
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideUp 0.3s ease;
  min-width: 280px;
}
.toast.toast-success { background: #065f46; border-right: 5px solid #10b981; }
.toast.toast-error { background: #7f1d1d; border-right: 5px solid #ef4444; }
.toast.toast-info { background: #1e3a8a; border-right: 5px solid #3b82f6; }

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

/* Footer */
.main-footer {
  background: white;
  border-top: 1px solid var(--border);
  padding: 20px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: auto;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .header-container {
    flex-direction: column;
    align-items: stretch;
  }
  .header-actions {
    justify-content: space-between;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .digital-id-body {
    grid-template-columns: 1fr;
  }
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}
