:root {
  --ink: #14251f;
  --ink-strong: #092e25;
  --muted: #66766f;
  --muted-2: #81928b;
  --paper: #f4f7f4;
  --paper-2: #eef4f0;
  --card: #ffffff;
  --green: #12664f;
  --green-dark: #0a493a;
  --green-soft: #e8f2ed;
  --green-soft-2: #f2faf6;
  --blue: #285f8f;
  --blue-soft: #eef6fc;
  --purple: #6d55b8;
  --warning: #b7791f;
  --warning-soft: #fff7df;
  --danger: #b42318;
  --danger-soft: #fff1f2;
  --line: #dce4df;
  --line-2: #e8eee9;
  --shadow: 0 16px 45px rgba(17, 46, 35, .11);
  --shadow-soft: 0 7px 23px rgba(21, 45, 36, .055);
  --radius: 15px;
  --radius-sm: 10px;
  --focus: 0 0 0 3px rgba(18,102,79,.14);
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, select, input { font: inherit; }
button { color: inherit; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: none; box-shadow: var(--focus); }
.app-shell { min-height: 100vh; }

/* Header */
.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 26px;
  color: #fff;
  background: linear-gradient(112deg, #073d31, #0d684f 62%, #138069);
  box-shadow: 0 4px 20px rgba(4, 41, 31, .2);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 11px;
  background: rgba(255,255,255,.1);
  font-size: 23px;
}
.brand h1 { margin: 0; font-size: 22px; line-height: 1.2; letter-spacing: -.02em; }
.brand p { margin: 3px 0 0; color: rgba(255,255,255,.72); font-size: 11px; }
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: max-content;
  font-size: 12px;
  color: rgba(255,255,255,.86);
}
.status span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f4c95d;
  box-shadow: 0 0 0 5px rgba(244,201,93,.13);
}
.status.ready span { background: #82e3b4; box-shadow: 0 0 0 5px rgba(130,227,180,.14); }
.status.error span { background: #ff8f8f; box-shadow: 0 0 0 5px rgba(255,143,143,.14); }

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  min-height: 48px;
  padding: 7px 26px 0;
  background: #fff;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: thin;
}
.tab {
  position: relative;
  min-width: max-content;
  padding: 10px 16px 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  border-radius: 10px 10px 0 0;
}
.tab::after {
  content: "";
  position: absolute;
  right: 14px;
  left: 14px;
  bottom: -1px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: transparent;
}
.tab:hover { color: var(--green); background: #f6faf8; }
.tab.active { color: var(--green-dark); }
.tab.active::after { background: var(--green); }

/* KPI strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  border-bottom: 1px solid var(--line);
  background: var(--line);
}
.kpi-strip article {
  position: relative;
  padding: 12px 24px;
  background: rgba(255,255,255,.95);
  min-width: 0;
}
.kpi-strip article::before {
  content: "";
  position: absolute;
  right: 13px;
  top: 17px;
  width: 3px;
  height: 35px;
  border-radius: 4px;
  background: #79ad97;
}
.kpi-strip span, .kpi-strip small { display: block; color: var(--muted); font-size: 10px; }
.kpi-strip strong {
  display: block;
  margin: 2px 0;
  color: var(--green-dark);
  font-size: 21px;
  direction: ltr;
  text-align: right;
  line-height: 1.25;
}

/* Views and map layout */
.views { padding: 0; }
.view { display: none; }
.view.active { display: block; }
.map-layout {
  display: grid;
  grid-template-columns: 322px minmax(0, 1fr);
  height: calc(100vh - 253px);
  min-height: 540px;
  direction: rtl;
}
.control-panel {
  overflow-y: auto;
  padding: 19px;
  background: rgba(255,255,255,.985);
  border-left: 1px solid var(--line);
  box-shadow: 8px 0 30px rgba(29,55,45,.05);
  z-index: 3;
  scrollbar-width: thin;
  scrollbar-color: #b9c9c0 transparent;
}
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-title h2 { margin: 2px 0 0; font-size: 17px; }
.overline {
  color: #789087;
  font-size: 9px;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
  font-size: 20px;
  transition: .18s ease;
}
.icon-button:hover { color: #fff; background: var(--green); border-color: var(--green); }
.control-group { display: block; margin: 12px 0; font-size: 11px; font-weight: 750; }
select {
  width: 100%;
  margin-top: 6px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cbd7d0;
  border-radius: 9px;
  outline: none;
  font-size: 12px;
  line-height: 1.3;
}
select:focus { border-color: var(--green); box-shadow: var(--focus); }
select:disabled { color: #94a09a; background: #f3f5f4; cursor: not-allowed; }
option:disabled { color: #9aa7a1; }
.micro-note { margin: -6px 0 10px; color: var(--muted); font-size: 9px; line-height: 1.5; }
.scope-badge {
  margin: 8px 0 12px;
  padding: 8px 10px;
  border-radius: 9px;
  color: #315749;
  background: #edf5f1;
  font-size: 10px;
  font-weight: 750;
  line-height: 1.45;
}
.scope-badge.waiting { color: #7c5a16; background: var(--warning-soft); }
.scope-badge.error { color: var(--danger); background: var(--danger-soft); }
.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 15px 0;
  padding: 10px;
  border-radius: 10px;
  background: var(--green-soft);
  font-size: 11px;
  cursor: pointer;
  user-select: none;
}
.toggle-row:hover { background: #deeee6; }
.toggle-row input { position: absolute; opacity: 0; }
.toggle {
  position: relative;
  flex: 0 0 auto;
  width: 37px;
  height: 20px;
  border-radius: 20px;
  background: #9eaaa4;
  transition: .2s;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
}
input:checked + .toggle { background: var(--green); }
input:checked + .toggle::after { transform: translateX(-17px); }
.legend-wrap, .method-note { margin-top: 17px; padding-top: 14px; border-top: 1px solid var(--line); }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.section-heading h3, .method-note h3 { margin: 0 0 9px; font-size: 12px; }
.section-heading span { color: var(--muted); font-size: 9px; }
.legend { display: grid; gap: 6px; }
.legend-item {
  display: grid;
  grid-template-columns: 17px 1fr;
  align-items: center;
  gap: 7px;
  color: #475951;
  font-size: 10px;
  line-height: 1.35;
}
.legend-swatch {
  width: 17px;
  height: 10px;
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 3px;
}
.method-note p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.65; }
.method-note p + p { margin-top: 6px; }

/* Map */
.map-stage { position: relative; min-width: 0; direction: ltr; overflow: hidden; }
#map { position: absolute; inset: 0; background: #dce8e2; }
.map-hint {
  position: absolute;
  left: 14px;
  bottom: 29px;
  z-index: 2;
  max-width: min(470px, calc(100% - 28px));
  padding: 7px 10px;
  border-radius: 8px;
  color: #405049;
  background: rgba(255,255,255,.92);
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  font-size: 10px;
  direction: rtl;
  line-height: 1.55;
}
.map-error {
  position: absolute;
  top: 16px;
  left: 50%;
  z-index: 10;
  transform: translateX(-50%);
  max-width: 560px;
  padding: 12px 16px;
  color: #7f1d1d;
  background: var(--danger-soft);
  border: 1px solid #fecdd3;
  border-radius: 10px;
  direction: rtl;
  box-shadow: var(--shadow);
}

/* Details panel */
.details-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 5;
  width: min(380px, calc(100% - 24px));
  overflow-y: auto;
  transform: translateX(calc(100% + 24px));
  transition: transform .28s ease;
  direction: rtl;
  background: rgba(255,255,255,.985);
  border: 1px solid rgba(210,222,216,.9);
  border-radius: 15px;
  box-shadow: 0 20px 55px rgba(12,45,34,.22);
  scrollbar-width: thin;
}
.details-panel.open { transform: translateX(0); }
.details-close {
  position: sticky;
  top: 9px;
  float: left;
  z-index: 2;
  width: 29px;
  height: 29px;
  margin: 9px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: rgba(8,58,45,.78);
  cursor: pointer;
  font-size: 19px;
  line-height: 1;
}
.details-close:hover { background: var(--green-dark); }
.details-content { clear: both; }
.details-empty { padding: 70px 30px; text-align: center; color: var(--muted); }
.details-empty span { display: block; color: #94aa9f; font-size: 38px; }
.details-empty h3 { margin: 8px 0; color: var(--ink); font-size: 15px; }
.details-empty p { margin: 0; font-size: 11px; line-height: 1.6; }
.details-head { padding: 4px 18px 16px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, #fff, #fbfdfc); }
.details-head small { color: var(--muted); font-size: 10px; direction: ltr; display: block; text-align: right; }
.details-head h3 { margin: 4px 0 2px; font-size: 19px; }
.details-head div { color: #52645c; font-size: 11px; line-height: 1.5; }
.status-pill, .pill, .compare-badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 20px;
  background: #edf3ef;
  color: #39574a;
  font-size: 9px;
  font-weight: 750;
  line-height: 1.2;
}
.status-pill { margin-top: 7px; }
.details-body { padding: 14px 18px 20px; }
.details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.detail-field {
  min-width: 0;
  padding: 9px;
  border: 1px solid #e7ece9;
  border-radius: 9px;
  background: #fafcfb;
}
.detail-field.wide { grid-column: 1 / -1; }
.detail-field span { display: block; color: var(--muted); font-size: 9px; }
.detail-field b {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.detail-field b:has(+ .compare-badge) { margin-bottom: 4px; }
.detail-section { margin-top: 16px; }
.detail-section h4 { margin: 0 0 7px; font-size: 11px; }
.category-list { display: grid; gap: 5px; }
.category-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 10px;
}
.category-row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.category-row i { display: inline-block; width: 7px; height: 7px; margin-left: 5px; border-radius: 50%; }
.maps-link {
  display: block;
  margin-top: 15px;
  padding: 10px;
  border-radius: 9px;
  color: #fff;
  background: var(--green);
  text-align: center;
  text-decoration: none;
  font-size: 11px;
  font-weight: 750;
}
.maps-link:hover { background: var(--green-dark); }

/* Mini insights */
.insights-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 15px 20px 22px; }
.insight-card, .table-card, .explain-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}
.insight-card { min-height: 190px; padding: 15px; }
.insight-card h3 { margin: 2px 0 12px; font-size: 14px; }
.loading-row { color: var(--muted); font-size: 11px; }
.mini-bars { display: grid; gap: 8px; }
.mini-bar-label { display: flex; justify-content: space-between; gap: 10px; color: #405049; font-size: 10px; }
.mini-bar-track { height: 6px; overflow: hidden; border-radius: 10px; background: #edf1ef; }
.mini-bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, #7fbea3, #176f55); }
.compact-list { display: grid; gap: 7px; }
.compact-row {
  display: grid;
  grid-template-columns: 23px 1fr auto;
  align-items: center;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid #edf1ef;
  font-size: 10px;
}
.compact-row em {
  display: grid;
  place-items: center;
  width: 21px;
  height: 21px;
  border-radius: 6px;
  color: var(--green);
  background: var(--green-soft);
  font-style: normal;
  font-weight: 700;
}
.compact-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Data views */
.data-view { min-height: calc(100vh - 190px); padding: 28px; }
.view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px;
  max-width: 1500px;
  margin: 0 auto 18px;
}
.view-header h2 { margin: 3px 0 5px; font-size: 25px; }
.view-header p { max-width: 720px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.inline-controls { display: flex; gap: 8px; min-width: 420px; }
.inline-controls select, .inline-controls input, .view-header > select { margin: 0; min-width: 190px; }
.inline-controls input {
  padding: 9px 11px;
  border: 1px solid #cbd7d0;
  border-radius: 9px;
  outline: none;
  background: #fff;
  font-size: 11px;
}
.inline-controls input:focus { border-color: var(--green); box-shadow: var(--focus); }
.download-link {
  padding: 9px 14px;
  border: 1px solid var(--green);
  border-radius: 9px;
  color: var(--green);
  background: #fff;
  cursor: pointer;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}
.download-link:hover { color: #fff; background: var(--green); }
.table-card { max-width: 1500px; margin: 0 auto; overflow: hidden; }
.table-scroll { overflow: auto; max-height: calc(100vh - 315px); scrollbar-width: thin; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; text-align: right; font-size: 11px; }
thead { position: sticky; top: 0; z-index: 1; }
th { padding: 12px; color: #fff; background: #164f3f; font-weight: 700; }
td { padding: 10px 12px; border-bottom: 1px solid #e9eeeb; }
tbody tr:nth-child(even) { background: #fafcfb; }
tbody tr:hover { background: #edf5f1; }
.row-link {
  color: var(--green);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 700;
}
.row-link:hover { color: var(--green-dark); }
.value-strong { color: var(--green-dark); font-weight: 750; }
.explain-card {
  max-width: 1500px;
  margin: 0 auto 13px;
  padding: 12px 15px;
  border-right: 4px solid #7b5cc8;
  color: #51485d;
  font-size: 11px;
  line-height: 1.7;
}
.explain-card.blue { border-right-color: #4b8fc1; color: #3b5366; }

/* MapLibre polish */
.maplibregl-ctrl-group { border-radius: 9px !important; overflow: hidden; box-shadow: 0 6px 18px rgba(17,46,35,.14) !important; }
.maplibregl-ctrl-attrib { direction: ltr; }
.maplibregl-canvas:focus { outline: none; }

/* Scrollbars */
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #b9c9c0; border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #97aa9f; border: 2px solid transparent; background-clip: content-box; }

@media (max-width: 1180px) {
  .map-layout { grid-template-columns: 300px minmax(0, 1fr); }
  .details-panel { width: min(350px, calc(100% - 24px)); }
}

@media (max-width: 1050px) {
  .map-layout { grid-template-columns: 280px minmax(0, 1fr); }
  .kpi-strip article { padding-inline: 19px; }
  .insights-grid { grid-template-columns: 1fr 1fr; }
  .insight-card:last-child { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .topbar { height: auto; padding: 11px 14px; }
  .brand h1 { font-size: 17px; }
  .brand p, .status { display: none; }
  .tabs { padding-right: 8px; padding-left: 8px; }
  .tab { padding-inline: 12px; }
  .kpi-strip { grid-template-columns: 1fr 1fr; }
  .kpi-strip article { padding: 9px 18px; }
  .kpi-strip strong { font-size: 17px; }
  .map-layout { display: block; height: auto; }
  .control-panel { max-height: none; border-left: 0; border-bottom: 1px solid var(--line); }
  .map-stage { height: 72vh; min-height: 520px; }
  .insights-grid { grid-template-columns: 1fr; padding: 12px; }
  .insight-card:last-child { grid-column: auto; }
  .details-panel { top: auto; right: 8px; left: 8px; bottom: 8px; width: auto; height: 72%; transform: translateY(calc(100% + 24px)); }
  .details-panel.open { transform: translateY(0); }
  .view-header { align-items: stretch; flex-direction: column; }
  .inline-controls { min-width: 0; width: 100%; flex-direction: column; }
  .inline-controls select, .inline-controls input, .view-header > select { min-width: 0; width: 100%; }
  .data-view { padding: 18px 12px; }
  .table-scroll { max-height: calc(100vh - 365px); }
}

@media (max-width: 460px) {
  .kpi-strip { grid-template-columns: 1fr; }
  .details-grid { grid-template-columns: 1fr; }
  .detail-field.wide { grid-column: auto; }
  .map-hint { display: none; }
}


/* ============================================================
   UX pass — 20260709
   الهدف: منع سكرول الصفحة العامة، نقل الملخصات إلى نظرة عامة،
   ودعم فلاتر الجداول الجديدة بدون كسر التصميم القديم.
   ============================================================ */

/* الصفحة نفسها لا تسكرول؛ السكرول يكون داخل اللوحات فقط */
html,
body {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body {
  overscroll-behavior: none;
}

.app-shell {
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar,
.tabs,
.kpi-strip {
  flex: 0 0 auto;
}

.views {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.view {
  height: 100%;
  min-height: 0;
}

.view.active {
  display: block;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

/* صفحة الخريطة: لا يوجد سكرول للصفحة، فقط لوحة التحكم والتفاصيل */
#map-view {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

#map-view .map-layout {
  height: 100%;
  min-height: 0;
}

.map-layout {
  min-height: 0;
}

.control-panel {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.map-stage {
  height: 100%;
  min-height: 0;
}

/* العناصر المخفية من HTML/JS تبقى مخفية بصرامة */
[hidden],
.advanced-controls[hidden],
#category-only-control[hidden],
#category-only-note[hidden] {
  display: none !important;
}

#category-only-control {
  margin-top: 12px;
  margin-bottom: 6px;
}

/* تبويب نظرة عامة بعد نقل كروت الملخصات إليه */
.overview-view {
  overflow: auto;
  overscroll-behavior: contain;
}

.overview-view .view-header {
  max-width: 1500px;
}

.overview-insights {
  max-width: 1500px;
  margin: 0 auto;
  padding: 0;
}

.overview-view .insight-card {
  min-height: 235px;
}

.overview-view .mini-bars {
  gap: 11px;
}

.overview-view .compact-list {
  gap: 10px;
}

/* صفحات البيانات: السكرول داخل الجدول فقط وليس الصفحة */
.data-view {
  height: 100%;
  min-height: 0;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.data-view .view-header {
  flex: 0 0 auto;
}

.data-view .explain-card {
  flex: 0 0 auto;
  width: 100%;
}

.data-view .table-card {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.data-view .table-scroll {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow: auto;
  overscroll-behavior: contain;
}

/* فلاتر منظمة بدل البحث النصي */
.inline-controls.structured-controls {
  min-width: min(760px, 100%);
  width: min(820px, 100%);
  display: grid;
  grid-template-columns: repeat(3, minmax(145px, 1fr));
  gap: 8px;
}

.inline-controls.structured-controls select,
.inline-controls.structured-controls input {
  min-width: 0;
  width: 100%;
}

/* الفلاتر المخفية القديمة لا تأخذ مساحة */
.inline-controls input[hidden] {
  display: none !important;
}

/* تحسين ازدحام الهيدر في تبويبات الجداول */
.data-view .view-header {
  align-items: flex-end;
}

.data-view .view-header > div:first-child {
  min-width: 260px;
}

/* تحسين وضع الخريطة بعد إزالة فوتر الملخصات */
#map-view .map-hint {
  bottom: 18px;
}

#map-view .details-panel {
  max-height: calc(100% - 24px);
}

/* اختصار بعض النصوص الطويلة داخل القوائم */
select option {
  font-size: 12px;
}

/* منع أي امتداد عرضي غير مرغوب */
body,
.app-shell,
.views,
.view,
.map-layout,
.data-view {
  max-width: 100vw;
}

/* تحسينات للتبويبات الجديدة */
.tab[data-view="overview-view"] {
  color: #5f6f69;
}

.tab[data-view="overview-view"].active {
  color: var(--green-dark);
}

/* استجابة للشاشات المتوسطة */
@media (max-width: 1180px) {
  .inline-controls.structured-controls {
    grid-template-columns: repeat(2, minmax(145px, 1fr));
    width: min(620px, 100%);
  }
}

/* موبايل: نبقي الصفحة العامة مضبوطة، لكن كل قسم يسكرول داخلياً */
@media (max-width: 760px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app-shell {
    height: 100vh;
  }

  .views {
    overflow: hidden;
  }

  .view.active {
    overflow: hidden;
  }

  #map-view .map-layout {
    display: grid;
    grid-template-rows: minmax(190px, 34%) minmax(0, 1fr);
    grid-template-columns: 1fr;
    height: 100%;
    min-height: 0;
  }

  .control-panel {
    max-height: none;
    height: 100%;
    overflow-y: auto;
    border-left: 0;
    border-bottom: 1px solid var(--line);
  }

  .map-stage {
    height: 100%;
    min-height: 0;
  }

  .data-view,
  .overview-view {
    padding: 18px 12px;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .data-view .table-scroll {
    max-height: none;
  }

  .inline-controls.structured-controls {
    grid-template-columns: 1fr;
    min-width: 0;
    width: 100%;
  }

  .overview-insights {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 460px) {
  .topbar,
  .tabs,
  .kpi-strip {
    flex-shrink: 0;
  }
}

/* ============================================================
   UX fix pass — 20260709-2
   Fix inactive tabs, independent overview, fit-Iraq button, and map sizing.
   ============================================================ */

/* Strong tab visibility rule: later .data-view display rules must not show inactive tabs. */
.view:not(.active) {
  display: none !important;
}

.view.active.data-view {
  display: flex;
}

.view.active#map-view {
  display: block;
}

/* Map quick action */
.map-fit-button {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 4;
  padding: 8px 12px;
  border: 1px solid rgba(15, 83, 63, .22);
  border-radius: 10px;
  color: var(--green-dark);
  background: rgba(255,255,255,.94);
  box-shadow: 0 7px 20px rgba(11, 49, 37, .13);
  cursor: pointer;
  font-size: 11px;
  font-weight: 750;
  direction: rtl;
}
.map-fit-button:hover { color: #fff; background: var(--green); border-color: var(--green); }

/* Overview became a real standalone tab. */
.overview-view {
  overflow: auto !important;
}

.overview-summary-grid {
  width: 100%;
  max-width: 1500px;
  margin: 0 auto 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.overview-summary-grid article {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-soft);
}
.overview-summary-grid span,
.overview-summary-grid small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}
.overview-summary-grid strong {
  display: block;
  margin: 4px 0;
  color: var(--green-dark);
  font-size: 18px;
  line-height: 1.35;
}
.overview-insights {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding-bottom: 26px;
}
.overview-view .insight-card.tall-card {
  min-height: 335px;
}
.overview-view .insight-card.tall-card .mini-bars {
  max-height: 255px;
  overflow: auto;
  padding-left: 4px;
}
.overview-view .compact-row {
  grid-template-columns: 26px minmax(0, 1fr) auto;
}

/* Let MapLibre own the exact viewport it sees. */
#map-view .map-layout,
#map-view .map-stage,
#map {
  min-width: 0;
  min-height: 0;
}

@media (max-width: 1180px) {
  .overview-summary-grid,
  .overview-insights { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .overview-summary-grid,
  .overview-insights { grid-template-columns: 1fr; }
  .map-fit-button { top: 10px; left: 10px; }
}

/* UX cleanup 20260709-3 */
.kpi-strip { grid-template-columns: repeat(3, 1fr); }
.compact-row-button {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: inherit;
  cursor: pointer;
  font-family: inherit;
}
.compact-row-button:hover {
  border-radius: 8px;
  background: #f3f8f5;
}
.about-view { overflow: auto !important; }
.about-card {
  max-width: 920px;
  margin: 0 auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: var(--shadow-soft);
}
.about-intro h3 { margin: 0 0 10px; color: var(--green-dark); font-size: 22px; }
.about-intro p { margin: 0; color: var(--text); line-height: 1.9; font-size: 14px; }
.project-links {
  margin-top: 20px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #fbfdfc, #f5faf7);
}
.project-links h4 {
  margin: 0 0 8px;
  color: var(--green-dark);
  font-size: 15px;
}
.project-links p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.85;
}
.project-link-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}
.project-link-buttons a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  color: #fff;
  background: var(--green);
  text-decoration: none;
  font-size: 12px;
  font-weight: 850;
  box-shadow: 0 7px 16px rgba(18, 102, 79, .16);
}
.project-link-buttons a:hover { background: var(--green-dark); }
.about-author {
  margin-top: 24px;
  padding: 18px;
  border-radius: 16px;
  background: var(--green-soft);
  display: grid;
  gap: 4px;
}
.about-author span { color: var(--muted); font-size: 12px; }
.about-author strong { color: var(--green-dark); font-size: 24px; }
.about-author small { color: var(--text); font-size: 13px; }
.contact-icons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}
.contact-icons a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--green-dark);
  background: #fff;
  text-decoration: none;
  font-weight: 750;
  box-shadow: 0 5px 14px rgba(12, 74, 53, .08);
}
.contact-icons a:hover { border-color: var(--green); background: #f5fbf8; }
@media (max-width: 760px) {
  .kpi-strip { grid-template-columns: 1fr; }
  .about-card { padding: 20px; }
}

/* ============================================================
   Mobile-first polish pass — 20260709-mobile-1
   يجعل تجربة الهاتف أقرب لتطبيق: نظرة أولاً، خريطة كاملة، فلاتر كـ bottom sheet، وجداول ككروت.
   ============================================================ */
:root {
  --radius-lg: 20px;
  --text: var(--ink);
  --mobile-nav-h: 62px;
}
.panel-actions { display: inline-flex; align-items: center; gap: 7px; }
.mobile-panel-close,
.mobile-filter-apply,
.mobile-indicator-control,
.mobile-map-toolbar,
.mobile-filter-button { display: none; }
.mini-bar-item {
  width: 100%;
  display: block;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: inherit;
  font-family: inherit;
}
button.mini-bar-item { cursor: pointer; border-radius: 9px; }
button.mini-bar-item:hover { background: #f3f8f5; }

@media (hover: none) {
  .tab:hover,
  .icon-button:hover,
  .map-fit-button:hover,
  .contact-icons a:hover,
  .compact-row-button:hover,
  button.mini-bar-item:hover { background: inherit; color: inherit; }
}

@media (max-width: 760px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
    background: var(--paper);
  }

  body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 89;
    background: rgba(7, 37, 29, .34);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  body.filters-open::before { opacity: 1; pointer-events: auto; }

  .app-shell {
    height: 100dvh;
    min-height: 100vh;
    padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom));
    overflow: hidden;
  }

  .topbar {
    min-height: 58px;
    height: auto;
    padding: 8px 11px;
    gap: 8px;
    position: relative;
    z-index: 60;
  }
  .brand { gap: 9px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 19px; }
  .brand h1 { font-size: 15px; line-height: 1.25; }
  .brand p { display: none; }
  .status {
    max-width: 124px;
    min-width: 0;
    font-size: 9px;
    line-height: 1.35;
    justify-content: flex-end;
    text-align: left;
  }
  .status span { width: 7px; height: 7px; flex: 0 0 auto; }

  .kpi-strip { display: none !important; }

  .tabs {
    position: fixed;
    right: 0;
    left: 0;
    bottom: 0;
    z-index: 120;
    min-height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom));
    padding: 6px 7px calc(6px + env(safe-area-inset-bottom));
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(58px, 1fr);
    gap: 4px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    background: rgba(255,255,255,.98);
    border-top: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: 0 -10px 28px rgba(11, 45, 35, .12);
  }
  .tab {
    min-width: 58px;
    padding: 9px 7px 8px;
    border-radius: 14px;
    font-size: 0;
    line-height: 1;
    display: grid;
    place-items: center;
    min-height: 44px;
  }
  .tab::before {
    content: attr(data-mobile-label);
    font-size: 11px;
    font-weight: 800;
    line-height: 1.15;
  }
  .tab::after {
    right: 18px;
    left: 18px;
    bottom: 5px;
    height: 2px;
  }
  .tab.active { background: var(--green-soft); }

  .views {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    padding-bottom: 0;
  }
  .view.active.data-view,
  .view.active.overview-view,
  .view.active.about-view {
    display: block !important;
    height: 100%;
    overflow: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .view.active#map-view { height: 100%; overflow: hidden !important; }

  #map-view .map-layout {
    display: block !important;
    height: 100%;
    min-height: 0;
  }
  .map-stage {
    height: 100% !important;
    min-height: 0 !important;
    border-radius: 0;
  }
  #map { inset: 0; }

  .mobile-map-toolbar {
    position: absolute;
    top: 10px;
    right: 10px;
    left: auto;
    z-index: 6;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    flex-wrap: nowrap;
    gap: 8px;
    direction: rtl;
    pointer-events: none;
  }
  .mobile-indicator-control {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: min(235px, calc(100vw - 190px));
    min-height: 38px;
    padding: 5px 8px;
    border: 1px solid rgba(15, 83, 63, .18);
    border-radius: 999px;
    color: var(--green-dark);
    background: rgba(255,255,255,.96);
    box-shadow: 0 7px 20px rgba(11, 49, 37, .14);
    font-size: 10px;
    font-weight: 850;
    pointer-events: auto;
  }
  .mobile-indicator-control span {
    flex: 0 0 auto;
    color: #557066;
  }
  .mobile-indicator-control select {
    width: min(150px, 38vw);
    min-height: 28px;
    margin: 0;
    padding: 4px 7px;
    border: 0;
    border-radius: 999px;
    background: var(--green-soft);
    color: var(--green-dark);
    font-size: 11px;
    font-weight: 800;
  }
  .mobile-filter-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    pointer-events: auto;
    padding: 9px 12px;
    border: 1px solid rgba(15, 83, 63, .2);
    border-radius: 999px;
    color: var(--green-dark);
    background: rgba(255,255,255,.95);
    box-shadow: 0 7px 20px rgba(11, 49, 37, .16);
    font-size: 12px;
    font-weight: 850;
    cursor: pointer;
  }
  .map-fit-button {
    top: 10px;
    left: 56px;
    z-index: 6;
    width: 38px;
    height: 38px;
    min-height: 38px;
    padding: 0;
    display: grid;
    place-items: center;
    border-radius: 50%;
    font-size: 21px;
    line-height: 1;
  }
  .map-hint { display: none !important; }
  .map-error {
    top: 58px;
    right: 10px;
    left: 10px;
    transform: none;
    max-width: none;
    font-size: 11px;
  }

  .control-panel {
    position: fixed;
    top: auto;
    right: 8px;
    left: 8px;
    bottom: calc(var(--mobile-nav-h) + 8px + env(safe-area-inset-bottom));
    z-index: 100;
    height: min(76dvh, 640px);
    max-height: min(76dvh, 640px);
    padding: 15px;
    border: 1px solid rgba(210,222,216,.95);
    border-radius: 22px 22px 18px 18px;
    box-shadow: 0 22px 70px rgba(6, 35, 27, .34);
    transform: translateY(calc(100% + 110px));
    transition: transform .24s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  body.filters-open .control-panel { transform: translateY(0); }
  .mobile-panel-close { display: grid; place-items: center; font-size: 22px; }
  .panel-title {
    position: sticky;
    top: -15px;
    z-index: 2;
    margin: -15px -15px 12px;
    padding: 13px 15px 10px;
    background: rgba(255,255,255,.98);
    border-bottom: 1px solid var(--line-2);
    border-radius: 22px 22px 0 0;
  }
  .panel-title h2 { font-size: 15px; }
  .control-group { margin: 10px 0; font-size: 11px; }
  .map-indicator-panel-control { display: none; }
  select { min-height: 41px; font-size: 13px; border-radius: 12px; }
  .scope-badge, .micro-note { font-size: 10px; }
  .legend-wrap { margin-top: 12px; }
  .legend { grid-template-columns: 1fr; }
  .legend-item { font-size: 10px; }

  .details-panel {
    position: fixed;
    top: max(74px, calc(env(safe-area-inset-top) + 64px));
    right: 8px;
    left: 8px;
    bottom: calc(var(--mobile-nav-h) + 8px + env(safe-area-inset-bottom));
    z-index: 112;
    width: auto;
    height: auto;
    max-height: min(69dvh, 620px);
    min-height: 205px;
    border-radius: 22px 22px 18px 18px;
    transform: translateY(calc(100% + 110px));
    box-shadow: 0 22px 70px rgba(6, 35, 27, .34);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .details-panel.open { transform: translateY(0); }
  .details-close {
    top: max(12px, env(safe-area-inset-top));
    width: 38px;
    height: 38px;
    margin: 12px 12px 4px;
    font-size: 24px;
    background: rgba(8,58,45,.9);
    box-shadow: 0 8px 18px rgba(8, 58, 45, .22);
  }
  .details-head { padding: 5px 16px 14px; }
  .details-head h3 { font-size: 17px; }
  .details-body { padding: 12px 14px 17px; }
  .details-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .detail-field { padding: 10px; border-radius: 12px; }
  .detail-field.wide { grid-column: 1 / -1; }

  .data-view,
  .overview-view,
  .about-view {
    padding: 14px 10px calc(var(--mobile-nav-h) + 34px + env(safe-area-inset-bottom));
    scroll-padding-bottom: calc(var(--mobile-nav-h) + 34px + env(safe-area-inset-bottom));
  }
  .view-header {
    gap: 10px;
    margin-bottom: 10px;
  }
  .view-header h2 { font-size: 18px; }
  .view-header .overline { font-size: 9px; }
  .inline-controls.structured-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }
  .inline-controls.structured-controls select,
  .inline-controls.structured-controls input { min-height: 39px; font-size: 12px; }

  .overview-insights {
    grid-template-columns: 1fr !important;
    gap: 10px;
    padding: 0 0 12px;
  }
  .overview-view .insight-card,
  .overview-view .insight-card.tall-card {
    min-height: 0;
    padding: 14px;
    border-radius: 18px;
  }
  .overview-view .insight-card.tall-card .mini-bars {
    max-height: none;
    overflow: visible;
  }
  .insight-card h3 { font-size: 14px; }
  .mini-bars { gap: 10px; }
  .mini-bar-item { padding: 4px 0; }
  .mini-bar-label { font-size: 11px; }
  .compact-row {
    grid-template-columns: 24px minmax(0, 1fr) auto !important;
    gap: 8px;
    min-height: 42px;
    padding: 9px 8px;
    border-radius: 12px;
    background: #fbfdfc;
  }
  .compact-row span { white-space: normal; line-height: 1.35; }
  .compact-row b { font-size: 12px; }

  .data-view .table-card {
    display: block;
    overflow: visible;
    border: 0;
    background: transparent;
    box-shadow: none;
  }
  .data-view .table-scroll {
    display: block;
    overflow: visible;
    max-height: none;
  }
  .data-view table,
  .data-view thead,
  .data-view tbody,
  .data-view tr,
  .data-view td {
    display: block;
    width: 100%;
  }
  .data-view thead { display: none; }
  .data-view tbody tr {
    margin: 0 0 10px;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 17px;
    background: #fff;
    box-shadow: var(--shadow-soft);
  }
  .data-view tbody tr:empty { display: none; }
  .data-view td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line-2);
    white-space: normal;
    text-align: left;
    direction: rtl;
    font-size: 12px;
    line-height: 1.45;
  }
  .data-view td:last-child { border-bottom: 0; }
  .data-view td::before {
    content: attr(data-label);
    flex: 0 0 42%;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-align: right;
  }
  .data-view td.loading-row,
  .data-view td[colspan] {
    display: block;
    text-align: center;
  }
  .data-view td.loading-row::before,
  .data-view td[colspan]::before { content: none; }
  .row-link {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: left;
    direction: ltr;
  }
  .value-strong { font-size: 13px; }

  .about-card {
    padding: 18px;
    border-radius: 20px;
    margin-bottom: calc(var(--mobile-nav-h) + 22px + env(safe-area-inset-bottom));
  }
  .about-intro h3 { font-size: 19px; }
  .about-intro p { font-size: 13px; line-height: 1.8; }
  .project-links { padding: 15px; }
  .project-link-buttons { display: grid; grid-template-columns: 1fr; }
  .project-link-buttons a { justify-content: center; min-height: 42px; }
  .about-author strong { font-size: 22px; }
  .contact-icons { display: grid; grid-template-columns: 1fr; gap: 9px; }
  .contact-icons a { justify-content: center; min-height: 44px; }
  .mobile-filter-apply {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 14px;
    border: 0;
    border-radius: 999px;
    color: #fff;
    background: var(--green);
    box-shadow: 0 7px 16px rgba(18, 102, 79, .22);
    font-size: 12px;
    font-weight: 900;
    cursor: pointer;
  }
}

@media (max-width: 420px) {
  .status { display: none; }
  .brand h1 { font-size: 14px; }
  .inline-controls.structured-controls { grid-template-columns: 1fr; }
  .details-grid { grid-template-columns: 1fr; }
  .detail-field.wide { grid-column: auto; }
  .tab { min-width: 54px; }
  .tab::before { font-size: 10px; }
}
