/*
 * MIRCO DEX — the shared identity.
 *
 * Professional enough for an active trader, clearer than a legacy exchange. The
 * palette is the accepted MIRCO white/light family, written down here rather than
 * imported: this is a separate product with its own build, and a build-time
 * dependency on a frozen artifact's source would couple the two.
 *
 * Density is deliberate. A trading screen earns its density by putting more true
 * facts in front of somebody at once; it does not earn it by being cramped. So the
 * rules here are tight leading, small type, hairline rules and almost no card
 * chrome — and generous hit targets, because a dense screen still has to be
 * clickable.
 */

/* The V5 tokens this file aliases. index.html links them first as well; a page that links only this sheet
   (test-lab/index.html) still gets them, and loading the same sheet twice changes nothing. */
@import url("./dex5-tokens.css");

:root {
  /*
   * V5: every legacy name below ALIASES a token in dex5-tokens.css (linked first), so the whole product
   * re-themes from one place and light/dark is decided there once. The names stay because every existing
   * stylesheet and inline style uses them; nothing here holds a raw colour any more.
   */
  --n0: var(--dx-surface);
  --n50: var(--dx-surface-2);
  --n100: var(--dx-surface-3);
  --n150: var(--dx-border-soft);
  --n200: var(--dx-border);
  --n300: var(--dx-text-faint);
  --n400: var(--dx-text-faint);
  --n500: var(--dx-text-dim);
  --n600: var(--dx-text-dim);
  --n800: var(--dx-text);
  --n900: var(--dx-text);

  --teal50: var(--dx-accent-soft);
  --teal100: var(--dx-accent-soft);
  --teal600: var(--dx-accent);
  --teal700: var(--dx-accent-strong);

  /* Semantic, and separate from the accent. A buy is not "the brand colour". */
  --up600: var(--dx-buy);
  --up50: var(--dx-buy-soft);
  --down600: var(--dx-sell);
  --down50: var(--dx-sell-soft);
  --warn600: var(--dx-warn);
  --warn50: var(--dx-warn-soft);

  --bg: var(--dx-bg);
  --surface: var(--dx-surface);
  --surface-2: var(--dx-surface-2);
  --line: var(--dx-border);
  --line-soft: var(--dx-border-soft);
  --ink: var(--dx-text);
  --ink-2: var(--dx-text-dim);
  --ink-3: var(--dx-text-faint);
  --accent: var(--dx-accent);
  --accent-ink: var(--dx-accent-strong);
  --accent-quiet: var(--dx-accent-soft);

  --s1: 2px;
  --s2: var(--dx-sp-1);
  --s3: 6px;
  --s4: 10px;
  --s5: 14px;
  --s6: 20px;
  --s7: 28px;

  --t-micro: 10px;
  --t-small: var(--dx-fs-xs);
  --t-body: var(--dx-fs-sm);
  --t-mid: var(--dx-fs-md);
  --t-head: var(--dx-fs-lg);
  --t-big: 22px;
  --t-display: 26px;

  --radius: var(--dx-radius-m);
  --radius-lg: var(--dx-radius-l);
  --tap: 32px;
  --mono: var(--dx-mono);
}

/* Dark mode lives in dex5-tokens.css: the aliases above follow it in all three viewer states. */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  /* Explicit, because the page composites over a ground somebody else paints. */
  background: var(--bg);
  color: var(--ink);
  font: var(--t-body) / var(--dx-lh) var(--dx-font);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

/* Anything that must stay left-to-right inside an RTL paragraph. */
.ltr-pinned,
[dir="ltr"] {
  unicode-bidi: isolate;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: 3px;
}

/* ------------------------------------------------------------------ shell --- */

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s5);
  padding: 0 var(--s5);
  min-height: 44px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand {
  font-size: var(--t-mid);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  white-space: nowrap;
}

.brand span {
  color: var(--accent);
}

.nav {
  display: flex;
  gap: var(--s1);
  flex-wrap: wrap;
}

.nav button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-weight: 600;
  padding: var(--s3) var(--s4);
  min-height: var(--tap);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
}

.nav button:hover {
  color: var(--ink);
  background: var(--surface-2);
}

.nav button[aria-current="page"] {
  color: var(--accent-ink);
  background: var(--accent-quiet);
}

.topbar-right {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: var(--s4);
  flex-wrap: wrap;
}

.chip-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
}

.meta {
  font-size: var(--t-small);
  color: var(--ink-2);
  display: flex;
  gap: var(--s2);
  align-items: baseline;
}

.meta b {
  color: var(--ink);
  font-weight: 600;
  font-family: var(--mono);
}

/* State chips: the word is the signal, the colour reinforces it. */
.state-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--t-micro);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px var(--s3);
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.state-chip::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: currentColor;
  flex: 0 0 auto;
}

.state-chip[data-tone="good"] {
  color: var(--up600);
  background: var(--up50);
}
.state-chip[data-tone="warn"] {
  color: var(--warn600);
  background: var(--warn50);
}
.state-chip[data-tone="bad"] {
  color: var(--down600);
  background: var(--down50);
}
.state-chip[data-tone="pending"] {
  color: var(--accent-ink);
  background: var(--accent-quiet);
}
.state-chip[data-tone="quiet"] {
  color: var(--ink-2);
  background: var(--surface-2);
  border-color: var(--line-soft);
}
.state-chip[data-tone="active"] {
  color: var(--accent-ink);
  background: var(--accent-quiet);
}
.state-chip[data-tone="done"] {
  color: var(--up600);
  background: var(--up50);
}
.state-chip[data-tone="armed"] {
  color: var(--warn600);
  background: var(--warn50);
}

/* ------------------------------------------------------------ primitives --- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* V5: the .dx-panel-head / .dx-panel-title look (dex5-components.css) on the existing markup. */
.panel-head {
  display: flex;
  align-items: center;
  gap: var(--dx-sp-2);
  padding-block: var(--dx-sp-1);
  padding-inline: var(--dx-sp-3);
  border-bottom: 1px solid var(--line-soft);
  flex: 0 0 auto;
  min-height: 36px;
}

.panel-title {
  font-size: var(--dx-fs-sm);
  font-weight: var(--dx-fw-strong);
  letter-spacing: 0.01em;
  color: var(--dx-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.panel-tools {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.panel-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.empty-note {
  padding: var(--s6) var(--s5);
  color: var(--ink-2);
  font-size: var(--t-small);
  text-align: center;
  line-height: 1.6;
}

.empty-note b {
  display: block;
  color: var(--ink);
  font-size: var(--t-body);
  margin-bottom: var(--s2);
}

/* Tables: dense, hairline, and scrollable in their own container. */
table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-small);
  font-family: var(--mono);
}

table.grid th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: end;
  font-family: var(--dx-font);
  font-size: var(--dx-fs-xs);
  font-weight: var(--dx-fw-medium);
  color: var(--dx-text-dim);
  padding: var(--s2) var(--s4);
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
  z-index: 1;
}

table.grid th:first-child,
table.grid td:first-child {
  text-align: start;
}

table.grid td {
  font-variant-numeric: tabular-nums;
  padding: var(--s2) var(--s4);
  border-bottom: 1px solid var(--line-soft);
  text-align: end;
  white-space: nowrap;
  color: var(--ink);
}

table.grid tbody tr:hover {
  background: var(--surface-2);
}

/* A table that would push figures off a phone becomes one labelled record per row. Every cell survives;
 * none is hidden to make the layout fit (owner audit 2026-10-10: pool reserves cut off at 390px). */
@media (max-width: 640px) {
  table.grid.stack thead { display: none; }
  table.grid.stack, table.grid.stack tbody, table.grid.stack tr, table.grid.stack td { display: block; width: 100%; }
  table.grid.stack tr { padding: var(--s2) var(--s4); border-bottom: 1px solid var(--line-soft); }
  table.grid.stack td {
    display: flex; justify-content: space-between; align-items: center; gap: var(--s4);
    padding: 3px 0; border-bottom: 0; text-align: end; white-space: normal; overflow-wrap: anywhere;
  }
  table.grid.stack td::before {
    content: attr(data-label); flex: none; text-align: start;
    font-family: var(--sans, inherit); font-size: var(--t-micro); font-weight: 700;
    letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3);
  }
  table.grid.stack td:first-child { font-weight: 700; }
  table.grid.stack td:last-child::before { content: none; }
}

/* The markets table (eleven figures per market) does not fit a tablet either (Track H H-25e13a): from 641 to
 * 1023px each market is a labelled card, two or more per row. Every cell survives; nothing scrolls sideways. */
@media (min-width: 641px) and (max-width: 1023.98px) {
  table.grid.stack.markets-grid thead { display: none; }
  table.grid.stack.markets-grid, table.grid.stack.markets-grid tbody { display: block; width: 100%; }
  table.grid.stack.markets-grid tbody {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--s3, 12px); padding: var(--s3, 12px);
  }
  table.grid.stack.markets-grid tr {
    display: block; padding: var(--s2) var(--s4); border: 1px solid var(--line-soft); border-radius: var(--radius, 6px);
  }
  table.grid.stack.markets-grid td {
    display: flex; justify-content: space-between; align-items: center; gap: var(--s4); width: 100%;
    padding: 3px 0; border-bottom: 0; text-align: end; white-space: normal; overflow-wrap: anywhere;
  }
  table.grid.stack.markets-grid td::before {
    content: attr(data-label); flex: none; text-align: start;
    font-family: var(--sans, inherit); font-size: var(--t-micro); font-weight: 700;
    letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3);
  }
  table.grid.stack.markets-grid td[data-label=""]::before, table.grid.stack.markets-grid td:last-child::before { content: none; }
  table.grid.stack.markets-grid td:first-child { font-weight: 700; }
}

.up {
  color: var(--up600);
}
.down {
  color: var(--down600);
}
.quiet {
  color: var(--ink-2);
}

/* A direction is a word and a mark, never a colour alone. */
.side-mark {
  font-weight: 700;
}
.side-mark[data-side="buy"]::before {
  content: "▲ ";
}
.side-mark[data-side="sell"]::before {
  content: "▼ ";
}

button.action {
  appearance: none;
  min-height: var(--tap);
  padding: var(--s3) var(--s5);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: var(--dx-fw-strong);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dx-dur) var(--dx-ease), border-color var(--dx-dur) var(--dx-ease);
}

button.action:hover {
  border-color: var(--dx-text-faint);
  background: var(--dx-surface-3);
}

button.action[data-kind="primary"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--dx-on-accent);
}

button.action[data-kind="primary"]:hover {
  background: var(--dx-accent-strong);
  border-color: var(--dx-accent-strong);
}

button.action[data-kind="buy"] {
  background: var(--up600);
  border-color: var(--up600);
  color: var(--dx-surface);
}

button.action[data-kind="sell"] {
  background: var(--down600);
  border-color: var(--down600);
  color: var(--dx-surface);
}

button.action[data-kind="buy"]:hover,
button.action[data-kind="sell"]:hover {
  filter: brightness(1.08);
}

/* Disabled reads as disabled without washing a primary action into an unreadable tint (A-012). */
button.action[disabled] {
  opacity: 1;
  cursor: not-allowed;
  filter: none;
  background: var(--dx-surface-3);
  border-color: var(--dx-border);
  color: var(--dx-text-faint);
}

button.tiny {
  min-height: 24px;
  padding: 1px var(--s3);
  /* Kept at the base's 10px: at 11px the ticket's order-type row wrapped "Stop-limit" onto two lines. */
  font-size: var(--t-micro);
  font-weight: var(--dx-fw-strong);
  border-radius: var(--dx-radius-s);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}

button.tiny:hover {
  color: var(--dx-text);
  border-color: var(--dx-text-faint);
}

button.tiny:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.tiny[aria-pressed="true"] {
  background: var(--accent-quiet);
  border-color: var(--accent);
  color: var(--accent-ink);
}

label.field {
  display: block;
  font-size: var(--t-small);
  color: var(--ink-2);
  margin-bottom: var(--s4);
}

/* A control group laid out as a field (the deadline chips, deadline.js) reads like every other field label (A-025). */
div.field {
  font-size: var(--t-small);
  color: var(--ink-2);
  margin-bottom: var(--s4);
}

div.field > span,
label.field > span {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s3);
  margin-bottom: var(--s2);
  font-weight: 600;
}

label.field input,
label.field select {
  width: 100%;
  min-height: var(--tap);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--dx-surface-2);
  color: var(--ink);
  font: inherit;
  font-family: var(--mono);
  font-size: var(--t-mid);
  font-variant-numeric: tabular-nums;
  /* A price is read left to right in every locale. */
  direction: ltr;
  text-align: end;
  transition: border-color var(--dx-dur) var(--dx-ease), background var(--dx-dur) var(--dx-ease);
}

label.field input:hover,
label.field select:hover {
  border-color: var(--dx-text-faint);
}

label.field input:focus,
label.field select:focus {
  outline: none;
  border-color: var(--dx-focus);
  background: var(--dx-surface);
  box-shadow: 0 0 0 2px var(--dx-accent-soft);
}

label.field input[aria-invalid="true"] {
  border-color: var(--down600);
  background: var(--down50);
}

.finding {
  display: flex;
  gap: var(--s3);
  align-items: flex-start;
  font-size: var(--t-small);
  color: var(--down600);
  background: var(--down50);
  border-radius: var(--radius);
  padding: var(--s3) var(--s4);
  margin-bottom: var(--s3);
}

.finding::before {
  content: "!";
  font-weight: 800;
  flex: 0 0 auto;
}

.finding[data-tone="warn"] {
  color: var(--warn600);
  background: var(--warn50);
}

.rows {
  display: grid;
  gap: var(--s2);
  padding: var(--s4);
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s4);
  font-size: var(--t-small);
}

.row dt,
.row .k {
  color: var(--ink-2);
}

.row dd,
.row .v {
  margin: 0;
  font-family: var(--mono);
  color: var(--ink);
  text-align: end;
  font-variant-numeric: tabular-nums;
  /* A figure with its units ("1,000 MTU / 2,000 TUSD") was reordered by the Arabic paragraph into
     "MTU / 2,000 TUSD 1,000" (A-020). plaintext takes each value's direction from its own first strong
     character: a figure stays left-to-right, an Arabic word stays right-to-left. */
  unicode-bidi: plaintext;
}

.tabs {
  display: flex;
  gap: var(--s1);
  border-bottom: 1px solid var(--line-soft);
  padding: 0 var(--s3);
  overflow-x: auto;
}

.tabs button {
  appearance: none;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: var(--dx-fs-sm);
  font-weight: var(--dx-fw-strong);
  padding: var(--s4) var(--s4);
  min-height: var(--tap);
  cursor: pointer;
  white-space: nowrap;
}

.tabs button:hover {
  color: var(--dx-text);
}

.tabs button[aria-selected="true"] {
  color: var(--dx-text);
  border-bottom-color: var(--accent);
}

dialog.sheet {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  max-width: 460px;
  width: calc(100vw - 32px);
  box-shadow: var(--dx-shadow-2);
}

dialog.sheet::backdrop {
  background: var(--dx-overlay);
}

.sheet-head {
  padding: var(--s5);
  border-bottom: 1px solid var(--line-soft);
  font-size: var(--t-head);
  font-weight: 650;
}

.sheet-body {
  padding: var(--s5);
  max-height: 60vh;
  overflow: auto;
}

.sheet-foot {
  padding: var(--s4) var(--s5);
  border-top: 1px solid var(--line-soft);
  display: flex;
  gap: var(--s3);
  justify-content: flex-end;
}

.note {
  font-size: var(--t-small);
  color: var(--ink-2);
  line-height: 1.55;
}

.note.caution {
  color: var(--warn600);
  background: var(--warn50);
  border-radius: var(--radius);
  padding: var(--s4);
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* ------------------------------------------------------- the market picker --- */

/*
 * The host is an empty, zero-size box out of the shell's grid flow: opening the selector never moves the page. The
 * panel inside it is fixed, placed under the control that opened it (selector.js placeDropdown), or a bottom sheet on
 * a phone. Never placed by a transform: a transform moves what is drawn and leaves the layout box where it was, so a
 * translated panel once gave the page 553px of horizontal scroll at phone width with nothing visible in it.
 */
.selector-host {
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  inline-size: 0;
  block-size: 0;
  overflow: visible;
}

.selector-host > .dx-selector {
  position: fixed;
  z-index: 65;
  margin: 0;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  min-block-size: 0;
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.08);
}

.dx-selector > .panel-body {
  flex: 1 1 auto;
  min-block-size: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.dx-selector-top {
  display: flex;
  align-items: center;
  gap: var(--dx-sp-2, 8px);
  padding-block: var(--dx-sp-1, 4px) 0;
  padding-inline: var(--dx-sp-3, 12px) var(--dx-sp-1, 4px);
  flex: 0 0 auto;
}

.dx-selector-title {
  flex: 1 1 auto;
  min-inline-size: 0;
  margin: 0;
  font-size: var(--dx-fs-sm, 13px);
  font-weight: var(--dx-fw-strong, 600);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dx-selector-close {
  flex: none;
  inline-size: 36px;
  block-size: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius, 6px);
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

.dx-selector-close:hover {
  background: var(--line-soft, rgba(0, 0, 0, 0.06));
}

.dx-selector-close:focus-visible {
  outline: 2px solid var(--dx-focus, var(--accent, #0b7a75));
  outline-offset: 1px;
}

.dx-selector .dx-selector-head input[type="search"] {
  min-inline-size: 0;
}

.dx-selector-backdrop {
  position: fixed;
  inset: 0;
  z-index: 64;
  background: rgba(8, 12, 16, 0.45);
}

.dx-selector-backdrop[hidden] {
  display: none;
}

/* A phone: a bottom sheet the width of the screen, its list scrolling inside it, the page behind it still. */
.selector-host[data-mode="sheet"] > .dx-selector {
  inset-inline: 0;
  inset-block-end: 0;
  inset-block-start: auto;
  inline-size: auto;
  max-block-size: 85vh;
  max-block-size: min(85dvh, 640px);
  border-end-start-radius: 0;
  border-end-end-radius: 0;
  border-start-start-radius: 14px;
  border-start-end-radius: 14px;
  border-block-end: 0;
  padding-block-end: env(safe-area-inset-bottom, 0px);
}

.selector-host[data-mode="sheet"] .dx-selector-top {
  padding-block-start: var(--dx-sp-2, 8px);
}

.selector-host[data-mode="sheet"] .dx-selector-close {
  inline-size: 44px;
  block-size: 44px;
}

.selector-host[data-mode="sheet"] .dx-selector .book-row {
  min-block-size: 44px !important;
}

html.dx-selector-lock,
html.dx-selector-lock body {
  overflow: hidden;
}

/* ------------------------------------------- the header's data status --- */

/* One summary chip (a button) and its details, collapsed by default; header-status.js places the details under it. */
.dx-hstatus {
  flex: none;
  display: inline-flex;
}

.dx-hstatus-button {
  cursor: pointer;
  white-space: nowrap;
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.dx-hstatus-button:focus-visible {
  outline: 2px solid var(--dx-focus, var(--accent, #0b7a75));
  outline-offset: 1px;
}

.dx-hstatus-caret {
  font-size: 0.8em;
  opacity: 0.75;
}

.dx-hstatus-details {
  position: fixed;
  z-index: 66;
  box-sizing: border-box;
  padding: var(--dx-sp-3, 12px);
  gap: var(--dx-sp-2, 8px);
  overflow-y: auto;
  white-space: normal;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.08);
}

.dx-hstatus-details[hidden] {
  display: none;
}

.dx-hstatus-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--dx-sp-2, 8px);
}

.dx-hstatus-what,
.dx-hstatus-fact,
.dx-hstatus-note {
  margin: 2px 0 0;
  font-size: var(--dx-fs-xs, 12px);
  line-height: 1.4;
  color: var(--dx-text-muted, inherit);
  overflow-wrap: anywhere;
}

.dx-hstatus-note {
  border-block-start: 1px solid var(--line-soft, rgba(0, 0, 0, 0.08));
  padding-block-start: var(--dx-sp-2, 8px);
}

/* --------------------------------------------------- the header, at phone --- */

@media (max-width: 820px) {
  .topbar {
    padding: var(--s2) var(--s4);
    row-gap: var(--s2);
  }
  /*
   * The areas scroll in their own box rather than forcing the header wider. A nav
   * that wrapped would push the trading surface down the screen on every load.
   */
  .nav {
    order: 3;
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar {
    display: none;
  }
  .topbar-right {
    /* Its own row, starting at the leading edge, so nothing is pushed off. */
    order: 2;
    width: 100%;
    margin-inline-start: 0;
    justify-content: flex-start;
    row-gap: var(--s2);
  }
  .meta {
    font-size: var(--t-micro);
  }
}

/* Nothing in the terminal may exceed the page, whatever it holds. */
.market-bar,
.panel,
.terminal {
  max-width: 100%;
}

/*
 * ```text
 * A GRID OR FLEX ITEM WILL NOT SHRINK BELOW ITS CONTENT UNLESS YOU SAY SO
 * ```
 *
 * `min-width: auto` is the default for a grid and flex item, and it means the item
 * refuses to be narrower than its content's min-content width. The market bar holds
 * nine columns with `min-width` floors, so its min-content width is about 1090px --
 * and `main`, being a grid item, grew to fit it and took the document with it. At a
 * 390px viewport the page scrolled sideways by 712px.
 *
 * `overflow-x: auto` on the bar could not help, because an item that never gets
 * squeezed never overflows. Saying `min-width: 0` down the chain is what lets the
 * squeeze reach the bar, which then scrolls in its own box as intended.
 */
#main,
.shell > main,
.terminal,
.market-bar,
.panel,
.panel-body,
.tabs,
.table-scroll,
/*
 * The navigation and the header's right-hand group are flex ITEMS as well as scroll
 * containers, and the same rule bites them: without this the nav refused to be
 * narrower than its six buttons and the page scrolled by nine pixels. Nine pixels is
 * still a page that scrolls sideways.
 */
.nav,
.topbar-right,
/*
 * And the header itself, which is a GRID item of the shell. It was the last nine
 * pixels: `flex-wrap: wrap` let its contents reflow, but the item still refused to be
 * narrower than the widest thing on any of those lines, so the grid column grew and
 * took the document with it.
 */
.topbar,
.shell > * {
  min-width: 0;
}

/* MAINNET / TESTNET context at the identity. Testnet is the loud one, so a terminal
   with no monetary value is never mistaken for the real one; it sits beside the chain's
   own verified identity, never in place of it. */
.net-kind {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: var(--t-micro);
  font-weight: 800;
  letter-spacing: 0.06em;
  margin-inline-end: 8px;
}
.net-kind-testnet {
  /* Was a fixed #f5b942 on white: 1.9:1 in light mode (A-013). The warn tokens hold >= 4.5:1 in both themes. */
  color: var(--dx-warn);
  background: var(--dx-warn-soft);
  border: 1px solid color-mix(in srgb, var(--dx-warn) 40%, transparent);
}
.net-kind-mainnet {
  color: inherit;
  opacity: 0.7;
  border: 1px solid currentColor;
}

/* ------------------------------------------------------------- the wallet --- */

button.tiny.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--dx-on-accent);
}

.wallet-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s3);
  padding: 2px 2px 2px var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: var(--t-small);
  max-width: 100%;
  min-width: 0;
}

.wallet-chip > span {
  font-family: var(--mono, ui-monospace, monospace);
  white-space: nowrap;
}

.wallet-chip .wallet-net {
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
}

.wallet-options {
  list-style: none;
  margin: var(--s4) 0;
  padding: 0;
  display: grid;
  gap: var(--s3);
}

.wallet-option {
  width: 100%;
  display: grid;
  gap: 2px;
  text-align: start;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  overflow-wrap: anywhere;
}

.wallet-option:not(:disabled):hover {
  border-color: var(--accent);
}

.wallet-option:disabled {
  cursor: not-allowed;
  opacity: 0.72;
  background: var(--surface-2);
}

.wallet-option small {
  color: var(--ink-2);
  line-height: 1.45;
}

a.tiny-link {
  font-size: var(--t-small);
  font-weight: 600;
  color: var(--accent-ink);
  text-decoration: none;
  white-space: nowrap;
}

a.tiny-link:hover { text-decoration: underline; }

/* ------------------------------------------------ asset logos (MIRCO_BRANDING_V1) --- */
/*
 * A pair is [LOGO A] A / [LOGO B] B. The box is fixed by the <img> width/height, so a logo that loads late moves
 * nothing; a missing one is the shared deterministic fallback, never a broken image. The ring keeps a dark logo
 * visible on the dark theme and a light one on the light theme, from the theme tokens alone.
 */
.asset-logo {
  display: inline-block;
  flex: none;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  background: var(--surface-2);
  box-shadow: 0 0 0 1px var(--line);
}
.pair-mark {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  column-gap: 0.35em;
  row-gap: 2px;
  min-width: 0;
  max-width: 100%;
}
.pair-leg,
.asset-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  min-width: 0;
  overflow-wrap: anywhere;
}
.activity-pair {
  margin-top: 2px;
  font-size: var(--t-micro);
  color: var(--ink-2);
}
/* A panel title that names a pair wraps at phone width instead of running under the panel's tools. */
.panel-title.pair-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 0.35em;
  min-width: 0;
  white-space: normal;
}
/* The id text beside a mark is the identity: always visible, never truncated by the mark. */
.market-identity {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 0.5em;
  row-gap: 2px;
  min-width: 0;
  max-width: 100%;
}
.identity-text {
  font-family: var(--mono);
  font-size: var(--t-micro);
  color: var(--ink-2);
  overflow-wrap: anywhere;
}
/* A network mark is a rounded square, so it never reads as an asset's disc. */
.asset-logo.network-logo {
  border-radius: 3px;
}

/* ------------------------------------------- the network switch (Universal AMM V1) --- */

/* Native / EVM / SVM. Each network is its own venue: the switch clears the selection and any open review. */
.net-switch {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
  min-width: 0;
}

.net-switch button {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: var(--tap);
  padding: 0 var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: var(--t-small);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.net-switch button[aria-pressed="true"] {
  background: var(--accent-quiet);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.net-badge {
  font-size: var(--t-micro);
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 0 5px;
  border-radius: 999px;
  border: 1px solid currentColor;
  opacity: 0.8;
}

button.tiny[aria-selected="true"] {
  background: var(--accent-quiet);
  border-color: var(--accent);
  color: var(--accent-ink);
}

[data-field="universal-tabs"] {
  flex-wrap: wrap;
  margin-block: var(--s3);
}

/* `hidden` must win over the flex display these bars declare. */
.nav[hidden],
.net-switch[hidden] {
  display: none;
}

/* A stacking table inside a box narrower than the table (DEX V5 fix, H-c7d840): each row becomes one labelled
 * record, whatever the viewport width. Every cell survives; nothing scrolls sideways. */
.dx-stack-host {
  container-type: inline-size;
}

@container (max-width: 820px) {
  table.grid.stack thead { display: none; }
  table.grid.stack, table.grid.stack tbody, table.grid.stack tr, table.grid.stack td { display: block; width: 100%; }
  table.grid.stack tr { padding: var(--s2) var(--s4); border-bottom: 1px solid var(--line-soft); }
  table.grid.stack td {
    display: flex; justify-content: space-between; align-items: center; gap: var(--s4);
    padding: 3px 0; border-bottom: 0; text-align: end; white-space: normal; overflow-wrap: anywhere;
  }
  table.grid.stack td::before {
    content: attr(data-label); flex: none; text-align: start;
    font-family: var(--sans, inherit); font-size: var(--t-micro); font-weight: 700;
    letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3);
  }
  table.grid.stack td:first-child { font-weight: 700; }
}
