:root {
  --bg: #f3f6f7;
  --surface: #ffffff;
  --surface-soft: #f7faf9;
  --ink: #162024;
  --muted: #66787d;
  --line: #dbe5e7;
  --brand: #0f766e;
  --brand-dark: #0a4f49;
  --accent: #c76b17;
  --danger: #b42318;
  --ok: #12805c;
  --sidebar: #10181b;
  --shadow: 0 16px 36px rgba(22, 32, 36, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 18px;
  background: var(--sidebar);
  color: #eef7f6;
}

.brand,
.nav-item,
.connection-card,
.topbar,
.topbar-actions,
.risk-banner,
.panel-heading,
.agent-state,
.exchange-row,
.risk-row,
.price-line,
.quota,
.backtest-stats div,
.step-list li {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  font-weight: 900;
}

.brand strong,
.brand small,
.connection-card strong,
.connection-card small {
  display: block;
}

.brand small,
.connection-card small {
  margin-top: 2px;
  color: #a8b9bc;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  min-height: 42px;
  padding: 0 13px;
  border-radius: 8px;
  color: #bbcccf;
  font-weight: 750;
}

.nav-item.active,
.nav-item:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.connection-card {
  margin-top: auto;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 99px;
  background: #39d98a;
  box-shadow: 0 0 0 5px rgba(57, 217, 138, 0.14);
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 780px;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.12;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.icon-button,
.primary-button,
.secondary-button,
.small-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  font-weight: 850;
}

.icon-button {
  width: 42px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}

.primary-button {
  padding: 0 18px;
  color: #ffffff;
  background: var(--brand);
}

.secondary-button {
  width: 100%;
  padding: 0 16px;
  color: var(--brand-dark);
  background: #dff4ef;
}

.small-button {
  min-height: 34px;
  padding: 0 12px;
  color: #ffffff;
  background: var(--ink);
}

.mode-switch,
.segmented,
.bot-select {
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: 8px;
  background: #e8eff0;
}

.mode-button,
.segment,
.bot-chip {
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 850;
}

.mode-button {
  min-width: 66px;
  min-height: 36px;
}

.segment {
  min-width: 48px;
  min-height: 36px;
}

.bot-chip {
  flex: 1;
  min-height: 36px;
}

.mode-button.active,
.segment.active,
.bot-chip.active {
  color: var(--ink);
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(22, 32, 36, 0.08);
}

.risk-banner {
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid #efd6b4;
  border-radius: 8px;
  color: #5f3b13;
  background: #fff8ed;
}

.risk-banner strong {
  white-space: nowrap;
}

.summary-grid,
.workspace-grid,
.launch-grid,
.service-grid,
.lower-grid {
  display: grid;
  gap: 14px;
}

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

.workspace-grid {
  grid-template-columns: minmax(0, 1.65fr) minmax(330px, 0.85fr);
}

.launch-grid {
  grid-template-columns: minmax(320px, 0.95fr) minmax(320px, 1.05fr);
  margin-top: 14px;
}

.service-grid {
  grid-template-columns: minmax(430px, 1.35fr) minmax(260px, 0.65fr);
  margin-top: 14px;
}

.lower-grid {
  grid-template-columns: minmax(260px, 0.9fr) minmax(380px, 1.4fr) minmax(240px, 0.75fr);
  margin-top: 14px;
}

.metric-card,
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 17px;
}

.metric-card span,
.metric-card small,
.panel-heading p,
.control-group label,
.agent-state span,
.exchange-row small,
.risk-row small,
.template-card span,
.template-card small,
.backtest-stats span,
.quota span,
.orders-table th,
.step-list small,
.footer-note span {
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin: 7px 0 3px;
  font-size: 26px;
}

.metric-card.alert strong {
  color: var(--accent);
}

.gain {
  color: var(--ok) !important;
}

.panel {
  padding: 18px;
}

.panel-heading {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-heading.tight {
  margin-bottom: 14px;
}

.panel-heading p {
  margin-top: 4px;
  font-size: 13px;
}

.chart-panel canvas {
  display: block;
  width: 100%;
  height: 330px;
  border-radius: 8px;
  background: linear-gradient(180deg, #f7fbfb 0%, #eef6f5 100%);
}

.toggle input {
  position: absolute;
  opacity: 0;
}

.toggle span {
  position: relative;
  display: block;
  width: 48px;
  height: 28px;
  border-radius: 99px;
  background: #cbd5d7;
}

.toggle span::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.18s ease;
}

.toggle input:checked + span {
  background: var(--brand);
}

.toggle input:checked + span::after {
  transform: translateX(20px);
}

.bot-select {
  margin-bottom: 14px;
}

.agent-state {
  justify-content: space-between;
  gap: 12px;
  padding: 15px;
  border-radius: 8px;
  background: var(--surface-soft);
  margin-bottom: 18px;
}

.agent-state strong,
.agent-state span {
  display: block;
}

.agent-state strong {
  margin-top: 4px;
}

.control-group {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 17px;
}

.control-group input {
  grid-column: 1 / -1;
  accent-color: var(--brand);
}

output {
  font-weight: 850;
}

.step-list {
  display: grid;
  gap: 10px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.step-list li {
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.step-list li > span {
  width: 30px;
  height: 30px;
  display: grid;
  flex: 0 0 30px;
  place-items: center;
  border-radius: 99px;
  color: var(--muted);
  background: #e8eff0;
  font-weight: 900;
}

.step-list li.done > span,
.step-list li.active > span {
  color: #ffffff;
  background: var(--brand);
}

.step-list strong,
.step-list small {
  display: block;
}

.step-list small {
  margin-top: 2px;
}

.exchange-list,
.risk-list,
.backtest-stats {
  display: grid;
  gap: 10px;
}

.exchange-row,
.risk-row {
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.exchange-row strong,
.exchange-row small,
.risk-row strong,
.risk-row small {
  display: block;
}

.exchange-row span {
  color: var(--ok);
  font-size: 12px;
  font-weight: 900;
}

.exchange-row button {
  min-width: 54px;
  min-height: 32px;
  border: 0;
  border-radius: 7px;
  color: var(--brand-dark);
  background: #dff4ef;
  font-weight: 850;
}

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

.template-card {
  display: grid;
  gap: 5px;
  min-height: 124px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fbfdfd;
  text-align: left;
}

.template-card:hover,
.template-card.active {
  border-color: rgba(15, 118, 110, 0.48);
  background: #eff8f6;
}

.template-card small {
  align-self: end;
}

.backtest-panel,
.pricing-panel {
  display: flex;
  flex-direction: column;
}

.backtest-stats {
  margin-bottom: auto;
}

.backtest-stats div {
  justify-content: space-between;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.backtest-stats strong {
  font-size: 18px;
}

.risk-row {
  justify-content: flex-start;
}

.risk-row > span {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 99px;
}

.risk-row.ok > span {
  background: var(--ok);
}

.risk-row.warn > span {
  background: var(--accent);
}

.orders-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.orders-table th,
.orders-table td {
  padding: 11px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
}

.side-buy {
  color: var(--ok);
  font-weight: 900;
}

.side-sell {
  color: var(--danger);
  font-weight: 900;
}

.price-line {
  align-items: baseline;
  gap: 5px;
  margin: 8px 0 18px;
}

.price-line strong {
  font-size: 38px;
}

.quota {
  display: grid;
  gap: 8px;
  margin-bottom: auto;
}

progress {
  width: 100%;
  height: 10px;
  accent-color: var(--brand);
}

.footer-note {
  display: flex;
  gap: 8px;
  margin: 16px 0 0;
  padding: 14px 0 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: 340px;
  padding: 13px 15px;
  color: #ffffff;
  background: #162024;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .brand span,
  .nav-item span,
  .connection-card div {
    display: none;
  }

  .brand,
  .nav-item,
  .connection-card {
    justify-content: center;
  }

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

  .workspace-grid,
  .launch-grid,
  .service-grid,
  .lower-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: sticky;
    z-index: 10;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 12px;
    overflow-x: auto;
  }

  .brand span,
  .nav-item span {
    display: block;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .nav-list {
    display: flex;
    gap: 6px;
  }

  .nav-item {
    white-space: nowrap;
  }

  .connection-card {
    display: none;
  }

  .main {
    padding: 18px;
  }

  .topbar,
  .panel-heading,
  .risk-banner,
  .footer-note {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .summary-grid,
  .template-grid {
    grid-template-columns: 1fr;
  }

  .chart-panel canvas {
    height: 250px;
  }

  .orders-table th:nth-child(2),
  .orders-table td:nth-child(2) {
    display: none;
  }
}
