:root {
  --bg: #f4f6fa;
  --bg-accent: #e8eef8;
  --surface: #ffffff;
  --ink: #0a1a33;
  --muted: #5a6a80;
  --primary: #0a2248;
  --primary-2: #123a73;
  --accent: #f18a1f;
  --accent-soft: #ffb65c;
  --danger: #9b2c2c;
  --ok: #1f6b45;
  --border: #d5dde8;
  --shadow: 0 10px 30px rgba(10, 34, 72, 0.1);
  --radius: 14px;
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --touch: 48px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1000px 420px at 100% -10%, rgba(241, 138, 31, 0.12) 0%, transparent 55%),
    radial-gradient(900px 400px at 0% 0%, rgba(18, 58, 115, 0.1) 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.6;
}
body.page-login {
  background:
    linear-gradient(165deg, #050d1c 0%, #0a2248 48%, #123a73 100%);
}

a { color: var(--primary-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(10px);
  background: linear-gradient(180deg, #071833 0%, #0a2248 100%);
  color: #fff;
  border-bottom: 3px solid var(--accent);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.45rem 0.85rem;
  display: flex;
  gap: 0.6rem;
  align-items: center;
  justify-content: space-between;
  position: relative;
  flex-wrap: nowrap;
}
.brand {
  display: flex;
  align-items: center;
  color: #fff;
  text-decoration: none !important;
  flex: 0 0 auto;
}
.brand-logo {
  height: 36px;
  width: auto;
  max-width: 170px;
  object-fit: contain;
  display: block;
}
.brand-text { display: none; }

.nav-toggle {
  display: none;
  width: var(--touch);
  height: var(--touch);
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 12px;
  background: rgba(255,255,255,0.08);
  padding: 0;
  cursor: pointer;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: transform .2s, opacity .2s;
}
.topbar.is-open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.topbar.is-open .nav-toggle span:nth-child(2) { opacity: 0; }
.topbar.is-open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.nav {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.3rem;
  align-items: center;
  min-width: 0;
}
.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0.3rem 0.62rem;
  border-radius: 999px;
  color: #e8f2ec !important;
  text-decoration: none !important;
  font-size: 0.84rem;
  font-weight: 600;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.06);
  white-space: nowrap;
}
.nav-link:hover,
.nav-link.is-active {
  background: rgba(241, 138, 31, 0.2);
  border-color: rgba(241, 138, 31, 0.65);
  color: #fff !important;
}
.nav-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-inline-start: 0.25rem;
  flex: 0 0 auto;
}
.nav-user {
  opacity: 0.9;
  font-size: 0.78rem;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-nav-out {
  background: var(--accent);
  color: #1a1005 !important;
  border: none;
  min-height: 34px;
  padding: 0.3rem 0.7rem;
  border-radius: 10px;
  font-weight: 700;
  text-decoration: none !important;
  font-size: 0.84rem;
  white-space: nowrap;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.15rem 1rem 3rem;
}

.page-head-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-head-row .btn { flex: 0 0 auto; }
.page-head h1, .section h2, .auth-panel h1, .form-panel h2 {
  margin: 0 0 0.35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.page-head p, .muted, .hint, .result-count { color: var(--muted); }
.hint { font-size: 0.9rem; margin-top: 0.75rem; }
.result-count { margin: 0.25rem 0 1rem; }

.form-panel, .auth-panel, .stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.form-panel { padding: 1.1rem; margin: 1rem 0 1.5rem; }
.auth-wrap {
  min-height: calc(100vh - 160px);
  display: grid;
  place-items: center;
  padding: 1rem 0 2rem;
}
.auth-panel {
  width: min(440px, 100%);
  padding: 1.35rem 1.35rem 1.5rem;
}
.auth-brand {
  text-align: center;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.auth-logo {
  width: 132px;
  height: auto;
  display: block;
  margin: 0 auto 0.65rem;
  filter: drop-shadow(0 8px 18px rgba(10, 34, 72, 0.18));
}
.auth-party {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
}
.auth-sub {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.auth-year {
  margin: 0.35rem 0 0;
  display: inline-block;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  background: rgba(241, 138, 31, 0.14);
  color: #9a5208;
  font-size: 0.82rem;
  font-weight: 700;
}
.auth-title {
  text-align: center;
  font-size: 1.15rem;
  margin: 0 0 0.9rem !important;
}
.btn-wide { width: 100%; }
.stack { display: grid; gap: 0.9rem; }
.page-login .topbar {
  background: rgba(5, 13, 28, 0.72);
  border-bottom-color: var(--accent);
}
.page-login .container {
  max-width: 520px;
}
.page-login .site-footer {
  color: rgba(255,255,255,0.72);
}
.page-login .footer-brand strong { color: #fff; }
.page-login .footer-brand span { color: rgba(255,255,255,0.7); }

label { display: grid; gap: 0.35rem; font-weight: 500; }
label span { font-size: 0.92rem; }
input, select, button, textarea { font: inherit; }
input[type="text"], input[type="password"], input[type="tel"], input[type="search"], input[type="file"], select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
  background: #fff;
  color: var(--ink);
  min-height: var(--touch);
}
input:focus, select:focus {
  outline: 2px solid rgba(26, 107, 79, 0.35);
  border-color: var(--primary-2);
}

.field-grid {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 1rem;
}

fieldset {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin: 0;
}
fieldset:disabled { opacity: 0.55; }
legend { padding: 0 0.4rem; font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.7rem 1.05rem;
  min-height: var(--touch);
  cursor: pointer;
  font-weight: 700;
  text-decoration: none !important;
}
.btn-primary {
  background: linear-gradient(180deg, var(--primary-2), var(--primary));
  color: #fff;
  box-shadow: 0 6px 16px rgba(10, 34, 72, 0.22);
}
.btn-ghost {
  background: transparent;
  border-color: rgba(255,255,255,0.35);
  color: #fff;
}
.btn-ghost-dark {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--ink);
}
.btn-danger { background: var(--danger); color: #fff; }
.btn-small {
  padding: 0.45rem 0.75rem;
  font-size: 0.88rem;
  min-height: 40px;
}
.btn-row, .filter-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}

.alert {
  border-radius: 12px;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid;
}
.alert-success { background: #e8f6ee; border-color: #b7dfc6; color: var(--ok); }
.alert-error { background: #fdecec; border-color: #f0b4b4; color: var(--danger); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.85rem;
  margin: 1rem 0 1.5rem;
}
.stat { padding: 1rem; display: grid; gap: 0.2rem; }
.stat strong { font-size: 1.45rem; }
.stat span { color: var(--muted); font-size: 0.9rem; }
.stat em { font-style: normal; color: var(--primary-2); font-weight: 600; }

.section { margin-top: 1.5rem; }
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
}
table, .data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}
th, td {
  padding: 0.75rem 0.8rem;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: middle;
}
th {
  background: var(--bg-accent);
  font-size: 0.9rem;
  white-space: nowrap;
}
tr:last-child td { border-bottom: 0; }
.row-ok td:nth-child(3) { color: var(--ok); font-weight: 600; }
.row-empty td:nth-child(3) { color: var(--danger); }
.row-partial td:nth-child(3) { color: #9a6b12; }

.bar {
  display: inline-block;
  width: 90px;
  height: 8px;
  background: #e5ece8;
  border-radius: 999px;
  overflow: hidden;
  margin-left: 0.4rem;
  vertical-align: middle;
}
.bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary-2), var(--accent));
}

.filters, .filters-cascade {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  align-items: end;
  margin: 1rem 0 0.75rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.filters label, .filters-cascade label { min-width: 0; }
.filter-search { grid-column: span 1; }
.filter-actions {
  grid-column: 1 / -1;
}
.filter-actions .btn { flex: 1 1 140px; }

.office-status {
  margin: 0.5rem 0 1rem;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  background: #eef5f1;
  border: 1px solid var(--border);
}
.office-status.warn { background: #fff6e8; border-color: #f0d3a0; }
.office-status.locked { background: #fdecec; border-color: #f0b4b4; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.actions form { display: inline-flex; gap: 0.3rem; align-items: center; margin: 0; }
.inline-reset input { width: 120px; padding: 0.35rem 0.5rem; min-height: 40px; }

.thumb-pair {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  width: 86px;
  text-decoration: none !important;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}
.thumb img {
  width: 80px;
  height: 54px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #edf2ef;
  display: block;
}
.thumb-empty {
  width: 80px;
  height: 54px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: #f7faf8;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.72rem;
}
.thumb-empty span { line-height: 1.2; text-align: center; padding: 0.2rem; }

.existing-images { margin-bottom: 0.8rem; display: flex; gap: 0.75rem; flex-wrap: wrap; }
.existing-images a { font-weight: 600; }
.existing-images .thumb img { width: 120px; height: 80px; }

.card-list { display: none; gap: 0.85rem; }
.person-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.95rem;
  display: grid;
  gap: 0.55rem;
}
.person-card header {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
  flex-wrap: wrap;
}
.person-card .meta { margin: 0; color: var(--muted); font-size: 0.9rem; }
.person-card .thumb { width: auto; flex: 1; }
.person-card .thumb img { width: 100%; height: 88px; }
.person-card .thumb-empty { width: 100%; height: 88px; }
.person-card .actions .btn { flex: 1; }

.mobile-only { display: none; }
.desk-only { display: block; }

.site-footer {
  color: var(--muted);
  padding: 1.25rem 1rem 1.5rem;
  font-size: 0.85rem;
}
.footer-brand {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: center;
  text-align: right;
}
.footer-brand img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex: 0 0 auto;
}
.footer-brand div {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  line-height: 1.35;
}
.footer-brand strong {
  color: var(--primary);
  font-size: 0.92rem;
}
.footer-brand span {
  font-size: 0.8rem;
}

@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; }
  .nav {
    display: none;
    position: absolute;
    top: calc(100% + 3px);
    right: 0;
    left: 0;
    margin: 0 0.75rem;
    padding: 0.75rem;
    background: #071833;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 14px;
    box-shadow: var(--shadow);
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }
  .topbar.is-open .nav { display: flex; }
  .nav-toggle {
    width: 42px;
    height: 42px;
  }
  .nav-link {
    width: 100%;
    justify-content: flex-start;
    min-height: var(--touch);
    border-radius: 12px;
    padding-inline: 1rem;
    font-size: 0.95rem;
  }
  .nav-meta {
    margin: 0.35rem 0 0;
    padding-top: 0.55rem;
    border-top: 1px solid rgba(255,255,255,0.12);
    justify-content: space-between;
  }
  .nav-user { max-width: none; }
  .btn-nav-out { min-height: var(--touch); }

  .desk-only { display: none !important; }
  .mobile-only, .card-list.mobile-only { display: grid; }

  .filters-cascade {
    grid-template-columns: 1fr;
  }
  .filter-actions { flex-direction: column; }
  .filter-actions .btn,
  .btn-block-sm {
    width: 100%;
  }

  table, .data-table { min-width: 0; }
  .brand-logo {
    height: 32px;
    max-width: 150px;
  }
  .footer-brand {
    align-items: flex-start;
  }
  .map-centers-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .container { padding-inline: 0.75rem; }
  .stats { grid-template-columns: 1fr; }
}

/* —— الخريطة الميدانية —— */
.overview-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}
.overview-legend {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
}
.legend-item i {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  display: inline-block;
}
.legend-filled i { background: #1f7a4d; }
.legend-vacant i { background: #c43c3c; }

.overview-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0.75rem 0 1rem;
}
.overview-summary .stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.85rem 1rem;
}
.text-ok { color: #1f7a4d; }
.text-danger { color: #c43c3c; }

.map-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}
.map-tab {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  text-align: right;
  cursor: pointer;
  display: grid;
  gap: 0.2rem;
  box-shadow: var(--shadow);
  font: inherit;
  color: var(--ink);
  min-height: 64px;
}
.map-tab strong { font-size: 1rem; }
.map-tab span { color: var(--muted); font-size: 0.85rem; }
.map-tab.is-active {
  border-color: var(--accent);
  background: linear-gradient(180deg, #fff8ef, #fff);
  box-shadow: 0 0 0 2px rgba(241, 138, 31, 0.25);
}
.map-panel { display: none; }
.map-panel.is-active { display: block; }

.map-center-nav {
  display: none;
}
.map-step-title {
  margin: 0.35rem 0 0.65rem;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 700;
}
.map-centers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.65rem;
  margin-bottom: 1rem;
}
.map-center-card {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 0.85rem;
  text-align: right;
  cursor: pointer;
  display: grid;
  gap: 0.35rem;
  font: inherit;
  color: var(--ink);
  box-shadow: var(--shadow);
  min-height: 92px;
}
.map-center-card strong { font-size: 0.95rem; line-height: 1.35; }
.map-center-card span { color: var(--muted); font-size: 0.84rem; }
.map-center-card .map-center-bar { width: 100%; }
.map-center-card .badge-ok { justify-self: start; }
.map-center-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(241, 138, 31, 0.28);
  background: linear-gradient(180deg, #fff8ef, #fff);
}
.map-center-chip {
  display: none;
}

.map-offices-panel { display: none; margin-bottom: 0.5rem; }
.map-offices-panel.is-active { display: block; }
.map-offices-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: baseline;
  margin-bottom: 0.65rem;
  padding: 0.65rem 0.85rem;
  background: var(--bg-accent);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.map-offices-head strong { color: var(--primary); }
.map-offices-head span { color: var(--muted); font-size: 0.88rem; }

.map-sheet {
  display: grid;
  gap: 1rem;
}
.map-center {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  scroll-margin-top: 90px;
}
.map-center-head {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  padding: 0.85rem 1rem;
  background: linear-gradient(180deg, #f7f9fc, #eef2f8);
  border-bottom: 1px solid var(--border);
}
.map-center-head h2 {
  margin: 0;
  font-size: 1.05rem;
}
.map-center-head p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.map-center-bar {
  flex: 1 1 120px;
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  min-width: 100px;
}
.map-center-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #1f7a4d, var(--accent));
}
.badge-ok {
  background: #e7f6ee;
  color: #1f7a4d;
  border: 1px solid #b7dfc6;
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 700;
}

.map-offices {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 0.55rem;
  padding: 0.85rem;
  max-height: none;
}

.office-cell {
  display: grid;
  gap: 0.15rem;
  padding: 0.65rem 0.7rem;
  border-radius: 12px;
  border: 1px solid transparent;
  text-decoration: none !important;
  color: inherit;
  min-height: 78px;
  transition: transform .12s ease, box-shadow .12s ease;
}
.office-cell:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(10, 34, 72, 0.12);
}
.office-num {
  font-weight: 800;
  font-size: 0.95rem;
}
.office-name {
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.office-phone {
  font-size: 0.75rem;
  opacity: 0.85;
  direction: ltr;
  unicode-bidi: plaintext;
}
.office-cell.is-filled {
  background: linear-gradient(180deg, #e9f8ef, #d8f0e2);
  border-color: #9fd4b4;
  color: #145c38;
}
.office-cell.is-vacant {
  background: linear-gradient(180deg, #fdeeee, #f8dede);
  border-color: #efb0b0;
  color: #8f2a2a;
}

@media (max-width: 860px) {
  .overview-summary { grid-template-columns: 1fr; }
  .map-offices {
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  }
  .map-center-head { align-items: flex-start; }
}

