/* Palette roles come from the validated dark instance of the data-viz reference
   palette. Operator hues are ordered blue -> orange -> aqua -> yellow -> magenta,
   which clears the adjacent pairlist in dark mode (worst CVD dE 8.4, normal 19.3).
   They are used ONLY in this vertical, always-text-labelled filter list: the same
   five hues fail the all-pairs gate, so map marks never carry operator identity
   by colour. Map colour carries magnitude via a single-hue ordinal ramp. */
:root {
  color-scheme: dark;

  --surface-1: #1a1a19;
  --surface-2: #232322;
  --surface-3: #2f2f2d;
  --border: #3a3a37;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8a8a80;
  --accent: #3987e5;

  --op-cyta: #3987e5;
  --op-epic: #d95926;
  --op-primetel: #199e70;
  --op-cablenet: #c98500;
  --op-inmarsat: #d55181;

  --radius: 8px;
  --shadow: 0 4px 16px rgba(0, 0, 0, .45);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 14px;
  background: var(--surface-1);
  color: var(--text-primary);
}

#map { position: absolute; inset: 0; z-index: 0; background: var(--surface-1); }

/* Mast canvas sits above tiles, below controls, and never takes pointer events --
   hit-testing runs off map events so dragging keeps working. */
#mast-canvas { position: absolute; inset: 0; z-index: 400; pointer-events: none; }

.panelish {
  background: rgba(26, 26, 25, .88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- top bar ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 1000;
  display: flex; align-items: center; gap: .5rem;
  padding: .6rem .75rem;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
#topbar .spacer { flex: 1; pointer-events: none; }

#topbar h1 {
  background: rgba(26, 26, 25, .88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .4rem .8rem;
  font-size: .95rem; font-weight: 650; letter-spacing: -.01em; white-space: nowrap;
}
#topbar h1 .accent { color: var(--accent); }
#topbar h1 > span:first-child { white-space: nowrap; }

/* The country sits beside the name rather than inside it, so a second country
   is a data change and not a rebrand. */
.region {
  margin-left: .45rem; padding: .1rem .35rem;
  font-size: .68rem; font-weight: 500; letter-spacing: .02em;
  color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: 4px;
  vertical-align: middle;
}

/* Inside the title chip: on bare imagery this text is unreadable over bright
   urban tiles, so it rides the panel background rather than the map. */
.count {
  margin-left: .4rem; font-size: .72rem; font-weight: 400; color: var(--text-muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

#search {
  flex: 1 1 14rem; max-width: 22rem;
  background: rgba(26, 26, 25, .88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .45rem .7rem;
  font: inherit; font-size: .85rem; color: var(--text-primary);
  outline: none;
}
#search:focus-visible { border-color: var(--accent); }
#search::placeholder { color: var(--text-muted); }

.chip {
  background: rgba(26, 26, 25, .88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .45rem .7rem;
  font: inherit; font-size: .8rem; color: var(--text-secondary);
  cursor: pointer; white-space: nowrap;
}
.chip:hover { color: var(--text-primary); border-color: #4d4d49; }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip.wide { width: 100%; text-align: center; margin-top: .25rem; }

/* ---------- filter panel ---------- */
#panel {
  position: absolute; top: 3.4rem; left: .75rem; z-index: 900;
  width: 15.5rem; max-height: calc(100% - 11rem);   /* leave room for the legend below */
  display: flex; flex-direction: column; gap: .4rem;
}
.panel-toggle { align-self: flex-start; }

#panel-body {
  background: rgba(26, 26, 25, .88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .7rem;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: .85rem;
}
#panel-body[hidden] { display: none; }

#panel section { display: flex; flex-direction: column; gap: .35rem; }
#panel h2 {
  font-size: .68rem; font-weight: 650; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-muted);
  display: flex; justify-content: space-between; align-items: baseline; gap: .5rem;
}
#panel h2 output { font-size: .72rem; color: var(--text-secondary); text-transform: none; letter-spacing: 0; }

.checks { display: flex; flex-direction: column; gap: .25rem; }
.checks.inline { flex-direction: row; flex-wrap: wrap; gap: .3rem .7rem; }

label.row, .checks label {
  display: flex; align-items: center; gap: .4rem;
  font-size: .82rem; color: var(--text-secondary); cursor: pointer;
}
label.row:hover, .checks label:hover { color: var(--text-primary); }
.checks input, label.row input { accent-color: var(--accent); flex: none; }

/* Operator identity: a hue swatch that always sits beside its text label. */
.dot { width: .6rem; height: .6rem; border-radius: 50%; flex: none; box-shadow: 0 0 0 1px rgba(0,0,0,.5); }
.tally { margin-left: auto; font-size: .7rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

select {
  background: var(--surface-2); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 6px;
  padding: .35rem .4rem; font: inherit; font-size: .8rem; width: 100%;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }

.note { font-size: .7rem; line-height: 1.45; color: var(--text-muted); }
.hint { font-size: .68rem; color: var(--text-muted); font-style: normal; }

/* ---------- legend ---------- */
#legend {
  position: absolute; bottom: 1.1rem; left: .75rem; z-index: 900;
  background: rgba(26, 26, 25, .88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .55rem .7rem; max-width: 15.5rem;
}
#legend h3 {
  font-size: .66rem; font-weight: 650; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-muted); margin-bottom: .4rem;
}
.ramp { display: flex; align-items: center; gap: .3rem; }
.ramp i { width: 1.5rem; height: .5rem; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0,0,0,.4); }
.ramp-labels { display: flex; justify-content: space-between; font-size: .68rem; color: var(--text-secondary); margin-top: .25rem; }
.legend-rows { display: flex; flex-direction: column; gap: .22rem; }
.legend-rows div { display: flex; align-items: center; gap: .4rem; font-size: .74rem; color: var(--text-secondary); }
#legend .foot { margin-top: .45rem; font-size: .66rem; line-height: 1.4; color: var(--text-muted); }

.locate { position: absolute; right: .75rem; bottom: 5.2rem; z-index: 900; font-size: 1rem; line-height: 1; padding: .5rem .6rem; }

/* ---------- tooltip ---------- */
#tooltip {
  position: absolute; z-index: 1100; pointer-events: none;
  background: rgba(26, 26, 25, .95);
  border: 1px solid var(--border); border-radius: 6px;
  padding: .3rem .5rem; font-size: .76rem; white-space: nowrap;
  box-shadow: var(--shadow); transform: translate(.6rem, -50%);
}
#tooltip b { font-weight: 600; }
#tooltip span { color: var(--text-muted); }

/* ---------- popup ---------- */
.leaflet-popup-content-wrapper {
  background: rgba(26, 26, 25, .96); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.leaflet-popup-content {
  margin: .7rem .8rem; font-size: .8rem; line-height: 1.5; width: 20rem !important;
  max-height: min(62vh, 34rem); overflow-y: auto; overscroll-behavior: contain;
}
.leaflet-popup-tip { background: rgba(26, 26, 25, .96); border: 1px solid var(--border); }
.leaflet-container a.leaflet-popup-close-button { color: var(--text-muted); }
.leaflet-container a.leaflet-popup-close-button:hover { color: var(--text-primary); }

.pop h3 { font-size: .9rem; font-weight: 650; margin-bottom: .1rem; }
.pop .sub { color: var(--text-secondary); font-size: .76rem; }
.pop .facts { display: flex; flex-wrap: wrap; gap: .2rem .5rem; margin: .45rem 0; font-size: .75rem; color: var(--text-secondary); }
.pop .facts b { color: var(--text-primary); font-weight: 600; }
.pop .tenant { border-top: 1px solid var(--border); padding-top: .4rem; margin-top: .4rem; }
.pop .tenant-name { display: flex; align-items: center; gap: .4rem; font-weight: 600; font-size: .78rem; }
.pop .bands { display: flex; flex-wrap: wrap; gap: .2rem; margin-top: .25rem; }
.pop .band {
  font-size: .66rem; padding: .07rem .3rem; border-radius: 3px;
  background: var(--surface-3); color: var(--text-secondary); white-space: nowrap;
}
.pop .band.g5 { color: #fff; background: #256abf; }
.pop .band.flag { border: 1px dashed #8a8a80; }
.pop .emf { margin-top: .3rem; font-size: .73rem; color: var(--text-secondary); }
.pop .emf b { color: var(--text-primary); }
.pop .photos { display: flex; gap: .25rem; margin-top: .5rem; flex-wrap: wrap; }
.pop .photos img {
  width: 3.6rem; height: 3.6rem; object-fit: cover; border-radius: 4px;
  border: 1px solid var(--border); cursor: pointer; background: var(--surface-2);
}
.pop .prov { margin-top: .5rem; font-size: .68rem; color: var(--text-muted); }
.pop .alts { margin-top: .3rem; font-size: .7rem; color: var(--text-muted); }
.pop .alts summary { cursor: pointer; }
.pop a { color: var(--accent); }

/* ---------- modals ---------- */
#about, #lightbox {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0, 0, 0, .72);
  display: flex; align-items: center; justify-content: center; padding: 1.25rem;
}
#about[hidden], #lightbox[hidden] { display: none; }

.modal {
  position: relative;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow);
  max-width: 40rem; max-height: 85vh; overflow-y: auto; padding: 1.4rem 1.5rem;
}
.modal-close {
  position: absolute; top: .5rem; right: .6rem;
  background: none; border: none; color: var(--text-muted);
  font-size: 1.5rem; line-height: 1; cursor: pointer;
}
.modal-close:hover { color: var(--text-primary); }

#about-body h2 { font-size: 1.05rem; margin-bottom: .6rem; }
#about-body .tagline {
  font-size: .95rem; color: var(--text-primary);
  margin: -.35rem 0 .8rem; letter-spacing: -.005em;
}
#about-body h3 { font-size: .82rem; margin: 1rem 0 .3rem; color: var(--text-primary); }
#about-body p, #about-body li { font-size: .82rem; line-height: 1.6; color: var(--text-secondary); }
#about-body ul { padding-left: 1.1rem; display: flex; flex-direction: column; gap: .4rem; }
#about-body a { color: var(--accent); }
#about-body .foot { margin-top: 1rem; font-size: .76rem; color: var(--text-muted); }

#lightbox figure { max-width: 100%; max-height: 100%; text-align: center; }
#lightbox img { max-width: min(88vw, 60rem); max-height: 78vh; border-radius: 6px; }
#lightbox figcaption { margin-top: .5rem; font-size: .8rem; color: var(--text-secondary); }
.lb-nav {
  background: rgba(26,26,25,.8); border: 1px solid var(--border); color: var(--text-primary);
  border-radius: 50%; width: 2.4rem; height: 2.4rem; cursor: pointer; flex: none;
  font-size: 1rem; margin: 0 .6rem;
}
.lb-nav:disabled { opacity: .3; cursor: default; }

/* ---------- leaflet chrome ---------- */
.leaflet-control-attribution {
  background: rgba(26, 26, 25, .85) !important;
  color: var(--text-muted) !important; font-size: .66rem !important;
}
.leaflet-control-attribution a { color: var(--text-secondary) !important; }
.leaflet-bar a {
  background: var(--surface-2); color: var(--text-primary); border-bottom-color: var(--border);
}
.leaflet-bar a:hover { background: var(--surface-3); }

/* ---------- narrow screens ---------- */
@media (max-width: 640px) {
  #panel { width: calc(100% - 1.5rem); max-height: 55%; }
  #legend { display: none; }
  #topbar h1 { font-size: .82rem; }
  #topbar .count { display: none; }
  .leaflet-popup-content { width: 15rem !important; }
}
