:root {
  --bg: #0e1117; --panel: #161b22; --panel2: #1c232d; --line: #2a323d; --text: #e6edf3; --muted: #8b96a3;
  --green: #26a69a; --red: #ef5350; --blue: #4c8dff; --amber: #f0b429;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.up { color: var(--green); } .down { color: var(--red); }
.spacer { flex: 1; }
input, select, textarea {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 9px; font: inherit; margin-top: 4px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); }
label { display: block; margin: 8px 0; color: var(--muted); font-size: 12px; }
label input, label select, label textarea { color: var(--text); font-size: 13px; }
label.check { display: flex; align-items: center; gap: 8px; margin-top: 26px; }
label.check input { width: auto; margin: 0; }
.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; font: inherit; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.danger { background: #3a1517; border-color: var(--red); color: #ffb4b0; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.wide { width: 100%; padding: 9px; margin-top: 8px; }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.error { color: var(--red); margin-top: 10px; min-height: 18px; }
.ok { color: var(--green); }

/* login */
.login-body { display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: 100%; max-width: 360px; }
.brand { font-weight: 700; letter-spacing: .3px; }
.brand.big { font-size: 22px; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 4px; background: #13324f; color: #8cc4ff; }
.badge.live { background: #5c1215; color: #ffd0cc; animation: pulse 2s infinite; }
.muted-badge { background: #3b2f0c; color: var(--amber); }
@keyframes pulse { 50% { opacity: .6; } }
.kpi { display: flex; flex-direction: column; align-items: flex-end; font-size: 11px; min-width: 70px; }
.kpi b { font-size: 14px; }
.switch { display: flex; align-items: center; gap: 6px; cursor: pointer; margin: 0; color: var(--text); font-size: 13px; }
.switch input { width: 34px; height: 18px; appearance: none; background: var(--line); border-radius: 9px; position: relative; margin: 0; padding: 0; border: 0; cursor: pointer; }
.switch input::after { content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: .15s; }
.switch input:checked { background: var(--green); }
.switch input:checked::after { left: 18px; }
.halt { background: #3a1517; color: #ffb4b0; padding: 6px 14px; display: flex; gap: 12px; align-items: center; }

/* layout */
.layout { display: grid; grid-template-columns: 230px 1fr 280px; grid-template-rows: minmax(380px, 1fr) 260px; gap: 8px; padding: 8px; height: calc(100vh - 56px); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.watch { grid-row: 1 / 3; }
.chart-panel { grid-column: 2; }
.ticket { grid-column: 3; grid-row: 1 / 3; padding: 0 12px 10px; overflow: auto; }
.ticket .panel-head { margin: 0 -12px; }
.bottom { grid-column: 2; }
.small-input { margin: 0; padding: 4px 8px; width: 110px; font-size: 12px; }
.list { overflow: auto; flex: 1; }
.wl-row { display: grid; grid-template-columns: 1fr auto; padding: 7px 10px; border-bottom: 1px solid #1d242d; cursor: pointer; }
.wl-row:hover, .wl-row.sel { background: var(--panel2); }
.wl-row .sym { font-weight: 600; }
.wl-row .px { text-align: right; font-variant-numeric: tabular-nums; }
.wl-row .chg { grid-column: 2; text-align: right; font-size: 11px; }
.wl-row .tag { font-size: 10px; color: var(--amber); }
.chart { flex: 1; min-height: 0; }
.legend { padding: 4px 10px; }
.dot { display: inline-block; width: 10px; height: 3px; margin: 0 4px 2px 8px; vertical-align: middle; }
.dot.ema20 { background: #f0b429; } .dot.ema50 { background: #b37feb; }
.ltp { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { background: transparent; color: var(--muted); border: 0; padding: 5px 10px; cursor: pointer; font: inherit; }
.seg button.on { background: var(--panel2); color: var(--text); }
.seg.full { display: flex; margin-top: 10px; }
.seg.full button { flex: 1; padding: 8px; }
.seg button.buy.on { background: var(--green); color: #fff; }
.seg button.sell.on { background: var(--red); color: #fff; }
.riskline { background: var(--bg); border-radius: 6px; padding: 8px; margin-top: 6px; font-size: 12px; }
.note { margin-top: 10px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 6px; flex-wrap: wrap; }
.tabs button { background: transparent; border: 0; color: var(--muted); padding: 9px 12px; cursor: pointer; font: inherit; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--text); border-bottom-color: var(--blue); }
.pill { background: var(--panel2); border-radius: 8px; padding: 0 6px; font-size: 11px; }
.tab { overflow: auto; flex: 1; padding: 6px 8px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11px; padding: 5px 6px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
td { padding: 6px; border-bottom: 1px solid #1d242d; white-space: nowrap; }
td.num, th.num { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.empty { color: var(--muted); padding: 18px; text-align: center; }
.log { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.log div { padding: 2px 0; border-bottom: 1px solid #1a2028; }
.log .trade { color: #9be7c4; } .log .loss, .log .error { color: #ffb4b0; }
.side-BUY { color: var(--green); font-weight: 600; } .side-SELL { color: var(--red); font-weight: 600; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 0; width: min(720px, calc(100vw - 32px)); max-height: 90vh; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.dlg-body { padding: 4px 16px 16px; }
.dlg h3 { margin: 18px 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.small-dlg { max-width: 360px; }
dialog:has(.small-dlg) { width: min(360px, calc(100vw - 32px)); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; z-index: 10; max-width: calc(100vw - 32px); }
.toast.err { border-color: var(--red); color: #ffb4b0; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 200px 1fr; grid-template-rows: 420px auto auto; height: auto; }
  .watch { grid-row: 1; } .chart-panel { grid-column: 2; grid-row: 1; }
  .ticket { grid-column: 1; grid-row: 2; } .bottom { grid-column: 2; grid-row: 2; min-height: 300px; }
}
@media (max-width: 720px) {
  .topbar { padding: 8px 16px; }
  .kpi { min-width: 0; }
  .layout { display: flex; flex-direction: column; padding: 8px 16px; }
  .watch { max-height: 220px; } .chart-panel { height: 380px; flex: none; }
  .bottom { min-height: 300px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
}
