:root {
  color-scheme: dark;
  --bg: #0b0e11;
  --panel: #141922;
  --panel-2: #1a212c;
  --line: #27303d;
  --text: #eef2f5;
  --muted: #8b98a7;
  --up: #20b26b;
  --down: #e04f5f;
  --accent: #d7b35a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  background: #05070a;
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.app {
  position: relative;
  width: min(100vw, 440px);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  /* minmax(0,…) caps every row at the app width — one over-wide row must
     clip itself instead of dragging the whole app past the viewport */
  grid-template-columns: minmax(0, 1fr);
  background: var(--bg);
  overflow: hidden;
}

[hidden] { display: none !important; }

.view { min-height: 0; }
.view-chart {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  min-height: 0;
}

/* ---- top bar ---- */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.symbol {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 999px;
  padding: 1px 7px;
}

.clock { flex: 1; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

/* ---- timeframe row (always visible — owner preference) ---- */
.timeframes {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}
.timeframes button {
  min-height: 38px;
  border: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: var(--panel);
  transition: color .12s, background .12s;
}
.timeframes button:active { background: var(--panel-2); }
.timeframes button.active { color: #15110a; background: var(--accent); font-weight: 700; }

/* ---- chart ---- */
.chart-shell { position: relative; min-height: 0; background: var(--bg); }
.chart { position: absolute; inset: 0; }

.status-pill {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: rgba(8, 11, 16, 0.78);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.status-pill span {
  font: 600 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.status-pill button {
  display: flex;
  align-items: center;
  gap: 5px;
  border: 0;
  border-left: 1px solid var(--line);
  padding: 0 0 0 8px;
  background: none;
  color: var(--accent);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.status-pill button[hidden] { display: none; }
.status-pill span[hidden] { display: none; }
.status-pill.no-hud button { display: none; }
.status-pill:has(span[hidden]):has(button[hidden]) { display: none; }
.status-pill.no-hud:has(span[hidden]) { display: none; }
.status-pill button .ind-icon { width: 12px; height: 12px; }
.status-pill .edge-stats { color: var(--muted); font-size: 11px; }

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: rgba(11, 14, 17, 0.9);
  z-index: 5;
}
.loading.hidden { display: none; }

/* ---- controls ---- */
.controls {
  display: grid;
  grid-template-columns: 44px 44px auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 6px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.step {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent);
  background: var(--panel-2);
}
.step:active { filter: brightness(1.2); }
.step.denied { border-color: var(--down); color: var(--down); }

.toast {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.jump-row {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(8, 11, 16, 0.92);
  font-size: 12px;
  color: var(--muted);
}
.jump-row input {
  height: 30px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--panel-2);
  font-size: 13px;
}
.jump-row button {
  min-height: 30px;
  padding: 0 14px;
  border: 0;
  border-radius: 7px;
  font-weight: 700;
  color: #15110a;
  background: var(--accent);
}

.play {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent);
  background: var(--panel-2);
}
.play.playing { color: #15110a; background: var(--accent); border-color: var(--accent); }
.play:active { filter: brightness(0.92); }

.speed-pick { position: relative; }
.speed-chip {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent);
  background: var(--panel-2);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.speed-menu {
  position: absolute;
  bottom: 46px;
  left: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}
.speed-menu button {
  min-width: 46px;
  padding: 7px 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: transparent;
  font-size: 12px;
}
.speed-menu button.active {
  border-color: var(--accent);
  color: #15110a;
  background: var(--accent);
  font-weight: 700;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.toggle input { accent-color: var(--accent); }

.chart-pnl {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  overflow: hidden;
  white-space: nowrap;
}
.chart-pnl strong { color: var(--text); }
.chart-pnl strong.pos { color: var(--up); }
.chart-pnl strong.neg { color: var(--down); }

/* ---- account ---- */
.account {
  overflow-y: auto;
  padding: 10px;
  background: #10151d;
}

.acct-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}

.acct-grid div {
  display: grid;
  gap: 1px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
}

.acct-grid span { color: var(--muted); font-size: 10px; }
.acct-grid strong { font-size: 12px; font-variant-numeric: tabular-nums; }
.pos { color: var(--up); }
.neg { color: var(--down); }

.orders {
  max-height: none;
  overflow-y: auto;
  display: grid;
  gap: 3px;
  font-size: 11px;
  color: var(--text);
}

.orders + .orders { margin-top: 4px; }
.orders.empty { color: var(--muted); }

.history-page {
  overflow-y: auto;
  padding: 10px;
  background: #10151d;
}

.report {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  font-size: 11px;
}
.rep-title { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.rep-title span { color: var(--muted); font-weight: 400; }
.rep-row { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); }
.rep-row.indent { padding-left: 12px; }
.rep-row strong { font-variant-numeric: tabular-nums; }
.rep-verdict { margin-top: 2px; padding-top: 6px; border-top: 1px solid var(--line); color: var(--accent); }
.rep-hint { color: var(--muted); }

.order {
  display: grid;
  grid-template-columns: 44px 38px 1fr 62px 48px;
  align-items: center;
  gap: 5px;
  min-height: 27px;
  padding: 3px 4px 3px 6px;
  border-radius: 6px;
  background: var(--panel);
  font-variant-numeric: tabular-nums;
}

.history .order { grid-template-columns: 44px 56px 1fr 62px; opacity: 0.82; }

.side {
  font-size: 10px;
  font-weight: 800;
}
.side.buy { color: var(--up); }
.side.sell { color: var(--down); }

.order strong { text-align: right; }
.order button {
  min-height: 22px;
  border: 0;
  border-radius: 5px;
  color: var(--text);
  background: var(--panel-2);
  font-size: 10px;
  font-weight: 700;
}
.order button:active { filter: brightness(0.9); }

/* ---- trade bar ---- */
.trade-opts {
  display: grid;
  /* minmax(0,…): number inputs report a wide intrinsic width; a plain 1fr
     track refuses to shrink below it and widens the whole app past 100vw */
  grid-template-columns: 76px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
  padding: 7px 10px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.trade-opts select {
  height: 30px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--panel-2);
  font-size: 12px;
}
.trade-opts input.invalid { border-color: var(--down); box-shadow: 0 0 0 1px var(--down); }
#ordPrice[hidden] { display: none; }
.trade-opts label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.trade-opts input {
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--panel-2);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.lot input {
  width: 68px;
  border: 0;
  padding: 0;
  color: var(--text);
  background: transparent;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
}
.lot input:focus { outline: none; color: var(--accent); }
.lot button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
}
.lot button.risk { color: var(--accent); font-weight: 700; }

.risk-line {
  padding: 0 12px 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.risk-line.warn { color: var(--down); }

.quick-acts {
  display: flex;
  gap: 6px;
  padding: 4px 10px 6px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.quick-acts button {
  flex: 1;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
}
.quick-acts button:active { filter: brightness(1.25); }
.quick-acts button.denied { border-color: var(--down); color: var(--down); }

.trade {
  display: grid;
  grid-template-columns: 1fr 92px 1fr;
  gap: 8px;
  padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.trade button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}
.trade .t-price {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.9;
  font-variant-numeric: tabular-nums;
}
.trade .sell { background: #b03a4a; }
.trade .buy { background: #1a8455; }
.trade button:active { filter: brightness(0.92); }

.lot {
  display: grid;
  place-items: center;
  gap: 1px;
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}
.lot strong { color: var(--text); font-size: 14px; }

/* ---- bottom tabs ---- */
.bottom-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: var(--line);
}

.bottom-tabs button {
  min-height: 45px;
  border: 0;
  color: var(--muted);
  background: var(--panel);
  font-size: 12px;
  font-weight: 700;
}

.bottom-tabs button.active {
  color: var(--accent);
  background: var(--panel-2);
}

/* ---- B++ order sheet overrides ---- */
.setups-page {
  overflow-y: auto;
  padding: 10px;
  background: #10151d;
}

.setup-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.setup-card span { display: block; color: var(--muted); font-size: 11px; }
.tools-card { display: grid; grid-template-columns: 1fr; gap: 8px; }
.tools-card label { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.tools-card input { width: 18px; height: 18px; accent-color: var(--accent); }
.setup-card strong { font-size: 13px; }
.setup-card button {
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  color: #15110a;
  background: var(--accent);
  font-weight: 800;
}

.view-chart {
  position: relative;
  grid-template-rows: 1fr auto;
}

.trade .lot-chip {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
}
.trade .lot-chip span { color: var(--muted); font-size: 10px; }
.trade .lot-chip strong { font-size: 13px; font-variant-numeric: tabular-nums; }
.trade .lot-chip .t-caret { font-size: 9px; }

.bottom-tabs {
  grid-template-columns: repeat(4, 1fr);
}
.bottom-tabs button { min-height: 40px; font-size: 11px; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  z-index: 18;
  background: rgba(0, 0, 0, 0.46);
}

.order-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 19;
  max-height: 58%;
  overflow-y: auto;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  background: var(--panel);
  box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.48);
}
.sheet-handle {
  width: 42px;
  height: 4px;
  margin: 8px auto 4px;
  border-radius: 999px;
  background: #536071;
}
.sheet-head {
  display: grid;
  grid-template-columns: 1fr auto 32px;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet-head span { display: block; color: var(--muted); font-size: 10px; }
.sheet-head strong { font-size: 15px; }
.sheet-head b { color: var(--accent); font-variant-numeric: tabular-nums; }
.sheet-head button {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 22px;
  line-height: 1;
}

.order-sheet.buy .sheet-head b { color: var(--up); }
.order-sheet.sell .sheet-head b { color: var(--down); }

.order-sheet .trade-opts {
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 12px 6px;
  border-top: 0;
  background: transparent;
}
.order-sheet .trade-opts label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}
.order-sheet .trade-opts select,
.order-sheet .trade-opts input,
.order-sheet .lot {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}
.order-sheet .lot {
  display: grid;
  grid-template-columns: 44px 1fr;
  place-items: center;
}
.order-sheet .lot input {
  width: 100%;
  min-height: 0;
  border: 0;
  background: transparent;
}
.order-sheet .risk-line {
  padding: 0 12px 9px;
  background: transparent;
}
.sheet-actions {
  padding: 0 12px 8px;
}
.sheet-actions button {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  font-size: 15px;
  font-weight: 800;
}
.order-sheet.buy .sheet-actions button { background: #1a8455; }
.order-sheet.sell .sheet-actions button { background: #b03a4a; }
/* ---- indicator system ---- */
.toolbelt {
  position: absolute;
  right: 8px;
  bottom: 10px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.belt-toggle,
.belt-menu button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: rgba(13, 17, 23, 0.9);
  font-size: 12px;
  font-weight: 700;
}
.belt-menu { display: flex; flex-direction: column; gap: 6px; }
.belt-menu[hidden] { display: none; }
.toolbelt.open .belt-toggle { color: var(--accent); transform: rotate(180deg); }

.ind-icon { width: 16px; height: 16px; display: block; }

.ind-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.5);
}
.ind-overlay[hidden] { display: none; }

.ind-sheet {
  width: 100%;
  max-height: 80%;
  overflow-y: auto;
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}

.ind-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.ind-head b { flex: 1; font-size: 15px; font-weight: 700; }

.ind-ic {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: none;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
}
.ind-ic:active { background: var(--panel-2); }

.ind-list { padding: 4px 0; }
.ind-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.ind-row.dragging { opacity: 0.55; }
.ind-row.drop-target { box-shadow: inset 0 2px 0 var(--accent); }
.ind-handle { display: inline-flex; flex: none; color: var(--muted); touch-action: none; cursor: grab; }
.ind-dots { display: inline-flex; gap: 3px; flex: none; }
.ind-dots i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.ind-name { flex: 1; font-size: 13px; font-variant-numeric: tabular-nums; }
.ind-name.off { color: var(--muted); text-decoration: line-through; }

.ind-add {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: calc(100% - 24px);
  margin: 8px 12px;
  padding: 11px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--accent);
  background: transparent;
  font-weight: 600;
}

/* ---- edge checker ---- */
.edge-cond { color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: 0.3px; }
.edge-stats { color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }

.edge-hint { padding: 0 14px 6px; color: var(--muted); font-size: 11px; }

/* ---- drawing tools ---- */
.draw-bar {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(8, 11, 16, 0.88);
}
.draw-bar button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
}
.draw-bar button.on { color: #15110a; background: var(--accent); }
.draw-bar button:active { background: var(--panel-2); }
.draw-sep { width: 1px; height: 20px; background: var(--line); }

.edge-actions { display: flex; gap: 8px; padding: 10px 12px 4px; }
.edge-actions button {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
}
.edge-start { color: #15110a; background: var(--accent); }
.edge-stop { color: var(--down); background: transparent; border: 1px solid var(--down) !important; }
.edge-actions button:active { filter: brightness(0.92); }

.ind-cat { padding: 12px 14px 4px; color: var(--muted); font-size: 12px; }
.ind-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 4px; }
.ind-chip {
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel-2);
  font-size: 13px;
}
.ind-chip.on { border-color: var(--accent); color: var(--accent); }

.ind-body { padding: 4px 0 10px; }
.ind-line { display: flex; align-items: center; gap: 10px; padding: 7px 14px; }
.ind-line input[type="number"] {
  flex: 1;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel-2);
  font-size: 14px;
}
.ind-line input[type="color"] {
  width: 32px;
  height: 32px;
  flex: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
}
.ind-plabel { width: 64px; flex: none; color: var(--muted); font-size: 12px; }
.ind-empty { padding: 18px; text-align: center; color: var(--muted); }
