/* Arb Bot - operator console.
   Dark only and deliberately dense: this is read at a glance next to a
   terminal, not browsed. */

:root {
  --bg: #0b0e13;
  --panel: #12161e;
  --panel-2: #161b25;
  --line: #232a36;
  --line-soft: #1b212c;
  --text: #dbe2ec;
  --muted: #7d8798;
  --dim: #5a6373;

  --green: #3fd68a;
  --red: #ff6b6b;
  --amber: #f5c451;
  --blue: #5aa9ff;
  --magenta: #c78bff;
  --cyan: #4fd6d2;

  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r: 8px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- shell ---------- */

.app {
  display: grid;
  grid-template-columns: 208px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "brand header" "nav main";
  height: 100vh;
}

.brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: 56px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand b { font-size: 13px; letter-spacing: .02em; }
.brand small { display: block; color: var(--dim); font: 11px/1.2 var(--mono); }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--dim); flex: none;
  box-shadow: 0 0 0 3px rgba(255,255,255,.04);
}
.dot.live { background: var(--green); }
.dot.dry { background: var(--amber); }
.dot.down { background: var(--red); }

header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 18px;
  height: 56px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.hstat { flex: none; }
.hstat span { display: block; color: var(--dim); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.hstat b { font: 500 14px/1.3 var(--mono); }

header .spacer { flex: 1 1 auto; }

nav {
  grid-area: nav;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 10px 0;
  overflow-y: auto;
}

nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  color: var(--muted);
  font-size: 13px;
  border-left: 2px solid transparent;
}
nav a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
nav a.on { color: var(--text); background: var(--panel-2); border-left-color: var(--blue); }
nav a .count { font: 11px var(--mono); color: var(--dim); }

main { grid-area: main; overflow-y: auto; padding: 18px; }

.view { display: none; }
.view.on { display: block; }

/* ---------- panels ---------- */

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 14px;
}

.panel > h2 {
  margin: 0;
  padding: 10px 14px;
  font: 600 11px/1.4 var(--sans);
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 10px;
}
.panel > h2 .note { margin-left: auto; font: 400 11px var(--mono); color: var(--dim); text-transform: none; letter-spacing: 0; }
.panel .body { padding: 12px 14px; }

.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 4px 14px; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; font: 13px var(--mono); word-break: break-all; }

.tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.tile {
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 10px 12px;
}
.tile span { display: block; color: var(--dim); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.tile b { font: 500 18px/1.4 var(--mono); }
.tile em { font-style: normal; color: var(--muted); font: 11px var(--mono); }

/* ---------- tables ---------- */

.scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font: 12px var(--mono); }
th {
  position: sticky; top: 0;
  text-align: right;
  padding: 7px 10px;
  color: var(--dim);
  font: 500 10px/1.4 var(--sans);
  letter-spacing: .07em;
  text-transform: uppercase;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th:first-child, td:first-child { text-align: left; }
th.l, td.l { text-align: left; }
td {
  padding: 6px 10px;
  text-align: right;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
tbody tr:hover { background: var(--panel-2); }
tbody tr.buy td { background: rgba(63, 214, 138, .07); }
tbody tr.mine td { background: rgba(90, 169, 255, .07); }
td.wrap { white-space: normal; word-break: break-word; color: var(--muted); }

.pos { color: var(--green); }
.neg { color: var(--red); }
.mut { color: var(--muted); }
.dimtext { color: var(--dim); }

.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font: 500 10px/1.6 var(--sans);
  letter-spacing: .05em;
  text-transform: uppercase;
  border: 1px solid transparent;
}
.tag.buy { color: var(--green); border-color: rgba(63,214,138,.4); background: rgba(63,214,138,.1); }
.tag.pass { color: var(--dim); border-color: var(--line); }
.tag.warn { color: var(--amber); border-color: rgba(245,196,81,.4); background: rgba(245,196,81,.1); }
.tag.info { color: var(--blue); border-color: rgba(90,169,255,.4); background: rgba(90,169,255,.1); }
.tag.bad { color: var(--red); border-color: rgba(255,107,107,.4); background: rgba(255,107,107,.1); }

/* ---------- log ---------- */

.logwrap {
  background: #080a0e;
  font: 12px/1.55 var(--mono);
  padding: 8px 0;
  overflow-y: auto;
  max-height: 100%;
}
.logline {
  display: grid;
  grid-template-columns: 92px 52px 1fr;
  gap: 10px;
  padding: 1px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
.logline:hover { background: #0e1218; }
.logline .t { color: #46505f; }
.logline .lv { text-align: right; font-size: 10px; letter-spacing: .06em; padding-top: 2px; }
.lv-info { color: var(--blue); }
.lv-ok   { color: var(--green); }
.lv-warn { color: var(--amber); }
.lv-err  { color: var(--red); }
.lv-hit  { color: var(--magenta); }
.lv-book { color: var(--cyan); }
.lv-skip { color: var(--dim); }
.logline.lvl-err .m { color: #ffb3b3; }
.logline.lvl-hit .m { color: #e2c8ff; }
.logline.lvl-skip .m { color: var(--dim); }

.logbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- controls ---------- */

button, .btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 11px;
  font: 12px var(--sans);
  cursor: pointer;
}
button:hover { border-color: #38404f; }
button.on { border-color: var(--blue); color: var(--blue); }
button:disabled { opacity: .5; cursor: default; }

input[type="text"], input[type="search"], input[type="password"] {
  background: #0a0d12;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 9px;
  font: 12px var(--mono);
  min-width: 180px;
}
input:focus { outline: none; border-color: var(--blue); }

label.chk { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; }

.empty { padding: 26px 14px; text-align: center; color: var(--dim); font-size: 12px; }

.bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }

/* ---------- gate / auth ---------- */

.gate {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: rgba(11,14,19,.96);
  z-index: 20;
}
.gate form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 22px 24px;
  width: min(380px, 92vw);
}
.gate h1 { margin: 0 0 6px; font-size: 15px; }
.gate p { margin: 0 0 14px; color: var(--muted); font-size: 12px; }
.gate input { width: 100%; margin-bottom: 10px; }
.gate button { width: 100%; }
.gate-error {
  margin: 10px 0 0;
  color: var(--red);
  font-size: 12px;
}
#signout { flex: none; }

.hidden { display: none !important; }

/* The log view fills what is left of the window rather than growing the page. */
#view-logs .panel { display: flex; flex-direction: column; height: calc(100vh - 56px - 36px - 52px); }
#view-logs .logwrap { flex: 1 1 auto; }

/* ---------- collections ---------- */

/* One row per collection, stats on the row itself. Opening a row is what
   reveals its listings - stacking every book vertically made the page a scroll
   past forty rows of one collection to reach the next. */
.colls { display: flex; flex-direction: column; gap: 8px; }

details.coll {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
details.coll > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  cursor: pointer;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
}
details.coll > summary::-webkit-details-marker { display: none; }
details.coll > summary:hover { background: var(--panel-2); }
details.coll[open] > summary { border-bottom: 1px solid var(--line); }

.cchev {
  flex: none;
  width: 0; height: 0;
  border-left: 5px solid var(--dim);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform .15s ease;
}
details.coll[open] > summary .cchev { transform: rotate(90deg); }

.cname { font: 600 13px/1.3 var(--sans); flex: none; }
.cstats { display: flex; gap: 20px; margin-left: auto; flex: none; }
.cstats i { font-style: normal; text-align: right; }
.cstats i span { display: block; color: var(--dim); font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
.cstats i b { font: 500 13px/1.35 var(--mono); }
.cwhen { flex: none; min-width: 56px; text-align: right; color: var(--dim); font: 11px var(--mono); }
.cmeta { padding: 9px 14px 0; }
.hint { margin: 0; color: var(--muted); font-size: 12px; }

/* ---------- responsive ---------- */

@media (max-width: 980px) {
  .cstats { gap: 14px; }
  .cstats i b { font-size: 12px; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "brand" "header" "nav" "main"; height: auto; }
  .brand { border-right: none; }
  nav { display: flex; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); padding: 0; }
  nav a { border-left: none; border-bottom: 2px solid transparent; white-space: nowrap; }
  nav a.on { border-left-color: transparent; border-bottom-color: var(--blue); }
  #view-logs .panel { height: 70vh; }

  /* Ten stats in one scrolling strip means the ones off-screen are never seen.
     A wrapping grid shows all of them without a horizontal gesture. */
  header {
    height: auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
    gap: 10px 14px;
    padding: 10px 14px;
    overflow-x: visible;
  }
  header .spacer { display: none; }
  #signout { grid-column: 1 / -1; justify-self: start; }

  .grid.wide { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
  .tile b { font-size: 16px; }

  /* The summary row stops being a single line: name on top, stats beneath. */
  details.coll > summary { flex-wrap: wrap; gap: 8px; }
  .cstats { margin-left: 0; width: 100%; gap: 0; display: grid; grid-template-columns: repeat(5, 1fr); }
  .cstats i { text-align: left; }
  .cwhen { display: none; }
}

@media (max-width: 640px) {
  /* Tables become one card per row. A nine-column book is unreadable on a
     phone either squeezed or side-scrolled, so each cell becomes a labelled
     line instead - which is why table() stamps data-label on every cell. */
  .scroll { overflow-x: visible; }
  .scroll table, .scroll tbody, .scroll tr, .scroll td { display: block; width: 100%; }
  .scroll thead { display: none; }
  .scroll tr {
    margin: 8px 0;
    padding: 4px 11px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: var(--r);
  }
  .scroll tbody tr:hover { background: var(--panel-2); }
  .scroll td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    text-align: right;
    white-space: normal;
    overflow-wrap: anywhere;
    padding: 5px 0;
    border: 0;
    border-bottom: 1px solid var(--line-soft);
  }
  .scroll tr td:last-child { border-bottom: 0; }
  .scroll td::before {
    content: attr(data-label);
    flex: none;
    color: var(--dim);
    font: 500 10px/1.7 var(--sans);
    letter-spacing: .07em;
    text-transform: uppercase;
    text-align: left;
  }
  /* The verdict tag and the empty-state row have no column name to show. */
  .scroll td.nolabel::before, .scroll td.empty::before { content: none; }
  .scroll td.nolabel { justify-content: flex-start; }
  .scroll td.empty { justify-content: center; text-align: center; }

  .cstats { grid-template-columns: repeat(3, 1fr); gap: 8px 0; }
  .panel > h2 { flex-wrap: wrap; gap: 6px; }
  .panel > h2 .note { margin-left: 0; width: 100%; }
  .bar { flex-wrap: wrap; }
}

/* ---------- inline warnings ---------- */

/* Used where two sources disagree - a held NFT with no tracked position, say.
   Loud enough to notice, quiet enough to live above a table. */
.warnbar {
  margin: 0;
  padding: 9px 14px;
  background: rgba(245, 196, 81, .08);
  border-bottom: 1px solid var(--line);
  color: var(--amber);
  font-size: 12px;
  line-height: 1.55;
}
.warnbar code {
  padding: 1px 5px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  font: 11px var(--mono);
}
