@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600;700&display=swap');

:root {
  --bg: #0A0D13;
  --bg-panel: #11151F;
  --bg-panel-2: #161B27;
  --bg-raised: #1B2130;
  --border: #232939;
  --border-soft: #1A2030;
  --text: #E7EAF2;
  --text-dim: #8B93A7;
  --text-faint: #5A6278;
  --amber: #F0A83C;
  --cyan: #3FD0C9;
  --violet: #8B5CF6;
  --long: #22C55E;
  --short: #EF4444;
  --wait: #EAB308;
  --long-bg: rgba(34,197,94,0.12);
  --short-bg: rgba(239,68,68,0.12);
  --wait-bg: rgba(234,179,8,0.12);
  --radius: 8px;
  --font-ui: 'IBM Plex Sans', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font-ui); }
body { -webkit-font-smoothing: antialiased; }
button, input, select { font-family: inherit; color: inherit; }
::selection { background: rgba(240,168,60,0.3); }
a { color: var(--cyan); }

/* ---------- App shell ---------- */
#app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 14px; padding: 10px 14px;
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
.brand .mark { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--amber), var(--cyan)); display: inline-block; }
.brand .venue-badge { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; letter-spacing: 0.04em; }
.venue-badge.paper { background: var(--wait-bg); color: var(--wait); border: 1px solid rgba(234,179,8,0.35); }
.venue-badge.testnet { background: rgba(63,208,201,0.14); color: var(--cyan); border: 1px solid rgba(63,208,201,0.35); }
.venue-badge.live { background: var(--short-bg); color: var(--short); border: 1px solid rgba(239,68,68,0.35); }

.conn-status { display: flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 12px; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; }
.conn-status .dot { width: 8px; height: 8px; border-radius: 50%; }
.conn-status.live .dot { background: var(--long); box-shadow: 0 0 8px var(--long); }
.conn-status.down .dot { background: var(--short); box-shadow: 0 0 8px var(--short); }
.conn-status.connecting .dot { background: var(--wait); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }

.topbar .spacer { flex: 1; }
.symbol-price { display: flex; align-items: baseline; gap: 8px; font-family: var(--font-mono); }
.symbol-price .sym { font-weight: 700; }
.symbol-price .px { font-size: 18px; font-weight: 700; }
.symbol-price .chg { font-size: 12px; font-weight: 600; padding: 2px 6px; border-radius: 4px; }
.chg.up { color: var(--long); background: var(--long-bg); }
.chg.down { color: var(--short); background: var(--short-bg); }

.icon-btn, .test-conn-btn { font-size: 11px; padding: 5px 9px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-raised); cursor: pointer; }
.icon-btn:hover, .test-conn-btn:hover { border-color: var(--cyan); }

/* ---------- Nav ---------- */
.nav { display: flex; gap: 2px; background: var(--bg-panel-2); border-bottom: 1px solid var(--border); padding: 0 10px; overflow-x: auto; scrollbar-width: none; -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent); }
.nav::-webkit-scrollbar { display: none; }
.nav button { background: none; border: none; padding: 11px 14px; font-size: 13px; color: var(--text-dim); cursor: pointer; white-space: nowrap; border-bottom: 2px solid transparent; font-weight: 500; }
.nav button.active { color: var(--text); border-bottom-color: var(--amber); }
.nav button:hover { color: var(--text); }

.view { display: none; padding: 14px; gap: 14px; flex-direction: column; }
.view.active { display: flex; }
/* Nested sub-panels (e.g. Strategy Lab's Gallery/Editor/Compare) use a separate class from the
   top-level .view so showView()'s document.querySelectorAll('.view') can't accidentally strip their
   own active state as a side effect of switching the top-level tab. */
.subview { display: none; padding: 14px 0 0; gap: 14px; flex-direction: column; }
.subview.active { display: flex; }

/* ---------- Cards / panels ---------- */
.card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.card-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); font-weight: 600; margin-bottom: 10px; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.terminal-layout { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
@media (max-width: 1000px) { .terminal-layout { grid-template-columns: 1fr; } }

/* ---------- Segmented sub-tabs (venue switcher within a view) ---------- */
.segment { display: inline-flex; background: var(--bg-raised); border: 1px solid var(--border); border-radius: 8px; padding: 2px; gap: 2px; }
.segment button { background: none; border: none; padding: 6px 14px; font-size: 12px; font-weight: 600; color: var(--text-dim); border-radius: 6px; cursor: pointer; }
.segment button.active { background: var(--bg-panel-2); color: var(--text); }

.symbol-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-raised); font-size: 12px; font-family: var(--font-mono); cursor: pointer; color: var(--text-dim); }
.chip.active { border-color: var(--amber); color: var(--amber); background: rgba(240,168,60,0.08); }
.tf-picker { display: flex; gap: 4px; }
.tf-picker button { padding: 5px 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-raised); font-size: 12px; cursor: pointer; color: var(--text-dim); }
.tf-picker button.active { border-color: var(--cyan); color: var(--cyan); }

canvas.price-chart { width: 100%; height: 340px; display: block; }
canvas.vol-chart { width: 100%; height: 60px; display: block; margin-top: 2px; }
canvas.osc-chart { width: 100%; height: 80px; display: block; }
.osc-row { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.osc-label { font-size: 10px; color: var(--text-faint); font-family: var(--font-mono); }

/* ---------- Signature: confidence-score gauge ---------- */
.score-panel { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.gauge-wrap { position: relative; width: 168px; height: 168px; }
.gauge-wrap svg { transform: rotate(-90deg); }
.gauge-bg { fill: none; stroke: var(--border-soft); stroke-width: 10; }
.gauge-fg { fill: none; stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset 0.6s ease, stroke 0.3s; }
.gauge-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.gauge-score { font-family: var(--font-mono); font-size: 30px; font-weight: 700; }
.gauge-score small { font-size: 13px; color: var(--text-faint); }
.gauge-label { font-size: 12px; font-weight: 700; letter-spacing: 0.04em; padding: 3px 10px; border-radius: 999px; margin-top: 2px; }
.dir-badge { font-size: 13px; font-weight: 700; letter-spacing: 0.05em; }
.dir-LONG { color: var(--long); } .dir-SHORT { color: var(--short); } .dir-WAIT { color: var(--wait); } .dir-HOLD { color: var(--wait); }
.label-WAIT, .label-HOLD, .label-WEAKSETUP { background: var(--wait-bg); color: var(--wait); }
.label-VALIDSETUP, .label-BUY, .label-SELL { background: rgba(63,208,201,0.14); color: var(--cyan); }
.label-ASETUP, .label-APLUSSETUP, .label-STRONGBUY, .label-STRONGSELL { background: var(--long-bg); color: var(--long); }

.category-bars { width: 100%; display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.cat-row { display: grid; grid-template-columns: 90px 1fr 34px; align-items: center; gap: 8px; font-size: 11px; }
.cat-track { height: 6px; border-radius: 4px; background: var(--border-soft); overflow: hidden; }
.cat-fill { height: 100%; background: linear-gradient(90deg, var(--amber), var(--cyan)); }
.cat-val { font-family: var(--font-mono); text-align: right; color: var(--text-dim); }

.reasons-list { list-style: none; margin: 8px 0 0; padding: 0; font-size: 12px; display: flex; flex-direction: column; gap: 4px; max-height: 200px; overflow-y: auto; }
.reasons-list li { color: var(--text-dim); }

.confidence-note { font-size: 11px; color: var(--text-faint); border-top: 1px solid var(--border-soft); margin-top: 10px; padding-top: 8px; line-height: 1.5; }

/* ---------- Trade plan / stat grids ---------- */
.plan-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; font-family: var(--font-mono); font-size: 12px; }
.plan-cell { background: var(--bg-raised); border: 1px solid var(--border); border-radius: 6px; padding: 8px; }
.plan-cell .k { color: var(--text-faint); font-size: 10px; text-transform: uppercase; }
.plan-cell .v { font-size: 14px; font-weight: 600; margin-top: 2px; }

/* ---------- Forms ---------- */
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); }
input[type=number], input[type=text], input[type=email], input[type=password], select {
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; font-size: 13px; color: var(--text); width: 100%;
}
input[type=checkbox] { accent-color: var(--amber); }
.btn { padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-raised); cursor: pointer; font-weight: 600; font-size: 13px; }
.btn:hover { border-color: var(--amber); }
.btn.primary { background: var(--amber); color: #1a1200; border-color: var(--amber); }
.btn.danger { background: var(--short); color: #fff; border-color: var(--short); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch { width: 40px; height: 22px; border-radius: 999px; background: var(--border); position: relative; transition: background 0.2s; flex: none; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--text); transition: transform 0.2s; }
.switch.on { background: var(--long); }
.switch.on::after { transform: translateX(18px); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; font-family: var(--font-mono); }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
th { color: var(--text-faint); font-weight: 600; text-transform: uppercase; font-size: 10px; letter-spacing: 0.04em; position: sticky; top: 0; background: var(--bg-panel); }
tr:hover td { background: rgba(255,255,255,0.02); }
.pill { padding: 2px 8px; border-radius: 999px; font-weight: 700; font-size: 11px; }
.pill.LONG { color: var(--long); background: var(--long-bg); }
.pill.SHORT { color: var(--short); background: var(--short-bg); }
.pill.WAIT { color: var(--wait); background: var(--wait-bg); }
.pill.WIN { color: var(--long); background: var(--long-bg); }
.pill.LOSS { color: var(--short); background: var(--short-bg); }
.num-pos { color: var(--long); } .num-neg { color: var(--short); }

/* ---------- Misc ---------- */
.hint { font-size: 11px; color: var(--text-faint); line-height: 1.5; }
.diag-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-family: var(--font-mono); font-size: 12px; }
.diag-item { display: flex; align-items: center; gap: 8px; }
.diag-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.diag-dot.ok { background: var(--long); } .diag-dot.bad { background: var(--short); }
.stat-tile { background: var(--bg-raised); border: 1px solid var(--border); border-radius: 6px; padding: 10px; }
.stat-tile .k { font-size: 10px; color: var(--text-faint); text-transform: uppercase; }
.stat-tile .v { font-family: var(--font-mono); font-size: 16px; font-weight: 700; margin-top: 2px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; max-width: 480px; width: 100%; max-height: 80vh; overflow-y: auto; }

.footer-note { font-size: 11px; color: var(--text-faint); text-align: center; padding: 16px; border-top: 1px solid var(--border); }
.log-list { list-style: none; margin: 0; padding: 0; font-family: var(--font-mono); font-size: 11px; display: flex; flex-direction: column; gap: 4px; max-height: 160px; overflow-y: auto; }
.log-list li { color: var(--text-dim); }

.empty-state { text-align: center; padding: 30px 16px; color: var(--text-faint); }

/* ---------- Auth gates (full-page, no app chrome) ---------- */
.auth-gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; max-width: 400px; width: 100%; }
.auth-card .brand { justify-content: center; margin-bottom: 6px; font-size: 18px; }
.auth-card .sub { text-align: center; color: var(--text-faint); font-size: 12px; margin-bottom: 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card .error { color: var(--short); font-size: 12px; min-height: 16px; }
.auth-card .switch-link { text-align: center; font-size: 12px; color: var(--text-dim); margin-top: 14px; }
.auth-card .switch-link a { cursor: pointer; }
.tos-box { font-size: 11px; color: var(--text-faint); line-height: 1.5; max-height: 120px; overflow-y: auto; background: var(--bg-raised); border: 1px solid var(--border); border-radius: 6px; padding: 8px; }

@media (max-width: 640px) {
  .plan-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { gap: 8px; }
  .symbol-price .px { font-size: 15px; }
}
