:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #66717f;
  --line: #d9e0e7;
  --panel: #ffffff;
  --bg: #f4f7f8;
  --up: #b33b31;
  --down: #1b7f79;
  --ma-fast: #c5892d;
  --ma-slow: #4158a8;
  --rsi: #6d4a9c;
  --taiex: #2f6f9f;
  --soft: #e9f0ee;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Noto Sans TC", system-ui, sans-serif;
}
button, select, input { font: inherit; }
.app-shell { width: min(1440px, 100%); margin: 0 auto; padding: 20px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 0 16px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.55rem, 2vw, 2.25rem); letter-spacing: 0; }
.topbar p, .panel-heading p { color: var(--muted); margin-top: 4px; }
.toolbar, .control-band, .segmented { display: flex; align-items: center; gap: 8px; }
.toolbar { flex-wrap: wrap; justify-content: flex-end; }
button, .import-button, select, input[type="number"] { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 6px; min-height: 38px; }
button, .import-button { padding: 0 12px; cursor: pointer; }
button:hover, .import-button:hover, select:hover, input[type="number"]:hover { border-color: #9ba9b5; }
#csvFile { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; pointer-events: none; }
.control-band { flex-wrap: wrap; justify-content: space-between; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.field { display: grid; grid-template-columns: auto minmax(110px, 160px); align-items: center; gap: 8px; }
.field label { color: var(--muted); font-size: 0.92rem; }
select { padding: 0 28px 0 10px; }
input[type="number"] { width: 84px; padding: 0 8px; }
.segmented { padding: 3px; background: var(--soft); border-radius: 8px; }
.segmented button { border-color: transparent; background: transparent; min-width: 72px; }
.segmented button.active { background: var(--ink); color: #fff; }
.summary-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 12px; margin: 14px 0; }
.summary-grid article, .chart-stage, .live-chart-panel, .analysis-panel, .news-panel {
  margin-top: 14px;
  overflow: hidden;
}

.reaction-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
}

.reaction-stats article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.reaction-stats span {
  color: var(--muted);
  font-size: 0.85rem;
}

.reaction-stats strong {
  display: block;
  margin-top: 4px;
  font-size: 1.25rem;
}

.compact {
  max-height: 260px;
}

.data-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.summary-grid article { padding: 14px; }
.summary-grid span { color: var(--muted); font-size: 0.85rem; }
.summary-grid strong { display: block; margin-top: 6px; font-size: clamp(1.05rem, 1.45vw, 1.55rem); }
.status-band { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; margin: 14px 0; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--line); }
.status-band > div { min-width: 0; padding: 14px; background: var(--panel); }
.status-label { color: var(--muted); font-size: 0.82rem; }
.status-band strong { display: block; margin-top: 4px; font-size: 1.05rem; }
.status-band p { margin-top: 4px; color: var(--muted); font-size: 0.88rem; overflow-wrap: anywhere; }
.status-good { color: #196b55; }
.status-warn { color: #9a5b13; }
.status-bad { color: #a6332a; }
.chart-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(340px, 1fr); gap: 14px; align-items: stretch; }
.chart-stage { position: relative; height: min(68vh, 760px); min-height: 520px; padding: 12px; }
.main-chart { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.taiex-chart-stage { display: grid; grid-template-rows: auto minmax(0, 1fr); height: min(52vh, 600px); min-height: 430px; }
.live-chart-stack { display: grid; grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 14px; min-height: 520px; height: min(68vh, 760px); margin-top: 14px; }
.live-chart-panel { position: relative; display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
.chart-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 4px 10px; }
.chart-heading p { margin-top: 3px; color: var(--muted); font-size: 0.78rem; }
.chart-heading > span { flex: 0 0 auto; font-size: 0.78rem; color: var(--muted); }
.live-chart-panel canvas { min-height: 0; }
canvas { width: 100%; height: 100%; display: block; }
.tooltip { position: absolute; z-index: 2; min-width: 210px; padding: 8px 10px; color: #fff; background: rgba(23, 33, 43, 0.94); border-radius: 6px; font-size: 0.86rem; pointer-events: none; box-shadow: 0 4px 14px rgba(23, 33, 43, 0.18); }
.live-tooltip { min-width: 180px; max-width: calc(100% - 24px); }
.live-crosshair { position: absolute; z-index: 1; pointer-events: none; background: rgba(45, 55, 72, 0.58); }
.live-crosshair-x { width: 1px; }
.live-crosshair-y { height: 1px; }
.analysis-panel {
  margin-top: 14px;
  overflow: hidden;
}

.reaction-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
}

.reaction-stats article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.reaction-stats span {
  color: var(--muted);
  font-size: 0.85rem;
}

.reaction-stats strong {
  display: block;
  margin-top: 4px;
  font-size: 1.25rem;
}

.compact {
  max-height: 260px;
}

.data-panel { margin-top: 14px; overflow: hidden; }
.news-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.news-notice { padding: 10px 14px; color: var(--muted); font-size: 0.86rem; border-bottom: 1px solid var(--line); }
.news-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.news-item { min-width: 0; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.news-item:nth-child(odd) { border-right: 1px solid var(--line); }
.news-item a { color: var(--ink); font-weight: 600; text-decoration: none; overflow-wrap: anywhere; }
.news-item a:hover { text-decoration: underline; }
.news-item p { margin-top: 5px; color: var(--muted); font-size: 0.82rem; }
.panel-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 14px; border-bottom: 1px solid var(--line); }
h2 { font-size: 1.05rem; }
.table-wrap { max-height: 360px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child, th:nth-child(2), td:nth-child(2) { text-align: left; }
thead th { position: sticky; top: 0; background: #f9fbfc; color: var(--muted); font-weight: 600; }
@media (max-width: 860px) {
  .app-shell { padding: 12px; }
  .topbar, .panel-heading { align-items: stretch; flex-direction: column; }
  .toolbar { justify-content: flex-start; }
  .field { grid-template-columns: 1fr; width: 100%; }
  .field select, .field input[type="number"], .segmented { width: 100%; }
  .segmented button { flex: 1; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-band { grid-template-columns: 1fr; }
  .chart-grid { grid-template-columns: 1fr; }
  .live-chart-stack { height: 640px; }
  .news-list { grid-template-columns: 1fr; }
  .news-item:nth-child(odd) { border-right: 0; }
}
@media (max-width: 520px) {
  .reaction-stats { grid-template-columns: 1fr; }
  .chart-stage { min-height: 460px; }
  .live-chart-stack { height: 560px; min-height: 560px; }
}




