:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-soft: #eef3f5;
  --ink: #18202b;
  --muted: #667085;
  --line: #d9e0e7;
  --teal: #0f9f8f;
  --teal-soft: #dff7f2;
  --red: #d94f45;
  --red-soft: #fde8e6;
  --amber: #c27a12;
  --amber-soft: #fff0d3;
  --violet: #6f5bd6;
  --blue: #2f6fcb;
  --shadow: 0 18px 45px rgba(31, 45, 61, 0.09);
  --radius: 8px;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(15, 159, 143, 0.08), transparent 32%),
    linear-gradient(315deg, rgba(47, 111, 203, 0.08), transparent 30%),
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 330px) minmax(0, 1fr);
  min-height: 100vh;
}

.side-panel {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100vh;
  padding: 20px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 4px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: var(--radius);
  color: #fff;
  background: linear-gradient(145deg, #f08a24, #be3f35);
  font-size: 1.7rem;
  font-weight: 800;
  box-shadow: 0 12px 28px rgba(190, 63, 53, 0.22);
}

h1,
h2,
h3,
p {
  margin: 0;
}

.brand-block h1 {
  font-size: 1.2rem;
  line-height: 1.15;
}

.brand-block p,
.panel-title-row p,
.metric-tile small,
.source-copy small,
.risk-note {
  color: var(--muted);
}

.control-section,
.chart-panel,
.weights-panel,
.correction-panel,
.direction-panel,
.metric-tile {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.control-section {
  padding: 16px;
}

.section-heading,
.panel-title-row,
.top-strip,
.prediction-band,
.market-snapshot,
.direction-lockup,
.range-readout,
.toolbar {
  display: flex;
  align-items: center;
}

.section-heading,
.panel-title-row,
.top-strip {
  justify-content: space-between;
  gap: 16px;
}

.section-heading h2,
.panel-title-row h3 {
  font-size: 0.98rem;
  line-height: 1.3;
}

.status-pill,
.mini-score,
.status-dot,
.market-snapshot span,
.metric-tile span,
.direction-panel .label,
.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.status-pill,
.mini-score {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-soft);
}

.status-pill.is-running {
  color: #06796d;
  background: var(--teal-soft);
}

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 5px var(--teal-soft);
}

.cycle-readout {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin: 18px 0 14px;
  padding: 12px;
  border-radius: var(--radius);
  background: #f8fafc;
}

.cycle-readout span {
  color: var(--muted);
  font-size: 0.85rem;
}

.cycle-readout strong {
  font-size: 1.45rem;
  line-height: 1;
}

.toolbar {
  gap: 10px;
}

.icon-button {
  position: relative;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--surface);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-button:hover,
.text-button:hover,
.segment:hover {
  border-color: #a9bacb;
  transform: translateY(-1px);
}

.icon-button.primary {
  color: #fff;
  border-color: var(--teal);
  background: var(--teal);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.2;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 14px;
  padding: 4px;
  border-radius: var(--radius);
  background: #edf1f5;
}

.segment {
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 0.86rem;
  font-weight: 700;
}

.segment.is-active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 8px 18px rgba(20, 31, 43, 0.08);
}

.source-list,
.signal-bars,
.weight-list,
.correction-log {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.source-row {
  display: grid;
  grid-template-columns: 20px 10px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfe;
}

.source-row.is-offline {
  opacity: 0.58;
}

.source-row.is-warning {
  border-color: #f0cf93;
  background: #fffaf0;
}

.source-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
}

.source-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--teal);
}

.source-dot.is-offline {
  background: #98a2b3;
}

.source-dot.is-warning {
  background: var(--amber);
}

.source-copy {
  min-width: 0;
}

.source-copy strong,
.source-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-copy strong {
  font-size: 0.9rem;
}

.source-copy small {
  margin-top: 2px;
  font-size: 0.76rem;
}

.input-label {
  display: block;
  margin: 14px 0 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.text-input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: #fbfcfe;
}

.text-input:focus,
.range-input:focus-visible,
button:focus-visible {
  outline: 3px solid rgba(15, 159, 143, 0.22);
  outline-offset: 2px;
}

.range-input {
  width: 100%;
  accent-color: var(--teal);
}

.range-readout {
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.78rem;
}

.range-readout strong {
  color: var(--ink);
}

.workspace {
  display: grid;
  gap: 18px;
  align-content: start;
  padding: 22px;
}

.top-strip {
  min-height: 78px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--teal);
}

.top-strip h2 {
  font-size: 1.6rem;
  line-height: 1.15;
}

.market-snapshot {
  gap: 10px;
}

.market-snapshot div {
  min-width: 132px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.market-snapshot span,
.market-snapshot strong {
  display: block;
}

.market-snapshot strong {
  margin-top: 4px;
  font-size: 1.04rem;
}

.positive {
  color: var(--teal);
}

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

.prediction-band {
  display: grid;
  grid-template-columns: minmax(280px, 1.35fr) repeat(3, minmax(150px, 0.55fr));
  gap: 14px;
}

.direction-panel {
  padding: 18px;
  color: #fff;
  background:
    linear-gradient(145deg, rgba(15, 159, 143, 0.92), rgba(47, 111, 203, 0.86)),
    #116f78;
  border-color: rgba(255, 255, 255, 0.2);
}

.direction-panel.is-down {
  background:
    linear-gradient(145deg, rgba(217, 79, 69, 0.94), rgba(111, 91, 214, 0.86)),
    #a83d44;
}

.direction-panel .label,
.direction-panel p {
  color: rgba(255, 255, 255, 0.84);
}

.direction-lockup {
  justify-content: space-between;
  gap: 14px;
  margin: 8px 0 14px;
}

.direction-lockup strong {
  font-size: 2.2rem;
  line-height: 1.05;
}

.direction-lockup span {
  font-size: 1.25rem;
  font-weight: 800;
}

.confidence-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
}

.confidence-track span {
  display: block;
  width: 50%;
  height: 100%;
  border-radius: inherit;
  background: #fff;
  transition: width 260ms ease;
}

.direction-panel p {
  margin-top: 12px;
  font-size: 0.9rem;
}

.metric-tile {
  display: grid;
  align-content: space-between;
  min-height: 136px;
  padding: 16px;
}

.metric-tile strong {
  display: block;
  margin: 10px 0 4px;
  font-size: 1.8rem;
  line-height: 1.05;
}

.chart-grid,
.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(320px, 0.85fr);
  gap: 18px;
}

.chart-panel,
.weights-panel,
.correction-panel {
  min-width: 0;
  padding: 18px;
}

.panel-title-row {
  margin-bottom: 14px;
}

.panel-title-row h3 {
  margin-bottom: 3px;
}

.panel-title-row span,
.text-button {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.canvas-wrap {
  position: relative;
  min-height: 280px;
  aspect-ratio: 21 / 9;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.signal-row {
  display: grid;
  grid-template-columns: minmax(96px, 0.56fr) minmax(0, 1fr) 48px;
  align-items: center;
  gap: 10px;
}

.signal-row strong,
.weight-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 0.86rem;
}

.signal-track {
  position: relative;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1f5;
}

.signal-track::after {
  position: absolute;
  top: 0;
  left: 50%;
  width: 1px;
  height: 100%;
  background: rgba(24, 32, 43, 0.22);
  content: "";
}

.signal-fill {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: inherit;
  transition: all 260ms ease;
}

.signal-fill.positive {
  left: 50%;
  background: var(--teal);
}

.signal-fill.negative {
  right: 50%;
  background: var(--red);
}

.signal-row span:last-child {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: right;
}

.weight-row {
  display: grid;
  grid-template-columns: minmax(110px, 0.8fr) minmax(120px, 1fr) 42px;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.weight-row:last-child {
  border-bottom: 0;
}

.weight-row span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.75rem;
}

.weight-row input {
  width: 100%;
  accent-color: var(--blue);
}

.weight-row b {
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}

.text-button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.correction-log {
  max-height: 345px;
  overflow: auto;
  padding-right: 4px;
}

.log-item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 72px;
  align-items: center;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfe;
}

.log-item time {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.log-item strong,
.log-item span {
  display: block;
}

.log-item strong {
  font-size: 0.88rem;
}

.log-item span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.76rem;
}

.log-result {
  justify-self: end;
  min-width: 58px;
  padding: 5px 8px;
  border-radius: 999px;
  color: #06796d;
  background: var(--teal-soft);
  font-size: 0.75rem;
  font-weight: 800;
  text-align: center;
}

.log-result.miss {
  color: #ac332b;
  background: var(--red-soft);
}

.log-result.pending {
  color: #8b5d08;
  background: var(--amber-soft);
}

.risk-note {
  padding: 0 4px 10px;
  font-size: 0.82rem;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: start;
  }

  .brand-block {
    grid-column: 1 / -1;
  }

  .prediction-band,
  .chart-grid,
  .detail-grid {
    grid-template-columns: 1fr 1fr;
  }

  .direction-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .side-panel,
  .prediction-band,
  .chart-grid,
  .detail-grid,
  .top-strip,
  .market-snapshot {
    grid-template-columns: 1fr;
  }

  .workspace {
    padding: 14px;
  }

  .top-strip,
  .market-snapshot {
    display: grid;
  }

  .market-snapshot div {
    min-width: 0;
  }

  .direction-lockup strong {
    font-size: 1.85rem;
  }

  .signal-row,
  .weight-row,
  .log-item {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .signal-row span:last-child,
  .weight-row b,
  .log-result {
    justify-self: start;
    text-align: left;
  }
}

@media (max-width: 520px) {
  .side-panel {
    padding: 14px;
  }

  .brand-block {
    align-items: flex-start;
  }

  .toolbar {
    display: grid;
    grid-template-columns: repeat(4, 42px);
  }

  .top-strip h2 {
    font-size: 1.3rem;
  }

  .metric-tile {
    min-height: 112px;
  }

  .canvas-wrap {
    min-height: 0;
    aspect-ratio: 4 / 3;
  }
}
