:root {
  --bg: #05070b;
  --surface: #0a0e14;
  --card: #0f141c;
  --border: #1a2433;
  --text: #eef3f9;
  --muted: #6b7f94;
  --green: #10b981;
  --red: #f43f5e;
  --amber: #f59e0b;
  --blue: #38bdf8;
  --accent: #6366f1;
  --pro-gold: #d4a853;
  --header-h: 3.4rem;
  --bottom-nav: 3.2rem;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-top: calc(var(--header-h) + var(--safe-t));
  padding-bottom: calc(var(--bottom-nav) + var(--safe-b));
}

.mobile-only { display: flex; }
.desktop-only { display: none; }

/* ── Compact header (single bar) ───────────────────────── */
.pro-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  background: rgba(5, 7, 11, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: calc(0.35rem + var(--safe-t)) 0.5rem 0.35rem;
}

.header-bar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.header-bar::-webkit-scrollbar { display: none; }

.brand-block {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}
.logo { font-size: 1.1rem; }
.brand-text { min-width: 0; }
.brand-row { display: flex; align-items: center; gap: 0.3rem; }
.brand-block h1 { font-size: 0.82rem; font-weight: 800; white-space: nowrap; }
.pro-badge {
  font-size: 0.48rem;
  font-weight: 800;
  color: #0a0a0a;
  background: linear-gradient(135deg, #f5d78e, var(--pro-gold));
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
}
.stream-pill {
  font-size: 0.5rem;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.stream-pill.live { color: var(--green); border-color: #14532d; background: rgba(16,185,129,0.08); }
.stream-pill.dead { color: var(--red); }
.status { font-size: 0.52rem; color: var(--muted); display: block; }
.status.ok { color: var(--green); }
.status.err { color: var(--red); }

.acct-chip {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.2rem 0.35rem;
  font-variant-numeric: tabular-nums;
}
.chip-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 2.1rem;
}
.chip-cell label {
  font-size: 0.42rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.chip-cell span {
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1.1;
}
.chip-cell span.pos { color: var(--green); }
.chip-cell span.neg { color: var(--red); }

.quote-chip {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.qc { display: flex; flex-direction: column; align-items: center; }
.qc label { font-size: 0.42rem; color: var(--muted); text-transform: uppercase; }
.qc b { font-size: 0.68rem; font-weight: 700; }
.qc b.bid { color: var(--green); }
.qc b.ask { color: var(--red); }
.qc.clock { font-size: 0.62rem; color: var(--muted); justify-content: center; min-width: 3.5rem; }

.member-bar {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
  margin-left: auto;
}
.member-avatar { width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--border); }
.member-tier {
  font-size: 0.45rem;
  font-weight: 700;
  padding: 0.08rem 0.25rem;
  border-radius: 3px;
  background: rgba(99,102,241,0.15);
  color: var(--accent);
}
.member-tier.admin { background: rgba(212,168,83,0.2); color: var(--pro-gold); }
.logout-btn {
  font-size: 0.52rem;
  color: var(--muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15rem 0.35rem;
  cursor: pointer;
}

.price-block {
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.sym-label { font-size: 0.48rem; color: var(--amber); font-weight: 700; }
.price-live {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--blue);
  line-height: 1;
}
.price-live.tick-up { color: var(--green); }
.price-live.tick-down { color: var(--red); }

.pos-strip { margin-top: 0.25rem; font-size: 0.62rem; }
.pos-strip:not([hidden]) {
  border-top: 1px solid var(--border);
  padding-top: 0.2rem;
}

/* ── Terminal layout ───────────────────────────────────── */
.terminal {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--header-h) - var(--bottom-nav) - var(--safe-t) - var(--safe-b));
}

.view-intel .chart-zone { display: none; }
.view-intel .intel-zone { display: flex; flex: 1; }
.view-chart .chart-zone { display: flex; flex: 1; min-height: 0; }
.view-chart .intel-zone { display: none; }

.chart-zone {
  flex-direction: column;
  background: var(--surface);
  min-height: 0;
  flex: 1;
}

.tf-toolbar {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}
.tf-btn {
  min-width: 36px;
  min-height: 32px;
  padding: 0 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}
.tf-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.tf-loading { font-size: 0.6rem; color: var(--blue); margin-left: 0.25rem; }

.chart-canvas {
  flex: 1;
  width: 100%;
  min-height: 280px;
  height: calc(100dvh - var(--header-h) - var(--bottom-nav) - 5.5rem);
}

.chart-foot {
  padding: 0.3rem 0.5rem;
  font-size: 0.58rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Intel ─────────────────────────────────────────────── */
.intel-zone { flex-direction: column; flex: 1; overflow: hidden; }
.intel-tabs {
  gap: 0.2rem;
  padding: 0.35rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.itab {
  flex: 1;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
}
.itab.active { background: var(--card); color: var(--text); }
.intel-panel { display: none; flex: 1; overflow-y: auto; padding: 0.4rem; }
.intel-panel.active { display: block; }

.pro-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem;
}
.pro-card h2 {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.plan-item, .cal-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.55rem;
  margin-bottom: 0.35rem;
  font-size: 0.74rem;
  line-height: 1.35;
}
.plan-item.primary { border-color: var(--accent); background: rgba(99,102,241,0.06); }
.plan-meta { color: var(--muted); font-size: 0.65rem; margin-top: 0.2rem; }
.dir-long { color: var(--green); font-weight: 700; }
.dir-short { color: var(--red); font-weight: 700; }
.pos { color: var(--green); }
.neg { color: var(--red); }

.chip-row { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.4rem; }
.chip {
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.analysis-box { font-size: 0.75rem; line-height: 1.45; }

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 200;
  height: calc(var(--bottom-nav) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(5,7,11,0.96);
  border-top: 1px solid var(--border);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.58rem;
  cursor: pointer;
  min-height: 44px;
}
.nav-btn.active { color: var(--blue); }

.desk-foot {
  font-size: 0.58rem;
  color: var(--muted);
  padding: 0.3rem 0.5rem;
  justify-content: space-between;
  max-width: 1440px;
  margin: 0 auto;
}

@media (min-width: 960px) {
  :root { --header-h: 3.2rem; --bottom-nav: 0; }
  body { padding-bottom: 1.5rem; }
  .mobile-only { display: none !important; }
  .desktop-only { display: flex; }

  .header-bar { flex-wrap: nowrap; overflow: visible; }
  .member-bar { margin-left: 0; }
  .price-block { margin-left: auto; }
  .price-live { font-size: 1.35rem; }

  .terminal {
    display: grid;
    grid-template-columns: 1fr 300px;
    max-width: 1440px;
    margin: 0 auto;
    min-height: calc(100dvh - var(--header-h) - 1.5rem);
  }
  .chart-canvas {
    min-height: 480px;
    height: calc(100dvh - var(--header-h) - 4rem);
  }
  .intel-zone {
    display: flex !important;
    flex-direction: column;
    overflow-y: auto;
    max-height: calc(100dvh - var(--header-h) - 1.5rem);
  }
  .intel-panel { display: block !important; padding: 0.35rem; }
}

@media (max-width: 700px) {
  :root { --header-h: 4.8rem; }
  .header-bar { flex-wrap: wrap; row-gap: 0.3rem; }
  .brand-block { order: 1; }
  .price-block { order: 2; margin-left: auto; }
  .acct-chip { order: 3; width: 100%; justify-content: space-around; }
  .quote-chip { order: 4; width: 100%; justify-content: space-between; }
  .member-bar { order: 5; margin-left: 0; }
}