:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1f2630;
  --line: #2a323d;
  --text: #e6edf3;
  --muted: #8b949e;
  --green: #26a69a;
  --red: #ef5350;
  --orange: #ffa726;
  --blue: #58a6ff;
  --yellow: #d4ac00;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Hiragino Sans GB", "Helvetica Neue", Arial, sans-serif;
  font-size: 12px;   /* 全局字号按约 80% 缩小（原 14px），整体更紧凑、单屏信息更多 */
  overflow-x: hidden;   /* 页面不该出现横向滚动条：任何超宽内容自己在容器里滚 */
}
/* 首屏区：header + 控制栏 + 图表正好占满一个视口高度。
   用固定 height（而非 min-height）给 main 一个确定高度，否则右侧挂单列表很长时会把
   grid 行撑高、图表跟着溢出。footer 在 .app-main 之外，正好落在首屏下方，往下滑才出现。 */
.app-main {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* 深色主题滚动条：覆盖侧栏纵向条、整页条、任何滚动容器的默认白色条，跟黑色主题一致 */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }   /* Firefox */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--panel-2); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a4552; }
::-webkit-scrollbar-corner { background: var(--panel-2); }
.nowrap { white-space: nowrap; }

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 11px; }

header {
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: relative;
  flex: 0 0 auto;
}
/* 语言切换按钮：整页最右上角 */
.lang-btn {
  position: absolute; top: 8px; right: 12px; z-index: 20;
  padding: 2px 8px; font-size: 11px;
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.title h1 {
  margin: 0 0 3px;
  font-size: 15px;
  font-weight: 600;
}
.title .addr { font-size: 11px; color: var(--muted); }
.title .addr a { color: var(--text); font-family: ui-monospace, Consolas, monospace; }

.cards {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 9px;
  min-width: 130px;
}
.card .label { font-size: 10px; color: var(--muted); }
.card .value { font-size: 15px; font-weight: 600; margin: 1px 0; }
.card .sub { font-size: 10px; color: var(--muted); }
.card .value.green { color: var(--green); }
.card .value.red { color: var(--red); }
.card .value.yellow { color: var(--yellow); }

.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  padding: 7px 4px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex: 0 0 auto;
}
.control-group {
  display: flex;
  gap: 6px;
  align-items: center;
}
.control-group .label { color: var(--muted); font-size: 11px; }
.control-group.right { margin-left: auto; }

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.seg button {
  background: transparent;
  color: var(--text);
  border: 0;
  padding: 4px 10px;
  cursor: pointer;
  font: inherit;
}
.seg button.active {
  background: var(--blue);
  color: #fff;
}

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
  font: inherit;
}
button:hover { border-color: var(--blue); }

select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 5px;
}
.speed { display: inline-flex; align-items: center; gap: 6px; }
.chk { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; user-select: none; }
.chk input { cursor: pointer; }

/* 技术指标控件（添加入口 + 挂单颜色共用色块） */
#ind-period {
  width: 56px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font: inherit;
}
.ind-color {
  width: 16px; height: 16px; padding: 0; border: 1px solid var(--line);
  border-radius: 3px; background: none; cursor: pointer; vertical-align: middle;
}
.ind-color::-webkit-color-swatch-wrapper { padding: 0; }
.ind-color::-webkit-color-swatch { border: none; border-radius: 2px; }
.ind-sub { color: var(--muted); font-size: 10px; }

/* 置灰不可用的分段控件（如"铺满横屏"形态下的"显示全部订单"） */
.seg.disabled { opacity: 0.4; pointer-events: none; }

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 8px;
  padding: 6px 4px;    /* 左右几乎贴边：K 线蜡烛本身就画到图表左缘，留 4px 发丝边、与上方控制栏对齐 */
  flex: 1 1 auto;      /* 吃掉 header / 控制栏之外、footer 之上的全部竖向空间 */
  min-height: 0;
}
/* 隐藏 PIT：右侧信息栏收起，K 线占满整行 */
main.sidebar-collapsed { grid-template-columns: 1fr; }
main.sidebar-collapsed .side { display: none; }
.charts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
  height: 100%;          /* 填满左列（grid 默认 stretch 也会给到，这里双保险） */
}
.chart-wrap { position: relative; min-width: 0; }
/* K 线图（第一个 chart-wrap）吃掉杠杆图之外的全部高度；杠杆图固定较矮。 */
.charts > .chart-wrap:first-child {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.charts > .chart-wrap:first-child > .chart {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
}
.charts > .chart-wrap:last-child { flex: 0 0 auto; }
/* 图左上角的标题标签（覆盖在图上，不挡交互） */
.chart-tag {
  position: absolute; top: 5px; left: 8px; z-index: 3;
  font-size: 10px; color: var(--muted); pointer-events: none;
  background: rgba(22, 27, 34, 0.72); padding: 1px 6px; border-radius: 4px;
}
/* 图右上角的说明标签（数据来源），避开右侧价格轴 */
.chart-tag-right { left: auto; right: 92px; }
/* K 线图右上角的全屏按钮 */
.chart-full-btn {
  position: absolute; top: 4px; right: 6px; z-index: 6;
  background: rgba(22, 27, 34, 0.72); border: 1px solid var(--line);
  color: var(--muted); border-radius: 4px; padding: 0 6px;
  font-size: 14px; line-height: 1.5; cursor: pointer;
}
.chart-full-btn:hover { color: var(--text); border-color: var(--blue); }
/* 全屏放大：K 线图铺满整个视口，只看 K 线 */
.chart-wrap.maximized {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg); padding: 10px;
}
.chart-wrap.maximized #chart-price { height: calc(100vh - 20px); }
/* 图左上角的指标图例（仿 TradingView）：每条一行，眼睛可单独隐藏 */
.chart-legend {
  position: absolute; top: 22px; left: 8px; z-index: 4;
  display: flex; flex-direction: column; gap: 1px; font-size: 11px;
}
.legend-item { display: flex; align-items: center; gap: 4px; }
.legend-item.off { opacity: 0.5; }
.legend-eye {
  background: rgba(22, 27, 34, 0.6); border: none; padding: 0 3px;
  font-size: 12px; line-height: 1.5; cursor: pointer; border-radius: 3px;
}
.legend-name {
  cursor: pointer; font-weight: 600;
  background: rgba(22, 27, 34, 0.6); padding: 0 5px; border-radius: 3px;
}
.legend-item.off .legend-name { text-decoration: line-through; }
.legend-x {
  background: rgba(22, 27, 34, 0.6); border: none; color: var(--muted);
  cursor: pointer; padding: 0 4px; font-size: 13px; line-height: 1.4; border-radius: 3px;
}
.legend-x:hover { color: var(--red); }
/* 点击图例名字弹出的指标编辑小框（颜色/周期/类型/粗细） */
.ind-editor {
  position: absolute; z-index: 10; min-width: 158px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px; display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5); font-size: 12px;
}
.ind-ed-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ind-ed-row > span { color: var(--muted); }
.ind-ed-row select, .ind-ed-row input {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 4px; padding: 2px 4px; font: inherit;
}
.ind-ed-period, .ind-ed-mult { width: 64px; }
.ind-ed-color { width: 36px; height: 22px; padding: 0; cursor: pointer; }
.ind-ed-done { align-self: flex-end; padding: 3px 12px; }
.chart {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  height: 520px;
}
.chart.small { height: 62px; }   /* 杠杆图压到约一半，省下的高度全给上面的 K 线图 */

.side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;   /* 侧栏本身不滚动：状态面板固定在上，挂单面板在自己内部纵向滚动 */
}
/* 上面的"选中时间状态"面板按内容高度固定，始终可见 */
.side > .panel { flex: 0 0 auto; }
/* 下面的挂单面板吃掉剩余高度；行多时只在这个面板内部纵向滚动，不撑高整页 */
.side > .panel:last-child {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  overflow-x: auto;   /* 万一表格还是略宽，就在面板内横滚，不撑破页面 */
}
.panel-head {
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.kv > div {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px dashed var(--line);
}
.kv > div:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-family: ui-monospace, Consolas, monospace; }
.kv .v.green { color: var(--green); }
.kv .v.red { color: var(--red); }
.kv .v.yellow { color: var(--yellow); }

#orders-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}
#orders-table th, #orders-table td {
  text-align: right;
  padding: 3px 2px;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;   /* 少数超宽内容（如触发单类型串）就地折行，不再撑出横向滚动条 */
}
#orders-table th { color: var(--muted); font-weight: 500; }
#orders-table th[data-sort] { cursor: pointer; user-select: none; white-space: normal; }
#orders-table th[data-sort]:hover { color: var(--text); }
#orders-table th .sort-ind { color: var(--blue); font-size: 10px; }
#orders-table th .sort-ind sup { font-size: 9px; }
#orders-sort-reset {
  background: none; border: none; padding: 0; margin-left: 4px;
  color: var(--blue); cursor: pointer; font-size: 11px; text-decoration: underline;
}
#orders-table td.left, #orders-table th.left { text-align: left; }
#orders-table tr.buy td.side { color: var(--green); }
#orders-table tr.sell td.side { color: var(--red); }
.badge {
  display: inline-block;
  border-radius: 3px;
  padding: 0 5px;
  font-size: 10px;
  margin-left: 4px;
  border: 1px solid transparent;
}
.badge.ok {
  background: rgba(38, 166, 154, 0.18);
  color: var(--green);
  border-color: rgba(38, 166, 154, 0.4);
}
.badge.canceled {
  background: rgba(139, 148, 158, 0.18);
  color: var(--muted);
  border-color: rgba(139, 148, 158, 0.35);
}
.badge.open {
  background: rgba(212, 172, 0, 0.18);
  color: var(--yellow);
  border-color: rgba(212, 172, 0, 0.4);
}
.orders-meta { margin-bottom: 4px; }

footer {
  padding: 12px 4px 24px;
  color: var(--muted);
  font-size: 12px;
}
footer summary { cursor: pointer; }

@media (max-width: 1100px) {
  /* 窄屏：回到普通文档流（图表在上、侧栏在下，整页滚动），不做视口铺满 */
  .app-main { display: block; height: auto; }
  main { grid-template-columns: 1fr; flex: none; }
  .charts { height: auto; }
  .charts > .chart-wrap:first-child { display: block; flex: none; }
  .charts > .chart-wrap:first-child > .chart { height: 420px; }
  .chart.small { height: 150px; }
  .side { height: auto; overflow: visible; }
  .side > .panel:last-child { flex: none; min-height: 0; overflow: visible; }
}
