:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #ccfbf1;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --off: #dc2626;
  --off-soft: #fee2e2;
  --neutral: #64748b;
  --neutral-soft: #e2e8f0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --font: "Segoe UI", Tahoma, "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 900;
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 18px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
  font-weight: 800;
  font-size: 17px;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav-link {
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 600;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--primary-soft); color: var(--primary-dark); }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.user-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
  font-weight: 700;
}
.user-chip small { color: var(--muted); font-weight: 500; }

.flash {
  max-width: 1180px;
  margin: 12px auto 0;
  padding: 10px 16px;
  background: var(--ok-soft);
  color: #166534;
  border: 1px solid #86efac;
  border-radius: var(--radius);
  font-weight: 600;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--neutral-soft); color: var(--text); }
.btn-danger { background: var(--off); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-xs { padding: 3px 9px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #0f766e 0%, #134e4a 60%, #0f172a 100%);
}
.login-wrap { width: 100%; max-width: 400px; padding: 20px; }
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 34px 30px;
  box-shadow: 0 24px 60px rgba(2, 6, 23, .35);
}
.login-logo { color: var(--primary); display: flex; justify-content: center; margin-bottom: 6px; }
.login-card h1 { margin: 0 0 2px; font-size: 22px; text-align: center; }
.login-sub { color: var(--muted); text-align: center; margin: 0 0 20px; }

/* ---------- Page head & stats ---------- */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-head h1 { margin: 2px 0 2px; font-size: 24px; }
.muted { color: var(--muted); }
.back-link { display: inline-block; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: var(--shadow);
}
.stat-num { font-size: 26px; font-weight: 800; color: var(--primary-dark); }
.stat-label { color: var(--muted); font-size: 13px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card-title { margin: 0 0 14px; font-size: 16px; font-weight: 800; color: var(--text); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2 .card { margin-bottom: 0; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Filter bar ---------- */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-bar .input { flex: 1; min-width: 200px; }

.input, select.input, textarea.input {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .15); }

/* ---------- Table ---------- */
.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; text-align: right; border-bottom: 1px solid var(--border); }
.table th { background: var(--surface-2); color: var(--muted); font-size: 13px; white-space: nowrap; }
.table tbody tr:hover { background: var(--surface-2); }
.cell-main { font-weight: 700; }
.empty { color: var(--muted); text-align: center; padding: 26px; }
.gps-link { direction: ltr; display: inline-block; font-variant-numeric: tabular-nums; }

.pager { display: flex; align-items: center; gap: 10px; justify-content: center; margin-top: 16px; }
.pager-info { color: var(--muted); font-size: 14px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-off { background: var(--off-soft); color: var(--off); }
.badge-neutral { background: var(--neutral-soft); color: var(--neutral); }

/* ---------- Info grid ---------- */
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 22px; }
@media (max-width: 720px) { .info-grid { grid-template-columns: 1fr; } }
.info-item { border-bottom: 1px dashed var(--border); padding-bottom: 8px; }
.info-item dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.info-item dd { margin: 2px 0 0; font-size: 14px; }

/* ---------- Maps ---------- */
.mini-map { height: 320px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.map-actions { display: flex; gap: 8px; margin-top: 10px; }
.fullmap-wrap { position: relative; height: calc(100vh - 58px); }
.full-map { position: absolute; inset: 0; }
.map-overlay {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 500;
  width: 300px;
  padding: 12px;
  margin: 0;
  box-shadow: 0 8px 24px rgba(2, 6, 23, .2);
}
.map-overlay .input { width: 100%; }
.map-stats { margin-top: 8px; font-size: 12px; color: var(--muted); }
@media (max-width: 640px) { .map-overlay { right: 8px; left: 8px; width: auto; } }

/* ---------- Photos ---------- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.photo-thumb {
  display: block;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0f172a;
  aspect-ratio: 4 / 3;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.admin-photo { position: relative; margin: 0; cursor: pointer; }
.admin-photo figcaption { padding: 6px 8px; font-size: 12px; word-break: break-all; background: var(--surface-2); }
.admin-photo form { padding: 0 8px 8px; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, .94);
  z-index: 1200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.lightbox.is-open { display: flex; }
.lightbox-figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
}
.lightbox-figure img {
  max-width: 100%;
  max-height: 82vh;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
.lightbox-cap {
  color: #cbd5e1;
  margin-top: 14px;
  font-size: 14px;
  word-break: break-all;
  text-align: center;
  max-width: 92vw;
}
.lightbox-close {
  position: absolute;
  top: 14px;
  right: 20px;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 50%;
  color: #e2e8f0;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  z-index: 2;
}
.lightbox-close:hover { background: rgba(255, 255, 255, .2); }
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 68px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 12px;
  color: #e2e8f0;
  font-size: 34px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-nav:hover { background: rgba(255, 255, 255, .2); }
.lightbox-nav:disabled { opacity: .25; cursor: default; }
.lb-prev { left: 14px; }
.lb-next { right: 14px; }
.lightbox-counter {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, .45);
  color: #e2e8f0;
  font-size: 13px;
  padding: 4px 14px;
  border-radius: 999px;
  white-space: nowrap;
  z-index: 2;
}
@media (max-width: 720px) {
  .lightbox-nav { width: 40px; height: 56px; font-size: 28px; }
  .lb-prev { left: 6px; }
  .lb-next { right: 6px; }
  .lightbox-close { top: 10px; right: 14px; width: 40px; height: 40px; }
  .lightbox-figure img { max-height: 74vh; }
}

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }
.form-grid .field.span-2 { grid-column: span 2; }
@media (max-width: 720px) { .form-grid .field.span-2 { grid-column: span 1; } }
.field { display: flex; flex-direction: column; gap: 4px; }
.field span { font-size: 13px; font-weight: 700; color: var(--muted); }
.field input, .field textarea, .field select {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .15);
}
.form-actions { margin-top: 16px; }
.edit-form h2.card-title { margin-top: 6px; }

/* ---------- Alerts ---------- */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-weight: 600; }
.alert-error { background: var(--off-soft); color: #b91c1c; border: 1px solid #fca5a5; }
.alert-ok { background: var(--ok-soft); color: #166534; border: 1px solid #86efac; }

/* ---------- Dashboard ---------- */
.mini-bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { width: 90px; font-size: 13px; font-weight: 600; }
.bar-track { flex: 1; background: var(--surface-2); border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--primary); height: 100%; border-radius: 999px; }
.bar-val { width: 60px; text-align: left; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.clean-list { list-style: none; margin: 0; padding: 0; }
.clean-list li { padding: 8px 0; border-bottom: 1px dashed var(--border); display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.clean-list li:last-child { border-bottom: none; }

/* ---------- Users ---------- */
.inline-details summary { cursor: pointer; color: var(--primary); font-size: 13px; font-weight: 700; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-top: 8px; }

.leaflet-container { font-family: var(--font); }
