/* Polaris — celestial-navigation operator console.
   Signature: the hero "equity trajectory" — a glowing curve ending in a pulsing
   Polaris star, with the live equity counted up over it. Everything else stays
   quiet glass so the trajectory is the one thing you remember. */

:root {
  --void:      #070b18;   /* deep space base            */
  --abyss:     #0c1326;   /* panel base                 */
  --horizon:   #131d38;   /* raised surface             */
  --line:      #233252;   /* hairline borders           */
  --starlight: #eef4ff;   /* primary ink                */
  --haze:      #8da3cc;   /* muted ink                  */
  --polaris:   #5fd0ff;   /* the guiding cyan           */
  --aurora:    #8a6bff;   /* secondary violet           */
  --gain:      #2fe0a6;
  --loss:      #ff5d7a;
  --gold:      #ffcf6b;

  --glass: linear-gradient(160deg, rgba(28,42,78,.55), rgba(12,19,38,.65));
  --glow-polaris: 0 0 18px rgba(95,208,255,.45);
  --r: 18px;
  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--void);
  color: var(--starlight);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ambient starfield canvas sits behind everything */
#stars {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(1200px 700px at 78% -8%, rgba(95,208,255,.10), transparent 60%),
    radial-gradient(900px 600px at 10% 110%, rgba(138,107,255,.10), transparent 55%);
}
.app { position: relative; z-index: 1; }

/* ── top bar ─────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 26px;
  background: rgba(7,11,24,.72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.wordmark { font-family: var(--font-display); font-weight: 700; font-size: 21px; letter-spacing: .14em; text-transform: uppercase; display: flex; align-items: center; gap: 10px; }
.wordmark .mark { color: var(--polaris); text-shadow: var(--glow-polaris); font-size: 18px; }
.badge { font-family: var(--font-mono); font-size: 11px; padding: 3px 9px; border-radius: 999px; letter-spacing: .05em; }
.badge-demo { background: rgba(255,207,107,.12); color: var(--gold); border: 1px solid rgba(255,207,107,.4); }
.top-right { display: flex; align-items: center; gap: 16px; }
.pulse { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 12px; color: var(--haze); }
.pulse .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--haze); }
.pulse.ok .dot { background: var(--gain); box-shadow: 0 0 10px var(--gain); animation: breathe 2.4s ease-in-out infinite; }
.pulse.bad .dot { background: var(--loss); box-shadow: 0 0 10px var(--loss); }
/* brief flash on the "updated · HH:MM:SS" text each 5s poll — the refresh signal,
   so charts can update smoothly in place instead of re-animating every refresh */
.just-updated { animation: tickflash .6s ease-out; }
@keyframes tickflash { 0% { color: var(--polaris); text-shadow: 0 0 8px var(--polaris); } 100% { color: var(--haze); text-shadow: none; } }
@keyframes breathe { 50% { opacity: .35; } }
.broker { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-mono); font-size: 12px; color: var(--haze);
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; }
.broker .bdot { width: 8px; height: 8px; border-radius: 50%; background: var(--haze); }
.broker.ok   { color: var(--gain); border-color: rgba(47,224,166,.4); }
.broker.ok .bdot   { background: var(--gain); box-shadow: 0 0 10px var(--gain); }
.broker.bad  { color: var(--loss); border-color: rgba(255,93,122,.5); }
.broker.bad .bdot  { background: var(--loss); box-shadow: 0 0 10px var(--loss); animation: breathe 1.2s ease-in-out infinite; }
.broker.idle .bdot { background: var(--haze); }

.wrap { max-width: 1320px; margin: 0 auto; padding: 26px; }

/* ── hero: the equity trajectory (signature) ─────────────── */
.hero {
  position: relative; overflow: hidden;
  border: 1px solid var(--line); border-radius: 24px;
  background: var(--glass);
  padding: 30px 32px 8px;
  min-height: 280px;
  margin-bottom: 22px;
}
.hero canvas { position: absolute; inset: auto 0 0 0; height: 78% !important; width: 100% !important; opacity: .9; }
.hero-head { position: relative; z-index: 2; }
.hero-eyebrow { font-family: var(--font-mono); font-size: 12px; letter-spacing: .22em; text-transform: uppercase; color: var(--polaris); margin-bottom: 8px; }
.hero-equity { font-family: var(--font-mono); font-weight: 700; font-size: clamp(40px, 7vw, 72px); line-height: 1; letter-spacing: -.02em; text-shadow: 0 4px 40px rgba(95,208,255,.25); }
.hero-sub { margin-top: 12px; display: flex; gap: 22px; flex-wrap: wrap; align-items: baseline; }
.hero-pnl { font-family: var(--font-mono); font-size: 20px; font-weight: 700; }
.hero-meta { font-size: 13px; color: var(--haze); }

/* ── KPI strip ───────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.kpi {
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px 18px; transition: transform .25s, border-color .25s, box-shadow .25s;
  /* equal-height cards with the explanatory sub-text pinned to the bottom, so
     labels/values/captions line up across the whole row */
  display: flex; flex-direction: column; min-height: 92px;
}
.kpi:hover { transform: translateY(-3px); border-color: rgba(95,208,255,.5); box-shadow: 0 10px 30px rgba(0,0,0,.35); }
/* the headline "Today — total" card stands out from the rest */
.kpi.hero-kpi { border-color: rgba(95,208,255,.45); background: linear-gradient(180deg, rgba(95,208,255,.10), var(--glass)); }
.kpi.hero-kpi .value { font-size: 27px; }
.kpi .label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--haze); }
.kpi .value { font-family: var(--font-mono); font-weight: 700; font-size: 23px; margin-top: 8px; }
.kpi .sub { font-family: var(--font-mono); font-size: 12px; color: var(--haze); margin-top: auto; padding-top: 6px; }

/* ── panels + charts ─────────────────────────────────────── */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel { background: var(--glass); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; margin-bottom: 18px; }
.panel h3 { margin: 0 0 4px; font-family: var(--font-display); font-weight: 500; font-size: 15px; }
.panel .cap { font-size: 12px; color: var(--haze); margin-bottom: 14px; }
.panel canvas { max-height: 240px; }
/* horizontal per-position bars: height set in JS by count, capped panel-sized */
#posPnlChart { max-height: 300px; }
.span-2 { grid-column: 1 / -1; }

/* ── tables ──────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; color: var(--haze); font-weight: 600; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 12px; border-bottom: 1px solid rgba(35,50,82,.45); font-family: var(--font-mono); }
.tbl td.sym { font-family: var(--font-display); font-weight: 500; letter-spacing: .02em; }
.tbl tr { transition: background .2s; }
.tbl tbody tr:hover { background: rgba(95,208,255,.05); }
.num { text-align: right; }
/* numeric column HEADERS must right-align too — `.tbl th` (left) out-specifies
   `.num`, which left the headers shifted off from their right-aligned values */
.tbl th.num { text-align: right; }
.gain { color: var(--gain); } .loss { color: var(--loss); }
.pill { font-family: var(--font-mono); font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 7px; letter-spacing: .04em; }
.pill.long  { background: rgba(47,224,166,.14); color: var(--gain); box-shadow: inset 0 0 0 1px rgba(47,224,166,.3); }
.pill.short { background: rgba(255,93,122,.14); color: var(--loss); box-shadow: inset 0 0 0 1px rgba(255,93,122,.3); }
.empty { color: var(--haze); padding: 18px 4px; text-align: center; }

/* ── buttons ─────────────────────────────────────────────── */
.btn { font-family: var(--font-body); font-size: 13px; padding: 8px 15px; border-radius: 10px; border: 1px solid var(--line); background: rgba(28,42,78,.5); color: var(--starlight); cursor: pointer; transition: border-color .2s, background .2s, transform .1s; }
.btn:hover { border-color: var(--polaris); }
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 2px solid var(--polaris); outline-offset: 2px; }
.btn-ghost-danger { border-color: rgba(255,93,122,.35); color: var(--loss); }
.btn-ghost-danger:hover { background: rgba(255,93,122,.14); border-color: var(--loss); }
.btn-danger { background: var(--loss); color: #2a0410; border: none; font-weight: 700; }
.btn-primary { background: linear-gradient(135deg, var(--polaris), var(--aurora)); color: #04121f; border: none; font-weight: 700; width: 100%; padding: 12px; }
.btn-xs { padding: 5px 11px; font-size: 12px; }

/* ── modal (display via .is-open class — never the [hidden] race) ── */
.modal { position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center; background: rgba(4,7,16,.74); backdrop-filter: blur(6px); }
.modal.is-open { display: flex; animation: fade .18s ease; }
.modal-box { width: min(440px, 92vw); background: var(--horizon); border: 1px solid var(--line); border-radius: 20px; padding: 26px; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.modal-box h3 { margin: 0 0 10px; font-family: var(--font-display); }
.modal-box p { color: var(--haze); }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 22px; }
@keyframes fade { from { opacity: 0; } }

/* ── entrance orchestration ──────────────────────────────── */
.rise { opacity: 0; transform: translateY(14px); animation: rise .6s cubic-bezier(.2,.7,.2,1) forwards; }
.rise:nth-child(2) { animation-delay: .05s; } .rise:nth-child(3) { animation-delay: .1s; }
.rise:nth-child(4) { animation-delay: .15s; } .rise:nth-child(5) { animation-delay: .2s; }
@keyframes rise { to { opacity: 1; transform: none; } }

/* ── login ───────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; position: relative; z-index: 1; }
.login-card { width: min(360px, 92vw); background: var(--glass); border: 1px solid var(--line); border-radius: 22px; padding: 34px 30px; text-align: center; }
.login-card .wordmark { justify-content: center; font-size: 26px; margin-bottom: 6px; }
.login-card .tag { color: var(--haze); font-size: 13px; margin-bottom: 22px; }
.login-card input { width: 100%; padding: 12px 14px; margin-bottom: 14px; border-radius: 11px; border: 1px solid var(--line); background: rgba(7,11,24,.6); color: var(--starlight); font-family: var(--font-mono); }
.login-card input:focus { outline: none; border-color: var(--polaris); box-shadow: var(--glow-polaris); }
.login-err { color: var(--loss); font-size: 13px; margin-bottom: 12px; }

/* ── tablet ─────────────────────────────────────────────── */
@media (max-width: 1000px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: 1fr; }
}

/* ── phone ──────────────────────────────────────────────── */
@media (max-width: 640px) {
  .wrap { padding: 14px; }
  .topbar { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
  .wordmark { font-size: 18px; }
  .top-right { gap: 8px; width: 100%; justify-content: space-between; }
  .top-right .btn { padding: 7px 10px; font-size: 12px; flex: 1; }
  .top-right .pulse { order: 3; width: 100%; justify-content: center; }

  /* hero: smaller, let the curve breathe */
  .hero { padding: 20px 18px 8px; min-height: 200px; border-radius: 18px; }
  .hero-equity { font-size: clamp(34px, 12vw, 48px); }
  .hero canvas { height: 70% !important; }

  /* KPIs: 2-up, tighter */
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 12px 13px; }
  .kpi .value { font-size: 19px; }

  .panel { padding: 14px 14px; border-radius: 14px; }
  .panel canvas { max-height: 200px; }

  /* tables scroll horizontally instead of squashing/overflowing the viewport */
  .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tbl { min-width: 540px; font-size: 12px; }
  .tbl th, .tbl td { padding: 9px 8px; }
  .btn-xs { padding: 6px 10px; }   /* keep the Close tap target usable */

  .modal-box { padding: 20px; border-radius: 16px; }
}

/* safe-area padding for notched iPhones */
@supports (padding: max(0px)) {
  .topbar { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .wrap { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
}

.login-input { width: 100%; padding: 12px 14px; margin-bottom: 14px; border-radius: 11px;
  border: 1px solid var(--line); background: rgba(7,11,24,.6); color: var(--starlight);
  font-family: var(--font-mono); font-size: 16px; }   /* 16px stops iOS zoom-on-focus */

/* ── activity feed ──────────────────────────────────────── */
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--haze); vertical-align: middle; margin-inline-start: 4px; }
.live-dot.on { background: var(--gain); box-shadow: 0 0 8px var(--gain);
  animation: breathe 2.4s ease-in-out infinite; }
.feed { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto;
  font-family: var(--font-mono); font-size: 12.5px; }
.feed-empty { color: var(--haze); padding: 10px 2px; }
.feed-row { display: flex; align-items: baseline; gap: 10px; padding: 7px 8px;
  border-radius: 9px; border-inline-start: 2px solid transparent; }
.feed-row:nth-child(odd) { background: rgba(255,255,255,.018); }
.feed-ico { flex: 0 0 auto; width: 16px; text-align: center; }
.feed-time { flex: 0 0 auto; color: var(--haze); font-size: 11px; }
.feed-txt { flex: 1 1 auto; color: var(--starlight); word-break: break-word; }
.feed-row.k-trade { border-inline-start-color: var(--gain); }
.feed-row.k-exit  { border-inline-start-color: var(--loss); }
.feed-row.k-stop  { border-inline-start-color: var(--polaris); }
.feed-row.k-error { border-inline-start-color: var(--gold); }
.feed-row.k-error .feed-txt { color: var(--gold); }
.feed-row.k-conn  { border-inline-start-color: var(--aurora); }
.feed-row.k-cycle .feed-txt { color: var(--haze); }
.login-input:focus { outline: none; border-color: var(--polaris); box-shadow: var(--glow-polaris); }
.login-input[readonly] { opacity: .6; }

.tbl td.age { font-family: var(--font-mono); font-size: 12px; white-space: nowrap; }
.tbl td.age.ok   { color: var(--gain, #2fe0a6); }
.tbl td.age.warn { color: var(--warn, #ffb454); }
.tbl td.age.due  { color: var(--loss, #ff5d7a); font-weight: 700; }
.tbl td.age.muted{ color: var(--haze); }

.tag-unmanaged { font-family: var(--font-mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--warn, #ffb454); border: 1px solid rgba(255,180,84,.5);
  border-radius: 6px; padding: 1px 5px; margin-inline-start: 6px; vertical-align: middle; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
