:root {
  --bg: #0b0d10;
  --bg-soft: #11151b;
  --panel: #171c23;
  --panel-soft: #10141a;
  --panel-strong: #202731;
  --text: #eef2f7;
  --muted: #96a2b2;
  --line: #2a3340;
  --line-bright: #394657;
  --green: #36d399;
  --red: #ff6478;
  --teal: #2dd4bf;
  --amber: #f8b84e;
  --blue: #8ab4ff;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, #0b0d10 0%, #101319 48%, #0c0f13 100%);
  color: var(--text);
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
  padding: 12px clamp(16px, 3vw, 34px);
  background: rgba(11, 13, 16, 0.88);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
}
.brand,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 8px;
  background:
    linear-gradient(135deg, var(--teal) 0 49%, transparent 50%),
    linear-gradient(315deg, var(--amber) 0 48%, #151a21 49%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 0 4px rgba(45, 212, 191, 0.08);
}
.topbar p,
.overview p,
.quote-summary p,
.score-panel > p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}
.topbar h1, h2 { margin: 0; letter-spacing: 0; }
.topbar h1 { font-size: 18px; line-height: 1.15; }
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid rgba(138, 180, 255, 0.28);
  border-radius: 999px;
  background: rgba(138, 180, 255, 0.1);
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}
.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}
.icon-button:hover {
  border-color: rgba(45, 212, 191, 0.48);
  color: var(--teal);
}
.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.overview {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  margin: 16px clamp(16px, 3vw, 34px) 0;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(45, 212, 191, 0.12), transparent 36%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.015)),
    var(--panel);
  box-shadow: var(--shadow);
}
.overview h1 {
  margin: 0 0 6px;
  font-size: clamp(28px, 3.2vw, 42px);
  line-height: 1.05;
}
.overview span {
  display: block;
  color: var(--muted);
  font-weight: 650;
}
.overview-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: 1px;
  overflow: hidden;
  min-width: 340px;
  border: 1px solid var(--line-bright);
  border-radius: 8px;
  background: var(--line);
}
.overview-stats div {
  padding: 10px 12px;
  background: rgba(12, 15, 19, 0.88);
}
.overview-stats small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.overview-stats strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: 17px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 330px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px clamp(16px, 3vw, 34px) 22px;
}
.sidebar,
.content {
  display: grid;
  align-content: start;
  gap: 14px;
  min-width: 0;
}
.sidebar {
  position: sticky;
  top: 84px;
}
.tool-panel,
.panel,
.quote-summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(23, 28, 35, 0.96);
  box-shadow: var(--shadow);
}
.tool-panel { padding: 14px; }
.panel { padding: 16px; }
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.section-title span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.sidebar h2,
.panel h2 {
  color: var(--text);
  font-size: 16px;
}

.search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 12px;
}
.search input,
.search button {
  min-height: 42px;
  border: 1px solid var(--line-bright);
  border-radius: 8px;
  padding: 0 12px;
}
.search input {
  background: var(--panel-soft);
  color: var(--text);
}
.search input::placeholder { color: #687589; }
.search input:focus {
  outline: 0;
  border-color: rgba(45, 212, 191, 0.72);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.14);
}
.search button {
  background: linear-gradient(180deg, #2dd4bf, #149f91);
  color: #06100f;
  border-color: rgba(45, 212, 191, 0.7);
  font-weight: 900;
}

.list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}
.stock {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  text-align: left;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}
.stock--no-price {
  grid-template-columns: minmax(0, 1fr);
}
.stock:hover,
.stock.active {
  border-color: rgba(45, 212, 191, 0.55);
  background: rgba(45, 212, 191, 0.08);
}
.stock:hover { transform: translateY(-1px); }
.stock strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stock small {
  color: var(--muted);
  font-weight: 700;
}
.stock .stock-price {
  display: grid;
  justify-items: end;
  align-content: center;
  gap: 3px;
}
.stock .stock-change {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.quote-summary {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(420px, 1.2fr);
  gap: 18px;
  align-items: center;
  padding: 18px 20px;
  background:
    linear-gradient(135deg, rgba(138, 180, 255, 0.1), transparent 32%),
    var(--panel);
}
.quote-summary h2 {
  color: var(--text);
  font-size: clamp(28px, 3.2vw, 40px);
}
#symbol {
  display: inline-flex;
  margin-top: 8px;
  padding: 5px 10px;
  border: 1px solid var(--line-bright);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}
.metrics div {
  min-width: 0;
  padding: 12px;
  border-left: 1px solid var(--line);
}
.metrics div:first-child { border-left: 0; }
.metrics small {
  display: block;
  color: var(--muted);
  margin-bottom: 4px;
}
.metrics strong {
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: clamp(18px, 2vw, 24px);
}
.up { color: var(--green) !important; }
.down { color: var(--red) !important; }

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(270px, 310px);
  gap: 14px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.panel-head span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.tabs {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}
.tabs button {
  min-width: 44px;
  border: 0;
  border-radius: 6px;
  padding: 6px 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}
.tabs button.active {
  background: rgba(45, 212, 191, 0.14);
  color: var(--teal);
}
.chart-panel { min-height: 500px; }
#chart {
  width: 100%;
  height: 420px;
  display: block;
}
.chart-wrap {
  position: relative;
}
.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 190px;
  max-width: min(280px, calc(100vw - 36px));
  padding: 10px 12px;
  border: 1px solid rgba(138, 180, 255, 0.34);
  border-radius: 8px;
  background: rgba(8, 11, 15, 0.94);
  color: var(--text);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.32);
  pointer-events: none;
  transform: translate(-50%, -100%);
}
.chart-tooltip strong {
  display: block;
  margin-bottom: 7px;
  color: var(--teal);
  font-size: 13px;
}
.chart-tooltip span {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.75;
}
.chart-tooltip b {
  color: var(--text);
}

.score-panel {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  text-align: center;
}
.score-ring {
  --score: 0;
  display: grid;
  width: 190px;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--panel) 0 57%, transparent 58%),
    conic-gradient(var(--teal) calc(var(--score) * 1%), #2c3440 0);
  box-shadow:
    inset 0 0 0 1px rgba(45, 212, 191, 0.13),
    0 16px 30px rgba(0, 0, 0, 0.22);
}
.score-ring span {
  color: var(--teal);
  font-size: 54px;
  font-weight: 900;
}
.score-ring small {
  margin-top: -54px;
  color: var(--muted);
  font-weight: 800;
}
#stance {
  margin: 0;
  color: var(--text);
  font-weight: 800;
}
#confidence,
#updated,
footer {
  color: var(--muted);
}

.details {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.compact-panel { min-height: 210px; }
.kv {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}
.kv div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}
.kv span { color: var(--muted); }
.kv strong { color: var(--text); }
ul {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}
li {
  padding: 10px;
  border-left: 4px solid var(--green);
  border-radius: 6px;
  background: rgba(54, 211, 153, 0.09);
  color: #dffaf0;
  line-height: 1.5;
}
#risks li {
  border-left-color: var(--amber);
  background: rgba(248, 184, 78, 0.1);
  color: #ffe8ba;
}

.news {
  display: grid;
  gap: 8px;
}
.news a {
  display: block;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  background: var(--panel-soft);
}
.news a:hover {
  background: rgba(138, 180, 255, 0.08);
  border-color: rgba(138, 180, 255, 0.36);
}
.news span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}
footer {
  padding: 0 clamp(16px, 3vw, 34px) 24px;
  font-size: 12px;
}

@media (max-width: 1120px) {
  .overview,
  .layout,
  .quote-summary,
  .grid {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
  }
  .overview-stats {
    min-width: 0;
  }
  .details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
  }
  .status-pill {
    display: none;
  }
  .overview {
    margin-top: 10px;
    padding: 14px;
  }
  .overview-stats,
  .metrics,
  .details {
    grid-template-columns: 1fr;
  }
  .metrics div {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
  .metrics div:first-child {
    border-top: 0;
  }
  #chart { height: 340px; }
}
