:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #17202a;
  --muted: #687385;
  --accent: #146c94;
  --accent-2: #7a5c14;
  --gain: #c92a2a;
  --loss: #087f5b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.admin-shell {
  width: min(1760px, calc(100vw - 32px));
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 24px;
  margin-bottom: 20px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  font-weight: 700;
}

h2,
.panel-title {
  font-size: 16px;
  font-weight: 650;
}

#subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.filters,
.cash-form {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.filters {
  grid-column: 1 / -1;
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.top-actions button,
.top-actions .button-link {
  width: auto;
}

.date-range-control {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.date-shortcuts {
  width: 252px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.date-shortcuts button {
  width: 100%;
  height: 28px;
  padding: 0 6px;
  border-color: var(--line);
  background: #fff;
  color: var(--accent);
  font-size: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

input,
select,
button,
.button-link {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  padding: 0 10px;
}

button,
.button-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  cursor: pointer;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

button.ghost,
.ghost-link {
  border-color: var(--line);
  background: #fff;
  color: var(--accent);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.snapshot-banner {
  margin-bottom: 12px;
  padding: 12px 16px;
  border: 1px solid #f08c00;
  border-left-width: 5px;
  border-radius: 8px;
  background: #fff4e6;
  color: #9c4f00;
  font-size: 15px;
  font-weight: 750;
  letter-spacing: 0.01em;
}

.snapshot-banner[hidden] {
  display: none;
}

.position-snapshot-note {
  display: inline-block;
  padding: 5px 9px;
  border: 1px solid #74c0fc;
  border-radius: 999px;
  background: #e7f5ff;
  color: #1864ab;
  font-weight: 750;
}

.position-snapshot-note:empty {
  display: none;
}

.position-snapshot-note.intraday-snapshot-note {
  border-color: #f08c00;
  background: #fff4e6;
  color: #9c4f00;
}

.metric,
.panel,
.cash-flow,
.daily-table {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric {
  padding: 14px;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
}

.metric-value {
  margin-top: 8px;
  font-size: 22px;
  font-weight: 720;
  font-variant-numeric: tabular-nums;
}

.gain {
  color: var(--gain);
}

.loss {
  color: var(--loss);
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-shell {
  width: min(420px, 100%);
}

.login-panel {
  display: grid;
  gap: 18px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.login-panel input,
.login-panel button {
  width: 100%;
}

.charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  height: 340px;
  padding: 16px;
}

.panel-wide {
  grid-column: 1 / -1;
  height: 300px;
}

.panel-title {
  margin-bottom: 12px;
}

.panel canvas {
  display: block;
  width: 100% !important;
  height: calc(100% - 32px) !important;
}

.fallback-chart {
  height: calc(100% - 32px);
}

.fallback-chart svg {
  display: block;
  width: 100%;
  height: 100%;
}

.fallback-chart text {
  fill: var(--muted);
  font-size: 13px;
}

.fallback-legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  color: var(--muted);
  font-size: 13px;
}

.fallback-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.fallback-legend i {
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: 999px;
}

.cash-flow,
.daily-table {
  padding: 16px;
  margin-bottom: 16px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-note {
  color: var(--muted);
  font-size: 12px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}

.pagination button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.tab {
  border-color: var(--line);
  background: #fff;
  color: var(--accent);
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.admin-panel {
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.hidden {
  display: none;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.row-actions button {
  height: 30px;
  padding: 0 8px;
  font-size: 12px;
}

.leverage-input {
  width: 72px;
  height: 30px;
}

.fee-lock-safety-input,
.margin-usage-limit-input,
.margin-wait-buffer-input,
.margin-wait-seconds-input {
  width: 72px;
  height: 30px;
}

.strategy-config {
  display: grid;
  gap: 4px;
}

.strategy-config label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  white-space: nowrap;
}

.trade-account-table th:nth-child(n + 4),
.trade-account-table td:nth-child(n + 4) {
  text-align: center;
  vertical-align: middle;
}

.trade-account-table .strategy-config {
  width: max-content;
  margin: 0 auto;
  justify-items: start;
}

.trade-account-table .instrument-config {
  min-width: 118px;
  gap: 6px;
  justify-items: stretch;
}

.trade-account-table .instrument-config > div {
  display: grid;
  grid-template-columns: 24px 48px auto;
  align-items: center;
  gap: 5px;
  text-align: left;
}

.trade-account-table .instrument-config button {
  height: 26px;
  padding: 0 6px;
  font-size: 11px;
}

.trade-account-table .risk-control-config > label:first-child {
  justify-self: center;
}

.trade-account-table .row-actions {
  justify-content: center;
}

textarea {
  width: 180px;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  font: inherit;
  font-size: 13px;
}

.permission-list,
.account-option-list,
.confirm-grid {
  display: grid;
  gap: 6px;
}

.permission-list {
  min-width: 240px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.account-option-list {
  min-width: 220px;
  max-height: 160px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.inline-check,
.confirm-grid label {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  color: var(--text);
  font-size: 12px;
}

.confirm-grid input[type="checkbox"] {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
}

.confirm-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.ledger-filter {
  margin-bottom: 12px;
}

.ledger-guide {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  background: #eef7fb;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.takeover-section {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.takeover-section h3 {
  margin: 0 0 6px;
}

.takeover-section p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.takeover-section .cash-form,
.takeover-section > label {
  margin-bottom: 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(23, 32, 42, 0.42);
}

.modal-backdrop.hidden {
  display: none;
}

.modal-panel {
  width: min(420px, 100%);
  max-height: calc(100dvh - 40px);
  display: grid;
  gap: 16px;
  padding: 20px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 48px rgba(23, 32, 42, 0.18);
}

.modal-panel p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.modal-panel input {
  width: 100%;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.cash-form {
  margin-bottom: 12px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
  font-size: 13px;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

thead th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 650;
}

tbody tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 1100px) {
  .toolbar {
    gap: 16px;
  }

  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .charts {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 20px, 1440px);
    padding-top: 16px;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  input,
  select,
  button,
  .button-link {
    width: 100%;
  }

  .filters,
  .cash-form,
  .confirm-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .top-actions {
    grid-row: 1;
  }

  .toolbar-title {
    grid-row: 2;
  }

  .date-range-control,
  .date-shortcuts {
    width: 100%;
  }

  .permission-list {
    grid-template-columns: 1fr;
  }

  .modal-backdrop {
    align-items: end;
    padding: 12px;
  }

  .modal-panel {
    width: 100%;
    max-height: calc(100dvh - 24px);
  }

  .modal-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .section-head {
    align-items: start;
    flex-direction: column;
  }

  .trade-account-table,
  .trade-account-table tbody,
  .trade-account-table tr,
  .trade-account-table td {
    display: block;
    width: 100%;
  }

  .trade-account-table thead {
    display: none;
  }

  .trade-account-table {
    white-space: normal;
  }

  .trade-account-table tr {
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
  }

  .trade-account-table tbody tr:last-child {
    border-bottom: 0;
  }

  .trade-account-table td {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    padding: 7px 0;
    border-bottom: 0;
    text-align: left;
  }

  .trade-account-table td::before {
    color: var(--muted);
    font-weight: 650;
  }

  .trade-account-table td:nth-child(1)::before { content: "账号"; }
  .trade-account-table td:nth-child(2)::before { content: "显示名"; }
  .trade-account-table td:nth-child(3)::before { content: "状态"; }
  .trade-account-table td:nth-child(4)::before { content: "交易品种"; }
  .trade-account-table td:nth-child(5)::before { content: "S1"; }
  .trade-account-table td:nth-child(6)::before { content: "S2"; }
  .trade-account-table td:nth-child(7)::before { content: "S3"; }
  .trade-account-table td:nth-child(8)::before { content: "S4"; }
  .trade-account-table td:nth-child(9)::before { content: "对锁设置"; }
  .trade-account-table td:nth-child(10)::before { content: "保证金风控"; }
  .trade-account-table td:nth-child(11)::before { content: "操作"; }

  .trade-account-table .strategy-config,
  .trade-account-table .instrument-config {
    width: 100%;
    margin: 0;
  }

  .trade-account-table .row-actions {
    justify-content: flex-start;
  }

  .trade-account-table button,
  .trade-account-table input,
  .trade-account-table select {
    width: auto;
  }
}
