/* Trading bot PWA — light dashboard theme (gray / white / orange).
   Mobile-first; sidebar nav on desktop, bottom tab bar on mobile. */
:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #111827;
  --muted: #6b7280;
  --border: #e7e9ee;
  --accent: #f97316;
  --accent-600: #ea580c;
  --accent-weak: #fff3ea;
  --ok: #16a34a;
  --ok-weak: #e7f6ec;
  --bad: #dc2626;
  --bad-weak: #fdeaea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.05), 0 1px 3px rgba(17, 24, 39, 0.06);
  --sidebar-w: 240px;
  --topbar-bg: rgba(255, 255, 255, 0.9);
  --skel-a: #eceef1;
  --skel-b: #f4f5f7;
  --switch-off: #cbd0d9;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #21252d;
  --text: #e8eaed;
  --muted: #99a1ad;
  --border: #2a2f3a;
  --accent: #fb8b3c;
  --accent-600: #f97316;
  --accent-weak: #2a2118;
  --ok: #34d399;
  --ok-weak: #14271f;
  --bad: #f87171;
  --bad-weak: #2a1818;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.4);
  --topbar-bg: rgba(15, 17, 21, 0.85);
  --skel-a: #20242c;
  --skel-b: #2a2f38;
  --switch-off: #3a4150;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }   /* author display:flex must not override the hidden attr */

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  /* A help popover that overruns the right edge must never widen/scroll the whole
     page (left content would get clipped on mobile). Clip horizontal overflow at
     the root scroller; popovers are also width-clamped to the viewport below. */
  overflow-x: hidden;
}
h2 { font-size: 16px; font-weight: 650; margin: 0; }

.layout { display: flex; min-height: 100vh; }

/* --- Sidebar (desktop) --- */
.sidebar { display: none; }
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px; font-weight: 700; font-size: 18px; }
.brand__mark { width: 28px; height: 28px; display: inline-flex; flex: none; }
.brand__mark .logo-svg { width: 100%; height: 100%; display: block; border-radius: 7px; }
.nav { display: flex; flex-direction: column; gap: 4px; padding: 6px 12px; }
.nav__item {
  display: flex; align-items: center; gap: 12px;
  border: none; background: transparent; color: var(--muted);
  font-size: 15px; font-weight: 550; text-align: left;
  padding: 11px 12px; border-radius: 10px; cursor: pointer;
}
.nav__item:hover { background: var(--surface-2); color: var(--text); }
.nav__item--active { background: var(--accent-weak); color: var(--accent-600); }
.nav__item .ico { width: 20px; height: 20px; fill: currentColor; }
.sidebar__foot { margin-top: auto; padding: 16px 18px; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.status-dot.ok { background: var(--ok); }
.status-dot.bad { background: var(--bad); }

/* --- Main column --- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--topbar-bg);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar__title { font-size: 18px; font-weight: 700; }
.topbar__right { display: flex; align-items: center; gap: 14px; }
.equity-mini { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.equity-mini__label { font-size: 11px; color: var(--muted); }
.equity-mini__value { font-size: 15px; font-weight: 700; }

.icon-btn {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  font-size: 18px; line-height: 1; width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
}
.icon-btn:active { background: var(--border); }
.icon-btn.spin { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.content {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 90px);
}

/* --- Views --- */
.view { display: none; flex-direction: column; gap: 14px; }
.view--active { display: flex; }

/* --- Dashboard-local profile bar --- */
.dash-profilebar { display: flex; align-items: center; gap: 10px; }
.dash-profilebar__lbl { color: var(--muted); font-size: 13px; }

/* --- Hero --- */
.hero {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-600) 100%);
  color: #fff; border-radius: 18px; padding: 20px 22px;
  box-shadow: var(--shadow);
}
.hero { flex-wrap: wrap; }
.hero__label { font-size: 13px; opacity: 0.9; }
.hero__value { font-size: 32px; font-weight: 800; margin-top: 4px; letter-spacing: -0.02em; }
.hero__cash { display: flex; flex-direction: column; }
.hero__cashrow { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.hero__cashval { font-size: 22px; font-weight: 750; letter-spacing: -0.01em; }
.hero-warn .help--warn { background: #fff; color: var(--accent-600); font-weight: 800; }
.help--warn { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px;
  border-radius: 50%; font-size: 13px; cursor: help; }
.hero__pnl { font-size: 14px; margin-top: 6px; font-weight: 600; opacity: 0.97; }
.hero__status {
  font-size: 13px; font-weight: 650; padding: 6px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.22); white-space: nowrap;
}
.hero__aside { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; flex: none; }
.profile-sel--hero { background: rgba(255, 255, 255, 0.18); color: #fff; border-color: rgba(255, 255, 255, 0.45); max-width: 180px; }
.profile-sel--hero option { color: var(--text); }

/* --- Price chart --- */
.chart-syms { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 0 auto; justify-content: flex-end; flex: 1 1 auto; min-width: 0; }
.chip-btn { border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 650; padding: 5px 12px; border-radius: 999px; cursor: pointer; }
.chip-btn--active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chart-ctl { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 2px 0 12px; }
.chart-ctl__row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1; }
.chart-ctl__lbl { color: var(--muted); font-size: 12px; }
.chart-wrap { position: relative; }
.chart-lw { width: 100%; height: 240px; }
.chart-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 0 16px; color: var(--muted); font-size: 12px; pointer-events: none; }
.chart-tip { position: absolute; z-index: 5; background: #111827; color: #fff; font-size: 12px; line-height: 1.45;
  padding: 8px 10px; border-radius: 8px; pointer-events: none; max-width: 240px; box-shadow: 0 6px 18px rgba(0,0,0,0.28); }
.chart-tip .mk-head { font-weight: 700; margin-bottom: 4px; }
.chart-tip .mk-row { display: flex; justify-content: space-between; gap: 14px; white-space: nowrap; }
.chart-tip .mk-row + .mk-row { margin-top: 2px; }
.chart-tip .muted { color: #aab2bd; }
.chart-tip .mk-tot { border-top: 1px solid rgba(255,255,255,0.18); margin-top: 5px; padding-top: 4px; }
.chart-iv-note { color: var(--muted); font-size: 12px; margin-left: 4px; }
.metric-sel { background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 14px; max-width: 100%; }
.metric-sel:disabled { opacity: 0.5; }
.metric-leg { display: inline-flex; align-items: center; gap: 5px; }
.metric-leg i { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }
.metric-desc { color: var(--muted); font-size: 12.5px; line-height: 1.45; margin: 8px 2px 2px; }
.chart-ind { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
/* Stack the metric control rows (Показатель / Бумага / Период) full-width instead
   of tiling them like the single-row chart control — otherwise flex:1 rows sit
   side-by-side and the chips scatter. */
.metric-ctl { flex-direction: column; align-items: stretch; }
.metric-ctl .chart-ctl__row { width: 100%; flex: 0 0 auto; }
.metric-ctl .metric-sel { flex: 1 1 100%; }
/* Left-align the ticker chips (and drop the auto left margin) so they share the
   same left edge as the dropdown, description and heading — no ragged gap. */
.metric-ctl .chart-syms { margin: 0; justify-content: flex-start; }
.chart-legend { color: var(--muted); font-size: 12px; margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
/* Generic inline help "?" with a hover/tap tooltip (used across forms + cards). */
.hlp { position: relative; display: inline-flex; vertical-align: middle; }
.hlp-pop { position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 20; width: max-content; max-width: min(260px, calc(100vw - 24px));
  white-space: normal; text-align: left; background: #111827; color: #fff; font-size: 12px; font-weight: 500;
  line-height: 1.5; padding: 9px 11px; border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,0.28); display: none; }
.hlp:hover .hlp-pop, .hlp:focus-within .hlp-pop, .hlp.open .hlp-pop { display: block; }
/* help anchored in a panel head (top-right): drop the tooltip down, right-aligned */
.hlp--head .hlp-pop { bottom: auto; top: calc(100% + 8px); left: auto; right: 0; }
.ph-right { display: flex; align-items: center; gap: 10px; }
@media (max-width: 600px) { .hlp-pop { max-width: min(240px, calc(100vw - 24px)); } }
.legend-help { position: relative; display: inline-flex; }
.legend-tip { position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 6; width: 250px;
  background: #111827; color: #fff; font-size: 12px; line-height: 1.5; padding: 9px 11px; border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.28); display: none; }
/* in the panel head (top-right) the tip drops down and aligns to the right edge */
.legend-help--head .legend-tip { bottom: auto; top: calc(100% + 8px); left: auto; right: 0; }
.legend-help:hover .legend-tip, .legend-help:focus-within .legend-tip { display: block; }
.chart-legend--end { justify-content: flex-end; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: middle; }
.dot--ok { background: var(--ok); } .dot--bad { background: var(--bad); }

/* --- Tiles --- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.tile__label { color: var(--muted); font-size: 12px; }
.tile__value { font-size: 22px; font-weight: 750; margin-top: 4px; }

/* --- Panel --- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel__hint { color: var(--muted); font-size: 12px; }
.panel__actions { display: flex; gap: 10px; margin-top: 14px; }
.panel__actions .btn--primary { margin-left: auto; }

.muted { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* --- Rows (positions + instruments) --- */
.rows { display: flex; flex-direction: column; }
.row-item { border-top: 1px solid var(--border); }
.row-item:first-child { border-top: none; }

.pos { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; }
.pos__sym { font-weight: 650; }
.pos__qty { color: var(--muted); font-size: 13px; margin-top: 2px; }
.pos__val { text-align: right; flex-shrink: 0; white-space: nowrap; }
.pos__cur { color: var(--muted); font-size: 12px; margin: 1px 0 3px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pnl-pos { color: var(--ok); font-weight: 650; }
.pnl-neg { color: var(--bad); font-weight: 650; }
.cash { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); color: var(--muted); font-size: 14px; }

/* instruments toolbar */
.inst-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.inst-search { flex: 1; min-width: 140px; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 9px 12px; font-size: 14px; }
.inst-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.inst-filter { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; cursor: pointer; white-space: nowrap; }
.inst__pos { font-weight: 600; }

/* instrument row + inline editor — CSS Grid keeps the limit column always aligned */
.inst__bar { display: grid; grid-template-columns: 230px 380px auto; align-items: center; gap: 12px; padding: 12px 0; }
.inst__main { cursor: pointer; min-width: 0; }
.inst__lims-col { display: flex; flex-direction: column; gap: 5px; }
.inst__lims-col .inst-lims { margin-top: 0; }
.inst__lims-col .inst-pills { margin-top: 0; }
.inst__right { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
@media (max-width: 560px) {
  .inst__bar { grid-template-columns: 1fr auto; }
  .inst__right { grid-row: 1; grid-column: 2; }
  .inst__lims-col { grid-column: 1 / -1; grid-row: 2; padding-top: 6px; border-top: 1px solid var(--border); }
}
/* Per-instrument status pill (running / exit / paused / sell-only / off) */
.st-pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 650;
  padding: 2px 9px; border-radius: 999px; white-space: nowrap; vertical-align: middle; }
.st-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st--run { color: var(--ok); background: var(--ok-weak); }
.st--exit { color: var(--accent-600); background: var(--accent-weak); }
.st--halt, .st--nobuy { color: #b45309; background: rgba(245, 158, 11, 0.16); }
.st--off { color: var(--muted); background: var(--surface-2); }
.st--lowfunds { color: var(--bad); background: var(--bad-weak); }
.st--closed { color: var(--bad); background: var(--bad-weak); }
.st--closed::before { display: none; }
.st--limit { color: var(--bad); background: var(--bad-weak); }
.st--limit::before { display: none; }
.st--wait { color: #b45309; background: rgba(245, 158, 11, 0.16); }
.st--wait::before { display: none; }
.st--cooldown { color: #64748b; background: rgba(100, 116, 139, 0.16); }
.st--cooldown::before { display: none; }
.st--bull { color: var(--ok); background: var(--ok-weak); }
.st--bull::before { display: none; }
.st--bear { color: var(--bad); background: var(--bad-weak); }
.st--bear::before { display: none; }
.st--neutral { color: #64748b; background: rgba(100, 116, 139, 0.16); }
.st--neutral::before { display: none; }
.st--regime { color: #4f46e5; background: rgba(99, 102, 241, 0.16); }
.st--regime-warn { color: #b45309; background: rgba(245, 158, 11, 0.16); }
.st-pill[tabindex] { cursor: help; }
/* Per-instrument buy-limit usage bar — one full-width row per limit:
   label · flexible bar (grows to fill) · value · "?" (per-row, own tooltip). */
.inst-lims { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.hlp--lims { flex: 0 0 auto; }
.hlp--lims .hlp-pop { bottom: auto; top: calc(100% + 6px); left: auto; right: 0; }
/* Status pills (exchange closed / limit reached) on a full-width wrapping row
   below the symbol — long labels no longer collide with the right-side controls. */
.inst-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.inst-pills:empty { display: none; }
.lim { display: flex; align-items: center; gap: 10px; }
.lim__lbl { flex: 0 0 auto; width: 46px; font-size: 11px; color: var(--muted); }
.lim__bar { flex: 1 1 auto; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.lim__bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.lim__val { flex: 0 0 auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
.lim__val b { color: var(--text); }
.lim--full .lim__bar > span { background: var(--bad); }
.lim--full .lim__val, .lim--full .lim__val b { color: var(--bad); font-weight: 650; }
.lim__top { font-size: 11px; color: var(--muted); }
.lim__tag { color: var(--bad); font-weight: 650; }
.badge-defensive .bd-ico { font-size: 11px; color: var(--accent-600); background: var(--accent-weak);
  padding: 1px 8px; border-radius: 999px; font-weight: 650; margin-left: 8px; cursor: help; }
.stage--defensive { box-shadow: inset 3px 0 0 var(--accent-600); }
:root[data-theme="dark"] .st--halt, :root[data-theme="dark"] .st--nobuy, :root[data-theme="dark"] .st--wait { color: #fbbf24; }
.inst__sym { font-weight: 650; display: flex; align-items: center; gap: 6px; }
.inst__meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.chevron { color: var(--muted); font-size: 11px; transition: transform 0.15s; }
.chevron.open { transform: rotate(180deg); }
.badge-off { font-size: 11px; color: var(--bad); background: var(--bad-weak); padding: 1px 7px; border-radius: 999px; }
.editor { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; align-items: stretch; padding: 4px 0 16px; }
.editor__group { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.editor__danger { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 2px; }
/* Instrument editor — logical setting blocks */
.btn--sm { padding: 7px 14px; font-size: 13px; border-radius: 9px; }
.inst-sec { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 12px 14px; margin: 0;
  display: flex; flex-direction: column; }
.inst-sec__title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin-bottom: 11px; display: flex; align-items: center; gap: 8px; }
.inst-sec__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 12px; margin-bottom: 12px; }
.inst-sec .field input { padding: 8px 10px; font-size: 14px; background: var(--surface); }
.inst-sec > .btn--primary { width: 100%; margin-top: auto; }
.inst-sec__note { font-size: 11px; color: var(--muted); margin-top: 10px; }
.inst-sec__global { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted);
  margin-bottom: 10px; cursor: pointer; user-select: none; }
.inst-sec__global input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.inst-sec--danger { background: transparent; }
.inst-exit__row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inst-exit__row .exit-mode { flex: 1; min-width: 150px; border: 1px solid var(--border);
  color: var(--text); border-radius: 9px; padding: 8px 30px 8px 10px; font-size: 13px; font-weight: 600; cursor: pointer;
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>") no-repeat right 10px center; }
.exit-allowbuy { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 13px; }
.exit-allowbuy label { flex: 1; display: flex; align-items: center; gap: 10px; margin: 0; cursor: pointer; user-select: none; line-height: 1.3; }
.exit-allowbuy .hlp { flex: none; }
.exit-allow { flex: none; -webkit-appearance: none; appearance: none; width: 20px; height: 20px;
  border: 1.5px solid var(--border); border-radius: 6px; background: var(--surface);
  position: relative; cursor: pointer; transition: background .15s, border-color .15s; }
.exit-allow:checked { background: var(--accent); border-color: var(--accent); }
.exit-allow:checked::after { content: ""; position: absolute; left: 6px; top: 2px;
  width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.inst-exit__row .exit-pct { width: 88px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 9px; padding: 8px 10px; font-size: 14px; }
.inst-exit__row .exit-toggle { white-space: nowrap; }
/* Pin the exit button to the bottom of the (stretched) card in BOTH states, so it
   doesn't teleport when the label flips ghost↔primary (.inst-sec > .btn--primary
   already gets margin-top:auto; match it for the ghost "Остановить" too). */
.exit-toggle--block { width: 100%; margin-top: auto; }
.badge-exit { font-size: 11px; color: var(--accent); background: var(--accent-weak); padding: 1px 8px; border-radius: 999px; font-weight: 650; }

/* add-instrument bar */
.inst-add { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.inst-add .btn { white-space: nowrap; }
.inst-add-wrap { margin-bottom: 10px; }
/* Compact "add instrument" pill — sits inside the toolbar, not a bulky bar */
.inst-add-btn { white-space: nowrap; flex: 0 0 auto; margin-left: auto; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--accent);
  background: var(--accent-weak); border: 1px solid transparent; border-radius: 9px; padding: 8px 14px; }
.inst-add-btn:hover { border-color: var(--accent); }
.inst-add-btn[aria-expanded="true"] { background: var(--accent); color: #fff; }
.inst-add-panel { margin-top: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.inst-add-panel .inst-search { width: 100%; }
.inst-add-results { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; max-height: 320px; overflow-y: auto; }
.inst-result { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--surface); cursor: pointer; font: inherit; color: var(--text); }
.inst-result:hover { border-color: var(--accent); background: var(--accent-weak); }
.inst-result--off { opacity: 0.55; }
.inst-result__name { font-weight: 600; font-size: 14px; }
.inst-result__tick { font-size: 12px; color: var(--muted); }
.inst-add-msg { font-size: 13px; margin-bottom: 10px; }
.inst-add-msg.ok { color: var(--ok); }
.inst-add-msg.err { color: var(--bad); }

/* --- Риски и защита: collapsible categories --- */
.risk-cat { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; background: var(--surface); }
.risk-cat > summary { list-style: none; cursor: pointer; padding: 13px 14px; font-weight: 650; font-size: 14px;
  display: flex; align-items: center; gap: 8px; user-select: none; }
.risk-cat > summary::-webkit-details-marker { display: none; }
.risk-cat > summary::after { content: "⌄"; margin-left: auto; color: var(--muted); font-size: 15px; transition: transform .15s; }
.risk-cat[open] > summary::after { transform: rotate(180deg); }
.risk-cat[open] > summary { border-bottom: 1px solid var(--border); }
.risk-cat__body { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
/* Anchor field help popovers to the full-width field (not the right-positioned
   "?"), so long-label tooltips don't run off the screen edge. */
.risk-cat .field { position: relative; }
.risk-cat .field label .hlp { position: static; }
.risk-cat .field .hlp-pop { left: 0; right: auto; max-width: 100%; }
.beta-chip { font-size: 10px; font-weight: 700; letter-spacing: .4px; color: #4f46e5;
  background: rgba(99, 102, 241, 0.16); border-radius: 6px; padding: 2px 6px; }
.risk-beta-note { font-size: 12px; color: var(--muted); line-height: 1.4;
  background: rgba(245, 158, 11, 0.10); border-radius: 8px; padding: 8px 10px; }
.regime-group { display: flex; flex-direction: column; }
.regime-sub { font-size: 11px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase;
  color: var(--muted); margin: 8px 0 2px; }
.setting--sub { padding: 8px 0; }
.regime-soft__ctl { display: flex; align-items: center; gap: 10px; }
.regime-num { width: 62px; text-align: center; background: var(--surface); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 7px 8px; font-size: 14px; }
.regime-group .is-off { opacity: .4; pointer-events: none; }

/* --- Fields --- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { color: var(--muted); font-size: 12px; }
.field input, .field select {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 15px; width: 100%;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
/* selects: kill the native chrome and draw our own caret so they match inputs */
.field select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center;
}

/* --- Inline help "?" + hint --- */
.help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%; padding: 0; margin-left: 2px;
  border: none; background: var(--surface-2); color: var(--muted);
  font-size: 11px; font-weight: 700; line-height: 1; cursor: pointer; vertical-align: middle;
}
.help:hover { background: var(--accent-weak); color: var(--accent-600); }
.hint {
  margin-top: 6px; padding: 8px 10px; border-radius: 8px;
  background: var(--accent-weak); color: var(--text);
  font-size: 12px; line-height: 1.45; border: 1px solid var(--border);
}
.hint.err { background: var(--bad-weak); color: var(--bad); border-color: transparent; }
.hint:empty { display: none; }
.linklike { background: none; border: none; padding: 0; font: inherit; font-size: 12px;
  color: var(--accent); cursor: pointer; text-decoration: underline; }

/* --- Accordion (help / reference) --- */
.acc { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin-top: 10px; }
.acc + .acc { margin-top: 8px; }
.acc__head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 14px; cursor: pointer; font-weight: 600; background: var(--surface);
}
.acc__head::after { content: "▾"; color: var(--muted); font-size: 12px; transition: transform 0.15s; }
.acc__head.open::after { transform: rotate(180deg); }
.acc__body { padding: 0 14px 14px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.acc__body p { margin: 8px 0; }
.acc__body b { color: var(--text); }
.acc__body code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 12px; }

/* --- Buttons --- */
.btn { border: 1px solid transparent; border-radius: 10px; padding: 10px 16px; font-size: 14px; font-weight: 650; cursor: pointer; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-600); }
.btn--ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--danger { background: var(--bad-weak); color: var(--bad); border-color: var(--bad); }
.btn--danger:hover { background: var(--bad); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* --- Segmented control --- */
.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 10px; border: 1px solid var(--border); }
.seg__btn { border: none; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; padding: 6px 16px; border-radius: 8px; cursor: pointer; }
.seg__btn--active { background: var(--surface); color: var(--accent-600); box-shadow: var(--shadow); }

/* --- Strategy summary --- */
.strat-summary { display: flex; flex-direction: column; gap: 10px; }
.sumrow { display: flex; gap: 12px; font-size: 14px; line-height: 1.5; }
.sumrow__k { flex-shrink: 0; width: 96px; font-weight: 650; }
.sumrow__v { flex: 1; min-width: 0; }
.sumrow__sub { font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.sum-list { margin: 5px 0 0; padding-left: 18px; line-height: 1.55; }
.sum-list li { margin: 1px 0; }
.sum-note { margin: 6px 0 0; padding: 6px 10px; border-radius: 8px; background: var(--surface-2);
  font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.sum-note b { color: var(--text); }
.sumrow b { font-variant-numeric: tabular-nums; }

/* --- Presets (trading modes) --- */
.presets { display: flex; flex-direction: column; gap: 10px; }
.preset { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.preset__main { flex: 1; min-width: 0; }
.preset__title { font-weight: 650; }
.preset__desc { color: var(--muted); font-size: 13px; line-height: 1.4; margin-top: 3px; }
.preset__meta { color: var(--muted); font-size: 11px; margin-top: 6px; }
.preset__apply { flex-shrink: 0; }
/* Mode cards inside the picker stay side-by-side on wider screens. */
@media (min-width: 760px) { .class-strats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); align-items: stretch; } .class-strats .preset { flex-direction: column; align-items: flex-start; } .class-strats .preset__apply { width: 100%; } }

/* --- Stages --- */
.stages-wrap { display: flex; flex-direction: column; gap: 12px; }
.stage { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.stage__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.stage__title { font-weight: 650; }
.stage__del { width: 32px; height: 32px; font-size: 15px; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

/* --- Account hub --- */
.acc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.acc-cell { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.acc-v { font-size: 16px; font-weight: 700; margin-top: 3px; }
@media (max-width: 560px) { .acc-grid { grid-template-columns: repeat(2, 1fr); } }
.conn-card { display: flex; flex-direction: column; gap: 10px; }
.conn-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.conn-row span { color: var(--muted); }

/* --- Settings rows --- */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 0; border-top: 1px solid var(--border); }
.panel__head + .setting { border-top: none; }
.setting--last { border-bottom: none; }
.setting__title { font-weight: 600; }
.setting__sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* --- Switch --- */
.switch { position: relative; display: inline-block; width: 50px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch__slider { position: absolute; cursor: pointer; inset: 0; background: var(--switch-off); border-radius: 30px; transition: 0.2s; }
.switch__slider::before { content: ""; position: absolute; height: 24px; width: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.2s; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.switch input:checked + .switch__slider { background: var(--accent); }
.switch input:checked + .switch__slider::before { transform: translateX(20px); }
.switch input:disabled + .switch__slider { opacity: 0.5; }

/* --- Bottom nav (mobile) --- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-around;
  background: var(--topbar-bg);
  backdrop-filter: saturate(180%) blur(8px);
  border-top: 1px solid var(--border);
  padding: 6px 6px calc(env(safe-area-inset-bottom) + 6px);
}
.bn__item { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; border: none; background: transparent; color: var(--muted); font-size: 10px; font-weight: 550; padding: 6px 2px; cursor: pointer; }
.bn__item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bn__item .ico { width: 21px; height: 21px; fill: currentColor; }
.bn__item--active { color: var(--accent-600); }

/* --- Last-updated --- */
.profile-sel { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 9px; padding: 7px 10px; font-size: 13px; font-weight: 600; cursor: pointer; max-width: 150px; }
.last-upd { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 420px) { .last-upd { display: none; } }

/* --- Modal --- */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.45); padding: 24px;
}
.modal.show { display: flex; animation: fadeIn 0.15s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal__card {
  background: var(--surface); color: var(--text); border-radius: 16px; padding: 22px;
  max-width: 360px; width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,0.3);
  animation: popIn 0.18s ease;
}
@keyframes popIn { from { transform: scale(0.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal__text { font-size: 15px; line-height: 1.45; margin-bottom: 18px; }
.modal__actions { display: flex; gap: 10px; }
.modal__actions .btn { flex: 1; }

/* --- Leaderboard --- */
.lb-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; cursor: pointer; }
.lb-rank { width: 30px; text-align: center; font-size: 18px; font-weight: 700; color: var(--muted); flex-shrink: 0; }
.lb-main { flex: 1; min-width: 0; }
.lb-name { font-weight: 650; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lb-prof { color: var(--muted); font-weight: 500; }
.lb-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { font-size: 11px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); padding: 1px 7px; border-radius: 999px; }
.chip--demo { color: #fff; background: #8b5cf6; border-color: #8b5cf6; font-weight: 700; letter-spacing: .3px; }
.lb-filter { margin-bottom: 12px; display: inline-flex; }
.wiz-demo { margin-top: 6px; }
.demo-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; letter-spacing: .3px; color: #fff; background: #8b5cf6; padding: 4px 11px; border-radius: 999px; white-space: nowrap; }
.demo-pill__short { display: none; }
body.demo-mode .topbar { box-shadow: inset 0 3px 0 #8b5cf6; }
/* Mobile/tablet: shorten the demo pill and drop the topbar equity-mini (the hero
   already shows equity full-width) so the topbar never overflows. */
@media (max-width: 760px) {
  .demo-pill__full { display: none; }
  .demo-pill__short { display: inline; }
  .equity-mini { display: none; }
}
.lb-spark { flex-shrink: 0; opacity: 0.9; }
.lb-net { text-align: right; flex-shrink: 0; min-width: 90px; }
.lb-grade { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 6px; font-size: 12px; font-weight: 800; color: #fff; }
.lb-grade--A { background: #16a34a; } .lb-grade--B { background: #65a30d; }
.lb-grade--C { background: #d97706; } .lb-grade--D { background: #ea580c; } .lb-grade--E { background: #dc2626; }
@media (max-width: 560px) { .lb-spark { display: none; } }

/* Leaderboard profile drill-in */
.prof-head { display: flex; align-items: center; gap: 12px; margin: 14px 0 4px; }
.prof-name { font-size: 20px; font-weight: 700; }
.prof-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px 0; }
.prof-score { display: flex; align-items: baseline; gap: 2px; margin-left: auto; }
.prof-score b { font-size: 24px; font-weight: 800; } .prof-score span { color: var(--muted); font-size: 13px; }
.prof-curve { margin: 14px 0 4px; }
.prof-curve svg { width: 100%; height: 90px; display: block; }

/* P&L contribution bars */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-row .mono { width: 30px; height: 30px; border-radius: 8px; font-size: 11px; }
.bar-sym { width: 52px; font-weight: 650; font-size: 13px; flex-shrink: 0; }
.bar-track { flex: 1; height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; min-width: 40px; }
.bar-fill { height: 100%; border-radius: 6px; }
.bar-fill.up { background: var(--ok); } .bar-fill.down { background: var(--bad); }
.bar-val { width: 96px; text-align: right; font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* --- Toast --- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 80px);
  transform: translateX(-50%) translateY(20px);
  background: #111827; color: #fff; padding: 11px 18px; border-radius: 12px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: 0.25s; max-width: 90vw;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2); z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--bad); }

/* Tabular figures so numbers align and don't jitter while counting up. */
.hero__value, .hero__pnl, .tile__value, .equity-mini__value,
.pos__val, .pnl-pos, .pnl-neg, .stat__big { font-variant-numeric: tabular-nums; }

/* --- Micro-animations --- */
.view--active { animation: fadeInUp 0.28s ease both; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (hover: hover) {
  .tile, .panel { transition: transform 0.15s ease, box-shadow 0.15s ease; }
  .tile:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(17,24,39,0.08); }
  .nav__item, .btn, .icon-btn { transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease; }
  .btn:active { transform: translateY(1px); }
}

/* Pulsing dot for the active trading status pill. */
.hero__status.live { display: inline-flex; align-items: center; gap: 7px; }
.hero__status.live::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 0 rgba(255,255,255,0.7); animation: pulse 1.8s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,255,255,0.55); }
  70% { box-shadow: 0 0 0 7px rgba(255,255,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}

/* Hero glow accent */
.hero { position: relative; overflow: hidden; }
.hero::after {
  content: ""; position: absolute; right: -40px; top: -60px; width: 220px; height: 220px;
  background: radial-gradient(circle, rgba(255,255,255,0.25), rgba(255,255,255,0) 70%);
  pointer-events: none;
}
.hero__main, .hero__status { position: relative; z-index: 1; }

/* --- Monogram (ticker avatar) --- */
.mono {
  width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px; letter-spacing: 0.02em;
}
.pos, .inst__bar { align-items: center; }
.pos__left, .inst__id { display: flex; align-items: center; gap: 12px; min-width: 0; }

/* --- P&L pill --- */
.pnl-pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 650; }
.pnl-pill.pos { color: var(--ok); background: var(--ok-weak); }
.pnl-pill.neg { color: var(--bad); background: var(--bad-weak); }

/* --- Allocation donut --- */
.alloc { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut { flex-shrink: 0; transform: rotate(-90deg); }
.donut__seg { transition: stroke-dasharray 0.5s ease; }
.donut-wrap { position: relative; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; transform: rotate(0deg); }
.donut-center__big { font-weight: 750; font-size: 15px; }
.donut-center__sub { color: var(--muted); font-size: 11px; }
.legend { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 140px; }
.legend__row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend__dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend__sym { font-weight: 600; }
.legend__pct { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

/* --- Skeleton shimmer --- */
.skel-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.skel-row:first-child { border-top: none; }
.skel { background: linear-gradient(90deg, var(--skel-a) 25%, var(--skel-b) 37%, var(--skel-a) 63%); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.skel--circle { width: 38px; height: 38px; border-radius: 11px; }
.skel--line { height: 12px; flex: 1; }
.skel--sm { height: 10px; width: 60%; }

/* --- P&L panel --- */
.pnl-panel { display: flex; flex-direction: column; gap: 12px; }
.alloc-panel { display: flex; flex-direction: column; }
/* "Результат по бумагам" — diverging P&L bars */
.perf-panel { display: flex; flex-direction: column; }
.perf { display: flex; flex-direction: column; justify-content: space-evenly; gap: 10px; flex: 1 1 auto; min-height: 200px; }
.perf-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.perf-sym { width: 52px; flex: 0 0 auto; font-weight: 650; }
.perf-track { position: relative; flex: 1 1 auto; height: 16px; background: var(--surface-2); border-radius: 4px; min-width: 40px; }
.perf-track::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--border); }
.perf-fill { position: absolute; top: 0; bottom: 0; border-radius: 4px; min-width: 2px; }
.perf-fill.pos { background: var(--ok); }
.perf-fill.neg { background: var(--bad); }
.perf-val { width: 84px; text-align: right; flex: 0 0 auto; font-weight: 650; font-variant-numeric: tabular-nums; }
/* Распределение: donut + legend with bars */
.alloc-legend { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 10px; }
.leg-row { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.leg-dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.leg-sym { font-weight: 650; width: 52px; flex: 0 0 auto; }
.leg-bar { flex: 1 1 auto; height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; min-width: 20px; }
.leg-bar__fill { display: block; height: 100%; border-radius: 4px; }
.leg-pct { width: 48px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.leg-row:hover .leg-sym { color: var(--accent-600); }
.donut__seg { cursor: pointer; transition: opacity 0.12s; }
.donut__seg:hover { opacity: 0.82; }
.donut-tip { position: absolute; z-index: 6; transform: translate(-50%, -135%); white-space: nowrap; pointer-events: none;
  background: #111827; color: #fff; font-size: 12px; padding: 5px 9px; border-radius: 7px; box-shadow: 0 4px 12px rgba(0,0,0,0.25); }
.pnl-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.pnl-box { padding: 4px 0; }
.pnl-box + .pnl-box { border-left: 1px solid var(--border); padding-left: 16px; }
.pnl-box__label { color: var(--muted); font-size: 12px; }
.pnl-box__val { font-size: 22px; font-weight: 750; margin-top: 4px; font-variant-numeric: tabular-nums; }
.pnl-box__pct { font-size: 13px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.up { color: var(--ok); }
.down { color: var(--bad); }

/* period P&L row + recent trades feed */
.stat-periods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 4px; }
@media (max-width: 540px) { .stat-periods { grid-template-columns: repeat(2, 1fr); } }
.stat-per { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 6px; text-align: center; }
.stat-per span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.stat-per b { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-per-hint { font-size: 11px; margin-top: 2px; }
.recent-trades { display: flex; flex-direction: column; }
.recent-trades--scroll { max-height: 460px; overflow-y: auto; overscroll-behavior: auto; padding-right: 4px; }
.rt-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 2px 0 8px; }
.rt-sym-sel { border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 600; cursor: pointer; }
.rt-empty { color: var(--muted); padding: 18px 0; text-align: center; }
.rt-row { display: flex; align-items: center; gap: 12px; padding: 9px 2px; border-top: 1px solid var(--border); }
.rt-row:first-child { border-top: none; }
.rt-ic { flex: 0 0 auto; font-size: 12px; line-height: 1; }
.rt-main { flex: 1 1 36%; min-width: 0; }
.rt-extra { flex: 1 1 32%; min-width: 0; font-size: 12px; font-weight: 600; }
.rt-extra.muted { font-weight: 500; }
.rt-net { display: block; color: var(--muted); font-weight: 500; font-size: 11px; margin-top: 1px; }
.rt-sym { font-weight: 600; font-size: 14px; }
.rt-sub { color: var(--muted); font-size: 12px; }
.rt-right { flex: 0 0 auto; margin-left: auto; text-align: right; white-space: nowrap; }
.rt-val { font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; }
.rt-time { color: var(--muted); font-size: 11px; }
@media (max-width: 600px) {
  .rt-row { flex-wrap: wrap; }
  .rt-main { flex: 1 1 auto; }
  .rt-extra { order: 5; flex-basis: 100%; padding-left: 24px; margin-top: 1px; }
  .rt-right { order: 4; }
}
.pnl-box__val.muted-val { color: var(--muted); font-size: 15px; font-weight: 600; }
.spark { width: 100%; height: 48px; display: block; }
.spark-head { display: flex; align-items: center; justify-content: space-between; }
.spark-label { color: var(--muted); font-size: 12px; }
.seg--sm .seg__btn { padding: 4px 10px; font-size: 12px; }

/* Accessibility: visible keyboard focus on all interactive elements. */
button:focus-visible, input:focus-visible, a:focus-visible, .nav__item:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px;
}

/* --- Strategy assessment --- */
.assess { display: flex; gap: 18px; align-items: stretch; }
.assess__score {
  flex-shrink: 0; width: 130px; border-radius: 14px; padding: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; text-align: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-600));
}
.assess[data-grade="A"] .assess__score { background: linear-gradient(135deg, #16a34a, #15803d); }
.assess[data-grade="B"] .assess__score { background: linear-gradient(135deg, #65a30d, #4d7c0f); }
.assess[data-grade="C"] .assess__score { background: linear-gradient(135deg, #f59e0b, #d97706); }
.assess[data-grade="D"] .assess__score { background: linear-gradient(135deg, #f97316, #ea580c); }
.assess[data-grade="E"] .assess__score { background: linear-gradient(135deg, #dc2626, #b91c1c); }
.assess__grade { font-size: 40px; font-weight: 800; line-height: 1; }
.assess__num { font-size: 15px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.assess__max { opacity: 0.8; font-weight: 600; }
.assess__cap { font-size: 11px; opacity: 0.9; margin-top: 4px; }
.assess__body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.assess__verdict { font-size: 14px; line-height: 1.45; margin-bottom: 10px; }
.assess__factors { display: flex; flex-direction: column; gap: 6px; margin-top: auto; }
.factor { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.factor__k { color: var(--muted); }
.factor__v { font-variant-numeric: tabular-nums; text-align: right; }
@media (max-width: 560px) { .assess { flex-direction: column; } .assess__score { width: 100%; flex-direction: row; gap: 12px; justify-content: flex-start; } .assess__cap { margin: 0; } }

/* --- Trade log --- */
.trade { display: flex; align-items: center; gap: 10px; padding: 10px 0; font-size: 13px; flex-wrap: wrap; }
.trade__side { font-weight: 650; width: 92px; flex-shrink: 0; }
.trade__sym { font-weight: 650; width: 56px; }
.trade__qty { color: var(--muted); flex: 1; min-width: 100px; }
.trade__val { font-weight: 600; font-variant-numeric: tabular-nums; }
.trade__time { color: var(--muted); width: 92px; text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .trade__time { width: auto; } .trade__qty { flex-basis: 100%; order: 5; } }

/* --- Costs (commissions / tax) --- */
.costs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cost { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.cost__v { font-size: 20px; font-weight: 750; margin-top: 4px; color: var(--bad); font-variant-numeric: tabular-nums; }

/* --- Analytics note --- */
.an-note { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 0; }
.an-note code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 12px; }

/* --- Dashboard columns --- */
.dash-cols { display: flex; flex-direction: column; gap: 14px; }

/* --- Responsive: tablet --- */
@media (min-width: 640px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
}

/* --- Responsive: desktop (sidebar instead of bottom nav) --- */
@media (min-width: 1000px) {
  .sidebar {
    display: flex; flex-direction: column;
    width: var(--sidebar-w); flex-shrink: 0;
    background: var(--surface); border-right: 1px solid var(--border);
    position: sticky; top: 0; height: 100vh;
  }
  .bottomnav { display: none; }
  .content { padding-bottom: 32px; }
  .topbar { padding-left: 24px; padding-right: 24px; }
  .equity-mini { display: none; } /* equity is in the hero on desktop */
  .grid { grid-template-columns: repeat(3, 1fr); }
  .dash-cols { display: grid; grid-template-columns: 0.9fr 1.1fr; gap: 14px; align-items: stretch; }
}

/* --- Auth gate + onboarding wizard --- */
.authwrap { position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 20px; overflow: auto; }
.authcard { background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow); padding: 26px 24px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.authcard--wide { max-width: 460px; }
.authcard__brand { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 750; justify-content: center; }
.authcard__brand .brand__mark { width: 30px; height: 30px; }
.auth-tabs { width: 100%; }
.auth-tabs .seg__btn { flex: 1; }
.authfield { display: flex; flex-direction: column; gap: 6px; }
.authfield span { color: var(--muted); font-size: 12px; }
.authfield input { background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 11px 12px; font-size: 15px; }
.authfield input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.authselect { background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 11px 12px; font-size: 15px; width: 100%; cursor: pointer; }
.authselect:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.auth-submit { width: 100%; padding: 12px; font-size: 15px; }
.auth-msg { font-size: 13px; padding: 9px 11px; border-radius: 9px; background: var(--bad-weak); color: var(--bad); }
.auth-msg.ok { background: var(--ok-weak); color: var(--ok); }
.auth-foot { font-size: 11px; text-align: center; }

/* wizard */
.wiz-head { display: flex; flex-direction: column; gap: 12px; }
.wiz-steps { display: flex; gap: 6px; }
.wiz-steps .dot { width: 100%; height: 4px; border-radius: 999px; background: var(--border); }
.wiz-steps .dot.on { background: var(--accent); }
.wiz-step h3 { margin: 6px 0 4px; font-size: 17px; }
.wiz-step { display: flex; flex-direction: column; gap: 12px; }
.wiz-presets { display: flex; flex-direction: column; gap: 10px; }
.wiz-preset { text-align: left; border: 1.5px solid var(--border); background: var(--surface-2);
  border-radius: 12px; padding: 12px 14px; cursor: pointer; }
.wiz-preset.sel { border-color: var(--accent); background: var(--accent-weak); }
.wiz-preset b { display: block; font-size: 15px; margin-bottom: 2px; }
.wiz-preset span { color: var(--muted); font-size: 12.5px; }
.wiz-pro { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; cursor: pointer; }
.wiz-summary { display: flex; flex-direction: column; gap: 8px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 12px; padding: 14px; font-size: 14px; }
.wiz-summary .sr { display: flex; justify-content: space-between; gap: 12px; }
.wiz-summary .sr span:first-child { color: var(--muted); }
.wiz-nav { display: flex; gap: 10px; justify-content: space-between; margin-top: 2px; }
.wiz-nav .btn { flex: 1; }

/* --- Admin panel --- */
.nav__item--admin span, .nav__item--admin .ico { color: var(--accent); }
.admin-users { display: flex; flex-direction: column; gap: 0; }
.admin-row { display: grid; grid-template-columns: 1.4fr 1fr 0.8fr auto; gap: 12px; align-items: center;
  padding: 12px 0; border-top: 1px solid var(--border); }
.admin-user:first-child .admin-row { border-top: none; }
.admin-email-form { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 0 12px; }
.admin-email-form .inst-search { flex: 1; min-width: 160px; }
.admin-edit-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; padding: 0 0 12px; }
.admin-edit-form .ef-lbl { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); flex: 1; min-width: 140px; }
.admin-edit-form .inst-search { width: 100%; }
.admin-strat { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.admin-json { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.45;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 10px; resize: vertical; }
.admin-strat-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.strat-editor, .admin-strat-form { margin-top: 12px; }
.admin-strat-form { padding: 12px; border: 1px dashed var(--border); border-radius: 10px; background: var(--surface-2); margin-bottom: 8px; }
.se-stages { margin: 10px 0; }
.admin-classes { display: flex; flex-direction: column; gap: 10px; }
.admin-class-card { padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.acl-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.acl-row .acl-title { flex: 1; }
.acl-desc { width: 100%; margin-bottom: 8px; }
.acl-presets { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.acl-chk { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--text); cursor: pointer; }
.acl-chk input { accent-color: var(--accent); cursor: pointer; }
/* keep form labels legible inside collapsible bodies */
.acc__body .field label, .acc__body .setting__title { color: var(--text); }
/* strategy class → strategy picker */
.class-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 14px; }
.class-card { text-align: left; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2);
  cursor: pointer; font: inherit; color: var(--text); transition: border-color .12s, background .12s; }
.class-card:hover { border-color: var(--accent); }
.class-card.sel { border-color: var(--accent); background: var(--accent-weak); }
.class-card__title { font-weight: 700; font-size: 15px; margin-bottom: 3px; }
.class-card__desc { font-size: 12px; color: var(--muted); line-height: 1.4; }
.class-card__meta { font-size: 11px; color: var(--muted); margin-top: 6px; }
.class-strats { display: flex; flex-direction: column; gap: 8px; }
.strat-active { padding: 10px 12px; border-radius: 10px; background: var(--ok-weak); color: var(--text);
  font-size: 14px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.strat-active__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.strat-active--none { background: var(--surface-2); color: var(--muted); }
.cat-label, .strat-list-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: 700; margin-bottom: 8px; }
.strat-list-label { margin-top: 14px; }
.preset--active { border-color: var(--ok); }
.badge-active { font-size: 11px; color: var(--ok); background: var(--ok-weak); padding: 1px 8px; border-radius: 999px; font-weight: 650; vertical-align: middle; }
.hchips { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.hchip { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); }
.hchip.ok { border-left: 3px solid var(--ok); }
.hchip.bad { border-left: 3px solid var(--bad); }
.hchip__k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.hchip__v { font-size: 14px; font-weight: 650; }
.hissue { font-size: 13px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); margin-bottom: 6px; }
.setups-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.setup-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); }
.setup-row__act { display: flex; gap: 6px; flex-wrap: wrap; }
.setup-row__act .btn { padding: 6px 10px; font-size: 12px; }
.setup-row__main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.se-auto { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); cursor: pointer; }
.se-auto input { accent-color: var(--accent); cursor: pointer; }
.setup-edit { flex-basis: 100%; }
.setup-edit:not([hidden]) { margin-top: 10px; padding: 10px; border: 1px dashed var(--border); border-radius: 10px; background: var(--surface-2); }
.nudge { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; margin-bottom: 14px; border-radius: 12px; border: 1px solid var(--accent);
  background: var(--accent-weak); }
.nudge__txt { font-size: 14px; font-weight: 600; color: var(--text); }
.nudge__act { display: flex; align-items: center; gap: 8px; }
.nudge-x { background: none; border: none; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.nudge-x:hover { color: var(--text); }
.pwd-form { display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.push-ctl { display: flex; gap: 10px; align-items: center; }
.pref-num { width: 84px; flex: none; padding: 7px 9px; }
.prof-actions { display: flex; gap: 6px; }
.risk-form { display: flex; flex-direction: column; gap: 12px; }
.risk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .risk-grid { grid-template-columns: 1fr; } }
.admin-row__who b { font-weight: 650; }
.admin-row__who .muted { font-size: 12px; }
.admin-row__meta { font-size: 13px; color: var(--muted); }
.admin-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.abadge { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.abadge.on { background: var(--ok-weak); color: var(--ok); border-color: transparent; }
.abadge.off { background: var(--bad-weak); color: var(--bad); border-color: transparent; }
.abadge.role { background: var(--accent-weak); color: var(--accent-600); border-color: transparent; }
.admin-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.admin-actions .btn { padding: 7px 12px; font-size: 13px; }
@media (max-width: 640px) {
  .admin-row { grid-template-columns: 1fr; gap: 6px; }
  .admin-actions { justify-content: flex-start; }
}


/* Reconnecting state (transient network drops): gentle amber, not the red error */
.status-dot.reconnecting { background: #f59e0b; animation: dotpulse 1s ease-in-out infinite; }
@keyframes dotpulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
.toast.reconnect { background: #b45309; }
.toast .toast-spin { display: inline-block; animation: spin 0.9s linear infinite; margin-right: 7px; }

/* Position avg-price badge, pinned to the LEFT of the chart (opposite the market
   price on the right axis) so the two prices never mix. */
.chart-avg {
  position: absolute; left: 6px; z-index: 4; transform: translateY(-50%);
  background: rgba(109,40,217,0.55); color: #fff; font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 7px; white-space: nowrap; pointer-events: none;
}