/* birj dashboard — compact product UI with light/dark themes. */
*, *::before, *::after { box-sizing: border-box; }

:root {
  color-scheme: dark;
  /* Binance signature dark palette — verified against app screenshots.
   * Background → surface step is tone-based (no borders); each tier is
   * roughly +6 lightness apart so cards stand out on their own. */
  --bg: #0b0e11;             /* page base */
  --bg-soft: #14171c;        /* hero gradient top + status edges */
  --surface: #1e2329;        /* default card */
  --surface-2: #252a32;      /* nested / inner card */
  --surface-3: #2b3139;      /* hover / pressed / segmented track */
  --elev: rgba(0, 0, 0, 0.32);
  /* `--line` reserved for SEPARATORS only (row dividers, modal header,
   * floating tabbar outline). Cards themselves are borderless. */
  --line: rgba(132, 142, 156, 0.10);
  --line-2: rgba(132, 142, 156, 0.18);
  --text: #eaecef;           /* Binance signature white-grey */
  --text-2: #d4d8de;
  --muted: #848e9c;          /* Binance signature secondary */
  --dim: #5e6673;
  --pos: #0ecb81;            /* Binance brand green */
  --neg: #f6465d;            /* Binance brand red */
  --warn: #d99d37;
  --accent: #f0b90b;
  --accent-strong: #fcd535;
  --accent-ink: #181a20;
  --accent-soft: color-mix(in srgb, var(--accent) 15%, transparent);
  --accent-2: #c99400;
  --shadow: rgba(240, 185, 11, 0.12);
  --radius: 8px;
  --radius-sm: 6px;
  --gutter: 14px;
  --tab-h: calc(60px + env(safe-area-inset-bottom));
}

:root[data-theme="light"] {
  color-scheme: light;
  /* Stronger light theme: clearer text, cooler page tone, and slightly deeper
   * separators so dense dashboard cards don't wash out in daylight. */
  --bg: #eef1f5;
  --bg-soft: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f4f6f9;
  --surface-3: #e7ebf0;
  --elev: rgba(17, 24, 39, 0.10);
  --line: rgba(17, 24, 39, 0.10);
  --line-2: rgba(17, 24, 39, 0.18);
  --text: #111827;
  --text-2: #2f3745;
  --muted: #5d6675;
  --dim: #767f8d;
  --pos: #078f5b;
  --neg: #c93142;
  --warn: #8b5b0d;
  --accent: #f0b90b;
  --accent-strong: #fcd535;
  --accent-ink: #1e2329;
  --accent-soft: color-mix(in srgb, var(--accent) 17%, transparent);
  --accent-2: #b88300;
  --shadow: rgba(240, 185, 11, 0.08);
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.42 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
input, textarea {
  user-select: text;
  -webkit-user-select: text;
}
body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: var(--tab-h);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(180deg, var(--bg-soft) 0%, var(--bg) 44%);
}

#app { min-height: calc(100vh - var(--tab-h)); }
.app-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 0 var(--gutter) 18px;
}
.tab-content > div {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ptr-indicator {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  z-index: 120;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--accent-ink);
  background: var(--accent-strong);
  border-radius: 999px;
  box-shadow: 0 8px 24px var(--elev);
  opacity: 0;
  transform: translate(-50%, -16px) scale(0.92);
  transition: opacity 140ms ease, transform 180ms ease;
  pointer-events: none;
}
.ptr-indicator.visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}
.ptr-indicator .ic {
  width: 18px;
  height: 18px;
}
.ptr-indicator.refreshing .ic,
.icon-btn.refreshing .ic {
  animation: spin 760ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

header {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 14px var(--gutter) 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
header .brand,
.setup-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.logo {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 2px var(--elev), 0 0 0 1px var(--line);
  flex-shrink: 0;
}
header h1,
.setup-card h1 {
  margin: 0;
  font-size: 25px;
  line-height: 1;
  font-weight: 760;
  color: var(--text);
  letter-spacing: 0;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}
.ts {
  font-size: 12px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  min-width: 54px;
  text-align: right;
}

button {
  min-height: 38px;
  background: color-mix(in srgb, var(--surface-3) 76%, transparent);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, transform 90ms ease, color 140ms ease;
}
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.5; cursor: default; }
button.cta {
  width: 100%;
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: var(--accent-ink);
}
.icon-btn {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
}
.icon-btn:active,
.icon-btn.refreshing {
  color: var(--accent-ink);
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}
.icon-btn.refreshing:disabled { opacity: 1; }
.icon-btn .ic {
  width: 18px;
  height: 18px;
  display: block;
  color: var(--text-2);
}
.icon-btn:active .ic,
.icon-btn.refreshing .ic { color: var(--accent-ink); }
#theme-toggle .theme-moon { display: none; }
#theme-toggle .theme-sun { display: block; }
:root[data-theme="light"] #theme-toggle .theme-sun { display: none; }
:root[data-theme="light"] #theme-toggle .theme-moon { display: block; }

#setup {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 26px 18px;
}
.setup-card {
  width: min(100%, 390px);
  background: var(--surface);
  border: 0;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 18px 48px var(--elev);
}
.setup-brand { margin-bottom: 22px; }
.setup-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}
#setup label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
}
#setup input {
  width: 100%;
  min-height: 42px;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius);
  font: inherit;
  margin-bottom: 12px;
  outline: none;
}
#setup input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.setup-note { text-align: center; font-size: 12px !important; }

.err {
  width: min(100%, 980px);
  margin: 0 auto;
  color: var(--neg);
  font-size: 12px;
  padding: 0 var(--gutter) 8px;
}

.card {
  /* Borderless: Binance separates cards by background tone alone — surface
   * sits one tier brighter than --bg, no border, no shadow needed. */
  background: var(--surface);
  border-radius: var(--radius);
  margin: 0;
  padding: 16px;
  border: 0;
  box-shadow: none;
}
:root[data-theme="light"] .card {
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.04);
}
.card h2 {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 760;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.9px;
}
.card.compact-card { padding: 12px 14px; }
.card.compact-card h2 { margin-bottom: 8px; }

.card.hero {
  padding: 20px 18px 16px;
  background: var(--surface);
}
.hero-label {
  font-size: 11px;
  font-weight: 760;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.9px;
  margin-bottom: 2px;
}
.hero-value {
  font-size: 40px;
  font-weight: 780;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: 3px;
  margin-bottom: 6px;
}
.hero-currency {
  font-size: 24px;
  font-weight: 650;
  color: var(--text-2);
}
.hero-value.pos .hero-currency,
.hero-value.neg .hero-currency {
  color: currentColor;
}
.hero-cents {
  font-size: 0.62em;
  opacity: 0.64;
  font-weight: 650;
  vertical-align: 4px;
}
.cents {
  font-size: 0.78em;
  opacity: 0.7;
  font-weight: inherit;
}
.money-prefix {
  font-size: 0.84em;
  font-weight: 650;
  opacity: 0.9;
  margin-right: 1px;
}
.hero-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.hero-meta .dim { margin-right: 3px; }
.hero-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding-top: 12px;
}
.hero-row.shadow-hero-row {
  grid-template-columns: minmax(58px, 0.72fr) minmax(82px, 0.9fr) minmax(0, 1.32fr);
  gap: 16px;
}
.hero-cell {
  min-width: 0;
  padding-right: 4px;
}
.shadow-hero-row .hero-cell {
  padding-right: 0;
}
.shadow-group {
  margin: 16px 2px 8px;
}
.shadow-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 820;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}
.decision-board {
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 11%, transparent), transparent 45%),
    var(--surface);
}
.decision-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.decision-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.decision-chip {
  min-width: 0;
  padding: 10px 9px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.decision-chip span {
  display: block;
  color: var(--dim);
  font-size: 10px;
  font-weight: 760;
  letter-spacing: 0.45px;
  text-transform: uppercase;
  white-space: nowrap;
}
.decision-chip strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
  line-height: 1;
}
.decision-chip.warn strong { color: var(--warn); }
.decision-chip.success strong { color: var(--pos); }
.decision-chip.danger strong { color: var(--neg); }
.decision-chip.shadow strong { color: var(--accent-2); }
.decision-list {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.decision-list-title {
  color: var(--dim);
  font-size: 10px;
  font-weight: 780;
  letter-spacing: 0.55px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.decision-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 13px;
  border-top: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
}
.decision-row:first-of-type { border-top: 0; }
.hero-cell-label,
.stat .stat-k {
  font-size: 10px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.55px;
  margin-bottom: 3px;
  white-space: nowrap;
}
.hero-cell-value {
  font-size: 15px;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.hero-cell-sub {
  font-size: 11px;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
  line-height: 1.15;
}
.hero-cell-divider,
.stat-divider {
  color: var(--dim);
  font-weight: 500;
  margin: 0 1px;
}

.card.pill {
  margin: 0;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: color-mix(in srgb, var(--pos) 10%, var(--surface));
}
.card.pill.bad  { background: color-mix(in srgb, var(--neg) 10%, var(--surface)); }
.card.pill.warn { background: color-mix(in srgb, var(--warn) 11%, var(--surface)); }
.pill-text { font-size: 13px; font-weight: 650; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.row:first-of-type { border-top: 0; }
.row .name { color: var(--text-2); min-width: 0; }
.row.compact { padding: 6px 0; font-size: 12px; }
.right-meta { display: flex; gap: 8px; align-items: center; white-space: nowrap; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.neu { color: var(--muted); }
.warn { color: var(--warn); }
.dim { color: var(--dim); }
.mono {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.small { font-size: 11px; }

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: 1px;
  flex-shrink: 0;
}
.dot.active { background: var(--pos); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pos) 16%, transparent); }
.dot.failed { background: var(--neg); }
.dot.inactive { background: var(--dim); }
.dot.warn { background: var(--warn); }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 760;
  background: color-mix(in srgb, var(--surface-3) 78%, transparent);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.badge.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.badge.danger { background: color-mix(in srgb, var(--neg) 16%, transparent); color: var(--neg); }
.badge.success { background: color-mix(in srgb, var(--pos) 16%, transparent); color: var(--pos); }
.badge.shadow { background: var(--shadow); color: var(--accent-2); }
.badge.live { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent-strong); }
:root[data-theme="light"] .badge.live { color: var(--accent-2); }

/* PnL/ROI history chart inside bot detail modal — Binance-style equity
 * curve. Inline SVG renders the line + filled area (paths get stretched
 * via preserveAspectRatio="none" so they fill the container without
 * letterboxing). Tick labels live in a HTML overlay layer so they render
 * at native device resolution — putting them inside the stretched SVG
 * makes glyphs look horizontally squished on narrow screens.
 *
 * Tabs (PnL/ROI) use their OWN styling, not the .segmented base class —
 * earlier inheritance fights kept reintroducing full-width stretching. */
.pnl-chart-card {
  padding: 14px 14px 12px;
  border-radius: var(--radius-sm);
}
.pnl-chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 6px;
}
.pnl-chart-metric {
  min-width: 0;
}
.pnl-chart-metric-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.4px;
}
.pnl-chart-metric-value {
  font-size: 28px;
  font-weight: 780;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  margin-top: 2px;
}
.pnl-chart-metric-value.pos { color: var(--pos); }
.pnl-chart-metric-value.neg { color: var(--neg); }
/* Standalone tabs — completely decoupled from .segmented. */
.pnl-chart-tabs {
  display: inline-flex;
  flex: 0 0 auto;
  align-self: flex-start;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}
.pnl-chart-tabs button {
  flex: 0 0 auto;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 14px;
  border-radius: 5px;
  white-space: nowrap;
  min-height: 24px;
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease;
}
.pnl-chart-tabs button.active {
  background: var(--accent-strong);
  color: var(--accent-ink);
}
.pnl-chart-tabs button:disabled {
  cursor: default;
  opacity: 0.45;
}
.pnl-chart-note {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.pnl-chart-svg-wrap {
  position: relative;
  margin-top: 10px;
  height: 204px;
  font-size: 11px;          /* Inherited by overlay ticks. */
}
.pnl-chart-svg {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}
.pnl-chart-svg .pnl-grid {
  stroke: var(--line);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  shape-rendering: crispEdges;
}
.pnl-chart-svg .pnl-day {
  stroke: var(--line-2);
  stroke-width: 1;
  stroke-dasharray: 3 5;
  opacity: 0.55;
  vector-effect: non-scaling-stroke;
  shape-rendering: crispEdges;
}
.pnl-chart-svg .pnl-zero {
  stroke: var(--line-2);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  vector-effect: non-scaling-stroke;
  shape-rendering: crispEdges;
}
.pnl-chart-svg .pnl-line {
  stroke-width: 1.55;
  stroke-linecap: butt;
  stroke-linejoin: miter;
  vector-effect: non-scaling-stroke;
  shape-rendering: geometricPrecision;
}
.pnl-chart-svg .pnl-line-pos { stroke: var(--pos); }
.pnl-chart-svg .pnl-line-neg { stroke: var(--neg); }
.pnl-chart-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.pnl-chart-overlay .pnl-tick-y {
  position: absolute;
  left: 6px;
  font-size: 11px;
  line-height: 1;
  padding-top: 1px;
  white-space: nowrap;
}
.pnl-chart-overlay .pnl-tick-x {
  position: absolute;
  bottom: 2px;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
}

.position {
  /* Borderless tile — surface-2 sits visibly atop the card it's nested in. */
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 8px 0;
  border: 0;
  transition: transform 80ms ease, background-color 160ms ease;
  cursor: pointer;
}
.position:active { transform: scale(0.992); background: var(--surface-3); }
.position .top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.ptop-left { display: flex; align-items: center; gap: 7px; min-width: 0; flex-wrap: wrap; }
.position .symbol { font-weight: 760; font-size: 15px; letter-spacing: 0; }
.position .lev { font-size: 10px; color: var(--dim); font-variant-numeric: tabular-nums; }
.position .upnl { font-size: 17px; font-weight: 760; font-variant-numeric: tabular-nums; white-space: nowrap; }
.position .meta {
  font-size: 11px;
  color: var(--text-2);
  margin-top: 6px;
  display: flex;
  gap: 12px;
  font-variant-numeric: tabular-nums;
  flex-wrap: wrap;
}
.position .meta .dim { margin-right: 3px; }
.position-bar { margin-top: 9px; padding: 0 1px; }
.position-bar-track {
  /* Red → amber → green via OKLCH interpolation. Goes through the natural
   * hue spectrum (red → orange → yellow → yellow-green → green) instead of
   * sRGB-direct red↔green which muddles into brown/grey at the midpoint.
   * Operator: "переход более красивый, грязный цвет не нравится".
   * Even on browsers without `in oklch` support, the explicit --warn amber
   * midpoint keeps the sRGB interpolation clean (red↔amber→orange,
   * amber↔green→yellow-green — no mud either way). */
  height: 3px;
  border-radius: 2px;
  position: relative;
  background: linear-gradient(90deg in oklch,
    color-mix(in srgb, var(--neg) 55%, transparent) 0%,
    color-mix(in srgb, var(--warn) 50%, transparent) 50%,
    color-mix(in srgb, var(--pos) 55%, transparent) 100%);
}
.position-bar-marker {
  position: absolute;
  top: -2px;
  width: 3px;
  height: 7px;
  border-radius: 2px;
  background: var(--text);
  box-shadow: 0 1px 4px var(--elev);
  transform: translateX(-50%);
}
.side-pill {
  font-size: 10px;
  font-weight: 800;
  min-height: 20px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.45px;
}
.side-pill.LONG { background: color-mix(in srgb, var(--pos) 16%, transparent); color: var(--pos); }
.side-pill.SHORT { background: color-mix(in srgb, var(--neg) 16%, transparent); color: var(--neg); }

.bot-card {
  cursor: pointer;
  transition: transform 100ms ease, background-color 140ms ease;
  position: relative;
}
.bot-card:active { transform: scale(0.992); background: var(--surface-2); }
.bot-card::after {
  content: "";
  position: absolute;
  top: 22px;
  right: 16px;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--dim);
  border-top: 1.5px solid var(--dim);
  transform: rotate(45deg);
  opacity: 0.65;
}
.bot-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding-right: 24px;
}
.bot-name-wrap { display: flex; align-items: center; gap: 5px; min-width: 0; flex-wrap: wrap; }
.bot-name-wrap strong { font-size: 14px; }
.bot-pnl { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bot-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 11px 14px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.stat .stat-v {
  font-size: 14px;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  min-width: 0;
}
.hint { font-size: 11px; color: var(--dim); text-align: center; padding: 8px 16px 16px; }

.show-more-row {
  display: flex;
  justify-content: center;
  padding: 10px 0 2px;
}
.show-more-btn {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 750;
  padding: 6px 12px;
}
.show-more-btn:active { transform: scale(0.98); }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 28px var(--elev);
  display: flex;
  justify-content: space-around;
  padding: 6px 4px calc(5px + env(safe-area-inset-bottom));
  z-index: 100;
}
.tabbar button {
  background: transparent;
  border: 0;
  padding: 6px 4px 4px;
  color: var(--dim);
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 650;
  border-radius: var(--radius);
  transition: color 160ms ease, transform 120ms ease, background-color 200ms ease;
  min-height: 50px;
}
.tabbar button:active { transform: scale(0.96); }
.tabbar button .ic { width: 23px; height: 23px; display: block; stroke-width: 1.8; color: var(--dim); transition: color 160ms ease; }
.tabbar button .lbl { line-height: 1; opacity: 0.9; }
/* Active tab — Binance-style: just accent color on icon + label,
 * NO background rectangle. Removed background per operator UX feedback. */
.tabbar button.active {
  color: var(--accent-strong);
  background: transparent;
}
.tabbar button.active .ic { color: var(--accent-strong); }
.tabbar button.active .lbl { opacity: 1; }

/* Journal filters — TWO different patterns by intent:
 *
 *  Top row (kind: Лайв / Тени / Все)
 *    Full-width segmented control. Primary dimension — most users pick
 *    one of these and keep it for the session. Active = yellow CTA fill,
 *    inactive = muted text on segmented track.
 *
 *  Bottom row (event: Выходы / Входы / Все)
 *    Text-tab underline style. Secondary dimension — operator switches
 *    between exits/entries frequently. Active = brighter text + 2px
 *    accent underline. No pill so it's quieter than the top control.
 *
 *  Together they form a clear hierarchy without competing visual noise. */
.journal-filters {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 4px 0 14px;
}
.segmented {
  /* Compact full-width segmented (2026-06-05 operator: "сделай меньше
   * по высоте, прям компактнее"). Track ~30px tall total, button ~22px. */
  display: flex;
  width: 100%;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}
.segmented button {
  flex: 1;
  min-height: 24px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 5px;
  white-space: nowrap;
  transition: background-color 160ms ease, color 160ms ease;
}
.segmented button:hover { color: var(--text-2); }
.segmented button.active {
  background: var(--accent-strong);
  color: var(--accent-ink);
}

/* Bottom row: text-tab underline */
.filter-row {
  display: flex;
  gap: 2px;
  align-items: stretch;
  padding: 0 2px;
  border-bottom: 1px solid var(--line);
}
.filter-chip {
  position: relative;
  min-height: 38px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  padding: 9px 16px 11px;
  white-space: nowrap;
  border-radius: 0;
  transition: color 160ms ease;
}
.filter-chip:hover { color: var(--text-2); }
.filter-chip.active {
  color: var(--text);
  background: transparent;
}
.filter-chip.active::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: -1px;
  height: 2px;
  background: var(--accent-strong);
  border-radius: 1px;
}

.trade {
  /* Trade row: borderless tile + meaningful left-tone bar (kept as the
   * single non-card border because it's a semantic profit/loss flag). */
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--radius);
  margin: 8px 0;
  font-variant-numeric: tabular-nums;
  border: 0;
  border-left: 3px solid var(--line-2);
  transition: transform 80ms ease, background-color 160ms ease;
}
.trade:active { transform: scale(0.992); background: var(--surface-3); }
.trade.tone-pos { border-left-color: var(--pos); }
.trade.tone-neg { border-left-color: var(--neg); }
.trade.tone-neu { border-left-color: var(--muted); }
.trade .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.trade .pnl { font-weight: 800; font-size: 15px; white-space: nowrap; }
.trade .entry-px { font-weight: 700; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.trade .sym { font-weight: 800; font-size: 14px; letter-spacing: 0; }
.trade .left { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.trade .meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: center;
}
.trade .meta .bot-name { color: var(--text-2); font-weight: 700; }
.trade .meta .ts { color: var(--dim); margin-left: auto; }
.trade .meta .reason,
.trade .meta .dur { color: var(--muted); }

.gauge-card { background: var(--surface); }
.gauge { margin: 4px 0 6px; }
.gauge-track {
  /* Same red→amber→green OKLCH gradient as .position-bar-track for the
   * larger modal version. Lockstep palette across both home + detail. */
  height: 8px;
  border-radius: 4px;
  position: relative;
  background: linear-gradient(90deg in oklch,
    color-mix(in srgb, var(--neg) 50%, transparent) 0%,
    color-mix(in srgb, var(--warn) 45%, transparent) 50%,
    color-mix(in srgb, var(--pos) 50%, transparent) 100%);
  box-shadow: inset 0 1px 1px var(--elev);
}
.gauge-marker {
  position: absolute;
  top: -3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 0 0 2px var(--surface), 0 2px 8px var(--elev);
  transform: translateX(-50%);
}
.gauge-bounds {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.gauge-sl { color: var(--neg); }
.gauge-tp { color: var(--pos); }
.gauge-status {
  margin-top: 10px;
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 11px;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}
.gauge-zone {
  font-weight: 760;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-size: 10.5px;
}
.gauge-mark { color: var(--text-2); margin-left: auto; }

.live-chart-card {
  padding: 14px;
  overflow: hidden;
}
.live-chart-head {
  display: block;
  margin-bottom: 10px;
}
.live-chart-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.live-chart-title {
  font-size: 14px;
  font-weight: 820;
  color: var(--text);
}
.live-chart-tfs {
  display: flex;
  width: 100%;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.live-chart-tfs button {
  flex: 1;
  min-height: 24px;
  padding: 4px 7px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
}
.live-chart-tfs button.active {
  background: var(--accent-strong);
  color: var(--accent-ink);
}
.live-chart-frame {
  position: relative;
  height: 322px;
  width: 100%;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.live-candle-canvas {
  display: block;
  width: 100%;
  height: 100%;
}
#market-chart-canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.market-chart-frame { cursor: grab; }
.market-chart-frame:active { cursor: grabbing; }
.live-chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  background: color-mix(in srgb, var(--surface-2) 82%, transparent);
  pointer-events: none;
}

.bar-wrap { margin-bottom: 8px; }
.bar { height: 6px; background: var(--surface-3); border-radius: 4px; overflow: hidden; margin-bottom: 6px; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 200ms ease; }
.bar-fill.ok { background: var(--pos); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.bad { background: var(--neg); }
.bar-label { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }

.kv {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px 12px;
  font-size: 12px;
}
.kv .k { color: var(--muted); min-width: 0; }
.kv .v {
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--text-2);
  min-width: 0;
  overflow-wrap: anywhere;
}
.push-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.push-state { font-size: 13px; font-weight: 700; }
.msg { min-height: 12px; margin-top: 6px; }
.toggle {
  position: relative;
  display: inline-block;
  width: 49px;
  height: 29px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: color-mix(in srgb, var(--dim) 30%, transparent);
  border-radius: 15px;
  transition: background-color 220ms ease;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  height: 25px;
  width: 25px;
  left: 2px;
  bottom: 2px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(0,0,0,0.25), 0 1px 1px rgba(0,0,0,0.08);
  transition: transform 220ms cubic-bezier(0.2,0.8,0.2,1);
}
.toggle input:checked + .toggle-slider { background: #34c759; }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }
.toggle input:disabled + .toggle-slider { opacity: 0.55; cursor: default; }

.market-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.market-tile {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  align-items: center;
  min-height: 72px;
  padding: 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
}
.market-symbol {
  font-size: 16px;
  font-weight: 850;
}
.market-price {
  grid-column: 1 / 3;
  font-size: 13px;
  font-weight: 760;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.market-change {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.manual-switch-card h2 { margin: 0 0 4px; }
.manual-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.manual-controls label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 740;
}
.manual-controls input,
.manual-controls select {
  width: 100%;
  min-height: 36px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  padding: 7px 9px;
  font: inherit;
  font-size: 13px;
  font-weight: 760;
}
.manual-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.manual-side-btn,
.manual-confirm-btn,
.manual-close-btn,
.manual-breakeven-btn {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 14px;
  font-weight: 850;
}
.manual-side-btn.buy,
.manual-confirm-btn.buy { background: var(--pos); }
.manual-side-btn.sell,
.manual-confirm-btn.sell { background: var(--neg); }
.manual-side-btn:disabled,
.manual-confirm-btn:disabled,
.manual-close-btn:disabled,
.manual-breakeven-btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.manual-confirm-box {
  margin-top: 12px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.compact-kv {
  margin-top: 8px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
}
.manual-confirm-btn { width: 100%; margin-top: 10px; }
.manual-result {
  margin-top: 12px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-weight: 800;
  text-align: center;
}
.manual-close-card {
  padding: 12px;
}
.manual-position-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.manual-close-btn {
  background: var(--neg);
}
.manual-close-btn.armed {
  background: color-mix(in srgb, var(--neg) 82%, var(--warn));
}
.manual-breakeven-btn {
  background: var(--accent-strong);
  color: var(--accent-ink);
}
.manual-breakeven-btn.armed {
  background: color-mix(in srgb, var(--accent-strong) 82%, var(--warn));
}
.manual-breakeven-btn.done {
  background: var(--surface-3);
  color: var(--muted);
}
#manual-close-status {
  margin-top: 8px;
}

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 22px 18px;
}
.right { text-align: right; }
.spacer { height: 8px; }
.divider { height: 1px; background: var(--line); margin: 10px 0; }

.tab-content { display: none; }
.tab-content.active { display: block; }

.modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 200;
}
.modal.open { display: block; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.58);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadein 220ms ease;
}
:root[data-theme="light"] .modal-backdrop { background: rgba(15, 23, 42, 0.28); }
.modal-sheet {
  /* 2026-06-05 operator: «фон слишком контрастен плиткам, нужно чуть
   * светлее». Раньше был --bg (#0b0e11) — карточки --surface-2 на нём
   * слишком яркие. Теперь --bg-soft (#14171c) — карточки сидят на нём
   * мягче, без жёсткого контраста, но всё ещё visibly elevated. */
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 90vh;
  background: var(--bg-soft);
  border-radius: var(--radius) var(--radius) 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
  box-shadow: 0 -10px 40px var(--elev);
  animation: slideup 280ms cubic-bezier(0.2,0.8,0.2,1);
}
.modal-header {
  position: relative;
  padding: 26px 18px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.modal-header::before {
  content: "";
  position: absolute;
  top: 9px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--dim) 40%, transparent);
}
.modal-title {
  min-width: 0;
  font-size: 17px;
  font-weight: 800;
}
.modal-position-title {
  flex: 1 1 auto;
  padding-right: 10px;
}
.modal-position-title-inner {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  flex-wrap: wrap;
}
.modal-position-symbol {
  min-width: 0;
  font-size: 16px;
  font-weight: 850;
  letter-spacing: 0;
}
.modal-position-title .badge {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.modal-position-pnl {
  margin-left: auto;
  font-size: 16px;
  font-weight: 850;
  white-space: nowrap;
}
.modal-close {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border-radius: 50%;
  font-size: 19px;
  line-height: 1;
  font-weight: 400;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  position: relative;
}
.modal-close::before { content: ""; position: absolute; inset: -8px; }
.modal-content {
  /* 2026-06-05: top padding 4px → 16px. Header was прилипающий к first
   * card (operator: «верхняя шапка слиплась с журналом, нужен небольшой
   * отступ»). Same fix applies to position detail modal — same class. */
  flex: 1;
  overflow-y: auto;
  padding: 16px var(--gutter) 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.modal-content .card { margin-left: 0; margin-right: 0; }

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeout { from { opacity: 1; } to { opacity: 0; } }
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
@keyframes slidedown { from { transform: none; } to { transform: translateY(100%); } }
.modal.closing { display: block; pointer-events: none; }
.modal.closing .modal-backdrop { animation: fadeout 220ms ease forwards; }
.modal.closing .modal-sheet { animation: slidedown 240ms cubic-bezier(0.4,0,1,1) forwards; }

@media (min-width: 720px) {
  :root { --gutter: 18px; }
  body { padding-bottom: 76px; }
  .app-shell { padding-bottom: 28px; }
  #home-content,
  #bots-content,
  #shadow-content,
  #system-content {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: start;
  }
  #journal-content {
    max-width: 720px;
    margin: 0 auto;
  }
  .card.hero,
  .card.pill,
  #home-content > .card:has(.empty),
  #system-content > .card:first-child {
    grid-column: 1 / -1;
  }
  .tabbar {
    width: min(720px, calc(100% - 32px));
    left: 50%;
    right: auto;
    bottom: 14px;
    transform: translateX(-50%);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 6px;
  }
  .modal-sheet {
    left: 50%;
    right: auto;
    width: min(620px, calc(100% - 32px));
    transform: translateX(-50%);
    border-radius: var(--radius) var(--radius) 0 0;
  }
  @keyframes slideup { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
  @keyframes slidedown { from { transform: translate(-50%, 0); } to { transform: translate(-50%, 100%); } }
}

@media (max-width: 430px) {
  .decision-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-chip { padding: 9px 11px 11px; font-size: 12.5px; }
  .filter-chip.active::after { left: 11px; right: 11px; }
  .live-chart-frame { height: 298px; }
  .live-chart-head { align-items: stretch; }
  .live-chart-tfs button { padding-left: 7px; padding-right: 7px; }
}

@media (max-width: 390px) {
  .hero-row,
  .bot-stats { gap: 10px 8px; }
  .hero-value { font-size: 37px; }
  .card { padding: 13px 14px; }
  .live-chart-frame { height: 276px; }
}

/* iOS Reduce Motion + Windows reduced-motion: kill slide-up / fade /
 * pulse animations and transitions. Preserve essential :active feedback
 * (scale 0.992) by leaving that opt-in below the strict reset. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .modal-sheet,
  .modal.closing .modal-sheet,
  .modal-backdrop,
  .modal.closing .modal-backdrop,
  .ptr-indicator.refreshing .ic,
  .icon-btn.refreshing .ic {
    animation: none !important;
  }
}
