/* hab-path web preview. Every rule lives here: the production CSP is
   style-src 'self', which silently refuses inline style= attributes — the
   page renders fractionally wrong with nothing but a console error as
   evidence. CSSOM assignment stays exempt, so canvas/JS sizing is fine.

   Two consequences worth stating out loud, because they are easy to undo:

   1. Nothing in this file styles or selects the site bar. build.py splices
      that <aside> in as body's first child and ships its own stylesheet,
      linked AFTER this one, so a rule here would lose the tie anyway. The
      page is pure document flow with a fixed-pixel #map for exactly that
      reason — the bar can push everything down without breaking the map box.

   2. Anything JS injects (a Leaflet divIcon, a popup, a waypoint row) must
      carry a CLASS, never a style= attribute. That is why the marker colours
      below are .hab-marker.launch and friends rather than a colour
      interpolated into the icon's html string. */

:root {
  --bg: #0d1117;
  --panel: #141a22;
  --panel-2: #101620;
  --sunken: #0a0f16;
  --line: #232c38;
  --line-2: #2f3b4a;
  --ink: #dfe7f0;
  --dim: #8b9bb0;

  /* The five flight colours are the contract. They are used identically by
     the map markers, the altitude chart, the legend and the waypoint list, so
     a colour means one thing everywhere on the page. */
  --track: #1a8fd4;
  --launch: #3dd68c;
  --burst: #ff9f43;
  --landing: #ff6b6b;
  --float: #e6c200;
  --sample: #7aa2c4;

  --accent: #1a8fd4;
  --accent-ink: #04121e;
  --warn: #ff9f43;
  --bad: #ff6b6b;
  --ok: #3dd68c;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* The class app.js toggles. !important on purpose: several rules below set an
   explicit display on the same elements, and a JS-driven hide must win every
   one of those arguments. */
.hidden { display: none !important; }

h1, h2, h3 { margin: 0; font-weight: 600; }
a { color: var(--accent); }
a:hover { color: #4fb4ef; }
code {
  font: inherit;
  font-size: 0.92em;
  padding: 0 3px;
  border-radius: 3px;
  background: rgba(122, 162, 196, 0.14);
  color: #b9d4e8;
}
b, strong { color: var(--ink); font-weight: 700; }

/* ---------------------------------------------------------------- header */

.topbar {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 12px; align-items: flex-start; }
.brand img { flex: none; margin-top: 2px; }
.brand h1 {
  font-size: 16px;
  letter-spacing: 0.02em;
  line-height: 1.25;
  color: var(--accent);
}
.brand p {
  margin: 4px 0 0;
  max-width: 78ch;
  color: var(--dim);
  font-size: 12px;
}
.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border: 1px solid var(--float);
  border-radius: 99px;
  color: var(--float);
  font-size: 10px;
  letter-spacing: 0.14em;
  vertical-align: 2px;
}

/* Not a toast, not dismissible, not below the fold. */
.banner {
  margin: 0;
  padding: 8px 18px;
  background: rgba(255, 159, 67, 0.12);
  border-bottom: 1px solid rgba(255, 159, 67, 0.42);
  color: #ffc98d;
  font-size: 12px;
  letter-spacing: 0.02em;
}
.banner strong { color: var(--warn); }

/* ---------------------------------------------------------------- layout */

main {
  display: grid;
  grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  align-items: start;
}
.col { min-width: 0; }
.col > * + * { margin-top: 14px; }

.card {
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card > h2 {
  margin: 0 0 10px;
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.card > h3 {
  margin: 14px 0 6px;
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.note {
  margin: 8px 0 0;
  color: var(--dim);
  font-size: 12px;
}
.card > h2 + .note { margin-top: 0; }
.hint {
  display: block;
  margin-top: 4px;
  color: var(--dim);
  font-size: 11px;
  line-height: 1.5;
}

/* ------------------------------------------------------------ form parts */

.field { display: block; margin-top: 10px; }
.field:first-child { margin-top: 0; }
.field > label,
.field > .lbl {
  display: block;
  margin-bottom: 3px;
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .field { margin-top: 0; }

input, select, textarea, button {
  font: inherit;
  color: var(--ink);
  background: var(--sunken);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 13px;
}
input, select { width: 100%; }
input::placeholder { color: #5a6a7d; }
input:focus-visible,
select:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input:hover:not(:disabled), select:hover:not(:disabled) { border-color: #3d4c5e; }
input[type="datetime-local"] { color-scheme: dark; }

/* Segmented radio pair. The input is present for keyboard and assistive
   tech; the <span> is what gets painted. */
.seg {
  display: flex;
  gap: 6px;
  padding: 3px;
  background: var(--sunken);
  border: 1px solid var(--line-2);
  border-radius: 8px;
}
.seg.small { max-width: 160px; }
.segbtn { position: relative; flex: 1; }
.segbtn input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}
.segbtn span {
  display: block;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--dim);
  font-size: 12px;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.segbtn span:hover { background: #1a2330; color: var(--ink); }
.segbtn input:checked + span {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.segbtn input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.profile-fields { margin-top: 12px; }

/* Declarative profile switching, so the correct half of the form is showing
   before app.js has run a line — and without an inline style= the CSP would
   refuse. Where :has() is unsupported both groups stay visible, which is
   merely cluttered rather than broken. .hidden still overrides either way. */
@supports selector(:has(*)) {
  #controls:has(#profileStandard:checked) #fields-float { display: none; }
  #controls:has(#profileFloat:checked) #fields-standard { display: none; }
}

.opts { padding: 0; }
.opts > summary {
  padding: 12px 14px;
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  list-style: none;
}
.opts > summary::-webkit-details-marker { display: none; }
.opts > summary::before { content: "\25B8\00a0\00a0"; color: var(--accent); }
.opts[open] > summary::before { content: "\25BE\00a0\00a0"; }
.opts[open] > summary { border-bottom: 1px solid var(--line); }
.opts > .field { margin: 0; padding: 12px 14px; }

/* --------------------------------------------------------------- buttons */

.btn, button {
  cursor: pointer;
  border-color: var(--line-2);
}
.btn:hover:not(:disabled), button:hover:not(:disabled) {
  border-color: var(--accent);
  background: #16202c;
}
.btn:disabled, button:disabled { opacity: 0.42; cursor: default; }

.actions { display: flex; gap: 8px; }
.btn.primary {
  flex: 1;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  letter-spacing: 0.04em;
}
.btn.primary:hover:not(:disabled) { background: #2ba2e8; border-color: #2ba2e8; }
.btn.ghost { background: transparent; color: var(--dim); white-space: nowrap; }
.btn.ghost:hover:not(:disabled) { color: var(--ink); }

.btn-label { display: inline-block; vertical-align: middle; }
.btn-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  border: 2px solid rgba(4, 18, 30, 0.35);
  border-top-color: var(--accent-ink);
  border-radius: 50%;
  vertical-align: middle;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.dl-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn.download {
  flex: 1 1 68px;
  background: var(--sunken);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-align: center;
  text-decoration: none;
}
.btn.download:hover:not(:disabled) { background: #16202c; }

/* ---------------------------------------------------------- status footer */

/* setStatus in the desktop app puts the state class on the footer, i.e. on
   status.parentElement. Both spellings are honoured so either wiring works. */
.panel-footer {
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--dim);
  font-size: 12px;
}
.panel-footer.ok, #status.ok { color: var(--ok); }
.panel-footer.error, #status.error { color: var(--bad); }
.panel-footer.error { border-color: rgba(255, 107, 107, 0.45); }
.panel-footer.ok { border-color: rgba(61, 214, 140, 0.4); }
#status.bad { color: var(--bad); }

/* -------------------------------------------------------------- the map */

/* Fixed pixels, never vh. The hosted build injects a site bar of unknown
   height above everything; a viewport-relative map box would be pushed
   partly off screen and fitBounds would then frame the track in the part
   nobody can see. */
#map {
  height: 460px;
  border-radius: 8px;
  background: var(--sunken);
}
.leaflet-container { font: inherit; }

.leaflet-container a { color: var(--accent); }
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line-2);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.55);
}
.leaflet-popup-content-wrapper { border-radius: 8px; }
.leaflet-popup-content { margin: 10px 12px; font-size: 12px; line-height: 1.5; }
.leaflet-popup-content b { color: var(--accent); }
.leaflet-container a.leaflet-popup-close-button { color: var(--dim); }
.leaflet-container a.leaflet-popup-close-button:hover { color: var(--ink); }
.leaflet-bar a,
.leaflet-control-layers,
.leaflet-control-layers-expanded {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line-2);
}
.leaflet-bar a { border-bottom-color: var(--line); }
.leaflet-bar a:hover { background: #1c2532; color: var(--ink); }
.leaflet-bar a.leaflet-disabled { background: var(--panel-2); color: #4d5c6d; }
.leaflet-control-layers-expanded { padding: 8px 10px; font-size: 12px; }
.leaflet-control-layers-separator { border-top-color: var(--line); }
.leaflet-control-attribution {
  background: rgba(13, 17, 23, 0.84);
  color: var(--dim);
  font-size: 10px;
}
.leaflet-control-attribution a { color: var(--accent); }
.leaflet-tooltip {
  background: var(--panel);
  border-color: var(--line-2);
  color: var(--ink);
}

/* Markers are divIcons. The colour arrives as a class because a style=
   attribute inside injected html is refused by style-src 'self'. */
.hab-marker {
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--sample);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 1px 4px rgba(0, 0, 0, 0.7);
}
.hab-marker.launch { background: var(--launch); }
.hab-marker.burst { background: var(--burst); }
.hab-marker.landing { background: var(--landing); }
.hab-marker.float_start,
.hab-marker.float_end { background: var(--float); }
.hab-marker.time_sample,
.hab-marker.alt_band { background: var(--sample); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.04em;
}
.legend li { display: flex; align-items: center; gap: 5px; }
.sw {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--sample);
}
.sw.track { width: 16px; height: 3px; border-radius: 2px; background: var(--track); }
.sw.launch { background: var(--launch); }
.sw.burst { background: var(--burst); }
.sw.landing { background: var(--landing); }
.sw.float { background: var(--float); }
.sw.sample { background: var(--sample); }

/* --------------------------------------------------------------- chart */

canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: var(--sunken);
}

/* -------------------------------------------------------------- results */

.summary { font-size: 12px; }
.summary p:first-child { margin-top: 0; }
.summary dl,
.kv {
  display: grid;
  grid-template-columns: minmax(9rem, auto) 1fr;
  gap: 2px 12px;
  margin: 0;
}
.summary dt, .kv .k, .k {
  color: var(--dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 11px;
}
.summary dd, .kv .v, .v {
  margin: 0;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

table { width: 100%; border-collapse: collapse; font-size: 12px; }
th {
  padding: 3px 7px;
  border-bottom: 1px solid var(--line);
  color: var(--dim);
  font-weight: 600;
  text-align: right;
}
td { padding: 2px 7px; text-align: right; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }

.results { min-height: 1px; }

.waypoint-list {
  max-height: 340px;
  margin: 10px 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.waypoint-list:empty { display: none; }
.waypoint-list > li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 9px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.waypoint-list > li:last-child { border-bottom: 0; }
.waypoint-list > li:hover,
.waypoint-list > li.on { background: #18222f; }

.wp-seq { flex: none; width: 2.2rem; color: var(--dim); text-align: right; }
.wp-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--sample);
}
.wp-dot.launch { background: var(--launch); }
.wp-dot.burst { background: var(--burst); }
.wp-dot.landing { background: var(--landing); }
.wp-dot.float_start,
.wp-dot.float_end { background: var(--float); }
.wp-dot.time_sample,
.wp-dot.alt_band { background: var(--sample); }
.wp-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.wp-alt, .wp-time { flex: none; color: var(--dim); font-size: 11px; }

.pill {
  display: inline-block;
  padding: 1px 7px;
  border: 1px solid currentColor;
  border-radius: 99px;
  font-size: 10px;
  letter-spacing: 0.06em;
}
.pill.launch { color: var(--launch); }
.pill.burst { color: var(--burst); }
.pill.landing { color: var(--landing); }
.pill.float_start, .pill.float_end { color: var(--float); }
.pill.time_sample, .pill.alt_band { color: var(--sample); }

/* ---------------------------------------------------------------- toast */

/* Fixed to the BOTTOM. Anything pinned to the top would fight the site bar
   build.py injects above the page. */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 1200;
  max-width: min(90vw, 60ch);
  padding: 8px 14px;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  color: var(--ink);
  font-size: 12px;
}
.toast.ok { border-color: rgba(61, 214, 140, 0.6); color: var(--ok); }
.toast.error { border-color: rgba(255, 107, 107, 0.6); color: var(--bad); }

/* --------------------------------------------------------------- footer */

.pagefoot {
  max-width: 96ch;
  padding: 4px 18px 28px;
  color: var(--dim);
  font-size: 12px;
}
.pagefoot h2 {
  margin: 0 0 8px;
  color: var(--warn);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.pagefoot p { margin: 0 0 10px; }
.honesty { margin: 0 0 12px; padding-left: 18px; }
.honesty li { margin-bottom: 7px; }
.honesty b { color: var(--ink); }

/* ------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  #map { height: 340px; }
  .brand p { font-size: 11px; }
}
@media (max-width: 560px) {
  main { padding: 10px; gap: 10px; }
  .col > * + * { margin-top: 10px; }
  .topbar { padding: 10px 12px; }
  .banner, .pagefoot { padding-left: 12px; padding-right: 12px; }
  .grid2 { grid-template-columns: 1fr; }
  #map { height: 300px; }
}
@media (prefers-reduced-motion: reduce) {
  .btn-spinner { animation-duration: 2.4s; }
}
