:root {
  --bg: #0b0e0d;
  --panel: #111614;
  --raised: #171d1a;
  --line: #232b28;
  --text: #cfd8d3;
  --dim: #7f8c85;
  --accent: #7ee0a8;
  --warn: #f0b35a;
  --danger: #ef7d74;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.5 var(--mono); }

button, input { font: inherit; color: inherit; }
:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }

/* login */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
#login-form { width: min(340px, 100%); display: grid; gap: 14px; }
#login-form h1 { margin: 0 0 8px; font-size: 20px; font-weight: 600; color: var(--accent); }
#login-form label { display: grid; gap: 4px; color: var(--dim); font-size: 12px; }
#login-form input {
  background: var(--panel); border: 1px solid var(--line); border-radius: 3px;
  padding: 9px 10px; color: var(--text); font-size: 14px;
}
#login-form button {
  background: var(--accent); color: #06130c; border: 0; border-radius: 3px;
  padding: 9px 10px; font-weight: 600; cursor: pointer;
}
#login-form button:disabled { opacity: .55; cursor: default; }
#login-form .hint { margin: -6px 0 0; color: var(--dim); font-size: 12px; }
#login-error { margin: 0; min-height: 1.5em; color: var(--danger); font-size: 12px; }
.cursor { animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cursor { animation: none; } }

/* frame */
#app { height: 100dvh; display: flex; flex-direction: column; }

header {
  display: flex; align-items: center; gap: 8px 14px; flex: none; flex-wrap: wrap;
  padding: 7px 12px; border-bottom: 1px solid var(--line); background: var(--panel); font-size: 12px;
}
.brand { color: var(--accent); font-weight: 600; }
.status { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); }
.status.live { background: var(--accent); }
.status.down { background: var(--danger); }
#address { color: var(--warn); cursor: copy; }
#address.none { color: var(--dim); cursor: default; }
.balance { color: var(--dim); }
.balance b { color: var(--text); font-weight: 600; }
header nav {
  flex: 1 0 100%; display: flex; flex-wrap: wrap; gap: 2px;
  margin: 0; padding-top: 2px; border-top: 1px solid var(--line);
}
header nav button, .actions button {
  background: none; border: 0; border-radius: 3px; padding: 2px 7px; color: var(--dim); cursor: pointer;
}
header nav button:hover, .actions button:hover { color: var(--text); background: var(--raised); }

#workspace { position: relative; flex: 1; min-height: 0; }

#dash {
  height: 100%; display: grid; gap: 1px; background: var(--line);
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas: "trade positions feed" "sniper orders feed";
}
[data-panel="trade"] { grid-area: trade; }
[data-panel="sniper"] { grid-area: sniper; }
[data-panel="positions"] { grid-area: positions; }
[data-panel="orders"] { grid-area: orders; }
#dash [data-panel="feed"], #dash [data-panel="eagle"], #dash [data-panel="trades"], #dash [data-panel="wolf"], #dash [data-panel="fish"] { grid-area: feed; }
#dash .panel.off { display: none; }

.panel { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.panel h2 {
  display: flex; align-items: center; flex: none; margin: 0; height: 30px; padding: 0 12px;
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--dim);
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.actions { margin-left: auto; display: flex; gap: 2px; font-weight: 400; letter-spacing: 0; text-transform: none; }

#token-form { flex: none; padding: 8px 12px 0; }
#token {
  width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 3px; padding: 6px 9px;
}
#token::placeholder { color: var(--dim); }

#feed { flex: 1; min-height: 0; overflow-y: auto; padding: 9px 12px; overflow-wrap: anywhere; }
#feed:empty::before { content: "Snipes, fills and alerts appear here."; color: var(--dim); }

/* a screen's text scrolls; its buttons stay in reach */
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; padding: 9px 12px 10px; overflow-wrap: anywhere; }
.screen > .body { flex: 1 1 auto; min-height: 4.5em; overflow-y: auto; }
.screen > .buttons { flex: none; }
/* the token card needs its text most, so its buttons pack together instead of one row each */
[data-panel="trade"] .buttons { display: flex; flex-wrap: wrap; gap: 4px; }
[data-panel="trade"] .buttons .row { display: contents; }

/* bot output */
.body { white-space: pre-wrap; }
.body pre { margin: 4px 0 0; font-size: 11px; color: var(--dim); white-space: pre-wrap; overflow-wrap: anywhere; }
.body b, .body strong { color: #eef4f0; font-weight: 600; }
.body a { color: var(--accent); }
.body code { color: var(--warn); cursor: copy; border-radius: 2px; }
.body code:hover { background: var(--raised); }
.body code.copied { color: var(--accent); }
.spoiler { background: var(--text); color: transparent; border-radius: 2px; cursor: pointer; user-select: none; }
.spoiler * { color: transparent !important; }
.spoiler.open { background: none; color: inherit; cursor: auto; user-select: text; }
.spoiler.open * { color: var(--warn) !important; }

.buttons { display: grid; gap: 4px; margin-top: 8px; }
.buttons .row { display: flex; flex-wrap: wrap; gap: 4px; }
.buttons button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 3px;
  padding: 2px 8px; cursor: pointer; font-size: 12px;
}
.buttons button:hover { border-color: var(--accent); color: var(--accent); }
.buttons button.pressed { border-color: var(--accent); color: var(--accent); opacity: .6; }

/* feed */
.msg { padding: 7px 0; border-top: 1px solid #161c19; }
.msg:first-child { border-top: 0; }
.msg time { display: block; color: var(--dim); font-size: 11px; }
.note { padding: 7px 0; border-top: 1px solid #161c19; color: var(--danger); }

/* a panel's question */
.ask { flex: none; padding: 9px 12px; border-top: 1px solid var(--warn); background: var(--raised); }
.ask .body { margin-bottom: 7px; }
.ask form { display: flex; gap: 6px; }
.ask input {
  flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 3px; padding: 5px 8px;
}
.ask button {
  background: none; border: 1px solid var(--line); border-radius: 3px; padding: 2px 9px; cursor: pointer;
}
.ask button[type="submit"] { background: var(--accent); border-color: var(--accent); color: #06130c; font-weight: 600; }

/* a new authenticator, shown only in the browser that created it */
#login-setup { flex: none; padding: 9px 12px; border-top: 1px solid var(--line); }
#login-setup p { margin: 0 0 8px; }
#login-qr {
  background: #fff; color: #111; line-height: 1; font-size: 8px; padding: 10px; margin: 0 0 8px;
  max-height: 46vh; overflow: auto; font-family: ui-monospace, monospace; white-space: pre;
}
#login-key { color: var(--warn); cursor: copy; }
#login-key.copied { color: var(--accent); }
#login-confirm { display: flex; gap: 6px; }
#login-confirm input {
  flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 3px; padding: 5px 8px;
}
#login-confirm button {
  background: none; border: 1px solid var(--line); border-radius: 3px; padding: 2px 9px; cursor: pointer;
}
#login-confirm button[type="submit"] { background: var(--accent); border-color: var(--accent); color: #06130c; font-weight: 600; }
#login-setup-error { color: var(--danger); }

/* drawer */
#drawer {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 10; width: min(440px, 100%);
  border-left: 1px solid var(--line); box-shadow: -12px 0 28px #0008;
}

/* right column tabs */
.panel h2.side-tabs { gap: 2px; padding: 0 6px; }
.side-tabs button {
  height: 100%; padding: 0 8px; background: none; border: 0; border-bottom: 2px solid transparent; cursor: pointer;
  font: inherit; letter-spacing: inherit; text-transform: inherit; color: var(--dim);
}
.side-tabs button:hover { color: var(--text); }
.side-tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.side-tabs button.unread::after { content: " •"; color: var(--warn); }

/* Eagle */
[data-panel="eagle"] .screen { flex: 0 1 auto; max-height: 62%; }
[data-panel="eagle"] h3 {
  display: flex; align-items: center; flex: none; margin: 0; padding: 4px 12px;
  border-block: 1px solid var(--line); background: var(--panel);
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--dim);
}
[data-panel="eagle"] h3 label {
  margin-left: auto; display: flex; align-items: center; gap: 5px; cursor: pointer;
  font-weight: 400; letter-spacing: 0; text-transform: none;
}
#eagle-log { flex: 1; min-height: 90px; overflow-y: auto; padding: 6px 12px; font-size: 12px; overflow-wrap: anywhere; }
#eagle-log:empty::before { content: "Nothing logged yet."; color: var(--dim); }
#eagle-log .line { padding: 1px 0; }
#eagle-log time { color: var(--dim); }
#eagle-log .good { color: var(--accent); }
#eagle-log .bad { color: var(--danger); }
#eagle-log .set { color: var(--warn); }
#eagle-log.trades .info { display: none; }

/* Trades */
.trades-body { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px; }
#kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.kpi { padding: 8px 10px; background: var(--raised); border: 1px solid var(--line); border-radius: 3px; }
.kpi-label, .kpi-note { color: var(--dim); font-size: 11px; }
.kpi-value { color: var(--text); font-size: 17px; font-weight: 600; white-space: nowrap; }
#pnl-figure { position: relative; margin: 0 0 12px; }
#pnl-figure figcaption { margin-bottom: 4px; color: var(--dim); font-size: 11px; }
#pnl-chart svg { display: block; touch-action: none; }
#pnl-chart .grid { stroke: var(--line); stroke-width: 1; }
#pnl-chart .zero { stroke: var(--dim); stroke-width: 1; }
#pnl-chart .hair { stroke: var(--dim); stroke-width: 1; }
#pnl-chart .pnl { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
#pnl-chart .pnl-end { fill: var(--accent); stroke: var(--panel); stroke-width: 2; }
#pnl-chart text { fill: var(--dim); font-size: 10px; }
#pnl-chart .end-label { fill: var(--text); font-size: 11px; font-weight: 600; }
#pnl-tip {
  position: absolute; top: 18px; padding: 3px 7px; background: var(--raised); border: 1px solid var(--line);
  border-radius: 3px; font-size: 11px; white-space: nowrap; pointer-events: none;
}
#trades-empty { padding: 18px 0; color: var(--dim); }
#trades-table { width: 100%; border-collapse: collapse; font-size: 12px; }
#trades-table th {
  position: sticky; top: -10px; padding: 3px 5px; background: var(--panel); border-bottom: 1px solid var(--line);
  color: var(--dim); font-size: 11px; font-weight: 400; text-align: left;
}
#trades-table td { padding: 3px 5px; border-bottom: 1px solid #161c19; white-space: nowrap; }
#trades-table .num { text-align: right; font-variant-numeric: tabular-nums; }
#trades-table .when { color: var(--dim); }
#trades-table .sym { max-width: 84px; overflow: hidden; text-overflow: ellipsis; }
#trades-table .state.stuck::before { content: "! "; }
#trades-table .state.open::before { content: "… "; }

#tabs { display: none; }

@media (max-width: 1000px) and (min-width: 701px) {
  #dash {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: repeat(3, minmax(0, 1fr));
    grid-template-areas: "trade feed" "sniper feed" "positions orders";
  }
}

@media (max-width: 700px) {
  header { gap: 8px 10px; }
  #dash { display: block; }
  #dash .panel, #dash .panel.off { display: none; height: 100%; }
  #dash .panel.current { display: flex; }
  .panel h2.side-tabs { display: none; }
  #tabs { display: flex; flex: none; overflow-x: auto; border-top: 1px solid var(--line); background: var(--panel); }
  #tabs button { flex: 1 0 auto; padding: 11px 10px; background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 12px; }
  #tabs button.current { color: var(--accent); }
  #tabs button.unread::after { content: " •"; color: var(--warn); }
}
