:root {
  --bg: #12201A;
  --surface: #192C24;
  --surface-2: #203A2F;
  --line: #2C4A3C;
  --ink: #E9EFE3;
  --muted: #8FA597;
  --profit: #7CD992;
  --loss: #F0806F;
  --amber: #F2B84B;
  --amber-ink: #2A1F05;
  --radius: 10px;
  --pad: 14px;
  --font: "IBM Plex Sans", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
button, input { font: inherit; color: inherit; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92em; background: var(--surface-2); padding: 0 4px; border-radius: 4px; }
h2 { font-size: 20px; font-weight: 600; margin: 4px 0 12px; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

.app { max-width: 560px; margin: 0 auto; padding: 0 12px; }

/* шапка ---------------------------------------------------------------- */
.top {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  position: sticky; top: 0; background: var(--bg); z-index: 5;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.top-right { flex: none; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: .01em; }
.brand-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--profit); }
.dot.bad { background: var(--loss); }
.dot.wait { background: var(--amber); }
.top-right { text-align: right; }
.acct { font-weight: 600; font-size: 15px; white-space: nowrap; }
.acct small { display: block; color: var(--muted); font-size: 11px; font-weight: 400; }
.day { font-size: 12px; color: var(--muted); margin-top: 2px; }
.day.pos { color: var(--profit); }
.day.neg { color: var(--loss); }

.banner { margin: 10px 0 0; padding: 10px 12px; border-radius: var(--radius); font-weight: 500; }
.banner-brake { background: #3A1F1B; color: #FFD9D2; border: 1px solid #6B2F27; }
.banner-warn { background: #3A3118; color: #FFE9B8; border: 1px solid #6B5A2A; }

/* функции --------------------------------------------------------------- */
.funcs { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.func {
  display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px 8px 8px;
}
.func.on { border-color: var(--amber); }
.func-main { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 4px; text-align: left; cursor: pointer; min-height: 44px; min-width: 0; }
.func-icon { font-size: 20px; width: 28px; text-align: center; flex: none; }
.func-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.func-text b { font-weight: 600; }
.func-text small { color: var(--muted); font-size: 12px; }
.func-status { color: var(--muted); font-size: 12px; }
.func.on .func-status { color: var(--ink); }
.func-toggle { font-weight: 600; font-size: 13px; padding: 6px 12px; min-height: 36px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); cursor: pointer; }
.func-toggle[aria-pressed="true"] { background: var(--amber); color: var(--amber-ink); border-color: var(--amber); }
.gauge { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 4px 4px 2px; }
.gauge-bar { position: relative; flex: 1; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.gauge-bar i { display: block; height: 100%; background: var(--profit); border-radius: 4px; transition: width .3s; }
.gauge-bar i.warm { background: var(--amber); }
.gauge-bar i.hot { background: #F2904B; }
.gauge-bar i.crit { background: var(--loss); }
.gauge-bar s { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); opacity: .6; text-decoration: none; }
.gauge-text { font-size: 12px; color: var(--muted); white-space: nowrap; }
.func-actions { grid-column: 1 / -1; padding: 4px; }
.btn-small { min-height: 36px; font-size: 13px; }

/* лист настроек функции */
.sheet-form { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; max-height: 55vh; overflow-y: auto; }
.f-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 2px 0; font-size: 14px; }
.f-row input, .f-row select { width: 170px; max-width: 50%; }
.f-row.f-check input { width: 22px; height: 22px; min-height: 0; }
.f-hint { color: var(--muted); font-size: 12px; margin: -2px 0 4px; }
select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-height: 44px; color: var(--ink); }

/* сделки --------------------------------------------------------------- */
.positions { display: flex; flex-direction: column; gap: 12px; }
.pos {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px var(--pad) 12px; border-left: 4px solid var(--muted);
}
.pos.profit { border-left-color: var(--profit); }
.pos.loss { border-left-color: var(--loss); }
.pos-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pos-sym { font-weight: 600; font-size: 15px; }
.pos-side { font-weight: 600; margin-left: 6px; }
.pos-side.buy { color: var(--profit); }
.pos-side.sell { color: var(--loss); }
.pos-lots { color: var(--muted); margin-left: 6px; }
.pos-age { color: var(--muted); font-size: 12px; white-space: nowrap; }
.pos-pnl { display: flex; align-items: baseline; gap: 12px; margin: 4px 0 6px; }
.pnl-pips { font-size: 34px; font-weight: 700; line-height: 1.1; letter-spacing: -.01em; }
.pnl-pips small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.pnl-money { font-size: 15px; color: var(--muted); }
.profit .pnl-pips, .profit .pnl-money { color: var(--profit); }
.loss .pnl-pips, .loss .pnl-money { color: var(--loss); }
.pos-lines { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.pos-lines b { color: var(--ink); font-weight: 500; }
.pos-lines .lock { color: var(--amber); }

.btns { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 6px; }
.btns-2 { grid-template-columns: 1fr 1fr; margin-bottom: 0; }
.btn {
  min-height: 44px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); font-weight: 600; font-size: 15px;
  padding: 0 10px; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--amber); color: var(--amber-ink); border-color: var(--amber); }
.btn-danger { background: transparent; color: var(--loss); border-color: #6B2F27; }
.btn-danger-ghost { background: transparent; color: var(--muted); border-color: var(--line); margin-top: 8px; }
.btn.busy { opacity: .6; pointer-events: none; }
.btn:focus-visible, .lever:focus-visible, .tab:focus-visible, input:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

.empty { text-align: center; padding: 40px 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row .btn { flex: 1; }
.row input { flex: 2; }

/* журнал --------------------------------------------------------------- */
.log { list-style: none; margin: 0; padding: 0; }
.log li { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; display: flex; gap: 10px; }
.log time { color: var(--muted); flex: none; font-size: 13px; }
.log .k-action { color: var(--ink); }
.log .k-ladder { color: var(--amber); }
.log .k-error { color: var(--loss); }
.log .k-info { color: var(--muted); }

/* настройки ------------------------------------------------------------ */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
label { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 8px 0; font-size: 14px; }
input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-height: 44px; color: var(--ink); width: 100%; max-width: 220px; }
.row input { max-width: none; }
.kv { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.kv b { color: var(--ink); font-weight: 500; }
.accounts { list-style: none; padding: 0; margin: 8px 0; }
.accounts li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.accounts .btn { min-height: 36px; font-size: 13px; flex: none; }
.accounts .sel { color: var(--amber); font-weight: 600; }

/* вкладки -------------------------------------------------------------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: var(--bg); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.tab { flex: 1; max-width: 190px; text-align: center; padding: 14px 0 12px; color: var(--muted); text-decoration: none; font-weight: 500; }
.tab.active { color: var(--amber); box-shadow: inset 0 2px 0 var(--amber); }

/* подтверждение -------------------------------------------------------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet { width: 100%; max-width: 560px; background: var(--surface); border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet h3 { font-size: 17px; }
.sheet p { color: var(--ink); margin-bottom: 14px; }
@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: up .18s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
}

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom));
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; max-width: 92vw; font-size: 14px; z-index: 15; box-shadow: 0 6px 20px rgba(0,0,0,.35);
}
.toast.err { border-color: var(--loss); color: #FFD9D2; }

@media (min-width: 600px) {
  .btns { gap: 8px; }
  .pnl-pips { font-size: 38px; }
}

.pos-tag { margin-left: 8px; font-size: 12px; color: var(--muted, #9aa); background: rgba(255,255,255,.06); padding: 2px 7px; border-radius: 999px; }

.prefs { display: grid; gap: 8px; margin: 12px 0 4px; }
.prefs label { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.prefs input { width: 20px; height: 20px; accent-color: var(--amber); }
