:root {
  color-scheme: dark;
  --bg: #0c0d0e;
  --elev: #111215;
  --sunken: #0c0d0f;
  --ink: #e5e7eb;
  --muted: #9ca3af;
  --faint: #6b7280;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --accent: #34d399;
  --go: #34d399;
  --down: #fb7185;
  --warn: #fbbf24;
  --danger: #e11d48;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset;
  font-family: "Instrument Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

::selection { background: #262626; color: #fff; }

body {
  margin: 0;
  min-height: 100vh;
  color: #d1d5db;
  background: var(--bg);
}

body[data-mode="live"]::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--danger);
  z-index: 40;
}

button, input, select { font: inherit; color: inherit; }

button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  background: #262626;
  color: var(--ink);
  cursor: pointer;
  font-weight: 550;
}

button:hover:not(:disabled) { background: #333; }

button:disabled { cursor: not-allowed; opacity: 0.55; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid #525252;
  outline-offset: 2px;
}

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #111215;
  border-bottom: 1px solid rgba(38, 38, 38, 0.9);
}

.bar, .frame {
  width: min(1720px, calc(100% - 32px));
  margin-inline: auto;
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  min-height: 52px;
  padding: 10px 0;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1 1 280px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  flex: none;
}

.desk-brand { gap: 10px; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #6b7280;
  box-shadow: 0 0 8px rgba(107, 114, 128, 0.45);
  flex: none;
}

body[data-copying="1"] .status-dot {
  background: #10b981;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

body[data-mode="live"] .status-dot {
  background: #fb7185;
  box-shadow: 0 0 8px rgba(251, 113, 133, 0.55);
}

.desk-title {
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #f5f5f5;
}

.logo {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent);
  color: #0c0d0e;
  flex: none;
}

.brand-text { display: grid; line-height: 1.05; }

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.mark {
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.pill {
  border: 1px solid #262626;
  border-radius: 6px;
  padding: 0.18rem 0.5rem;
  color: #a3a3a3;
  background: #171717;
  font-size: 0.72rem;
  font-weight: 550;
  white-space: nowrap;
}

.pill.paper { background: #262626; color: #d4d4d4; border-color: transparent; }

.pill.on {
  color: #34d399;
  background: rgba(6, 78, 59, 0.7);
  border-color: rgba(6, 95, 70, 0.7);
}

.pill.live {
  color: #ffe7a8;
  background: rgba(240, 193, 74, 0.12);
  border-color: rgba(240, 193, 74, 0.32);
}

.pill.bad {
  color: #fda4af;
  background: rgba(136, 19, 55, 0.45);
  border-color: rgba(159, 18, 57, 0.55);
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 18px;
  flex: none;
}

.net {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.net-label {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.profit-num {
  margin: 0;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: #f5f5f5;
  font-variant-numeric: tabular-nums;
}

.profit-num.up { color: var(--go); }
.profit-num.down { color: var(--down); }
.profit-num.paper { color: #f5f5f5; }
.profit-num.paper.up { color: var(--go); }
.profit-num.paper.down { color: var(--down); }

.unit {
  display: inline-flex;
  padding: 2px;
  border-radius: 6px;
  border: 1px solid #262626;
  background: #171717;
}

.unit button {
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.68rem;
  font-weight: 500;
}

.unit button[aria-pressed="true"] {
  background: #404040;
  color: #f5f5f5;
}

.unit button:hover:not(:disabled) { background: transparent; color: #e5e5e5; }
.unit button[aria-pressed="true"]:hover:not(:disabled) { background: #404040; }

.logout button {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 0.3rem 0.2rem;
  font-size: 0.75rem;
  font-weight: 500;
}

.logout button:hover { color: #e5e5e5; background: transparent; }

.frame { padding: 18px 0 48px; }

.strips { display: grid; gap: 8px; margin-bottom: 14px; }
.strips:empty { display: none; }

.strip {
  margin: 0;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.82rem;
}

.strip.live {
  color: #ffe7a8;
  background: rgba(240, 193, 74, 0.08);
  border-color: rgba(240, 193, 74, 0.24);
}

.strip.warn {
  color: #fecdd3;
  background: rgba(225, 29, 72, 0.12);
  border-color: rgba(225, 29, 72, 0.32);
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, 0.85fr);
  gap: 20px;
  align-items: start;
}

.book, .rail { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.sheet, .panel {
  background: var(--elev);
  border: 1px solid rgba(38, 38, 38, 0.9);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.tabbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding: 10px 12px;
  flex-wrap: wrap;
}

.tabs {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 8px;
  background: #0c0d0f;
  border: 1px solid #262626;
}

.tabs button {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 6px;
  padding: 0.38rem 0.85rem;
  font-size: 0.75rem;
  font-weight: 550;
}

.tabs button:hover:not(:disabled) { background: rgba(38, 38, 38, 0.45); color: #e5e5e5; }

.tabs button[aria-selected="true"] {
  background: #262626;
  color: #f5f5f5;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
}

.tab-count {
  margin-left: 4px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.68rem;
  opacity: 0.7;
}

.book-note {
  margin: 0;
  font-size: 0.68rem;
  line-height: 1.4;
  max-width: 36rem;
  text-align: right;
}

.table-sheet { overflow: hidden; min-height: 8rem; }

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.75rem;
}

thead th {
  padding: 10px 14px;
  border-bottom: 1px solid #262626;
  background: rgba(23, 23, 23, 0.65);
  color: var(--muted);
  font-weight: 550;
  white-space: nowrap;
}

th.right, td.time { text-align: right; }

tbody td {
  padding: 12px 14px;
  border-top: 1px solid rgba(38, 38, 38, 0.65);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  color: #d4d4d4;
  vertical-align: middle;
  white-space: nowrap;
}

tbody tr:hover { background: rgba(38, 38, 38, 0.28); }

tr.failed { background: rgba(225, 29, 72, 0.08); }

.asset {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: "Instrument Sans", "Segoe UI", sans-serif;
}

.asset .row-close { margin-left: 10px; }

.asset strong {
  display: block;
  color: #f5f5f5;
  font-size: 0.78rem;
  letter-spacing: -0.01em;
}

.subname, .fail {
  display: block;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 450;
}

.fail { color: var(--down); margin-top: 2px; }

.mono {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  flex: none;
  border: 1px solid rgba(64, 64, 64, 0.7);
  background: #262626;
  color: #d4d4d4;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.62rem;
  font-weight: 650;
}

.mono.a { color: #d5defe; }
.mono.b { color: #bbf7d0; }
.mono.c { color: #fde68a; }
.mono.d { color: #fecdd3; }

.ca {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.68rem;
  font-weight: 450;
}

.ca:hover:not(:disabled) { background: transparent; color: #e5e5e5; }

.muted { color: var(--faint); }

.ico { width: 12px; height: 12px; flex: none; }
.ico-ok { display: none; color: var(--go); }
.ca .ico-copy { opacity: 0.45; }
.ca:hover .ico-copy { opacity: 1; }
.ca.copied .ico-copy { display: none; }
.ca.copied .ico-ok { display: block; }

.pnl { display: flex; align-items: center; gap: 6px; }
.up { color: var(--go); }
.down { color: var(--down); }

.pct {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 6px;
  border-radius: 999px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.65rem;
  font-weight: 650;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
}

.pct.up { color: #d1fae5; background: rgba(16, 185, 129, 0.2); }
.pct.down { color: #ffe4e6; background: rgba(251, 113, 133, 0.18); }

.time {
  color: var(--muted);
  font-family: "Instrument Sans", "Segoe UI", sans-serif;
  font-size: 0.68rem;
}

.row-close {
  margin-left: 8px;
  padding: 0.22rem 0.5rem;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  font-size: 0.68rem;
}

.row-close:hover:not(:disabled) { background: rgba(255, 255, 255, 0.05); }

tr.failed .row-close {
  background: var(--danger);
  color: white;
  border-color: transparent;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 56px 20px;
  text-align: center;
}

.empty-title {
  margin: 0;
  color: #d4d4d4;
  font-size: 0.88rem;
  font-weight: 600;
}

.empty {
  margin: 0;
  max-width: 26rem;
  color: var(--faint);
  font-size: 0.75rem;
  line-height: 1.45;
}

.ledger {
  padding: 14px 16px 12px;
  background: transparent;
  border: 0;
  box-shadow: none;
  border-radius: 0;
}

.ledger-head, .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(38, 38, 38, 0.9);
}

.ledger-head h2, .panel h2, .panel-head h2 {
  margin: 0;
  color: #e5e5e5;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ledger-head span {
  color: var(--faint);
  font-size: 0.68rem;
}

#events {
  list-style: none;
  margin: 10px 0 0;
  padding: 0 4px 4px 0;
  max-height: min(36rem, calc(100vh - 260px));
  min-height: 12rem;
  overflow: auto;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
}

#events li {
  display: grid;
  grid-template-columns: 5.4rem auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 4px 0;
  line-height: 1.35;
}

#events time { color: var(--faint); }

#events .msg { color: #d4d4d4; }
#events .warn { color: #fda4af; }
#events .quiet { grid-template-columns: 1fr; }

.tag {
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: #262626;
  color: #a3a3a3;
}

.tag.buy { color: #34d399; background: #022c22; border: 1px solid rgba(6, 78, 59, 0.7); }
.tag.sell { color: #fbbf24; background: #451a03; border: 1px solid rgba(120, 53, 15, 0.7); }
.tag.warn { color: #fb7185; background: #4c0519; border: 1px solid rgba(136, 19, 55, 0.7); }

.rail {
  position: sticky;
  top: 68px;
  align-self: start;
  max-height: calc(100vh - 84px);
  overflow: auto;
  padding-right: 2px;
}

.panel { padding: 14px 16px 16px; }

.engine-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

#copyToggle {
  flex: none;
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
}

#copyToggle[data-enabled="1"] {
  background: rgba(6, 78, 59, 0.85);
  color: #a7f3d0;
  border: 1px solid rgba(6, 95, 70, 0.75);
}

#copyToggle[data-enabled="1"]:hover:not(:disabled) { background: rgba(6, 95, 70, 0.75); }

.flash-row {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(38, 38, 38, 0.9);
}

#flash {
  width: 100%;
  min-height: 38px;
  background: #171717;
  color: #d4d4d4;
  border: 1px solid #262626;
  font-size: 0.75rem;
}

#flash:hover:not(:disabled) { border-color: #404040; background: #171717; }

#flash:disabled {
  opacity: 1;
  color: var(--faint);
  background: #171717;
}

#flash.armed {
  background: var(--danger);
  color: white;
  border-color: transparent;
  animation: pulse 1.1s ease-in-out infinite;
}

#flash[data-busy="1"] {
  background: var(--danger);
  color: white;
  border-color: transparent;
  opacity: 0.75;
  animation: none;
}

.hint { color: var(--muted); }

.panel .hint, #flash-help, #copy-blurb {
  margin: 6px 0 0;
  font-size: 0.68rem;
  line-height: 1.45;
  text-align: left;
}

#flash-help { text-align: center; color: var(--faint); }

label {
  display: grid;
  gap: 4px;
  margin: 10px 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 500;
}

.fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.fields label { margin: 0; }

input, select {
  width: 100%;
  border: 1px solid #262626;
  border-radius: 6px;
  min-height: 32px;
  padding: 0.35rem 0.5rem;
  background: #171717;
  color: #e5e5e5;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
}

#wallet { font-size: 0.68rem; }

input:focus, select:focus { border-color: #525252; outline: none; }

input[type="number"] { appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { appearance: none; margin: 0; }

.check {
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 8px;
  font-weight: 450;
  line-height: 1.4;
}

.check input {
  width: 0.9rem;
  height: 0.9rem;
  min-height: 0;
  margin-top: 0.1rem;
  accent-color: #a3a3a3;
}

.panel > button,
#fire {
  width: 100%;
  margin-top: 4px;
  font-size: 0.75rem;
}

.text-btn {
  width: auto;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 500;
}

.text-btn:hover:not(:disabled) { background: transparent; color: #e5e5e5; }

#skips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 0 0;
  margin: 0;
}

#skips li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: #171717;
  border: 1px solid #262626;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.68rem;
  color: #d4d4d4;
}

#skips li.empty-skip {
  display: block;
  width: 100%;
  background: transparent;
  border: 0;
  padding: 8px 0 0;
  font-family: "Instrument Sans", "Segoe UI", sans-serif;
}

#skips button {
  width: auto;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-family: "Instrument Sans", "Segoe UI", sans-serif;
  font-size: 0.62rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#skips button:hover:not(:disabled) { background: transparent; color: #e5e5e5; }

.signal-row {
  display: grid;
  grid-template-columns: 0.7fr 1.1fr;
  gap: 8px;
}

.signal-row label { margin: 8px 0; }

.steps { margin: 10px 0 0; padding-left: 1.1rem; color: var(--muted); font-size: 0.78rem; }
.steps li { margin: 0.5rem 0; }
code { color: var(--ink); font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 0.74rem; }

details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: #e5e5e5;
  list-style: none;
}

details summary::-webkit-details-marker { display: none; }

details summary::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
  flex: none;
}

details[open] summary::after { transform: rotate(-135deg) translateY(-1px); }

#conn { margin-bottom: 0; }

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate form {
  width: min(420px, 100%);
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 26px 24px;
  box-shadow: var(--shadow);
}

.gate .brand { margin-bottom: 22px; }

.gate h1 {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 650;
  letter-spacing: -0.04em;
  color: var(--ink);
}

.gate .lede { margin: 8px 0 4px; line-height: 1.45; color: var(--muted); }

.gate button[type="submit"] {
  width: 100%;
  margin-top: 6px;
  background: #f3f4f6;
  color: #111215;
  border: 0;
  font-weight: 650;
}

.gate button[type="submit"]:hover:not(:disabled) { background: #fff; }

.error {
  margin: 12px 0;
  color: #fecdd3;
  background: rgba(225, 29, 72, 0.12);
  border: 1px solid rgba(225, 29, 72, 0.28);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  font-size: 0.9rem;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.72; }
}

@media (max-width: 860px) {
  .bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 12px;
    row-gap: 8px;
  }
  .brand-row { display: contents; }
  .desk-brand { grid-column: 1; grid-row: 1; }
  .pills { grid-column: 1 / -1; grid-row: 2; }
  .head-actions {
    grid-column: 1 / -1;
    grid-row: 3;
    width: auto;
    justify-content: space-between;
  }
}

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .book, .rail { display: contents; }
  .engine { order: 1; }
  .tabbar { order: 2; }
  .table-sheet { order: 3; }
  .rail > .panel:not(.engine) { order: 4; }
  .book-note { text-align: left; }
  .rail { position: static; max-height: none; overflow: visible; }
}

@media (max-width: 640px) {
  .fields, .signal-row { grid-template-columns: 1fr; }
  #events li { grid-template-columns: 1fr; gap: 2px; }
  .tabbar { align-items: flex-start; }
}

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