* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --bg: #07090a;
  --surface: #101315;
  --surface-2: #161a1d;
  --surface-3: #1b2024;
  --line: #30383e;
  --line-soft: #22292e;
  --muted: #939da5;
  --text: #edf0f2;
  --red: #ed5148;
  --red-deep: #912b26;
  --cyan: #19bdc8;
  --green: #45b878;
  --yellow: #d8bc56;
  --amber: #e2a53c;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  font-size: 13px;
}

button,
select,
input {
  font: inherit;
}

button,
select,
input[type="number"],
input[type="text"] {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #15191c;
  color: var(--text);
}

button {
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: #69757e;
  background: #1d2226;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  display: grid;
  grid-template-rows: 54px 24px minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #0d1012;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.24);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 330px;
}

.brand-mark,
.setup-mark {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border: 1px solid #bb443d;
  border-radius: 5px;
  background: #3a1715;
  color: #ff746b;
  font-size: 12px;
  font-weight: 800;
}

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

.brand-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.title {
  font-size: 16px;
  font-weight: 700;
}

.strategy-chip,
.fee-model-badge,
.risk-pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 6px;
  border: 1px solid #4d565d;
  border-radius: 3px;
  color: #bdc5ca;
  background: #171b1e;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 600;
}

.strategy-chip {
  border-color: #675626;
  color: #e3cb79;
  background: #241f10;
}

.subtitle {
  max-width: 520px;
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.icon-button {
  width: 34px;
  min-width: 34px;
  padding: 0;
  font-size: 17px;
}

.controls select {
  height: 32px;
}

.time-readout,
.zoom-readout,
.save-state {
  display: flex;
  align-items: center;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #141719;
  white-space: nowrap;
}

.time-readout {
  min-width: 128px;
  justify-content: center;
  color: #f1f3f4;
  font-variant-numeric: tabular-nums;
}

.save-state {
  min-width: 58px;
  color: var(--muted);
  font-size: 11px;
}

.save-state.saved {
  color: #66c58b;
}

.save-state.error {
  color: #f07469;
}

.progress-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 54px;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--line-soft);
  background: #0b0e10;
}

.progress-row progress {
  width: 100%;
  height: 7px;
  accent-color: var(--red);
}

#progressReadout {
  color: var(--muted);
  text-align: right;
  font-size: 11px;
}

.daily-flat-banner {
  position: fixed;
  top: 92px;
  left: calc((100vw - 400px) / 2);
  z-index: 45;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  width: min(620px, calc(100vw - 460px));
  min-height: 58px;
  padding: 9px 10px;
  border: 1px solid #9f762a;
  border-radius: 6px;
  background: rgba(35, 29, 14, 0.97);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.46);
  transform: translateX(-50%);
}

.daily-flat-banner.urgent {
  border-color: #b64239;
  background: rgba(45, 19, 17, 0.98);
}

.daily-flat-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid #b98a34;
  border-radius: 50%;
  color: #f0c769;
  font-size: 18px;
  font-weight: 800;
}

.daily-flat-banner.urgent .daily-flat-icon {
  border-color: #db554c;
  color: #ff8279;
}

.daily-flat-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.daily-flat-copy strong {
  color: #f4e4b5;
  font-size: 13px;
}

.daily-flat-banner.urgent .daily-flat-copy strong {
  color: #ffaba4;
}

.daily-flat-copy span {
  overflow: hidden;
  color: #c9bea0;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.daily-flat-actions {
  display: flex;
  gap: 6px;
}

.daily-flat-actions button {
  min-width: 78px;
  padding: 0 10px;
  white-space: nowrap;
}

.daily-flat-actions .daily-flat-primary {
  border-color: #b88630;
  background: #8f631d;
  color: #fff3d4;
  font-weight: 700;
}

.daily-flat-banner.urgent .daily-flat-primary {
  border-color: #d15147;
  background: #9d3029;
  color: #fff;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  min-height: 0;
  overflow: hidden;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(245px, 1fr));
  min-height: 0;
  overflow-x: auto;
  background: var(--line);
  gap: 1px;
}

.panel {
  position: relative;
  display: grid;
  grid-template-rows: 38px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  border: 1px solid #2d353a;
  background: #080a0b;
}

.panel-header {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 4px 6px;
  border-bottom: 1px solid #2b3237;
  background: #101315;
}

.period-select {
  width: 78px;
  min-width: 0;
  min-height: 28px;
  height: 28px;
  padding: 2px 5px;
  border: 1px solid #334149;
  border-radius: 4px;
  outline: 0;
  appearance: auto;
  background: #161d21;
  color: #f0f2f3;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.period-select:focus-visible {
  color: #63dce3;
}

.period-select option {
  background: #101315;
  color: #f0f2f3;
}

.panel-values {
  min-width: 0;
  overflow: hidden;
  color: #bfc6cb;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.panel canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  background: #080a0b;
  cursor: crosshair;
}

.trade-panel {
  min-height: 0;
  overflow-y: auto;
  border-left: 1px solid #3a4248;
  background: var(--surface);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.18);
  scrollbar-color: #455058 #15191c;
  scrollbar-width: thin;
}

.trade-panel section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.section-head.compact {
  align-items: center;
}

.section-title {
  color: #f1f3f5;
  font-size: 13px;
  font-weight: 700;
}

.session-id {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.head-actions {
  display: flex;
  gap: 5px;
}

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

.account-metric {
  min-width: 0;
  min-height: 48px;
  padding: 7px 8px;
  border-left: 2px solid #384148;
  background: #14181b;
}

.account-metric.primary {
  border-left-color: #b88935;
  background: #191a17;
}

.account-grid span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 10px;
}

.account-grid strong {
  display: block;
  overflow: hidden;
  color: #f3f5f7;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.account-metric.primary strong {
  color: #fff;
  font-size: 16px;
}

.position-line {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: baseline;
  gap: 10px;
  margin-top: 8px;
  padding: 9px 10px;
  border: 1px solid #2b3338;
  border-radius: 4px;
  background: #131719;
  font-variant-numeric: tabular-nums;
}

.position-line strong {
  font-size: 15px;
}

.position-line strong.long,
.positive {
  color: var(--red) !important;
}

.position-line strong.short,
.negative {
  color: var(--cyan) !important;
}

.position-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 7px;
  color: var(--muted);
  font-size: 10px;
}

.risk-pill {
  border-color: #38634c;
  background: #14251c;
  color: #76ca98;
}

.risk-pill.warning {
  border-color: #826624;
  background: #29220f;
  color: #e7c15e;
}

.risk-pill.danger {
  border-color: #9e3932;
  background: #311513;
  color: #ff8178;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #7c878e;
  font-size: 10px;
}

.live-indicator i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #50b77a;
  box-shadow: 0 0 0 2px rgba(80, 183, 122, 0.14);
}

.signal-status {
  margin-top: 8px;
  padding: 7px 8px;
  border-left: 3px solid #59636d;
  background: #111417;
  font-weight: 700;
}

.signal-status.long {
  border-color: var(--red);
  color: #ff8178;
}

.signal-status.short {
  border-color: var(--cyan);
  color: #5adce5;
}

.signal-status.neutral {
  color: var(--muted);
}

.cross-status {
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
}

.fee-model-badge {
  border-color: #665727;
  background: #24200f;
  color: #dfca79;
}

.quantity-row {
  display: grid;
  grid-template-columns: 34px 30px 54px 30px repeat(3, 31px);
  align-items: center;
  gap: 5px;
  margin-top: 9px;
}

.quantity-row label,
.field-row label {
  color: var(--muted);
  font-size: 11px;
}

.quantity-row input {
  width: 54px;
  padding: 0 5px;
  text-align: center;
}

.quantity-step,
.quick-qty {
  width: 30px;
  min-width: 30px;
  padding: 0;
}

.quick-qty {
  color: #bdc5ca;
  font-size: 11px;
}

input:focus,
select:focus,
button:focus-visible {
  border-color: #76828b;
  outline: 2px solid rgba(118, 130, 139, 0.22);
  outline-offset: 1px;
}

.field-row {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  margin-top: 7px;
}

.field-row select {
  width: 100%;
  padding: 0 6px;
}

.note-input {
  width: 100%;
  margin-top: 7px;
  padding: 0 8px;
}

.research-labels {
  margin-top: 9px;
  border-top: 1px solid #293136;
  border-bottom: 1px solid #293136;
}

.quick-research-capture {
  margin-top: 9px;
  padding: 9px;
  border: 1px solid #355059;
  background: #142126;
}

.quick-research-head {
  margin-bottom: 6px;
  color: #a9cbd2;
  font-size: 11px;
  font-weight: 600;
}

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

.quick-research-grid label {
  min-width: 0;
  color: var(--muted);
  font-size: 10px;
}

.quick-research-grid select {
  width: 100%;
  min-width: 0;
  height: 28px;
  margin-top: 3px;
  border: 1px solid #3a5059;
  background: #11191d;
  color: var(--text);
  font-size: 11px;
}

.research-labels summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 31px;
  cursor: pointer;
  color: #d8dde0;
  font-size: 11px;
  font-weight: 700;
  list-style: none;
}

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

.research-labels summary::before {
  margin-right: 6px;
  color: #88949c;
  content: "+";
  font-size: 14px;
  font-weight: 400;
}

.research-labels[open] summary::before {
  content: "−";
}

.research-labels summary > span:first-child {
  margin-right: auto;
}

.research-label-state {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 0 5px;
  border: 1px solid #465159;
  border-radius: 3px;
  color: #aab3b9;
  background: #15191c;
  font-size: 10px;
  font-weight: 600;
}

.research-label-state.active {
  border-color: #667246;
  color: #d6e29c;
  background: #202517;
}

.research-label-body {
  padding: 1px 0 9px;
}

.research-field {
  margin-top: 8px;
}

.research-field-label {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 10px;
}

.tag-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag-grid label {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid #344047;
  border-radius: 3px;
  background: #13181b;
  cursor: pointer;
  overflow: hidden;
}

.tag-grid input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.tag-grid span {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 6px;
  color: #aeb8be;
  font-size: 10px;
  white-space: nowrap;
}

.tag-grid input:checked + span {
  color: #f1e4a8;
  background: #3a3218;
}

.family-tags input:checked + span {
  color: #a6e4e9;
  background: #13343a;
}

.structure-tags input:checked + span {
  color: #f3c39b;
  background: #392516;
}

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

@media (max-width: 780px) {
  .quick-research-grid {
    grid-template-columns: 1fr;
  }
}

.research-context-grid label {
  min-width: 0;
  color: var(--muted);
  font-size: 10px;
}

.research-context-grid select {
  width: 100%;
  min-width: 0;
  height: 28px;
  min-height: 28px;
  margin-top: 3px;
  padding: 0 4px;
  color: #d8dee1;
  font-size: 10px;
}

.research-export-button {
  width: 100%;
  height: 29px;
  margin-top: 8px;
  border-color: #566a73;
  color: #cddce0;
  background: #172126;
  font-size: 11px;
  font-weight: 600;
}

.research-export-button:hover:not(:disabled) {
  border-color: #78a5ae;
  background: #1d2e34;
}

.trade-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.trade-buttons button {
  height: 38px;
  font-weight: 700;
}

.buy-button {
  border-color: #a3362e;
  background: #7d241f;
}

.buy-button:hover:not(:disabled) {
  border-color: #ef6a5f;
  background: #9b2f28;
}

.sell-button {
  border-color: #15818a;
  background: #0b6168;
}

.sell-button:hover:not(:disabled) {
  border-color: #47d7e1;
  background: #0f7881;
}

.close-button {
  border-color: #727b84;
  background: #3c434a;
}

.secondary-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 6px;
}

.secondary-buttons button {
  color: #cbd1d5;
}

.pending-order {
  margin-top: 8px;
  padding: 7px;
  border: 1px solid #725f22;
  border-radius: 4px;
  background: #211d0c;
  color: #eadb86;
  font-size: 11px;
}

.execution-note {
  margin-top: 7px;
  color: var(--muted);
  font-size: 10px;
}

.action-list {
  max-height: 190px;
  margin-top: 7px;
  overflow-y: auto;
}

.action-item {
  display: grid;
  grid-template-columns: 58px 1fr auto;
  gap: 7px;
  align-items: center;
  min-height: 30px;
  border-top: 1px solid #20262b;
  color: #ced4da;
  font-size: 10px;
}

.action-item:hover {
  background: #15191c;
}

.action-item:first-child {
  border-top: 0;
}

.action-item .action-time {
  color: var(--muted);
}

.action-item .action-main {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-item .action-value {
  text-align: right;
}

.empty-ledger {
  padding: 12px 0;
  color: var(--muted);
  text-align: center;
  font-size: 11px;
}

.market-rules {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
}

.market-rule-note {
  margin-top: 3px;
  color: #d2bc70;
}

.tooltip {
  position: fixed;
  z-index: 30;
  min-width: 210px;
  padding: 8px 9px;
  border: 1px solid #52606a;
  border-radius: 4px;
  background: rgba(5, 6, 7, 0.96);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  font-size: 11px;
  line-height: 1.45;
}

.tooltip .row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
}

.tooltip .name {
  color: var(--muted);
}

.toast {
  position: fixed;
  z-index: 60;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 10px 12px;
  border: 1px solid #53606b;
  border-radius: 4px;
  background: #171b1f;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.toast.error {
  border-color: #a23d34;
  color: #ff8f86;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.78);
}

.setup-dialog {
  width: min(390px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid #47515a;
  border-radius: 6px;
  background: #101316;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
}

.setup-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.setup-heading .setup-mark {
  width: 44px;
  height: 44px;
  flex-basis: 44px;
  font-size: 14px;
}

.setup-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

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

.setup-dialog label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
}

.setup-dialog input,
.setup-dialog select {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  font-size: 16px;
}

.setup-dialog select {
  margin-bottom: 10px;
  cursor: pointer;
}

.contract-choice-hint {
  margin: -3px 0 12px;
  color: #aeb9c0;
  font-size: 11px;
  line-height: 1.45;
}

.setup-rule {
  margin-top: 9px;
  color: var(--muted);
  font-size: 11px;
}

.primary-button {
  width: 100%;
  height: 38px;
  margin-top: 18px;
  border-color: #b54036;
  background: #8f2b25;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.up,
.ma250 {
  color: #ff554b;
}

.down {
  color: #22d0da;
}

.ma5 {
  color: #d8d8d8;
}

.ma10 {
  color: #e5d900;
}

.ma89 {
  color: #478dff;
}

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 360px;
  }

  .daily-flat-banner {
    left: calc((100vw - 360px) / 2);
    width: min(560px, calc(100vw - 410px));
  }

  .grid {
    grid-template-columns: repeat(2, minmax(300px, 1fr));
    grid-template-rows: repeat(2, minmax(320px, 1fr));
    overflow: auto;
  }
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-rows: auto 24px auto;
    height: auto;
    min-height: 100vh;
  }

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

  .brand {
    min-width: 0;
  }

  .daily-flat-banner {
    top: 108px;
    right: 10px;
    left: 10px;
    grid-template-columns: 32px minmax(0, 1fr);
    width: auto;
    transform: none;
  }

  .daily-flat-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }

  .controls {
    width: 100%;
    overflow-x: auto;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  .grid {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, 520px);
    overflow: visible;
  }

  .trade-panel {
    overflow: visible;
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}
