/* FX Copier — trade copy terminal.
   Voice: phosphor terminal. Mono carries all data; amber = signal. */

:root {
  --ink: #111412;
  --panel: #191d1a;
  --panel-2: #1f241f;
  --line: #2b302b;
  --text: #eae7dc;
  --dim: #909789;
  --amber: #ffb000;
  --amber-soft: rgba(255, 176, 0, 0.13);
  --up: #46c287;
  --down: #e5484d;
  --warn: #d29922;
  --r: 2px;
  --mono: "SF Mono", SFMono-Regular, ui-monospace, "Cascadia Mono", "JetBrains Mono", Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
  background: var(--ink);
  color: var(--text);
  font: 13px/1.55 var(--mono);
  font-variant-numeric: tabular-nums;
}

button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

.hidden { display: none !important; }

::selection { background: var(--amber); color: var(--ink); }

/* ---------- terminal chrome ---------- */
.cursor { color: var(--amber); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.eyebrow {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--dim);
}

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  width: 100%;
  max-width: 23rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 2px solid var(--amber);
  border-radius: var(--r);
  padding: 2rem;
  animation: rise 0.45s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}
.login-card .wordmark { font-size: 1.3rem; letter-spacing: 0.04em; }
.login-card .wordmark b { color: var(--amber); font-weight: 400; }
.login-card .eyebrow { margin: 0.35rem 0 1.5rem; }
.login-error { color: var(--down); font-size: 0.8rem; margin-top: 0.8rem; min-height: 1.2rem; }

/* ---------- shell layout: rail + content ---------- */
.shell { display: flex; min-height: 100vh; }

.rail {
  width: 13.5rem;
  flex: none;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 1rem 0.75rem;
  gap: 1.25rem;
}
.rail .wordmark { font-size: 0.95rem; letter-spacing: 0.04em; padding: 0 0.5rem; }
.rail .wordmark b { color: var(--amber); font-weight: 400; }

#nav { display: flex; flex-direction: column; gap: 0.15rem; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: var(--r);
  color: var(--dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 0.5rem 0.65rem;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.nav-item:hover { color: var(--text); background: var(--panel-2); }
.nav-item.active { color: var(--amber); border-left-color: var(--amber); background: var(--amber-soft); }
.nav-item:focus-visible { outline: 2px solid var(--amber); outline-offset: -2px; }
.nav-count {
  margin-left: auto;
  font-size: 0.64rem;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 0.4rem;
  min-width: 1.3rem;
  text-align: center;
}
.nav-item.active .nav-count { color: var(--amber); border-color: rgba(255, 176, 0, 0.5); }

.rail-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem;
  border-top: 1px solid var(--line);
}
.rail-foot .meta { overflow: hidden; text-overflow: ellipsis; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.55rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  overflow: hidden;
}
/* ambient scanline sweeping the topbar's bottom edge */
.topbar::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 1px;
  width: 18%;
  background: linear-gradient(90deg, transparent, var(--amber), transparent);
  opacity: 0.55;
  animation: scan 7s linear infinite;
}
@keyframes scan {
  from { transform: translateX(-30vw); }
  to { transform: translateX(120vw); }
}
.view-title { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--text); }
.view-title::before { content: "▸ "; color: var(--amber); }
.meta { color: var(--dim); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.spacer { flex: 1; }
.clock { color: var(--text); font-size: 0.78rem; white-space: nowrap; }

main {
  padding: 1.25rem;
  max-width: 88rem;
  width: 100%;
  margin: 0 auto;
  display: grid;
  gap: 1.75rem;
  align-content: start;
}
section.off { display: none; }

/* staggered section entrance on view switch */
main.enter section:not(.off) {
  animation: rise 0.35s cubic-bezier(0.2, 0.7, 0.3, 1) both;
  animation-delay: calc(var(--i, 0) * 70ms);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(0.6rem); }
  to { opacity: 1; transform: none; }
}

section h2 {
  font-size: 0.68rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--dim);
  margin-bottom: 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
section h2::before { content: "▸"; color: var(--amber); }

/* ---------- buttons & focus ---------- */
.btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 0.28rem 0.7rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.btn:hover { border-color: var(--dim); background: var(--panel-2); }
.btn:focus-visible, input:focus-visible, select:focus-visible, .wire:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}
.btn-primary { background: var(--amber); border-color: var(--amber); color: var(--ink); }
.btn-primary:hover { background: #ffc233; border-color: #ffc233; }
.btn-danger { color: var(--down); }
.btn-danger:hover { border-color: var(--down); background: rgba(229, 72, 77, 0.08); }
.btn-sm { padding: 0.14rem 0.5rem; font-size: 0.68rem; }

/* ---------- routing board (signature) ---------- */
.flow-board {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 1.1rem 1.25rem;
  display: flex;
  justify-content: space-between;
  gap: 6rem;
  overflow: hidden;
  background-image: radial-gradient(rgba(144, 151, 137, 0.13) 1px, transparent 1px);
  background-size: 14px 14px;
}
.flow-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.flow-svg .wire { pointer-events: stroke; cursor: pointer; }
.flow-col {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-width: 0;
  z-index: 1;
}
.flow-col.slaves { align-items: flex-end; }
.node {
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 0.4rem 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  max-width: 17rem;
}
.node.master { border-left: 2px solid var(--amber); }
.node.slave { border-right: 2px solid var(--line); }
.node .n-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .n-sub { color: var(--dim); font-size: 0.68rem; text-transform: uppercase; }

.wire-base { stroke: var(--line); stroke-width: 1.5; fill: none; }
.wire-base.armed { stroke: rgba(255, 176, 0, 0.45); }
.wire-base.off { stroke-dasharray: 3 5; }
.wire-pulse {
  stroke: var(--amber);
  stroke-width: 1.5;
  fill: none;
  stroke-dasharray: 10 120;
  animation: pulse 2.2s linear infinite;
}
@keyframes pulse { to { stroke-dashoffset: -130; } }

/* ---------- status LEDs ---------- */
.led {
  width: 7px;
  height: 7px;
  border-radius: 1px;
  background: var(--line);
  flex: none;
}
.led.online {
  background: var(--up);
  box-shadow: 0 0 6px rgba(70, 194, 135, 0.7);
  animation: led-breathe 2.6s ease-in-out infinite;
}
.led.offline { background: var(--down); }
@keyframes led-breathe {
  0%, 100% { box-shadow: 0 0 4px rgba(70, 194, 135, 0.45); }
  50% { box-shadow: 0 0 9px rgba(70, 194, 135, 0.85); }
}

.badge {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.08rem 0.4rem;
  border-radius: var(--r);
  border: 1px solid var(--line);
  color: var(--dim);
}
.badge.master { color: var(--amber); border-color: rgba(255, 176, 0, 0.5); }
.badge.suspended { color: var(--down); border-color: var(--down); }

/* ---------- account cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr)); gap: 0.75rem; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 0.85rem 1rem;
  transition: transform 0.18s cubic-bezier(0.2, 0.7, 0.3, 1), border-color 0.18s, box-shadow 0.18s;
}
.card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 176, 0, 0.35);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.node { transition: border-color 0.15s, box-shadow 0.15s; }
.node:hover { border-color: var(--amber); box-shadow: 0 0 12px var(--amber-soft); }
.card-head { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 0.6rem; }
.card-head .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.08rem 1rem; font-size: 0.78rem; }
.kv dt { color: var(--dim); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; align-self: baseline; }
.kv dd { text-align: right; }
.card-actions { display: flex; gap: 0.4rem; margin-top: 0.75rem; flex-wrap: wrap; }
.token-row { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.6rem; }
.token-row code {
  font-size: 0.68rem;
  color: var(--dim);
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 0.18rem 0.45rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

/* ---------- tables ---------- */
.table-wrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
th, td { text-align: left; padding: 0.42rem 0.75rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th {
  color: var(--dim);
  font-weight: 400;
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
tbody tr:hover td { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: none; }
td.num { text-align: right; }
th.num { text-align: right; }
.side-buy { color: var(--up); }
.side-sell { color: var(--down); }
.empty { color: var(--dim); padding: 1.25rem; text-align: center; font-size: 0.8rem; font-family: var(--sans); }

.level-info { color: var(--dim); }
.level-warn { color: var(--warn); }
.level-error { color: var(--down); }
.profit-pos { color: var(--up); }
.profit-neg { color: var(--down); }

.toggle { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.72rem; cursor: pointer; text-transform: uppercase; }
.toggle input { accent-color: var(--amber); }

/* ---------- modal ---------- */
dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-top: 2px solid var(--amber);
  border-radius: var(--r);
  padding: 0;
  width: min(46rem, calc(100vw - 2rem));
  max-height: calc(100vh - 4rem);
}
dialog::backdrop { background: rgba(6, 8, 6, 0.72); animation: fade 0.18s ease-out; }
dialog[open] { animation: modal-in 0.2s cubic-bezier(0.2, 0.7, 0.3, 1); }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(0.75rem) scale(0.985); }
  to { opacity: 1; transform: none; }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { font-size: 0.85rem; font-weight: 400; letter-spacing: 0.04em; }
.modal-body { padding: 1rem 1.25rem; overflow-y: auto; max-height: calc(100vh - 12rem); }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--line);
}
fieldset {
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 0.75rem 1rem 0.9rem;
  margin-bottom: 1rem;
}
legend {
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--amber);
  padding: 0 0.4rem;
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: 0.65rem 1rem; }
.field { display: flex; flex-direction: column; gap: 0.22rem; }
.field label { font-size: 0.68rem; color: var(--dim); text-transform: uppercase; letter-spacing: 0.06em; }
.field input[type="text"], .field input[type="number"], .field input[type="password"], .field select {
  background: var(--ink);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 0.34rem 0.5rem;
  font-size: 0.8rem;
  width: 100%;
}
.field input::placeholder { color: var(--dim); }
.field-check { flex-direction: row; align-items: center; gap: 0.45rem; }
.field-check label { color: var(--text); font-size: 0.78rem; text-transform: none; letter-spacing: 0; }
.field-check input { accent-color: var(--amber); }
.hint { font-size: 0.66rem; color: var(--dim); font-family: var(--sans); letter-spacing: 0; text-transform: none; }

/* ---------- toasts ---------- */
#toasts {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
  max-width: 24rem;
}
.toast {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 2px solid var(--amber);
  border-radius: var(--r);
  padding: 0.55rem 0.9rem;
  font-size: 0.78rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.16s ease-out;
}
.toast.error { border-left-color: var(--down); }
.toast.success { border-left-color: var(--up); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(0.4rem); }
  to { opacity: 1; transform: none; }
}

/* ---------- onboarding ---------- */
.onboarding {
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: var(--r);
  padding: 1.5rem;
  grid-column: 1 / -1;
  font-family: var(--sans);
}
.onboarding h3 { font-family: var(--mono); font-size: 0.9rem; font-weight: 400; margin-bottom: 0.8rem; }
.onboarding h3 b { color: var(--amber); font-weight: 400; }
.onboarding ol { margin: 0 0 0.8rem 1.25rem; display: grid; gap: 0.4rem; font-size: 0.85rem; }
.onboarding code {
  font-family: var(--mono);
  font-size: 0.76rem;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 0.1rem 0.35rem;
}
.onboarding p { color: var(--dim); font-size: 0.8rem; }

/* ---------- motion & responsive ---------- */
@media (prefers-reduced-motion: reduce) {
  .wire-pulse { animation: none; stroke-dasharray: none; opacity: 0.55; }
  .cursor, .led.online, .topbar::after { animation: none; }
  .toast, .login-card, dialog[open], dialog::backdrop { animation: none; }
  main.enter section:not(.off) { animation: none; }
  .card, .card:hover { transform: none; transition: none; }
}

@media (max-width: 880px) {
  .shell { flex-direction: column; }
  .rail {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  #nav { flex-direction: row; overflow-x: auto; flex: 1; }
  .nav-item { width: auto; white-space: nowrap; border-left: 0; border-bottom: 2px solid transparent; }
  .nav-item.active { border-left: 0; border-bottom-color: var(--amber); }
  .rail-foot { margin: 0; border: 0; padding: 0; flex-direction: row; align-items: center; }
  .rail-foot .meta { display: none; }
}

@media (max-width: 720px) {
  main { padding: 0.75rem; gap: 1.25rem; }
  .cards { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 0.5rem; }
  .flow-board { gap: 2.5rem; }
  .node { max-width: 11rem; }
}
