:root {
  color-scheme: dark;
  --bg: #111315;
  --panel: #1b2024;
  --panel-2: #22282d;
  --text: #eef2f3;
  --muted: #9ca7ae;
  --line: #303940;
  --green: #6ddf9b;
  --red: #ff7b7b;
  --amber: #f4c16f;
  --blue: #7ab7ff;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1380px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.topbar,
.panel-head,
.actions,
.form-actions {
  display: flex;
  align-items: center;
}

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

.brand {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  display: block;
  margin-top: 2px;
}

.brand-status {
  width: fit-content;
  margin-top: 6px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 42px;
  line-height: 1.12;
}

h2 {
  font-size: 16px;
  font-weight: 700;
}

.topbar p,
.label,
small,
.metrics {
  color: var(--muted);
}

.actions,
.form-actions {
  gap: 8px;
  flex-wrap: wrap;
}

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

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.tab-button {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-color: transparent;
}

.tab-button.active {
  background: #1f6feb;
  border-color: #2f81f7;
}

.tab-page {
  display: none;
}

.tab-page.active {
  display: block;
}

.view-switch {
  min-width: 230px;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
}

.view-switch span {
  white-space: nowrap;
}

button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  cursor: pointer;
}

button:hover {
  border-color: var(--blue);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button.primary {
  background: #1f6feb;
  border-color: #2f81f7;
}

button.danger {
  background: rgba(255, 123, 123, 0.14);
  border-color: rgba(255, 123, 123, 0.42);
  color: var(--red);
}

.menu {
  position: relative;
}

.menu summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  list-style: none;
}

.menu summary::-webkit-details-marker {
  display: none;
}

.menu summary::after {
  content: "⌄";
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
}

.menu[open] summary,
.menu summary:hover {
  border-color: var(--blue);
}

.account-menu.viewer summary {
  color: var(--amber);
  border-color: rgba(244, 193, 111, 0.45);
}

.menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  display: grid;
  gap: 8px;
  min-width: 230px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.34);
}

.menu-panel button {
  width: 100%;
  text-align: left;
}

.account-panel {
  min-width: 180px;
}

.profile-info {
  display: grid;
  gap: 4px;
  padding: 6px 8px 8px;
  border-bottom: 1px solid var(--line);
}

.profile-info small {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.profile-info b {
  color: var(--text);
  font-size: 14px;
  overflow-wrap: anywhere;
}

#engineToggleBtn,
.menu summary {
  white-space: nowrap;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.wallet-panel {
  margin-bottom: 12px;
}

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

.wallet-summary span,
.wallet-coin {
  background: #14181b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  overflow-wrap: anywhere;
}

.wallet-summary small,
.wallet-coin small {
  display: block;
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
}

.wallet-summary b {
  display: block;
  font-size: 18px;
  line-height: 1.2;
}

.wallet-coins {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.wallet-coin {
  min-height: 86px;
}

.wallet-coin strong {
  display: block;
  font-size: 15px;
  line-height: 1.2;
}

.wallet-coin b {
  color: var(--text);
  font-weight: 700;
}

.wallet-coin.active {
  border-color: rgba(109, 223, 155, 0.45);
}

.wallet-coin.empty {
  opacity: 0.62;
}

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

.accent {
  border-color: rgba(109, 223, 155, 0.45);
}

.label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  margin-bottom: 8px;
}

.panel strong {
  display: block;
  font-size: 26px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.panel small {
  display: block;
  margin-top: 8px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.workspace {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.panel-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.switch input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-height: 20px;
  flex: 0 0 20px;
  margin: 0;
  padding: 0;
  accent-color: #1f6feb;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.field-name {
  position: relative;
  display: inline-flex;
  width: max-content;
  max-width: 100%;
  align-items: center;
  color: var(--muted);
  cursor: help;
  overflow: visible;
}

.field-name::after {
  content: attr(data-help);
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 30;
  width: max-content;
  max-width: min(320px, calc(100vw - 48px));
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1316;
  color: var(--text);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.38);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition:
    opacity 120ms ease,
    transform 120ms ease;
  white-space: normal;
}

.field-name::before {
  content: "";
  position: absolute;
  left: 12px;
  bottom: calc(100% + 3px);
  z-index: 31;
  width: 10px;
  height: 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #0f1316;
  opacity: 0;
  pointer-events: none;
  transform: rotate(45deg) translateY(4px);
  transition:
    opacity 120ms ease,
    transform 120ms ease;
}

.field-name:hover,
.field-name:focus-visible {
  color: var(--text);
}

.field-name:hover::after,
.field-name:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.field-name:hover::before,
.field-name:focus-visible::before {
  opacity: 1;
  transform: rotate(45deg) translateY(0);
}

.field-name:focus-visible {
  outline: 2px solid rgba(122, 183, 255, 0.7);
  outline-offset: 2px;
  border-radius: 4px;
}

input:not([type="checkbox"]),
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #14181b;
  color: var(--text);
}

.actions .menu summary {
  min-height: 46px;
}

.view-switch select {
  width: auto;
  min-width: 126px;
  min-height: 32px;
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--text);
  font-weight: 700;
}

.form-actions {
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(48, 57, 64, 0.72);
}

.save-button {
  min-width: 210px;
}

.form-service-menu {
  margin-left: auto;
}

.form-service-menu summary {
  min-width: 92px;
  justify-content: center;
  color: var(--muted);
}

.form-service-menu .menu-panel {
  min-width: 240px;
}

.form-service-menu .menu-panel button[hidden] {
  display: none;
}

.chart-panel {
  min-height: 585px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: -2px 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-help {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  margin: -2px 0 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #14181b;
  color: var(--muted);
  font-size: 12px;
}

.chart-help:empty {
  display: none;
}

.chart-help span {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.chart-help b {
  color: var(--text);
  font-size: 13px;
  line-height: 1.25;
}

.chart-help small {
  margin: 0;
  white-space: nowrap;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.price-dot {
  background: var(--blue);
}

.lower-dot,
.buy-dot {
  background: var(--green);
}

.upper-dot {
  background: var(--amber);
}

.sell-dot {
  background: var(--red);
}

canvas {
  width: 100%;
  height: 340px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121619;
}

.chart-readout {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.chart-readout span {
  min-height: 54px;
  background: #14181b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  overflow-wrap: anywhere;
}

.chart-readout small {
  display: block;
  margin: 0 0 4px;
  font-size: 11px;
  color: var(--muted);
}

.chart-readout b {
  display: block;
  font-size: 13px;
  line-height: 1.25;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
}

.badge.on {
  color: var(--green);
  border-color: rgba(109, 223, 155, 0.45);
}

.badge.viewer {
  color: var(--amber);
  border-color: rgba(244, 193, 111, 0.45);
}

.read-only input,
.read-only select {
  opacity: 0.72;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
  font-size: 13px;
}

.metrics span {
  background: #14181b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  overflow-wrap: anywhere;
}

.metrics small {
  display: inline-flex;
  margin: 0 0 5px;
  font-size: 12px;
}

.metrics b {
  display: block;
  color: var(--text);
  font-size: 16px;
  line-height: 1.25;
}

.grid-status {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.grid-status div {
  min-height: 54px;
  background: #14181b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  overflow-wrap: anywhere;
}

.grid-status small {
  display: block;
  margin: 0 0 4px;
  font-size: 11px;
  color: var(--muted);
}

.chart-readout .field-name,
.metrics .field-name,
.grid-status .field-name {
  display: inline-flex;
  width: max-content;
  max-width: 100%;
}

.grid-status b {
  display: block;
  font-size: 13px;
  line-height: 1.25;
}

.grid-plan {
  margin-top: 12px;
}

.grid-plan-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.grid-plan-head strong {
  font-size: 15px;
}

.grid-plan-head small {
  margin: 0;
}

.grid-plan-rows {
  display: grid;
  gap: 8px;
}

.grid-plan-row {
  display: grid;
  grid-template-columns: 42px repeat(4, minmax(0, 1fr));
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 10px;
  background: #14181b;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
}

.grid-plan-row b {
  color: var(--text);
  font-size: 13px;
}

.grid-plan-row span {
  overflow-wrap: anywhere;
}

.grid-plan-row span:first-child {
  color: var(--green);
  font-weight: 700;
}

.muted-row {
  opacity: 0.55;
}

.logs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.table {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.row {
  display: grid;
  grid-template-columns: 136px 82px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #14181b;
  font-size: 13px;
}

.row span {
  overflow-wrap: anywhere;
}

.trade-row {
  grid-template-columns: 94px 88px minmax(0, 1fr);
  min-height: 58px;
}

.trade-time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.trade-side {
  font-weight: 700;
}

.trade-details {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.trade-details b {
  font-size: 14px;
}

.trade-details span {
  color: var(--muted);
  white-space: nowrap;
}

.trade-details .buy,
.trade-details .sell {
  font-weight: 700;
}

.buy {
  color: var(--green);
}

.sell,
.error {
  color: var(--red);
}

.warning {
  color: var(--amber);
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(420px, calc(100vw - 32px));
}

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

.login-brand {
  align-items: flex-start;
}

.login-brand .brand-logo {
  width: 48px;
  height: 48px;
  flex-basis: 48px;
}

.login-panel h1 {
  font-size: 34px;
}

.login-panel p {
  margin-top: 6px;
  color: var(--muted);
}

@media (max-width: 980px) {
  .topbar,
  .workspace,
  .logs {
    grid-template-columns: 1fr;
  }

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

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

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

@media (max-width: 620px) {
  .shell {
    width: min(100vw - 20px, 1380px);
    padding-top: 14px;
  }

  h1 {
    font-size: 32px;
  }

  .brand-logo {
    width: 48px;
    height: 48px;
    flex-basis: 48px;
    margin-top: 1px;
  }

  .status-grid,
  .form-grid,
  .chart-readout,
  .wallet-summary,
  .wallet-coins,
  .grid-status,
  .metrics {
    grid-template-columns: 1fr;
  }

  .row {
    grid-template-columns: 1fr;
  }

  .grid-plan-row {
    grid-template-columns: 1fr 1fr;
  }

  .chart-help,
  .chart-help span {
    align-items: flex-start;
    flex-direction: column;
  }

  .chart-help small {
    white-space: normal;
  }

  .actions,
  .view-switch,
  #engineToggleBtn,
  .form-actions,
  .save-button,
  .form-service-menu,
  .form-service-menu summary {
    width: 100%;
  }

  .form-actions {
    align-items: stretch;
  }

  .menu-panel {
    left: 0;
    right: auto;
    min-width: min(280px, calc(100vw - 32px));
  }
}
