:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #111820;
  --panel-strong: #151d26;
  --panel-soft: #202a35;
  --text: #f4f7fb;
  --muted: #97a6b8;
  --line: #2b3644;
  --good: #22c55e;
  --bad: #ef4444;
  --accent: #2dd4bf;
  --gold: #f5c451;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(45, 212, 191, 0.08), transparent 280px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: rgba(12, 17, 23, 0.96);
  padding: 24px 14px;
}

.sidebar-brand {
  padding: 0 8px 22px;
}

.sidebar-brand strong {
  display: block;
  font-size: 24px;
  line-height: 1.05;
}

.main-menu {
  display: grid;
  gap: 6px;
}

.menu-item {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.menu-item:hover,
.menu-item:focus {
  border-color: rgba(45, 212, 191, 0.44);
  background: rgba(45, 212, 191, 0.08);
  color: var(--text);
}

.menu-item.is-active {
  border-color: rgba(45, 212, 191, 0.5);
  background: rgba(45, 212, 191, 0.14);
  color: #ffffff;
}

.content-shell {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 28px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(12, 17, 23, 0.92);
}

.brand-lockup {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  letter-spacing: 0;
}

h2 {
  font-size: 21px;
}

main {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 24px clamp(14px, 3vw, 28px) 48px;
}

.page-view {
  display: none;
}

.page-view.is-active {
  display: block;
}

.menu-panel {
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 24px;
}

.menu-panel h2 {
  margin-bottom: 8px;
}

.menu-panel p {
  color: var(--muted);
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.settings-layout {
  display: grid;
  gap: 14px;
}

.settings-status {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.settings-status.is-error {
  color: #fecaca;
}

.settings-status.is-success {
  color: #9af2bb;
}

.settings-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

fieldset {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  background: #101720;
  padding: 16px;
}

legend {
  padding: 0 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.wide-fieldset,
.form-actions {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.field:last-child {
  margin-bottom: 0;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #3d4b5e;
  border-radius: 6px;
  background: #0b1118;
  color: var(--text);
  font: inherit;
  padding: 0 11px;
}

.field textarea {
  min-height: 178px;
  padding: 10px 11px;
  resize: vertical;
}

.strategy-description-field textarea {
  min-height: 92px;
  color: #c8d4e2;
  resize: none;
}

.bot-description-field textarea {
  min-height: 82px;
  resize: vertical;
}

.field textarea[readonly] {
  background: #101820;
  border-color: #2f3b49;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check-field input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.header-subtitle {
  margin-top: 7px;
  color: var(--muted);
  font-size: 14px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

button {
  min-height: 38px;
  border: 1px solid #3d4b5e;
  border-radius: 6px;
  padding: 0 14px;
  background: #22313f;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

button:hover,
.logout-link:hover {
  border-color: var(--accent);
}

.logout-link {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #3d4b5e;
  border-radius: 6px;
  padding: 0 14px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.summary-strip,
.bot-grid {
  display: grid;
  gap: 16px;
}

.summary-strip {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 20px;
}

.summary-pill,
.bot-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.summary-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 74px;
  padding: 16px 18px;
  background: var(--panel-strong);
}

.summary-pill span,
.details-grid span,
.stats-grid span,
.performance-grid span,
.hero-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.summary-pill strong {
  display: block;
  font-size: 26px;
}

.bot-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.bot-card {
  padding: 20px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.22);
}

.bot-card.is-online {
  border-color: rgba(45, 212, 191, 0.42);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.bot-title-block {
  min-width: 0;
}

.muted {
  color: var(--muted);
  margin-top: 4px;
  font-size: 14px;
}

.status-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.status-pill.online {
  background: rgba(34, 197, 94, 0.16);
  color: #9af2bb;
}

.status-pill.offline {
  background: rgba(239, 68, 68, 0.14);
  color: #fca5a5;
}

.hero-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(170px, 0.76fr);
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  margin-bottom: 12px;
  background: #101720;
  padding: 18px 14px;
}

.balance-chart {
  position: relative;
  min-height: 186px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  margin-top: 10px;
  margin-bottom: 12px;
  background: #101720;
  padding: 12px 12px 10px;
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.chart-tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(6, 11, 18, 0.56);
  margin-bottom: 8px;
  padding: 3px;
}

.chart-tab {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  padding: 7px 10px;
  text-transform: uppercase;
}

.chart-tab.is-active {
  background: rgba(45, 212, 191, 0.14);
  color: #d7fffa;
}

.chart-tab:focus-visible {
  outline: 2px solid rgba(45, 212, 191, 0.75);
  outline-offset: 2px;
}

.chart-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.chart-head small,
.chart-empty {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chart-body {
  position: relative;
  height: 132px;
  min-width: 0;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: thin;
}

.balance-chart canvas {
  display: block;
  min-width: 100%;
  height: 132px;
  cursor: crosshair;
  contain: strict;
}

.chart-empty {
  display: none;
  margin-top: 4px;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  display: block;
  max-width: calc(100% - 24px);
  border: 1px solid rgba(45, 212, 191, 0.65);
  border-radius: 6px;
  background: #0a1018;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.32);
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  opacity: 0;
  overflow-wrap: anywhere;
  padding: 6px 8px;
  pointer-events: none;
  transform: translate(-50%, -100%);
  transition: opacity 120ms ease;
}

.chart-tooltip.is-visible {
  opacity: 1;
}

.balance-chart.is-empty .chart-empty {
  display: block;
}

.hero-stat {
  min-width: 0;
}

.hero-profit {
  text-align: left;
}

.hero-stat strong {
  display: block;
  margin-top: 8px;
  color: var(--text);
  font-size: 34px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.hero-balance strong {
  display: inline-block;
  width: auto;
  background: rgba(148, 163, 184, 0.16);
  padding: 2px 4px;
  color: #ffffff;
  font-size: 35px;
  line-height: 1.2;
}

.hero-profit strong {
  color: var(--text);
  font-size: 35px;
}

.hero-stat small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.bot-card.is-positive .hero-stat strong {
  color: var(--good);
}

.bot-card.is-negative .hero-stat strong {
  color: #f87171;
}

.bot-card.is-positive .hero-balance strong,
.bot-card.is-negative .hero-balance strong {
  color: #ffffff;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.stats-grid > div,
.details-grid > div,
.performance-grid > div {
  min-width: 0;
  border-radius: 6px;
  background: var(--panel-soft);
  padding: 12px;
}

.stats-grid > div {
  min-height: 90px;
}

.stat-tooltip {
  cursor: help;
  position: relative;
}

.stat-tooltip:focus {
  outline: 1px solid rgba(125, 211, 252, 0.65);
  outline-offset: 2px;
}

.hover-panel {
  position: absolute;
  left: 0;
  top: calc(100% - 8px);
  z-index: 20;
  display: block;
  width: max-content;
  min-width: 260px;
  max-width: min(360px, calc(100vw - 48px));
  max-height: 180px;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 6px;
  background: #0a1018;
  box-shadow: 0 16px 35px rgba(0, 0, 0, 0.36);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
  opacity: 0;
  padding: 10px;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 140ms ease, transform 140ms ease;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.stat-tooltip:hover .hover-panel,
.stat-tooltip:focus .hover-panel,
.stat-tooltip:focus-within .hover-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.win-rate-history-panel {
  max-height: calc(20px + (12px * 1.45 * 5));
}

.stats-grid .wide-stat {
  grid-column: span 2;
}

.stats-grid strong {
  display: block;
  margin-top: 7px;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.runtime-stat strong {
  font-size: 15px;
  line-height: 1.35;
  white-space: pre-line;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.details-grid strong,
.performance-grid strong {
  display: block;
  margin-top: 6px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.panel-drawer {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101720;
}

summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 0 14px;
  color: var(--text);
  font-weight: 700;
}

.performance-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 0 12px 12px;
}

.trade-list,
.performance-list,
pre {
  max-height: 260px;
  overflow: auto;
  margin: 0 12px 12px;
  border-radius: 0;
  background: transparent;
  padding: 0 2px 12px;
  color: #cbd5e1;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.performance-list {
  color: var(--text);
}

.trade-list {
  color: var(--text);
}

.error-panel {
  grid-column: 1 / -1;
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.08);
  padding: 18px;
  color: #fecaca;
}

.login-page {
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(440px, 100%);
  padding: 24px;
}

.login-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 28px;
}

.login-panel h1 {
  margin-bottom: 22px;
  font-size: 28px;
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-form input {
  width: 100%;
  min-height: 42px;
  border: 1px solid #475569;
  border-radius: 6px;
  background: #0f141b;
  color: var(--text);
  padding: 0 12px;
  font: inherit;
}

.login-error {
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 6px;
  margin: 0;
  background: rgba(239, 68, 68, 0.1);
  color: #fecaca;
  padding: 10px 12px;
  font-size: 14px;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 16px clamp(14px, 3vw, 28px);
  }

  .sidebar-brand {
    padding: 0 0 12px;
  }

  .sidebar-brand strong {
    font-size: 21px;
  }

  .main-menu {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .menu-item {
    justify-content: center;
    padding: 0 10px;
    text-align: center;
  }

  .topbar,
  .top-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary-strip,
  .bot-grid,
  .details-grid,
  .performance-grid,
  .settings-form {
    grid-template-columns: 1fr;
  }

  .wide-fieldset,
  .form-actions {
    grid-column: auto;
  }

  .section-head {
    flex-direction: column;
  }

  .hero-row,
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-grid .wide-stat {
    grid-column: 1 / -1;
  }

  .summary-pill {
    min-height: 60px;
  }

  .hero-stat strong {
    font-size: 30px;
  }
}
