:root {
  --bg: #0e1116;
  --panel: #161b22;
  --border: #30363d;
  --fg: #e6edf3;
  --dim: #8b949e;
  --accent: #58a6ff;
  --bid: #3fb950;
  --ask: #f85149;
  --warn: #d29922;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  background: var(--bg);
  color: var(--fg);
  font-size: 13px;
  line-height: 1.5;
}
.dim { color: var(--dim); }
.small { font-size: 11px; }

/* Asset page: full-viewport compact layout */
body.asset-page {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
header.compact {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 36px;
}
header.compact .back { font-size: 16px; }
header.compact h1 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
header.compact strong {
  color: var(--accent);
  background: rgba(88,166,255,0.15);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
}
header.compact code { font-size: 10px; }
header.compact .asset-id-tag { display: none; }
@media (min-width: 1500px) {
  header.compact .asset-id-tag { display: inline; }
}

header:not(.compact) {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
header:not(.compact) h1 { margin: 0 0 4px 0; font-size: 18px; }
.subtitle { margin: 0; color: var(--dim); font-size: 12px; }

.header-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.header-row h1 { margin: 0; }
.header-row .auth-slot { margin-left: auto; }

.topnav {
  display: flex;
  gap: 12px;
  margin: 4px 0 8px 0;
  font-size: 12px;
}
.topnav a {
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  color: var(--fg);
}
.topnav a:hover { border-color: var(--accent); text-decoration: none; }
.topnav a.active { border-color: var(--accent); color: var(--accent); background: rgba(88,166,255,0.08); }

.arb-pos { color: var(--bid); font-weight: 600; }
.arb-zero { color: var(--dim); }

th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
}
th.sortable:hover { color: var(--fg); }
th.sortable.sort-asc::after  { content: " ▲"; font-size: 9px; color: var(--accent); }
th.sortable.sort-desc::after { content: " ▼"; font-size: 9px; color: var(--accent); }

.help-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  line-height: 14px;
  text-align: center;
  border-radius: 50%;
  background: var(--panel);
  color: var(--dim);
  font-size: 10px;
  font-weight: 700;
  margin-left: 4px;
  cursor: help;
  position: relative;
  user-select: none;
}
.help-icon:hover { color: var(--accent); }
.help-icon:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  width: 320px;
  white-space: normal;
  text-align: left;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.5;
  font-weight: 400;
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
  z-index: 30;
  cursor: text;
}

/* Sign-in widget */
.auth-slot { display: flex; align-items: center; }
.auth-slot.compact { font-size: 11px; }
.auth-btn, .auth-pill {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.auth-btn:hover, .auth-pill:hover { border-color: var(--accent); }
.auth-btn { color: var(--accent); }
.auth-pill { font-variant-numeric: tabular-nums; }
.auth-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--bid);
}

.empty-state {
  padding: 40px 24px;
  text-align: center;
  color: var(--fg);
}
.empty-state p { margin: 4px 0; }

.totals-bar {
  display: flex;
  gap: 24px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(88,166,255,0.04);
  font-size: 12px;
  color: var(--dim);
  flex-wrap: wrap;
}
.totals-item strong {
  color: var(--fg);
  margin-left: 6px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.totals-bar:empty { display: none; }

/* Positions drill-down */
.market-row { cursor: pointer; }
.market-row:hover { background: rgba(88,166,255,0.06); }
/* On positions, the title <a> sits next to the ▶ toggle. The shared rule
   `#tbl tbody td:first-child a { display: block }` (markets page) would
   force a line break and stretch the link to full width — both of
   which we want suppressed here. ID selector specificity beats class so
   we mirror it. */
#tbl tbody .market-row td:first-child a,
#tbl tbody .ev-row td:first-child a { display: inline; word-break: normal; }
#tbl tbody .market-row td:first-child .ev-toggle,
#tbl tbody .ev-row td:first-child .ev-toggle {
  display: inline-block;
  width: 1em;
  color: var(--accent);
  margin-right: 4px;
}
.drilldown-row > td { padding: 0 !important; background: rgba(0,0,0,0.20); }
.drilldown {
  padding: 10px 14px 14px 32px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.drilldown-empty { padding: 8px; color: var(--dim); font-size: 11px; }
.drilldown-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--dim);
}
.drilldown-side strong { color: var(--accent); }
.drilldown-toggle {
  font-size: 11px;
  padding: 2px 8px;
}
.book-grid {
  display: grid;
  grid-template-columns: 80px 80px 24px;
  gap: 0;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  width: max-content;
}
.book-col-head {
  padding: 4px 8px;
  font-size: 10px;
  color: var(--dim);
  background: rgba(0,0,0,0.25);
  border-bottom: 1px solid var(--border);
}
.book-col-head.num { text-align: right; }
.book-price { padding: 3px 8px; font-weight: 600; }
.book-price.ask { color: var(--ask); }
.book-price.bid { color: var(--bid); }
.book-size { padding: 3px 8px; text-align: right; }
.book-dot { padding: 3px 6px; }
.book-spread {
  padding: 4px 8px;
  text-align: center;
  background: rgba(255,255,255,0.04);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  color: var(--dim);
  font-size: 11px;
}
.book-price.in-band, .book-size.in-band, .book-dot.in-band {
  background: rgba(88,166,255,0.10);
}
.your-order-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  vertical-align: middle;
  background: var(--accent);
}

/* Drill-down two-column body: book on left, orders panel on right. */
.drilldown-body {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.orders-panel {
  flex: 1 1 360px;
  min-width: 320px;
  max-width: 560px;
}
.drilldown-side-panel {
  flex: 1 1 420px;
  min-width: 340px;
  max-width: 620px;
  display: grid;
  gap: 12px;
}
.drilldown-side-panel .orders-panel {
  min-width: 0;
  max-width: none;
}
.orders-head { margin-bottom: 6px; font-size: 11px; color: var(--dim); }
.orders-table {
  width: 100%;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  border-collapse: collapse;
}
.orders-table th,
.orders-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.orders-table .num { text-align: right; }
.orders-table thead th {
  background: rgba(0,0,0,0.25);
  color: var(--dim);
  font-size: 10px;
  font-weight: 500;
}
.orders-table tbody tr:last-child td { border-bottom: 0; }
.o-side.o-buy  { color: var(--bid); font-weight: 600; }
.o-side.o-sell { color: var(--ask); font-weight: 600; }
.o-outcome {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
}
.o-outcome.o-yes { background: rgba(63,185,80,0.18); color: var(--bid); }
.o-outcome.o-no  { background: rgba(248,81,73,0.18); color: var(--ask); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--panel); padding: 2px 4px; border-radius: 3px; font-size: 11px; }

.controls {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}
.controls label { display: inline-flex; gap: 6px; align-items: center; }
.controls input[type=text] { width: 280px; }
.controls input, .controls select, .controls button {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font: inherit;
}
.controls button { cursor: pointer; }
.controls button:hover { border-color: var(--accent); }
.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  background: var(--panel);
}
.controls .segmented button {
  border: 0;
  border-right: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--dim);
}
.controls .segmented button:last-child { border-right: 0; }
.controls .segmented button:hover { color: var(--fg); background: rgba(88,166,255,0.08); }
.controls .segmented button.active {
  color: var(--fg);
  background: rgba(88,166,255,0.18);
}
.hint { color: var(--dim); font-size: 11px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
table thead th {
  text-align: left;
  font-weight: 600;
  color: var(--dim);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  position: sticky; top: 0;
  background: var(--bg);
}
table tbody td {
  border-bottom: 1px solid var(--border);
  padding: 4px 12px;
  vertical-align: top;
}
table tbody tr:hover { background: rgba(88, 166, 255, 0.05); }
table .num { text-align: right; font-variant-numeric: tabular-nums; }

#tbl tbody td:first-child { max-width: 520px; }
#tbl tbody td:first-child a { display: block; word-break: break-word; }
.outcome {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  background: rgba(88,166,255,0.15);
  color: var(--accent);
  font-size: 11px;
}
.speed-wrap { display: inline-flex; gap: 4px; align-items: center; }
#btnPlay { min-width: 90px; }

/* Event-group header rows in the index table */
.ev-row {
  cursor: pointer;
  background: rgba(88, 166, 255, 0.06);
}
.ev-row:hover { background: rgba(88, 166, 255, 0.12); }
.ev-row td { font-weight: 600; }
.ev-row .ev-toggle { display: inline-block; width: 1em; color: var(--accent); }
.ev-row .ev-meta { font-weight: 400; margin-left: 8px; }
tr.child-row td:first-child { padding-left: 32px; }
.warn-text { color: var(--warn); }

/* Stream header: title + tail/types selectors on one row */
.stream .stream-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: nowrap;
}
.stream .stream-head h3 { margin: 0; flex: 1 1 auto; }
.stream-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 11px;
}
.stream-controls select,
.stream-controls .dropdown-btn {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 6px;
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}
.stream-controls .dropdown-btn:hover { border-color: var(--accent); }

.dropdown { position: relative; }
.dropdown-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 2px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 0;
  min-width: 160px;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.dropdown-panel label {
  display: flex;
  gap: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 11px;
  white-space: nowrap;
}
.dropdown-panel label:hover { background: rgba(88,166,255,0.08); }

/* Chart */
.chart-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 12px;
  flex: 0 0 auto;
}
.chart-controls select {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  font: inherit;
  font-size: 12px;
}
#chart {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
}

.my-trade-tip {
  display: none;
  position: absolute;
  background: rgba(13, 17, 23, 0.95);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  white-space: nowrap;
  z-index: 10;
  min-width: 130px;
}
.my-trade-tip .row { display: flex; gap: 6px; line-height: 1.5; }
.my-trade-tip a { color: var(--accent); pointer-events: auto; }
.my-trade-tip .matched {
  color: var(--accent);
  font-weight: 700;
}
.my-trade-tip .role {
  display: inline-block;
  width: 14px;
  text-align: center;
  font-weight: 700;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
}
.my-trade-tip .row.buy  .side { color: var(--bid); font-weight: 600; }
.my-trade-tip .row.sell .side { color: var(--ask); font-weight: 600; }

.timeline { flex-direction: column; align-items: stretch; }
.time-row { display: flex; gap: 12px; align-items: center; }
.time-row .t-current { font-weight: 600; min-width: 220px; }
#slider { flex: 1; min-width: 0; }
.ticks {
  position: relative;
  height: 6px;
  flex: 0 0 auto;
  margin: -2px 16px 4px 16px;
}
.ticks .tick {
  position: absolute;
  width: 1px; top: 0; bottom: 0;
  background: var(--accent);
  opacity: 0.55;
}

.compact-controls {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: nowrap;
  min-height: 36px;
}
.compact-controls button {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.compact-controls button:hover { border-color: var(--accent); }
.compact-controls select {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 4px;
  font: inherit;
  font-size: 12px;
}
.compact-controls #btnPlay { min-width: 70px; font-weight: 600; }
.compact-controls .t-current {
  font-weight: 600;
  min-width: 200px;
  font-size: 12px;
  text-align: right;
}

.quality {
  padding: 4px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.quality.inline {
  flex: 1 1 280px;
  min-width: 0;
}
.quality.good   { border-left: 3px solid var(--bid); }
.quality.warn   { border-left: 3px solid var(--warn); }
.quality.bad    { border-left: 3px solid var(--ask); }

main.grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 10px;
  padding: 8px 16px 12px 16px;
}
.chart-section { grid-column: 1; min-width: 0; min-height: 0; }
.ladder        { grid-column: 2; min-width: 0; min-height: 0; }
.stream        { grid-column: 3; min-width: 0; min-height: 0; }
@media (max-width: 1100px) {
  main.grid {
    grid-template-columns: 1fr;
    grid-template-rows: 280px 260px 1fr;
  }
  .chart-section { grid-column: 1; grid-row: 1; }
  .ladder       { grid-column: 1; grid-row: 2; }
  .stream       { grid-column: 1; grid-row: 3; }
}

/* Compact events table for narrow column */
.stream .events table { font-size: 11px; }
.stream .events table td,
.stream .events table th { padding: 3px 6px; }
.stream .events table td:nth-child(6) {
  /* extra column wraps gracefully */
  white-space: normal;
  word-break: break-word;
  max-width: 120px;
}

.ladder, .stream, .chart-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
}
.ladder h3, .stream h3 { margin: 0 0 6px 0; font-size: 12px; color: var(--dim); }
.stream .hint { margin: 0 0 6px 0; }

/* Hyperliquid-style stacked book */
.hl-book {
  display: flex;
  flex-direction: column;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  flex: 1 1 auto;
  min-height: 0;
}
.hl-header {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 6px 10px;
  font-size: 11px;
  color: var(--dim);
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.2);
}
.hl-asks, .hl-bids {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.hl-spread { flex: 0 0 auto; }
.ladder #bookSummary { margin: 6px 0 0 0; }
.hl-spread {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 6px 10px;
  background: rgba(255,255,255,0.04);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}
.hl-spread .num { text-align: right; }
.hl-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 0 10px;
  font-size: 12px;
  height: 22px;
  align-items: center;
  flex-shrink: 0;
}
.hl-row::before {
  content: "";
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: var(--bar, 0%);
  pointer-events: none;
  z-index: 0;
}
.hl-row.ask::before { background: rgba(248, 81, 73, 0.20); }
.hl-row.bid::before { background: rgba(63, 185, 80, 0.20); }
.hl-row > * { position: relative; z-index: 1; }
.hl-row .num { text-align: right; }
.hl-row.ask .price { color: var(--ask); font-weight: 600; }
.hl-row.bid .price { color: var(--bid); font-weight: 600; }
/* Best level on each side gets a subtle accent border */
.hl-asks .hl-row:last-child::after,
.hl-bids .hl-row:first-child::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 0;
  border-bottom: none;
}

.events tr.trade  td { background: rgba(248, 81, 73, 0.07); }
.events tr.my-fill td {
  background: rgba(63, 185, 80, 0.16);
  box-shadow: inset 3px 0 0 var(--bid);
}
.my-fill-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  border: 1px solid rgba(63, 185, 80, 0.55);
  border-radius: 3px;
  color: var(--bid);
  background: rgba(63, 185, 80, 0.12);
  font-size: 11px;
  font-weight: 700;
}
.events tr.book   td { background: rgba(88, 166, 255, 0.10); }
.events td.side-BUY  { color: var(--bid); }
.events td.side-SELL { color: var(--ask); }
.events {
  flex: 1 1 auto;
  min-height: 0;
  display: block;
  overflow: auto;
}

#status { margin-left: auto; }

/* ============ Add-LP modal + +LP button on NegRisk page ============= */
button.lp-button {
  background: transparent;
  color: var(--accent, #58a6ff);
  border: 0;
  padding: 0;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
button.lp-button:hover { filter: brightness(1.25); }
button.lp-button:disabled { opacity: 0.4; cursor: not-allowed; text-decoration: none; }

.lp-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.lp-modal[hidden] { display: none; }
.lp-modal-box {
  background: var(--bg-panel, #161b22);
  border: 1px solid var(--border, #30363d);
  border-radius: 6px;
  padding: 18px 22px;
  width: min(760px, 92vw);
  display: flex; flex-direction: column; gap: 10px;
}
.lp-modal-box h3 { margin: 0; }
.lp-modal-box label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 13px;
}
.lp-modal-box input, .lp-modal-box select {
  background: var(--bg, #0d1117);
  border: 1px solid var(--border, #30363d);
  color: inherit;
  padding: 6px 8px;
  border-radius: 4px;
}
.lp-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.lp-modal-actions button {
  padding: 6px 14px;
  border-radius: 4px;
  border: 1px solid var(--border, #30363d);
  background: var(--bg, #0d1117);
  color: inherit;
  cursor: pointer;
}
#lpConfirm { background: var(--accent, #58a6ff); color: #0d1117; font-weight: 600; border: 0; }
#lpConfirm:disabled { opacity: 0.4; cursor: not-allowed; }
#lpProgress {
  font-size: 12px;
  font-family: ui-monospace, monospace;
  white-space: normal;
  max-height: 360px;
  overflow-y: auto;
  background: var(--bg, #0d1117);
  border: 1px solid var(--border, #30363d);
  border-radius: 4px;
  padding: 8px;
  margin-top: 4px;
  display: none;
}
#lpProgress.show { display: block; }
.taker-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.taker-suggestions button {
  background: transparent;
  color: var(--accent, #58a6ff);
  border: 1px solid var(--border, #30363d);
  border-radius: 4px;
  padding: 4px 7px;
  cursor: pointer;
  font: inherit;
}
.taker-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}
.taker-metrics span {
  border: 1px solid var(--border, #30363d);
  border-radius: 4px;
  padding: 5px 7px;
  color: var(--dim);
}
.taker-metrics b { color: var(--fg); }
.taker-breakdown {
  margin-top: 8px;
  font-size: 11px;
}
.taker-breakdown th,
.taker-breakdown td {
  padding: 4px 6px;
}
.taker-breakdown tfoot th,
.taker-breakdown tfoot td {
  border-top: 1px solid var(--border, #30363d);
  font-weight: 700;
}

.stale-banner {
  background: rgba(248, 81, 73, 0.10);
  border: 1px solid rgba(248, 81, 73, 0.45);
  color: #ffb4ad;
  padding: 10px 14px;
  border-radius: 4px;
  margin: 10px 0;
  font-size: 13px;
  line-height: 1.45;
}
.stale-banner[hidden] { display: none; }
.stale-banner small { display: block; margin-top: 4px; font-size: 11px; opacity: 0.7; }

.mc-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(120px, 1fr) minmax(130px, 0.8fr);
  gap: 10px;
  margin: 8px 0;
}
.mc-add-step {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}
.mc-add-step[hidden],
.mc-link-preview[hidden],
#mcSettings[hidden],
#mcSettingsHint[hidden],
#mcNote[hidden] {
  display: none;
}
.mc-add-step button {
  padding: 6px 14px;
  min-height: 31px;
}
.mc-link-preview {
  border: 1px solid var(--border, #30363d);
  border-radius: 4px;
  padding: 10px 12px;
  background: var(--bg, #0d1117);
  line-height: 1.45;
}
.mc-link-preview strong {
  display: block;
  margin-bottom: 4px;
}
.mc-check {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  align-self: end;
  gap: 8px;
  min-height: 31px;
  color: var(--dim);
}
.mc-check input {
  width: auto;
  margin: 0;
}
@media (max-width: 900px) {
  .mc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.manual-row {
  background: rgba(88, 166, 255, 0.05);
}

.toast-host {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 36px));
  pointer-events: none;
}
.toast {
  border: 1px solid var(--border, #30363d);
  border-radius: 4px;
  padding: 10px 12px;
  background: #0d1117;
  color: var(--fg, #e6edf3);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  font-size: 13px;
  line-height: 1.35;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast-success {
  border-color: rgba(63, 185, 80, 0.65);
  background: rgba(35, 90, 48, 0.96);
}
.toast-error {
  border-color: rgba(248, 81, 73, 0.70);
  background: rgba(111, 33, 33, 0.96);
}
.toast-out {
  opacity: 0;
  transform: translateY(8px);
}

/* API docs link injected by auth.js, sits just left of the sign-in pill */
.api-docs-link {
  color: var(--accent, #58a6ff);
  font-size: 12px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  margin-right: 12px;
  margin-left: auto;
}
.api-docs-link:hover { filter: brightness(1.25); }
.api-docs-link.active { text-decoration: underline; text-decoration-thickness: 2px; }
/* When .api-docs-link claims the auto-margin, the auth-slot loses it */
.api-docs-link + .auth-slot { margin-left: 0; }

/* ============== API docs page ============== */
body.api-docs-page { padding: 0; }
.api-docs-wrap {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 28px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px 24px 80px;
}
.api-docs-toc {
  position: sticky;
  top: 18px;
  align-self: start;
  font-size: 12px;
}
.api-docs-toc h4 {
  margin: 0 0 6px;
  font-size: 11px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.api-docs-toc ul { list-style: none; padding: 0; margin: 0 0 14px; }
.api-docs-toc li { margin: 2px 0; }
.api-docs-toc a {
  color: var(--fg);
  text-decoration: none;
  border-left: 2px solid transparent;
  padding-left: 8px;
  display: block;
}
.api-docs-toc a:hover { color: var(--accent); }
.api-docs-toc a.depth-2 { padding-left: 18px; color: var(--dim); }
.api-docs-toc a.depth-2:hover { color: var(--accent); }
.api-docs-toc .toc-section {
  font-size: 11px;
  color: var(--dim);
  margin: 12px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-left: 8px;
}

.api-docs-main h2 {
  margin: 24px 0 6px;
  font-size: 18px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}
.api-docs-main h2:first-child { margin-top: 4px; }
.api-docs-main h3 {
  margin: 22px 0 6px;
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
}
.api-docs-main h4 { margin: 14px 0 4px; font-size: 12px; color: var(--dim); }
.api-docs-main p { margin: 6px 0; }
.api-docs-main code {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 12px;
}
.api-docs-main pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 12px;
  overflow-x: auto;
  line-height: 1.45;
  margin: 6px 0 12px;
}
.api-docs-main pre code { border: 0; padding: 0; background: transparent; }
.api-docs-main table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: 6px 0 12px;
}
.api-docs-main table th, .api-docs-main table td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.api-docs-main table th {
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.04em;
}
.api-docs-main table td code { font-size: 11px; }
.api-docs-main .req {
  color: var(--ask);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
}
.api-docs-main .opt {
  color: var(--dim);
  font-size: 10px;
  text-transform: uppercase;
}
.api-docs-main .badge {
  display: inline-block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 6px;
  font-size: 10px;
  color: var(--dim);
  margin-left: 8px;
  vertical-align: middle;
}
.api-docs-main .callout {
  background: rgba(88, 166, 255, 0.06);
  border-left: 3px solid var(--accent);
  padding: 8px 12px;
  border-radius: 0 4px 4px 0;
  margin: 10px 0;
  font-size: 12px;
}
.api-docs-main .callout.warn {
  background: rgba(210, 153, 34, 0.08);
  border-left-color: var(--warn);
}
@media (max-width: 800px) {
  .api-docs-wrap { grid-template-columns: 1fr; }
  .api-docs-toc { position: static; }
}

/* ============ Market WS live demo on /api-docs ============ */
.ws-demo {
  border: 1px solid var(--accent, #58a6ff);
  border-radius: 6px;
  padding: 12px 14px;
  margin: 10px 0 22px;
  background: rgba(88, 166, 255, 0.04);
}
.ws-demo h4 { font-size: 13px; color: var(--accent); }
.ws-demo-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 6px 0; font-size: 12px; }
.ws-demo-controls label { display: flex; gap: 4px; align-items: center; }
.ws-demo-btn {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 4px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.ws-demo-btn:hover { border-color: var(--accent); }
.ws-demo-btn.primary { background: var(--accent); color: #0d1117; border: 0; font-weight: 600; }
.ws-demo-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ws-demo-market { font-size: 11px; line-height: 1.55; margin: 4px 0 8px; }
.ws-demo-market code { font-size: 10px; }
.ws-demo-filters {
  display: flex; gap: 12px; flex-wrap: wrap; align-items: center;
  font-size: 11px; padding: 6px 0; border-top: 1px dashed var(--border);
}
.ws-demo-filters label { display: flex; gap: 4px; align-items: center; }
.ws-demo-log {
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  font-size: 11px;
  height: 360px;
  overflow-y: auto;
  padding: 6px;
  font-variant-numeric: tabular-nums;
}
.ws-demo-row { padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,0.04); }
.ws-demo-time { color: var(--dim); margin-right: 8px; }
.ws-demo-type {
  display: inline-block;
  min-width: 130px;
  font-weight: 600;
}
.ws-demo-prev { color: var(--fg); }
.ws-demo-row.ws-demo-book .ws-demo-type      { color: var(--accent); }
.ws-demo-row.ws-demo-price_change .ws-demo-type { color: var(--warn); }
.ws-demo-row.ws-demo-last_trade_price .ws-demo-type { color: var(--bid); }
.ws-demo-row.ws-demo-best_bid_ask .ws-demo-type { color: #d2a8ff; }
.ws-demo-row.ws-demo-tick_size_change .ws-demo-type { color: var(--ask); }
.ws-demo-row.ws-demo-meta { color: var(--dim); font-style: italic; }
.ws-demo-raw { display: inline-block; margin-left: 8px; }
.ws-demo-raw summary { cursor: pointer; font-size: 10px; }
.ws-demo-raw pre { margin: 4px 0; font-size: 10px; line-height: 1.4; max-width: 700px; }
#wsDemoStatus.err { color: var(--ask); }
#wsDemoStatus.ok  { color: var(--bid); }

/* Address pill is now a link to the Profile page + a separate sign-out button */
a.auth-pill { text-decoration: none; }
a.auth-pill:hover { border-color: var(--accent); }
.auth-signout {
  background: transparent;
  color: var(--dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  margin-left: 6px;
}
.auth-signout:hover { color: var(--ask); border-color: var(--ask); }

/* ============ Profile page ============ */
.profile-tabs { display: flex; gap: 8px; margin: 4px 0 0; }
.profile-tabs button {
  background: var(--panel); color: var(--fg);
  border: 1px solid var(--border); border-bottom: 0;
  border-radius: 5px 5px 0 0; padding: 6px 16px; font: inherit; font-size: 13px; cursor: pointer;
}
.profile-tabs button.active { border-color: var(--accent); color: var(--accent); background: rgba(88,166,255,0.08); }
.reward-badge {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 3px;
  text-transform: uppercase; letter-spacing: 0.03em; font-weight: 600;
}
.reward-badge.earning   { color: var(--bid); background: rgba(63,185,80,0.12); }
.reward-badge.below_min { color: var(--warn); background: rgba(210,153,34,0.12); }
.reward-badge.no_rewards { color: var(--dim); background: rgba(139,148,158,0.10); }
.scoring-badge { display:inline-block; font-size:10px; padding:1px 6px; border-radius:3px; font-weight:600; }
.scoring-badge.yes { color: var(--bid); background: rgba(63,185,80,0.12); }
.scoring-badge.no  { color: var(--dim); background: rgba(139,148,158,0.10); }
.pnl-pos { color: var(--bid); }
.pnl-neg { color: var(--ask); }
.profile-icon { width: 16px; height: 16px; border-radius: 50%; vertical-align: middle; margin-right: 6px; }
.cond-progress { display:inline-block; width: 60px; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; vertical-align: middle; margin-left: 6px; }
.cond-progress > i { display:block; height: 100%; background: var(--accent); }
.profile-est-dim { color: var(--dim); font-size: 11px; }

/* Profile page: keep market icon + title + outcome badge on a single row
   (override the markets-page block-display rule at td:first-child a). */
body.profile-page #tbl tbody td:first-child { white-space: nowrap; }
body.profile-page #tbl tbody td:first-child a { display: inline; word-break: normal; }
body.profile-page .profile-icon { vertical-align: middle; }
body.profile-page #tbl tbody td:first-child .reward-badge { vertical-align: middle; }

/* Sell confirm modal: two-column key/value grid. */
.sell-modal-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 16px;
  margin: 6px 0;
  font-size: 13px;
}
.sell-modal-grid > span:nth-child(odd) { color: var(--dim); }
.sell-modal-grid .num { font-variant-numeric: tabular-nums; }
button.sell-pos-btn { padding: 2px 10px; }
