:root {
  --sea: #0d1b26;
  --panel: #13283a;
  --panel-2: #183247;
  --rule: #21405a;
  --text: #dce7ee;
  --muted: #8099aa;
  --gain: #62d2a2;
  --loss: #ef7b6b;
  --brass: #e2b652;
  --focus: #9fd6ff;

  --wide: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.125rem;
  --step-2: 1.5rem;
  --step-4: 3rem;

  --gap: 16px;
  --radius-s: 4px;
  --radius-m: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; background: var(--sea); color: var(--text); }

body {
  font-family: var(--wide);
  font-size: var(--step-0);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--focus); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

h1, h2, h3 {
  font-stretch: 75%;
  font-weight: 600;
  line-height: 1.15;
  margin: 0;
}
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }

.muted { color: var(--muted); }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.brass { color: var(--brass); }
.num { font-stretch: 80%; font-variant-numeric: tabular-nums; white-space: nowrap; }
.addr { font-stretch: 85%; letter-spacing: 0.01em; }

/* ── Shell ─────────────────────────────────────────── */

.shell { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }

.rail {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 2px;
  padding: 20px 12px;
  border-right: 1px solid var(--rule);
}
.brand { font-stretch: 70%; font-weight: 700; font-size: var(--step-2); padding: 0 10px 18px; }
.brand span { color: var(--muted); font-weight: 500; }

.rail a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-radius: var(--radius-s);
  color: var(--muted);
}
.rail a:hover { color: var(--text); text-decoration: none; background: var(--panel); }
.rail a[aria-current='page'] { color: var(--text); background: var(--panel-2); }
.rail .badge { font-size: var(--step--1); color: var(--brass); }
.rail .who { margin-top: auto; padding: 10px; font-size: var(--step--1); color: var(--muted); }
.rail .who button { margin-top: 6px; }

main { padding: 24px clamp(16px, 3vw, 36px) 80px; max-width: 1400px; width: 100%; }

/* ── Helm (the one loud element) ───────────────────── */

.helm {
  display: grid;
  grid-template-columns: minmax(260px, 1.1fr) 2fr;
  gap: 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius-m);
  background: linear-gradient(180deg, var(--panel) 0%, var(--sea) 140%);
  margin-bottom: 28px;
  overflow: hidden;
}
.helm .state { padding: 20px 22px; border-right: 1px solid var(--rule); display: flex; flex-direction: column; gap: 12px; }
.helm .pnl { padding: 20px 22px; display: grid; grid-template-columns: auto 1fr; gap: 6px 28px; align-items: end; }

.engine-line { display: flex; align-items: center; gap: 12px; }
.lamp {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--muted); flex: none;
}
.lamp.on { background: var(--gain); box-shadow: 0 0 0 0 rgba(98, 210, 162, 0.55); animation: breathe 2.4s ease-out infinite; }
@keyframes breathe { 0% { box-shadow: 0 0 0 0 rgba(98, 210, 162, 0.5); } 100% { box-shadow: 0 0 0 12px rgba(98, 210, 162, 0); } }
.engine-word { font-size: var(--step-2); font-stretch: 70%; font-weight: 700; }
.mode { font-size: var(--step--1); color: var(--brass); border: 1px solid currentColor; border-radius: 999px; padding: 1px 8px; }

.big {
  font-size: var(--step-4);
  font-stretch: 62%;
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.01em;
}
.big small { font-size: var(--step-1); font-weight: 500; color: var(--muted); margin-left: 6px; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 22px; font-size: var(--step--1); color: var(--muted); }
.facts b { color: var(--text); font-weight: 600; font-stretch: 80%; }

.equity { width: 100%; height: 72px; display: block; }
.equity .line { fill: none; stroke-width: 2; }
.equity .zero { stroke: var(--rule); stroke-dasharray: 3 4; }

/* ── Layout blocks ─────────────────────────────────── */

.cols { display: grid; grid-template-columns: 3fr 2fr; gap: 28px; align-items: start; }
section { margin-bottom: 32px; }
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.head p { margin: 0; color: var(--muted); font-size: var(--step--1); }

/* ── Tables ────────────────────────────────────────── */

.table-wrap { overflow-x: auto; border-top: 1px solid var(--rule); }
table { width: 100%; border-collapse: collapse; font-size: var(--step--1); }
th {
  text-align: left; font-weight: 500; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--rule); white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid rgba(33, 64, 90, 0.6); vertical-align: middle; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: rgba(19, 40, 58, 0.7); }
td.r, th.r { text-align: right; }
.empty { padding: 22px 10px; color: var(--muted); border-bottom: 1px solid var(--rule); }

/* Position multiple bar: where price sits between stop loss and TP1 */
.mbar { position: relative; width: 90px; height: 6px; background: var(--rule); border-radius: 3px; }
.mbar i { position: absolute; top: -3px; width: 2px; height: 12px; background: var(--text); }
.mbar .fill { position: absolute; inset: 0 auto 0 0; border-radius: 3px; }

.flags { display: flex; flex-wrap: wrap; gap: 4px; }
.flag { font-size: 0.75rem; padding: 0 6px; border-radius: 3px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.flag.hard { color: var(--loss); }
.flag.pass { color: var(--gain); }
.flag.sig { color: var(--brass); }

/* ── Log ───────────────────────────────────────────── */

.log {
  height: 380px; overflow-y: auto;
  border-top: 1px solid var(--rule);
  font-size: var(--step--1);
  padding-top: 6px;
}
.log div { padding: 3px 0; display: grid; grid-template-columns: 62px 70px 1fr; gap: 8px; }
.log time { color: var(--muted); }
.log .scope { color: var(--muted); font-stretch: 80%; }
.log .warn .msg { color: var(--brass); }
.log .error .msg { color: var(--loss); }
.log .signal .msg, .log .paper .msg { color: var(--text); font-weight: 600; }

/* ── Controls ──────────────────────────────────────── */

button, .btn {
  font: inherit; font-size: var(--step--1); font-weight: 600;
  color: var(--text); background: var(--panel-2);
  border: 1px solid var(--rule); border-radius: var(--radius-s);
  padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--gain); color: var(--sea); border-color: var(--gain); }
button.danger { background: transparent; color: var(--loss); border-color: var(--loss); }
button.quiet { background: transparent; border-color: transparent; color: var(--muted); padding: 4px 6px; }

.jobs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.jobs .running { color: var(--brass); font-size: var(--step--1); }

.counts { display: flex; flex-wrap: wrap; gap: 6px 26px; margin: 10px 0 16px; font-size: var(--step--1); color: var(--muted); }
.counts b { display: block; font-size: var(--step-2); font-stretch: 70%; color: var(--text); font-weight: 600; }

textarea, input[type='text'], input[type='number'] {
  font: inherit; color: var(--text); background: var(--sea);
  border: 1px solid var(--rule); border-radius: var(--radius-s);
  padding: 8px 10px; width: 100%;
}
textarea { min-height: 96px; resize: vertical; font-size: var(--step--1); }
label { display: block; font-size: var(--step--1); color: var(--muted); margin-bottom: 4px; }
.form-row { display: flex; gap: 8px; margin-top: 8px; align-items: center; flex-wrap: wrap; }

.settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 28px; }
.settings fieldset { border: none; padding: 0; margin: 0; }
.settings legend { font-stretch: 75%; font-weight: 600; font-size: var(--step-1); padding: 0 0 8px; }
.field { display: grid; grid-template-columns: 1fr 96px; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid rgba(33, 64, 90, 0.6); }
.field label { margin: 0; color: var(--text); font-size: var(--step--1); }
.field label small { display: block; color: var(--muted); }
.field input[type='number'] { text-align: right; padding: 5px 8px; }
.field input[type='checkbox'] { justify-self: end; width: 18px; height: 18px; accent-color: var(--gain); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--rule); border-radius: var(--radius-m);
  padding: 10px 16px; font-size: var(--step--1); z-index: 50; max-width: 90vw;
}
.toast.err { border-color: var(--loss); }

/* Detail drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(5, 12, 18, 0.6); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(560px, 100%);
  background: var(--sea); border-left: 1px solid var(--rule); z-index: 41;
  overflow-y: auto; padding: 22px;
}
.drawer .kv { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; margin: 14px 0 20px; }
.drawer .kv div { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid rgba(33, 64, 90, 0.6); font-size: var(--step--1); }
.drawer .kv span { color: var(--muted); }

/* ── Login ─────────────────────────────────────────── */

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-box { width: min(420px, 100%); }
.login-box h1 { font-size: var(--step-4); font-stretch: 62%; font-weight: 700; line-height: 1; margin-bottom: 10px; }
.login-box p { color: var(--muted); margin: 0 0 22px; }
.wallet-list { display: grid; gap: 8px; }
.wallet-list button {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 12px 14px; font-size: var(--step-0); text-align: left;
}
.wallet-list img { width: 28px; height: 28px; border-radius: 6px; }
.login-err { color: var(--loss); margin-top: 14px; font-size: var(--step--1); min-height: 1.5em; }
.login-note { font-size: var(--step--1); color: var(--muted); margin-top: 22px; border-top: 1px solid var(--rule); padding-top: 14px; }

/* ── Mobile ────────────────────────────────────────── */

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 30;
    flex-direction: row; justify-content: space-around; gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    border-right: none; border-top: 1px solid var(--rule); background: var(--sea);
  }
  .rail .brand, .rail .who { display: none; }
  .rail a { flex-direction: column; gap: 0; padding: 6px 6px; font-size: 0.75rem; }
  main { padding: 16px 16px 96px; }
  .helm { grid-template-columns: 1fr; }
  .helm .state { border-right: none; border-bottom: 1px solid var(--rule); }
  .helm .pnl { grid-template-columns: 1fr; }
  .cols { grid-template-columns: 1fr; }
  .big { font-size: 2.5rem; }
  .log { height: 300px; }
  .hide-m { display: none; }
  .drawer .kv { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .lamp.on { animation: none; }
}
