/* Measure tools on the Open Map (static/js/open_map_measure_tools.js).
   Its own file, loaded by this page alone, so it goes with the feature.

   On the map's glass like every other control here, with the same palette
   re-pointing open_map.css gives them (--ink-2/3 become --ink on the glass,
   because contrast is worked out over the worst thing that can show through).
   No coloured side bars: a panel is a panel. */

.nh-measure,
.nh-measure-banner,
.nh-measure-tool {
  color: var(--ink);
  --ink-2: var(--ink);
  --ink-3: var(--ink);
  --surface: var(--nh-glass-well);
  --surface-2: var(--nh-glass-well);
  --line: var(--nh-glass-line);
  --line-strong: var(--nh-glass-line-strong);
  --nh-measure-draw: #A21CAF;          /* the drawn line's fuchsia, as text: 6.4:1 on white */
  --nh-measure-steep: var(--nh-glass-critical);
}
body.dark-mode .nh-measure,
body.dark-mode .nh-measure-banner,
body.dark-mode .nh-measure-tool {
  --nh-measure-draw: #F5D0FE;          /* 11:1 on the dark glass */
}

/* --- the Tools menu entry ------------------------------------------------ */
.nh-measure-tool__title {
  margin: 0 0 4px;
  font-size: 0.82rem;
  font-weight: 600;
}
.nh-measure-tool__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.maplibregl-ctrl button.nh-measure-tool__btn {
  width: 100%; height: auto; min-height: 30px;
  padding: 4px 6px;
  font: inherit; font-size: 0.78rem; font-weight: 600;
  color: var(--ink);
  background: var(--nh-glass-well);
  border: 1px solid var(--nh-glass-line-strong);
  border-radius: var(--r-sm, 6px);
  cursor: pointer;
}
.maplibregl-ctrl button.nh-measure-tool__btn.is-on,
.maplibregl-ctrl button.nh-measure-tool__btn.is-on:not(:disabled):hover {
  color: var(--accent-ink, #fff);
  background: var(--accent, #1F6D8F);
  border-color: var(--accent, #1F6D8F);
}

/* --- the banner ----------------------------------------------------------- */
.nh-measure-banner {
  position: absolute;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: flex; align-items: center; gap: 10px;
  max-width: min(640px, calc(100% - 24px));
  padding: 6px 6px 6px 12px;
  background: var(--nh-glass-solid);
  border: 1px solid var(--nh-glass-line-strong);
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
  font-size: 0.82rem;
}
.nh-measure-banner[hidden] { display: none; }
.nh-measure-banner__text { margin: 0; line-height: 1.3; font-weight: 600; }
.nh-measure-banner__exit {
  flex: none;
  min-height: 30px; padding: 3px 14px;
  font: inherit; font-weight: 700;
  color: var(--accent-ink, #fff);
  background: var(--accent, #1F6D8F);
  border: 0; border-radius: 999px;
  cursor: pointer;
}
.nh-measure-banner__exit:hover { background: var(--accent-hover, #175571); }

/* --- the panel ------------------------------------------------------------ */
.nh-measure {
  position: absolute;
  top: 56px; right: 10px;
  z-index: 5;
  width: 330px; max-width: calc(100% - 20px);
  max-height: calc(100% - 110px);
  overflow-y: auto;
  padding: 10px 12px 12px;
  background: var(--nh-glass-solid);
  border: 1px solid var(--nh-glass-line);
  border-radius: var(--r-md, 10px);
  box-shadow: 0 2px 14px rgba(15, 23, 42, 0.25);
  font-size: 0.84rem;
}
.nh-measure[hidden] { display: none; }
.nh-measure__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.nh-measure__title { margin: 0; font-size: 1rem; font-weight: 700; }
.nh-measure__close {
  width: 30px; height: 30px;
  border: 0; border-radius: var(--r-sm, 6px);
  background: var(--nh-glass-well); color: inherit;
  font-size: 1.2rem; line-height: 1; cursor: pointer;
}

.nh-measure__tabs,
.nh-measure__units {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  margin-top: 8px;
}
.nh-measure__unitsLabel { margin-right: 4px; font-size: 0.78rem; }
.nh-measure__seg {
  min-height: 30px; padding: 3px 10px;
  font: inherit; font-size: 0.78rem; font-weight: 600;
  color: var(--ink);
  background: var(--nh-glass-well);
  border: 1px solid var(--nh-glass-line-strong);
  border-radius: 999px;
  cursor: pointer;
}
.nh-measure__seg.is-on {
  color: var(--accent-ink, #fff);
  background: var(--accent, #1F6D8F);
  border-color: var(--accent, #1F6D8F);
}

.nh-measure__status { margin: 8px 0 0; font-weight: 600; }
.nh-measure__status:empty { display: none; }

.nh-measure__results { margin: 8px 0 0; }
.nh-measure__row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 3px 0;
  border-bottom: 1px solid var(--nh-glass-line);
}
.nh-measure__row dt { font-weight: 400; }
.nh-measure__row dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.nh-measure__row.is-total dd { font-size: 1.05rem; color: var(--nh-measure-draw); }
.nh-measure__row.is-steep dd { color: var(--nh-measure-steep); }

.nh-measure__legs {
  margin: 6px 0 0; padding-left: 0; list-style: none;
  max-height: 7.5em; overflow-y: auto;
  font-size: 0.78rem; font-variant-numeric: tabular-nums;
}
.nh-measure__legs:empty { display: none; }

.nh-measure__chart { margin-top: 8px; }
.nh-measure__chart[hidden] { display: none; }
.nh-measure__plot { position: relative; }
.nh-measure__svg {
  display: block; width: 100%; overflow: visible;
  touch-action: pan-y; cursor: crosshair; border-radius: 4px;
}
.nh-measure__svg:focus-visible { outline: 2px solid var(--accent-ring, #2887b1); outline-offset: 2px; }
/* The same chart vocabulary as the usage and analytics charts (pages/usage.css):
   dashed grid, solid base axis, 11px tabular ticks, a crosshair and a readout. */
.nh-mc-grid { stroke: var(--nh-glass-line); stroke-width: 1; stroke-dasharray: 2 3; }
.nh-mc-axis { stroke: var(--nh-glass-line-strong); stroke-width: 1; }
.nh-mc-tick { fill: var(--ink); font-size: 11px; font-variant-numeric: tabular-nums; }
.nh-mc-title { fill: var(--ink); font-size: 11px; }
.nh-mc-area { fill: var(--nh-measure-draw); opacity: 0.16; }
.nh-mc-line { fill: none; stroke: var(--nh-measure-draw); stroke-width: 2; stroke-linejoin: round; }
.nh-mc-steepBand { fill: #DC2626; opacity: 0.22; }
.nh-mc-steep { fill: none; stroke: #DC2626; stroke-width: 3.5; stroke-linecap: round; }
.nh-mc-cross { stroke: var(--ink); stroke-width: 1; pointer-events: none; }
.nh-mc-dot { fill: var(--nh-measure-draw); stroke: var(--nh-glass-solid); stroke-width: 2; pointer-events: none; }
.nh-measure__tip {
  position: absolute; z-index: 2; pointer-events: none; white-space: nowrap;
  padding: 5px 8px;
  font-size: 0.78rem; color: var(--ink);
  background: var(--nh-glass-solid);
  border: 1px solid var(--nh-glass-line-strong);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.16);
}
.nh-measure__tip[hidden] { display: none; }
.nh-measure__tip span { display: block; }
.nh-measure__tip strong { font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.nh-measure__legend { margin: 2px 0 0; font-size: 0.74rem; }
.nh-measure__legend:empty { display: none; }

.nh-measure__note { margin: 8px 0 0; font-size: 0.74rem; line-height: 1.35; }
.nh-measure__note:empty { display: none; }

.nh-measure__actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.nh-measure__btn {
  min-height: 32px; padding: 4px 10px;
  font: inherit; font-size: 0.8rem; font-weight: 600;
  color: var(--ink);
  background: var(--nh-glass-well);
  border: 1px solid var(--nh-glass-line-strong);
  border-radius: var(--r-sm, 6px);
  cursor: pointer;
}
.nh-measure__btn--primary {
  color: var(--accent-ink, #fff);
  background: var(--accent, #1F6D8F);
  border-color: var(--accent, #1F6D8F);
}
.nh-measure__btn[hidden] { display: none; }
.nh-measure__seg:focus-visible,
.nh-measure__btn:focus-visible,
.nh-measure__close:focus-visible,
.nh-measure-banner__exit:focus-visible,
.maplibregl-ctrl button.nh-measure-tool__btn:focus-visible {
  outline: 3px solid var(--accent-ring, #2887b1); outline-offset: 1px;
}

.nh-measure__live,
.nh-measure__copy {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* The leg lengths on the map, beside each leg. */
.nh-measure-label {
  padding: 1px 6px;
  font-size: 0.72rem; font-weight: 700; font-variant-numeric: tabular-nums;
  color: #1A1A19;
  background: rgb(255 255 255 / 0.92);
  border: 1px solid #A21CAF;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}
body.dark-mode .nh-measure-label {
  color: #F2F2EF;
  background: rgb(20 27 34 / 0.92);
  border-color: #F0ABFC;
}

/* The map under a measure tool takes a crosshair, so the reader can see the
   click is not going to open anything. */
.maplibregl-canvas-container.nh-measuring .maplibregl-canvas { cursor: crosshair; }

/* --- phone ---------------------------------------------------------------- */
/* A bottom sheet anchored to the VIEWPORT, as the Layers sheet is (see "THE
   SHEET IS THE SCREEN'S" in open_map.css): inside a 380px map a results panel
   would leave nothing to draw on. Over the Layers sheet (z-index 900) while a
   tool is on, under a station card (2000). The banner moves to the map's top
   edge, between the left-hand controls and the Layers button, so the middle
   of the map stays free for tapping. */
@media (max-width: 640px) {
  .nh-measure-banner {
    top: 8px; left: 52px; right: 56px; transform: none;
    max-width: none;
    padding: 5px 5px 5px 9px;
    border-radius: var(--r-md, 10px);
    font-size: 0.74rem;
  }
  .nh-measure-banner__text { font-weight: 600; }
  .nh-measure {
    position: fixed;
    top: auto; left: 0; right: 0; bottom: 0;
    z-index: 950;
    width: auto; max-width: none;
    max-height: 46vh;
    border-radius: var(--r-md, 10px) var(--r-md, 10px) 0 0;
  }
  .nh-measure__btn { min-height: 40px; }
  .nh-measure__seg { min-height: 36px; }
}
