/* 3D map stage: the map fills the card; controls, side panel, legend and
   cards float over it as glass panels (dark in the command room, light in
   the atlas). */

.map-stage {
  position: relative;
  height: 800px;
  overflow: hidden;
  padding: 0;
  border: 0;
  background: #0e1a16;
  isolation: isolate;
}
.map3d {
  position: absolute;
  inset: 0;
  /* Its own stacking context: the labels' per-depth z-index (set by
     CSS2DRenderer) must not rise above the cards floating over the map. */
  z-index: 0;
}
.map3d canvas {
  display: block;
}
.map-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  /* CSS2DRenderer positions labels from the top left: keep this layer
     left-to-right; the text inside the labels stays right-to-left. */
  direction: ltr;
}
.map-labels > div {
  direction: rtl;
}
.glass {
  background: rgba(14, 28, 24, 0.62);
  border: 1px solid rgba(217, 196, 143, 0.18);
  backdrop-filter: blur(14px) saturate(1.3);
  color: #f3ecdc;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.map-stage.is-atlas .glass {
  background: rgba(255, 252, 244, 0.84);
  border-color: rgba(131, 117, 76, 0.22);
  color: var(--ink);
  box-shadow: 0 16px 40px rgba(78, 69, 41, 0.16);
}

/* Title and controls */
.map-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 22px 26px;
  pointer-events: none;
}
.map-top > * {
  pointer-events: auto;
}
.map-title h2 {
  font-size: 30px;
  font-weight: 800;
  color: #f4fbf9;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5);
}
.map-title p {
  color: rgba(233, 243, 241, 0.75);
  font-size: 15px;
  margin-top: 4px;
}
.map-stage.is-atlas .map-title h2 {
  color: var(--ink);
  text-shadow: 0 1px 12px rgba(255, 255, 255, 0.8);
}
.map-stage.is-atlas .map-title p {
  color: var(--gold-deep);
}
.title-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.btn.back {
  background: rgba(217, 196, 143, 0.16);
  border-color: rgba(217, 196, 143, 0.5);
  color: #f6e8c4;
  font-size: 14px;
}
.map-stage.is-atlas .btn.back {
  background: var(--card);
  border-color: var(--gold);
  color: var(--gold-deep);
}
.map-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.seg.glass {
  padding: 5px;
  border-radius: 999px;
}
.seg.glass button {
  color: inherit;
  opacity: 0.75;
  font-size: 15px;
}
.seg.glass button.on {
  opacity: 1;
  background: linear-gradient(135deg, #8d6a24, #d8b45e);
  color: #fff;
  box-shadow: 0 4px 14px rgba(216, 180, 94, 0.35);
}
.map-stage.is-atlas .seg.glass button.on {
  background: linear-gradient(135deg, #8d6a24, #d8b45e);
  box-shadow: 0 4px 14px rgba(141, 106, 36, 0.3);
}
.sector-chips {
  position: absolute;
  z-index: 3;
  top: 128px;
  left: 26px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 620px;
  justify-content: flex-end;
}
.sector-chips .chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(14, 28, 24, 0.6);
  color: #f3ecdc;
  border-color: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
}
.map-stage.is-atlas .sector-chips .chip {
  background: rgba(255, 252, 244, 0.88);
  color: var(--ink);
  border-color: var(--line);
}
.sector-chips .chip.is-on {
  color: #fff !important;
}
.sw {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* Floating side panel on the left */
.map-stage .side {
  position: absolute;
  z-index: 3;
  left: 22px;
  top: 190px;
  bottom: 22px;
  width: 340px;
  border-radius: 20px;
  padding: 18px 18px 16px;
  overflow-y: auto;
  gap: 10px;
}
.map-stage .side h3 {
  font-size: 20px;
}
.map-stage .side .hint {
  color: inherit;
  opacity: 0.65;
}
.map-stage .rank {
  color: inherit;
  padding: 6px 4px;
}
.map-stage .rank:hover {
  background: rgba(217, 196, 143, 0.08);
}
.map-stage.is-atlas .rank:hover {
  background: #faf6ec;
}
.map-stage .rank .bar {
  background: rgba(255, 255, 255, 0.08);
}
.map-stage .rank .bar i {
  background: linear-gradient(to left, #3c8e70, #e0bd68);
}
.map-stage.is-atlas .rank .bar {
  background: var(--gold-pale);
}
.map-stage.is-atlas .rank .bar i {
  background: linear-gradient(to left, #9db07a, #2f7a5f);
}
.map-stage .rank .tag {
  color: #e0bd68;
}
.map-stage.is-atlas .rank .tag {
  color: var(--late);
}
.map-stage .gp {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
  color: inherit;
  margin-top: 6px;
}
.map-stage .gp .top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.map-stage .gp .nm {
  display: flex;
  align-items: center;
  gap: 8px;
}
.map-stage .gp .mt {
  color: inherit;
  opacity: 0.7;
}
.map-stage .gp:hover,
.map-stage .gp.hl {
  border-color: #e0bd68;
  box-shadow: 0 0 0 1px #e0bd68, 0 10px 24px rgba(0, 0, 0, 0.3);
}
.map-stage.is-atlas .gp {
  background: var(--card);
  border-color: var(--line);
}
.map-stage.is-atlas .gp:hover,
.map-stage.is-atlas .gp.hl {
  border-color: var(--gold);
  box-shadow: 0 6px 18px rgba(78, 69, 41, 0.15);
}
.map-stage .group-k {
  color: #e0bd68;
}
.map-stage.is-atlas .group-k {
  color: var(--gold);
}
.map-stage .side .seg {
  background: rgba(255, 255, 255, 0.08);
}
.map-stage .side .seg button {
  color: inherit;
}
.map-stage .side .seg button.on {
  background: #3c8e70;
  color: #fff;
}
.map-stage.is-atlas .side .seg {
  background: var(--gold-pale);
}
.map-stage.is-atlas .side .seg button.on {
  background: var(--card);
  color: var(--ink);
}
.map-stage .side svg text,
.hovercard svg text {
  fill: currentColor;
}

/* Legend */
.legend3 {
  position: absolute;
  z-index: 3;
  right: 22px;
  bottom: 22px;
  border-radius: 14px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}
.lg-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.lg-row .ramp {
  width: 130px;
  height: 10px;
  border-radius: 5px;
}
.lg-k {
  opacity: 0.7;
}
.dotp {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dotp.decision {
  background: #f2b33d;
  box-shadow: 0 0 0 3px rgba(242, 179, 61, 0.3);
}
.dotp.late {
  background: #ff5a4e;
  box-shadow: 0 0 0 3px rgba(255, 90, 78, 0.3);
}

/* Labels in the scene */
.glabel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
  font-family: "Tajawal", sans-serif;
}
.glabel span {
  font-size: 13px;
  font-weight: 800;
  color: #e9f6f3;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
}
.glabel.zero {
  opacity: 0.5;
}
.badge3 {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(12, 22, 19, 0.82);
  border: 1px solid rgba(217, 196, 143, 0.35);
  display: grid;
  place-items: center;
}
.badge3 .ring {
  position: absolute;
  inset: 1px;
}
.badge3 b {
  font-size: 15px;
  color: #fff;
}
.badge3.st {
  width: auto;
  height: auto;
  border-radius: 8px;
  padding: 4px 6px;
}
.badge3 .stagebars {
  width: 50px;
  height: 22px;
}
.atlas .glabel span {
  color: var(--ink);
  text-shadow: 0 0 4px #fff, 0 0 8px #fff;
}
.atlas .badge3 {
  background: rgba(255, 253, 248, 0.94);
  border-color: rgba(131, 117, 76, 0.4);
  box-shadow: 0 4px 12px rgba(78, 69, 41, 0.18);
}
.atlas .badge3 b {
  color: var(--ink);
}
.gpulse {
  position: absolute;
  top: 0;
  left: 50%;
  width: 42px;
  height: 42px;
  margin-left: -21px;
  border-radius: 50%;
  animation: pulse 1.8s ease-out infinite;
}
.gpulse.decision,
.pinpulse.decision {
  border: 2px solid #f2b33d;
}
.gpulse.late,
.pinpulse.late {
  border: 2px solid #ff5a4e;
}
@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(2.2);
    opacity: 0;
  }
}
.pinpulse {
  width: 26px;
  height: 26px;
  border-radius: 50%;
}
.pinpulse.decision,
.pinpulse.late {
  animation: pulse 1.6s ease-out infinite;
}

.city {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: "Tajawal", sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: #3d3423;
}
.city i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3d3423;
  border: 1.5px solid #fff;
}
.city.r3 span {
  display: none;
}
.command .city {
  color: #9fc3d6;
}
.command .city i {
  background: #9fc3d6;
  border-color: #0b1626;
}
.river-name {
  font-family: "Tajawal", sans-serif;
  font-style: italic;
  font-size: 14px;
  font-weight: 700;
  color: #3b7fa3;
  text-shadow: 0 0 4px #fff;
}
.dlabel3 {
  font-family: "Tajawal", sans-serif;
  font-size: 14px;
  font-weight: 800;
  color: #ffe6a8;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.95);
  white-space: nowrap;
}
.atlas .dlabel3 {
  color: var(--gold-deep);
  text-shadow: 0 0 4px #fff, 0 0 8px #fff;
}

/* Hover card */
.hovercard {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  width: 280px;
  border-radius: 16px;
  padding: 12px 14px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.hovercard.on {
  opacity: 1;
}
.hc-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.hc-head b {
  font-size: 19px;
}
.hc-head span {
  opacity: 0.75;
  font-weight: 700;
}
.hc-body {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}
.hc-sectors {
  flex: 1;
}
.hc-sectors div {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
}
.hc-sectors i {
  width: 9px;
  height: 9px;
  border-radius: 3px;
}
.hc-sectors span {
  margin-right: auto;
  opacity: 0.7;
}
.hc-stages {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  height: 70px;
  align-items: flex-end;
}
.hc-st {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  height: 100%;
  font-size: 11px;
}
.hc-st .bar {
  flex: 1;
  width: 14px;
  display: flex;
  align-items: flex-end;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
}
.hc-st .bar i {
  width: 100%;
  background: linear-gradient(to top, #3c8e70, #e0bd68);
  border-radius: 4px;
}
.map-stage.is-atlas .hc-st .bar {
  background: var(--gold-pale);
}
.map-stage.is-atlas .hc-st .bar i {
  background: linear-gradient(to top, #2f7a5f, #9db07a);
}
.hc-st b {
  font-size: 12px;
}
.hc-st small {
  opacity: 0.7;
}
.hc-flag {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px 6px;
  border-radius: 8px;
}
.hc-flag.decision {
  background: rgba(242, 179, 61, 0.18);
  color: #f2b33d;
}
.hc-flag.late {
  background: rgba(255, 90, 78, 0.16);
  color: #ff7a6e;
}
.map-stage.is-atlas .hc-flag.decision {
  color: var(--dec);
}
.map-stage.is-atlas .hc-flag.late {
  color: var(--late);
}
.hc-hint {
  margin-top: 6px;
  font-size: 12px;
  opacity: 0.7;
}

/* Project card from a pin */
.pincard {
  position: absolute;
  z-index: 6;
  right: 22px;
  top: 140px;
  width: 360px;
  border-radius: 20px;
  overflow: hidden;
  transform: translateX(30px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.pincard.on {
  transform: none;
  opacity: 1;
  pointer-events: auto;
}
.pc-photo {
  height: 190px;
  background-size: cover;
  background-position: center;
  position: relative;
  display: grid;
  place-items: center;
}
.pc-photo span {
  position: absolute;
  bottom: 10px;
  right: 12px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  padding: 2px 10px 4px;
  border-radius: 999px;
}
.pc-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pc-body .top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.pc-body b {
  font-size: 19px;
}
.pc-body .mt {
  opacity: 0.75;
  font-size: 14px;
}
.pc-body .step {
  color: inherit;
  opacity: 0.85;
}
.pc-body .owner .o,
.pc-body .owner .k {
  color: inherit;
}
.pc-close {
  position: absolute;
  z-index: 2;
  top: 10px;
  left: 10px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 20px;
}

/* Compact header for a project without a site photo: the sector icon and
   name, instead of a large empty picture. */
.pc-photo.emblem {
  height: 96px;
  display: flex;
  justify-content: flex-start;
  gap: 14px;
  padding: 0 22px 0 56px;
}
.pc-photo.emblem em {
  font-style: normal;
  font-weight: 800;
  font-size: 17px;
  color: #fff;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.35);
}

/* Tablet and phone: the map keeps its own height at the top of the card,
   and the chips, legend and side panel follow below it instead of covering
   it. A project card opens as a sheet at the bottom of the map. */
@media (max-width: 1100px) {
  .map-stage {
    --map-h: 600px;
    height: auto;
    display: flex;
    flex-direction: column;
  }
  .map3d {
    position: relative;
    inset: auto;
    height: var(--map-h);
    flex-shrink: 0;
  }
  .sector-chips {
    position: static;
    max-width: none;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 14px 16px 4px;
    scrollbar-width: none;
  }
  .sector-chips .chip {
    flex-shrink: 0;
  }
  .sector-chips {
    order: 1;
  }
  .sector-chips:empty {
    display: none;
  }
  .legend3 {
    order: 2;
    position: static;
    align-self: flex-start;
    margin: 10px 16px 0;
  }
  .map-stage .side {
    position: static;
    width: auto;
    order: 3;
    max-height: 640px;
    overflow-y: auto;
    margin: 12px 16px 16px;
  }
  .pincard {
    top: auto;
    bottom: calc(100% - var(--map-h) + 14px);
    right: 14px;
    max-height: calc(var(--map-h) - 150px);
    overflow-y: auto;
    transform: translateY(24px);
  }
}
@media (max-width: 720px) {
  .map-stage {
    --map-h: 470px;
  }
  .map-top {
    flex-direction: column;
    gap: 10px;
    padding: 14px;
  }
  .map-title h2 {
    font-size: 22px;
  }
  .map-title p {
    font-size: 13px;
  }
  .map-controls {
    align-items: stretch;
    width: 100%;
    gap: 6px;
  }
  .seg.glass {
    display: flex;
    width: 100%;
  }
  .seg.glass button {
    flex: 1;
    font-size: 13px;
    padding: 6px 4px 8px;
    white-space: nowrap;
  }
  .pincard {
    left: 10px;
    right: 10px;
    width: auto;
    max-height: calc(var(--map-h) - 40px);
  }
  .hovercard {
    display: none;
  }
}

/* Capitals keep only their dot on the national view (the governorate
   label already names them); names return in the drill-down. */
.map3d:not(.focus) .city.cap span {
  display: none;
}
.stagebars .adv {
  fill: #e0bd68;
}
.stagebars .pre {
  fill: #6f7f99;
}
.atlas .stagebars .adv {
  fill: #3f7a62;
}
.atlas .stagebars .pre {
  fill: #d4c49a;
}
.map-stage .side .seg button {
  white-space: nowrap;
  font-size: 13px;
  padding: 5px 11px 7px;
}
.map-stage .side-split {
  flex-wrap: wrap;
}

/* Governorate badges answer clicks (small governorates are hard to hit). */
.glabel {
  pointer-events: auto;
  cursor: pointer;
}
.glabel:hover .badge3 {
  border-color: #ffd98a;
  box-shadow: 0 0 0 4px rgba(255, 217, 138, 0.18);
}

/* Project location marker */
.pin3 {
  pointer-events: auto;
  cursor: pointer;
}
.pin3-b {
  width: 26px;
  height: 34px;
  filter: drop-shadow(0 5px 6px rgba(0, 0, 0, 0.45));
  transform-origin: 50% 100%;
  transition: transform 0.18s ease;
  animation: pin3drop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
.pin3-b svg {
  display: block;
  width: 100%;
  height: 100%;
}
/* Marker B: sector colour, a white sector glyph, the status on its edge
   (white on track, amber on hold, red stalled). */
.pin3 .pd {
  fill: var(--c);
  stroke: #fff;
  stroke-width: 2.2;
}
.pin3.decision .pd {
  stroke: #f2b33a;
  stroke-width: 2.8;
}
.pin3.late .pd {
  stroke: #d2412b;
  stroke-width: 2.8;
}
.pin3:hover .pin3-b,
.pin3.hl .pin3-b {
  transform: scale(1.35);
}
.atlas .pin3-b {
  filter: drop-shadow(0 4px 5px rgba(78, 69, 41, 0.35));
}
@keyframes pin3drop {
  from {
    opacity: 0;
    transform: translateY(-14px) scale(0.7);
  }
}
