:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #eef5f2;
  --ink: #14201b;
  --muted: #66736d;
  --line: #d8e1dd;
  --red: #d94c4c;
  --red-soft: #ffe8e7;
  --green: #16856b;
  --green-soft: #ddf4ec;
  --blue: #2f6bd8;
  --blue-soft: #e7efff;
  --amber: #bf7b16;
  --amber-soft: #fff1d8;
  --teal: #0f9b9b;
  --shadow: 0 16px 40px rgba(20, 32, 27, 0.08);
}

body.dark {
  color-scheme: dark;
  --bg: #111512;
  --surface: #181f1b;
  --surface-2: #202b25;
  --ink: #eff7f2;
  --muted: #a3b0aa;
  --line: #314038;
  --red-soft: rgba(217, 76, 76, 0.15);
  --green-soft: rgba(22, 133, 107, 0.18);
  --blue-soft: rgba(47, 107, 216, 0.18);
  --amber-soft: rgba(191, 123, 22, 0.18);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(22, 133, 107, 0.08), transparent 380px),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui,
    -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.side-panel {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(18px);
}

body.dark .side-panel {
  background: rgba(24, 31, 27, 0.76);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.brand strong {
  display: block;
  font-size: 18px;
  line-height: 1.2;
}

.brand small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 12px);
  grid-auto-rows: 12px;
  gap: 4px;
  align-items: end;
  width: 42px;
  height: 42px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-mark span {
  border-radius: 3px;
}

.brand-mark span:nth-child(1) {
  height: 10px;
  background: var(--green);
}

.brand-mark span:nth-child(2) {
  height: 20px;
  background: var(--red);
}

.brand-mark span:nth-child(3) {
  height: 16px;
  background: var(--blue);
}

.brand-mark span:nth-child(4) {
  height: 24px;
  background: var(--amber);
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.1;
}

h2 {
  font-size: 16px;
  line-height: 1.25;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.timestamp {
  min-width: 152px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.timestamp span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.timestamp strong {
  display: block;
  margin-top: 2px;
  font-size: 14px;
}

.panel,
.notice,
.metric,
.rank-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.control-panel {
  margin-top: 12px;
  box-shadow: none;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title > span {
  min-width: fit-content;
  color: var(--muted);
  font-size: 12px;
}

.field,
.slider-row,
.toggle-row {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.field select {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink);
}

.toggle-row {
  grid-template-columns: 18px 1fr;
  align-items: center;
  color: var(--ink);
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.slider-row {
  grid-template-columns: 72px minmax(0, 1fr) 32px;
  align-items: center;
  color: var(--ink);
}

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

.slider-row output {
  justify-self: end;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.icon-button,
.primary-button,
.secondary-button,
.file-drop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
}

.icon-button {
  padding: 0 11px;
  background: var(--surface-2);
}

.icon-button svg,
.primary-button svg,
.secondary-button svg,
.file-drop svg,
.notice svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.primary-button,
.secondary-button,
.file-drop {
  width: 100%;
  margin-top: 10px;
  padding: 0 12px;
}

.primary-button {
  border-color: rgba(217, 76, 76, 0.42);
  background: var(--red);
  color: #fff;
  font-weight: 800;
}

.secondary-button,
.file-drop {
  background: var(--surface-2);
}

.file-drop {
  position: relative;
}

.file-drop input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px 14px;
  background: var(--amber-soft);
  color: var(--ink);
  box-shadow: none;
  font-size: 13px;
  line-height: 1.45;
}

.notice svg {
  color: var(--amber);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  min-height: 86px;
  padding: 14px;
  box-shadow: none;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}

.main-stack,
.right-stack {
  display: grid;
  gap: 16px;
}

.ranking-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.rank-card {
  min-height: 236px;
  padding: 14px;
  box-shadow: none;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    background 180ms ease;
}

.rank-card:hover,
.rank-card.active {
  border-color: rgba(217, 76, 76, 0.55);
  transform: translateY(-2px);
}

.rank-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.rank-number {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: var(--red-soft);
  color: var(--red);
  font-weight: 900;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

.stock-name {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.stock-name strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}

.stock-name span {
  color: var(--muted);
  font-size: 12px;
}

.price-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.price-line strong {
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}

.price-line span {
  align-self: end;
  color: var(--red);
  font-weight: 800;
}

.reason-list {
  display: grid;
  gap: 7px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.reason-list li {
  display: flex;
  gap: 8px;
}

.reason-list li::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--red);
  flex: 0 0 7px;
}

.chart-panel canvas,
.radar canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
}

.chart-panel canvas {
  height: 300px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  min-width: 222px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.segment {
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.segment.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.matrix-table {
  overflow-x: auto;
}

.matrix-row {
  display: grid;
  grid-template-columns: 92px 1fr 1fr 1fr 1fr 74px;
  gap: 10px;
  align-items: center;
  min-width: 680px;
  min-height: 44px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.matrix-row.header {
  min-height: 34px;
  color: var(--muted);
  font-weight: 800;
}

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

.matrix-row[data-code] {
  cursor: pointer;
}

.matrix-row[data-code]:hover {
  background: var(--surface-2);
}

.matrix-stock {
  display: grid;
  gap: 2px;
}

.matrix-stock strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.matrix-stock span {
  color: var(--muted);
  font-size: 11px;
}

.bar-cell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 8px;
  align-items: center;
  font-variant-numeric: tabular-nums;
}

.bar-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.bar-fill.red {
  background: var(--red);
}

.bar-fill.green {
  background: var(--green);
}

.bar-fill.amber {
  background: var(--amber);
}

.probability {
  justify-self: end;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--red-soft);
  color: var(--red);
  font-weight: 900;
}

.insight-body {
  display: grid;
  gap: 12px;
}

.insight-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.insight-card strong {
  display: block;
  margin-bottom: 6px;
}

.insight-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.factor-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.factor-list li {
  display: grid;
  gap: 6px;
}

.factor-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.radar {
  margin-bottom: 12px;
}

.radar canvas {
  height: 240px;
}

.risk-list {
  display: grid;
  gap: 8px;
}

.risk-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}

.risk-item strong {
  color: var(--ink);
}

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

  .content-grid,
  .ranking-list {
    grid-template-columns: 1fr;
  }

  .rank-card {
    min-height: unset;
  }

  .right-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 840px) {
  .app-shell {
    display: block;
  }

  .side-panel {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    padding: 16px;
  }

  .topbar,
  .top-actions {
    align-items: stretch;
  }

  .topbar {
    flex-direction: column;
  }

  .metric-grid,
  .right-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .workspace {
    padding: 12px;
  }

  .metric-grid,
  .right-stack {
    grid-template-columns: 1fr;
  }

  .top-actions,
  .notice {
    flex-direction: column;
    align-items: stretch;
  }

  .timestamp,
  .icon-button {
    width: 100%;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .segmented {
    width: 100%;
    min-width: 0;
  }

  .chart-panel canvas {
    height: 260px;
  }
}
