:root {
  --bg: #0b0e11;
  --bg-2: #12161c;
  --panel: #1e2329;
  --panel-2: #2b3139;
  --line: #2b3139;
  --text: #eaecef;
  --muted: #848e9c;
  --yellow: #f7a600;
  --green: #0ecb81;
  --red: #f6465d;
  --blue: #3d7eff;
  --scroll: #3a424c;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll) var(--bg);
}
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "IBM Plex Sans", "Segoe UI", sans-serif;
  font-size: 13px;
}

button, input, select { font: inherit; color: inherit; color-scheme: dark; }
a { color: var(--yellow); text-decoration: none; }
.hidden { display: none !important; }

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  background: radial-gradient(800px 400px at 50% 0%, rgba(247,166,0,.12), transparent 50%), var(--bg);
}
.login-card {
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px 24px;
}
.brand-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.logo {
  width: 28px; height: 28px; border-radius: 6px;
  background: var(--yellow); color: #111; font-weight: 800;
  display: grid; place-items: center;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { color: var(--muted); margin: 8px 0 20px; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { color: var(--muted); }
.field input, .field select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 12px;
}
.field input:focus, .field select:focus { outline: 1px solid var(--yellow); }
.error { color: var(--red); min-height: 18px; }
.btn {
  border: 0; border-radius: 4px; padding: 10px 14px; cursor: pointer;
  background: var(--panel-2); color: var(--text);
}
.btn.yellow { background: var(--yellow); color: #111; font-weight: 700; }
.btn.green { background: var(--green); color: #111; font-weight: 700; }
.btn.red { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }

.shell { display: none; height: 100%; grid-template-rows: auto 36px 1fr 280px; }
.shell.visible { display: grid; }

.topbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px;
  padding: 8px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.topbar .brand-row { margin-bottom: 0; flex-shrink: 0; }
.pair-head { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.balance-chip {
  display: flex; align-items: baseline; gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  color: inherit;
  flex-shrink: 0;
}
.balance-chip:hover { border-color: var(--yellow); }
.balance-chip span { color: var(--muted); font-size: 11px; }
.balance-chip b { font-size: 15px; }
.balance-chip em { font-style: normal; font-size: 12px; font-weight: 600; }
.modal-card.balance-card {
  width: min(960px, 96vw);
  max-height: 92vh;
  overflow: auto;
}
.balance-card .table-wrap { max-height: 52vh; }
.pair-head b { font-size: 20px; }
.chg.up, .pos { color: var(--green); }
.chg.down, .neg { color: var(--red); }
.stats {
  display: flex; gap: 16px; color: var(--muted);
  flex: 1 0 100%;
  order: 5;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}
.stats b { color: var(--text); font-weight: 600; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.top-right .btn { padding: 6px 10px; }
.pill {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--muted);
}
.pill.ok { color: var(--green); border-color: rgba(14,203,129,.35); }
.pill.warn { color: var(--yellow); border-color: rgba(247,166,0,.4); }
.icon-status {
  width: 28px; height: 28px; padding: 0;
  display: grid; place-items: center;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  cursor: default;
  flex-shrink: 0;
}
.icon-status svg { width: 16px; height: 16px; display: block; }
.icon-status.ok { color: var(--green); border-color: rgba(14,203,129,.35); }
.icon-status.warn { color: var(--yellow); border-color: rgba(247,166,0,.4); }

.ticker {
  display: flex; gap: 0; overflow: auto;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.ticker button {
  background: transparent; border: 0; border-right: 1px solid var(--line);
  padding: 8px 14px; cursor: pointer; white-space: nowrap;
}
.ticker button.active { background: var(--panel); color: var(--yellow); }

.ws-tabs { display: none; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.ws-tabs .btn { padding: 6px 10px; }
.ws-tabs .btn.active { color: var(--yellow); }

.workspace {
  display: grid;
  grid-template-columns: 1fr 300px 360px;
  min-height: 0;
}
.panel {
  background: var(--bg);
  border-right: 1px solid var(--line);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.panel:last-child { border-right: 0; }
.panel-h {
  height: 36px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; border-bottom: 1px solid var(--line); color: var(--muted);
  gap: 8px;
}
.panel-h-actions { display: flex; gap: 4px; flex-shrink: 0; }
.panel-h-actions .btn { padding: 4px 8px; }
.tf { display: flex; gap: 4px; }
.tf button { padding: 4px 8px; }
.tf button.active { color: var(--yellow); }

#chart { width: 100%; height: calc(100% - 36px); display: block; }

.book { display: grid; grid-template-rows: 36px 1fr 28px 1fr; height: 100%; min-height: 0; }
.book-row { display: grid; grid-template-columns: 1fr 1fr 1fr; padding: 2px 10px; font-variant-numeric: tabular-nums; }
.book-row .p { color: var(--red); }
.book-row.bid .p { color: var(--green); }
.mid { text-align: center; padding: 4px; font-size: 18px; font-weight: 700; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }

.tape { height: 100%; min-height: 0; display: grid; grid-template-rows: 36px minmax(0, 1fr) minmax(220px, 1fr); }
.notes { overflow: auto; min-height: 0; padding: 8px; display: grid; align-content: start; gap: 4px; }
.note-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px;
  cursor: pointer;
  color: var(--text);
}
.note-row:hover { border-color: var(--yellow); }
.note-row .note-at { color: var(--muted); font-size: 11px; white-space: nowrap; }
.note-row .note-pair { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-row .note-verdict { color: var(--yellow); font-size: 11px; white-space: nowrap; }
.note-row .note-verdict.ok { color: var(--green); }
.note-row .note-verdict.bad { color: var(--red); }
.agent-chat {
  border-top: 1px solid var(--line);
  min-height: 0;
  display: grid;
  grid-template-rows: 36px minmax(80px, 1fr) 48px;
}
.chat-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  font-size: 12px;
  color: var(--muted);
}
.chat-messages { overflow: auto; padding: 8px 10px; display: grid; align-content: start; gap: 8px; }
.chat-message { max-width: 92%; padding: 8px 10px; border-radius: 8px; font-size: 12px; line-height: 1.45; white-space: pre-wrap; }
.chat-message.user { justify-self: end; background: #27364a; }
.chat-message.agent { background: #1d242d; border: 1px solid var(--line); }
.chat-message.system { background: #29231a; color: #f0b90b; font-size: 11px; }
.chat-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--line); }
.chat-form input { min-width: 0; background: #11161d; border: 1px solid var(--line); color: #f1f1f1; border-radius: 4px; padding: 0 8px; }
.note {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;
}
.note h3 { margin: 0 0 6px; font-size: 13px; }
.note p { margin: 0; color: #cfd3d8; line-height: 1.5; white-space: pre-wrap; }
.checks { margin-top: 8px; display: grid; gap: 4px; }
.check { color: var(--muted); }
.check.ok { color: var(--green); }

.bottom {
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-rows: 36px 1fr;
  background: var(--bg-2);
  min-height: 0;
}
.tabs { display: flex; align-items: center; gap: 4px; padding: 0 8px; overflow-x: auto; }
.tabs button.active, .tabs a.active { color: var(--yellow); }
.tabs .btn { white-space: nowrap; flex-shrink: 0; }
.table-wrap { overflow: auto; }
.demo-desk { overflow: auto; padding: 8px 10px; display: grid; gap: 8px; }
.demo-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.desk-filter { position: relative; }
.desk-menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 8;
  min-width: 160px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 0;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.desk-menu button {
  display: block; width: 100%; text-align: left;
  background: transparent; border: 0; color: var(--text);
  padding: 8px 12px; cursor: pointer;
}
.desk-menu button:hover { background: var(--panel-2); color: var(--yellow); }
.demo-cards { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); }
.demo-cards b { color: var(--text); }
#equity { width: 100%; height: 90px; display: block; background: #0b0e11; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: grid; place-items: center; z-index: 20;
}
.modal-card {
  width: min(760px, 94vw);
  max-height: 90vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}
.modal-card h2 { margin: 0 0 14px; }
.modal-card.analysis-card {
  width: min(1080px, 96vw);
  max-height: 92vh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}
.analysis-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.analysis-head h2 { margin: 0; }
.analysis-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}
.analysis-list { overflow: auto; border-right: 1px solid var(--line); padding-right: 8px; display: grid; align-content: start; gap: 4px; }
.analysis-list .note-row.active { border-color: var(--yellow); }
.analysis-detail { overflow: auto; min-height: 0; padding-left: 4px; }
.analysis-detail h3 { margin: 0 0 6px; font-size: 16px; }
.analysis-body { margin: 0 0 12px; color: #cfd3d8; line-height: 1.55; white-space: pre-wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.settings-sub { margin: 8px 0 4px; font-size: 15px; }
.voter-table { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 0 0 14px; }
.voter-table .field { margin-bottom: 0; }
@media (max-width: 720px) {
  .voter-table { grid-template-columns: 1fr; }
}
.help { color: var(--muted); margin: 0 0 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .shell { grid-template-rows: auto 36px 1fr 1fr auto; }
  .book, .tape { min-height: 280px; }
}

@media (max-width: 720px) {
  .shell { grid-template-rows: auto 36px auto minmax(240px, 1fr) minmax(220px, 1fr); }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .stats { display: none; }
  .top-right .btn.ghost { display: none; }
  .top-right #settings-btn { display: inline-flex; padding: 6px 8px; }
  .top-right #header-analysis { display: inline-flex; }
  .balance-chip span:first-child { display: none; }
  .analysis-layout { grid-template-columns: 1fr; }
  .analysis-list { border-right: 0; max-height: 28vh; padding-right: 0; }
  .pair-head b { font-size: 16px; }
  .ws-tabs { display: flex; }
  .workspace [data-ws-panel] { display: none; min-height: 0; }
  .workspace [data-ws-panel].ws-active { display: grid; }
  .workspace [data-ws-panel="chart"].ws-active { display: block; }
  .book, .tape { min-height: 0; height: 100%; }
  .modal-card {
    width: 100%;
    max-height: 100dvh;
    border-radius: 0;
    height: 100dvh;
  }
  .grid-2 { grid-template-columns: 1fr; }
  .demo-desk { overflow-x: auto; }
}
