/* ============================================
   Camera Project Tracker - Main Stylesheet
   Arabic RTL Layout — Modern Redesign
   ============================================ */

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

:root {
  /* === Core Palette === */
  --primary:        #0f2f5e;
  --primary-mid:    #1a4a8a;
  --primary-light:  #2563eb;
  --primary-glow:   rgba(37, 99, 235, 0.18);
  --accent:         #0ea5e9;
  --accent-soft:    rgba(14, 165, 233, 0.12);

  --success:        #10b981;
  --success-light:  #d1fae5;
  --success-text:   #065f46;
  --warning:        #f59e0b;
  --warning-light:  #fef3c7;
  --warning-text:   #92400e;
  --danger:         #ef4444;
  --danger-light:   #fee2e2;
  --danger-text:    #991b1b;

  /* === Surfaces === */
  --bg:             #f1f5fb;
  --bg-pattern:     radial-gradient(circle at 20% 20%, rgba(37,99,235,.06) 0%, transparent 55%),
                    radial-gradient(circle at 80% 80%, rgba(14,165,233,.05) 0%, transparent 55%);
  --card-bg:        #ffffff;
  --card-glass:     rgba(255,255,255,0.75);
  --surface-2:      #f8fafd;

  /* === Text === */
  --text:           #0f172a;
  --text-muted:     #64748b;
  --text-light:     #94a3b8;

  /* === Borders & Shadows === */
  --border:         #e2e8f0;
  --border-focus:   #2563eb;
  --border-radius:  14px;
  --radius-sm:      8px;
  --radius-lg:      20px;
  --radius-full:    9999px;

  --shadow-xs:  0 1px 2px rgba(15,23,42,.06);
  --shadow-sm:  0 2px 8px rgba(15,23,42,.07), 0 1px 2px rgba(15,23,42,.04);
  --shadow:     0 4px 16px rgba(15,23,42,.09), 0 2px 4px rgba(15,23,42,.05);
  --shadow-lg:  0 12px 32px rgba(15,23,42,.13), 0 4px 8px rgba(15,23,42,.06);
  --shadow-xl:  0 20px 50px rgba(15,23,42,.17);

  /* === Motion === */
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);

  /* === Layout === */
  --navbar-h: 68px;
  --page-max: 1240px;
  --page-pad: clamp(16px, 4vw, 32px);
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Cairo', sans-serif;
  background: var(--bg);
  background-image: var(--bg-pattern);
  color: var(--text);
  direction: rtl;
  line-height: 1.65;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   NAVBAR
   ============================================ */
.navbar {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-mid) 100%);
  color: #fff;
  height: var(--navbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--page-pad);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(15,23,42,.20);
  backdrop-filter: blur(10px);
}

/* subtle animated bottom border */
.navbar::after {
  content: '';
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), var(--primary-light), transparent);
  opacity: 0.7;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.navbar-brand .nav-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--primary-light) 100%);
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  box-shadow: 0 4px 12px rgba(14,165,233,.40);
  flex-shrink: 0;
}

.navbar-menu {
  display: flex;
  gap: 6px;
  align-items: center;
}

.nav-link {
  color: rgba(255,255,255,0.88);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.nav-link:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}
.nav-add {
  background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(16,185,129,.35);
}
.nav-add:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(16,185,129,.45);
  background: linear-gradient(135deg, #059669 0%, var(--success) 100%);
}
.nav-logout {
  background: rgba(239,68,68,.15);
  color: rgba(255,255,255,.9);
  border: 1px solid rgba(239,68,68,.30);
}
.nav-logout:hover {
  background: rgba(239,68,68,.30);
}

/* ============================================
   PAGE CONTAINER
   ============================================ */
.page-container {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 28px var(--page-pad);
  width: 100%;
  flex: 1;
}

/* ============================================
   PAGE HEADER (optional section title)
   ============================================ */
.page-header {
  margin-bottom: 28px;
}
.page-title {
  font-size: clamp(1.4rem, 3vw, 1.9rem);
  font-weight: 900;
  color: var(--primary);
  letter-spacing: -0.02em;
}
.page-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ============================================
   STATS GRID
   ============================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card-bg);
  padding: 22px 20px;
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  border-right: 4px solid var(--primary-light);
  transition: var(--transition-spring);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  inset-inline-end: -20px;
  top: -20px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--primary-glow);
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-right-color: var(--accent);
}
.stat-card:hover::before { transform: scale(2); }

.stat-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary-glow), var(--accent-soft));
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.stat-info { min-width: 0; }
.stat-number {
  font-size: 1.9rem;
  font-weight: 900;
  color: var(--primary);
  display: block;
  line-height: 1;
  letter-spacing: -0.03em;
}
.stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 3px;
  font-weight: 500;
}

/* ============================================
   TOOLBAR
   ============================================ */
.toolbar {
  background: var(--card-bg);
  padding: 16px 20px;
  border-radius: var(--border-radius);
  margin-bottom: 22px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}

.search-form {
  flex: 1;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.search-input {
  flex: 1;
  min-width: 180px;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Cairo', sans-serif;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface-2);
  transition: var(--transition);
  direction: rtl;
}
.search-input:focus {
  outline: none;
  border-color: var(--border-focus);
  background: #fff;
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.search-input::placeholder { color: var(--text-light); }

/* ============================================
   BRANCHES LIST
   ============================================ */
.branches-list {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.branch-item {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  border-right: 5px solid var(--primary-light);
  overflow: hidden;
  transition: var(--transition-spring);
}
.branch-item:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.branch-header {
  padding: 16px 20px;
  background: linear-gradient(to left, #f8fafd, #f1f5fb);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.branch-name {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.01em;
}

.branch-info-badges {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.badge {
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.branch-content {
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 24px;
}

/* ============================================
   CAMERA GRID
   ============================================ */
.cam-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ip-tag {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-family: 'IBM Plex Mono', monospace;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: var(--transition);
}
.ip-tag:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.ip-broken {
  background: var(--danger-light) !important;
  border-color: #fca5a5 !important;
  color: var(--danger-text) !important;
}
.ip-broken:hover {
  background: #fecaca !important;
}

.btn-issue {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 3px;
  opacity: 0.7;
  transition: var(--transition);
  line-height: 1;
  border-radius: 4px;
}
.btn-issue:hover { opacity: 1; transform: scale(1.2); }

/* ============================================
   MODALS
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.65);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

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

.modal-content {
  background: var(--card-bg);
  width: 100%;
  max-width: 520px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border);
  animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(to left, #f8fafd, var(--card-bg));
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--surface-2);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  transition: var(--transition);
  color: var(--text-muted);
}
.modal-close:hover {
  background: var(--danger-light);
  color: var(--danger);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  font-family: 'Cairo', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition-spring);
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(37,99,235,.30);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37,99,235,.40);
}

.btn-danger {
  background: linear-gradient(135deg, #f87171 0%, var(--danger) 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(239,68,68,.25);
}
.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(239,68,68,.35);
}

.btn-success {
  background: linear-gradient(135deg, #34d399 0%, var(--success) 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(16,185,129,.30);
}
.btn-success:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(16,185,129,.40);
}

.btn-edit {
  background: var(--surface-2);
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-edit:hover {
  background: #e9eef6;
  border-color: #c9d6e8;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-sm { padding: 7px 14px; font-size: 0.82rem; border-radius: 6px; }
.btn-lg { padding: 13px 28px; font-size: 1rem; }

/* ============================================
   FORM ELEMENTS
   ============================================ */
.form-group { margin-bottom: 18px; }

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

.form-input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Cairo', sans-serif;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface-2);
  transition: var(--transition);
  direction: rtl;
}
.form-input:focus {
  outline: none;
  border-color: var(--border-focus);
  background: #fff;
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.form-input::placeholder { color: var(--text-light); }

select.form-input { cursor: pointer; }

/* ============================================
   STATUS / BADGE UTILITIES
   ============================================ */
.status-mktml    { border-right-color: var(--success) !important; }
.status-tanfiz   { border-right-color: var(--warning) !important; }
.status-mutawaqif { border-right-color: var(--danger) !important; }

.badge-mktml    { background: var(--success-light); color: var(--success-text); }
.badge-tanfiz   { background: var(--warning-light); color: var(--warning-text); }
.badge-mutawaqif { background: var(--danger-light);  color: var(--danger-text);  }

/* ============================================
   ALERTS
   ============================================ */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1.5px solid transparent;
}
.alert-error {
  background: var(--danger-light);
  color: var(--danger-text);
  border-color: #fca5a5;
}
.alert-success {
  background: var(--success-light);
  color: var(--success-text);
  border-color: #6ee7b7;
}
.alert-warning {
  background: var(--warning-light);
  color: var(--warning-text);
  border-color: #fcd34d;
}

/* ============================================
   EMPTY STATE
   ============================================ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; opacity: 0.5; }
.empty-state-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; color: var(--text); }
.empty-state-desc  { font-size: 0.88rem; }

/* ============================================
   DIVIDER
   ============================================ */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ============================================
   SCROLLBAR (WebKit)
   ============================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ============================================
   RESPONSIVE — TABLET ≤ 900px
   ============================================ */
@media (max-width: 900px) {
  .branch-content {
    grid-template-columns: 1fr;
    gap: 18px;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================
   RESPONSIVE — MOBILE ≤ 640px
   ============================================ */
@media (max-width: 640px) {
  :root { --navbar-h: 60px; }

  .navbar-brand span:not(.nav-icon) { display: none; }

  .nav-link span:not(.nav-icon) { display: none; }
  .nav-link { padding: 8px 10px; }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .stat-card { padding: 16px 14px; }
  .stat-number { font-size: 1.55rem; }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    padding: 14px;
  }
  .search-form { flex-direction: column; }
  .search-input { min-width: unset; }

  .branch-header { padding: 13px 15px; }
  .branch-name   { font-size: 1rem; }
  .branch-content { padding: 15px; }

  .modal-content { border-radius: var(--border-radius); }
  .modal-body    { padding: 18px; }

  .btn { padding: 9px 16px; font-size: 0.85rem; }
}

/* ============================================
   RESPONSIVE — SMALL MOBILE ≤ 380px
   ============================================ */
@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card  { flex-direction: row; }
}

/* ============================================
   PRINT
   ============================================ */
@media print {
  .navbar, .toolbar, .modal-overlay, .btn-issue { display: none !important; }
  .branch-item { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  body { background: #fff; }
}
