/* Page chrome follows the Moshun design system (design.moshun.earth):
   Deep Black / Cream neutrals, Orange for accents, Hauora type,
   the 8px / 24px spacing scale and the 6-step radius scale.
   Layer colours (seagrass, cables, pipelines, BEAT classes) encode data and stay as they are. */

@font-face { font-family: 'Hauora'; font-weight: 300; font-style: normal; font-display: swap; src: url(./fonts/Hauora-Light.woff2) format('woff2'); }
@font-face { font-family: 'Hauora'; font-weight: 500; font-style: normal; font-display: swap; src: url(./fonts/Hauora-Medium.woff2) format('woff2'); }
@font-face { font-family: 'Hauora'; font-weight: 700; font-style: normal; font-display: swap; src: url(./fonts/Hauora-Bold.woff2) format('woff2'); }

:root {
  /* design-system tokens */
  --color-cream: #FFEEE1;
  --color-deep-black: #161E1D;
  --color-c-72: rgba(255, 238, 225, 0.72);
  --color-c-48: rgba(255, 238, 225, 0.48);
  --color-c-12: rgba(255, 238, 225, 0.12);
  --color-c-08: rgba(255, 238, 225, 0.08);
  --color-c-04: rgba(255, 238, 225, 0.04);
  --color-orange: #F08254;
  --color-deep-orange: #FF5722;
  --color-border-focus: #7EC8C0;
  --radius-1: 4px;
  --radius-2: 6px;
  --radius-4: 12px;
  --space-tight: 8px;
  --space-loose: 24px;
  --font-sans: 'Hauora', ui-sans-serif, system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;

  /* semantic aliases used below */
  --bg: var(--color-deep-black);
  --panel: rgba(22, 30, 29, 0.92);
  --panel-border: var(--color-c-08);
  --fg: var(--color-cream);
  --fg-soft: var(--color-c-72);
  --muted: var(--color-c-48);
  --accent: var(--color-orange);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --topbar-h: 56px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 300 14px/20px var(--font-sans);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 2px solid var(--color-border-focus); outline-offset: 2px; }

#map { position: fixed; inset: var(--topbar-h) 0 0 0; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 var(--space-loose);
  background: var(--bg);
  border-bottom: 1px solid var(--panel-border);
  z-index: 10;
}
.topbar img { height: 16px; width: auto; display: block; }

/* ---------- panel ---------- */
.panel {
  position: fixed;
  top: calc(var(--topbar-h) + var(--space-tight));
  left: var(--space-tight);
  width: 320px;
  max-height: calc(100vh - var(--topbar-h) - 2 * var(--space-tight));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-loose);
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--color-deep-orange);
  border-radius: var(--radius-4);
  box-shadow: var(--shadow);
  z-index: 5;
  transition: transform 0.22s ease, opacity 0.22s ease;
}
.panel.hidden { transform: translateX(calc(-100% - 20px)); opacity: 0; pointer-events: none; }

/* Card title, then Caption text */
.panel-head h1 { margin: 0; font-size: 18px; line-height: 24px; font-weight: 500; }
.panel-head .sub { margin: 4px 0 var(--space-loose); font-size: 12px; line-height: 18px; color: var(--muted); }

.panel-toggle {
  position: fixed;
  top: calc(var(--topbar-h) + var(--space-tight));
  left: var(--space-tight);
  z-index: 6;
  width: 36px;
  height: 36px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-2);
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--fg);
  font-size: 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.panel-toggle.show { display: flex; }

.group { border-top: 1px solid var(--panel-border); padding: var(--space-tight) 0; }
.group:first-of-type { border-top: 0; padding-top: 0; }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-tight); min-height: 24px; }
.group .body { padding: var(--space-tight) 0 0 24px; display: grid; gap: var(--space-tight); }
.group.off .body { display: none; }

.switch { display: flex; align-items: center; gap: var(--space-tight); cursor: pointer; user-select: none; }
.switch input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c, #fff); box-shadow: 0 0 9px var(--c, #fff); flex: none; }
.name { font-weight: 500; font-size: 14px; }
/* Caption title */
.name.plain { color: var(--muted); font-weight: 700; font-size: 12px; line-height: 18px; text-transform: uppercase; letter-spacing: 0.01em; }
.count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.check { display: flex; align-items: center; gap: var(--space-tight); font-size: 13px; color: var(--fg-soft); cursor: pointer; }
.check input { accent-color: var(--accent); cursor: pointer; }
.check em { color: var(--muted); font-style: normal; font-size: 12px; }

.slider { display: flex; align-items: center; gap: var(--space-tight); font-size: 12px; color: var(--muted); }
.slider input { flex: 1; accent-color: var(--accent); }

/* Button M: Hauora 300 14/20, radius-2 */
.select, .btn {
  width: 100%;
  padding: 5px var(--space-tight);
  font: inherit;
  font-size: 14px;
  line-height: 20px;
  color: var(--fg);
  background: var(--color-c-04);
  border: 1px solid var(--color-c-12);
  border-radius: var(--radius-2);
  cursor: pointer;
}
.btn:hover, .select:hover { background: var(--color-c-08); }
.select option, .select optgroup { background: var(--bg); color: var(--fg); }

.note { margin: 0; font-size: 12px; line-height: 18px; color: var(--muted); }
.legend-img { max-width: 100%; background: rgba(255, 238, 225, 0.92); border-radius: var(--radius-1); padding: 4px; }
.legend-img:not([src]), .legend-img[src=""] { display: none; }

.legend { display: grid; gap: 4px; font-size: 12px; color: var(--fg-soft); }
.legend .row { display: flex; align-items: center; gap: var(--space-tight); }
.legend .sw { width: 14px; height: 10px; border-radius: 2px; flex: none; border: 1px solid var(--color-c-12); }
.legend em { color: var(--muted); font-style: normal; font-size: 12px; margin-left: auto; font-variant-numeric: tabular-nums; }

.sources { border-top: 1px solid var(--panel-border); padding-top: var(--space-tight); margin-top: 4px; }
.sources summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.sources h4 { margin: var(--space-tight) 0 2px; font-size: 12px; font-weight: 500; }
.sources p { margin: 0 0 var(--space-tight); font-size: 12px; line-height: 18px; color: var(--muted); }
.sources a, .pop a { color: var(--fg); text-decoration: underline; text-decoration-color: var(--color-c-48); text-underline-offset: 2px; word-break: break-all; }
.sources a:hover, .pop a:hover { text-decoration-color: var(--accent); }

/* ---------- start-up zoom chooser ---------- */
.zoom-chooser {
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-tight);
  background: rgba(22, 30, 29, 0.55);
  z-index: 8;
}
.zoom-chooser.gone { display: none; }

.zoom-card {
  position: relative;
  width: 360px;
  max-width: 100%;
  display: grid;
  gap: var(--space-tight);
  padding: var(--space-loose);
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--color-deep-orange);
  border-radius: var(--radius-4);
  box-shadow: var(--shadow);
}
.zoom-card h2 { margin: 0 0 var(--space-tight); padding-right: var(--space-loose); font-size: 18px; line-height: 24px; font-weight: 500; }
.zoom-label { color: var(--muted); font-weight: 700; font-size: 12px; line-height: 18px; text-transform: uppercase; letter-spacing: 0.01em; }
.zoom-close {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 2px 7px;
  font-size: 15px;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}
.zoom-close:hover { color: var(--fg); }

.combo { position: relative; margin-bottom: var(--space-tight); }
.combo .select { cursor: text; }
.commune-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--color-c-12);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow);
  z-index: 1;
}
.commune-list:empty { display: none; }
.commune-list li { display: flex; justify-content: space-between; gap: var(--space-tight); padding: 5px var(--space-tight); border-radius: var(--radius-1); cursor: pointer; }
.commune-list li.active, .commune-list li:hover { background: var(--color-c-08); }
.commune-list li em { color: var(--muted); font-style: normal; font-size: 12px; font-variant-numeric: tabular-nums; }
.commune-list li.empty { color: var(--muted); cursor: default; background: none; }

/* ---------- status toast ---------- */
.status {
  position: fixed;
  bottom: var(--space-loose);
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 16px;
  font-size: 13px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 5;
  transition: opacity 0.3s ease;
}
.status.gone { opacity: 0; pointer-events: none; }

/* ---------- popups ---------- */
.maplibregl-popup-content {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-4);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  max-width: 300px;
  font-family: var(--font-sans);
  font-size: 13px;
}
.maplibregl-popup-tip { border-top-color: var(--panel) !important; border-bottom-color: var(--panel) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 17px; padding: 2px 7px; }
.pop h3 { margin: 0 0 var(--space-tight); font-size: 14px; font-weight: 500; }
/* Caption title on an Orange pill */
.pop .tag { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 0.01em; text-transform: uppercase; color: var(--color-deep-black); background: var(--accent); border-radius: 999px; padding: 1px var(--space-tight); margin-bottom: var(--space-tight); }
.pop table { border-collapse: collapse; width: 100%; }
.pop td { padding: 2px 0; vertical-align: top; }
.pop .sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: baseline; }
.pop td:first-child { color: var(--muted); padding-right: 10px; white-space: nowrap; }
.pop .src { margin: var(--space-tight) 0 0; font-size: 12px; color: var(--muted); border-top: 1px solid var(--panel-border); padding-top: var(--space-tight); }

.maplibregl-ctrl-group { background: var(--panel) !important; border: 1px solid var(--panel-border); border-radius: var(--radius-2) !important; }
.maplibregl-ctrl-group button { filter: invert(1) hue-rotate(180deg); }
.maplibregl-ctrl-scale { background: var(--panel); color: var(--fg); border-color: var(--panel-border); font-family: var(--font-sans); }
.maplibregl-ctrl-attrib { background: rgba(22, 30, 29, 0.82) !important; font-family: var(--font-sans); }
.maplibregl-ctrl-attrib a { color: var(--fg-soft) !important; }

@media (max-width: 620px) {
  .topbar { padding: 0 var(--space-tight) 0 56px; }
  .panel-toggle { top: 10px; z-index: 11; display: flex; }
  .panel { width: calc(100vw - 2 * var(--space-tight)); padding: var(--space-loose) var(--space-tight); }
}
