:root {
  color-scheme: light;
  --bg: #eef2ef;
  --surface: #ffffff;
  --surface-soft: #f7f9f6;
  --ink: #17201c;
  --muted: #65716b;
  --line: #dbe2dc;
  --green: #24755a;
  --green-dark: #165a43;
  --blue: #3867b7;
  --amber: #b7791f;
  --coral: #c95c45;
  --violet: #7254a8;
  --shadow: 0 16px 42px rgba(23, 32, 28, 0.08);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0) 260px),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--green-dark);
  font-weight: 800;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0;
}

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

h1 {
  font-size: clamp(1.75rem, 3vw, 2.9rem);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  font-size: 1rem;
  line-height: 1.35;
  letter-spacing: 0;
}

h3 {
  font-size: 1rem;
  line-height: 1.35;
}

.subtitle {
  margin-top: 8px;
  color: var(--muted);
  font-weight: 700;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 900;
  color: var(--ink);
  background: var(--surface);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(23, 32, 28, 0.11);
}

.btn-primary {
  color: #fff;
  background: var(--green-dark);
}

.btn-secondary {
  border-color: var(--line);
}

.btn.compact {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.85rem;
}

.full-btn {
  width: 100%;
  margin-top: 12px;
}

.btn-icon {
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(36, 117, 90, 0.12);
  color: var(--green-dark);
  font-weight: 900;
}

.btn-primary .btn-icon {
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
}

.data-note {
  margin-bottom: 18px;
  border: 1px solid #e5d2a5;
  border-left: 5px solid var(--amber);
  border-radius: 8px;
  padding: 10px 12px;
  color: #6f4d18;
  background: #fff8e7;
  font-size: 0.92rem;
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.control-panel,
.panel,
.kpi {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.control-panel {
  position: sticky;
  top: 16px;
  display: grid;
  overflow: hidden;
}

.control-section {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.control-section:last-child {
  border-bottom: 0;
}

.section-title,
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.panel-head p,
.source-stamp {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.55;
}

.source-stamp {
  margin-top: 10px;
}

.status-badge {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  color: #6f4d18;
  background: #fff0c9;
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.status-badge.good {
  color: var(--green-dark);
  background: #ddf4ec;
}

.status-badge.warn {
  color: #8a3a25;
  background: #ffe4dc;
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 13px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 900;
}

.field input,
.field select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: rgba(36, 117, 90, 0.65);
  box-shadow: 0 0 0 3px rgba(36, 117, 90, 0.14);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 13px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

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

.segment.active {
  color: #fff;
  background: var(--green-dark);
}

.selected-brief {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.selected-brief strong {
  display: block;
  margin-bottom: 4px;
}

.selected-brief p {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.plain-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.workspace {
  display: grid;
  gap: 18px;
}

.holdings-form {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.holding-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  align-items: center;
}

.holding-row span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 900;
}

.holding-row input {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
}

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

.kpi {
  min-height: 118px;
  padding: 16px;
  display: grid;
  align-content: space-between;
  gap: 8px;
  box-shadow: none;
}

.kpi-accent {
  border-color: rgba(36, 117, 90, 0.4);
  background: linear-gradient(180deg, #ffffff, #eef8f4);
}

.kpi-label {
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 900;
}

.kpi strong {
  overflow-wrap: anywhere;
  font-size: clamp(1.25rem, 2vw, 2rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.kpi small {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.chart-grid,
.market-grid,
.summary-grid,
.decision-grid,
.info-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(0, 0.82fr);
  gap: 18px;
}

.panel {
  padding: 16px;
}

.panel canvas {
  width: 100%;
  margin-top: 14px;
  display: block;
}

.market-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.market-card,
.futures-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.market-card {
  display: grid;
  gap: 8px;
}

.market-card header,
.futures-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.market-card h3,
.futures-card h3 {
  font-size: 0.92rem;
}

.market-price {
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex-wrap: wrap;
}

.market-price strong {
  font-size: 1.15rem;
}

.market-note,
.futures-card p {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.market-meter {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7ebe7;
}

.market-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.market-meter.caution span {
  background: var(--amber);
}

.market-meter.risk span {
  background: var(--coral);
}

.futures-card {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.macro-badge {
  display: inline-flex;
  min-height: 25px;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 0.76rem;
  font-weight: 900;
  white-space: nowrap;
}

.macro-badge.good {
  color: var(--green-dark);
  background: #ddf4ec;
}

.macro-badge.caution {
  color: #6f4d18;
  background: #fff0c9;
}

.macro-badge.risk {
  color: #8a3a25;
  background: #ffe4dc;
}

.today-summary,
.timestamp-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.today-hero {
  border: 1px solid rgba(36, 117, 90, 0.28);
  border-radius: 8px;
  padding: 14px;
  background: #eef8f4;
}

.today-hero strong {
  display: block;
  margin-bottom: 6px;
  font-size: 1.25rem;
}

.today-hero p,
.timestamp-item p {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.today-actions,
.timestamp-item {
  display: grid;
  gap: 8px;
}

.today-action,
.timestamp-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-soft);
}

.today-action {
  display: grid;
  grid-template-columns: 76px 1fr auto;
  gap: 10px;
  align-items: center;
}

.today-action strong {
  font-size: 0.95rem;
}

.today-action p {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.timestamp-item header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.decision-list,
.scenario-list,
.risk-grid {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.decision-item,
.scenario-item,
.risk-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.decision-item header,
.scenario-item header,
.risk-item header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.score-breakdown {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.score-chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.score-chip span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}

.score-chip strong {
  display: block;
  margin-top: 3px;
  font-size: 0.95rem;
}

.scenario-steps {
  display: grid;
  gap: 8px;
}

.scenario-step {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 10px;
  align-items: start;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.scenario-step:first-child {
  border-top: 0;
  padding-top: 0;
}

.scenario-step strong {
  font-size: 0.88rem;
}

.scenario-step p,
.risk-item p {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.risk-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.risk-list {
  display: grid;
  gap: 7px;
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.table-wrap {
  margin-top: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1080px;
  background: #fff;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 0.9rem;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #f8faf7;
  font-size: 0.8rem;
  font-weight: 900;
  white-space: nowrap;
}

tbody tr {
  transition: background 0.16s ease;
}

tbody tr:hover,
tbody tr.is-focused {
  background: #eef8f4;
}

.etf-button {
  display: grid;
  gap: 3px;
  border: 0;
  padding: 0;
  text-align: left;
  color: inherit;
  background: transparent;
}

.etf-button strong {
  font-size: 0.98rem;
}

.muted,
.subtle {
  color: var(--muted);
  font-size: 0.8rem;
}

.price-cell strong {
  display: block;
  font-size: 1rem;
}

.up {
  color: #b8352a;
}

.down {
  color: #24755a;
}

.tag {
  display: inline-flex;
  min-height: 25px;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.tag.buy {
  color: var(--green-dark);
  background: #ddf4ec;
}

.tag.watch {
  color: #6f4d18;
  background: #fff0c9;
}

.tag.wait {
  color: #8a3a25;
  background: #ffe4dc;
}

.tag.cool {
  color: var(--blue);
  background: #e7eefb;
}

.money-cell strong {
  display: block;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.report-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-soft);
}

.report-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.report-card h3 {
  font-size: 1rem;
}

.report-card p {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.report-card .mini-title {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 900;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}

.stat strong {
  display: block;
  margin-top: 3px;
  font-size: 0.95rem;
}

.news-list,
.source-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.news-item,
.source-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.news-item strong,
.source-item strong {
  display: block;
  margin-bottom: 4px;
}

.news-item p,
.source-item p {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.55;
}

.source-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-size: 0.84rem;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  border-radius: 8px;
  padding: 12px 14px;
  color: #fff;
  background: rgba(23, 32, 28, 0.92);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1250px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }

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

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

  .market-cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .score-breakdown,
  .risk-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .app-shell {
    width: min(100% - 20px, 1500px);
    padding-top: 16px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .chart-grid,
  .market-grid,
  .summary-grid,
  .decision-grid,
  .info-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 580px) {
  .kpi-grid,
  .report-grid {
    grid-template-columns: 1fr;
  }

  .market-cards {
    grid-template-columns: 1fr;
  }

  .score-breakdown,
  .risk-grid,
  .today-action {
    grid-template-columns: 1fr;
  }

  .btn {
    flex: 1 1 auto;
  }

  .segmented {
    grid-template-columns: 1fr;
  }
}
