:root {
  --bg: #0e1218;
  --panel: #151b24;
  --panel2: #1a222e;
  --line: #2a3342;
  --text: #e6ebf2;
  --muted: #8b95a8;
  --dim: #5c677a;
  --up: #3ecf8e;
  --dn: #e85d6a;
  --accent: #5b8def;
  --amber: #d4a017;
  --chip: #1e2736;
  --hair: #243044;
  --rail: 148px;
  --side: 300px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Noto Sans TC", system-ui, -apple-system, sans-serif;
  font-size: 12px;
  overflow: hidden;
}

button { font: inherit; color: inherit; background: none; border: 0; }

.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 3px;
  border: 1px solid var(--hair);
  background: var(--chip);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge.warn { border-color: #4a3a1a; color: var(--amber); background: #1c180e; }
.badge.ok { border-color: #1f3d30; color: var(--up); background: #0f1c16; }
.badge.dim { opacity: 0.85; }

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 100dvh;
}

.hdr {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.hdr h1 { font-size: 14px; font-weight: 600; letter-spacing: 0.01em; }
.hdr .sub { color: var(--muted); font-size: 11px; }
.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-left: auto; }

.main {
  flex: 1;
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr) var(--side);
  min-height: 0;
}

.rail {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.rail .label {
  padding: 4px 12px 8px;
  color: var(--dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.sym {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  border-left: 2px solid transparent;
}
.sym:hover { background: rgba(255, 255, 255, 0.03); }
.sym.active { background: var(--panel2); border-left-color: var(--accent); }
.sym.active .t { color: #dbe6ff; }
.sym .t { font-weight: 600; font-size: 13px; }
.sym .p { font-size: 13px; margin-top: 2px; }
.sym .meta { color: var(--dim); font-size: 10px; margin-top: 2px; }
.rail .export {
  margin-top: auto;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  color: var(--dim);
  font-size: 10px;
  line-height: 1.5;
}

.center {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 8px;
  gap: 6px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 3px 8px;
  background: var(--chip);
  border: 1px solid var(--hair);
  border-radius: 3px;
  font-size: 11px;
}
.chip b { color: var(--text); font-weight: 600; }
.chip span { color: var(--muted); }

.ohlc-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
}
.ohlc-bar .k { color: var(--dim); }
.ohlc-bar .v { font-weight: 500; }
.ohlc-bar .win { margin-left: auto; color: var(--dim); }

.chart-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel2);
  overflow: hidden;
  position: relative;
}
.chart-top {
  flex: 1;
  min-height: 0;
  position: relative;
  cursor: crosshair;
  display: flex;
  flex-direction: column;
}
.chart-top canvas,
.chart-bot canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.chart-top canvas {
  flex: 1;
  min-height: 0;
}
.chart-bot {
  height: 88px;
  flex-shrink: 0;
  border-top: 1px solid var(--line);
}
.legend {
  position: absolute;
  top: 8px;
  right: 64px;
  display: flex;
  gap: 10px;
  font-size: 10px;
  color: var(--muted);
  pointer-events: none;
  z-index: 2;
}
.legend .chart-range { display: none; color: var(--text); font-weight: 600; }
.legend i {
  display: inline-block;
  width: 12px;
  height: 2px;
  vertical-align: middle;
  margin-right: 4px;
}
.legend .dash {
  background: transparent;
  border-top: 1.5px dashed var(--accent);
  height: 0;
  width: 12px;
}

.side {
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.side .title {
  padding: 8px 10px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.side .scroll {
  flex: 1;
  overflow: auto;
  min-height: 0;
}
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 4px 8px;
  text-align: right;
  border-bottom: 1px solid var(--hair);
  font-variant-numeric: tabular-nums;
}
th {
  color: var(--dim);
  font-weight: 500;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}
td:first-child, th:first-child { text-align: left; }
.side td, .side th { padding: 3px 6px; }
.side table { font-size: 11px; }
tr.sel { background: rgba(91, 141, 239, 0.12); }
tr.hover { background: rgba(91, 141, 239, 0.08); }

.up { color: var(--up); }
.dn { color: var(--dn); }

.foot {
  padding: 5px 12px;
  border-top: 1px solid var(--line);
  color: var(--dim);
  font-size: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  background: var(--panel);
  flex-shrink: 0;
}

.banner {
  display: none;
  padding: 6px 12px;
  font-size: 11px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.banner.error { display: block; background: #2a1518; color: #f0b4ba; }
.banner.loading { display: block; background: var(--panel2); color: var(--muted); }

.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dim);
  margin-right: 6px;
  vertical-align: middle;
}
.status-dot.ok { background: var(--up); }
.status-dot.err { background: var(--dn); }

@media (max-width: 1100px) {
  :root { --side: 240px; --rail: 128px; }
}

@media (max-width: 860px) {
  html, body { overflow: auto; height: auto; }
  .app { height: auto; min-height: 100dvh; }
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(420px, 62vh) minmax(240px, 38vh);
  }
  .rail {
    flex-direction: row;
    align-items: stretch;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    padding: 0;
  }
  .rail .label { display: none; }
  .sym { min-width: 120px; border-left: 0; border-bottom: 2px solid transparent; }
  .sym.active { border-bottom-color: var(--accent); }
  .rail .export {
    margin-top: 0;
    margin-left: auto;
    border-top: 0;
    border-left: 1px solid var(--line);
    min-width: 140px;
  }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .chart-wrap { min-height: 360px; }
  .ohlc-bar .win { margin-left: 0; }
  .legend {
    position: relative;
    top: auto;
    right: auto;
    padding: 6px 10px 2px 8px;
    flex-wrap: wrap;
  }
  .legend .chart-range { display: inline; }
}

@media (max-width: 520px) {
  .hdr h1 { font-size: 13px; }
  .legend { right: 8px; top: 4px; flex-direction: column; gap: 4px; }
  .main { grid-template-rows: auto minmax(320px, 55vh) minmax(220px, 40vh); }
}
