/* TradingView-like look: light theme by default, dark via [data-theme=dark]. */
:root, [data-theme=light] {
  --bg: #ffffff; --panel: #ffffff; --panel2: #f0f3fa; --hover: #f0f3fa; --line: #e0e3eb; --line2: #d1d4dc;
  --text: #131722; --muted: #787b86; --accent: #2962ff; --accent2: #1e53e5; --accentBg: #e3effd;
  --buy: #2962ff; --sell: #f23645; --up: #089981; --down: #f23645; --gold: #f7a600;
  --shadow: 0 2px 12px rgba(19,23,34,.15); --radius: 6px;
  color-scheme: light;
}
[data-theme=dark] {
  --bg: #131722; --panel: #131722; --panel2: #1e222d; --hover: #2a2e39; --line: #2a2e39; --line2: #363a45;
  --text: #d1d4dc; --muted: #787b86; --accent: #2962ff; --accent2: #5b8cff; --accentBg: #142e61;
  --shadow: 0 2px 14px rgba(0,0,0,.5);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.35 -apple-system, BlinkMacSystemFont, "Trebuchet MS", Roboto, Ubuntu, sans-serif; }
body { display: flex; flex-direction: column; overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
input, select { background: var(--bg); border: 1px solid var(--line2); border-radius: 4px; padding: 5px 7px; min-width: 0; }
input:focus, select:focus { outline: none; border-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.grow { flex: 1; }
svg { width: 28px; height: 28px; flex: none; }

/* ---------------------------------------------------------------- top toolbar */
.topbar { display: flex; align-items: center; gap: 2px; height: 46px; padding: 0 8px; background: var(--panel); border-bottom: 4px solid var(--panel2); flex: none; }
.symbol { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 6px; border-radius: 4px; font-size: 15px; }
.symbol:hover { background: var(--hover); }
.coin { width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffd34d, var(--gold)); color: #7a4b00; display: grid; place-items: center; font-weight: 800; font-size: 9px; flex: none; }
.coin.small { width: 18px; height: 18px; font-size: 8px; }
.vsep { width: 1px; height: 26px; background: var(--line); margin: 0 6px; flex: none; }
.group { display: flex; align-items: center; gap: 2px; }
.group.right { margin-left: auto; gap: 6px; }
.tfbtn { background: none; border: none; height: 34px; padding: 0 9px; border-radius: 4px; cursor: pointer; font-size: 14px; color: var(--text); }
.tfbtn:hover { background: var(--hover); }
.tfbtn.active { color: var(--accent); background: var(--accentBg); }
.tbtn { display: flex; align-items: center; gap: 4px; height: 34px; padding: 0 8px; background: none; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.tbtn:hover { background: var(--hover); }
.tbtn.active { color: var(--accent); background: var(--accentBg); }
.tbtn.icon { padding: 0 3px; }
.tbtn.small { height: 26px; font-size: 13px; }
.tsel { border: none; background: none; padding: 6px 4px; cursor: pointer; border-radius: 4px; }
.tsel:hover { background: var(--hover); }
.clock { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text); }
.liveBadge { border: none; background: var(--panel2); border-radius: 12px; padding: 3px 10px; font-size: 12px; font-weight: 600; cursor: default; color: var(--muted); }
.liveBadge.open { color: var(--up); }
.liveBadge.closed { color: var(--gold); }
.liveBadge.error { color: var(--sell); }
.liveBadge.replay { color: #fff; background: var(--accent); cursor: pointer; }
.btn { background: var(--bg); border: 1px solid var(--line2); border-radius: 4px; padding: 5px 10px; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.accent:hover:not(:disabled) { background: var(--accent2); }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn.danger:hover { border-color: var(--sell); color: var(--sell); }

/* ---------------------------------------------------------------- layout */
.layout { flex: 1; display: grid; grid-template-columns: 52px minmax(0, 1fr) 280px; min-height: 0; }
.tools { background: var(--panel); border-right: 4px solid var(--panel2); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0; }
.tool { width: 38px; height: 38px; display: grid; place-items: center; background: none; border: none; border-radius: 4px; cursor: pointer; color: var(--text); }
.tool:hover { background: var(--hover); }
.tool.active { color: var(--accent); background: var(--accentBg); }
.tsep { width: 30px; height: 1px; background: var(--line); margin: 4px 0; }
.colorTool input { width: 22px; height: 22px; padding: 0; border: 1px solid var(--line2); border-radius: 50%; cursor: pointer; overflow: hidden; }
.colorTool input::-webkit-color-swatch-wrapper { padding: 0; }
.colorTool input::-webkit-color-swatch { border: none; border-radius: 50%; }
.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chartWrap { position: relative; flex: 1; min-height: 220px; overflow: hidden; }
#chart { position: absolute; inset: 0; }
#chart.drawing canvas { cursor: crosshair !important; }
#chart.dragline canvas { cursor: ns-resize !important; }
#chart.picking canvas, #chart.btnhover canvas { cursor: pointer !important; }

/* legend + quick trade, top left of the chart like TradingView */
.legend { position: absolute; left: 10px; top: 6px; z-index: 3; pointer-events: none; max-width: calc(100% - 90px); }
.titleRow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 16px; }
.titleRow .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.titleRow .dot.open { background: var(--up); box-shadow: 0 0 0 3px color-mix(in srgb, var(--up) 25%, transparent); }
.titleRow .dot.closed { background: var(--gold); }
.ohlc { font-size: 13px; font-variant-numeric: tabular-nums; margin-left: 6px; }
.ohlc i { font-style: normal; color: var(--text); margin-left: 6px; }
.ohlc i:first-child { margin-left: 0; }
.ohlc .pos { color: var(--up); } .ohlc .neg { color: var(--down); }
.quick { display: flex; align-items: center; gap: 6px; margin: 6px 0 4px; pointer-events: auto; width: max-content; }
.quick button { display: flex; flex-direction: column; align-items: flex-start; min-width: 96px; padding: 3px 10px; border-radius: 4px; background: var(--bg); cursor: pointer; font-variant-numeric: tabular-nums; line-height: 1.15; }
.quick button b { font-size: 15px; font-weight: 500; }
.quick button span { font-size: 11px; }
.qSell { border: 1px solid var(--sell); color: var(--sell); }
.qBuy { border: 1px solid var(--buy); color: var(--buy); }
.qSell:hover:not(:disabled) { background: var(--sell); color: #fff; } .qBuy:hover:not(:disabled) { background: var(--buy); color: #fff; }
.quick button:disabled { opacity: .5; cursor: default; }
.qSpread { font-size: 12px; color: var(--muted); min-width: 28px; text-align: center; font-variant-numeric: tabular-nums; }
#legend { font-size: 13px; line-height: 1.7; }
#legend .ind { pointer-events: auto; display: flex; gap: 6px; align-items: center; color: var(--text); width: max-content; padding: 0 4px; margin-left: -4px; border-radius: 3px; }
#legend .ind:hover { outline: 1px solid var(--line2); background: var(--bg); }
#legend .ind .acts { display: none; gap: 2px; }
#legend .ind:hover .acts { display: inline-flex; }
#legend .ind button { background: var(--bg); border: 1px solid var(--line2); border-radius: 3px; cursor: pointer; font-size: 11px; padding: 0 5px; color: var(--muted); line-height: 18px; }
#legend .ind button:hover { color: var(--text); }
#legend .ind.off .name { color: var(--muted); }
.countdown { position: absolute; z-index: 3; right: 0; pointer-events: none; color: #fff; font-size: 12px; font-variant-numeric: tabular-nums; padding: 0 0 2px 7px; line-height: 15px; }
.banner { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 5; background: var(--text); color: var(--bg); padding: 7px 16px; border-radius: 4px; box-shadow: var(--shadow); }

/* floating replay toolbar, bottom centre like TradingView's Bar Replay */
.replayBar { position: absolute; left: 50%; bottom: 40px; transform: translateX(-50%); width: max-content; z-index: 6; display: flex; align-items: center; gap: 2px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); max-width: calc(100% - 20px); flex-wrap: wrap; justify-content: center; }
.rgroup { display: flex; align-items: center; gap: 2px; }
.rsep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.rbtn { display: flex; align-items: center; gap: 4px; height: 32px; padding: 0 8px; background: none; border: none; border-radius: 4px; cursor: pointer; white-space: nowrap; }
.rbtn svg { width: 22px; height: 22px; }
.rbtn:hover:not(:disabled) { background: var(--hover); }
.rbtn:disabled { opacity: .35; cursor: default; }
.rbtn.icon { padding: 0 5px; }
.rbtn.active { color: var(--accent); background: var(--accentBg); }
.rbtn.accent { background: var(--accent); color: #fff; font-weight: 600; padding: 0 14px; }
.rbtn.accent:hover { background: var(--accent2); }
.rsel { border: none; background: none; padding: 6px 2px; cursor: pointer; }
.rsel:hover { background: var(--hover); }
#replayDate { border: 1px solid var(--line); height: 32px; }

/* ---------------------------------------------------------------- bottom panel */
.bottom { height: 240px; border-top: 4px solid var(--panel2); background: var(--panel); display: flex; flex-direction: column; flex: none; }
.bottom.collapsed { height: 42px; }
.bottom.collapsed .tabBody { display: none; }
.tabs { display: flex; align-items: center; gap: 2px; padding: 0 8px; border-bottom: 1px solid var(--line); min-height: 38px; overflow-x: auto; }
.panelName { font-weight: 600; margin-right: 10px; white-space: nowrap; }
.tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 9px 10px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--text); }
.pill { background: var(--panel2); border-radius: 8px; padding: 0 6px; font-size: 11px; }
.accStrip { display: flex; gap: 16px; white-space: nowrap; font-size: 12px; color: var(--muted); margin-right: 8px; font-variant-numeric: tabular-nums; }
.accStrip b { color: var(--text); font-weight: 600; margin-left: 4px; }
.accStrip b.pos { color: var(--up); } .accStrip b.neg { color: var(--down); }
.tabBody { flex: 1; overflow: auto; padding: 4px 10px; }
.grid { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.grid th { text-align: left; color: var(--muted); font-weight: 400; padding: 6px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); white-space: nowrap; font-size: 12px; }
.grid td { padding: 5px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid tr:hover td { background: var(--hover); }
.grid input { width: 90px; padding: 2px 5px; }
.grid .empty { color: var(--muted); text-align: center; padding: 26px; }
.pos { color: var(--up); } .neg { color: var(--down); }
.row { display: flex; gap: 6px; align-items: center; }
.row.end { justify-content: flex-end; margin: 4px 0; }
.statsWrap { display: grid; grid-template-columns: minmax(300px, 1.1fr) 1fr; gap: 12px; height: 100%; }
.statGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; align-content: start; padding: 4px 0; }
.stat { background: var(--panel2); border-radius: 4px; padding: 6px 8px; }
.stat span { display: block; color: var(--muted); font-size: 11px; }
.stat b { font-size: 14px; font-variant-numeric: tabular-nums; font-weight: 600; }
.equity { min-height: 150px; position: relative; }
.settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; max-width: 900px; padding: 6px 0; }
.settings label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.settings label.cb { flex-direction: row; align-items: center; grid-column: 1 / -1; }
.settings p { grid-column: 1 / -1; margin: 0; }

/* ---------------------------------------------------------------- order panel */
.side { background: var(--panel); border-left: 4px solid var(--panel2); padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.sideHead { display: flex; align-items: center; gap: 10px; }
.sideHead .coin { width: 30px; height: 30px; font-size: 11px; }
.sideHead b { font-size: 15px; }
.sideHead small { display: block; color: var(--muted); font-size: 11px; }
.buysell { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.buysell button { border: none; border-radius: 4px; padding: 8px; cursor: pointer; color: #fff; display: flex; flex-direction: column; align-items: center; font-variant-numeric: tabular-nums; }
.buysell button span { font-size: 12px; opacity: .9; }
.buysell button b { font-size: 16px; font-weight: 600; }
.buy { background: var(--buy); } .sell { background: var(--sell); }
.buy:hover, .sell:hover { filter: brightness(1.08); }
.buysell button:disabled { opacity: .4; cursor: default; filter: none; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.seg button { background: none; border: none; border-bottom: 2px solid transparent; padding: 7px 4px; cursor: pointer; color: var(--muted); }
.seg button.active { color: var(--text); border-bottom-color: var(--text); }
.f { display: flex; flex-direction: column; gap: 4px; color: var(--muted); margin-bottom: 10px; font-size: 12px; }
.f input[type=number] { width: 100%; }
.f2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chk span { display: flex; align-items: center; gap: 4px; }
.chk input[type=checkbox] { margin: 0; }
.rr { font-size: 12px; color: var(--muted); min-height: 16px; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.msg { min-height: 16px; font-size: 12px; color: var(--sell); }

/* ---------------------------------------------------------------- dialogs */
.dlg { background: var(--panel); color: var(--text); border: none; border-radius: 6px; padding: 0; width: min(800px, calc(100vw - 32px)); max-height: 82vh; box-shadow: 0 6px 30px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(19,23,34,.35); }
.dlgHead { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 16px; }
.dlgBody { padding: 14px 16px; overflow: auto; max-height: calc(82vh - 56px); }
.indBody { display: grid; grid-template-columns: 1fr 1.3fr; gap: 16px; }
.indBody h4 { margin: 0 0 8px; color: var(--muted); font-weight: 400; }
#indSearch { width: 100%; margin-bottom: 6px; }
.indList { display: flex; flex-direction: column; max-height: 56vh; overflow: auto; }
.indList button { text-align: left; background: none; border: none; padding: 7px 8px; border-radius: 4px; cursor: pointer; }
.indList button:hover { background: var(--hover); }
.indList button small { color: var(--muted); margin-left: 6px; }
.indItem { border: 1px solid var(--line); border-radius: 5px; padding: 8px; margin-bottom: 8px; }
.indItem .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.indItem .params { display: flex; flex-wrap: wrap; gap: 6px; }
.indItem label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 2px; }
.indItem input[type=number] { width: 72px; }
.indItem input[type=color], .sessRow input[type=color] { width: 32px; height: 28px; padding: 1px; }
.sessRow { display: grid; grid-template-columns: 24px 1fr 46px 160px 70px 70px 36px 36px; gap: 8px; align-items: center; margin-bottom: 6px; }
.sessRow .hhmm { text-align: center; font-variant-numeric: tabular-nums; }
.sessOpts { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 12px; align-items: center; }
.sessOpts label { display: flex; gap: 6px; align-items: center; }
.sessOpts select { max-width: 100%; }
.sessRow.head { margin-bottom: 2px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(30px); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 4px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 1000px) {
  body { overflow: auto; height: auto; }
  .topbar { height: auto; flex-wrap: wrap; padding: 4px 16px; }
  .topbar .tbtn span { display: none; }
  .group.right { margin-left: 0; flex-wrap: wrap; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .tools { flex-direction: row; border-right: none; border-bottom: 4px solid var(--panel2); padding: 2px 16px; }
  .tools .grow { display: none; }
  .tsep { width: 1px; height: 24px; }
  .chartWrap { min-height: 62vh; }
  .side { border-left: none; border-top: 4px solid var(--panel2); }
  .statsWrap { grid-template-columns: 1fr; }
  .indBody { grid-template-columns: 1fr; }
  .sessRow { grid-template-columns: 24px 1fr 1fr 1fr; }
  .accStrip { display: none; }
  .replayBar { bottom: 34px; }
  .rbtn span { display: none; }
  .legend { max-width: calc(100% - 70px); }
  .titleRow { font-size: 13px; }
  #legend .ind { width: auto; flex-wrap: wrap; }
  .clock { display: none; }
  .tabs .panelName { display: none; }
}
