:root {
  --bg: #0b0e13;
  --panel: #12161d;
  --panel-2: #181d26;
  --line: #232a36;
  --text: #e6e9ef;
  --muted: #8a93a3;
  --gold: #e3b341;
  --green: #2fbf71;
  --red: #f0524f;
  --amber: #f2a93b;
  --blue: #4c9aff;
  --violet: #a78bfa;
  --hl: rgba(227, 179, 65, 0.14);
  --radius: 10px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  min-height: 100vh;
}
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.r, .tbl th.r, .tbl td.r { text-align: right; }
h2 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; margin: 0; color: var(--muted); font-weight: 600; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 16px; background: rgba(11, 14, 19, .96);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.sym { font-weight: 700; color: var(--gold); font-size: 18px; letter-spacing: .04em; }
.quote, .status { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.q { display: flex; flex-direction: column; }
.q label, .kv label, .cfg label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.big { font-size: 20px; font-weight: 600; }
#bid { color: var(--red); }
#ask { color: var(--green); }
.status { margin-left: auto; }
.acct { color: var(--muted); font-size: 12px; }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600;
  letter-spacing: .05em; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap;
}
.pill.muted { color: var(--muted); }
.pill.ok { color: var(--green); border-color: rgba(47,191,113,.4); }
.pill.warn { color: var(--amber); border-color: rgba(242,169,59,.4); }
.pill.bad { color: var(--red); border-color: rgba(240,82,79,.4); }
.pill.info { color: var(--blue); border-color: rgba(76,154,255,.4); }
.pill.gold { color: var(--gold); border-color: rgba(227,179,65,.45); }

.health { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.health i { width: 9px; height: 9px; border-radius: 50%; background: var(--red); box-shadow: 0 0 8px var(--red); }
.health.ok i { background: var(--green); box-shadow: 0 0 8px var(--green); }

.btn {
  font: inherit; font-weight: 600; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); padding: 6px 12px; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible, input:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.btn.danger { background: #3a1214; border-color: #6d1f22; color: #ffb4b2; }
.btn.danger:hover { background: #561a1d; }
.big-btn { padding: 10px 18px; font-size: 14px; letter-spacing: .05em; background: #b3261e; color: #fff; border-color: #e0443b; }
.big-btn:hover { background: #d03128; }
.big-btn.confirm { background: #fff; color: #b3261e; animation: pulse .6s infinite alternate; }
@keyframes pulse { to { box-shadow: 0 0 18px rgba(240,82,79,.8); } }

/* ---------- tabs + layout ---------- */
.tabs {
  position: sticky; top: var(--topbar-h, 62px); z-index: 9; display: flex; gap: 4px; overflow-x: auto;
  padding: 0 16px; background: rgba(11, 14, 19, .96); border-bottom: 1px solid var(--line); scrollbar-width: none;
}
.tabs button {
  font: inherit; font-weight: 600; font-size: 13px; color: var(--muted); background: none; border: 0;
  border-bottom: 2px solid transparent; padding: 11px 12px 9px; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--gold); border-bottom-color: var(--gold); }
.tabs button:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.tabs .tab-right { margin-left: auto; }
.tab-count { font: 600 11px var(--mono); background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; color: var(--muted); }
.tab-count.on { color: var(--bg); background: var(--blue); border-color: var(--blue); }
.tab-dot { width: 7px; height: 7px; border-radius: 50%; background: transparent; }
.tab-dot.gold { background: var(--gold); box-shadow: 0 0 6px var(--gold); }
.tab-dot.ok { background: var(--green); }
.tab-dot.bad { background: var(--red); box-shadow: 0 0 6px var(--red); }

main { padding: 14px 16px 40px; }
.panel { display: flex; flex-direction: column; gap: 14px; }
.panel[hidden] { display: none; }
.row { display: grid; gap: 14px; }
.row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1100px) { .row.two { grid-template-columns: minmax(0, 1fr); } }

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi small { color: var(--muted); font-size: 12px; min-height: 1em; }
.kpi .pill { align-self: flex-start; white-space: normal; }
.kpi .big { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }

/* ---------- tokyo ---------- */
.kv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.kv-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.range-bar { position: relative; height: 6px; background: var(--panel-2); border-radius: 999px; margin-top: 14px; overflow: hidden; }
.rb-fill { height: 100%; width: 0; background: var(--green); border-radius: 999px; transition: width .3s; }
.rb-fill.over { background: var(--red); }
.rb-max { position: absolute; top: -2px; bottom: -2px; left: 80%; width: 2px; background: var(--amber); }
.steps { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 6px; counter-reset: st; }
.steps li { counter-increment: st; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.steps li::before { content: counter(st); flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font: 600 11px var(--mono); border: 1px solid var(--line); background: var(--panel-2); }
.steps li.done { color: var(--text); }
.steps li.done::before { content: "✓"; background: rgba(47,191,113,.15); border-color: rgba(47,191,113,.5); color: var(--green); }
.steps li.cur { color: var(--gold); font-weight: 600; }
.steps li.cur::before { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 8px rgba(227,179,65,.4); }
.steps li.fail { color: var(--red); }
.steps li.fail::before { content: "✕"; border-color: var(--red); color: var(--red); }
.kv { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.kv small { color: var(--muted); font-size: 12px; }
.inline { display: flex; align-items: center; gap: 6px; }
.unit { color: var(--muted); font-size: 12px; }
.note { color: var(--muted); font-size: 12px; margin: 10px 0 0; min-height: 1em; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.near td { background: var(--hl); }
.tbl tr.near td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
.tbl tr.empty td { color: var(--muted); text-align: center; padding: 18px; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.lvl-key { font-family: var(--mono); font-weight: 600; color: var(--gold); }
.gold-t { color: var(--gold); font-weight: 600; }
.block { display: block; }
.inst-grid td { vertical-align: top; }
.inst-grid td small { font-size: 11px; }
.inst-grid td.near-cell { background: var(--hl); box-shadow: inset 0 -2px 0 var(--gold); }
.link { color: var(--blue); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ---------- strategy deck ---------- */
.cfg { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; margin-bottom: 12px; }
.cfg.wide { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
.rules, .help ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; display: grid; gap: 4px; }
.rules b, .help b { color: var(--text); }
.help h2 { margin-bottom: 6px; }
.cfg label { display: flex; flex-direction: column; gap: 4px; }
input[type=number], input[type=text], input[type=password] {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; font: 13px var(--mono);
}
input.saved { border-color: var(--green); transition: border-color .2s; }
input.error { border-color: var(--red); }
.level-row {
  display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 8px;
}
.level-row.on { border-color: rgba(47,191,113,.45); }
.level-row .name { font-weight: 600; font-size: 12px; letter-spacing: .04em; }
.level-row .name.buy { color: var(--green); }
.level-row .name.sell { color: var(--red); }
.level-row .sub { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }

.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: #2a313d; border-radius: 999px; cursor: pointer; transition: background .15s; }
.switch span::after { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: #c9cfda; transition: transform .15s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(20px); background: #fff; }
.switch input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- log ---------- */
.log-list { list-style: none; margin: 0; padding: 0; max-height: 560px; overflow-y: auto; font: 12px/1.6 var(--mono); }
.log-list.compact { max-height: 300px; }
.log-list li { display: grid; grid-template-columns: 150px 130px minmax(0, 1fr); gap: 10px; padding: 3px 4px; border-bottom: 1px solid rgba(35,42,54,.6); }
.log-list.compact li { grid-template-columns: 70px 120px minmax(0, 1fr); }
.log-list.compact .t { overflow: hidden; direction: rtl; text-align: left; white-space: nowrap; }
.log-list li.empty-li { display: block; color: var(--muted); text-align: center; padding: 16px; font-family: inherit; }
.log-list .t { color: var(--muted); }
.log-list .k { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.log-list .m { white-space: normal; overflow-wrap: anywhere; }
.k-fill, .k-order { color: var(--green); }
.k-touch, .k-retest { color: var(--gold); }
.k-auto { color: var(--violet); }
.k-breakout, .k-tokyo, .k-closed { color: var(--blue); }
.k-timer, .k-warn { color: var(--amber); }
.k-error, .k-panic, .k-failed { color: var(--red); }
#logSearch { width: 180px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 600 12px Inter, system-ui, sans-serif; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 11px; cursor: pointer; }
.chip:hover { color: var(--text); }
.chip.on { color: var(--gold); border-color: rgba(227,179,65,.5); }
.chip small { color: var(--muted); font-weight: 400; font-family: var(--mono); }

/* ---------- health / forms / telegram ---------- */
.health-list { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 7px 16px; margin: 0; font-size: 13px; }
.health-list dt { color: var(--muted); }
.health-list dd { margin: 0; font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.form { display: grid; gap: 14px; }
.form > label { display: grid; gap: 5px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.form > label small { text-transform: none; letter-spacing: 0; }
.form .inline input { flex: 1; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0; display: grid; gap: 8px; }
legend { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 0 4px; }
.check { display: flex; align-items: baseline; gap: 8px; cursor: pointer; flex-wrap: wrap; }
.check input { accent-color: var(--gold); width: 15px; height: 15px; transform: translateY(2px); }
.check small { color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.primary { background: var(--gold); color: #1a1405; border-color: var(--gold); }
.btn.primary:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .55; cursor: default; }
.sub-h { margin: 18px 0 8px; }
.setup { margin: 0; padding-left: 20px; display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.setup b { color: var(--text); }
code { font-family: var(--mono); background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.bubbles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); align-items: start; }
.bubble { position: relative; background: #1e2733; border: 1px solid #2b3747; border-radius: 12px 12px 12px 4px; padding: 10px 12px 20px;
  font: 12.5px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble b { font-family: Inter, system-ui, sans-serif; font-size: 13px; }
.bubble-t { position: absolute; right: 10px; bottom: 4px; font-size: 10.5px; color: var(--muted); }

@media (max-width: 700px) {
  .log-list li, .log-list.compact li { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .topbar { gap: 12px; }
  .status { margin-left: 0; }
  .kv-grid, .kv-grid.three { grid-template-columns: minmax(0, 1fr); }
  .card-head { flex-wrap: wrap; }
  #logSearch { width: 100%; }
}

#toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: all .2s; max-width: min(640px, calc(100vw - 32px)); z-index: 20;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { border-color: var(--red); color: #ffb4b2; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 24px; }
.login-brand { display: flex; flex-direction: column; gap: 2px; margin-bottom: 20px; }
.login-brand .sym { font-size: 22px; }
.login-btn { padding: 10px; font-size: 14px; }
.login-err { color: var(--red); min-height: 1.2em; margin: 0; font-size: 13px; }

/* ---------- session range ---------- */
.sess-controls { display: flex; flex-wrap: wrap; gap: 18px 32px; margin-bottom: 14px; }
.sess-wins { display: grid; gap: 8px; }
.sess-wins label { display: grid; grid-template-columns: 90px auto; align-items: center; gap: 10px; font-size: 13px; }
.sess-wins .inline { color: var(--muted); }
input[type=time] { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 6px;
  padding: 6px 8px; font: 13px var(--mono); color-scheme: dark; }
.sess-opts { display: grid; gap: 10px; align-content: start; }
.opt-label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 5px; }
#sessForm > small { display: block; margin-top: 10px; }
.sess-name { font-weight: 600; }
.sess-name.tokyo { color: var(--violet); }
.sess-name.london { color: var(--blue); }
.sess-name.ny { color: var(--gold); }
.sess-tbl td.sess-cell { min-width: 140px; }
.sess-val.over { color: var(--red); }
.sess-bar { height: 4px; background: var(--panel-2); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.sess-bar i { display: block; height: 100%; margin-left: auto; border-radius: 2px; opacity: .8; }
.sess-bar.tokyo i { background: var(--violet); }
.sess-bar.london i { background: var(--blue); }
.sess-bar.ny i { background: var(--gold); }
#sessKpis .kpi label { text-transform: none; letter-spacing: 0; }
