/* ==========================================================================
   Trading app — shares the marketing site's design language (Inter, near-
   monochrome, hairline borders, #0079ff accent) but with an app shell:
   fixed sidebar, dense data tables, tabular figures.
   ========================================================================== */

:root {
  --ink: #141414;
  --bg: #ffffff;
  --bg-alt: #f7f4f3;
  --bg-dark: #141414;
  --surface: #ffffff;
  --muted: #6b6b6b;
  --muted-2: #a3a3a3;
  --line: rgba(20, 20, 20, 0.10);
  --line-strong: rgba(20, 20, 20, 0.16);
  --red: #9d0615;
  --red-deep: #7d0410;
  --accent: #9d0615;
  --accent-hover: #7d0410;
  --accent-tint: rgba(157, 6, 21, 0.09);
  --up: #147a2e;
  --up-tint: rgba(20, 122, 46, 0.1);
  --down: #c0182a;
  --down-tint: rgba(192, 24, 42, 0.1);
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 20, 0.05);
  --shadow: 0 6px 28px -10px rgba(20, 20, 20, 0.14);
  --shadow-lg: 0 30px 70px -30px rgba(20, 20, 20, 0.3);
  --sans: "Jost", "Futura PT", "Avenir Next", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg-alt);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-weight: 600;
  letter-spacing: -0.035em;
  margin: 0;
}

a { color: inherit; text-decoration: none; }

button, input, select { font: inherit; color: inherit; }

.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

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

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
}
.brand svg { width: 34px; height: 15px; color: var(--ink); }
.cc-badge {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 13.5px;
  letter-spacing: 0.04em;
  box-shadow: var(--shadow-sm);
}
.brand-text {
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 12.5px;
  line-height: 1.2;
}
.brand-text em {
  font-style: normal;
  color: var(--muted);
  display: block;
  font-size: 9.5px;
  letter-spacing: 0.15em;
  margin-top: 3px;
}

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 500;
  transition: background 0.14s, color 0.14s;
}
.side-nav a svg { width: 17px; height: 17px; flex: 0 0 17px; }
.side-nav a:hover { background: var(--bg-alt); color: var(--ink); }
.side-nav a.is-active { background: var(--red); color: #fff; }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }

.team-chip {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  background: var(--bg);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: border-color 0.14s;
}
.team-chip:hover { border-color: var(--line-strong); }
.team-chip .tc-label {
  display: block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted-2);
  font-weight: 600;
}
.team-chip .tc-name {
  display: block;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 58px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 26px;
  position: sticky;
  top: 0;
  z-index: 30;
}

/* Scrolling ticker tape: the strip is a fixed viewport; the track holds two
   identical runs of quotes and slides left by exactly one run (-50%) for a
   seamless loop. Trailing space lives on each .tick (padding-right) so the two
   halves are the same width and the wrap is invisible. */
.ticker-strip {
  overflow: hidden;
  flex: 1;
  min-width: 0;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent);
}
.ticker-track {
  display: inline-flex;
  white-space: nowrap;
  will-change: transform;
  animation: tape 80s linear infinite;
}
.ticker-strip:hover .ticker-track { animation-play-state: paused; }
@keyframes tape { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.tick { display: inline-flex; align-items: baseline; gap: 7px; white-space: nowrap; font-size: 12.5px; padding-right: 34px; }
.tick b { font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; }
.tick .val { font-family: var(--mono); font-size: 11.5px; }

.topbar-actions { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--muted);
  padding: 6px 2px;
}
.lang-toggle .sep { opacity: 0.4; }
.lang-toggle [data-lang] { transition: color 0.15s; }
.lang-toggle [data-lang].is-active { color: var(--red); font-weight: 600; }
#leavePortal { font-size: 12px; }

.view { padding: 26px; max-width: 1240px; width: 100%; }

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.view-head h1 { font-size: 26px; }
.view-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, opacity 0.14s, transform 0.14s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-alt); }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-deep); border-color: var(--red-deep); }
.btn-buy { background: var(--up); border-color: var(--up); color: #fff; }
.btn-buy:hover { background: #0f6023; }
.btn-sell { background: var(--down); border-color: var(--down); color: #fff; }
.btn-sell:hover { background: #b02a14; }
.btn-sm { padding: 6px 13px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  /* Grid and flex children default to min-width:auto, which lets a wide table
     push the whole page sideways instead of scrolling inside its own box.
     Every container in the chain down to .table-scroll must opt out. */
  min-width: 0;
}

/* Wide content scrolls inside itself; the page body never scrolls sideways. */
.table-scroll { overflow-x: auto; min-width: 0; }
.card-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-head h2 { font-size: 15px; }
.card-body { padding: 20px; }

.grid-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat .k {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
}
.stat .v {
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.04em;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.stat .s { font-size: 12.5px; margin-top: 3px; font-variant-numeric: tabular-nums; }

.cols {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.cols > * { min-width: 0; }

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

table.dt { width: 100%; border-collapse: collapse; }
table.dt th {
  text-align: right;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  font-weight: 600;
  padding: 4px 26px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.dt th:first-child, table.dt td:first-child { text-align: left; }
/* Opt-in left alignment for label columns that aren't first (e.g. team name
   sitting after a rank badge). */
table.dt th.l, table.dt td.l { text-align: left; }
table.dt td {
  padding: 13px 26px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
table.dt tbody tr:last-child td { border-bottom: none; }
table.dt tbody tr.clickable { cursor: pointer; }
table.dt tbody tr.clickable:hover { background: var(--bg-alt); }

.sym { display: flex; flex-direction: column; gap: 1px; }
.sym b { font-weight: 600; letter-spacing: -0.02em; }
.sym span {
  font-size: 12px;
  color: var(--muted);
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--bg-alt);
  color: var(--muted);
}
.pill-buy { background: var(--up-tint); color: var(--up); }
.pill-sell { background: var(--down-tint); color: var(--down); }

.rank {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12.5px;
  background: var(--bg-alt);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.rank-1 { background: var(--red); color: #fff; }
.rank-2, .rank-3 { background: var(--line-strong); color: var(--ink); }

.you { background: var(--accent-tint) !important; }
.you .rank { box-shadow: 0 0 0 2px var(--accent); }

/* ----------------------------------------------------------- empty states */

.empty { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty h3 { font-size: 15px; color: var(--ink); margin-bottom: 5px; }
.empty p { margin: 0 0 16px; }

.skel {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--bg-alt) 25%, #eee 50%, var(--bg-alt) 75%);
  background-size: 200% 100%;
  animation: sk 1.3s linear infinite;
}
@keyframes sk { to { background-position: -200% 0; } }

/* ---------------------------------------------------------------- charts */

.chart-wrap { position: relative; height: 240px; }
.chart-wrap svg { width: 100%; height: 100%; display: block; overflow: visible; }
.range-tabs { display: flex; gap: 3px; }
.range-tabs button {
  border: none;
  background: none;
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}
.range-tabs button:hover { background: var(--bg-alt); }
.range-tabs button.is-active { background: var(--red); color: #fff; }

/* -------------------------------------------------------------- alloc bar */

.alloc { display: flex; height: 9px; border-radius: 999px; overflow: hidden; gap: 2px; }
.alloc i { display: block; height: 100%; background: var(--ink); border-radius: 2px; }
.alloc-legend { display: flex; flex-direction: column; gap: 9px; margin-top: 16px; }
.alloc-legend div { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.alloc-legend .sw { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 9px; }
.alloc-legend .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alloc-legend .pc { font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---------------------------------------------------------------- search */

.search-box { position: relative; }
.search-box input {
  width: 100%;
  padding: 11px 15px 11px 40px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--bg);
  outline: none;
  transition: border-color 0.14s, box-shadow 0.14s;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.search-box svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--muted-2);
  pointer-events: none;
}

.results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 40;
  max-height: 340px;
  overflow-y: auto;
  padding: 5px;
}
.results button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  border: none;
  background: none;
  padding: 9px 11px;
  border-radius: 9px;
  cursor: pointer;
  text-align: left;
}
.results button:hover { background: var(--bg-alt); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button {
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  color: var(--muted);
}
.tabs button.is-active { background: var(--red); border-color: var(--red); color: #fff; }

/* ---------------------------------------------------------------- dialog */

dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  box-shadow: var(--shadow-lg);
  max-width: 440px;
  width: calc(100vw - 32px);
  color: var(--ink);
}
dialog::backdrop { background: rgba(20, 20, 20, 0.32); backdrop-filter: blur(2px); }
.dlg-head {
  padding: 20px 22px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.dlg-head h2 { font-size: 18px; }
.dlg-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.dlg-body { padding: 18px 22px; }
.dlg-foot {
  padding: 0 22px 20px;
  display: flex;
  gap: 9px;
  justify-content: flex-end;
}
.x-btn {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
  border-radius: 8px;
  line-height: 0;
}
.x-btn:hover { background: var(--bg-alt); }
.x-btn svg { width: 18px; height: 18px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.field input, .field select {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--bg);
  outline: none;
}
.field input:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }

.seg { display: flex; background: var(--bg-alt); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1;
  border: none;
  background: none;
  padding: 9px;
  border-radius: 9px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}
.seg button[data-side="buy"].is-active { background: var(--up); color: #fff; }
.seg button[data-side="sell"].is-active { background: var(--down); color: #fff; }

.summary { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 13px; }
.summary div {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-variant-numeric: tabular-nums;
}
.summary div.total { font-weight: 600; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 9px; }

.err {
  background: var(--down-tint);
  color: var(--down);
  border-radius: 11px;
  padding: 10px 13px;
  font-size: 13px;
  margin-top: 12px;
}

.note {
  background: var(--accent-tint);
  border-radius: 11px;
  padding: 12px 15px;
  font-size: 13px;
  color: var(--red-deep);
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.note svg { width: 16px; height: 16px; flex: 0 0 16px; margin-top: 1px; }

.toast-wrap {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  z-index: 100;
}
.toast {
  background: var(--ink);
  color: #fff;
  padding: 12px 17px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  animation: pop 0.22s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

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

@media (max-width: 980px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
  .grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .shell { flex-direction: column; }

  /* The sidebar becomes a compact top bar: icon-only nav, no wordmark, and a
     square New-order button, so nothing has to scroll horizontally. */
  .sidebar {
    width: 100%;
    flex: none;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 40;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0; flex: 0 0 auto; }
  .brand-text { display: none; }

  .side-nav { flex-direction: row; gap: 2px; flex: 1; min-width: 0; }
  .side-nav a { padding: 8px 10px; }
  .side-nav a span { display: none; }

  .side-foot { margin: 0; flex-direction: row; align-items: center; gap: 8px; flex: 0 0 auto; }
  .side-foot .btn { padding: 8px 11px; }
  .side-foot .btn span { display: none; }
  .team-chip { width: auto; max-width: 116px; padding: 7px 10px; }
  .team-chip .tc-label { display: none; }
  .team-chip .tc-name { font-size: 13px; }

  .topbar { height: 46px; padding: 0 14px; gap: 10px; }
  .tick .val { font-size: 11px; }
  .topbar-actions { gap: 8px; }
  #marketState { display: none; }
  #leavePortal { padding: 7px 12px; }

  .view { padding: 14px; }
  .view-head h1 { font-size: 22px; }
  .stat { padding: 13px 14px; }
  .stat .v { font-size: 20px; }
  .chart-wrap { height: 190px; }
}
