/*
 * PROWL — dark, dense, terminal-adjacent.
 *
 * Rules held throughout: numbers are the interface, so every figure is tabular
 * and monospace; colour encodes direction only, never decoration; touch targets
 * stay >=44px and inputs stay at 16px, because iOS zooms below that and the user
 * cannot undo it.
 */

/*
 * Palette.
 *
 * Raised off near-black: the first cut used #0a0b0d with #23272e borders, which
 * read as a void on a phone in daylight and made every panel edge invisible.
 * Surfaces now step clearly (bg -> surface -> surface-2) and text contrast is
 * lifted, while staying a dark terminal rather than turning grey.
 */
:root {
  --bg: #16181d;
  --surface: #1e2128;
  --surface-2: #272b34;
  --line: #363b46;
  --line-soft: #2a2e37;
  --text: #f2f5f9;
  --muted: #a4aebc;
  --dim: #7b8493;

  --up: #3ddc84;
  --down: #ff6b6b;
  --warn: #ffb454;
  --accent: #3ddc84;

  --pad: 14px;
  --radius: 12px;

  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
  max-width: 720px;
  margin: 0 auto;
}

/* Every number in the app renders through this. */
.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) var(--pad) 10px;
  background: rgba(22, 24, 29, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: center; gap: 9px; margin-right: auto; }

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.mark {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(61, 220, 132, 0.7);
}

.band-readout {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  white-space: nowrap;
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
}

.icon-btn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.icon-btn[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }

/* ---------- status ---------- */

.statusline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px var(--pad);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--dim);
  border-bottom: 1px solid var(--line-soft);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dim);
  flex: none;
}

.dot.live { background: var(--up); animation: pulse 2.4s ease-in-out infinite; }
.dot.warn { background: var(--warn); }
.dot.err  { background: var(--down); }

@keyframes pulse { 50% { opacity: 0.35; } }

@media (prefers-reduced-motion: reduce) {
  .dot.live { animation: none; }
}

/* ---------- filters ---------- */

.filters {
  padding: var(--pad);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.filters input[type="number"] {
  /* 16px exactly — anything smaller triggers the iOS zoom trap. */
  font: 16px var(--mono);
  font-variant-numeric: tabular-nums;
  min-height: 44px;
  padding: 0 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
}

.filters input:focus-visible,
.tab:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible,
.row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.filter-toggles { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.chk {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  cursor: pointer;
}

.chk input { width: 17px; height: 17px; accent-color: var(--accent); }

.filter-actions { display: flex; gap: 10px; margin-top: 12px; }

.btn {
  flex: 1;
  min-height: 44px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #06210f;
  font: 600 15px var(--sans);
  cursor: pointer;
}

.btn.ghost { background: none; border: 1px solid var(--line); color: var(--text); }

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px var(--pad) 0;
  border-bottom: 1px solid var(--line-soft);
}

.tab {
  min-height: 44px;
  padding: 0 14px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font: 600 14px var(--sans);
  cursor: pointer;
}

.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

.count { font-family: var(--mono); font-size: 11px; color: var(--dim); }

/* ---------- tape rows ---------- */

.tape { list-style: none; margin: 0; padding: 0; }

.row {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 11px;
  align-items: center;
  width: 100%;
  min-height: 76px;
  padding: 11px var(--pad);
  background: none;
  border: none;
  border-bottom: 1px solid var(--line-soft);
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.row:active { background: var(--surface); }

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface-2);
  object-fit: cover;
  flex: none;
}

.row-main { min-width: 0; }

.row-top { display: flex; align-items: baseline; gap: 7px; min-width: 0; }

/* The ticker is the identifier — it must never be the thing that truncates.
   `flex: none` keeps it whole and forces the name to give up room instead. */
.sym {
  flex: none;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}

.name {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The structure strip — the line that answers "better or worse" without a tap. */
.strip {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 9px;
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
}

.strip b { font-weight: 600; color: var(--text); }

.row-right { text-align: right; display: grid; gap: 3px; justify-items: end; }

.mcap { font-family: var(--mono); font-size: 15px; font-weight: 600; }

.chg { font-family: var(--mono); font-size: 12.5px; }

/* Structure score: a bar, because the exact integer matters less than the rank. */
.score-wrap { display: flex; align-items: center; gap: 6px; margin-top: 2px; }

.score-bar {
  width: 46px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.score-fill { height: 100%; border-radius: 2px; }

.score-val { font-family: var(--mono); font-size: 11px; color: var(--muted); }

.trend-improving { background: var(--up); }
.trend-decaying  { background: var(--down); }
.trend-flat      { background: var(--muted); }

.flag {
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.flag.bad { color: var(--down); border-color: rgba(255, 107, 107, 0.45); }
.flag.good { color: var(--up); border-color: rgba(61, 220, 132, 0.4); }

.star {
  border: none;
  background: none;
  color: var(--dim);
  font-size: 17px;
  line-height: 1;
  width: 44px;
  height: 44px;
  cursor: pointer;
}

.star.on { color: var(--warn); }

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

/* ---------- detail sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 40;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-height: 86vh;
  overflow-y: auto;
  padding: 8px var(--pad) calc(env(safe-area-inset-bottom) + 22px);
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  max-width: 720px;
  margin: 0 auto;
}

.sheet-grab {
  width: 34px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 4px auto 14px;
}

.sheet h2 { margin: 0; font-size: 19px; }

.sheet .sub { color: var(--dim); font-size: 13px; margin: 2px 0 16px; }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
}

.metric { background: var(--surface); padding: 10px 11px; }

.metric .k {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--dim);
}

.metric .v {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  margin-top: 3px;
}

.section-h {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--dim);
  margin: 16px 0 8px;
}

table.windows {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
}

table.windows th,
table.windows td { padding: 7px 6px; text-align: right; border-bottom: 1px solid var(--line-soft); }

table.windows th { color: var(--dim); font-weight: 500; font-size: 11px; }

table.windows th:first-child,
table.windows td:first-child { text-align: left; color: var(--muted); }

.reasons { display: flex; flex-wrap: wrap; gap: 6px; }

.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }

.sheet-actions a,
.sheet-actions button {
  flex: 1;
  min-height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: none;
  color: var(--text);
  font: 600 14px var(--sans);
  text-decoration: none;
  cursor: pointer;
}

.disclaimer {
  padding: 22px var(--pad) 30px;
  text-align: center;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--dim);
}

/* ---------- positions / PnL ---------- */

/* The priority read: unrealised PnL large, everything else supporting it. */
.pnl-head {
  padding: 16px var(--pad);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.pnl-total { display: grid; gap: 2px; }

.pnl-total .k {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dim);
}

.pnl-total .v {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.1;
}

.pnl-total .sub { font-size: 13px; }

.pnl-side {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.pnl-side > div { display: grid; gap: 2px; }

.pnl-side .k {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--dim);
}

.pnl-side .num { font-size: 13.5px; }

.basis-note {
  margin: 12px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--dim);
}

.wallet-bar { padding: 28px var(--pad); text-align: center; }

.wallet-bar .btn { max-width: 320px; margin: 0 auto; }

.wallet-bar .hint {
  margin: 12px 0 0;
  font-size: 11.5px;
  color: var(--dim);
}

/* Row + star share a line; the star stays a full 44px target of its own. */
.row-outer { display: flex; align-items: center; }

.row-outer .row { flex: 1; min-width: 0; border-bottom: none; }

.row-outer { border-bottom: 1px solid var(--line-soft); }

.row-outer .star { flex: none; margin-right: 6px; }

/* ---------- home / categories ---------- */

.home { padding: var(--pad); display: grid; gap: 14px; }

/* Portfolio strip: SOL and USD together, because a SOL figure alone does not
   answer "how much money is that" and a USD figure alone hides the unit the
   position was actually taken in. */
.home-pnl {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 14px;
}

.home-pnl .hp-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dim);
}

.home-pnl .hp-main {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.15;
  margin-top: 2px;
}

.home-pnl .hp-sub {
  font-family: var(--mono);
  font-size: 13px;
  margin-top: 2px;
}

.hp-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.hp-grid > div { display: grid; gap: 2px; }

.hp-grid .k {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--dim);
}

.hp-grid .v {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

.hp-grid .v small {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
}

/* Category tiles route into a filtered tape. */
.cats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

.cat {
  min-height: 92px;
  text-align: left;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  color: inherit;
  font: inherit;
  cursor: pointer;
  display: grid;
  align-content: start;
  gap: 4px;
}

.cat:active { background: var(--surface-2); }

.cat .cat-n {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.cat .cat-t { font-size: 13px; font-weight: 600; }

.cat .cat-d { font-size: 11px; color: var(--dim); line-height: 1.35; }

.cat.wide { grid-column: 1 / -1; min-height: 0; }
