:root {
  --bg: #0b0f17;
  --bg2: #0f1420;
  --card: #131a28;
  --card2: #182134;
  --line: #222c40;
  --text: #e7eaf2;
  --muted: #8c95ab;
  --faint: #5d667c;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, .14);
  --up: #22c55e;
  --up-soft: rgba(34, 197, 94, .14);
  --down: #f05252;
  --down-soft: rgba(240, 82, 82, .14);
  --warn: #f5a524;
  --warn-soft: rgba(245, 165, 36, .14);
  --radius: 16px;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 8px 24px rgba(0, 0, 0, .25);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f6fb; --bg2: #eef1f8; --card: #ffffff; --card2: #f6f8fc; --line: #e3e7f0;
    --text: #141a26; --muted: #5f6b82; --faint: #98a1b5; --accent: #3366ff;
    --accent-soft: rgba(51, 102, 255, .10); --up: #12a150; --up-soft: rgba(18, 161, 80, .10);
    --down: #dc3545; --down-soft: rgba(220, 53, 69, .10); --warn: #c77c00; --warn-soft: rgba(199, 124, 0, .12);
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 18px rgba(16, 24, 40, .06);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
[hidden] { display: none !important; }

/* ---------- вход ---------- */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 50% -20%, var(--accent-soft), transparent 60%), var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 10px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.logo { width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); display: grid; place-items: center; }
.field {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--text); font-size: 16px; outline: none;
}
.field:focus { border-color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2);
  font-weight: 600; font-size: 14px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--down); border-color: var(--down-soft); background: var(--down-soft); }
.btn.block { width: 100%; margin-top: 12px; padding: 13px; font-size: 15px; }
.btn:disabled { opacity: .55; cursor: default; }
.error { color: var(--down); font-size: 14px; min-height: 20px; margin-top: 10px; }

/* ---------- каркас ---------- */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.top .spacer { flex: 1; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; white-space: nowrap;
  background: var(--accent-soft); color: var(--accent);
}
.badge.live { background: var(--down-soft); color: var(--down); }
.badge.demo { background: var(--warn-soft); color: var(--warn); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.ok { background: var(--up); box-shadow: 0 0 0 4px var(--up-soft); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); }
.dot.bad { background: var(--down); box-shadow: 0 0 0 4px var(--down-soft); }

main { max-width: 1180px; margin: 0 auto; padding: 14px 16px calc(92px + env(safe-area-inset-bottom)); }
.grid { display: grid; gap: 14px; }
@media (min-width: 900px) {
  .grid.two { grid-template-columns: 1.35fr 1fr; align-items: start; }
}
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card h2 { margin: 0 0 12px; font-size: 15px; font-weight: 650; display: flex; align-items: center; gap: 4px 10px; flex-wrap: wrap; }
.card h2 .count { color: var(--muted); font-weight: 500; margin-left: 6px; }
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.chart-head h2 { margin: 0; }
.card h2 .right { margin-left: auto; font-weight: 500; font-size: 12.5px; color: var(--muted); }
.section-title { margin: 22px 2px 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }

/* ---------- главная цифра ---------- */
.hero { padding: 18px 16px 16px; }
.hero .label { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.hero .equity { font-size: clamp(32px, 9vw, 44px); font-weight: 750; letter-spacing: -.8px; margin: 2px 0 2px; }
.hero .equity small { font-size: 16px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.hero .change { font-size: 15px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  padding: 6px 10px; border-radius: 10px; background: var(--card2); border: 1px solid var(--line);
  font-size: 13px; display: inline-flex; gap: 6px;
}
.chip b { font-weight: 650; }
.notice {
  margin-top: 12px; padding: 10px 12px; border-radius: 12px; font-size: 13.5px;
  background: var(--warn-soft); color: var(--warn); border: 1px solid transparent;
}
.notice.bad { background: var(--down-soft); color: var(--down); }

/* ---------- график ---------- */
.seg { display: inline-flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.seg button {
  border: 0; background: none; padding: 6px 11px; border-radius: 8px; font-size: 13px; color: var(--muted); font-weight: 600;
}
.seg button.on { background: var(--card2); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.chart-wrap { position: relative; margin-top: 10px; touch-action: pan-y; }
.chart-wrap svg { display: block; width: 100%; overflow: visible; }
.tip {
  position: absolute; top: 0; pointer-events: none; transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 9px;
  font-size: 12.5px; white-space: nowrap; box-shadow: var(--shadow);
}
.axis { fill: var(--faint); font-size: 11px; }
.empty { color: var(--muted); font-size: 14px; padding: 18px 4px; text-align: center; }

/* ---------- показатели ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 13px; min-width: 0; }
.kpi .k { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.kpi .v { font-size: 19px; font-weight: 700; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { color: var(--faint); font-size: 12px; margin-top: 1px; }
.meter { height: 6px; border-radius: 99px; background: var(--bg2); margin-top: 8px; overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }

/* ---------- позиции ---------- */
.pos { border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: var(--card2); }
.pos + .pos { margin-top: 10px; }
.pos .row1 { display: flex; align-items: center; gap: 8px; }
.pos .sym { font-weight: 700; font-size: 16px; }
.side { font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 6px; letter-spacing: .4px; }
.side.long { background: var(--up-soft); color: var(--up); }
.side.short { background: var(--down-soft); color: var(--down); }
.pos .pnl { margin-left: auto; text-align: right; font-weight: 700; }
.pos .pnl small { display: block; font-weight: 500; font-size: 12px; }
.pos .meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 10px; margin-top: 10px; font-size: 12.5px; }
.pos .meta div span { display: block; color: var(--muted); font-size: 11.5px; }
.stopbar { position: relative; height: 6px; border-radius: 99px; background: var(--bg); margin-top: 10px; }
.stopbar i { position: absolute; top: -3px; width: 2px; height: 12px; border-radius: 2px; }

/* ---------- таблицы и списки ---------- */
.list { display: flex; flex-direction: column; }
.li { display: flex; align-items: center; gap: 10px; padding: 11px 2px; border-bottom: 1px solid var(--line); min-width: 0; }
.li:last-child { border-bottom: 0; }
.li .main { min-width: 0; flex: 1; }
.li .t1 { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.li .t2 { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.li .end { text-align: right; white-space: nowrap; font-weight: 650; }
.li .end small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.regime { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.regime.trend_up { background: var(--up-soft); color: var(--up); }
.regime.trend_down { background: var(--down-soft); color: var(--down); }
.regime.weak_up, .regime.weak_down, .regime.range { background: var(--card2); color: var(--muted); border: 1px solid var(--line); }
.regime.storm { background: var(--warn-soft); color: var(--warn); }
.regime.warmup { background: var(--card2); color: var(--faint); }
.fbar { position: relative; height: 6px; width: 92px; border-radius: 99px; background: var(--bg2); flex: none; }
.fbar::after { content: ""; position: absolute; left: 50%; top: -2px; width: 1px; height: 10px; background: var(--faint); }
.fbar i { position: absolute; top: 0; height: 100%; border-radius: 99px; }
.ev { font-size: 13.5px; padding: 9px 2px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; }
.ev:last-child { border-bottom: 0; }
.ev time { color: var(--faint); font-size: 12px; white-space: nowrap; padding-top: 1px; min-width: 76px; }
.ev.warn { color: var(--warn); }
.ev.error { color: var(--down); }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 6px; border-bottom: 1px solid var(--line); }
table.t td { padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.t td.r, table.t th.r { text-align: right; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.months { display: grid; grid-template-columns: 44px repeat(12, minmax(30px, 1fr)) 58px; gap: 3px; font-size: 11.5px; min-width: 560px; }
.months div { padding: 6px 2px; border-radius: 6px; text-align: center; }
.months .h { color: var(--muted); font-weight: 600; }
.bars .b { display: grid; grid-template-columns: 70px 1fr 74px; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; }
.bars .track { position: relative; height: 10px; }
.bars .track::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--line); }
.bars .track i { position: absolute; top: 0; height: 100%; border-radius: 3px; }
.cmp { display: grid; grid-template-columns: 1fr auto auto; gap: 8px 14px; font-size: 13.5px; align-items: center; }
.cmp .h { color: var(--muted); font-size: 12px; font-weight: 600; }

/* ---------- отчёты ---------- */
.review { border: 1px solid var(--line); border-radius: 14px; background: var(--card2); }
.review + .review { margin-top: 10px; }
.review > button { width: 100%; text-align: left; background: none; border: 0; padding: 13px; display: flex; gap: 10px; align-items: flex-start; }
.review .vd { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; }
.vd.ok { background: var(--up); } .vd.warn { background: var(--warn); } .vd.alert { background: var(--down); }
.review .body { padding: 0 14px 14px; font-size: 14px; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3 { font-size: 15px; margin: 14px 0 6px; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 20px; }
.md code { font-family: var(--mono); font-size: 12.5px; background: var(--bg2); padding: 1px 5px; border-radius: 5px; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 13px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; font-size: 13.5px; }
.kv div:nth-child(odd) { color: var(--muted); }

/* ---------- нижняя навигация ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  background: none; border: 0; padding: 9px 2px 8px; display: flex; flex-direction: column; align-items: center;
  gap: 3px; font-size: 11px; color: var(--muted); font-weight: 600;
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button.on { color: var(--accent); }
@media (min-width: 900px) {
  .tabbar { left: 50%; right: auto; transform: translateX(-50%); bottom: 14px; border-radius: 18px; border: 1px solid var(--line); width: 560px; box-shadow: var(--shadow); padding-bottom: 0; }
  main { padding-bottom: 110px; }
}
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 12px;
  box-shadow: var(--shadow); font-size: 14px; z-index: 40; max-width: calc(100% - 32px);
}
dialog {
  border: 1px solid var(--line); border-radius: 18px; background: var(--card); color: var(--text);
  padding: 20px; max-width: 360px; width: calc(100% - 32px); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h3 { margin: 0 0 8px; }
dialog p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
dialog .row { display: flex; gap: 10px; justify-content: flex-end; }
