/* links.css -- the Links page. Loaded after tokens.css (the brand tokens and
   typeface, shared with the analyst pages) and BEFORE scenario_results.mobile.css
   (the analyst page's phone sheet, byte-copied into this bundle), so on a phone
   the analyst rules win over the desktop rules below exactly as they do on the
   analyst page. The page therefore wears the analyst skeleton's ids: #panel,
   #map-area, #legend, #measurements with its .sheet-handle / #mobile-summary /
   #mp-header / #mp-body, #loading-overlay. The desktop rules for those ids are
   restated here from scenario_results.css (the analyst sheet is not loaded);
   keep them in step when that sheet's shell changes.

   Every colour is a token (docs/developers/applet-gotchas.md, "Colour literals
   ... go through the token layer"). Phone-only rules for this page's own
   elements sit in the media query at the end, prefixed `body.links-page` so they
   outrank the analyst phone sheet that loads after this one. */

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

html { height: 100%; }
body {
  height: 100%; font-family: var(--font-ui); font-size: 14px; line-height: var(--lh-ui);
  display: flex; flex-direction: column; background: var(--ground);
  --mp-h: 184px;
}
#app { display: flex; flex: 1 1 auto; min-height: 0; }
button, input, select, textarea, optgroup { font-family: inherit; }
.maplibregl-map { font-family: var(--font-ui); }
table, #legend, .lk-kv, .li-props { font-variant-numeric: tabular-nums; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--sel); }

/* ---- Sidebar (Settings) ---- */
#panel {
  width: 280px; min-width: 280px;
  background: var(--ground);
  border-right: 1px solid var(--n-dd);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
#panel-close { display: none; }
#panel-title { padding: 10px 12px 8px; border-bottom: 1px solid var(--n-dd); flex-shrink: 0; }
#panel-title h2 { font-size: 14px; font-weight: 700; color: var(--n-22); }
#panel-title .subtitle { font-size: 11px; color: var(--n-77); margin-top: 4px; }
#panel-title .copyright { font-size: 10px; color: var(--n-aa); margin-top: 2px; }
.title-footer { display: flex; align-items: center; justify-content: space-between; }
.applet-nav {
  display: flex; border: 1px solid var(--n-cc); border-radius: 4px;
  overflow: hidden; margin-top: 6px;
}
.applet-nav a {
  flex: 1; padding: 4px 8px; text-align: center; text-decoration: none;
  background: var(--n-ff); font-size: 11px; color: var(--n-55); font-weight: 600;
}
.applet-nav a:hover { background: var(--hover); }
.applet-nav a.active { background: var(--sel); color: var(--on-accent); }
.sidebar-section { border-bottom: 1px solid var(--n-dd); }
.sec-label {
  padding: 7px 12px;
  font-size: 12px; font-weight: 600; color: var(--n-55);
  background: var(--ground-band);
  border-bottom: 1px solid var(--n-e0);
}
.lk-about { padding: 8px 12px 10px; font-size: 12px; line-height: 1.45; color: var(--n-33); }
.lk-about p + p { margin-top: 6px; }
.lk-about b { color: var(--n-22); }
.lk-muted { color: var(--n-66); }
.lk-kv { border-collapse: collapse; width: 100%; font-size: 11px; }
.lk-kv td { padding: 2px 0; vertical-align: top; color: var(--n-22); }
.lk-kv td:first-child { color: var(--n-66); padding-right: 10px; white-space: nowrap; }

/* ---- Map ---- */
#map-area { flex: 1; display: flex; flex-direction: column; position: relative; min-width: 0; }
#map { flex: 1; }

/* ---- Legend (desktop: bottom-right, as on the analyst page) ---- */
#legend {
  position: absolute; bottom: 28px; right: 12px;
  background: var(--veil-ground-94); border: 1px solid var(--n-cc);
  border-radius: 6px; padding: 8px 10px; z-index: 900;
  font-size: 11px; min-width: 180px; max-width: 270px;
  box-shadow: 0 2px 6px var(--shade-15);
  max-height: 70vh; overflow-y: auto;
  color: var(--n-44);
}
#legend .leg-title { font-weight: 700; color: var(--n-33); font-size: 11px; }
#legend .leg-sub { color: var(--n-77); margin: 1px 0 5px; }
#legend .leg-bar {
  height: 13px; border-radius: 3px; margin-bottom: 4px;
  background: linear-gradient(to right, var(--n-cc), var(--n-cc));
}
#legend .leg-labels { display: flex; justify-content: space-between; color: var(--n-55); }
#legend .leg-const { margin-top: 4px; color: var(--warn-text); }
#legend .leg-const[hidden] { display: none; }
#legend .leg-extra:empty { display: none; }
#legend #leg-notes { margin-top: 5px; color: var(--n-66); line-height: 1.35; }
#legend #leg-notes div + div { margin-top: 3px; }
#legend #leg-keys { margin-top: 6px; padding-top: 5px; border-top: 1px solid var(--n-dd); }
.lk-key { display: flex; align-items: center; gap: 6px; line-height: 1.3; }
.lk-key + .lk-key { margin-top: 3px; }
.lk-sw { flex: 0 0 22px; height: 10px; position: relative; }
.lk-sw-sides::before, .lk-sw-sides::after {
  content: ""; position: absolute; left: 0; right: 0; height: 3px; border-radius: 2px;
  background: var(--n-66);
}
.lk-sw-sides::before { top: 1px; }
.lk-sw-sides::after { bottom: 1px; }
.lk-sw-dash { border-top: 3px dashed var(--n-77); height: 0; margin-top: 1px; }
.lk-sw-arrow { height: auto; text-align: center; font-weight: 700; font-size: 14px; line-height: 10px; color: var(--n-22); }
.lk-sw-ring { flex: 0 0 22px; }
.lk-sw-ring::before {
  content: ""; position: absolute; left: 6px; top: 0; width: 10px; height: 10px;
  border-radius: 50%; border: 1.5px solid var(--n-99);
}
.lk-jn-bar { flex: 0 0 22px; height: 8px; border-radius: 4px; }

/* ---- The dock: header, controls strip, inspector ---- */
#measurements {
  flex: 0 0 var(--mp-h); height: var(--mp-h);
  background: var(--ground-raised); border-top: 1px solid var(--n-cc);
  display: flex; flex-direction: column;
  font-size: 12px; color: var(--n-33);
}
#mobile-summary { display: none; }
.sheet-handle { display: none; }
#ctrl-3d { display: none; }
#ctrl-settings { display: none; }
#mp-header {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 5px 12px; background: var(--ground); border-bottom: 1px solid var(--n-e3);
}
#mp-context {
  flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  font-size: 11px; color: var(--nc-556); white-space: nowrap;
  padding-right: 10px; border-right: 1px solid var(--n-dd);
}
#mp-context:empty { display: none; }
.mp-stage {
  color: var(--n-77); font-style: italic;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mp-spacer { flex: 1; }
.mp-btn {
  background: var(--n-ff); border: 1px solid var(--n-cc); border-radius: 3px;
  padding: 2px 8px; font-size: 11px; color: var(--label-em); cursor: pointer;
  white-space: nowrap; flex: 0 0 auto;
}
.mp-btn:hover:not(:disabled) { background: var(--hover); border-color: var(--sel-border); }
.mp-btn:disabled { color: var(--n-bb); cursor: default; }

/* The controls strip (applet-controls' #mp-params: its own row between the
   dock header and the body, both layouts). */
.lk-strip {
  flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center;
  gap: 6px 18px; padding: 6px 12px; border-bottom: 1px solid var(--n-e3);
  background: var(--ground-raised);
}
.lk-ctl { display: flex; align-items: center; gap: 6px; }
.lk-lbl { font-size: 11px; font-weight: 600; color: var(--label-em); white-space: nowrap; }
.lk-ctl select {
  font-size: 12px; padding: 2px 4px; max-width: 320px;
  border: 1px solid var(--n-cc); border-radius: 3px; background: var(--n-ff); color: var(--n-22);
}
.lk-ctl select:focus-visible, .mode-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.lk-check { font-size: 11px; color: var(--n-44); cursor: pointer; }
.lk-check input { margin: 0; cursor: pointer; }
.lk-check.lk-off { color: var(--n-aa); cursor: default; }
.mode-toggle-strip {
  display: flex; border: 1px solid var(--n-cc); border-radius: 4px;
  overflow: hidden;
}
.mode-btn {
  flex: 1; padding: 3px 10px; border: none;
  background: var(--n-ff); font-size: 11px; cursor: pointer; color: var(--n-55);
  font-weight: 600; white-space: nowrap;
}
.mode-btn + .mode-btn { border-left: 1px solid var(--n-dd); }
.mode-btn:hover:not(:disabled) { background: var(--hover); }
.mode-btn.active { background: var(--sel); color: var(--on-accent); }
.mode-btn:disabled { color: var(--n-bb); cursor: not-allowed; }

#mp-body {
  flex: 1 1 auto; min-height: 0;
  padding: 6px 12px 4px; overflow: auto;
}
#mp-placeholder {
  flex: 1 1 auto; display: none;
  align-items: center; justify-content: center;
  color: var(--n-99); font-size: 12px; text-align: center; padding: 0 20px;
}
#measurements.mp-empty #mp-body { display: none; }
#measurements.mp-empty #mp-placeholder { display: flex; }
#mp-body .pn-name { font-weight: 700; margin-bottom: 4px; color: var(--n-22); font-size: 13px; }

/* ---- The inspector (inspector.js) ---- */
.li-head { margin-bottom: 6px; }
#mp-body .li-head .pn-name { margin-bottom: 1px; }
#mp-body .pn-name.li-unnamed { font-style: italic; }
.li-sub { font-weight: 400; font-size: 10.5px; color: var(--n-88); }
.li-meta { font-size: 11px; color: var(--n-55); line-height: 1.4; }
.li-ids { color: var(--n-88); }
.li-notes { margin-top: 4px; font-size: 11px; line-height: 1.4; color: var(--n-33); }
.li-notes > div { padding: 2px 6px; border-left: 2px solid var(--n-cc); background: var(--ground-band); }
.li-notes > div + div { margin-top: 2px; }
.li-note { margin-top: 6px; font-size: 11px; }
.li-warn, .li-warnt { color: var(--warn-text); }
.li-cols { display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: flex-start; }
.li-block { flex: 1 1 380px; min-width: 0; max-width: 620px; }
.li-tab { border-collapse: collapse; width: 100%; font-size: 11px; font-variant-numeric: tabular-nums; }
.li-tab th { font-weight: 600; color: var(--n-55); text-align: right; padding: 2px 5px;
             border-bottom: 1px solid var(--n-cc); white-space: nowrap; }
.li-tab th.li-f { text-align: left; }
.li-tab tr.li-grp th { border-bottom: none; padding-bottom: 0; }
.li-tab tr.li-grp th.li-twin { text-align: center; border-bottom: 1px solid var(--n-dd); }
.li-tab td { padding: 2px 5px; border-bottom: 1px solid var(--n-f0); vertical-align: top; color: var(--n-22); }
.li-tab td.li-f { color: var(--n-33); white-space: nowrap; }
.li-tab .li-n { text-align: right; white-space: nowrap; }
.li-time .li-n { white-space: normal; }
.li-tab .li-strong { font-weight: 700; }
.li-tab .li-ind { font-style: italic; color: var(--n-55); }
.li-tab .li-na { color: var(--n-aa); }
.li-tab .li-sh { background: var(--ground-band); }
.li-tab .li-chosen { box-shadow: inset 0 -2px 0 var(--sel); }
.li-tab th.li-clicked, .li-tab td.li-clicked { background: var(--hover); }
.li-tab .li-blank { background: transparent; }
.li-tab tr.li-prod td, .li-tab tr.li-total td { border-top: 1px solid var(--n-cc); }
.li-tab tr.li-total td { font-weight: 700; }
.li-tab tr.li-subrow td { color: var(--n-66); }
.li-tab tr.li-sum td { border-top: 1px solid var(--n-cc); }
.li-tab tr.li-check td { border-top: 1px solid var(--n-bb); background: var(--ground-band); font-weight: 600; }
.li-tab tr.li-in td { background: var(--ground-band); color: var(--n-44); font-size: 10.5px; }
.li-tab td.li-inl { padding-left: 22px; white-space: normal; }
.li-tab td.li-span { text-align: center; }
.li-tab td.li-imp { font-style: italic; }
.li-tab .li-mks { margin-top: 1px; white-space: normal; font-style: normal; }
.li-tab td.li-f .li-sub { white-space: normal; }
.li-mkt { display: inline-block; padding: 0 4px; border-radius: 3px; font-size: 10px; line-height: 14px;
          color: var(--warn-text); background: var(--warn-bg); border: 1px solid var(--warn-border); }
.li-mk { color: var(--warn-text); font-weight: 700; }
.li-tog {
  width: 14px; margin-right: 3px; border: none; background: none; cursor: pointer;
  color: var(--n-66); font-size: 10px; line-height: 1; padding: 0; transition: transform 0.1s;
}
.li-tog[aria-expanded="true"] { transform: rotate(90deg); }
.li-tog:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.li-tog-sp { display: inline-block; width: 17px; }
.li-foot { margin-top: 3px; font-size: 10.5px; color: var(--n-77); line-height: 1.35; }
.li-props { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); column-gap: 22px; }
.li-row { display: flex; justify-content: space-between; gap: 10px; padding: 1px 0; font-size: 11px;
          border-bottom: 1px solid var(--n-f0); }
.li-props .li-k { color: var(--n-66); }
.li-props .li-v { color: var(--n-22); font-weight: 600; }

/* A desktop dock grows while it shows a link (the inspector's two tables need
   the room); the phone sheet keeps the analyst page's own heights. The query
   is the complement of LAYOUT_MQ. */
@media (min-width: 761px) and (min-height: 501px) {
  #measurements:not(.mp-empty) { flex-basis: min(360px, 50vh); height: min(360px, 50vh); }
}

/* ---- Loading overlay (the analyst page's, restated) ----
   Boot: visible from first paint over an opaque ground; app.js hides it after
   the map's first idle frame. The badge is fetched (ives-badge.png beside this
   sheet) rather than inlined as on the analyst page: the data URI would be a
   second copy of 12 KB of base64 to keep in step. */
#loading-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: var(--veil-45);
}
#loading-overlay.boot { background: var(--ground); }
#loading-overlay[hidden] { display: none; }
#loading-overlay .spinner {
  width: 72px; height: 72px;
  background: url("ives-badge.png") center / contain no-repeat;
  animation: spin 3.2s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  #loading-overlay .spinner { animation: none; }
}
.lk-error {
  background: var(--warn-bg); border-bottom: 1px solid var(--warn-border);
  color: var(--warn-text); padding: 8px 12px; font-size: 12px;
}

/* ---- Phone (the analyst page's layout; this block only adds this page's own
   elements). The media query must stay byte-identical to LAYOUT_MQ in
   layout.js and to scenario_results.mobile.css's. ---- */
@media (max-width: 760px), (max-height: 500px) {
  /* The strip wraps to the sheet's width and shows once the dock is raised
     (applet-controls S3-a: the 56px rest is unchanged). */
  body.links-page .lk-strip { gap: 8px 12px; padding: 8px 12px; }
  body.links-page .lk-ctl select { max-width: 62vw; font-size: 14px; padding: 4px 6px; }
  body.links-page .mode-btn { padding: 6px 12px; font-size: 13px; }
  body.links-page .lk-check { font-size: 13px; }
  body.links-page .lk-check input { width: 18px; height: 18px; }
  /* The phone legend is the analyst page's title chip: title and ramp. The
     notes and keys stay on the desktop legend (the sidebar's About says the
     same). */
  body.links-page #legend .leg-sub,
  body.links-page #legend .leg-extra { display: none; }
  body.links-page #legend .leg-const { grid-column: 1 / -1; font-size: 10px; }
  body.links-page #panel { width: auto; min-width: 0; }
  body.links-page .li-props { grid-template-columns: 1fr; }
  body.links-page .li-block { flex-basis: 100%; }
  body.links-page .li-tab { font-size: 11px; }
  body.links-page .li-tab th, body.links-page .li-tab td { padding: 3px 2px; }
  body.links-page .li-tab th.li-twin { white-space: normal; }
  body.links-page .li-tab td.li-inl { padding-left: 14px; }
  body.links-page .li-tog { width: 16px; font-size: 12px; }
  body.links-page .li-tog-sp { width: 19px; }
}
