:root {
  --ink: #1d1c1a;
  --muted: #655f59;
  --line: #dcd6ce;
  --paper: #f5f2ec;
  --card: #ffffff;
  --side-bg: #f8f6f2;
  --accent: #2563eb;
  --accent-soft: #eaf1ff;
  --accent-border: #bfd4fe;
  --red: #d62728;
  --green: #15803d;
  --amber: #b45309;
  --gray: #4e4e4e;
  --blue: #c5dff0;
  --cash: #e4e4e4;
  --purple: #ddd0ea;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  font: 14px/1.5 "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
}

/* 頂部標題列 */
.top {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex: none;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  letter-spacing: 0.03em;
  font-size: 12px;
}

h1 {
  margin: 1px 0 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.flow-summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.flow-step {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 4px 10px;
  color: var(--ink);
}

.flow-step b {
  color: var(--accent);
  margin-right: 3px;
}

.flow-arrow {
  color: var(--muted);
  font-weight: bold;
}

/* 主框架 */
.shell {
  display: flex;
  align-items: stretch;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.side {
  width: 480px;
  flex: none;
  min-height: 0;
  background: var(--side-bg);
  border-right: 1px solid var(--line);
  padding: 12px 12px 36px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 左側欄卡片區塊 */
.side-block {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 13px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.side-block.highlight-block {
  border-color: var(--accent-border);
  background: linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
}

#ratchet-tools[hidden],
#ratchet-rebound-row[hidden],
#ratchet-ma-row[hidden] {
  display: none !important;
}

.block-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
}

.step-badge {
  display: inline-block;
  background: #e9e4dc;
  color: #3f3b37;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  letter-spacing: 0.02em;
  flex: none;
}

.step-badge.accent {
  background: var(--accent);
  color: #fff;
}

.side h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.sub-label {
  display: block;
  font-size: 12px;
  font-weight: 650;
  color: var(--ink);
  margin: 8px 0 5px;
}

/* 說明方塊 */
.explain-box {
  background: #f7f5f0;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
  font-size: 12px;
  color: #3d3935;
}

.explain-box p {
  margin: 0 0 4px;
  line-height: 1.45;
}

.explain-box p:last-child {
  margin-bottom: 0;
}

.explain-box code,
.hint code {
  background: #e6ecf8;
  color: #1e40af;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 600;
}

.hint {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.warn-note {
  display: inline-block;
  margin-top: 3px;
  color: var(--amber);
  font-weight: 600;
}

/* 日期與勾選框 */
.dates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.dates label {
  font-size: 12px;
  font-weight: 600;
}

.dates input[type="date"] {
  width: 100%;
  padding: 6px 8px;
  font-size: 13px;
}

.check {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 6px 0;
  font-size: 12.5px;
  color: var(--ink);
  cursor: pointer;
}

.check input[type="checkbox"] {
  margin-top: 3px;
  width: 15px;
  height: 15px;
  flex: none;
}

.cost-check {
  background: #f5f8ff;
  border: 1px solid #d8e5ff;
  border-radius: 8px;
  padding: 7px 9px;
  margin: 4px 0 0;
}

.cost-check span {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.cost-check small {
  color: var(--muted);
  font-size: 11.5px;
}

.fut-toggle-check {
  background: #f0f9ff;
  border-color: #bae6fd;
}

#earth-tools .explain-box {
  margin-bottom: 8px;
}

#earth-tools .cost-check {
  margin-top: 8px;
}

.step-presets {
  grid-template-columns: repeat(4, 1fr);
  margin: 4px 0 8px;
}

.step-presets button {
  background: #eff4fc;
  color: #1e3a8a;
  border: 1px solid #d5e2fc;
  padding: 5px 4px;
  font-size: 11.5px;
  font-weight: 600;
}

.step-presets button:hover {
  background: #dbeafe;
}

.step-presets button.on {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.ladder-preview {
  margin-top: 8px;
  padding: 6px 9px;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 6px;
  font-size: 11.5px;
  color: #334155;
  line-height: 1.45;
}

.ladder-preview b {
  color: var(--accent);
}

/* 策略範本大按鈕 */
.strategy-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.strategy-cards button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: 2px;
  background: #f1f5fe;
  color: #1e3a8a;
  border: 1px solid #d5e2fc;
  border-radius: 8px;
  padding: 8px 10px;
  transition: all 0.12s ease;
}

.strategy-cards button strong {
  font-size: 13px;
  font-weight: 700;
}

.strategy-cards button span {
  font-size: 11px;
  opacity: 0.85;
  line-height: 1.3;
}

.strategy-cards button:hover {
  background: #e3ecfe;
}

.strategy-cards button.zscore-preset {
  background: #f5f3ff;
  border-color: #c4b5fd;
  color: #4c1d95;
}

.strategy-cards button.zscore-preset:hover {
  background: #ede9fe;
}

.strategy-cards button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}

.active-recipe {
  margin-top: 8px;
  padding: 6px 9px;
  background: #eef4ff;
  border-radius: 6px;
  font-size: 12px;
  color: #1e3a8a;
  font-weight: 600;
}

/* 模式與參數按鈕群 */
.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 6px;
}

.modes.timing-grid {
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
}
.modes.timing-grid button {
  padding: 6px 3px;
  font-size: 11.5px;
}
.modes.timing-grid button small {
  font-size: 10px;
}

.modes button {
  background: #edf2fc;
  color: #1d3f86;
  border: 1px solid #d6e2fa;
  padding: 7px 8px;
  font-size: 12.5px;
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  line-height: 1.3;
}

.modes button small {
  font-size: 10.5px;
  opacity: 0.82;
  font-weight: normal;
}

.modes button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* 滑桿群 */
.lags {
  display: grid;
  gap: 7px;
  margin-top: 6px;
}

.lags label {
  display: grid;
  grid-template-columns: 9.5em 1fr 3.2em;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 12.5px;
}

.lags input[type="range"] {
  width: 100%;
  padding: 0;
}

.lags b {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

/* 配倉範本小按鈕 */
.presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0 0 8px;
}

.presets.grid-presets {
  grid-template-columns: repeat(3, 1fr);
}

.presets button {
  background: #2c2a28;
  color: white;
  padding: 6px 6px;
  font-size: 11.5px;
  border-radius: 6px;
}

.presets button:hover {
  background: #44413e;
}

/* 配倉表格 */
.alloc {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  border-radius: 8px;
  overflow: hidden;
}

.alloc th {
  background: #2563eb;
  color: white;
  font-weight: 650;
  padding: 6px 5px;
  line-height: 1.25;
  border: 1px solid #1d4ed8;
}

.alloc th small {
  font-weight: normal;
  opacity: 0.88;
  font-size: 10.5px;
}

.alloc td {
  border: 1px solid #d5e3fb;
  background: #f8faff;
  padding: 6px 5px;
  text-align: center;
  vertical-align: middle;
}

.alloc th.row-group-0 {
  background: #475569;
  border-color: #334155;
}

.alloc th.row-group-1 {
  background: #1d4ed8;
  border-color: #1e40af;
}

.alloc th.six-0 {
  background: #eff4fc;
  color: #334155;
  border-color: #d5e3fb;
  font-weight: 600;
}

.alloc th.six-1 {
  background: #dbeafe;
  color: #1e3a8a;
  border-color: #bfdbfe;
  font-weight: 700;
}

.cell-input-wrap {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.alloc input,
.miss input {
  width: 60px;
  text-align: right;
  padding: 4px 5px;
  font-weight: 700;
  font-size: 13px;
}

.pct-unit {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

.cell-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 3px;
  padding: 0 4px;
  font-size: 10.5px;
  color: var(--muted);
}

.cell-code {
  font-family: Consolas, monospace;
  background: #e2e8f0;
  color: #475569;
  padding: 0 4px;
  border-radius: 3px;
  font-size: 10px;
}

.days {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.cell-meta .days {
  display: inline;
  margin-top: 0;
}

/* 區間統計表 */
.days-summary td {
  padding: 5px 8px;
}

.bar-cell {
  display: flex;
  align-items: center;
   justify-content: flex-end;
  gap: 6px;
}

.mini-bar {
  width: 52px;
  height: 6px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
}

.mini-bar > i {
  display: block;
  height: 100%;
  background: var(--accent);
}

.miss {
  display: grid;
  gap: 4px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

/* 分隔拖曳條 */
.splitter {
  width: 7px;
  flex: none;
  cursor: col-resize;
  background: #e4ddd4;
}

.splitter:hover,
.splitter.dragging {
  background: #94a3b8;
}

/* 右側主畫面 */
.main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 28px;
}

.main .stats,
.main .info-banner,
.main .panel,
.main .chips,
.main footer {
  width: calc(100% - 28px);
  margin-left: 14px;
  margin-right: 14px;
}

label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 12.5px;
}

input, button {
  font: inherit;
  color: var(--ink);
}

input {
  border: 1px solid var(--line);
  background: white;
  border-radius: 6px;
  padding: 6px 8px;
}

button {
  border: 0;
  background: var(--ink);
  color: white;
  border-radius: 7px;
  padding: 8px 12px;
  cursor: pointer;
}

/* 頂部核心指標卡片 */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.stats.stats-six {
  grid-template-columns: repeat(6, 1fr);
}

.stats article, .panel, .chip {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.stats article {
  padding: 11px 13px 10px;
}

.stats article.primary-stat {
  border-color: var(--accent-border);
  background: linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
}

.stats article.fut-stat {
  border-color: #bae6fd;
  background: linear-gradient(180deg, #f0f9ff 0%, #ffffff 100%);
}

.stats article.dual-stat {
  border-color: #ddd6fe;
  background: linear-gradient(180deg, #faf5ff 0%, #ffffff 100%);
}

.swatch.dual {
  background: #8b5cf6;
}

.stats.stats-eight {
  grid-template-columns: repeat(4, 1fr);
}

.main .stats-period-bar {
  width: calc(100% - 28px);
  margin: 12px 14px 8px;
}

.stats.stats-table-card {
  display: block;
  margin-top: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.stats-table-scroll {
  width: 100%;
  overflow-x: auto;
}

.stats-table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
  table-layout: auto;
}

.stats-table thead th {
  background: #f8f6f2;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.stats-table thead th.col-num,
.stats-table thead th.col-ratio {
  text-align: right;
}

.stats-table thead th.col-ratio,
.stats-table thead th.col-mult {
  cursor: help;
}

.stats-table tbody td {
  padding: 9px 10px;
  vertical-align: middle;
  border-bottom: 1px solid #ece7df;
}

.stats-table tbody tr:last-child td {
  border-bottom: none;
}

.stats-table .col-name {
  width: 17%;
  min-width: 168px;
}

.stats-table .col-num {
  width: 13%;
  min-width: 138px;
  text-align: right;
  white-space: nowrap;
}

.stats-table .col-ratio {
  width: 5.5%;
  min-width: 58px;
  text-align: right;
  white-space: nowrap;
}

.stats-table .col-detail {
  width: 17.5%;
  min-width: 165px;
}

.stats-table .col-meta {
  width: 10%;
  min-width: 112px;
}

.stats-table .v-mult {
  color: #1e3a8a;
}

.stats-table tbody tr.row-bench .v-mult {
  color: var(--ink);
}

.stats-table .v-ratio {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.row-name-cell {
  display: flex;
  align-items: center;
  gap: 9px;
}

.row-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}

.row-dot.strat { background: var(--red); }
.row-dot.dual { background: #8b5cf6; }
.row-dot.fut { background: #0284c7; }
.row-dot.bench { background: var(--gray); }

.row-name strong {
  display: block;
  font-size: 13.5px;
  color: var(--ink);
  line-height: 1.3;
}

.row-name small {
  display: block;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
  margin-top: 1px;
}

.stats-table tbody tr.row-primary {
  background: #fffdfd;
}
.stats-table tbody tr.row-primary td:first-child {
  box-shadow: inset 3px 0 0 var(--red);
}

.stats-table tbody tr.row-dual {
  background: #fcfaff;
}
.stats-table tbody tr.row-dual td:first-child {
  box-shadow: inset 3px 0 0 #8b5cf6;
}

.stats-table tbody tr.row-fut {
  background: #f7fcff;
}
.stats-table tbody tr.row-fut td:first-child {
  box-shadow: inset 3px 0 0 #0284c7;
}

.stats-table tbody tr.row-bench {
  background: #fafafa;
}
.stats-table tbody tr.row-bench td:first-child {
  box-shadow: inset 3px 0 0 var(--gray);
}

.stats-table tbody tr:hover {
  background: #f3f6fb;
}

.stats-table .v {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stats-table .s {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  min-height: 0;
}

.stats-table .card-split-row {
  margin-top: 3px;
  padding-top: 0;
  border-top: 0;
  justify-content: flex-end;
  gap: 5px;
  font-size: 11px;
  min-height: 16px;
}

.k {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}

.v {
  margin: 3px 0 0;
  font-size: 27px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.s {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  min-height: 1.2em;
  line-height: 1.35;
}

.neg { color: var(--red); }

.info-banner {
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.stats-period-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: #ffffff;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  flex-wrap: wrap;
}

.stats-period-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.period-indicator-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.stats-scope-badge {
  font-size: 11px;
  padding: 2px 6px;
  background: #eff6ff;
  color: #1d4ed8;
  border-radius: 4px;
  font-weight: 600;
}

.stats-period-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-stat-scope {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-stat-scope:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

.btn-stat-scope.on {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25);
}

.card-split-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #e2e8f0;
  font-size: 11px;
  color: #64748b;
  min-height: 20px;
}

.card-split-row .split-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.card-split-row .split-item small {
  font-size: 10px;
  color: #94a3b8;
  font-weight: 600;
}

.card-split-row .split-item b {
  color: #1e293b;
  font-weight: 700;
}

.card-split-row .split-divider {
  color: #cbd5e1;
}

.target, .status, .caption, footer p {
  color: var(--muted);
  font-size: 12.5px;
}

.target { margin: 0; }
.status { margin: 3px 0 0; color: var(--ink); font-weight: 600; }
.status.bad { color: var(--red); }

.panel {
  margin-top: 10px;
  padding: 14px 16px 12px;
}

.chart-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.chart-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.scope-toggle-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.scope-btn-pill {
  display: inline-flex;
  background: #f1f5f9;
  padding: 2px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
}

.btn-scope {
  border: none;
  background: transparent;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1.4;
}

.btn-scope:hover {
  color: #1e293b;
}

.btn-scope.on {
  background: #2563eb;
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25);
}

.year-nav-wrap {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 1px 4px;
}

.select-year {
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: #1e293b;
  padding: 3px 4px;
  cursor: pointer;
  outline: none;
}

.btn-year-arrow {
  border: none;
  background: transparent;
  padding: 3px 6px;
  font-size: 11px;
  color: #64748b;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s ease;
  line-height: 1;
}

.btn-year-arrow:hover:not(:disabled) {
  background: #e2e8f0;
  color: #0f172a;
}

.btn-year-arrow:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 12px;
}

.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 18px; height: 8px; display: inline-block; border-radius: 99px; }
.swatch.bench { background: var(--gray); }
.swatch.strat { background: var(--red); }
.swatch.fut { background: #0284c7; }
.swatch.short { background: #9ec9e2; }
.swatch.cash { background: #cfcfcf; }
.swatch.discount { background: #c4add4; }

.chart-wrap { position: relative; margin-top: 8px; }
canvas { width: 100%; height: 820px; display: block; cursor: crosshair; }

.tip {
  position: absolute;
  pointer-events: none;
  background: rgba(29, 28, 26, 0.92);
  color: white;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.45;
  white-space: nowrap;
}

.caption { margin: 8px 0 0; }

/* 年度績效圖與逐筆交易明細面板 */
.panel-heading-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.annual-panel {
  margin-top: 12px;
}

.annual-title-left {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.panel-fold-toggle {
  background: transparent;
  color: var(--ink);
  border: 0;
  padding: 2px 4px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.panel-fold-toggle:hover {
  background: #f1f5f9;
}

.panel-subnote {
  font-size: 12px;
  color: var(--muted);
}

.annual-chart-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  font-size: 12px;
  color: var(--ink);
}

.annual-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.annual-legend-item i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
  flex-shrink: 0;
}

#annual-body[hidden] {
  display: none !important;
}

.annual-chart-container {
  margin-top: 10px;
  width: 100%;
  overflow-x: auto;
}

.annual-bar-chart {
  width: 100%;
  min-width: 720px;
  height: 300px;
  display: block;
}

.annual-bar-chart text {
  font-variant-numeric: tabular-nums;
}

.annual-empty-note {
  padding: 36px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.trades-panel {
  margin-top: 12px;
}

.trades-panel-head {
  align-items: flex-start;
  margin-bottom: 10px;
}

.trades-tab-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.trades-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.trades-title-row h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.trades-count-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #1d4ed8;
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.trade-tabs {
  display: inline-flex;
  flex-wrap: wrap;
  background: #f1f5f9;
  padding: 3px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  gap: 3px;
}

.trade-tab-btn {
  border: 0;
  background: transparent;
  color: #475569;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  transition: all 0.14s ease;
}

.trade-tab-btn:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
}

.trade-tab-btn.on {
  background: #ffffff;
  color: var(--accent);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.trades-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.trade-rolls-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 7px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  font-size: 12px;
  font-weight: 600;
  color: #0369a1;
  cursor: pointer;
}

.trade-rolls-check[hidden] {
  display: none !important;
}

.btn-trade-action {
  border: 1px solid #bfd4fe;
  background: #eff6ff;
  color: #1d4ed8;
  border-radius: 7px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 650;
  transition: all 0.14s ease;
}

.btn-trade-action:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}

.btn-trade-action.secondary {
  background: #f8fafc;
  color: #334155;
  border-color: #cbd5e1;
}

.btn-trade-action.secondary:hover {
  background: #f1f5f9;
}

.trades-table-scroll {
  max-height: 480px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.trades-table-scroll[hidden] {
  display: none !important;
}

.trades-table {
  width: 100%;
  min-width: 980px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.trades-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8f6f2;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.trades-table thead th.col-price,
.trades-table thead th.col-cost,
.trades-table thead th.col-ret,
.trades-table thead th.col-eq {
  text-align: right;
}

.trades-table tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid #ece7df;
  vertical-align: middle;
  color: var(--ink);
  white-space: nowrap;
}

.trades-table tbody tr:last-child td {
  border-bottom: none;
}

.trades-table tbody tr:nth-child(even) td {
  background: #faf9f7;
}

.trades-table tbody tr.trade-row-hold td {
  background: #f0f6ff;
  border-bottom: 2px solid #bfd4fe;
  font-weight: 600;
}

.trades-table tbody tr.trade-row-roll td {
  background: #f8fafc;
  color: #475569;
}

.trades-table tbody tr:hover td {
  background: #eef4ff;
}

.trades-table td.col-reason {
  white-space: normal;
  min-width: 220px;
  max-width: 340px;
  line-height: 1.4;
}

.trades-table td.col-price,
.trades-table td.col-cost,
.trades-table td.col-ret,
.trades-table td.col-eq {
  text-align: right;
}

.trades-table .ret-pos {
  color: #dc2626;
  font-weight: 700;
}

.trades-table .ret-neg {
  color: #15803d;
  font-weight: 700;
}

.trade-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.4;
}

.trade-badge.buy {
  background: #eaf1ff;
  color: #1d4ed8;
}

.trade-badge.sell {
  background: #e9f4ef;
  color: #15803d;
}

.trade-badge.short {
  background: #fef2f2;
  color: #b91c1c;
}

.trade-badge.cover {
  background: #fffbeb;
  color: #b45309;
}

.trade-badge.roll {
  background: #e2e8f0;
  color: #334155;
}

.trade-badge.hold {
  background: #2563eb;
  color: #ffffff;
}

.trade-cell-chip {
  display: inline-block;
  font-family: Consolas, monospace;
  background: #e2e8f0;
  color: #334155;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
  margin-right: 5px;
  font-weight: 600;
}

.trades-empty {
  text-align: center !important;
  color: var(--muted) !important;
  padding: 26px 12px !important;
}

.chips {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.chip { padding: 12px 15px; }
.chip h3 { margin: 0 0 5px; font-size: 14px; }
.chip p { margin: 0 0 3px; color: var(--muted); font-size: 12.5px; }
.chip strong { color: var(--ink); font-weight: 650; }

footer {
  margin-top: 12px;
}

footer p { margin: 0 0 4px; }
code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px; }

@media (max-width: 1440px) {
  .stats.stats-six {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ==========================================================================
   公開檢視（左側欄收合鎖定）與 AES 解密解鎖介面
   ========================================================================== */

body.locked-mode .side,
body.locked-mode .splitter,
body.locked-mode #flow-summary,
body.locked-mode #chips,
body.locked-mode #legend-discount-item,
body.locked-mode .trades-table th.col-reason,
body.locked-mode .trades-table td.col-reason {
  display: none !important;
}

body:not(.locked-mode) #side-rail,
body:not(.locked-mode) #public-mode-badge {
  display: none !important;
}

.side-rail {
  width: 42px;
  flex: none;
  background: var(--side-bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.side-rail:hover {
  background: var(--accent-soft);
  border-right-color: var(--accent-border);
}

.rail-unlock-btn {
  writing-mode: vertical-rl;
  text-orientation: upright;
  letter-spacing: 0.16em;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  font-family: inherit;
}

.rail-icon {
  writing-mode: horizontal-tb;
  font-size: 15px;
}

.rail-chevron {
  writing-mode: horizontal-tb;
  font-size: 13px;
  color: var(--muted);
}

.public-mode-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 99px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
}

.btn-header-unlock {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 99px;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s ease;
}

.btn-header-unlock:hover {
  opacity: 0.9;
}

.side-lock-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent);
}

.btn-lock-workbench {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-lock-workbench:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.unlock-modal[hidden] {
  display: none !important;
}

.unlock-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(3px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.unlock-card {
  width: 100%;
  max-width: 390px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.25);
}

.unlock-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.unlock-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}

.unlock-desc {
  margin: 0 0 14px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.55;
}

.unlock-input {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

.unlock-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.unlock-error {
  margin: 8px 0 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--red);
}

.unlock-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.btn-unlock-cancel {
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}

.btn-unlock-submit {
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}

.btn-unlock-submit:disabled {
  opacity: 0.65;
  cursor: wait;
}

@media (max-width: 960px) {
  html, body { height: auto; }
  body { overflow: auto; }
  .shell {
    flex-direction: column;
    overflow: visible;
  }
  .side-rail {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 8px 14px;
    flex-direction: row;
    justify-content: center;
  }
  .rail-unlock-btn {
    writing-mode: horizontal-tb;
    letter-spacing: 0.04em;
    padding: 4px 10px;
    gap: 8px;
  }
  .side {
    width: 100% !important;
    max-width: none;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    overflow-y: visible;
  }
  .splitter { display: none; }
  .main {
    width: 100%;
    overflow-y: visible;
  }
  .tip {
    white-space: normal;
    max-width: calc(100% - 16px);
  }
  .top, .chart-head, .panel-heading-bar { flex-direction: column; align-items: flex-start; }
  .stats, .stats.stats-six, .stats.stats-eight, .chips { grid-template-columns: 1fr 1fr; }
  .stats.stats-table-card { display: block; }
  .annual-bar-chart { min-width: 580px; }
  canvas { height: 560px; }
}
