/* EXOpace Mesh — layout deck. Phones: one header, a full-height screen, one thumb tab bar.
   640px and up (landscape phones, Fold inner, tablets, desktop): link + screens rail on the left,
   the active screen on the right. Page-scoped (body.mx-page). The shell excludes .mx-page
   from the generic !important control skin. */
:root { --mx-tab: 58px; --mx-composer: 64px; --mx-rail: clamp(220px, 26vw, 288px); --mx-b: var(--exo-sab, env(safe-area-inset-bottom)); }

html body.mx-page {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
html body.mx-page > header.exo-bar { flex: 0 0 auto; position: relative; }
html body.mx-page .mx-rail { display: contents; }

/* Link header */
html body.mx-page .mx-head {
  flex: 0 0 auto;
  min-height: 60px;
  gap: 10px;
  padding: 8px 12px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  background: rgba(4, 7, 13, 0.9);
  border-bottom: 1px solid rgba(198, 216, 226, 0.1);
}
html body.mx-page .callsign { font-size: 17px; font-weight: 600; letter-spacing: 0.08em; color: var(--exo-text); }
html body.mx-page #pathLbl { font-size: 10px; letter-spacing: 0.16em; }
html body.mx-page .link { margin-left: auto; }
html body.mx-page #hMeter:not([hidden]) + .link { margin-left: 0; }
html body.mx-page #btnConn {
  min-height: 44px !important;
  padding: 0 16px !important;
  border-radius: 999px !important;
  color: #04070d !important;
  background: #f4f8fb !important;
  border: 1px solid #f4f8fb !important;
  font: 600 11px/1 var(--exo-mono) !important;
  letter-spacing: 0.14em !important;
}
html body.mx-page #btnConn.up {
  color: var(--ok) !important;
  background: transparent !important;
  border-color: var(--ok) !important;
}

/* Comms workspace switch: a quiet segmented strip under the header */
html body.mx-page nav.exo-comms {
  position: static;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  height: auto;
  margin: 0;
  padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  overflow: hidden;
  background: rgba(4, 7, 13, 0.9);
  border: 0;
  border-bottom: 1px solid rgba(198, 216, 226, 0.1);
  box-shadow: none;
}
html body.mx-page nav.exo-comms a {
  justify-content: center;
  min-height: 44px;
  padding: 0 4px;
  color: var(--exo-muted);
  font: 500 11px/1 var(--exo-mono);
  letter-spacing: 0.14em;
}
html body.mx-page nav.exo-comms a[aria-current="page"] { color: var(--exo-text); box-shadow: inset 0 -1px 0 var(--exo-cyan); }

/* Screen area */
html body.mx-page main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 0;
}
/* Phones: the scroller ends where the tab bar begins */
@media (max-width: 639.98px) {
  html body.mx-page { padding-bottom: calc(var(--mx-tab) + var(--mx-b)); }
}
html body.mx-page .screen { max-width: 760px; padding: 14px 14px 20px; }
html body.mx-page #scr-chat.screen.active { padding-bottom: 0; min-height: 0; }
html body.mx-page #chatLog { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
html body.mx-page #scr-map.screen.active { padding: 0; max-width: none; }
html body.mx-page #scr-nodes { padding-bottom: 24px; }
html body.mx-page h2 { margin: 18px 0 10px; }
html body.mx-page .screen > h2:first-child { margin-top: 4px; }
html body.mx-page .card { border-radius: 14px !important; box-shadow: none !important; }
html body.mx-page .sub { color: var(--exo-muted); line-height: 1.45; }
html body.mx-page .big { color: var(--exo-text); font-weight: 400; }

/* All in-screen buttons: same instrument key */
html body.mx-page main .btn,
html body.mx-page #sheet .btn,
html body.mx-page #navHud .btn,
html body.mx-page #sosBanner .btn,
html body.mx-page #composer .btn,
html body.mx-page #composer select {
  min-height: 44px !important;
  padding: 0 14px !important;
  font: 500 11px/1.2 var(--exo-mono) !important;
  letter-spacing: 0.12em !important;
  white-space: normal;
  color: var(--exo-text, #f0f6fc) !important;
  background: rgba(8, 14, 22, 0.94) !important;
  border: 1px solid rgba(198, 216, 226, 0.22) !important;
}
html body.mx-page main .btn.primary { color: #04070d !important; background: #f4f8fb !important; border-color: #f4f8fb !important; }
html body.mx-page main label.btn { display: flex; align-items: center; justify-content: center; cursor: pointer; }
html body.mx-page .row { gap: 8px; }

/* Tool rows: one line of chips that scrolls sideways instead of crushing */
html body.mx-page .mx-tools,
html body.mx-page #qtx {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin: 0 0 10px;
  overflow-x: auto;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
html body.mx-page #qtx[hidden] { display: none !important; }
html body.mx-page .mx-tools::-webkit-scrollbar,
html body.mx-page #qtx::-webkit-scrollbar { display: none; }
html body.mx-page :is(.mx-tools, #qtx) > .btn { flex: 0 0 auto; width: auto; border-radius: 999px !important; white-space: nowrap; }
html body.mx-page #chatEmpty { margin-bottom: 10px; }
html body.mx-page #chatSearch { margin-bottom: 10px !important; }

/* Composer: fixed above the tab bar */
/* Composer: the last row of the chat column, never a floating layer */
html body.mx-page #composer {
  position: static;
  flex: 0 0 auto;
  margin: 0 -14px;
  min-height: var(--mx-composer);
  gap: 8px;
  padding: 10px max(12px, env(safe-area-inset-right)) calc(10px + var(--kb)) max(12px, env(safe-area-inset-left));
  background: rgba(4, 7, 13, 0.96);
  border-top: 1px solid rgba(198, 216, 226, 0.1);
}
html body.mx-page #composer select { flex: 0 0 auto; width: 76px; max-width: 96px; padding: 0 8px; }
html body.mx-page #composer .btn { flex: 0 0 auto; width: auto; min-width: 56px; padding: 0 12px !important; }

/* Bottom tab bar */
html body.mx-page nav.exo-tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  gap: 0;
  height: calc(var(--mx-tab) + var(--mx-b));
  margin: 0;
  padding: 0 env(safe-area-inset-right) var(--mx-b) env(safe-area-inset-left);
  overflow: hidden;
  background: rgba(4, 7, 13, 0.96);
  border-top: 1px solid rgba(198, 216, 226, 0.14);
  box-shadow: none;
  -webkit-mask-image: none;
  mask-image: none;
}
html body.mx-page nav.exo-tabs > button {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--mx-tab) !important;
  padding: 0 2px !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  color: var(--exo-muted) !important;
  font: 500 11px/1 var(--exo-mono) !important;
  letter-spacing: 0.14em !important;
}
html body.mx-page nav.exo-tabs > button.active {
  color: var(--exo-text) !important;
  box-shadow: inset 0 2px 0 var(--exo-cyan) !important;
  background: linear-gradient(180deg, rgba(126, 224, 255, 0.08), transparent 70%) !important;
}

/* Map: layer chips across the top, tools across the bottom — no stacked floaters */
html body.mx-page .mapwrap { background: #05080d; min-height: 220px; }
html body.mx-page .mapst {
  left: 8px;
  right: 8px;
  top: 8px;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  min-height: 0;
  padding: 0;
  overflow-x: auto;
  scrollbar-width: none;
  background: transparent;
  border: 0;
}
html body.mx-page .mapst::-webkit-scrollbar { display: none; }
html body.mx-page .mapst label {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 12px 0 10px;
  border: 1px solid rgba(198, 216, 226, 0.16);
  border-radius: 999px;
  background: rgba(4, 7, 13, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--exo-steel);
  letter-spacing: 0.12em;
}
html body.mx-page .mapst input[type=checkbox] { width: 18px; height: 18px; min-width: 18px; min-height: 18px; flex-basis: 18px; accent-color: var(--exo-cyan); }
html body.mx-page #mapEmpty { top: 62px; left: 14px; right: 14px; color: var(--exo-muted); line-height: 1.5; }
html body.mx-page #mapTip { bottom: 62px; }
html body.mx-page .mx-maptools {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 2;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
html body.mx-page .mx-maptools .btn,
html body.mx-page .mx-maptools #btnRecage,
html body.mx-page .mx-maptools #btnTapDrop {
  position: static;
  left: auto;
  bottom: auto;
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
  border-radius: 999px !important;
  background: rgba(4, 7, 13, 0.86) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  white-space: nowrap;
}
html body.mx-page .mx-maptools .btn.primary { color: #04070d !important; background: #f4f8fb !important; }
html body.mx-page .mapsec { margin: 10px; }

/* NET */
html body.mx-page #scr-nodes > .row:not(.mx-tools) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
html body.mx-page .mx-topo .exo-wave { margin: 0 0 12px; min-height: 44px; }
html body.mx-page #exo-mesh-graph { width: 100%; height: auto; display: block; border-radius: 10px; background: #05080d; border: 1px solid rgba(198, 216, 226, 0.1); }
html body.mx-page .grid2 { gap: 10px; }

/* Link sheet */
html body.mx-page #sheet { background: rgba(2, 4, 8, 0.66); z-index: 60; }
html body.mx-page #sheet .sheet {
  max-height: 88dvh;
  overflow-y: auto;
  padding: 20px 16px calc(16px + var(--mx-b));
  border-radius: 20px 20px 0 0 !important;
  background: rgba(7, 12, 18, 0.98) !important;
}
html body.mx-page #sheet .opt {
  min-height: 64px !important;
  padding: 14px 16px !important;
  border-radius: 14px !important;
  text-align: left;
  text-transform: none !important;
  letter-spacing: 0 !important;
  white-space: normal;
}
html body.mx-page #sheet .opt b { color: var(--exo-text); font-family: var(--exo-mono); letter-spacing: 0.12em; text-transform: uppercase; }
html body.mx-page #sheet .opt span { display: block; margin-top: 4px; color: var(--exo-muted); font: 400 13px/1.4 var(--exo-sans); }
html body.mx-page #sheet [data-usb-node-status] { margin: 4px 2px 8px; color: var(--exo-muted); font: 500 11px/1.4 var(--exo-mono); letter-spacing: 0.1em; }

/* Nav HUD sits above whatever is docked */
html body.mx-page #navHud {
  bottom: calc(var(--mx-tab) + var(--mx-b) + 8px);
  background: rgba(7, 12, 18, 0.96);
  border-color: rgba(255, 184, 77, 0.6);
  border-radius: 14px;
}
html body.mx-page:has(#scr-chat.active) #navHud { bottom: calc(var(--mx-tab) + var(--mx-b) + var(--mx-composer) + 8px); }
/* Link sheet is modal: the tab bar beneath stops taking taps */
html body.mx-page:has(#sheet.show) :is(nav.exo-tabs, .mx-rail, main, .exo-pill, header.exo-bar) { pointer-events: none; }
html body.mx-page #toast { bottom: calc(var(--mx-tab) + var(--mx-b) + 12px + var(--kb)); z-index: 70; }
html body.mx-page:has(#scr-chat.active) #toast { bottom: calc(var(--mx-tab) + var(--mx-b) + var(--mx-composer) + 12px + var(--kb)); }

@media (max-width: 639.98px) {
  html body.mx-page .mx-head { order: 1; }
  html body.mx-page nav.exo-comms { order: 2; }
  html body.mx-page > main { order: 3; }
}
@media (max-width: 380px) {
  html body.mx-page #pathLbl { letter-spacing: 0.08em; }
  html body.mx-page #btnConn { padding: 0 12px !important; }
  html body.mx-page #scr-nodes > .row:not(.mx-tools) { grid-template-columns: 1fr 1fr; }
}

/* ---------- Two panes ---------- */
@media (min-width: 640px) {
  html body.mx-page {
    display: grid;
    grid-template-columns: var(--mx-rail) minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
  }
  html body.mx-page > header.exo-bar,
  html body.mx-page > .exo-pill { grid-column: 1 / -1; }
  html body.mx-page .mx-rail {
    grid-column: 1;
    grid-row: 3;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    overflow-y: auto;
    padding: 14px 12px calc(14px + var(--mx-b)) max(12px, env(safe-area-inset-left));
    background: rgba(4, 7, 13, 0.55);
    border-right: 1px solid rgba(198, 216, 226, 0.1);
  }
  html body.mx-page > main { grid-column: 2; grid-row: 3; padding-bottom: 0; }
  html body.mx-page .mx-head {
    flex-wrap: wrap;
    min-height: 0;
    padding: 4px 4px 14px;
    background: transparent;
    border-bottom: 1px solid rgba(198, 216, 226, 0.1);
  }
  html body.mx-page .mx-head > div:first-child { flex: 1 1 100%; }
  html body.mx-page .mx-head .link { margin-left: 0; }
  html body.mx-page #btnConn { flex: 1 1 100%; margin-top: 4px; min-height: 48px !important; }
  html body.mx-page nav.exo-tabs {
    position: static;
    flex-direction: column;
    gap: 2px;
    height: auto;
    padding: 0;
    overflow: visible;
    background: transparent;
    border: 0;
  }
  html body.mx-page nav.exo-tabs > button {
    flex: 0 0 auto;
    justify-content: flex-start;
    text-align: left;
    min-height: 48px !important;
    padding: 0 14px !important;
    border-radius: 10px !important;
  }
  html body.mx-page nav.exo-tabs > button.active {
    background: rgba(126, 224, 255, 0.07) !important;
    box-shadow: inset 2px 0 0 var(--exo-cyan) !important;
  }
  html body.mx-page nav.exo-comms {
    margin-top: auto;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 12px 0 0;
    background: transparent;
    border: 0;
    border-top: 1px solid rgba(198, 216, 226, 0.1);
  }
  html body.mx-page nav.exo-comms a { justify-content: flex-start; padding: 0 10px; border-radius: 10px; }
  html body.mx-page nav.exo-comms a[aria-current="page"] { box-shadow: none; background: rgba(126, 224, 255, 0.07); }
  html body.mx-page .screen { padding: 22px clamp(16px, 3vw, 32px) 28px; }
  html body.mx-page #scr-chat.screen.active { padding-bottom: 0; }
  html body.mx-page #composer { margin: 0 calc(-1 * clamp(16px, 3vw, 32px)); padding-bottom: calc(10px + var(--mx-b) + var(--kb)); }
  html body.mx-page #navHud { left: calc(var(--mx-rail) + 12px); right: 12px; bottom: calc(12px + var(--mx-b)); }
  html body.mx-page:has(#scr-chat.active) #navHud { bottom: calc(var(--mx-composer) + 12px + var(--mx-b)); }
  html body.mx-page #toast { left: calc(var(--mx-rail) + (100vw - var(--mx-rail)) / 2); bottom: calc(20px + var(--mx-b) + var(--kb)); }
  html body.mx-page:has(#scr-chat.active) #toast { bottom: calc(var(--mx-composer) + 20px + var(--kb)); }
  html body.mx-page #sheet { align-items: center; justify-content: center; }
  html body.mx-page #sheet .sheet { width: min(520px, calc(100% - 32px)); border-radius: 20px !important; border: 1px solid rgba(198, 216, 226, 0.14) !important; padding-bottom: 18px; }
  html body.mx-page #scr-map .mapwrap { min-height: 320px; }
}
/* Landscape phones: drop the clock strip so the screen keeps its height */
@media (min-width: 640px) and (max-height: 500px) {
  html body.mx-page > .exo-pill { display: none !important; }
  html body.mx-page .mx-rail { gap: 8px; padding-top: 8px; }
  html body.mx-page nav.exo-tabs > button { min-height: 44px !important; }
  html body.mx-page nav.exo-comms { margin-top: 4px; }
  html body.mx-page #scr-map .mapwrap { min-height: 200px; }
}
@media (min-width: 1100px) {
  html body.mx-page .screen:not(#scr-map) { margin: 0 auto; }
  html body.mx-page #scr-vitals .grid2 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Audit fixes 2: page title, no-node intro, dark composer. */
html body.mx-page h1.callsign { margin: 0; line-height: 1.2; }
html body.mx-page .mx-intro { margin-top: 10px; line-height: 1.5; color: var(--exo-muted, #9fb0b4); }
html body.mx-page .mx-intro b { color: var(--exo-text, #f0f6fc); font-weight: 600; }
html body.mx-page .mx-intro[hidden] { display: none !important; }
html body.mx-page #chatText {
  background: rgba(10, 18, 30, 0.78);
  color: var(--exo-text, #f0f6fc);
  border: 1px solid rgba(126, 224, 255, 0.22);
  color-scheme: dark;
}
html body.mx-page #chatText::placeholder { color: var(--exo-muted, #9fb0b4); }
html body.mx-page #chatText:disabled { opacity: 0.7; cursor: not-allowed; }
