:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-strong: #eef3f8;
  --text: #17202c;
  --muted: #667085;
  --line: #d8dee8;
  --blue: #1f6feb;
  --green: #0c9b72;
  --amber: #b7791f;
  --red: #d04444;
  --ink: #0d1117;
  --shadow: 0 16px 42px rgba(20, 35, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  letter-spacing: 0;
}

body.sidebar-open {
  overflow: hidden;
}

button,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: min(340px, calc(100vw - 28px));
  border-right: 1px solid var(--line);
  background: #111927;
  color: #f8fafc;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  transform: translateX(-104%);
  transition: transform 180ms ease;
  box-shadow: 22px 0 56px rgba(13, 17, 23, 0.22);
}

body.sidebar-open .sidebar {
  transform: translateX(0);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(13, 17, 23, 0.46);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

body.sidebar-open .sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.sidebar-toggle {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 19;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 10px;
  align-items: center;
  min-width: 178px;
  min-height: 56px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 8px 12px;
  color: #fff;
  background: #111927;
  box-shadow: 0 16px 38px rgba(13, 17, 23, 0.22);
  text-align: left;
}

.sidebar-toggle span:not(.brand-mark) {
  font-weight: 800;
}

.sidebar-toggle small {
  grid-column: 2;
  color: #aab7c8;
  font-size: 12px;
  line-height: 1.2;
}

.brand-mark.small {
  width: 36px;
  height: 36px;
  grid-row: 1 / span 2;
}

body.sidebar-open .sidebar-toggle {
  opacity: 0;
  pointer-events: none;
}

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

.brand > div:nth-child(2) {
  min-width: 0;
  flex: 1;
}

.close-sidebar {
  flex: 0 0 auto;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #2f80ed;
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.module h3 {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
}

.brand p {
  margin-top: 3px;
  color: #aab7c8;
  font-size: 12px;
}

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

.sidebar .panel {
  background: #182235;
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: none;
}

.panel-title,
.module-head,
.topbar,
.top-actions,
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title {
  padding: 16px 16px 10px;
  font-weight: 700;
}

.strategy-panel textarea {
  width: calc(100% - 32px);
  margin: 0 16px;
  resize: vertical;
  color: #f8fafc;
  background: #111927;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 12px;
  line-height: 1.55;
}

.strategy-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px 0;
}

.tag,
.count-pill,
.status-dot,
.sector-badge {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  white-space: nowrap;
}

.tag {
  color: #cfe3ff;
  background: rgba(47, 128, 237, 0.17);
  border: 1px solid rgba(47, 128, 237, 0.3);
}

.count-pill {
  color: #111927;
  background: #e9f2ff;
}

.primary-button,
.ghost-button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button {
  color: #fff;
  background: var(--blue);
}

.primary-button.compact {
  min-height: 36px;
}

.ghost-button {
  color: var(--text);
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.strategy-panel .primary-button {
  width: calc(100% - 32px);
  margin: 14px 16px 16px;
}

.icon-button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: inherit;
  background: transparent;
}

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

.market-tabs {
  display: inline-flex;
  gap: 4px;
  margin-bottom: 18px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.market-tabs button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.market-tabs button.active {
  color: #fff;
  background: var(--ink);
}

.topbar {
  margin-bottom: 18px;
}

.market-summary {
  max-width: 760px;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 700;
}

.topbar h2 {
  font-size: 25px;
}

.metrics-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

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

.metric strong {
  display: block;
  margin: 6px 0 5px;
  font-size: 28px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 0.75fr);
  gap: 18px;
  align-items: start;
}

.left-content,
.right-content {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.module {
  padding: 18px;
}

.module h3 {
  font-size: 18px;
}

.segmented {
  display: flex;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
}

.segmented button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 6px 11px;
}

.segmented button.active {
  color: var(--text);
  background: #fff;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.12);
}

select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

.signal-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.signal-card,
.sector-card,
.watch-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.signal-card {
  padding: 14px;
}

.signal-top,
.sector-top,
.stock-row,
.allocation-row,
.watch-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.signal-type {
  color: #fff;
  background: var(--ink);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
}

.signal-card h4 {
  margin: 13px 0 7px;
  font-size: 16px;
}

.signal-card p,
.sector-card p,
.brief p {
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
}

.score {
  font-weight: 800;
}

.score.up {
  color: var(--green);
}

.score.warn {
  color: var(--amber);
}

.sector-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.portfolio-monitor[hidden] {
  display: none;
}

.portfolio-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.holding-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 15px;
}

.holding-head,
.holding-metrics {
  display: flex;
  gap: 12px;
}

.holding-head {
  align-items: flex-start;
  justify-content: space-between;
}

.holding-head h4 {
  margin: 0 0 4px;
  font-size: 18px;
}

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

.risk-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.risk-high {
  color: #9f2d2d;
  background: #ffeaea;
}

.risk-medium {
  color: #8a5a11;
  background: #fff3d8;
}

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

.holding-metrics div {
  min-width: 0;
  border-radius: 8px;
  background: #f9fbfd;
  padding: 9px;
}

.holding-metrics small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.holding-metrics strong {
  display: block;
  margin-top: 4px;
  font-size: 15px;
}

.monitor-block {
  border-left: 3px solid var(--blue);
  border-radius: 0 8px 8px 0;
  background: #f9fbfd;
  padding: 9px 10px;
}

.monitor-block strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.monitor-block p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.warning-block {
  border-left-color: var(--amber);
}

.action-hold {
  border-left-color: var(--green);
}

.action-add {
  border-left-color: var(--blue);
}

.action-sell {
  border-left-color: var(--red);
}

.sector-card {
  padding: 16px;
}

.sector-title {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.sector-title h4 {
  margin: 0;
  font-size: 18px;
}

.sector-badge {
  color: var(--blue);
  background: #eaf3ff;
}

.add-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  min-height: 34px;
  padding: 0 10px;
  color: var(--blue);
  font-weight: 700;
}

.add-button.active {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.reason-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.reason {
  background: var(--surface-strong);
  border-radius: 8px;
  padding: 9px;
  color: var(--muted);
  font-size: 13px;
}

.stock-table {
  display: grid;
  gap: 8px;
}

.stock-row {
  min-height: 38px;
  background: #f9fbfd;
  border-radius: 8px;
  padding: 7px 10px;
}

.stock-name {
  font-weight: 800;
}

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

.watchlist {
  padding: 0 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.watch-item {
  background: #111927;
  color: #f8fafc;
  border-color: rgba(255, 255, 255, 0.08);
  padding: 12px;
}

.watch-item small {
  color: #aab7c8;
}

.brief {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.brief-block {
  border-left: 3px solid var(--blue);
  padding: 2px 0 2px 12px;
}

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

.status-dot {
  color: var(--green);
  background: #e7f7f1;
}

.allocation {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.allocation-row {
  align-items: flex-start;
}

.bar {
  height: 8px;
  border-radius: 99px;
  background: var(--surface-strong);
  overflow: hidden;
  margin-top: 7px;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--blue);
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  margin-top: 10px;
  border-radius: 8px;
  background: #f8fafc;
}

dialog {
  width: min(720px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(13, 17, 23, 0.48);
}

dialog form {
  padding: 18px;
}

dialog .icon-button {
  color: var(--text);
  border-color: var(--line);
}

pre {
  max-height: 52vh;
  overflow: auto;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  white-space: pre-wrap;
  line-height: 1.6;
}

@media (max-width: 1180px) {
  .content-grid,
  .metrics-row {
    grid-template-columns: 1fr 1fr;
  }

  .left-content {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .main {
    padding: 16px;
  }

  .sidebar-toggle {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
  }

  .topbar,
  .module-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .market-tabs {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .metrics-row,
  .content-grid,
  .signal-board,
  .portfolio-grid,
  .holding-metrics,
  .reason-list {
    grid-template-columns: 1fr;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1;
  }
}
