:root {
  --bg: #0b1017;
  --bg-elevated: #121a24;
  --card: #141c28;
  --card-2: #1a2433;
  --border: #2a3648;
  --border-soft: color-mix(in srgb, var(--border) 70%, transparent);
  --text: #e8eef7;
  --muted: #8b9cb3;
  --ai: #3b82f6;
  --strat: #10b981;
  --grid: #a78bfa;
  --bybitgrid: #f59e0b;
  --teststrat: #38bdf8;
  --danger: #ef4444;
  --warn: #f59e0b;
  --pos: #34d399;
  --neg: #f87171;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  --shadow-soft: 0 4px 16px rgba(0, 0, 0, 0.18);
  --radius-panel: 16px;
  --radius-sm: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(56, 189, 248, 0.08), transparent 55%),
    radial-gradient(900px 500px at 90% 0%, rgba(16, 185, 129, 0.07), transparent 50%),
    radial-gradient(800px 480px at 70% 100%, rgba(245, 158, 11, 0.05), transparent 45%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); margin-top: 0.5rem; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* Full nav labels everywhere; short labels unused */
.lbl-full { display: inline; }
.lbl-short { display: none; }

.screen { min-height: 100vh; min-height: 100dvh; }

#login-screen.screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, var(--safe-top)) max(1rem, var(--safe-right)) max(1rem, var(--safe-bottom)) max(1rem, var(--safe-left));
  box-sizing: border-box;
}

.login-card {
  max-width: 380px;
  width: min(100%, 380px);
  margin: 0;
  padding: 1.65rem 1.5rem 1.55rem;
  background:
    linear-gradient(
      165deg,
      color-mix(in srgb, var(--ai) 10%, transparent) 0%,
      transparent 42%
    ),
    var(--card);
  border: 1px solid color-mix(in srgb, var(--ai) 22%, var(--border));
  border-radius: 14px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

@media (max-width: 640px) {
  .login-card {
    width: 100%;
    max-width: 26rem;
    padding: 1.25rem 1.1rem 1.35rem;
  }
  .login-card input {
    min-height: 2.6rem;
    font-size: 16px;
  }
  .login-card .btn {
    min-height: 2.75rem;
  }
}
.brand-title {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.brand-home-btn {
  margin: 0;
  padding: 0.15rem 0.2rem 0.15rem 0.1rem;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
  border-radius: 12px;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.brand-home-btn:hover {
  background: color-mix(in srgb, var(--ai) 8%, transparent);
}
.brand-home-btn:focus-visible {
  outline: 2px solid var(--ai);
  outline-offset: 3px;
}
.brand-home-btn h1 {
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 12px;
  background:
    linear-gradient(
      145deg,
      color-mix(in srgb, var(--ai) 28%, transparent),
      color-mix(in srgb, var(--strat) 12%, transparent)
    );
  border: 1px solid color-mix(in srgb, var(--ai) 30%, var(--border));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}
.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}
.brand-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}
.login-card .brand-icon { width: 2.5rem; height: 2.5rem; }
.login-card .brand-mark {
  width: 2.85rem;
  height: 2.85rem;
}
.login-card h1 { margin: 0; font-size: 1.4rem; }
.login-card .brand-title { margin: 0 0 0.35rem; }
.login-card label { display: block; margin: 1rem 0 0.35rem; font-size: 0.9rem; }
.login-card input {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}
.login-card .btn { width: 100%; margin-top: 1rem; }
.login-alt { margin-top: 1rem; text-align: center; }
.login-alt a { color: var(--ai); text-decoration: none; padding: 0.35rem; display: inline-block; }
.login-alt a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(0.35rem + var(--safe-top)) 0.75rem 0.35rem;
  border-bottom: 1px solid color-mix(in srgb, var(--ai) 18%, var(--border));
  flex-wrap: nowrap;
  gap: 0.55rem 0.75rem;
  position: sticky;
  top: 0;
  z-index: 200;
  min-height: 0;
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--ai) 12%, #0b1017) 0%,
      color-mix(in srgb, #0b1017 92%, transparent) 100%
    );
  backdrop-filter: blur(14px) saturate(1.15);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
}

.topbar::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    color-mix(in srgb, var(--ai) 70%, transparent) 22%,
    color-mix(in srgb, var(--strat) 55%, transparent) 55%,
    color-mix(in srgb, var(--bybitgrid) 45%, transparent) 78%,
    transparent 100%
  );
  pointer-events: none;
}

.topbar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;
  flex: 0 0 auto;
}

.topbar-brand { min-width: 0; }
.topbar .brand-home-btn {
  padding: 0.1rem 0.15rem 0.1rem 0.05rem;
  gap: 0.45rem;
}
.topbar .brand-mark {
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 9px;
}
.topbar .brand-icon { width: 1.1rem; height: 1.1rem; }
.topbar h1 {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.1;
  letter-spacing: 0.01em;
  font-weight: 700;
  white-space: nowrap;
}
.topbar-sub {
  display: none;
}

.menu-toggle {
  display: none;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  min-height: 2rem;
  padding-inline: 0.7rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--ai) 28%, var(--border));
  background: color-mix(in srgb, var(--ai) 12%, transparent);
}
.menu-icon { font-size: 1.05rem; line-height: 1; }
.menu-toggle-text { font-size: 0.82rem; }
.menu-desc {
  display: none;
  margin: 0 0 0.55rem;
  font-size: 0.78rem;
}

/* Compact one-line chip in the meta row */
.trades-summary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 14rem;
  min-width: 0;
  padding: 0.2rem 0.55rem;
  margin: 0;
  background:
    linear-gradient(
      145deg,
      color-mix(in srgb, var(--strat) 10%, transparent),
      transparent 55%
    ),
    color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--strat) 22%, var(--border));
  border-radius: 999px;
  font-size: 0.72rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: none;
}
.trades-summary .ts-label {
  color: var(--muted);
  font-size: 0.65rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-weight: 650;
  flex-shrink: 0;
}
.trades-summary > strong {
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trades-summary .ts-row {
  display: none;
}

@media (max-width: 900px) {
  .topbar:not(.is-menu-open) .trades-summary { display: none; }
  .trades-summary.is-empty { display: none !important; }
}

.topbar-menu {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.topbar-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  min-width: 0;
  width: 100%;
}
.toolbar-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.35rem;
}
.toolbar-main {
  justify-content: flex-end;
  gap: 0.35rem;
  min-width: 0;
  flex: 1 1 auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.toolbar-main::-webkit-scrollbar { display: none; }
.toolbar-meta {
  justify-content: flex-end;
  gap: 0.35rem;
  align-items: center;
  flex: 0 0 auto;
}
.last-update {
  font-size: 0.68rem;
  white-space: nowrap;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  border: 1px solid var(--border-soft);
}

.nav-group {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.12rem;
  padding: 0.12rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  border: 1px solid color-mix(in srgb, var(--ai) 14%, var(--border));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.nav-group-system {
  border-color: color-mix(in srgb, var(--bybitgrid) 18%, var(--border));
  background: color-mix(in srgb, var(--bybitgrid) 6%, color-mix(in srgb, var(--bg) 72%, transparent));
}

.btn-nav {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  min-height: 1.75rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px !important;
  border: 1px solid transparent !important;
  background: transparent !important;
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.1;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.btn-nav:hover {
  background: color-mix(in srgb, var(--ai) 16%, transparent) !important;
  border-color: color-mix(in srgb, var(--ai) 28%, transparent) !important;
}

.btn-nav:active {
  transform: translateY(1px);
}

.btn-nav .nav-glyph {
  display: inline-grid;
  place-items: center;
  width: 0.9rem;
  color: color-mix(in srgb, var(--ai) 70%, #fff);
  font-size: 0.72rem;
  opacity: 0.9;
}

.btn-nav-accent {
  background: color-mix(in srgb, var(--ai) 18%, transparent) !important;
  border-color: color-mix(in srgb, var(--ai) 32%, transparent) !important;
  color: #dbeafe;
}

.btn-nav-accent:hover {
  background: color-mix(in srgb, var(--ai) 28%, transparent) !important;
}

.btn-logout {
  min-height: 1.75rem;
  padding: 0.18rem 0.65rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--neg) 28%, var(--border));
  background: color-mix(in srgb, var(--neg) 10%, transparent);
  color: #fecaca;
  font-size: 0.74rem;
}

.btn-logout:hover {
  background: color-mix(in srgb, var(--neg) 18%, transparent);
  border-color: color-mix(in srgb, var(--neg) 42%, var(--border));
}

.server-status {
  font-size: 0.68rem;
  white-space: nowrap;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-elevated) 85%, transparent);
  border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.server-status.status-ok {
  color: color-mix(in srgb, var(--pos) 55%, var(--muted));
  border-color: color-mix(in srgb, var(--pos) 28%, var(--border));
  background: color-mix(in srgb, var(--pos) 8%, transparent);
}
.server-status.status-warn {
  color: #eab308;
  border-color: rgba(234, 179, 8, 0.35);
  background: rgba(234, 179, 8, 0.08);
}
.server-status.status-high {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.08);
}

.reconcile-banner {
  max-width: 920px;
  margin: 0.65rem auto 0;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.08);
  color: #fecaca;
  font-size: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}
.reconcile-banner.hidden { display: none; }
.reconcile-banner .reconcile-text { flex: 1 1 220px; }
.reconcile-banner .btn { flex-shrink: 0; }

.topbar-actions a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

.grid-2,
.grid-3,
.grid-4 {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: none;
  gap: 1.35rem;
  padding: 1.15rem 0 1.5rem;
  margin: 0;
}

.grid-2 .panel,
.grid-3 .panel,
.grid-4 .panel {
  width: 70%;
  max-width: 70vw;
  box-sizing: border-box;
}

.panel {
  --panel-accent: var(--ai);
  position: relative;
  isolation: isolate;
  background:
    linear-gradient(
      165deg,
      color-mix(in srgb, var(--panel-accent) 14%, transparent) 0%,
      transparent 42%
    ),
    linear-gradient(180deg, var(--card-2) 0%, var(--card) 100%);
  border: 1px solid color-mix(in srgb, var(--panel-accent) 28%, var(--border));
  border-radius: var(--radius-panel);
  padding: 1.1rem 1.25rem 1.2rem;
  min-width: 0;
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}


.panel::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--panel-accent) 95%, #fff),
    color-mix(in srgb, var(--panel-accent) 45%, transparent)
  );
  border-radius: var(--radius-panel) 0 0 var(--radius-panel);
  z-index: 1;
}

.panel::after {
  content: "";
  position: absolute;
  top: -40%;
  right: -12%;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--panel-accent) 18%, transparent),
    transparent 68%
  );
  pointer-events: none;
  z-index: 0;
}

.panel > * {
  position: relative;
  z-index: 1;
}

.panel:hover {
  border-color: color-mix(in srgb, var(--panel-accent) 42%, var(--border));
  box-shadow: var(--shadow);
}

.panel-strategy { --panel-accent: var(--strat); }
.panel-grid { --panel-accent: var(--grid); }
.panel-bybitgrid { --panel-accent: var(--bybitgrid); }
.panel-test-strategies { --panel-accent: var(--teststrat); }
.panel-finder,
.panel-finder-retired { --panel-accent: var(--ai); }

.badge-test {
  background: color-mix(in srgb, var(--teststrat) 22%, transparent);
  color: var(--teststrat);
  border: 1px solid color-mix(in srgb, var(--teststrat) 45%, transparent);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.65rem;
  margin-bottom: 0.95rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid color-mix(in srgb, var(--panel-accent) 16%, var(--border-soft));
}

.panel-head h2 {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.3;
  flex: 0 1 auto;
  letter-spacing: -0.01em;
  font-weight: 650;
}

.panel-head h2::before {
  content: "";
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  margin-right: 0.55rem;
  border-radius: 50%;
  background: var(--panel-accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--panel-accent) 22%, transparent);
  vertical-align: 0.08em;
}

.panel-head-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.panel-stats-btn {
  padding: 0.28rem 0.65rem;
  font-size: 0.72rem;
  white-space: nowrap;
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel-accent) 12%, transparent);
  border-color: color-mix(in srgb, var(--panel-accent) 30%, var(--border));
}

.panel-stats-btn:hover {
  background: color-mix(in srgb, var(--panel-accent) 22%, transparent);
}

.stats-modal-head {
  align-items: flex-start;
  gap: 0.75rem;
}

.stats-modal-head-main {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-width: 0;
}

.stats-period-toggle {
  display: inline-flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  padding: 0.25rem;
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  border: 1px solid var(--border);
  box-sizing: border-box;
  max-width: 100%;
  overflow: hidden;
}

.stats-period-btn {
  border-radius: 8px !important;
  border: none !important;
  background: transparent !important;
  min-height: 2rem;
  padding: 0.25rem 0.7rem;
  box-sizing: border-box;
  min-width: 0;
}

.stats-period-btn.is-active {
  background: color-mix(in srgb, var(--ai) 28%, transparent) !important;
  color: #dbeafe;
  box-shadow: none;
}

@media (max-width: 640px) {
  .stats-period-toggle {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 0.25rem;
    padding: 0.3rem;
    border-radius: 12px;
  }
  .stats-period-btn {
    width: 100%;
    min-height: 2.2rem;
    justify-content: center;
    padding: 0.35rem 0.45rem;
    font-size: 0.78rem;
  }
  .stats-period-btn[data-period="all"] {
    grid-column: 1 / -1;
  }
}

.badge {
  padding: 0.32rem 0.7rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  background: color-mix(in srgb, var(--border) 80%, transparent);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.badge.running {
  background: color-mix(in srgb, #059669 35%, #064e3b);
  color: #a7f3d0;
  border-color: color-mix(in srgb, #34d399 45%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, #10b981 16%, transparent);
}
.badge.stopped {
  background: color-mix(in srgb, #7f1d1d 55%, #1a1010);
  color: #fecaca;
  border-color: color-mix(in srgb, #f87171 35%, transparent);
}

.ml-gate-badge {
  margin: 0 0 0.9rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  line-height: 1.45;
  background: color-mix(in srgb, var(--panel-accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--panel-accent) 32%, transparent);
  color: color-mix(in srgb, var(--panel-accent) 72%, #fff);
}

/* Compact tips — opened on demand, don't clutter the panel */
.ui-hint {
  position: relative;
  display: inline-flex;
  align-items: flex-start;
  margin: 0;
  vertical-align: middle;
}

.ui-hint-btn {
  list-style: none;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  width: 1.1rem;
  height: 1.1rem;
  min-width: 1.1rem;
  padding: 0;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--panel-accent, var(--ai)) 28%, var(--border));
  background: transparent;
  color: color-mix(in srgb, var(--panel-accent, var(--ai)) 65%, var(--muted));
  font-size: 0.68rem;
  font-weight: 650;
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1;
  flex-shrink: 0;
  touch-action: manipulation;
  user-select: none;
  opacity: 0.85;
  position: relative;
}

/* Invisible hit pad — icon stays small, tap area ~36px */
.ui-hint-btn::after {
  content: "";
  position: absolute;
  inset: -0.55rem;
}

.ui-hint-btn::-webkit-details-marker { display: none; }
.ui-hint-btn::marker { content: ""; }

.ui-hint-btn:hover,
.ui-hint[open] > .ui-hint-btn {
  opacity: 1;
  background: color-mix(in srgb, var(--panel-accent, var(--ai)) 14%, transparent);
  border-color: color-mix(in srgb, var(--panel-accent, var(--ai)) 45%, var(--border));
  color: color-mix(in srgb, var(--panel-accent, var(--ai)) 80%, #fff);
}

.ui-hint-body {
  position: absolute;
  z-index: 60;
  left: 0;
  top: calc(100% + 0.35rem);
  width: min(18.5rem, calc(100vw - 1.5rem));
  max-width: calc(100vw - 1.5rem);
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--panel-accent, var(--ai)) 28%, var(--border));
  background: var(--card, #1a2332);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--muted);
  font-weight: 400;
  font-style: normal;
  box-sizing: border-box;
  overflow-wrap: anywhere;
  word-break: break-word;
  -webkit-overflow-scrolling: touch;
}

/* Keep overflow open as fallback; do NOT raise z-index — that covers the sticky topbar. */
.panel:has(.ui-hint[open]:not(.ui-hint-block)),
.collapsible-section:has(.ui-hint[open]:not(.ui-hint-block)) {
  overflow: visible;
}

@media (max-width: 960px) {
  .ui-hint-btn {
    width: 1.1rem;
    height: 1.1rem;
    min-width: 1.1rem;
    font-size: 0.68rem;
    border-color: color-mix(in srgb, var(--panel-accent, var(--ai)) 32%, var(--border));
    color: color-mix(in srgb, var(--panel-accent, var(--ai)) 70%, var(--muted));
    background: transparent;
    opacity: 0.92;
  }

  .ui-hint-btn:hover,
  .ui-hint[open] > .ui-hint-btn {
    opacity: 1;
    background: color-mix(in srgb, var(--panel-accent, var(--ai)) 12%, transparent);
  }

  /*
   * Keep the «i» button beside the title; only the tip text drops below.
   * Critical: .ui-hint must be position:static so absolute body uses the
   * title-row as containing block — otherwise width ≈ 1rem → one letter per line.
   */
  .panel-title-row,
  .settings-section-head,
  .strategy-toggle-title-row,
  .collapsible-title-group,
  .strategy-dual-hedge-row,
  .strategy-risk-title,
  .strategy-enable-bulk-head,
  .strategy-ml-conf-bulk-head,
  .ui-hint-row,
  .collapsible-toggle {
    position: relative;
  }

  .panel-title-row,
  .settings-section-head,
  .strategy-toggle-title-row,
  .collapsible-title-group,
  .strategy-dual-hedge-row,
  .strategy-risk-title,
  .strategy-enable-bulk-head,
  .strategy-ml-conf-bulk-head,
  .ui-hint-row {
    flex-wrap: nowrap;
    align-items: center;
  }

  .ui-hint:not(.ui-hint-block) {
    position: static;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    width: auto;
    max-width: none;
  }

  .ui-hint:not(.ui-hint-block)[open] {
    display: inline-flex;
    flex: 0 0 auto;
    width: auto;
    max-width: none;
  }

  .settings-section-head .ui-hint:not(.ui-hint-block) .ui-hint-body,
  .strategy-toggle-title-row .ui-hint:not(.ui-hint-block) .ui-hint-body,
  .strategy-dual-hedge-row .ui-hint:not(.ui-hint-block) .ui-hint-body,
  .strategy-risk-title .ui-hint:not(.ui-hint-block) .ui-hint-body,
  .strategy-enable-bulk-head .ui-hint:not(.ui-hint-block) .ui-hint-body,
  .strategy-ml-conf-bulk-head .ui-hint:not(.ui-hint-block) .ui-hint-body,
  .ui-hint-row .ui-hint:not(.ui-hint-block) .ui-hint-body,
  .collapsible-toggle .ui-hint:not(.ui-hint-block):not(.collapsible-title-hint) .ui-hint-body {
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    top: calc(100% + 0.35rem) !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    max-height: min(50vh, 16rem);
    overflow-x: hidden;
    overflow-y: auto;
    margin-top: 0;
    box-sizing: border-box;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
    transform: none !important;
    z-index: 40 !important;
    white-space: normal;
    word-break: normal;
    overflow-wrap: anywhere;
  }

  /* Section / panel «i» tips: JS sets left/top (fixed). Do NOT force
     left/top:auto !important — that overrides inline coords and parks
     the tip under the next blocks on mobile. */
  .collapsible-toggle .collapsible-title-hint .ui-hint-body,
  .collapsible-title-group > .collapsible-title-hint .ui-hint-body,
  .panel-title-row .ui-hint:not(.ui-hint-block) .ui-hint-body,
  .panel-head > .ui-hint:not(.ui-hint-block) .ui-hint-body {
    position: fixed !important;
    right: auto;
    bottom: auto;
    max-width: calc(100vw - 1.25rem) !important;
    z-index: 150 !important;
  }

  .collapsible-toggle .collapsible-title-hint {
    align-self: center;
  }

  .panel-title-row,
  .settings-section-head,
  .strategy-toggle-title-row {
    gap: 0.35rem;
  }

  .panel-head .ui-hint,
  .settings-section-head .ui-hint,
  .collapsible-title-hint {
    margin-left: 0;
  }
}


.ui-hint-body strong {
  color: var(--text);
  font-weight: 600;
}

.ui-hint-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin: 0 0 0.65rem;
}

.ui-hint-row .ui-hint-label {
  font-size: 0.78rem;
  color: var(--muted);
}

.panel-head .ui-hint {
  margin-left: 0;
}

.panel-title-row {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  flex-wrap: wrap;
  width: fit-content;
  max-width: 100%;
}

.panel-title-row h2 {
  margin: 0;
  flex: 0 1 auto;
  width: auto;
  max-width: 100%;
}

.strategy-toggle-title-row {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  flex-wrap: nowrap;
  width: 100%;
  max-width: 100%;
}

.strategy-toggle-title-row > strong {
  flex: 1 1 auto;
  min-width: 0;
}

.strategy-toggle-title-row > .ui-hint {
  flex: 0 0 auto;
  margin: 0.15rem 0 0;
  align-self: flex-start;
}

.modal-head .panel-title-row {
  flex: 1;
  min-width: 0;
}

.modal-head .panel-title-row h2 {
  margin: 0;
}

.strategy-risk-bar-inner .ui-hint,
.strategy-enable-bulk-inner .ui-hint,
.strategy-ml-conf-bulk-inner .ui-hint {
  margin-left: 0.15rem;
}

.ui-hint-block {
  display: block;
  margin: 0 0 0.65rem;
}

.ui-hint-block > .ui-hint-btn {
  width: auto;
  height: auto;
  min-width: 0;
  padding: 0.28rem 0.55rem;
  border-radius: 8px;
  font-style: normal;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  gap: 0.25rem;
}

.ui-hint-block > .ui-hint-btn::before {
  content: "i";
  display: inline-grid;
  place-items: center;
  width: 1rem;
  height: 1rem;
  margin-right: 0.3rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel-accent, var(--ai)) 25%, transparent);
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 0.7rem;
}

.ui-hint-block .ui-hint-body {
  position: static;
  width: auto;
  max-width: none;
  margin-top: 0.4rem;
  box-shadow: none;
}

.settings-section-head {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  margin-bottom: 0.55rem;
  width: fit-content;
  max-width: 100%;
}

.settings-section-head h3 {
  margin: 0;
  flex: 0 1 auto;
}

.settings-section-head .ui-hint {
  flex: 0 0 auto;
  align-self: center;
}

.panel-retired-note {
  margin: 0 0 0.85rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  line-height: 1.45;
  background: rgba(127, 29, 29, 0.18);
  border: 1px solid rgba(248, 113, 113, 0.28);
  color: #fca5a5;
}

.panel-finder,
.panel-finder-retired {
  opacity: 0.9;
}

.info-block.info-ml {
  border-left: 3px solid #3b82f6;
  padding-left: 0.75rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-bottom: 1rem;
}
.stat {
  background:
    linear-gradient(
      160deg,
      color-mix(in srgb, var(--panel-accent) 8%, transparent),
      transparent 55%
    ),
    var(--bg-elevated);
  padding: 0.7rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--panel-accent) 14%, var(--border));
  font-size: 0.82rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
.stat strong {
  display: block;
  font-size: 1.02rem;
  margin-top: 0.2rem;
  word-break: break-word;
  letter-spacing: -0.01em;
}
.stat-hint {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 400;
  margin-top: 0.2rem;
}

.stat-trades-limit strong {
  display: block;
  margin-bottom: 0.35rem;
}

.stat-per-strategy {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.5rem;
  margin-top: 0.55rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.stat-per-strategy .stat-inline-label {
  font-weight: 600;
  font-size: 0.78rem;
  width: 100%;
}

.stat-per-strategy .stat-hint {
  margin-top: 0;
  flex: 1 1 auto;
}

.numeric-setting {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.15rem;
}

.numeric-setting-input {
  width: 4.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  text-align: center;
}

.numeric-setting-suffix {
  font-size: 0.78rem;
  color: var(--muted);
}

.numeric-setting-save {
  flex-shrink: 0;
}

.stat-stake-limit {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.stat-stake-limit .numeric-setting-stake {
  margin-left: auto;
}

.stat-inline-label {
  font-size: 0.82rem;
}

.max-trades-row .numeric-setting {
  margin-top: 0;
}

.bybitgrid-max-bots-label .numeric-setting-input {
  width: 100%;
  margin-top: 0.25rem;
  text-align: left;
}

.max-trades-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.max-trades-row:last-of-type {
  border-bottom: none;
  margin-bottom: 0.5rem;
}

.max-trades-label {
  min-width: 6.5rem;
  font-weight: 600;
}

.max-trades-hint {
  font-size: 0.78rem;
}

.strategy-risk-bar {
  margin: 0.35rem 0 0.75rem;
  padding: 0.7rem 0.8rem;
  background:
    linear-gradient(
      140deg,
      color-mix(in srgb, var(--panel-accent) 10%, transparent),
      transparent 60%
    ),
    var(--bg-elevated);
  border: 1px solid color-mix(in srgb, var(--panel-accent) 22%, var(--border));
  border-radius: 12px;
}

.strategy-risk-bar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.strategy-risk-title {
  font-weight: 600;
  font-size: 0.9rem;
  min-width: 5.5rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.strategy-risk-hint {
  font-size: 0.78rem;
  flex: 1 1 100%;
}

.strategy-risk-row {
  margin: 0.35rem 0 0.75rem;
  padding-top: 0.25rem;
  border-bottom: none;
}

.strategy-risk-setting {
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.strategy-risk-field {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.strategy-risk-field .numeric-setting-input {
  width: 4.25rem;
}

.settings-strategy .strategy-risk-row {
  margin-top: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.strategy-dual-hedge {
  margin: 0 0 0.75rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2, rgba(255, 255, 255, 0.02));
}

.strategy-dual-hedge-label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  font-size: 0.88rem;
}

.strategy-dual-hedge-label input {
  margin-top: 0;
}

.strategy-dual-hedge-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.strategy-dual-hedge-hint {
  display: none;
}

.strategy-ml-conf-bulk {
  margin: 0 0 0.55rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2, rgba(255, 255, 255, 0.02));
}

/* ML menus use position:fixed — do not flip overflow:visible (that
   inflated the test-strategies list scroll area with empty gaps). */

.strategy-enable-bulk {
  margin: 0 0 0.55rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2, rgba(255, 255, 255, 0.02));
}

.strategy-enable-bulk-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.75rem;
}

.strategy-enable-bulk-head,
.strategy-ml-conf-bulk-head {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  min-width: 0;
}

.strategy-ml-conf-bulk-head {
  /* Grow horizontally in a row; never use 10rem basis — in column
     (mobile) that became ~160px of empty height under the title. */
  flex: 1 1 auto;
  min-width: min(100%, 10rem);
}

.strategy-ml-conf-bulk-title,
.strategy-enable-bulk-label {
  font-size: 0.88rem;
  font-weight: 600;
}

.strategy-enable-bulk-count {
  font-size: 0.82rem;
}

.strategy-enable-bulk-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-left: auto;
}

.strategy-enable-bulk-hint {
  margin: 0.4rem 0 0;
  font-size: 0.78rem;
}

.strategy-ml-conf-bulk-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.65rem;
}

.strategy-ml-conf-bulk-picker {
  flex: 1 1 12rem;
  min-width: 0;
  padding: 0 !important;
  border-top: none !important;
  margin: 0 !important;
}

.strategy-ml-conf-bulk-picker .strategy-ml-conf-menu {
  left: 0;
  right: 0;
}

.strategy-ml-conf-bulk-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-left: auto;
}

.strategy-ml-conf-bulk-hint {
  display: none;
}

.settings-max-trades {
  margin-top: 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.settings-strategy {
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.strategy-picker {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.75rem 0 0.35rem;
  font-size: 0.88rem;
}

.strategy-picker select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.panel-note {
  margin: 0 0 0.65rem;
  font-size: 0.82rem;
  line-height: 1.4;
}

.bot-settings-collapsible {
  margin-top: 0.55rem;
  margin-bottom: 0.65rem;
}

.bot-overview-stats {
  margin: 0.55rem 0 0.45rem;
}

.bot-overview-actions.actions {
  margin-bottom: 0.55rem;
}

.bot-settings-collapsible .collapsible-body .stats {
  margin-bottom: 0.75rem;
}

.bot-settings-collapsible .strategy-risk-bar,
.bot-settings-collapsible .strategy-dual-hedge {
  margin-bottom: 0.65rem;
}

.bybitgrid-defaults-title {
  margin: 0.85rem 0 0.35rem;
  font-size: 0.88rem;
  font-weight: 650;
}

.collapsible-section {
  margin: 1rem 0;
  border: 1px solid color-mix(in srgb, var(--panel-accent) 16%, var(--border));
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg-elevated) 90%, transparent);
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.025);
}


.collapsible-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.85rem;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
  font: inherit;
  touch-action: manipulation;
  transition: background 0.15s ease;
}

.collapsible-toggle:hover {
  background: color-mix(in srgb, var(--panel-accent) 8%, transparent);
}

.collapsible-title {
  font-size: 0.92rem;
  font-weight: 650;
  color: var(--text);
  flex-shrink: 0;
}

.collapsible-title-group {
  display: inline-flex;
  align-items: center;
  gap: 0.16rem;
  flex: 0 1 auto;
  flex-shrink: 1;
  min-width: 0;
  max-width: 100%;
  width: fit-content;
}

.collapsible-title-hint {
  flex-shrink: 0;
  margin: 0;
}

.collapsible-sub {
  flex: 1;
  min-width: 0;
  font-size: 0.78rem;
  line-height: 1.35;
  text-align: right;
}

.collapsible-chevron {
  flex-shrink: 0;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.collapsible-section.is-expanded .collapsible-chevron {
  transform: rotate(90deg);
}

.collapsible-section.is-collapsed .collapsible-body {
  display: none;
}

.collapsible-section.is-expanded .collapsible-body {
  padding: 0 0.75rem 0.75rem;
  border-top: 1px solid var(--border);
}

.trades-collapsible {
  margin-top: 0.85rem;
}

.trades-collapsible .trades-list {
  margin-top: 0.35rem;
}

.trades-collapsible .empty {
  margin: 0.15rem 0 0;
}

.collapsible-section.is-expanded .panel-note {
  margin-top: 0.65rem;
}

.pairs-collapsible {
  margin-top: 0.85rem;
  margin-bottom: 0;
}

.pairs-collapsible .collapsible-body .pairs {
  margin: 0.65rem 0 0;
}

#pair-lists-body h3 {
  margin: 0.85rem 0 0.45rem;
  font-size: 0.85rem;
  color: var(--muted);
}

#pair-lists-body h3:first-child {
  margin-top: 0.65rem;
}

#strategy-panel-toggles {
  margin-bottom: 0;
}

.strategy-toggle-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.strategy-toggle-item {
  position: relative;
  z-index: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}


.strategy-toggle-item.is-inverted {
  border-color: color-mix(in srgb, var(--strat, #3b82f6) 45%, var(--border));
}

.strategy-toggle-label {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem 0.35rem;
  cursor: pointer;
}

.strategy-toggle-main {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  flex: 1 1 auto;
  min-width: 0;
}

.strategy-toggle-main .strategy-toggle-label {
  flex: 1 1 auto;
  min-width: 0;
}

.strategy-toggle-main > .ui-hint {
  margin: 0;
  flex-shrink: 0;
  align-self: center;
}

.strategy-dual-hedge-title-text {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.strategy-toggle-label input {
  margin-top: 0.2rem;
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
  accent-color: var(--strat);
}

.strategy-toggle-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.strategy-toggle-text strong {
  font-size: 0.92rem;
}

.strategy-inv-badge {
  display: inline-block;
  margin-left: 0.25rem;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  vertical-align: middle;
  color: #fff;
  background: var(--strat, #3b82f6);
}

.strategy-train-badge {
  display: inline-block;
  margin-left: 0.25rem;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  vertical-align: middle;
  color: #0b1f17;
  background: color-mix(in srgb, #34d399 75%, #fff);
}

.strategy-ml-badge {
  display: inline-block;
  margin-left: 0.25rem;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  vertical-align: middle;
  color: #1e293b;
  background: color-mix(in srgb, #94a3b8 35%, #fff);
}

.strategy-toggle-item.is-trained-risk {
  border-color: color-mix(in srgb, #34d399 40%, var(--border));
}

.strategy-trained-risk-switch.is-on .strategy-invert-slider {
  background: #34d399;
}

.strategy-ml-conf {
  position: relative;
  padding: 0.25rem 0.65rem 0.4rem;
  border-top: 1px dashed var(--border);
  margin-top: 0.1rem;
}

.strategy-ml-conf-btn {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--bg, #0f172a) 92%, #fff);
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.strategy-ml-conf-btn:hover {
  border-color: color-mix(in srgb, var(--strat, #3b82f6) 45%, var(--border));
}

.strategy-ml-conf-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.strategy-ml-conf-label {
  flex: 1;
  font-size: 0.78rem;
  color: var(--muted, #8b93a7);
}

.strategy-ml-conf-value {
  font-size: 0.82rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.strategy-ml-conf-caret {
  font-size: 0.75rem;
  color: var(--muted, #8b93a7);
}

.strategy-ml-conf.is-open .strategy-ml-conf-caret {
  transform: rotate(180deg);
}

.strategy-ml-conf-menu {
  position: absolute;
  left: 0.65rem;
  right: 0.65rem;
  top: calc(100% + 0.2rem);
  bottom: auto;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
  max-height: min(14rem, 45vh);
  overflow: auto;
  padding: 0.28rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card, var(--panel, #1a2332));
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

.strategy-ml-conf-menu.opens-up {
  top: auto;
  bottom: calc(100% + 0.2rem);
  box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.28);
}


.strategy-ml-conf-menu[hidden] {
  display: none !important;
}

.strategy-ml-conf-option {
  display: block;
  width: 100%;
  padding: 0.32rem 0.5rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  text-align: left;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

.strategy-ml-conf-option:hover {
  background: color-mix(in srgb, var(--strat, #3b82f6) 18%, transparent);
}

.strategy-ml-conf-option.is-selected {
  background: color-mix(in srgb, var(--strat, #3b82f6) 28%, transparent);
  font-weight: 650;
}

.strategy-toggle-desc {
  font-size: 0.78rem;
  line-height: 1.35;
}

.strategy-invert-switch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem 0.65rem;
  cursor: pointer;
  user-select: none;
  border-top: 1px dashed var(--border);
  margin-top: 0.15rem;
}

.strategy-invert-text {
  font-size: 0.78rem;
  color: var(--muted, #8b93a7);
  flex: 1;
}

.strategy-invert-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.strategy-invert-slider {
  position: relative;
  width: 2.4rem;
  height: 1.25rem;
  border-radius: 999px;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.strategy-invert-slider::after {
  content: "";
  position: absolute;
  top: 0.15rem;
  left: 0.15rem;
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease;
}

.strategy-invert-switch input:checked + .strategy-invert-slider {
  background: var(--strat, #3b82f6);
}

.strategy-invert-switch input:checked + .strategy-invert-slider::after {
  transform: translateX(1.1rem);
}

.strategy-invert-switch input:disabled + .strategy-invert-slider {
  opacity: 0.55;
}

.strategy-active.warn {
  color: var(--warn);
}

.strategy-desc {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  line-height: 1.45;
}

.panel-title h2 {
  margin: 0;
}

.strategy-active {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
}

.panel-head .panel-title {
  flex: 1 1 auto;
  min-width: 0;
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.btn {
  padding: 0.55rem 0.85rem;
  min-height: 44px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 80%, #000);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.15s ease, transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover {
  filter: brightness(1.08);
  border-color: color-mix(in srgb, var(--panel-accent, var(--ai)) 35%, var(--border));
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--ai) 90%, #fff), var(--ai));
  border-color: var(--ai);
  color: #fff;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--ai) 26%, transparent);
}
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn-sm { min-height: 38px; padding: 0.35rem 0.65rem; font-size: 0.78rem; }

.panel-strategy .btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--strat) 88%, #fff), var(--strat));
  border-color: var(--strat);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--strat) 26%, transparent);
}
.panel-grid .btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--grid) 88%, #fff), var(--grid));
  border-color: var(--grid);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--grid) 26%, transparent);
}
.panel-bybitgrid .btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--bybitgrid) 88%, #fff), var(--bybitgrid));
  border-color: var(--bybitgrid);
  color: #1a1200;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--bybitgrid) 26%, transparent);
}
.panel-test-strategies .btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--teststrat) 88%, #fff), var(--teststrat));
  border-color: var(--teststrat);
  color: #0b1220;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--teststrat) 26%, transparent);
}
.test-strategy-isolate-note {
  margin: -0.2rem 0 0.9rem;
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  font-size: 0.78rem;
  line-height: 1.45;
  background: color-mix(in srgb, var(--teststrat) 8%, transparent);
  border: 1px dashed color-mix(in srgb, var(--teststrat) 35%, transparent);
  color: color-mix(in srgb, var(--teststrat) 55%, var(--muted));
}
.panel-finder-retired {
  opacity: 0.88;
}
.panel-finder-retired .panel-retired-note {
  margin: 0 0 0.85rem;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--muted);
}

.grid-scan-info,
.strategy-scan-info {
  margin: -0.25rem 0 0.75rem;
  font-size: 0.78rem;
  line-height: 1.4;
}

h3 { font-size: 0.92rem; margin: 1rem 0 0.5rem; color: var(--muted); }

.trades-list { display: flex; flex-direction: column; gap: 0.75rem; }

.trade-card {
  background:
    linear-gradient(
      145deg,
      color-mix(in srgb, var(--panel-accent) 6%, transparent),
      transparent 50%
    ),
    var(--bg-elevated);
  border: 1px solid color-mix(in srgb, var(--panel-accent) 14%, var(--border));
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.trade-card:hover {
  border-color: color-mix(in srgb, var(--panel-accent) 32%, var(--border));
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.trade-summary {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
}

.trade-toggle {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.15rem 0.25rem;
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.trade-summary-main {
  flex: 1;
  min-width: 0;
}

.trade-chevron {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.85rem;
  transition: transform 0.15s ease;
}

.trade-card.is-expanded .trade-chevron {
  transform: rotate(90deg);
}

.trade-card.is-collapsed .trade-details {
  display: none;
}

.trade-card.is-expanded .trade-details {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.trade-summary .btn.danger {
  flex-shrink: 0;
  align-self: center;
  padding: 0.35rem 0.55rem;
  font-size: 0.75rem;
}

.trade-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--border);
}
.trade-pair { font-size: 0.95rem; display: block; word-break: break-word; }
.trade-meta { font-size: 0.75rem; color: var(--muted); display: block; margin-top: 0.1rem; }
.trade-head-right { text-align: right; flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 0.2rem; }
.trade-ml-badge {
  display: inline-block;
  padding: 0.12rem 0.4rem;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 600;
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(96, 165, 250, 0.35);
  color: #93c5fd;
  line-height: 1.2;
}
.trade-ml-badge.is-missing {
  background: rgba(148, 163, 184, 0.12);
  border-color: rgba(148, 163, 184, 0.3);
  color: #94a3b8;
  font-weight: 500;
}
.history-chip-ml {
  background: rgba(59, 130, 246, 0.14);
  border: 1px solid rgba(96, 165, 250, 0.3);
  color: #93c5fd;
}
.history-chip-ml.is-missing {
  background: rgba(148, 163, 184, 0.1);
  border-color: rgba(148, 163, 184, 0.25);
  color: #94a3b8;
}
.trade-pnl { display: block; font-weight: 700; font-size: 1rem; }
.trade-rate { font-size: 0.78rem; color: var(--muted); }

.trade-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem 0.75rem;
}

.trade-field {
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  min-width: 0;
}
.trade-field span { color: var(--muted); }
.trade-field strong { font-weight: 600; word-break: break-word; }

.trade-actions { margin-top: 0.75rem; }
.trade-actions .btn { width: 100%; }

.stats-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin-bottom: 1.1rem;
}

.stats-kpi {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.03), transparent 42%),
    var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.8rem 0.85rem 0.85rem;
  font-size: 0.78rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.stats-kpi::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--muted);
  opacity: 0.65;
}

.stats-kpi span {
  display: block;
  color: var(--muted);
  margin-bottom: 0.3rem;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 650;
}

.stats-kpi strong {
  font-size: 1.12rem;
  word-break: break-word;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.stats-kpi-income {
  border-color: color-mix(in srgb, var(--pos) 28%, var(--border));
  background:
    linear-gradient(155deg, color-mix(in srgb, var(--pos) 12%, transparent), transparent 55%),
    var(--bg-elevated);
}
.stats-kpi-income::before { background: var(--pos); opacity: 1; }

.stats-kpi-expense {
  border-color: color-mix(in srgb, var(--neg) 28%, var(--border));
  background:
    linear-gradient(155deg, color-mix(in srgb, var(--neg) 12%, transparent), transparent 55%),
    var(--bg-elevated);
}
.stats-kpi-expense::before { background: var(--neg); opacity: 1; }

.stats-kpi-net {
  border-color: color-mix(in srgb, var(--ai) 28%, var(--border));
  background:
    linear-gradient(155deg, color-mix(in srgb, var(--ai) 12%, transparent), transparent 55%),
    var(--bg-elevated);
}
.stats-kpi-net::before { background: var(--ai); opacity: 1; }

.stats-kpi-ratio {
  border-color: color-mix(in srgb, var(--bybitgrid) 24%, var(--border));
  background:
    linear-gradient(155deg, color-mix(in srgb, var(--bybitgrid) 10%, transparent), transparent 55%),
    var(--bg-elevated);
}
.stats-kpi-ratio::before { background: var(--bybitgrid); opacity: 1; }

.stats-load-warn {
  grid-column: 1 / -1;
  margin: 0;
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 180, 80, 0.35);
  background: rgba(255, 180, 80, 0.08);
  color: var(--text);
  font-size: 0.85rem;
}

.stats-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.stats-table th,
.stats-table td {
  padding: 0.7rem 0.7rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  text-align: left;
  vertical-align: top;
}

.stats-table th {
  color: var(--muted);
  font-weight: 650;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  background: color-mix(in srgb, var(--card) 70%, transparent);
  position: sticky;
  top: 0;
  z-index: 1;
}

.stats-table td:not(:first-child),
.stats-table th:not(:first-child) {
  text-align: right;
  white-space: nowrap;
}

.stats-table tbody tr {
  transition: background 0.12s ease;
}

.stats-table tbody tr:hover {
  background: color-mix(in srgb, var(--ai) 7%, transparent);
}

.stats-table tbody tr:last-child td {
  border-bottom: none;
}

.stats-table tbody tr.stats-row-idle {
  opacity: 0.5;
}

.stats-footnote {
  margin: 0.35rem 0 0;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  font-size: 0.78rem;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  border: 1px dashed var(--border);
}

.stats-history-section {
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.stats-history-toggle {
  width: 100%;
  justify-content: center;
  gap: 0.35rem;
}

.stats-history-chevron {
  font-size: 0.75rem;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.stats-history-toggle[aria-expanded="true"] .stats-history-chevron {
  transform: rotate(180deg);
}

.stats-history {
  margin-top: 0.65rem;
}

.stats-history-note {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
}

.stats-history-wrap {
  max-height: min(42vh, 320px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}

.stats-history-table th:first-child,
.stats-history-table td:first-child {
  white-space: nowrap;
}

.stats-history-table td:nth-child(3) {
  word-break: break-word;
  max-width: 7rem;
}

.stats-history-empty td {
  text-align: center;
  color: var(--muted);
  padding: 1rem !important;
}

.bybitgrid-history-section {
  margin-top: 0.5rem;
}

.bybitgrid-history .trades-list {
  max-height: min(36vh, 280px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.bybitgrid-settings {
  margin: 0.75rem 0 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.bybitgrid-settings h3 {
  margin: 0 0 0.65rem;
  font-size: 0.85rem;
}

.bybitgrid-settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem 0.75rem;
  align-items: end;
}

.bybitgrid-settings-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.bybitgrid-settings-grid input {
  font-size: 0.85rem;
}

.bybitgrid-settings-grid .stat-trades-limit {
  grid-column: 1 / -1;
}

.bybitgrid-settings-save {
  grid-column: 1 / -1;
  justify-self: start;
}

.bybitgrid-settings-note {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.72rem;
}

.bybitgrid-hint.funding-warn {
  color: #fbbf24;
  font-size: 0.82rem;
}

.pairs { font-size: 0.78rem; line-height: 1.55; word-break: break-word; }
.empty { color: var(--muted); font-size: 0.85rem; padding: 0.5rem 0; }

.modal-card-wide {
  max-width: 560px;
}

#stats-modal .stats-modal-card {
  max-width: min(980px, calc(100vw - 1.5rem));
}

#stats-modal .stats-table {
  min-width: 720px;
  table-layout: auto;
}

#stats-modal .stats-table th:first-child,
#stats-modal .stats-table td:first-child {
  min-width: 12rem;
  max-width: none;
}

#stats-modal .stats-table th:not(:first-child),
#stats-modal .stats-table td:not(:first-child) {
  min-width: 5.5rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 8, 16, 0.72);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  width: 100%;
  max-height: 92vh;
  max-height: 92dvh;
  overflow: auto;
  background:
    radial-gradient(700px 280px at 10% -20%, rgba(59, 130, 246, 0.12), transparent 55%),
    linear-gradient(180deg, var(--card-2) 0%, var(--card) 100%);
  border: 1px solid color-mix(in srgb, var(--ai) 22%, var(--border));
  border-radius: 18px 18px 0 0;
  padding: 1.05rem 1.05rem calc(1.05rem + var(--safe-bottom));
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.35);
  -webkit-overflow-scrolling: touch;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(8px);
  padding-bottom: 0.55rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  z-index: 1;
}
.modal-head h2 {
  margin: 0;
  font-size: 1.08rem;
  letter-spacing: -0.015em;
  font-weight: 700;
}
.modal-note { margin: 0 0 1rem; font-size: 0.82rem; line-height: 1.45; }

.info-block {
  margin-bottom: 1rem;
  padding: 0.75rem;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.info-block h3 {
  margin: 0 0 0.4rem;
  font-size: 0.92rem;
  color: var(--ai);
}

.info-subhead {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
}

.info-desc {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--muted);
}

.info-desc strong {
  color: var(--text);
}

.info-strategy-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  max-height: min(55vh, 420px);
  overflow-y: auto;
}

.info-strategy-item {
  padding: 0.75rem;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.info-strategy-name {
  display: block;
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
  color: var(--strat);
}

.info-strategy-desc {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--muted);
}

.modal-note code {
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  word-break: break-all;
}

.settings-add {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.settings-add input {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}
.settings-add .btn { width: 100%; }

.settings-view {
  overflow: hidden;
}

.settings-page {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.25rem 0 1.25rem;
  -webkit-overflow-scrolling: touch;
}

.settings-page .settings-section {
  margin-top: 1.25rem;
  padding: 1rem 1.05rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
}

.settings-page .settings-section:first-child {
  margin-top: 0.35rem;
}

.settings-page .settings-section > h3 {
  margin: 0 0 0.45rem;
  font-size: 1rem;
}

.settings-page .settings-section-head h3 {
  margin: 0;
  font-size: 1rem;
}

.settings-toggle-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.35rem 0;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
}

.settings-toggle-row input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  flex: 0 0 auto;
}

.telegram-notify-kinds {
  margin: 0.55rem 0 0.25rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--card) 88%, var(--bg));
}

.telegram-notify-kinds-title {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
}

.telegram-notify-kinds.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.telegram-notify-kinds .settings-toggle-row {
  margin: 0.28rem 0;
  font-size: 0.84rem;
}

.settings-toolbar {
  position: sticky;
  top: 0;
  z-index: 4;
  background: var(--bg);
}

@media (max-width: 640px) {
  #settings-view.logs-view {
    height: calc(100dvh - 3.5rem);
    max-height: calc(100dvh - 3.5rem);
    padding: 0 0.55rem calc(0.55rem + var(--safe-bottom));
  }

  .settings-page .settings-section {
    padding: 0.85rem 0.75rem;
  }
}


.pair-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.pair-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  background: var(--bg);
  border-radius: 10px;
  font-size: 0.82rem;
}
.pair-list li span { flex: 1; min-width: 0; word-break: break-word; }
.pair-list li .btn { flex-shrink: 0; }
.pair-list.muted-list li { opacity: 0.85; }
.empty-li { justify-content: flex-start !important; color: var(--muted); }

.pair-msg {
  font-size: 0.82rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  line-height: 1.4;
}
.pair-msg.ok { background: rgba(16, 185, 129, 0.15); color: var(--pos); }
.trade-card-closed { opacity: 0.75; border-left: 3px solid var(--muted); }
.pair-msg.error { background: rgba(239, 68, 68, 0.15); color: var(--neg); }
.trade-card-closed { opacity: 0.75; border-left: 3px solid var(--muted); }

.bg-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.bg-row label, #bybitgrid-modal > .modal-card > label {
  display: block;
  font-size: 0.85rem;
  margin-top: 0.65rem;
}
.bg-row input, .bg-row select, #bybitgrid-modal input, #bybitgrid-modal select {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: flex-end;
}

/* Tablet */
@media (max-width: 960px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    padding: 0.65rem max(0.45rem, var(--safe-left)) 1rem max(0.45rem, var(--safe-right));
    gap: 0.85rem;
  }

  .grid-2 .panel,
  .grid-3 .panel,
  .grid-4 .panel {
    width: 100%;
    max-width: none;
  }
}

/* Phone + compact tablet chrome (hamburger through 900px) */
@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: wrap;
    gap: 0;
    padding-left: max(0.65rem, var(--safe-left));
    padding-right: max(0.65rem, var(--safe-right));
    padding-bottom: 0.45rem;
  }

  .topbar-head { width: 100%; flex: none; }
  .menu-toggle { display: inline-flex; }
  .menu-desc { display: block; }

  .topbar-menu {
    display: none;
    width: 100%;
    flex: none;
    margin-top: 0;
    padding-top: 0.55rem;
    border-top: 1px solid transparent;
    justify-content: stretch;
  }

  .topbar.is-menu-open .topbar-menu {
    display: block;
    margin-top: 0.45rem;
    padding-top: 0.55rem;
    border-top-color: color-mix(in srgb, var(--ai) 20%, var(--border));
  }

  .topbar.is-menu-open .menu-icon-open { display: none; }
  .topbar.is-menu-open .menu-icon-close { display: inline !important; }
  .topbar.is-menu-open .menu-toggle {
    background: color-mix(in srgb, var(--ai) 22%, transparent);
    border-color: color-mix(in srgb, var(--ai) 40%, var(--border));
  }

  .topbar-actions {
    width: 100%;
    flex-direction: column;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 0.5rem;
  }
  /* One aligned block for all menu buttons */
  .toolbar-main {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    overflow: hidden;
    gap: 0.3rem;
    padding: 0.35rem;
    box-sizing: border-box;
    border-radius: 12px;
    background: color-mix(in srgb, var(--bg) 72%, transparent);
    border: 1px solid color-mix(in srgb, var(--ai) 14%, var(--border));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  }
  .toolbar-main .nav-group {
    display: contents;
    width: auto;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    box-shadow: none;
  }
  .toolbar-main .btn-nav {
    width: 100%;
    min-width: 0;
    justify-content: flex-start;
    align-items: center;
    text-align: left;
    min-height: 2.45rem;
    border-radius: 8px !important;
    font-size: 0.82rem;
    box-sizing: border-box;
    padding: 0.4rem 0.55rem 0.4rem 0.65rem;
    gap: 0.4rem;
    white-space: nowrap;
    background: color-mix(in srgb, var(--bg-elevated) 55%, transparent) !important;
    border: 1px solid color-mix(in srgb, var(--ai) 12%, var(--border)) !important;
  }
  .toolbar-main .btn-nav .nav-glyph {
    width: 1rem;
    flex-shrink: 0;
    text-align: center;
  }
  .toolbar-main .btn-nav .lbl-full,
  .toolbar-main .btn-nav .lbl-short {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .toolbar-main .btn-nav:hover,
  .toolbar-main .btn-nav:active {
    background: color-mix(in srgb, var(--ai) 18%, transparent) !important;
    border-color: color-mix(in srgb, var(--ai) 30%, var(--border)) !important;
  }
  .toolbar-main .btn-nav-accent {
    background: color-mix(in srgb, var(--ai) 18%, transparent) !important;
    border-color: color-mix(in srgb, var(--ai) 32%, transparent) !important;
  }
  .toolbar-meta {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding-top: 0.1rem;
  }
  .trades-summary {
    display: grid;
    grid-template-columns: 1fr auto;
    width: 100%;
    max-width: none;
    border-radius: 12px;
    padding: 0.55rem 0.7rem;
    white-space: normal;
  }
  .trades-summary .ts-row {
    display: block;
    grid-column: 1;
    color: var(--muted);
    font-size: 0.78rem;
  }
  .trades-summary > strong {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
    text-align: right;
    font-size: 0.95rem;
  }
  .server-status { font-size: 0.68rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }

  .panel { padding: 0.85rem 0.9rem; border-radius: 10px; }
  .panel-head h2 { font-size: 0.98rem; }

  .stats { grid-template-columns: 1fr 1fr; gap: 0.4rem; }
  .stat { padding: 0.55rem 0.6rem; }
  .stat strong { font-size: 0.92rem; }

  .actions { grid-template-columns: 1fr; }
  .actions .btn { width: 100%; }

  .trade-grid { grid-template-columns: 1fr; }
  .trade-card-head { flex-direction: column; }
  .trade-head-right {
    text-align: left;
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
  }

  .pair-list li {
    flex-direction: column;
    align-items: stretch;
  }
  .pair-list li .btn { width: 100%; }

  /* —— Panels / strategy blocks —— */
  .panel {
    padding: 0.8rem 0.75rem 0.95rem;
    border-radius: 12px;
  }

  .panel-head {
    flex-wrap: wrap;
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem 0.55rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.7rem;
  }

  .panel-head .panel-title {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
  }

  .panel-head h2 {
    font-size: 0.95rem;
    line-height: 1.25;
  }

  .panel-head-actions {
    flex: 0 0 auto;
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .panel-stats-btn {
    min-height: 2.2rem;
  }

  /* Title + tip: tip button stays beside title (body drops under via absolute) */
  .panel-title-row {
    flex-wrap: nowrap;
    gap: 0.4rem;
    align-items: center;
  }

  .panel-title-row h2 {
    flex: 0 1 auto;
    min-width: 0;
  }

  .panel-title-row .ui-hint {
    flex: 0 0 auto;
    align-self: center;
  }

  .collapsible-toggle {
    gap: 0.4rem;
    padding: 0.65rem 0.7rem;
  }

  .collapsible-title {
    font-size: 0.88rem;
  }

  .collapsible-title-group {
    gap: 0.28rem;
  }

  .collapsible-sub {
    font-size: 0.72rem;
  }

  .strategy-toggle-label {
    gap: 0.5rem;
    padding: 0.55rem 0.6rem 0.3rem;
  }

  .strategy-toggle-text strong {
    font-size: 0.86rem;
    line-height: 1.3;
  }

  .strategy-toggle-title-row {
    gap: 0.35rem;
    align-items: center;
  }

  .settings-section-head {
    gap: 0.35rem;
  }

  .ui-hint-block {
    margin-bottom: 0.5rem;
  }

  .ui-hint-block > .ui-hint-btn {
    padding: 0.22rem 0.45rem;
    font-size: 0.72rem;
  }

  .panel-note,
  .test-strategy-isolate-note,
  .ml-gate-badge,
  .strategy-scan-info,
  .grid-scan-info {
    font-size: 0.76rem;
    line-height: 1.4;
  }

  .test-strategy-isolate-note {
    margin-bottom: 0.7rem;
    padding: 0.45rem 0.55rem;
  }

  .stats {
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
  }

  .stat {
    padding: 0.5rem 0.55rem;
    font-size: 0.76rem;
  }

  .stat strong {
    font-size: 0.9rem;
  }

  .strategy-risk-bar {
    padding: 0.55rem 0.6rem;
    margin-bottom: 0.6rem;
  }

  .strategy-risk-bar-inner,
  .strategy-risk-setting {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }

  .strategy-risk-title {
    min-width: 0;
  }

  .strategy-risk-field {
    width: 100%;
    justify-content: space-between;
  }

  .strategy-risk-field .numeric-setting-input {
    width: 5rem;
    min-height: 2.35rem;
    font-size: 16px;
  }

  .strategy-dual-hedge,
  .strategy-enable-bulk,
  .strategy-ml-conf-bulk {
    padding: 0.5rem 0.6rem;
  }

  .strategy-enable-bulk-inner,
  .strategy-ml-conf-bulk-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }

  .strategy-ml-conf-bulk-head,
  .strategy-enable-bulk-head {
    flex: 0 0 auto;
    min-width: 0;
    width: 100%;
  }

  .strategy-enable-bulk-actions,
  .strategy-ml-conf-bulk-actions {
    margin-left: 0;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.4rem;
  }

  .strategy-ml-conf-bulk-picker {
    flex: 1 1 100%;
    width: 100%;
  }

  .strategy-enable-bulk-actions .btn,
  .strategy-ml-conf-bulk-actions .btn {
    width: 100%;
    min-height: 2.35rem;
  }

  .collapsible-section {
    margin: 0.75rem 0;
    border-radius: 10px;
  }

  .collapsible-toggle {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.25rem 0.45rem;
    padding: 0.7rem 0.7rem;
    min-height: 2.75rem;
  }

  .collapsible-title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.88rem;
  }

  .collapsible-sub {
    flex: 1 1 100%;
    order: 3;
    font-size: 0.72rem;
    line-height: 1.35;
    padding-right: 1.4rem;
  }

  .collapsible-chevron {
    margin-left: auto;
  }

  .strategy-toggle-list {
    margin-top: 0.55rem;
    gap: 0.55rem;
  }

  .strategy-toggle-item {
    border-radius: 10px;
  }

  .strategy-toggle-label {
    padding: 0.6rem 0.65rem 0.3rem;
    gap: 0.55rem;
  }

  .strategy-toggle-label input {
    width: 1.2rem;
    height: 1.2rem;
    margin-top: 0.15rem;
  }

  .strategy-toggle-text strong {
    font-size: 0.86rem;
    line-height: 1.35;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.2rem 0.15rem;
  }

  .strategy-inv-badge,
  .strategy-train-badge,
  .strategy-ml-badge {
    margin-left: 0;
  }

  .strategy-toggle-desc {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 0.72rem;
  }

  .strategy-invert-switch {
    min-height: 2.5rem;
    padding: 0.45rem 0.65rem;
  }

  .strategy-invert-text {
    font-size: 0.76rem;
  }

  .strategy-ml-conf {
    padding: 0.2rem 0.55rem 0.35rem;
  }

  .strategy-ml-conf-btn {
    min-height: 2.2rem;
    padding: 0.3rem 0.45rem;
  }

  .strategy-ml-conf-menu {
    left: 0;
    right: 0;
    max-height: min(11rem, 38vh);
    padding: 0.22rem;
    gap: 0.05rem;
  }

  .strategy-ml-conf-option {
    min-height: 1.9rem;
    padding: 0.28rem 0.45rem;
    font-size: 0.8rem;
  }

  .strategy-panel-empty {
    padding: 0.75rem 0.35rem;
    font-size: 0.8rem;
    line-height: 1.4;
  }

  /* Placement admin */
  .placement-grid {
    gap: 0.85rem;
  }

  .placement-list {
    max-height: 16rem;
  }

  .placement-list-item {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
    padding: 0.55rem;
  }

  .placement-list-item .btn {
    width: 100%;
    min-height: 2.4rem;
  }

  .placement-list-name {
    font-size: 0.82rem;
  }

  .secrets-form,
  .users-create-form {
    flex-direction: column;
    align-items: stretch;
  }

  .secrets-form .btn,
  .users-create-form .btn,
  .settings-field {
    width: 100%;
    flex: none;
  }

  .users-list-item {
    flex-direction: column;
    align-items: stretch;
  }

  .users-list-actions {
    width: 100%;
    justify-content: stretch;
  }

  .users-list-actions .btn {
    flex: 1 1 auto;
    min-height: 2.35rem;
  }

  .user-perms-grid {
    grid-template-columns: 1fr !important;
  }

  .modal-card-wide {
    width: 100%;
    max-height: min(92dvh, 100%);
  }

  .trade-card {
    padding: 0.6rem 0.65rem;
  }

  .pnl-dash-scope,
  .history-filter {
    min-height: 2.25rem;
  }
}

/* Small phone */
@media (max-width: 380px) {
  .topbar h1 { font-size: 0.95rem; }
  .stats { grid-template-columns: 1fr; }
  .menu-toggle-text { display: none; }
  .toolbar-main .btn-nav {
    font-size: 0.78rem;
    min-height: 2.35rem;
    padding-inline: 0.35rem;
  }
  .stats-period-btn {
    font-size: 0.72rem;
    padding-inline: 0.3rem;
  }
}

/* Desktop modal centered */
@media (min-width: 641px) {
  .modal {
    align-items: center;
    padding: 1rem;
  }
  .modal-card {
    width: min(520px, 100%);
    max-height: 85vh;
    border-radius: 12px;
    padding: 1.25rem;
  }
  /* Stats needs room for all columns on PC */
  #stats-modal .stats-modal-card {
    width: min(980px, calc(100vw - 2rem));
    max-width: min(980px, calc(100vw - 2rem));
    max-height: min(90vh, 920px);
  }
  #stats-modal .stats-summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  #stats-modal .stats-table-wrap {
    overflow-x: visible;
  }
  #stats-modal .stats-table {
    min-width: 0;
    width: 100%;
  }
  .settings-add {
    flex-direction: row;
  }
  .settings-add .btn { width: auto; flex-shrink: 0; }

  .last-update { display: none; }
}

@media (min-width: 1500px) {
  .last-update { display: inline-block; }
}

/* Desktop composition: panels, tips, topbar */
@media (min-width: 961px) {
  .topbar {
    padding-left: 1.1rem;
    padding-right: 1.1rem;
    gap: 0.75rem 1rem;
  }

  .topbar-actions {
    gap: 0.75rem;
  }

  .toolbar-main {
    gap: 0.45rem;
    justify-content: flex-end;
  }

  .toolbar-meta {
    gap: 0.45rem;
    padding-left: 0.55rem;
    border-left: 1px solid color-mix(in srgb, var(--ai) 16%, var(--border));
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    gap: 1.25rem;
    padding: 1.25rem max(1rem, var(--safe-left)) 1.75rem max(1rem, var(--safe-right));
  }

  .grid-2 .panel,
  .grid-3 .panel,
  .grid-4 .panel {
    width: min(90%, 1280px);
    max-width: min(90vw, 1280px);
  }

  .settings-page {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .settings-page .settings-section {
    width: min(90%, 1280px);
    max-width: min(90vw, 1280px);
    box-sizing: border-box;
  }

  .panel-head {
    align-items: center;
  }

  .panel-title-row {
    flex-wrap: nowrap;
    gap: 0.18rem;
    align-items: center;
  }

  .panel-title-row h2 {
    flex: 0 1 auto;
    width: auto;
  }

  .panel-title-row .ui-hint {
    align-self: center;
    flex: 0 0 auto;
  }

  .ui-hint-btn {
    width: 1.05rem;
    height: 1.05rem;
    min-width: 1.05rem;
    font-size: 0.66rem;
  }

  .collapsible-title-group {
    gap: 0.16rem;
  }

  .settings-section-head {
    gap: 0.18rem;
  }

  .strategy-toggle-title-row {
    gap: 0.2rem;
  }

  .nav-group {
    gap: 0.1rem;
    padding: 0.12rem;
  }

  .btn-nav {
    padding: 0.18rem 0.5rem;
  }

  /* Tip body stays under topbar when near top */
  .ui-hint-body {
    z-index: 60;
  }
}

@media (min-width: 1600px) {
  .grid-2 .panel,
  .grid-3 .panel,
  .grid-4 .panel {
    width: min(88%, 1360px);
    max-width: min(88vw, 1360px);
  }

  .settings-page .settings-section {
    width: min(88%, 1360px);
    max-width: min(88vw, 1360px);
  }
}

@media (min-width: 641px) and (max-width: 900px) {
  /* Hamburger mode already active ≤900 — keep glyphs in the menu grid */
  .trades-summary .ts-label { display: none; }
}

@media (min-width: 901px) and (max-width: 1100px) {
  .btn-nav .nav-glyph { display: none; }
  .trades-summary .ts-label { display: none; }
}

@media (hover: none) and (pointer: coarse) {
  .btn:hover { filter: none; }
}

/* Logs viewer */
.logs-view {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 5.5rem);
  max-height: calc(100dvh - 5.5rem);
  padding: 0 1rem 1rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.logs-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}

.logs-title {
  margin: 0;
  font-size: 1rem;
  flex: 1 1 auto;
  min-width: 8rem;
}

.logs-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.logs-filter.is-active {
  background: var(--border);
  border-color: var(--muted);
}

.logs-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.logs-pause-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.logs-output {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #0a0e12;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font-family: "Cascadia Code", "Consolas", "Ubuntu Mono", monospace;
  font-size: 0.72rem;
  line-height: 1.45;
}

.log-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.5rem;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 0.1rem 0;
  border-bottom: 1px solid rgba(45, 58, 79, 0.35);
}

.log-line:last-child {
  border-bottom: none;
}

.log-time {
  flex: 0 0 auto;
  color: var(--muted);
  min-width: 9.5rem;
  font-size: 0.68rem;
  opacity: 0.85;
}

.log-time-missing {
  min-width: 1.5rem;
  opacity: 0.35;
}

.log-tag {
  display: inline-block;
  min-width: 5.5rem;
  margin-right: 0.5rem;
  font-weight: 600;
  opacity: 0.85;
}

.log-finder .log-tag { color: var(--ai); }
.log-strategy .log-tag { color: var(--strat); }
.log-grid .log-tag { color: var(--grid); }
.log-scanner .log-tag { color: var(--warn); }
.log-strategy_scanner .log-tag { color: #38bdf8; }
.log-pair_config .log-tag { color: #a78bfa; }
.log-executor .log-tag { color: #34d399; }

.log-line.log-warn { color: #fbbf24; }
.log-line.log-error { color: #f87171; }
.log-line.log-ok { color: #4ade80; }

.logs-footnote {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  text-align: right;
}

.changelog-sub {
  margin: 0;
  font-size: 0.8rem;
  flex: 1 1 100%;
}

.changelog-output {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.5rem;
  font-size: 0.82rem;
  line-height: 1.45;
}

.changelog-day {
  margin-bottom: 1.25rem;
}

.changelog-day-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted, #8b98a5);
  margin: 0 0 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.changelog-entry {
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.45rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border-left: 3px solid rgba(96, 165, 250, 0.55);
}

.changelog-entry.is-guards {
  border-left-color: rgba(251, 191, 36, 0.65);
}

.changelog-entry.is-system {
  border-left-color: rgba(148, 163, 184, 0.5);
}

.changelog-entry.is-finder {
  border-left-color: rgba(52, 211, 153, 0.55);
}

.changelog-entry.is-strategy {
  border-left-color: rgba(96, 165, 250, 0.55);
}

.changelog-entry.is-grid {
  border-left-color: rgba(45, 212, 191, 0.55);
}

.changelog-entry.is-scanner {
  border-left-color: rgba(251, 146, 60, 0.6);
}

.changelog-entry.is-telegram {
  border-left-color: rgba(167, 139, 250, 0.6);
}

.changelog-filters {
  flex: 1 1 100%;
}

.changelog-entry-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  align-items: baseline;
  margin-bottom: 0.25rem;
}

.changelog-entry-time {
  font-size: 0.72rem;
  color: var(--muted, #8b98a5);
  font-variant-numeric: tabular-nums;
}

.changelog-entry-cat {
  font-size: 0.68rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted, #8b98a5);
}

.changelog-entry-text {
  margin: 0;
}

.changelog-period {
  margin: 0.2rem 0 0;
  font-size: 0.72rem;
  color: var(--muted, #8b98a5);
}

@media (max-width: 640px) {
  .logs-view {
    height: calc(100dvh - 4rem);
    max-height: calc(100dvh - 4rem);
    padding: 0 0.5rem 0.5rem;
  }
  .logs-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .logs-actions { margin-left: 0; justify-content: space-between; }
  .logs-output { font-size: 0.68rem; }
}

#history-view.logs-view {
  --history-accent: var(--ai);
}

#history-view .history-toolbar {
  padding: 0.85rem 0 0.75rem;
  border-bottom: 1px solid color-mix(in srgb, var(--history-accent) 18%, var(--border));
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--history-accent) 10%, transparent),
      transparent 100%
    );
}

#history-view .history-toolbar .logs-title {
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}

.history-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  margin-top: 0.55rem;
  max-height: none;
  border: 1px solid color-mix(in srgb, var(--history-accent) 16%, var(--border));
  border-radius: 14px;
  background:
    linear-gradient(
      165deg,
      color-mix(in srgb, var(--history-accent) 6%, transparent) 0%,
      transparent 40%
    ),
    color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

#history-view .history-desktop-table {
  margin: 0;
}

#history-view .history-desktop-table th {
  background: color-mix(in srgb, var(--card) 82%, transparent);
  backdrop-filter: blur(6px);
}

#history-view .history-desktop-table td:nth-child(2),
#history-view .history-desktop-table th:nth-child(2),
#history-view .history-desktop-table td:nth-child(3),
#history-view .history-desktop-table th:nth-child(3),
#history-view .history-desktop-table td:nth-child(4),
#history-view .history-desktop-table th:nth-child(4),
#history-view .history-desktop-table td:nth-child(5),
#history-view .history-desktop-table th:nth-child(5) {
  text-align: left;
}

#history-view .history-desktop-table tbody tr.history-row {
  --row-accent: var(--muted);
}

#history-view .history-desktop-table tbody tr.history-row.bot-strategy {
  --row-accent: var(--strat);
}

#history-view .history-desktop-table tbody tr.history-row.bot-test {
  --row-accent: var(--teststrat);
}

#history-view .history-desktop-table tbody tr.history-row.bot-grid {
  --row-accent: var(--grid);
}

#history-view .history-desktop-table tbody tr.history-row.bot-bybitgrid {
  --row-accent: var(--bybitgrid);
}

#history-view .history-desktop-table tbody tr.history-row.bot-finder {
  --row-accent: var(--ai);
}

#history-view .history-desktop-table tbody tr.history-row:hover {
  background: color-mix(in srgb, var(--row-accent) 9%, transparent);
}

#history-view .history-desktop-table tbody tr.history-row td:first-child {
  box-shadow: inset 3px 0 0 var(--row-accent);
}

.history-bot-badge,
.history-side-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  background: color-mix(in srgb, var(--row-accent, var(--border)) 18%, transparent);
  color: color-mix(in srgb, var(--row-accent, var(--text)) 70%, #fff);
  border: 1px solid color-mix(in srgb, var(--row-accent, var(--border)) 28%, transparent);
}

.history-side-badge.side-long {
  background: color-mix(in srgb, var(--pos) 18%, transparent);
  color: #6ee7b7;
  border-color: color-mix(in srgb, var(--pos) 30%, transparent);
}

.history-side-badge.side-short {
  background: color-mix(in srgb, var(--neg) 18%, transparent);
  color: #fca5a5;
  border-color: color-mix(in srgb, var(--neg) 30%, transparent);
}

.history-pair-cell {
  font-weight: 600;
  word-break: break-word;
}

.history-pnl-cell {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.history-pnl-pct {
  font-size: 0.72rem;
  font-weight: 500;
}

.history-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.7rem 0.35rem 0.35rem;
  border-top: 1px solid color-mix(in srgb, var(--history-accent) 14%, var(--border));
  margin-top: 0.45rem;
}

.history-pagination.hidden,
.history-pagination[hidden] {
  display: none !important;
}

.history-page-info {
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 10rem;
  text-align: center;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-elevated) 80%, transparent);
  border: 1px solid var(--border-soft);
}

.history-pagination .btn {
  min-width: 6.5rem;
}

.history-filters {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 0.65rem 0 0.85rem;
  border-bottom: 1px solid color-mix(in srgb, var(--history-accent) 12%, var(--border));
}

.history-filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.75rem;
  padding: 0.75rem 0.85rem;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--history-accent) 14%, var(--border));
  background:
    linear-gradient(
      145deg,
      color-mix(in srgb, var(--history-accent) 7%, transparent),
      transparent 55%
    ),
    color-mix(in srgb, var(--bg-elevated) 82%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.history-filter-label {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 650;
  color: var(--muted);
  min-width: 4.5rem;
}

.history-select,
.history-pair-input,
.history-date-input {
  padding: 0.45rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  color: var(--text);
  font-size: 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.history-select:focus,
.history-pair-input:focus,
.history-date-input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--history-accent) 45%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--history-accent) 18%, transparent);
}

.history-pair-input {
  flex: 1 1 14rem;
  min-width: 10rem;
}

.history-select {
  min-width: 10rem;
}

.history-date-range {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  font-size: 0.82rem;
}

.history-date-range label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
}

.history-bot-filters .history-filter,
.history-period-filters .history-period-btn {
  border-radius: 999px;
}

.history-export-section {
  margin: 0.55rem 0 0.15rem;
  border: 1px solid color-mix(in srgb, var(--history-accent) 12%, var(--border));
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg-elevated) 70%, transparent);
  overflow: hidden;
}

.history-export-body {
  padding-top: 0.35rem;
}

.history-export-note {
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
}

.history-export-columns {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 0.35rem 0.75rem;
}

.history-export-col {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
}

.guide-card {
  max-height: 92vh;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
}

.guide-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  margin: 0 0 0.85rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}

.guide-toc a {
  color: var(--ai);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
}

.guide-toc a:hover {
  text-decoration: underline;
}

.guide-body {
  overflow: auto;
  min-height: 0;
  padding-right: 0.25rem;
  -webkit-overflow-scrolling: touch;
}

.guide-section {
  margin: 0 0 1.15rem;
}

.guide-section h3 {
  margin: 0 0 0.45rem;
  font-size: 0.95rem;
}

.guide-section ol,
.guide-section ul {
  margin: 0.25rem 0 0.5rem;
  padding-left: 1.2rem;
}

.guide-section li {
  margin: 0.3rem 0;
  font-size: 0.88rem;
  line-height: 1.45;
}

.guide-bots {
  list-style: disc;
}

.guide-note {
  margin: 0.45rem 0 0;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--border) 35%, transparent);
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}

.guide-note code {
  font-size: 0.78rem;
  color: var(--text);
}

@media (max-width: 640px) {
  .guide-toc {
    gap: 0.45rem;
  }
  .guide-toc a {
    font-size: 0.78rem;
  }
}


.secrets-form,
.users-create-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}

#secrets-status.secrets-status-warn {
  color: var(--neg, #ef4444);
  font-weight: 500;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--muted);
  flex: 1 1 10rem;
}

.settings-field.settings-check {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  flex: 1 1 auto;
  padding-bottom: 0.15rem;
  color: var(--text);
}

.settings-field.settings-check input[type="checkbox"],
.settings-field.settings-check input[type="radio"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  flex: 0 0 auto;
}

.secrets-mode {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.75rem 0.35rem;
  margin: 0;
  flex: 1 1 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
}

.secrets-mode-legend {
  padding: 0 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.secrets-profiles {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0.35rem 0 0.75rem;
}

.secrets-profiles-empty {
  margin: 0;
}

.secrets-add-label {
  flex: 1 1 100%;
  margin: 0 0 0.15rem;
  font-size: 0.82rem;
}

.secrets-trade-on {
  margin: 0.25rem 0 0.85rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg) 88%, var(--accent, #3d8bfd) 12%);
}

.secrets-trade-on-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.45rem;
}

.secrets-trade-on-options {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.secrets-trade-option {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
}

.secrets-trade-option:hover {
  border-color: var(--border);
  background: var(--bg);
}

.secrets-trade-option.is-active {
  border-color: color-mix(in srgb, var(--accent, #3d8bfd) 55%, var(--border));
  background: var(--bg);
}

.secrets-trade-option input[type="radio"] {
  margin-top: 0.2rem;
  flex: 0 0 auto;
}

.secrets-trade-option-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.secrets-trade-option-text strong {
  font-size: 0.9rem;
  color: var(--text);
}

.secrets-profile-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.secrets-profile-card.is-active {
  border-color: color-mix(in srgb, var(--accent, #3d8bfd) 55%, var(--border));
}

.secrets-profile-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.65rem;
}

.secrets-profile-name {
  font-size: 0.92rem;
  color: var(--text);
}

.secrets-profile-badge {
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
}

.secrets-profile-badge.active {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent, #3d8bfd) 50%, var(--border));
}

.secrets-profile-body {
  display: grid;
  gap: 0.2rem;
  font-size: 0.82rem;
}

.secrets-profile-body code {
  font-size: 0.78rem;
  word-break: break-all;
}

.secrets-profile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.settings-field input {
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.users-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.placement-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 0.75rem;
}

@media (max-width: 720px) {
  .placement-grid {
    grid-template-columns: 1fr;
  }
}

.placement-col h4 {
  margin: 0 0 0.45rem;
  font-size: 0.9rem;
}

.placement-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 22rem;
  overflow: auto;
}

.placement-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.placement-list-name {
  font-size: 0.85rem;
  line-height: 1.3;
}

.placement-list-empty {
  padding: 0.5rem 0.25rem;
  font-size: 0.85rem;
}

.strategy-panel-empty {
  list-style: none;
  padding: 0.65rem 0.25rem;
}

.users-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.users-list-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex-shrink: 0;
  justify-content: flex-end;
}

.users-perms-hint {
  font-size: 0.72rem;
  margin-top: 0.15rem;
}

.impersonate-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem 0.85rem;
  padding: 0.65rem 1rem;
  background:
    linear-gradient(
      90deg,
      color-mix(in srgb, var(--bybitgrid) 22%, transparent),
      color-mix(in srgb, var(--ai) 12%, transparent)
    );
  border-bottom: 1px solid color-mix(in srgb, var(--bybitgrid) 40%, var(--border));
  color: var(--text);
  font-size: 0.88rem;
}

.impersonate-banner.hidden {
  display: none;
}

.account-switch-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem 0.85rem;
  padding: 0.55rem 1rem;
  background: color-mix(in srgb, var(--accent, #3d8bfd) 12%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--accent, #3d8bfd) 28%, var(--border));
  color: var(--text);
  font-size: 0.88rem;
}

.account-switch-banner.hidden {
  display: none;
}

.account-switch-toggle {
  display: inline-flex;
  gap: 0.35rem;
}

.account-switch-btn.is-active {
  border-color: color-mix(in srgb, var(--accent, #3d8bfd) 55%, var(--border));
  background: color-mix(in srgb, var(--accent, #3d8bfd) 22%, transparent);
}

.secrets-banner {
  padding: 0.65rem 1rem;
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 35%, var(--border));
  color: var(--text);
  font-size: 0.88rem;
}

.secrets-banner.hidden {
  display: none;
}

.user-perms-card {
  max-height: 90vh;
  overflow: auto;
}

.user-perms-section {
  margin: 0.85rem 0 1rem;
}

.user-perms-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.user-perms-head h3 {
  margin: 0;
}

.user-perms-quick {
  display: flex;
  gap: 0.35rem;
}

.user-perms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.35rem 0.65rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 80%, transparent);
  max-height: 14rem;
  overflow: auto;
}

.user-perms-strategies {
  max-height: 22rem;
}

.user-perms-check {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  font-size: 0.82rem;
  cursor: pointer;
  line-height: 1.3;
}

.user-perms-check input {
  margin-top: 0.15rem;
  flex-shrink: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}


.history-cards {
  display: none;
}

.history-cards-empty {
  margin: 1.25rem 0.5rem;
  text-align: center;
  font-size: 0.9rem;
  padding: 1rem;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 55%, transparent);
}

.history-card {
  --card-accent: var(--muted);
  border: 1px solid color-mix(in srgb, var(--card-accent) 22%, var(--border));
  border-radius: 14px;
  background:
    linear-gradient(
      145deg,
      color-mix(in srgb, var(--card-accent) 10%, transparent),
      transparent 52%
    ),
    var(--bg-elevated);
  padding: 0.8rem 0.85rem;
  border-left: 3px solid var(--card-accent);
  box-shadow: var(--shadow-soft);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.history-card.bot-strategy { --card-accent: var(--strat); }
.history-card.bot-test { --card-accent: var(--teststrat); }
.history-card.bot-grid { --card-accent: var(--grid); }
.history-card.bot-bybitgrid { --card-accent: var(--bybitgrid); }
.history-card.bot-finder { --card-accent: var(--ai); }

.history-card.pos {
  border-left-color: var(--pos);
}

.history-card.neg {
  border-left-color: var(--neg);
}

.history-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.65rem;
}

.history-card-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.history-card-pair {
  font-size: 0.98rem;
  word-break: break-word;
  letter-spacing: 0.01em;
}

.history-card-meta {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.35;
}

.history-card-pnl {
  text-align: right;
  font-weight: 700;
  font-size: 1.05rem;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.1rem;
  font-variant-numeric: tabular-nums;
  padding: 0.2rem 0.45rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
}

.history-card-pnl.pos {
  background: color-mix(in srgb, var(--pos) 12%, transparent);
}

.history-card-pnl.neg {
  background: color-mix(in srgb, var(--neg) 12%, transparent);
}

.history-card-pct {
  font-size: 0.72rem;
  font-weight: 500;
}

.history-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.6rem;
}

.history-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  background: color-mix(in srgb, var(--card-accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--card-accent) 22%, transparent);
  color: var(--text);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-chip.side-long {
  background: color-mix(in srgb, var(--pos) 22%, transparent);
  border-color: color-mix(in srgb, var(--pos) 28%, transparent);
  color: #6ee7b7;
}

.history-chip.side-short {
  background: color-mix(in srgb, var(--neg) 22%, transparent);
  border-color: color-mix(in srgb, var(--neg) 28%, transparent);
  color: #fca5a5;
}

.history-chip.muted-chip {
  font-weight: 500;
  color: var(--muted);
  background: color-mix(in srgb, var(--border) 55%, transparent);
  border-color: transparent;
}

.history-chip-ml {
  background: color-mix(in srgb, var(--ai) 16%, transparent);
  border-color: color-mix(in srgb, var(--ai) 28%, transparent);
  color: #bfdbfe;
}

.history-chip-ml.is-missing {
  opacity: 0.65;
}

@media (max-width: 640px) {
  .history-filter-group {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
  }
  .history-filter-label {
    min-width: 0;
    font-size: 0.72rem;
  }
  .history-pair-input,
  .history-select {
    width: 100%;
    min-width: 0;
  }

  #history-view.logs-view {
    height: calc(100dvh - 3.5rem);
    max-height: calc(100dvh - 3.5rem);
    padding: 0 0.55rem calc(0.55rem + var(--safe-bottom));
    overflow: hidden;
    overscroll-behavior: contain;
  }

  #history-view .history-toolbar {
    position: relative;
    z-index: 3;
    flex: 0 0 auto;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    background: var(--bg);
    padding: 0.45rem 0 0.5rem;
    gap: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
  }

  #history-view .history-toolbar .logs-title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.95rem;
  }

  #history-view .history-toolbar .btn {
    min-height: 2.4rem;
  }

  /* Mobile: only period + trades */
  #history-view .logs-actions,
  #history-view .history-filter-group:not(.history-period-group),
  #history-view .history-date-range,
  #history-view .history-export-section {
    display: none !important;
  }

  #history-view .history-filters {
    flex: 0 0 auto;
    max-height: none;
    overflow: visible;
    position: relative;
    z-index: 2;
    gap: 0;
    padding: 0.45rem 0 0.5rem;
    margin: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }

  #history-view .history-period-group {
    gap: 0.35rem;
  }

  #history-view .history-period-group .history-filter-label {
    display: none;
  }

  #history-view .history-period-filters {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.35rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0.05rem 0.1rem 0.15rem;
    margin: 0;
  }

  #history-view .history-period-filters::-webkit-scrollbar {
    display: none;
  }

  #history-view .history-period-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    min-height: 2.15rem;
    padding: 0.4rem 0.7rem;
  }

  #history-view .history-desktop-table {
    display: none;
  }

  #history-view .history-table-wrap {
    flex: 1 1 auto;
    min-height: 0;
    border: none;
    background: transparent;
    box-shadow: none;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    margin-top: 0.35rem;
    padding-top: 0.1rem;
    isolation: isolate;
  }

  #history-view .history-cards {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    padding: 0.15rem 0 0.35rem;
  }

  #history-view .history-pagination {
    flex: 0 0 auto;
    position: relative;
    z-index: 2;
    background: var(--bg);
    margin-top: 0;
    padding: 0.5rem 0 0.2rem;
  }

  #history-view .logs-footnote {
    flex: 0 0 auto;
    position: relative;
    z-index: 2;
    background: var(--bg);
    padding: 0.45rem 0 0.1rem;
    font-size: 0.75rem;
  }
}

/* —— PnL dashboard (strategy share charts) —— */
.pnl-dashboard-view {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.pnl-dashboard-note {
  margin: 0.35rem 0 0.9rem;
  font-size: 0.85rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px dashed var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 70%, transparent);
}

.pnl-dashboard-summary {
  margin-bottom: 1.1rem;
}

.pnl-dashboard-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.pnl-chart-card {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background:
    radial-gradient(420px 180px at 100% 0%, rgba(59, 130, 246, 0.12), transparent 60%),
    linear-gradient(165deg, rgba(36, 48, 68, 0.95) 0%, rgba(18, 26, 38, 0.98) 100%);
  border: 1px solid color-mix(in srgb, var(--ai) 22%, var(--border));
  border-radius: 18px;
  padding: 1.1rem 1.15rem 1.25rem;
  min-width: 0;
  box-shadow: var(--shadow-soft);
}

.pnl-chart-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: linear-gradient(180deg, var(--ai), transparent);
}

.pnl-chart-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.pnl-chart-sub {
  margin: 0.28rem 0 0.75rem;
  font-size: 0.8rem;
}

.pnl-dash-scope.is-active,
.pnl-dash-period.is-active,
.history-filter.is-active,
.history-period-btn.is-active {
  background: color-mix(in srgb, var(--ai) 26%, transparent) !important;
  border-color: color-mix(in srgb, var(--ai) 45%, var(--border)) !important;
  color: #dbeafe;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--ai) 20%, transparent);
}

.pnl-chart-body {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.85rem 1.15rem;
}

.pnl-chart-svg {
  flex: 0 0 auto;
  width: 220px;
  height: 220px;
  margin: 0 auto;
}

.pnl-chart-svg svg,
.pnl-donut-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.pnl-donut-slice {
  cursor: pointer;
  transform-origin: center;
  transition: opacity 0.18s ease, filter 0.18s ease;
}

.pnl-donut-slice:focus {
  outline: none;
}

.pnl-donut-slice.is-dim,
.pnl-legend-item.is-dim {
  opacity: 0.28;
}

.pnl-donut-slice.is-active {
  opacity: 1;
  filter: brightness(1.12);
}

.pnl-donut-center-label {
  font-size: 11px;
  fill: var(--muted);
  text-anchor: middle;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pnl-donut-center-value {
  font-size: 20px;
  font-weight: 750;
  fill: var(--text);
  text-anchor: middle;
  font-variant-numeric: tabular-nums;
}

.pnl-donut-center-value.pnl-tone-pos {
  fill: var(--pos);
}

.pnl-donut-center-value.pnl-tone-neg {
  fill: var(--neg);
}

.pnl-donut-center-unit {
  font-size: 9px;
  fill: var(--muted);
  text-anchor: middle;
  letter-spacing: 0.06em;
}

.pnl-donut-pct-label {
  font-size: 11px;
  font-weight: 700;
  fill: var(--text);
  pointer-events: none;
  paint-order: stroke;
  stroke: rgba(15, 20, 25, 0.75);
  stroke-width: 3px;
}

.pnl-chart-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 170px;
  min-width: 0;
  max-height: none;
  overflow: visible;
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
}

.pnl-legend-item {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 0.4rem;
  align-items: start;
  font-size: 0.74rem;
  line-height: 1.2;
  padding: 0.2rem 0.3rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.18s ease;
}

.pnl-legend-item:hover,
.pnl-legend-item.is-active,
.pnl-legend-item:focus {
  background: rgba(255, 255, 255, 0.04);
  outline: none;
}

.pnl-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-top: 0.18rem;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.pnl-legend-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}

.pnl-legend-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: baseline;
  gap: 0.45rem;
}

.pnl-legend-name {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  font-weight: 550;
}

.pnl-legend-bar {
  height: 3px;
  border-radius: 999px;
  background: rgba(45, 58, 79, 0.9);
  overflow: hidden;
}

.pnl-legend-bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  min-width: 2px;
  opacity: 0.95;
}

.pnl-legend-meta {
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
  white-space: nowrap;
  text-align: right;
}

.pnl-legend-pct {
  color: var(--muted);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 2.4em;
  text-align: right;
}

.pnl-chart-empty-wrap,
.pnl-chart-empty {
  width: 100%;
  text-align: center;
  padding: 2.4rem 0.5rem;
  color: var(--muted);
  font-size: 0.88rem;
}

@media (max-width: 900px) {
  .pnl-dashboard-charts {
    grid-template-columns: 1fr;
  }

  .pnl-chart-body {
    flex-direction: column;
    align-items: stretch;
  }

  .pnl-chart-svg {
    width: 200px;
    height: 200px;
  }

  .pnl-chart-legend {
    max-height: none;
    overflow: visible;
  }
}

.rating-view {
  max-width: 1200px;
  margin: 0 auto;
}

.rating-toolbar {
  align-items: flex-start;
  gap: 0.75rem 1rem;
}

.rating-title-wrap {
  flex: 1 1 auto;
  min-width: 0;
}

.rating-title-wrap .logs-title {
  margin: 0;
}

.rating-subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
}

.rating-shell {
  margin-top: 0.35rem;
  padding: 0.9rem 1rem 0.75rem;
  background:
    linear-gradient(180deg, rgba(59, 130, 246, 0.08), transparent 42%),
    var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.rating-filters {
  margin: 0;
  padding: 0;
  border: none;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 0.65rem;
  align-items: flex-start;
  justify-content: flex-start;
  flex: 0 1 auto;
  min-width: 0;
}

.rating-filters .history-filter-group {
  justify-content: flex-start;
}

.rating-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1.25rem;
  margin: 0 0 0.75rem;
  width: 100%;
}

.rating-scope-pills,
.rating-period-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.rating-scope-pills .rating-scope,
.rating-period-pills .rating-period {
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--border);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.rating-scope-pills .rating-scope:hover,
.rating-period-pills .rating-period:hover {
  border-color: color-mix(in srgb, var(--ai) 45%, var(--border));
  color: var(--text);
}

.rating-scope-pills .rating-scope.is-active,
.rating-period-pills .rating-period.is-active {
  background: color-mix(in srgb, var(--ai) 22%, transparent);
  border-color: color-mix(in srgb, var(--ai) 55%, var(--border));
  color: #dbeafe;
}

.rating-user-group .rating-user-select {
  min-width: 11rem;
  max-width: min(18rem, 100%);
  padding: 0.35rem 0.65rem;
  border-radius: 0.55rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  color-scheme: dark;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.3;
}

.rating-user-group .rating-user-select option {
  background: var(--card);
  color: var(--text);
}

.rating-user-group .rating-user-select:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--ai) 55%, var(--border));
  background: var(--card);
  color: var(--text);
}

.rating-pair-row {
  cursor: pointer;
}

.rating-pair-row:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--ai) 60%, transparent);
  outline-offset: -2px;
}

.rating-pair-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.rating-expand-icon {
  display: inline-flex;
  width: 0.9rem;
  color: color-mix(in srgb, var(--ai) 75%, var(--muted));
  font-size: 0.75rem;
  line-height: 1;
}

.rating-pair-meta {
  font-size: 0.72rem;
  font-weight: 500;
}

.rating-pair-row.is-expanded {
  background: color-mix(in srgb, var(--ai) 8%, transparent);
}

.rating-detail-row td {
  background: rgba(0, 0, 0, 0.18);
  border-top-color: transparent;
  font-size: 0.88rem;
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
}

.rating-detail-label {
  padding-left: 1.6rem !important;
}

.rating-detail-strategy {
  display: inline-block;
  margin-right: 0.45rem;
}

.rating-detail-bot {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.7rem;
  color: #c7d2fe;
  background: color-mix(in srgb, var(--ai) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--ai) 35%, var(--border));
}

.rating-detail-empty {
  padding-left: 1.6rem !important;
}

.rating-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0;
  margin-left: auto;
  justify-content: flex-end;
  align-items: stretch;
  flex: 0 1 auto;
}

.rating-chip {
  display: inline-flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 5.5rem;
  padding: 0.45rem 0.7rem;
  border-radius: 10px;
  background: rgba(15, 20, 25, 0.45);
  border: 1px solid var(--border);
}

.rating-chip span {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.rating-chip strong {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.rating-table-wrap {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: auto;
  background: rgba(15, 20, 25, 0.35);
}

.rating-table {
  margin: 0;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.rating-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: color-mix(in srgb, var(--card) 92%, #000);
  border-bottom: 1px solid var(--border);
  padding: 0.7rem 0.75rem;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.rating-table td {
  padding: 0.72rem 0.75rem;
  border-bottom: 1px solid rgba(45, 58, 79, 0.55);
  vertical-align: middle;
}

.rating-table tbody tr:last-child td {
  border-bottom: none;
}

.rating-table td.num,
.rating-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rating-table .rating-strategy {
  font-weight: 600;
  color: var(--text);
}

.rating-table .rating-net strong {
  font-size: 0.98rem;
}

.rating-table td.pos {
  color: var(--pos);
}

.rating-table td.neg {
  color: var(--neg);
}

.rating-row {
  transition: background 0.12s ease;
}

.rating-row:hover {
  background: rgba(59, 130, 246, 0.06);
}

.rating-row.is-gold {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.12), transparent 55%);
}

.rating-row.is-silver {
  background: linear-gradient(90deg, rgba(148, 163, 184, 0.1), transparent 55%);
}

.rating-row.is-bronze {
  background: linear-gradient(90deg, rgba(180, 83, 9, 0.12), transparent 55%);
}

.rating-place-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.7rem;
  height: 1.7rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
}

.rating-row.is-gold .rating-place-badge {
  color: #0f1419;
  background: #fbbf24;
  border-color: #f59e0b;
}

.rating-row.is-silver .rating-place-badge {
  color: #0f1419;
  background: #cbd5e1;
  border-color: #94a3b8;
}

.rating-row.is-bronze .rating-place-badge {
  color: #fff;
  background: #b45309;
  border-color: #92400e;
}

.rating-wr {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
  min-width: 3.4rem;
}

.rating-wr-val {
  font-variant-numeric: tabular-nums;
}

.rating-wr-track {
  display: block;
  width: 3.4rem;
  height: 0.28rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.rating-wr-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #34d399, #3b82f6);
}

.rating-view .stats-table th.rating-sort {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.rating-view .stats-table th.rating-sort:hover {
  color: var(--text);
}

.rating-view .stats-table th.rating-sort.is-active {
  color: #93c5fd;
}

.rating-footnote {
  margin: 0.7rem 0 0.1rem;
  font-size: 0.78rem;
}

@media (max-width: 760px) {
  .rating-shell {
    padding: 0.75rem;
    border-radius: 12px;
  }

  .rating-toolbar-row {
    flex-direction: column;
    align-items: stretch;
  }

  .rating-summary {
    margin-left: 0;
    justify-content: flex-start;
  }

  .rating-table thead th,
  .rating-table td {
    padding: 0.55rem 0.5rem;
    font-size: 0.8rem;
  }

  .rating-wr-track {
    width: 2.6rem;
  }
}

