:root {
  --bg: #f3f6f8;
  --ink: #111827;
  --muted: #6b7280;
  --line: #d9e0e7;
  --panel: #ffffff;
  --nav: #07111d;
  --nav-soft: #101d2b;
  --green: #07884f;
  --red: #d72d42;
  --amber: #b7791f;
  --blue: #2563eb;
  --shadow: 0 12px 30px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 260px;
  padding: 22px 14px;
  color: white;
  background: linear-gradient(180deg, var(--nav), #0b1724);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 12px; }
.brand strong { display: block; font-size: 15px; letter-spacing: 0; }
.brand span { display: block; color: #9aa9b8; font-size: 12px; margin-top: 3px; }
.coin {
  width: 42px; height: 42px; border-radius: 8px;
  display: grid; place-items: center;
  background: #f7931a; font-size: 28px; font-weight: 800;
}

.nav { display: grid; gap: 8px; }
.nav button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 12px 14px;
  color: #c7d2df;
  background: transparent;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
}
.nav button.active, .nav button:hover { background: var(--nav-soft); color: white; border-color: #24364b; }

.source-card {
  padding: 14px;
  border: 1px solid #223247;
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
}
.label { color: #9aa9b8; font-size: 12px; }
.source-line { display: flex; justify-content: space-between; margin-top: 12px; font-size: 13px; }
.source-line b { color: #55d38b; font-weight: 700; }
.sidebar-note { margin-top: auto; color: #9aa9b8; font-size: 12px; line-height: 1.65; padding: 8px; }

.app { margin-left: 260px; padding: 22px; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 18px;
}
h1, h2, p { margin: 0; }
h1 { font-size: 30px; line-height: 1.1; }
h2 { font-size: 16px; }
.topbar p, .panel-head p { color: var(--muted); font-size: 12px; margin-top: 6px; }

.header-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 12px;
  min-width: 520px;
}
.header-metrics div, .backtest-grid div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.header-metrics span, .backtest-grid span, .levels span { color: var(--muted); display: block; font-size: 12px; }
.header-metrics strong { display: block; margin-top: 6px; font-size: 18px; }
.header-metrics small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; font-weight: 700; }

.command-center {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}
.command-card {
  min-height: 146px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.command-card.primary {
  color: white;
  background: linear-gradient(135deg, #0b1724, #17324f);
  border-color: #203a5c;
}
.command-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.command-card.primary span { color: #9eb4cd; }
.command-card strong {
  display: block;
  margin: 14px 0 8px;
  font-size: 24px;
  line-height: 1.15;
}
.command-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}
.command-card.primary p { color: #c7d5e3; }
.risk-card strong { color: var(--amber); }

.scenario-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}
.scenario-strip div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 9px;
  row-gap: 4px;
  align-items: start;
}
.scenario-strip b { font-size: 14px; }
.scenario-strip p {
  grid-column: 2;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 4px;
}
.dot.up { background: var(--green); }
.dot.wait { background: var(--amber); }
.dot.down { background: var(--red); }

.position-playbook {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}
.playbook-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px;
}
.playbook-card.holding { border-top: 4px solid var(--blue); }
.playbook-card.cash { border-top: 4px solid var(--green); }
.playbook-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.playbook-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.playbook-head strong {
  font-size: 22px;
  line-height: 1.2;
  text-align: right;
}
.playbook-card p {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 10px;
}
.playbook-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.pm-dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}
.pm-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 14px;
}
.pm-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}
.pm-card-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.pm-card-head strong {
  font-size: 24px;
  line-height: 1.1;
}
.pm-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  margin-top: 9px;
}
.mini-bars {
  display: grid;
  grid-template-columns: repeat(20, 1fr);
  gap: 3px;
  height: 34px;
  align-items: end;
  margin-top: 10px;
}
.mini-bars span {
  display: block;
  min-height: 5px;
  border-radius: 2px;
  background: #d7dee7;
}
.mini-bars span.good { background: var(--green); }
.mini-bars span.bad { background: var(--red); }
.rr-line {
  display: grid;
  grid-template-columns: 1fr 2px 1fr;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.rr-line span {
  height: 10px;
  border-radius: 999px;
  background: var(--red);
}
.rr-line span:last-child { background: var(--green); }
.rr-line b {
  height: 24px;
  width: 2px;
  background: var(--line);
}
.allocation {
  height: 12px;
  border-radius: 999px;
  background: #e7edf3;
  overflow: hidden;
  margin-top: 14px;
}
.allocation span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--green), #35b779);
}

.simulation-dashboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 10px;
}
.sim-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 14px;
}
.sim-card.primary {
  color: white;
  background: #122238;
  border-color: #253a55;
}
.sim-card span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
}
.sim-card.primary span { color: #a8bdd5; }
.sim-card strong {
  display: block;
  margin-top: 8px;
  font-size: 23px;
  line-height: 1.15;
}
.sim-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin-top: 6px;
}
.sim-card.primary p { color: #c8d7e7; }
.sim-note {
  border: 1px solid #d6e0ec;
  border-radius: 8px;
  background: #fbfcfe;
  margin-bottom: 14px;
  padding: 11px 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}
.sim-note strong { font-size: 14px; }
.sim-note span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: right;
}
.engine-status {
  border: 1px solid #c8ead8;
  border-radius: 8px;
  background: #f1fbf6;
  margin-bottom: 14px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 9px;
  align-items: center;
}
.engine-status strong {
  color: var(--green);
  font-size: 14px;
}
.engine-status p {
  color: #456052;
  font-size: 12px;
  text-align: right;
}
.pulse {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(7, 136, 79, 0.45);
  animation: pulse 1.8s infinite;
}
@keyframes pulse {
  70% { box-shadow: 0 0 0 8px rgba(7, 136, 79, 0); }
  100% { box-shadow: 0 0 0 0 rgba(7, 136, 79, 0); }
}

.cloud-war-room {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  padding: 16px;
}
.cloud-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 12px;
}
.cloud-head h2, .cloud-detail h3 {
  margin: 0;
  font-size: 16px;
}
.cloud-head p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 5px;
}
.cloud-head a {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--blue);
  text-decoration: none;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
}
.cloud-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.cloud-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfe;
}
.cloud-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.cloud-grid strong {
  display: block;
  margin-top: 7px;
  font-size: 20px;
}
.cloud-grid p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 5px;
  line-height: 1.45;
}
.cloud-detail {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 12px;
}
.cloud-detail > div {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  min-height: 120px;
}
.cloud-detail h3 {
  font-size: 13px;
  margin-bottom: 8px;
}
.cloud-list {
  display: grid;
  gap: 7px;
}
.cloud-list .row {
  border: 1px solid #e4eaf0;
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  line-height: 1.45;
}
.cloud-list .row b {
  display: block;
  font-size: 13px;
  margin-bottom: 2px;
}
.cloud-list .row span { color: var(--muted); }
.cloud-list .buy b, .cloud-list .good b { color: var(--green); }
.cloud-list .risk b, .cloud-list .bad b { color: var(--red); }
.cloud-list .wait b { color: var(--amber); }

.grid {
  display: grid;
  grid-template-columns: minmax(560px, 1.35fr) minmax(330px, 0.65fr);
  gap: 14px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.chart-panel { grid-row: span 2; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button {
  min-width: 44px;
  border: 0;
  border-right: 1px solid var(--line);
  background: white;
  padding: 8px 10px;
  color: var(--muted);
  cursor: pointer;
}
.segmented button:last-child { border-right: 0; }
.segmented .selected { background: #e8f0ff; color: var(--blue); font-weight: 700; }
.chart-wrap { height: 482px; }

.tag { border-radius: 8px; padding: 6px 8px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.tag.good { background: #dff8eb; color: var(--green); }
.tag.bad { background: #ffe2e7; color: var(--red); }
.tag.neutral { background: #edf1f5; color: #52606f; }
.score-ring {
  width: 148px;
  height: 148px;
  border-radius: 50%;
  margin: 8px auto 14px;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--green) 0deg, var(--green) var(--scoreDeg, 0deg), #e7edf3 var(--scoreDeg, 0deg));
}
.score-ring > div {
  width: 112px; height: 112px; border-radius: 50%; background: white;
  display: grid; place-items: center; align-content: center;
}
.score-ring span, .score-ring em { color: var(--muted); font-size: 12px; font-style: normal; }
.score-ring strong { font-size: 34px; }
.decision { border-left: 4px solid var(--amber); padding: 10px 12px; background: #fff8eb; font-size: 14px; line-height: 1.6; }
.levels { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 14px; }
.levels div { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.levels strong { display: block; margin-top: 5px; font-size: 16px; }
.buy strong { color: var(--green); }
.sell strong { color: var(--red); }

.metric-list { display: grid; gap: 10px; }
.metric {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.metric:last-child { border-bottom: 0; }
.metric span { color: var(--muted); font-size: 12px; display: block; margin-top: 3px; }
.metric b.green { color: var(--green); }
.metric b.red { color: var(--red); }
.metric b.amber { color: var(--amber); }

.volume-bar { height: 12px; border-radius: 999px; background: var(--red); overflow: hidden; margin: 10px 0; }
.volume-bar span { display: block; height: 100%; background: var(--green); }
.pressure-labels { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 10px; }
.pressure-labels b:first-child { color: var(--green); }
.pressure-labels b:last-child { color: var(--red); }
.compact .metric { padding: 8px 0; }

.backtest-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.backtest-grid div { box-shadow: none; }
.backtest-grid strong { display: block; font-size: 20px; margin-top: 4px; }
.validation-text { color: var(--muted); font-size: 13px; line-height: 1.6; margin-top: 12px; }

.journal {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}
.journal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}
.journal h3 {
  margin: 0;
  font-size: 15px;
}
.journal p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 5px;
}
.journal-head strong {
  font-size: 20px;
  white-space: nowrap;
}
.journal-meter {
  height: 10px;
  border-radius: 999px;
  background: #e7edf3;
  overflow: hidden;
  margin: 12px 0;
}
.journal-meter span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--amber), var(--green));
}
.journal-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.journal-stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}
.journal-stats span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}
.journal-stats b {
  display: block;
  margin-top: 4px;
  font-size: 13px;
}
.journal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.journal-actions button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
}
.journal-actions button:hover { background: #f5f8fb; }

.intel-feed { display: grid; gap: 10px; max-height: 340px; overflow: auto; padding-right: 3px; }
.intel-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 7px;
}
.intel-item a { color: var(--ink); text-decoration: none; font-weight: 700; line-height: 1.35; }
.intel-item a:hover { color: var(--blue); }
.intel-meta { color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; gap: 10px; }
.intel-meta b { color: var(--green); }

.risk {
  margin-top: 14px;
  border: 1px solid #f0d499;
  border-radius: 8px;
  background: #fff8eb;
  color: #68470c;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
}
.risk strong { margin-right: 8px; }

.green-text { color: var(--green); }
.red-text { color: var(--red); }
.muted { color: var(--muted); }

@media (max-width: 1080px) {
  .sidebar { position: static; width: auto; min-height: auto; }
  .app { margin-left: 0; }
  .topbar { flex-direction: column; }
  .header-metrics { min-width: 0; width: 100%; }
  .command-center { grid-template-columns: repeat(2, 1fr); }
  .position-playbook { grid-template-columns: 1fr; }
  .pm-dashboard { grid-template-columns: 1fr; }
  .simulation-dashboard { grid-template-columns: repeat(2, 1fr); }
  .cloud-grid, .cloud-detail { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: 1fr; }
  .chart-panel { grid-row: auto; }
}

@media (max-width: 640px) {
  .app { padding: 14px; }
  .header-metrics, .backtest-grid { grid-template-columns: 1fr; }
  .command-center, .scenario-strip, .simulation-dashboard { grid-template-columns: 1fr; }
  .sim-note { display: block; }
  .sim-note span { display: block; text-align: left; margin-top: 6px; }
  .engine-status { grid-template-columns: auto 1fr; }
  .engine-status p { grid-column: 2; text-align: left; }
  .cloud-grid, .cloud-detail { grid-template-columns: 1fr; }
  .cloud-head { display: block; }
  .cloud-head a { display: inline-block; margin-top: 8px; }
  .panel-head { flex-direction: column; }
  .chart-wrap { height: 360px; }
  h1 { font-size: 24px; }
}
