:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --panel: #ffffff;
  --panel-alt: #f9faf8;
  --text: #1d2522;
  --muted: #66706a;
  --line: #dfe4dc;
  --blue: #2864d8;
  --green: #138453;
  --red: #bd2d2d;
  --amber: #9a6400;
  --cyan: #087a8c;
  --shadow: 0 16px 42px rgba(26, 33, 29, 0.08);
  font-family: "Inter", "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  padding: 0 14px;
  font-weight: 650;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

button:hover {
  border-color: #aeb8b0;
  background: #f7f8f6;
}

button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

button.success {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

button.danger {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

button.ghost {
  background: transparent;
}

button.wide {
  width: 100%;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 100, 216, 0.14);
}

input[readonly] {
  color: var(--muted);
  background: #f7f8f6;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  height: 40px;
  border-bottom: 1px solid var(--line);
  padding: 0 10px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  background: var(--panel-alt);
}

td {
  color: var(--text);
}

.login-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-row h1,
.topbar h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.brand-row p,
.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #20332c;
  color: #fff;
  font-weight: 850;
}

.brand-mark.small {
  width: 36px;
  height: 36px;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.app {
  min-height: 100vh;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  position: sticky;
  top: 0;
  z-index: 4;
  backdrop-filter: blur(10px);
}

.title-block,
.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.badge {
  display: inline-grid;
  place-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #fff;
  font-size: 12px;
  font-weight: 750;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
  align-items: start;
}

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

.strategy-panel {
  display: grid;
  gap: 18px;
  padding: 18px;
  position: sticky;
  top: 82px;
}

.workspace {
  display: grid;
  gap: 18px;
}

.panel-head {
  min-height: 48px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-alt);
}

.strategy-panel .panel-head {
  margin: -18px -18px 0;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

.muted {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

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

.field-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  border-radius: 0;
  min-height: 36px;
  border-right: 1px solid var(--line);
  color: var(--muted);
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: #20332c;
  color: #fff;
}

.toggle-line {
  min-height: 38px;
  align-items: end;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  color: var(--text);
}

.toggle-line input {
  width: 18px;
  min-height: 18px;
  align-self: center;
  accent-color: var(--green);
}

.range-group {
  display: grid;
  gap: 10px;
}

.range-group h3 {
  margin: 0;
  color: var(--text);
  font-size: 13px;
}

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

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

.metric {
  min-height: 74px;
  display: grid;
  align-content: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.metric strong {
  font-size: 19px;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.market-panel {
  padding-bottom: 14px;
}

.market-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto auto;
  gap: 10px;
  padding: 14px;
}

.table-wrap {
  overflow-x: auto;
}

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

.status-pill {
  display: inline-grid;
  place-items: center;
  min-width: 72px;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 780;
}

.status-pending {
  background: #fff3d8;
  color: var(--amber);
}

.status-filled {
  background: #dcf6ed;
  color: var(--green);
}

.status-closed {
  background: #e6eefc;
  color: var(--blue);
}

.status-canceled,
.status-halted {
  background: #fde3e3;
  color: var(--red);
}

.direction-long {
  color: var(--green);
  font-weight: 800;
}

.direction-short {
  color: var(--red);
  font-weight: 800;
}

.pnl-pos {
  color: var(--green);
  font-weight: 780;
}

.pnl-neg {
  color: var(--red);
  font-weight: 780;
}

.logs {
  display: grid;
  max-height: 260px;
  overflow: auto;
}

.log-row {
  display: grid;
  grid-template-columns: 168px 80px minmax(0, 1fr);
  gap: 10px;
  min-height: 38px;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.log-row:last-child {
  border-bottom: 0;
}

.log-time,
.log-level {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.log-level.risk {
  color: var(--red);
}

.log-level.fill {
  color: var(--green);
}

.log-level.close {
  color: var(--blue);
}

.empty-row {
  height: 46px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  min-width: 220px;
  max-width: min(420px, calc(100vw - 36px));
  min-height: 42px;
  display: none;
  align-items: center;
  padding: 10px 14px;
  border-radius: 8px;
  background: #20332c;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
  z-index: 8;
}

.toast.show {
  display: flex;
}

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

  .strategy-panel {
    position: static;
  }

  .metrics {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }
}

@media (max-width: 740px) {
  .topbar {
    height: auto;
    padding: 12px;
    align-items: flex-start;
  }

  .top-actions {
    gap: 8px;
  }

  .layout {
    padding: 10px;
    gap: 10px;
  }

  .field-grid.two,
  .field-grid.three,
  .split,
  .metrics,
  .market-row {
    grid-template-columns: 1fr;
  }

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

  .metric {
    min-height: 62px;
  }

  .log-row {
    grid-template-columns: 1fr;
    gap: 3px;
    padding: 10px 14px;
  }
}
