/* 本样式表由一次性脚本合并 v1/v2/v3 三段历史层叠并去重：同一（at-rule 上下文, 选择器）的声明按源码顺序合并（!important 恒胜、后者胜），规则顺序按各规则在原文件中最后一次出现的位置排列；个别被合并改变了竞争位置的声明以「层叠锚定」小规则保留在其原始位置，渲染结果与合并前完全一致。 */

* {
  box-sizing: border-box;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--acid);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.field input:hover,
.field input:focus,
.field select:hover,
.field select:focus {
  background: var(--bg-raised);
  border-color: var(--line-hot);
}

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

.primary-action:disabled {
  background: #d9dfd9;
  color: #86928a;
  cursor: not-allowed;
}

.login-action {
  width: 100%;
}

.status-dot,
.connection-light {
  background: var(--dim);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(83, 98, 100, 0.12);
  display: inline-block;
  height: 6px;
  width: 6px;
}

.status-dot,
.connection-light.is-data,
.connection-light.is-connected {
  background: var(--acid);
  box-shadow: 0 0 0 3px var(--acid-soft), 0 0 12px rgba(39, 122, 70, 0.3);
}

.desk-brand strong,
.desk-brand small,
.connection-state strong,
.connection-state small,
.account-button strong,
.account-button small,
.position-timer strong,
.position-timer small {
  display: block;
}

/* 顶栏中央的持仓计时：开仓起点存 localStorage（刷新续计），空仓隐藏。
   绝对定位相对整个顶栏居中——flex 双 spacer 只能让计时在左右两组元素
   之间居中，移动端左组（图标）远窄于右组（灯+设置+退出）会明显偏左。 */
.position-timer {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  text-align: center;
}

/* 作者样式的 display:flex 会压过 UA 的 [hidden] 规则，显式补回。 */
.position-timer[hidden] {
  display: none;
}

/* 层叠锚定：保持该声明在原文件中的竞争位置（详见文件头）。 */
.header-mode {
  display: flex;
}

.header-spacer {
  flex: 1;
}

/* 层叠锚定：保持该声明在原文件中的竞争位置（详见文件头）。 */
.connection-state,
.account-button {
  display: flex;
}

/* 层叠锚定：保持该声明在原文件中的竞争位置（详见文件头）。 */
.legend-item em {
  color: var(--dim);
  font-style: normal;
}

.legend-value {
  font-weight: 500;
}

.legend-value.ema20 {
  color: var(--amber);
}

.legend-value.ema50 {
  color: #e843b9;
}

.legend-value.ema200 {
  color: #e94b71;
}

.legend-value.donchian {
  color: #5096ad;
}

.legend-value.day-range {
  color: #848e9c;
}

.legend-value.supertrend-up {
  color: #0ecb81;
}

.legend-value.supertrend-down {
  color: #f6465d;
}

.tool-button:hover {
  color: var(--text);
}

.tool-button.is-active {
  color: var(--text);
  font-weight: 600;
}

#market-chart {
  display: block;
  height: 100%;
  position: relative;
  width: 100%;
  z-index: 2;
}

.chart-tooltip {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 4px 14px rgba(24, 26, 32, 0.12);
  color: var(--text);
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.5;
  max-width: 280px;
  padding: 8px 10px;
  pointer-events: none;
  position: absolute;
  z-index: 5;
}

.chart-tooltip[hidden] {
  display: none;
}

.chart-tooltip-time {
  color: var(--muted);
  margin-bottom: 4px;
}

.chart-tooltip-grid {
  display: grid;
  gap: 1px 8px;
  grid-template-columns: auto 1fr;
}

.chart-tooltip-grid span {
  color: var(--muted);
}

.chart-tooltip-grid strong {
  font-weight: 600;
  text-align: right;
}

.chart-tooltip-reversal {
  border-top: 1px solid var(--line);
  font-weight: 600;
  margin-top: 6px;
  padding-top: 6px;
}

.chart-tooltip-reversal.is-long {
  color: #0ecb81;
}

.chart-tooltip-reversal.is-short {
  color: #f6465d;
}

.chart-tooltip-factors {
  border-top: 1px dashed var(--line);
  display: grid;
  gap: 2px;
  margin-top: 4px;
  padding-top: 4px;
}

.chart-tooltip-factor {
  display: grid;
  gap: 6px;
  grid-template-columns: auto 1fr auto;
}

.chart-tooltip-factor span {
  color: var(--muted);
}

.chart-tooltip-factor strong {
  font-weight: 500;
}

.chart-tooltip-factor.is-long strong {
  color: #0ecb81;
}

.chart-tooltip-factor.is-short strong {
  color: #f6465d;
}

.chart-tooltip-factor.is-unavailable strong,
.chart-tooltip-factor em {
  color: var(--dim);
}

.chart-tooltip-factor em {
  font-style: normal;
  text-align: right;
}

.tool-button:disabled {
  cursor: default;
  opacity: 0.42;
}

/* The 最新 button doubles as an "at latest" state indicator, keep it readable. */
#chart-latest:disabled {
  opacity: 1;
}

/* 币安式最新价标签：价格轴旁的彩色方块，上行最新价、下行 K 线倒计时；
   宽度由 JS 对齐到价格轴列宽，左缘与价格轴竖线齐平。 */
.chart-price-tag {
  align-items: center;
  background: var(--acid);
  border-radius: 3px;
  box-sizing: border-box;
  color: #ffffff;
  display: flex;
  flex-direction: column;
  font-family: var(--mono);
  gap: 0;
  padding: 3px 4px;
  pointer-events: none;
  position: absolute;
  right: 0;
  top: 4px;
  z-index: 3;
}

.chart-price-tag.is-down {
  background: var(--red);
}

/* 均价标签：与均价线同色的深色方块，锚定图表左缘（右轴原生标签关闭）。 */
.chart-entry-tag {
  align-items: baseline;
  background: #474d57;
  flex-direction: row;
  gap: 3px;
  left: 0;
  right: auto;
}

/* 24h 高/低点标签：比均价标签更淡的灰色小方块，横向「标签 + 数值」，
   锚定图表左缘，纵坐标跟随各自的 price line。 */
.chart-day-range-tag {
  align-items: baseline;
  background: #848e9c;
  flex-direction: row;
  gap: 3px;
  left: 0;
  opacity: 0.9;
  padding: 1px 4px;
  right: auto;
}

.chart-price-tag strong {
  font-size: 10px;
  font-weight: 600;
  line-height: 1.3;
}

.chart-price-tag span {
  font-size: 9px;
  line-height: 1.3;
  opacity: 0.92;
}

/* 层叠锚定：保持该声明在原文件中的竞争位置（详见文件头）。 */
.right-rail {
  grid-template-rows: minmax(390px, auto) auto;
}

.toast.is-error {
  border-left-color: var(--red);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

  .ticker-deck {
    grid-template-columns: auto auto;
  }

  .ticker-stats {
    grid-column: 1 / -1;
  }
}

@media (max-width: 1050px) {
  .desk-workspace {
    grid-template-columns: 1fr;
  }

  .right-rail {
    grid-template-columns: 1fr 1fr;
  }
}

/* 层叠锚定：保持该声明在原文件中的竞争位置（详见文件头）。 */
@media (max-width: 1050px) {
  .right-rail {
    grid-template-rows: auto;
  }
}

/* 层叠锚定：保持该声明在原文件中的竞争位置（详见文件头）。 */
@media (max-width: 1050px) {
  .connection-state {
    display: none;
  }
}

@media (max-width: 760px) {
  .desk-header {
    padding: 0 10px;
  }

  .desk-brand {
    min-width: auto;
  }

  .account-button {
    min-width: auto;
    padding: 0 12px;
  }

  .chart-stage {
    height: 520px;
  }

  .right-rail {
    grid-template-columns: 1fr;
  }
}

/* 层叠锚定：保持该声明在原文件中的竞争位置（详见文件头）。 */
@media (max-width: 760px) {
  .desk-brand > span:last-child,
  .header-mode,
  .account-button small,
  .account-button > span:last-child,
  .position-timer small {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}

:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --bg-raised: #f7f8fa;
  --panel: #ffffff;
  --line: #e6e8ec;
  --line-hot: #c9ced6;
  --text: #181a20;
  --muted: #616975;
  --dim: #8b93a1;
  --acid: #0ecb81;
  --acid-soft: rgba(14, 203, 129, 0.09);
  --red: #f6465d;
  --amber: #f0b90b;
  --border: #e6e8ec;
  --surface: #f8f9fa;
  --text-muted: #616975;
  --shadow-xl: 0 30px 80px rgba(31, 38, 51, 0.12);
  --danger: #f6465d;
  --success: #0ecb81;
  --display: "SF Pro Display", -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI",
    sans-serif;
  --body: "SF Pro Text", -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI",
    sans-serif;
  --mono: "SFMono-Regular", "Roboto Mono", Menlo, Consolas, monospace;
}

html {
  min-width: 320px;
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  color: var(--text);
  font-family: var(--body);
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: radial-gradient(circle at 4% -8%, rgba(11, 143, 106, 0.07), transparent 28rem),
    var(--bg);
  font-feature-settings: "tnum" 1, "cv02" 1, "cv03" 1;
}

/* Login */
.login-view {
  align-items: center;
  background: #f6f7f9;
  display: grid;
  justify-content: center;
  margin: 0 auto;
  max-width: 1920px;
  min-height: 100vh;
}

.login-card {
  animation: modern-card-in 560ms 80ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  background: rgba(255, 255, 255, 0.93);
  border: 1px solid rgba(225, 228, 233, 0.9);
  border-radius: 24px;
  box-shadow: 0 30px 80px rgba(31, 38, 51, 0.12),
    0 2px 8px rgba(31, 38, 51, 0.04);
  justify-self: center;
  margin: 0;
  padding: 42px;
  width: clamp(320px, 25vw, 480px);
}

.dialog-header h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 18px;
  font-weight: 680;
  letter-spacing: -0.025em;
  line-height: 1.2;
  text-transform: none;
}

.login-card h2 {
  font-size: 30px;
  text-align: center;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 17px;
}

.field > span {
  color: #474e59;
  font-family: var(--body);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.field input,
.field select {
  color: var(--text);
  padding: 0 13px;
  width: 100%;
  background: #f8f9fa;
  border: 1px solid #e1e4e8;
  border-radius: 11px;
  min-height: 48px;
  padding-inline: 14px;
  transition: background 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease;
}

.field input:not([type="checkbox"]):hover,
.field input:not([type="checkbox"]):focus,
.field select:hover,
.field select:focus {
  background: #fff;
  border-color: rgba(11, 143, 106, 0.58);
  box-shadow: 0 0 0 3px rgba(11, 143, 106, 0.08);
}

.primary-action {
  align-items: center;
  border: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 16px;
  color: #fff;
  border-radius: 11px;
  font-family: var(--body);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0;
  min-height: 50px;
  padding-inline: 17px;
  text-transform: none;
  background: linear-gradient(135deg, #0a8a67, #0ba679);
  box-shadow: 0 8px 18px rgba(11, 143, 106, 0.16);
}

.primary-action:hover {
  background: linear-gradient(135deg, #087a5b, #09946c);
  transform: translateY(-1px);
}

.login-footnote {
  align-items: center;
  display: flex;
  gap: 8px;
  letter-spacing: 0.04em;
  color: var(--dim);
  font-family: var(--body);
  font-size: 11px;
  justify-content: center;
  margin-top: 20px;
}

.terminal-shell {
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  z-index: 1;
  max-width: none;
  padding-bottom: 28px;
}

.desk-header {
  border-bottom: 1px solid var(--line);
  display: flex;
  position: sticky;
  top: 0;
  z-index: 40;
  align-items: center;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
  border-color: var(--line);
  height: 64px;
  padding: 0 18px;
}

.desk-brand {
  align-items: center;
  color: inherit;
  display: flex;
  text-decoration: none;
  gap: 10px;
  min-width: 220px;
}

.brand-sigil {
  align-items: center;
  color: #fff;
  display: flex;
  font-family: var(--display);
  font-weight: 900;
  justify-content: center;
  background: linear-gradient(145deg, #087a5b, #12a87e);
  border-radius: 10px;
  box-shadow: 0 6px 14px rgba(11, 143, 106, 0.18);
  font-size: 16px;
  height: 34px;
  letter-spacing: 0;
  transform: none;
  width: 34px;
}

.desk-brand strong {
  font-family: var(--display);
  font-size: 15px;
  font-weight: 680;
  letter-spacing: -0.015em;
}

.desk-brand small,
.connection-state small,
.account-button small {
  color: var(--dim);
  font-family: var(--body);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0;
  margin-top: 2px;
}

.desk-nav {
  align-items: center;
  display: flex;
  gap: 6px;
  height: 100%;
  margin-left: 8px;
}

.desk-nav a {
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
  padding: 9px 12px;
  text-decoration: none;
  transition: background 150ms ease,
    color 150ms ease;
}

.desk-nav a:hover,
.desk-nav a.is-active {
  background: #f2f4f6;
  color: var(--text);
}

.header-mode {
  align-items: center;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: #fff8e7;
  border: 1px solid #f0dfb7;
  border-radius: 999px;
  color: #98640b;
  font-family: var(--body);
  font-size: 10px;
  font-weight: 650;
  gap: 6px;
  height: 28px;
  letter-spacing: 0;
  margin-left: 12px;
  padding: 0 10px;
}

.mode-switch {
  position: relative;
  background: #e5b035;
  border-radius: 999px;
  height: 8px;
  width: 8px;
}

.connection-state,
.account-button {
  align-items: center;
  gap: 9px;
  padding: 0 13px;
}

.connection-state strong,
.account-button strong {
  font-family: var(--body);
  font-size: 11px;
  font-weight: 620;
  letter-spacing: 0;
  margin-top: 2px;
}

.account-button {
  background: transparent;
  border-left: 1px solid var(--line);
  text-align: left;
  border: 1px solid transparent;
  border-radius: 10px;
  min-height: 44px;
  min-width: 170px;
}

.account-button:hover {
  background: #f5f6f8;
  border-color: var(--line);
}

.icon-button {
  background: transparent;
  border-left: 1px solid var(--line);
  color: var(--muted);
  border: 0;
  border-radius: 9px;
  font-size: 12px;
  height: 38px;
  margin-left: 4px;
  padding-inline: 12px;
  white-space: nowrap;
}

.icon-button:hover {
  color: var(--text);
  background: #f1f3f5;
}

/* 顶栏元素一律不换行、不压缩（弹性空间由 .header-spacer 吸收），
   空间不足时靠媒体查询分级收敛，杜绝「仅人工」折行这类挤压。 */
.desk-header > *:not(.header-spacer) {
  flex-shrink: 0;
}

.desk-brand,
.desk-nav a,
.header-mode,
.connection-state,
.account-button,
.position-timer {
  white-space: nowrap;
}

.ticker-deck {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 28px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(31, 38, 51, 0.025);
  column-gap: 20px;
  grid-template-columns: minmax(270px, auto) minmax(520px, 1fr);
  margin: 12px 16px 0;
  min-height: 80px;
  padding: 10px 16px;
  row-gap: 9px;
}

.ticker-identity {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: center;
  min-width: 270px;
}

.symbol-row {
  align-items: center;
  display: flex;
  gap: 10px;
}

.symbol-trigger strong {
  line-height: 1;
  font-family: var(--display);
  font-size: 23px;
  font-weight: 720;
  letter-spacing: -0.035em;
}

.symbol-menu {
  position: relative;
}

.trend-badge {
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.symbol-trigger {
  align-items: baseline;
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  gap: 6px;
  padding: 0;
}

.symbol-options {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  display: grid;
  left: 0;
  min-width: 150px;
  padding: 6px;
  position: absolute;
  top: calc(100% + 6px);
  z-index: 30;
}

.symbol-options button {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 7px;
  color: inherit;
  cursor: pointer;
  display: flex;
  font-family: var(--body);
  font-size: 13px;
  font-weight: 600;
  gap: 8px;
  padding: 8px 10px;
  text-align: left;
}

.symbol-options button span {
  color: var(--muted);
  width: 14px;
}

.symbol-options button:hover {
  background: #f3f5f7;
}

.symbol-options button.is-active {
  color: var(--acid);
}

.symbol-options button.is-active span {
  color: var(--acid);
}

.ticker-stats {
  display: grid;
  margin: 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.ticker-stats div {
  border-left: 1px solid var(--line);
  border-left-color: var(--line);
  min-width: 0;
  padding-left: 10px;
}

.ticker-stats dt {
  color: var(--dim);
  font-family: var(--body);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
}

.ticker-stats dd {
  margin: 9px 0 0;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 550;
  margin-top: 4px;
}

.ticker-stats dd.is-long {
  color: var(--acid);
}

.ticker-stats dd.is-short {
  color: var(--red);
}

.panel {
  border: 1px solid var(--line);
  min-width: 0;
  position: relative;
  background: rgba(255, 255, 255, 0.98);
  border-color: var(--line);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(31, 38, 51, 0.03),
    0 8px 24px rgba(31, 38, 51, 0.025);
  overflow: hidden;
}

/* 图例悬浮在 K 线图左上角（币安式），不拦截鼠标事件；EMA 一行、唐奇安一行。 */
.chart-legends {
  display: flex;
  flex-direction: column;
  gap: 2px;
  left: 8px;
  pointer-events: none;
  position: absolute;
  top: 6px;
  z-index: 3;
}

.chart-legends-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.chart-legends span {
  align-items: center;
  display: flex;
  color: var(--muted);
  font-family: var(--body);
  font-size: 11px;
  gap: 6px;
}

/* 币安式纯文字标签：无边框无底色，选中项加粗深色。 */
.tool-button {
  -webkit-tap-highlight-color: transparent;
  background: transparent;
  border: none;
  color: var(--dim);
  font-weight: 500;
  padding: 0 10px;
  font-family: var(--body);
  font-size: 12px;
  min-height: 30px;
  padding-inline: 10px;
}

.tool-button-icon {
  align-items: center;
  display: inline-flex;
  justify-content: center;
}

.tool-button-icon svg {
  height: 16px;
  width: 16px;
}

.chart-toolbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  color: var(--dim);
  display: flex;
  font-family: var(--mono);
  padding: 0 16px;
  background: #fafbfc;
  border-bottom-color: var(--line);
  font-size: 11px;
  gap: clamp(9px, 1vw, 18px);
  min-height: 32px;
  overflow-x: auto;
  white-space: nowrap;
}

.chart-toolbar .chart-tools {
  align-items: center;
  flex-direction: row;
  flex-shrink: 0;
}

.chart-toolbar .tool-button {
  font-size: 12px;
  min-height: 24px;
  padding-inline: 8px;
}

.chart-watermark {
  left: 50%;
  pointer-events: none;
  position: absolute;
  text-align: center;
  top: 33%;
  transform: translate(-50%, -50%);
  z-index: 1;
  opacity: 0.032;
}

.chart-watermark strong {
  display: block;
  letter-spacing: -0.06em;
  font-family: var(--display);
  font-size: clamp(60px, 7vw, 104px);
  font-weight: 720;
}

.chart-watermark span {
  font-family: var(--body);
  font-size: 10px;
  letter-spacing: 0.12em;
}

.field.compact {
  gap: 5px;
  margin-bottom: 7px;
}

.field.compact input,
.field.compact select {
  font-family: var(--mono);
  background: #f7f8fa;
  border-radius: 9px;
  font-size: 14px;
  min-height: 44px;
}

.order-actions {
  display: grid;
  gap: 7px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 10px;
  /* 「手动」按钮/手动行/「半平」按钮的绝对定位锚点（三者移出网格流，不占列）。 */
  position: relative;
}

.order-action {
  border: 1px solid transparent;
  border-radius: 10px;
  font-family: var(--body);
  font-size: 14px;
  font-weight: 680;
  min-height: 50px;
  padding-inline: 8px;
  transition: background 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease,
    transform 150ms ease;
}

.order-action:hover:not(:disabled) {
  box-shadow: 0 8px 18px rgba(31, 38, 51, 0.12);
  transform: translateY(-1px);
}

.order-action.is-open.is-long {
  background: linear-gradient(135deg, #0b8f6a, #0ba579);
  color: #fff;
}

.order-action.is-open.is-short {
  background: linear-gradient(135deg, #df4057, #ef5267);
  color: #fff;
}

.order-action.is-close {
  background: #fff8e9;
  border-color: #f0dfb7;
  color: #98640b;
}

.order-action.is-cancel {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-muted);
}

.order-action.is-cancel:hover:not(:disabled) {
  color: var(--danger);
  border-color: var(--danger);
}

.order-actions .order-action:disabled {
  cursor: wait;
}

/* 手动快捷行：「手动」按钮锚在保证金/杠杆模块的右上方（以操作按钮行为
   定位锚点：7px 行距 + 字段行 40px + 6px 间距 = 53px），尺寸与「平仓」
   等操作按钮一致（44px 高、网格单列宽）；点击向左展开一行（金额输入 /
   做多 / 做空 / 全平 / 关闭），行宽与下方操作模块同宽，PC/H5 同一交互。 */
.manual-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  bottom: calc(100% + 53px);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 680;
  min-height: 44px;
  padding-inline: 8px;
  position: absolute;
  right: 0;
  /* 与操作行网格单列同宽（4 列、3 × 7px 间距）。 */
  width: calc((100% - 21px) / 4);
  z-index: 45;
}

.manual-toggle[aria-expanded="true"] {
  border-color: var(--muted);
  color: var(--text);
}

/* 「半平」按钮（1/2 平仓）：与「手动」同款浮出定位（移出网格流），锚在其
   左侧一个网格列宽 + 7px 间距处，尺寸与操作按钮一致。 */
.close-half-toggle {
  bottom: calc(100% + 53px);
  cursor: pointer;
  min-height: 44px;
  position: absolute;
  right: calc((100% - 21px) / 4 + 7px);
  width: calc((100% - 21px) / 4);
  z-index: 45;
}

/* 「信号」按钮（按最近反转信号先平再开）：与「半平」同款浮出定位（移出
   网格流），锚在半平左侧一个网格列宽 + 7px 间距处，尺寸与操作按钮一致。 */
.signal-order-toggle {
  background: #eef2ff;
  border-color: #c7d2fe;
  bottom: calc(100% + 53px);
  color: #4338ca;
  cursor: pointer;
  min-height: 44px;
  position: absolute;
  right: calc(2 * ((100% - 21px) / 4) + 14px);
  width: calc((100% - 21px) / 4);
  z-index: 45;
}

.signal-order-toggle.is-unavailable {
  cursor: pointer;
}

.manual-row {
  align-items: center;
  animation: manual-row-in 150ms ease-out;
  backdrop-filter: blur(12px);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: 12px;
  bottom: calc(100% + 53px);
  box-shadow: 0 -6px 18px rgba(31, 38, 51, 0.08);
  display: flex;
  gap: 7px;
  left: 0;
  padding: 6px;
  position: absolute;
  right: 0;
  transform-origin: right center;
  z-index: 45;
}

/* 作者 display:flex 会压过 UA 的 [hidden] 规则，必须显式补一条。 */
.manual-row[hidden] {
  display: none;
}

@keyframes manual-row-in {
  from {
    opacity: 0;
    transform: translateX(12px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.manual-row input {
  border: 1px solid var(--border);
  border-radius: 9px;
  flex: 0 0 96px;
  font-family: var(--mono);
  font-size: 14px;
  min-height: 44px;
  padding: 0 10px;
  width: 96px;
}

.manual-row .order-action {
  flex: 1;
  min-height: 44px;
  white-space: nowrap;
}

/* Dialogs and feedback */
.dialog-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 0 22px;
  margin: -24px -24px 22px;
  min-height: 74px;
  padding-inline: 24px;
}

.toast-region {
  display: grid;
  pointer-events: none;
  position: fixed;
  width: min(360px, calc(100vw - 36px));
  z-index: 100;
  bottom: 20px;
  gap: 9px;
  right: 20px;
}

.toast {
  animation: toast-in 260ms ease both;
  display: grid;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 12px;
  box-shadow: 0 18px 46px rgba(31, 38, 51, 0.16);
  gap: 5px;
  padding: 14px 16px;
}

.toast::before {
  background: var(--acid);
  border-radius: 50%;
  content: "";
  height: 7px;
  position: absolute;
  right: 14px;
  top: 14px;
  width: 7px;
}

.toast.is-error::before {
  background: var(--red);
}

.toast strong {
  font-size: 12px;
  padding-right: 16px;
}

.toast span {
  color: var(--muted);
  font-size: 10px;
}

@keyframes modern-card-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 1320px) {
  .desk-nav {
    display: none;
  }

  .ticker-deck {
    grid-template-columns: minmax(270px, auto) minmax(190px, auto);
  }

  .ticker-stats {
    grid-column: 1 / -1;
  }

  .desk-workspace {
    grid-template-columns: minmax(0, 1fr) 350px;
  }
}

/* 平板档：收敛顶栏各块的桌面版固定占位宽度，保证单行排布不折行。 */
@media (min-width: 761px) and (max-width: 1320px) {
  .desk-brand {
    min-width: auto;
  }

  .desk-brand small {
    display: none;
  }

  .connection-state,
  .account-button {
    min-width: auto;
    padding-inline: 8px;
  }

  .account-button {
    min-height: 38px;
  }

  .header-mode {
    margin-left: 8px;
  }
}

@media (max-width: 1080px) {
  .desk-workspace {
    grid-template-columns: 1fr;
  }

  .right-rail {
    display: grid;
    grid-template-columns: minmax(330px, 0.8fr) minmax(0, 1.2fr);
  }

  .order-panel {
    order: 1;
  }
}

.desk-workspace {
  display: grid;
  gap: 12px;
  padding: 12px 16px 0;
  scroll-margin-top: 80px;
  --workspace-panel-height: 720px;
  align-items: stretch;
  grid-template-columns: minmax(0, 1fr) 388px;
}

.market-column {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.chart-panel {
  align-self: stretch;
}

.chart-stage {
  overflow: hidden;
  position: relative;
  height: 540px;
  min-height: 540px;
}

.chart-tools {
  align-items: center;
  display: flex;
  gap: 6px;
}

.right-rail {
  flex-direction: column;
  align-content: start;
  display: grid;
  gap: 12px;
}

.order-panel {
  order: initial;
  /* 「手动」按钮/展开行浮出面板顶缘（杠杆模块右上方），不能被面板裁剪
     （.panel 默认 overflow: hidden；本面板子元素无贴角背景，放行安全）。 */
  overflow: visible;
}

.order-panel form {
  padding: 10px 14px 12px;
}

.order-fields {
  display: grid;
  gap: 8px;
  align-items: start;
  column-gap: 8px;
  /* 杠杆列须容纳「杠杆」内嵌标签（padding-left 42px）+ 三字符档位（125x）
     + 原生下拉箭头，108px 会裁掉档位的 x。 */
  grid-template-columns: minmax(0, 1fr) 124px;
}

/* 标签文字内嵌在下拉框左缘（保证金/杠杆），选中值右移避让。 */
.order-fields .select-field {
  position: relative;
}

.order-fields .select-prefix {
  color: var(--muted);
  font-size: 12px;
  left: 10px;
  line-height: 1;
  pointer-events: none;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.order-fields .margin-field select {
  padding-left: 54px;
}

.order-fields .leverage-field select {
  padding-left: 42px;
}

.order-fields .field.compact {
  margin-bottom: 0;
}

.order-fields .field.compact input,
.order-fields .field.compact select {
  min-height: 40px;
}

.open-orders-panel {
  padding: 10px 14px 12px;
}

.open-orders-header {
  color: var(--dim);
  font-size: 11px;
  margin-bottom: 4px;
}

.open-orders ul {
  display: grid;
  gap: 3px;
  list-style: none;
  margin: 0;
  max-height: 132px;
  overflow-y: auto;
  padding: 0;
}

.open-orders li {
  background: #fafbfc;
  border-radius: 7px;
  font-family: var(--mono);
  font-size: 11px;
  padding: 5px 8px;
  white-space: nowrap;
}

.open-orders li.is-long {
  color: var(--acid);
}

.open-orders li.is-short {
  color: var(--red);
}

.open-orders li.is-empty {
  color: var(--dim);
}

.open-orders li.is-done {
  opacity: 0.55;
}

.position-strip {
  background: #fafbfc;
  border-radius: 9px;
  display: grid;
  gap: 6px 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 7px;
  padding: 7px 10px;
}

.position-strip span {
  color: var(--muted);
  display: block;
  font-size: 10px;
}

.position-strip strong {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 560;
  margin-top: 2px;
  white-space: nowrap;
}

/* 盈亏回报率小字行：金额正下方，防移动端溢出到右侧止损格。 */
.position-strip small {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 560;
  margin-top: 1px;
  white-space: nowrap;
}

.position-strip small.is-long {
  color: var(--acid);
}

.position-strip small.is-short {
  color: var(--red);
}

.position-strip strong.is-long {
  color: var(--acid);
}

.position-strip strong.is-short {
  color: var(--red);
}

.order-panel .order-actions {
  margin-top: 7px;
}

.order-panel .order-action {
  min-height: 44px;
}

.order-action.is-unavailable {
  cursor: pointer;
}

/* 回撤止盈开关：PC 端 fixed 右下角浮动；H5 端在媒体查询里改为内联于头部行右侧。
   未武装（aria-pressed=false）为灰底，武装后为默认高亮绿底。 */
.trading-switch {
  background: #e8f5e9;
  border: 1px solid #a5d6a7;
  border-radius: 999px;
  bottom: 16px;
  color: #1b5e20;
  cursor: pointer;
  font-size: 12px;
  font-weight: 560;
  padding: 6px 14px;
  position: fixed;
  right: 16px;
  touch-action: none;
  z-index: 60;
}

.trading-switch[aria-pressed="false"] {
  background: #eceff3;
  border-color: #c3c9d4;
  color: #6b7280;
}

/* 拖动后的自由定位态：脱离默认锚点（PC 右下角 / H5 持仓模块右侧居中）。 */
.trading-switch.is-floating {
  bottom: auto;
  cursor: grab;
  margin: 0;
  position: fixed;
  right: auto;
  transform: none;
  touch-action: none;
}

@media (min-width: 1121px) {
  .desk-workspace {
    grid-template-rows: var(--workspace-panel-height);
  }

  .market-column {
    align-content: stretch;
    height: var(--workspace-panel-height);
    grid-template-rows: minmax(0, 1fr);
  }

  .right-rail {
    align-self: stretch;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
  }

  /* 交易记录面板填满右栏剩余高度，底部与左侧图表对齐。 */
  .open-orders-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .open-orders-panel .open-orders {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
  }

  .open-orders-panel .open-orders ul {
    flex: 1;
    max-height: none;
    min-height: 0;
  }

  .chart-panel {
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  .chart-panel .chart-stage {
    flex: 1;
    height: auto;
    min-height: 0;
  }

  .order-panel {
    display: flex;
    flex-direction: column;
    height: auto;
  }

  .order-panel form {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
}

@media (min-width: 1740px) {
  .desk-workspace {
    grid-template-columns: minmax(0, 1fr) 404px;
  }

  .chart-stage {
    height: auto;
    min-height: 0;
  }
}

@media (max-width: 1380px) {
  .desk-nav {
    display: flex;
  }

  .desk-nav a:not(.is-active) {
    display: none;
  }
}

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

  .right-rail {
    grid-template-columns: minmax(360px, 1fr);
  }

  .chart-stage {
    height: clamp(440px, 45vw, 500px);
    min-height: 440px;
  }
}

@media (max-width: 780px) {
  .desk-header {
    padding-inline: 10px;
  }

  .desk-brand {
    min-width: auto;
  }

  .desk-brand > span:last-child,
  .header-mode,
  .connection-state,
  .account-button small,
  .account-button > span:last-child {
    display: none;
  }

  .account-button {
    min-width: auto;
    padding-inline: 10px;
  }

  /* 移动端：顶栏固定在视口顶部（与底部下单栏同款毛玻璃）——
     第一行合约选择，第二行今日涨跌/账户盈亏/浮动盈亏三个模块居中；
     壳层顶部预留高度避免遮挡页头。 */
  .terminal-shell {
    padding-top: 78px;
  }

  .ticker-deck {
    align-items: center;
    backdrop-filter: blur(12px);
    background: rgba(255, 255, 255, 0.96);
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    box-shadow: 0 6px 18px rgba(31, 38, 51, 0.08);
    display: flex;
    flex-direction: column;
    gap: 2px;
    left: 0;
    margin: 0;
    padding: 6px 12px;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 40;
  }

  .ticker-identity {
    gap: 8px;
    justify-content: center;
    min-width: 0;
  }

  .symbol-trigger strong {
    font-size: 17px;
  }

  .ticker-stats {
    display: flex;
    gap: 18px;
    justify-content: center;
    margin: 0;
  }

  .ticker-stats div {
    align-items: center;
    border-left: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding-left: 0;
  }

  .ticker-stats dd {
    margin: 0;
    font-size: 12px;
  }

  .desk-workspace {
    padding-inline: 10px;
  }

  /* 移动端同样保持三列六格：字号随档位缩小，不再塌成两列。 */
  .position-strip {
    gap: 5px 6px;
    padding: 7px 8px;
  }

  .position-strip strong {
    font-size: 11px;
  }

  /* H5：右下角是杠杆/操作按钮，开关浮动锚在持仓模块右侧、垂直居中。 */
  .order-panel {
    position: relative;
  }

  .trading-switch {
    bottom: auto;
    margin-left: 0;
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
  }

  /* 移动端弹窗紧凑化：收窄内边距 / 标题 / 表单项距。 */
  .profile-dialog .dialog-body {
    padding: 16px;
  }

  .profile-dialog .dialog-header {
    margin-bottom: 10px;
  }

  .profile-dialog .dialog-header h2 {
    font-size: 16px;
  }

  .profile-form {
    gap: 10px;
  }

  .desk-nav {
    margin-left: auto;
  }

  .desk-nav a {
    display: none;
  }

  .chart-legends-row {
    gap: 9px;
  }

  .chart-tools {
    align-items: flex-end;
    flex-direction: column;
  }

  .chart-stage {
    height: clamp(280px, 38vh, 340px);
    min-height: 280px;
  }

  .right-rail {
    display: grid;
    grid-template-columns: 1fr;
  }

  /* 移动端：保证金/杠杆与做多/做空一起悬浮在页面底部（字段栏在按钮栏正上方，
     两段共用同一底色与毛玻璃，随时可点）；「手动」按钮再浮在整个操作模块
     右上角上方（122px 带起、44px 高）；页面底部留出对应高度避免内容被遮挡。 */
  .terminal-shell {
    padding-bottom: calc(174px + env(safe-area-inset-bottom));
  }

  /* 移动端去掉原生下拉箭头（点 select 任意位置都会弹出选择器，箭头纯属
     装饰且遮挡数值）；杠杆列收窄，省下的空间让给保证金金额。 */
  .order-fields {
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    bottom: calc(60px + env(safe-area-inset-bottom));
    box-shadow: 0 -6px 18px rgba(31, 38, 51, 0.08);
    grid-template-columns: minmax(0, 1fr) 96px;
    left: 0;
    margin: 0;
    padding: 8px 10px 4px;
    position: fixed;
    right: 0;
    z-index: 40;
  }

  .order-fields .select-field select {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 10px;
  }

  .order-actions {
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    bottom: 0;
    left: 0;
    margin-top: 0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    position: fixed;
    right: 0;
    z-index: 40;
  }

  /* H5：「手动」按钮固定在整个底部操作模块（字段栏 + 按钮栏，顶缘约
     116px + safe-area）的右上角上方；点击后手动行在同一带向左展开。
     尺寸对齐「杠杆」框（96px 宽 × 44px 高）。 */
  .manual-toggle {
    border-radius: 10px;
    bottom: calc(122px + env(safe-area-inset-bottom));
    font-size: 14px;
    font-weight: 680;
    min-height: 44px;
    padding-inline: 8px;
    position: fixed;
    right: 10px;
    width: 96px;
    z-index: 45;
  }

  /* H5：「半平」浮在「手动」左侧（96px 宽 + 7px 间距），同款 fixed 定位。 */
  .close-half-toggle {
    border-radius: 10px;
    bottom: calc(122px + env(safe-area-inset-bottom));
    font-size: 14px;
    font-weight: 680;
    min-height: 44px;
    padding-inline: 8px;
    position: fixed;
    right: calc(10px + 96px + 7px);
    width: 96px;
    z-index: 45;
  }

  /* H5：「信号」浮在「半平」左侧（96px 宽 + 7px 间距），同款 fixed 定位。 */
  .signal-order-toggle {
    border-radius: 10px;
    bottom: calc(122px + env(safe-area-inset-bottom));
    font-size: 14px;
    font-weight: 680;
    min-height: 44px;
    padding-inline: 8px;
    position: fixed;
    right: calc(10px + 96px * 2 + 14px);
    width: 96px;
    z-index: 45;
  }

  .manual-row {
    bottom: calc(122px + env(safe-area-inset-bottom));
    left: 10px;
    position: fixed;
    right: 10px;
    z-index: 45;
  }

  .manual-row input {
    flex: 1;
    min-width: 0;
    width: auto;
  }

  .manual-row .order-action {
    padding-inline: 10px;
  }

  .toast-region {
    bottom: calc(180px + env(safe-area-inset-bottom));
  }
}

.profile-dialog {
  width: min(520px, 92vw);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow-xl);
  padding: 0;
}

.profile-dialog::backdrop {
  background: rgba(10, 12, 18, 0.65);
  backdrop-filter: blur(4px);
}

.profile-dialog .dialog-body {
  padding: 24px;
}

.profile-dialog .dialog-header {
  margin-bottom: 18px;
}

.profile-dialog .dialog-header h2 {
  font-size: 20px;
  font-weight: 600;
}

.profile-subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}

.profile-form {
  display: grid;
  gap: 16px;
}

.profile-form .field {
  display: grid;
  gap: 6px;
}

.profile-form .field.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-toggles {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 24px;
}

.profile-form .field.checkbox input {
  width: 18px;
  height: 18px;
}

.profile-form .field span {
  font-size: 13px;
  color: var(--text-muted);
}

.profile-form input,
.profile-form select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}

.profile-password {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: grid;
  gap: 14px;
}

.profile-password legend {
  padding: 0 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.profile-form .form-error {
  color: var(--danger);
  font-size: 13px;
}

.profile-form .form-error:empty {
  display: none;
}
