/* 3D GPS uplift view.
   Reuses the .d3-* layout primitives from app.css (sidebar, fields, stage) so
   this panel matches the existing 3D Depth view; only the pieces unique to the
   uplift map are defined here. */

#panel-uplift3d .d3-stage {
  /* MapLibre paints its own background, so unlike the Three.js stage this one
     does not need the radial gradient. */
  background: var(--bg-sunken);
}

/* The stage is a grid cell; MapLibre must fill it rather than escape to the
   panel. An absolutely positioned map with inset:0 resolves against the
   nearest positioned ancestor and covered the sidebar. */
#panel-uplift3d .maplibregl-map {
  position: relative;
  width: 100%;
  height: 100%;
}

/* MapLibre's default controls are built for light backgrounds; tone them into
   the dashboard palette. */
#panel-uplift3d .maplibregl-ctrl-group {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

#panel-uplift3d .maplibregl-ctrl-group button + button {
  border-top: 1px solid var(--line);
}

#panel-uplift3d .maplibregl-ctrl-icon {
  filter: var(--up3d-ctrl-filter, invert(1) opacity(0.75));
}

:root[data-theme='light'] #panel-uplift3d .maplibregl-ctrl-icon {
  --up3d-ctrl-filter: none;
}

#panel-uplift3d .maplibregl-ctrl-attrib {
  background: color-mix(in srgb, var(--bg-raised) 88%, transparent);
  color: var(--ink-faint);
  font-size: 10px;
}

#panel-uplift3d .maplibregl-ctrl-attrib a {
  color: var(--ink-soft);
}

/* Legend: the diverging scale is the key to reading the map, so it sits
   over the stage rather than in the sidebar. */
.up3d-legend {
  position: absolute;
  bottom: 46px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  background: color-mix(in srgb, var(--bg-raised) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.up3d-legend-caption {
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.up3d-legend-bar {
  width: 190px;
  height: 9px;
  border-radius: 5px;
  border: 1px solid var(--line);
}

.up3d-status {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 400;
  margin: 0;
  padding: 5px 11px;
  background: color-mix(in srgb, var(--bg-raised) 90%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
}

/* The detail card and status card both anchor top-left; when a station is
   selected the card takes over, so move the status line clear of it. A fixed
   top offset was not enough: the card grows with its caveat lines and hid the
   status underneath it. */
#panel-uplift3d .d3-detail:not([hidden]) ~ .up3d-status {
  top: auto;
  bottom: 90px;
}

.up3d-buttons {
  display: flex;
  gap: 8px;
}

.up3d-buttons button {
  flex: 1;
  padding: 7px 9px;
  font: inherit;
  font-size: 11.5px;
  color: var(--ink-soft);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.up3d-buttons button:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.up3d-buttons button[aria-pressed='true'] {
  color: var(--magma-strong);
  border-color: color-mix(in srgb, var(--magma) 45%, var(--line));
}

.up3d-buttons button:focus-visible {
  outline: 2px solid var(--magma-strong);
  outline-offset: 1px;
}

.up3d-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.up3d-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: var(--ink-faint);
}

.up3d-stat strong {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 11.5px;
  color: var(--ink);
  text-align: right;
}

.up3d-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  overflow-y: auto;
}

.up3d-list button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 7px;
  font: inherit;
  font-size: 11.5px;
  color: var(--ink-soft);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
}

.up3d-list button:hover {
  background: var(--bg-raised);
  color: var(--ink);
}

.up3d-list button.is-active {
  border-color: color-mix(in srgb, var(--magma) 45%, var(--line));
  background: var(--bg-raised);
  color: var(--ink);
}

.up3d-list button:focus-visible {
  outline: 2px solid var(--magma-strong);
  outline-offset: 1px;
}

.up3d-swatch {
  width: 11px;
  height: 11px;
  flex: none;
  border-radius: 3px;
  border: 1px solid var(--line);
}

.up3d-code {
  font-family: var(--font-mono);
  flex: 1;
}

.up3d-val {
  font-family: var(--font-mono);
  color: var(--ink);
}

.up3d-note,
.up3d-empty {
  margin: 0;
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--ink-faint);
}

.up3d-note strong {
  color: var(--ink-soft);
  font-weight: 500;
}

/* The mobile nav is a fixed 4-column grid sized for the original six tabs.
   With a seventh it needs four columns over two rows, and the taller bar has
   to be reflected in the shell's bottom padding so content is not hidden. */
@media (max-width: 760px) {
  .shell {
    padding-bottom: calc(104px + env(safe-area-inset-bottom));
  }

  .view-nav {
    height: calc(104px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 52px;
  }

  /* On a phone the map is the point of the view, so it leads; the controls
     and ranking scroll beneath it rather than pushing it off-screen. */
  #panel-uplift3d .d3-layout {
    display: flex;
    flex-direction: column;
    overflow: auto;
  }

  #panel-uplift3d .d3-stage {
    order: -1;
    flex: none;
    height: 62vh;
    min-height: 340px;
  }

  #panel-uplift3d .d3-sidebar {
    flex: none;
    overflow: visible;
    border-right: none;
    border-top: 1px solid var(--line);
  }

  #panel-uplift3d .up3d-list {
    overflow: visible;
  }

  /* Clear of MapLibre's attribution bar, which sits at the bottom edge. */
  .up3d-legend {
    bottom: 34px;
    font-size: 9px;
    gap: 7px;
    padding: 5px 10px;
  }

  .up3d-legend-bar {
    width: 110px;
  }

  .up3d-legend-caption {
    display: none;
  }

  #panel-uplift3d .globe-hint {
    display: none;
  }
}

/* Short-window noise warning and the matching per-station caveat. Amber rather
   than red: the data is valid, it just cannot resolve a trend this short. */
.up3d-warn {
  margin: 0;
  padding: 7px 9px;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--sulphur);
  background: color-mix(in srgb, var(--sulphur) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--sulphur) 35%, var(--line));
  border-radius: var(--radius-sm);
}

.up3d-caveat {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--sulphur);
}

/* The raw-minus-median arithmetic behind the headline figure. It reconciles
   the card with the raw displacement graph, so it reads as quiet supporting
   detail rather than a warning. */
.up3d-breakdown {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-soft);
  line-height: 1.45;
}

/* A removed equipment offset is a correction, not a warning about the value,
   so it reads quieter than the noise caveat. */
.up3d-offset {
  color: var(--ink-soft);
  line-height: 1.45;
}

.up3d-details-button {
  align-self: flex-start;
  margin-top: 6px;
  padding: 7px 16px;
  min-height: 36px;
  border: 1px solid var(--magma);
  border-radius: 6px;
  background: var(--bg);
  color: var(--magma);
  font: 600 12px var(--font-ui);
  cursor: pointer;
}
.up3d-details-button:hover { background: var(--bg-raised); }
.up3d-details-button:focus-visible { outline: 2px solid var(--magma); outline-offset: 3px; }

.gps-station-dialog { width:min(840px,calc(100vw - 32px));max-height:calc(100dvh - 32px);box-sizing:border-box;overflow:auto;padding:22px;border:1px solid var(--line-strong);border-radius:12px;background:var(--bg-raised);color:var(--ink);box-shadow:0 20px 80px #0008; }
.gps-station-dialog::backdrop { background:#061017b8; }
.gps-dialog-header { display:flex;align-items:flex-start;justify-content:space-between;gap:16px; }
.gps-dialog-header h2 { font-size:20px;margin:0 0 5px; }
.gps-dialog-header p,#gpsDialogStatus { color:var(--ink-soft);font-size:12px; }
#gpsDialogClose { flex:none;width:40px;height:40px;border:1px solid var(--line-strong);border-radius:6px;color:var(--ink);background:var(--bg);font-size:26px;cursor:pointer; }
#gpsDialogRetry { padding:8px 16px;background:var(--bg);color:var(--magma);border:1px solid var(--magma);border-radius:6px;cursor:pointer; }
#gpsDialogChart { display:block;width:100%;height:320px; }
#gpsDialogReadout { min-height:32px;font:11px/1.5 var(--font-mono);color:var(--ink-soft); }
.gps-dialog-note { font-size:11px;line-height:1.6;color:var(--ink-faint);margin-bottom:0; }
.gps-station-dialog :focus-visible { outline:2px solid var(--magma);outline-offset:3px; }
@media(max-width:600px) { .gps-station-dialog { padding:14px; } .gps-dialog-header h2 { font-size:17px; } #gpsDialogChart { height:260px; } }
