:root {
  --bg: #07090d;
  --panel: #0e131b;
  --panel2: #141b27;
  --line: #243041;
  --text: #e7eef8;
  --muted: #8b9bb0;
  --dim: #5c6b80;
  --cyan: #3de0c5;
  --blue: #5aa7ff;
  --gold: #f0c14b;
  --red: #ff5d73;
  --purple: #b58cff;
  --green: #3ddc97;
  --font: "Syne", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; min-height: 100%;
  background:
    radial-gradient(900px 420px at 10% -10%, rgba(61,224,197,.08), transparent 55%),
    radial-gradient(700px 400px at 90% 0%, rgba(90,167,255,.07), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
}
.grain {
  pointer-events: none; position: fixed; inset: 0; z-index: 0; opacity: .04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.top, .nav, .wrap, .toast, .stale { position: relative; z-index: 1; }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.tiny { font-size: 11px; letter-spacing: .02em; }

.stale {
  background: linear-gradient(90deg, #5a3a08, #7a4e10); color: #ffe2a0;
  text-align: center; font-size: 12px; font-weight: 700; padding: 7px; letter-spacing: .04em;
}

.top {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line); background: rgba(14,19,27,.92);
  backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; gap: 12px; align-items: center; }
.mark {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; letter-spacing: .06em;
  background: linear-gradient(145deg, #163a36, #102033); color: var(--cyan);
  border: 1px solid #2a4f4a; box-shadow: 0 0 24px rgba(61,224,197,.12);
}
.title { font-weight: 700; font-size: 16px; }
.sub { color: var(--dim); font-size: 11px; margin-top: 2px; }
.top-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.tag {
  border: 1px solid var(--line); background: var(--panel2); border-radius: 999px;
  padding: 5px 10px; font-size: 11px; color: var(--muted);
}
.tag.us { color: var(--blue); border-color: #2a4f8a; }
.tag.rival { color: var(--purple); border-color: #5a3d8a; }
.tag.whale { color: var(--gold); border-color: #6a5418; }

.nav {
  display: flex; gap: 6px; overflow-x: auto; padding: 10px 14px;
  border-bottom: 1px solid var(--line); background: rgba(7,9,13,.9);
  position: sticky; top: 70px; z-index: 25;
}
.nav button {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 8px 12px; border-radius: 999px; white-space: nowrap; font-size: 13px; cursor: pointer;
  font-family: var(--font); font-weight: 600;
}
.nav button.active, .nav button:hover {
  color: var(--text); border-color: var(--line); background: var(--panel2);
}

.wrap { max-width: 1680px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.active { display: block; animation: in .18s ease; }
@keyframes in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.grid { display: grid; gap: 12px; }
.grid.kpi { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid.bots { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid.two { grid-template-columns: 1.25fr .75fr; }
.grid.tools { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
@media (max-width: 960px) {
  .grid.two { grid-template-columns: 1fr; }
  .top { top: 0; }
  .nav { top: 64px; }
}

.card {
  background: linear-gradient(180deg, rgba(20,27,39,.95), rgba(14,19,27,.98));
  border: 1px solid var(--line); border-radius: 14px; padding: 14px 14px 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.card h2, .card h3 { margin: 0 0 10px; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.kpi-val {
  font-family: var(--mono); font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.kpi-val.pos { color: var(--green); }
.kpi-val.neg { color: var(--red); }
.kpi-lab { color: var(--dim); font-size: 11px; margin-top: 4px; }

.btn {
  border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  border-radius: 9px; padding: 8px 12px; font-size: 12px; cursor: pointer; font-family: var(--font); font-weight: 600;
}
.btn:hover { border-color: #3a4f6a; }
.btn.primary { background: #123f39; border-color: #1f6b5f; color: var(--cyan); }
.btn.danger { background: #3a1520; border-color: #7a2a40; color: #ffb0bd; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 8px; font-size: 11px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
}
.pill.live { background: rgba(61,220,151,.12); color: var(--green); }
.pill.paused, .pill.degraded { background: rgba(240,193,75,.12); color: var(--gold); }
.pill.down, .pill.unresolved { background: rgba(255,93,115,.14); color: var(--red); }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; max-height: 70vh; }
table { width: 100%; border-collapse: collapse; font-size: 12px; font-family: var(--mono); }
th, td { padding: 8px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th {
  position: sticky; top: 0; background: #121924; color: var(--dim); font-weight: 600;
  text-transform: uppercase; font-size: 10px; letter-spacing: .04em; z-index: 1;
}
tr:hover td { background: rgba(255,255,255,.015); }
tr.us td:first-child { box-shadow: inset 3px 0 0 var(--blue); }
tr.rival td:first-child { box-shadow: inset 3px 0 0 var(--purple); }
tr.whale td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
.pos { color: var(--green); }
.neg { color: var(--red); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: end; }
.filters label, .field label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--dim); font-weight: 600; }
.filters input, .filters select, .field input, .field select, .field textarea {
  background: #0a0e15; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  color: var(--text); font-family: var(--mono); font-size: 12px; min-width: 0;
}
.field { margin-bottom: 10px; }

.logbox {
  background: #05070b; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; max-height: 420px; overflow: auto; font-family: var(--mono); font-size: 11px;
  line-height: 1.45; color: #c5d0e0; white-space: pre-wrap;
}

.chart-box { height: 220px; position: relative; }
.chart-box canvas { width: 100% !important; height: 220px !important; }

.tool {
  cursor: pointer; transition: border-color .15s, transform .15s;
  border-left: 3px solid #2a3a4a;
}
.tool:hover { border-color: #3a5a50; border-left-color: var(--cyan); transform: translateY(-1px); }
.tool h4 { margin: 0 0 6px; font-size: 14px; color: var(--text); text-transform: none; letter-spacing: 0; }
.tool p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.4; font-weight: 500; }
.tool .g { color: var(--dim); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px; }

.toast {
  position: fixed; right: 16px; bottom: 16px; max-width: min(440px, 92vw);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 13px; box-shadow: 0 16px 50px rgba(0,0,0,.45); z-index: 50;
}

/* login */
.login-body {
  min-height: 100vh; display: grid; place-items: center; position: relative;
}
.login-card {
  width: min(400px, 92vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px; box-shadow: 0 30px 80px rgba(0,0,0,.5); position: relative; z-index: 1;
}
.login-card label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: #0a0e15; margin-bottom: 14px; color: var(--text); font-family: var(--mono);
}
.err { color: var(--red); font-size: 13px; margin-top: 10px; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.tok {
  width: 14px; height: 14px; vertical-align: -2px; margin-right: 4px; border-radius: 50%;
  display: inline-block;
}

/* Round-trip cards — exact ops format */
.trip {
  font-family: var(--mono);
  background: #0a0f16;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.trip.us { border-left: 3px solid var(--blue); }
.trip.rival { border-left: 3px solid var(--purple); }
.trip-head {
  font-weight: 600; font-size: 13px; color: var(--text);
  margin-bottom: 10px; letter-spacing: .02em;
}
.trip-line {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 8px;
  padding: 3px 0;
  font-size: 12px;
  color: var(--muted);
}
.trip-line .kind { font-weight: 700; color: var(--text); }
.trip-line .kind.BUY { color: var(--green); }
.trip-line .kind.SELL { color: var(--gold); }
.trip-line .body { color: var(--text); }
.trip-line .via { color: var(--dim); }
.trip-rule {
  border: 0; border-top: 1px dashed #2a3a4a; margin: 10px 0;
}
.trip-net {
  font-size: 12.5px; font-weight: 600; color: var(--text);
}
.trip-net .pos { color: var(--green); }
.trip-net .neg { color: var(--red); }
.trip-net .tagq {
  display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 999px;
  font-size: 10px; border: 1px solid var(--line); color: var(--dim); font-weight: 600;
}
.trip-net .tagq.exact { color: var(--cyan); border-color: #1f6b5f; }
.trip-net .tagq.open { color: var(--gold); }
