: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; }
.title .addr a.view-link { margin-left: 12px; font-family: inherit; color: #58a6ff; }

.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,
#btn-pin.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); }
/* 回放三键（← ▶ →）：等宽居中。▶ 和 ⏸ 字宽不同，不定宽的话一播一停整条控制栏横跳。 */
.replay-btn { min-width: 30px; padding-left: 4px; padding-right: 4px; text-align: center; }

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; }
/* 未成交挂单线的浓淡滑块。压到和同排色块一样的高度，别把这一行撑高。 */
.ind-range {
  width: 64px;
  height: 16px;
  vertical-align: middle;
  accent-color: var(--blue);
  cursor: pointer;
}
#order-unfilled-alpha-val {
  display: inline-block;
  width: 30px;            /* 定宽：数字从 100% 变 40% 时后面的控件不要跟着跳 */
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* 置灰不可用的分段控件（如"铺满横屏"形态下的"显示全部订单"） */
.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: 0;                /* 图与图之间的间距由分隔条自己占，别再叠一层 gap */
  min-width: 0;
  min-height: 0;
  height: 100%;          /* 填满左列（grid 默认 stretch 也会给到，这里双保险） */
}
.chart-wrap { position: relative; min-width: 0; }
/* 三张图（价格 / 杠杆 / 盈亏）高度按 flex-grow 分配。拖分隔条时 JS 只改这个
   grow，不写死像素——窗口高度一变，三张图仍按用户拖出来的比例一起缩放。
   min-height 保证拖到底也留得下一张能看的图，不会把某张压成 0 再也拉不回来。 */
.charts > .chart-wrap {
  flex: 1 1 0;
  min-height: 44px;
  display: flex;
  flex-direction: column;
}
.charts > .chart-wrap > .chart {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
}
/* 主图拿掉四分之三。杠杆和盈亏是"扫一眼看形状"的图，不需要和 K 线平分高度；
   分隔条随时能拖回来。窄屏那套固定高度不动——那边是整页滚动，没有高度之争。 */
.charts > .chart-wrap.pane-price { flex-grow: 6; }
.charts > .chart-wrap.pane-lev { flex-grow: 1; }
.charts > .chart-wrap.pane-pnl { flex-grow: 1; }

/* 分隔条：本体 8px 高（够好点中），视觉上只是中间一条发丝线，悬停/拖动时变蓝。 */
.chart-split {
  flex: 0 0 8px;
  position: relative;
  cursor: row-resize;
  touch-action: none;    /* 触屏上按住拖分隔条不要变成滚页面 */
}
.chart-split::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 2px;
  margin-top: -1px;
  border-radius: 1px;
  background: transparent;
}
.chart-split:hover::after,
.chart-split.dragging::after { background: var(--blue); }
/* 拖动时整页锁成同一个光标，并禁掉选中——否则拖过图表会拖出一片蓝色选区 */
body.resizing-panes { cursor: row-resize; user-select: none; }
/* 图左上角的标题标签（覆盖在图上，不挡交互） */
.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; }
/* 图左上角"标题 + 图内小控件"的一行。用 flex 让控件紧跟标题末尾，而不是给它
   写死一个 left：标题文案随语言和计价单位有四种长短，写死迟早撞上或离得老远。
   整行不吃鼠标事件（否则标题和控件之间的空隙会挡住图表的 hover），只有控件
   自己收回点击。 */
.chart-head {
  position: absolute; top: 4px; left: 8px; z-index: 6;
  display: flex; align-items: center; gap: 8px;
  pointer-events: none;
}
.chart-head > .chart-tag { position: static; }
/* 画在图里的小分段控件（盈亏计价单位）。放在图上而不是顶部控制栏：那一排已经
   有九组控件，而这个开关只对这一张图有意义，就近放最省找。 */
.chart-head > .seg-chart {
  position: static;
  background: rgba(22, 27, 34, 0.72);
  font-size: 10px;
  pointer-events: auto;
}
.seg-chart button { padding: 1px 7px; }
/* 图内的"盈亏起算时刻"下拉。和 .seg-chart 同样处理：父容器 .chart-head 是
   pointer-events:none（免得挡住图表 hover），子控件必须自己把点击收回来，
   否则这个 select 看得见却点不动。其余外观沿用全局 select 规则，只压字号和底色。 */
.chart-head > .sel-chart {
  position: static;
  background: rgba(22, 27, 34, 0.72);
  font-size: 10px;
  padding: 1px 4px;
  pointer-events: auto;
  max-width: 200px;
}
/* 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 线图铺满整个视口。粒度选择器被搬到图上方，全屏时仍可切换。
   布局本身（display/height）在文件末尾定义——窄屏 media query 里的
   `.charts > .chart-wrap:first-child` 特异性更高且位置更后，必须在它之后覆盖。 */
.chart-wrap.maximized {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg); padding: 10px;
}
/* 全屏时搬进来的控件行：粒度 + 钉住并排一行 */
.chart-wrap.maximized > .maximized-controls {
  flex: 0 0 auto;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 6px;
  padding-right: 34px;   /* 让开右上角的退出按钮 */
}
/* 两个说明标签在全屏时会压到粒度选择器上，且全屏本来就是"只看图"，直接收起 */
.chart-wrap.maximized .chart-tag,
.chart-wrap.maximized .chart-head { display: none; }
/* 指标图例改为相对图区顶部定位（控件行 ≈30px + 原本的 12px 内边距） */
.chart-wrap.maximized .chart-legend { top: 52px; }
/* 图左上角的指标图例（仿 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;
}

.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; position: relative; }
#orders-table th[data-sort]:hover { color: var(--text); }
/* 排序箭头绝对定位到表头角落，不占内联宽度——无论同时对多少列排序，
   箭头都不会把表头挤宽/挤出一行，表头始终保持原样一排。 */
#orders-table th .sort-ind {
  position: absolute; top: -2px; color: var(--blue);
  font-size: 8px; line-height: 1; pointer-events: none; white-space: nowrap;
}
#orders-table th[data-sort]:not(.left) .sort-ind { left: 1px; }   /* 右对齐数字表头：箭头放左上角空白处 */
#orders-table th[data-sort].left .sort-ind { right: 1px; }         /* 左对齐表头：箭头放右上角空白处 */
#orders-table th .sort-ind sup { font-size: 8px; }
#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 { display: block; flex: none; min-height: 0; margin-bottom: 8px; }
  .charts > .chart-wrap > .chart { height: auto; }
  .charts > .chart-wrap.pane-price > .chart { height: 420px; }
  .charts > .chart-wrap.pane-lev > .chart { height: 150px; }
  .charts > .chart-wrap.pane-pnl > .chart { height: 180px; }
  .chart-split { display: none; }
  .side { height: auto; overflow: visible; }
  .side > .panel:last-child { flex: none; min-height: 0; overflow: visible; }
}

/* 全屏放大的布局，必须放在窄屏 media query 之后：
   `.charts > .chart-wrap:first-child` 在 max-width:1100px 里被设成 display:block，
   特异性(3 类)高于 `.chart-wrap.maximized`(2 类)，所以这里用同等特异性 + 更后的位置取胜。
   否则窄屏全屏时 K 线只会停在内容高度，撑不满视口。 */
.charts > .chart-wrap.maximized {
  display: flex;
  flex-direction: column;
  flex: none;
}
.charts > .chart-wrap.maximized > .chart {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
}
/* 全屏层是 fixed 铺满视口，底下那两张图和分隔条既看不见、又还在按 flex 抢高度，
   直接收起。退出全屏时类一去掉就恢复，比例还是用户拖出来的那个。 */
.charts:has(> .chart-wrap.maximized) > .chart-split,
.charts:has(> .chart-wrap.maximized) > .chart-wrap:not(.maximized) { display: none; }

/* "最新"是这个页面最常用的动作——打开就想看当前挂单——所以用琥珀色实心把它
   从一排同色按钮里挑出来。蓝色在这套界面里代表"当前选中"（粒度、钉住、分段控件
   都是），不能拿来做主动作，否则看着像已经按下了。 */
#btn-pin-latest {
  background: var(--orange);
  border-color: var(--orange);
  color: #1a1207;
  font-weight: 600;
}
#btn-pin-latest:hover {
  background: #ffb851;
  border-color: #ffb851;
}

/* 归档边界提示：只在选中时刻越过 2023-09-17 时出现在活跃挂单面板里。
   用琥珀色而不是红色——这不是错误，是数据本身的边界。 */
.panel-note {
  margin: 6px 8px 2px;
  padding: 6px 8px;
  border-left: 2px solid #ffa726;
  background: rgba(255, 167, 38, 0.08);
  border-radius: 3px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}
.panel-note strong { color: #ffa726; font-weight: 600; }

/* 长任务遮罩（切 K 线粒度时）。盖住整屏而不只是图表区：切换期间控制栏点了也没用，
   与其让它看起来能点，不如明确挡住。 */
.busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 16, 0.72);
  backdrop-filter: blur(1px);
}
.busy-overlay[hidden] { display: none; }
.busy-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 30px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}
.busy-spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--line);
  border-top-color: #ffa726;
  border-radius: 50%;
  animation: busy-spin 0.8s linear infinite;
}
@keyframes busy-spin { to { transform: rotate(360deg); } }
.busy-label { font-size: 13px; }
.busy-hint { font-size: 11px; }
@media (prefers-reduced-motion: reduce) { .busy-spinner { animation: none; } }


/* 假设挂单时长：两个天数输入框沿用指标周期输入框的样式；开关关掉时变淡，但仍可改 */
.assume-days { display: inline-flex; align-items: center; gap: 4px; }
.assume-days input {
  width: 56px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font: inherit;
}
.assume-days input { width: 44px; }
.assume-group.off .assume-days { opacity: 0.45; }
