:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --text: #1d2528;
  --muted: #69757b;
  --line: #dfe5e7;
  --accent: #116b5f;
  --accent-2: #b45309;
  --danger: #b42318;
  --warn: #b7791f;
  --ok: #16803c;
  --shadow: 0 18px 40px rgba(24, 33, 36, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
  white-space: nowrap;
}

button:hover {
  filter: brightness(0.97);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

button.secondary {
  background: #e7ecef;
  color: var(--text);
}

button.primary {
  background: var(--accent-2);
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  min-height: 36px;
  padding: 7px 9px;
}

textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  min-height: 96px;
  padding: 10px 12px;
  font: inherit;
  line-height: 1.55;
  resize: vertical;
}

textarea:focus {
  outline: 2px solid rgba(17, 107, 95, 0.18);
  border-color: var(--accent);
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #182124;
  color: white;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  overflow: hidden;
  overscroll-behavior: contain;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #d7ede7;
  color: #0f5f54;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.brand p,
.eyebrow,
.section-head p,
.panel-head p {
  margin: 0;
  color: var(--muted);
}

.brand p {
  color: #b6c1c5;
  font-size: 13px;
  margin-top: 4px;
}

.nav {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(215, 237, 231, 0.45) transparent;
}

.nav::-webkit-scrollbar {
  width: 8px;
}

.nav::-webkit-scrollbar-track {
  background: transparent;
}

.nav::-webkit-scrollbar-thumb {
  background: rgba(215, 237, 231, 0.28);
  border-radius: 999px;
}

.nav button {
  background: transparent;
  color: #d7dee1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  padding: 0 12px;
}

.nav button.active,
.nav button:hover {
  background: #273438;
  color: white;
}

.nav-status-badge {
  border-radius: 999px;
  background: rgba(183, 121, 31, 0.22);
  color: #f6d08d;
  flex: 0 0 auto;
  font-size: 11px;
  line-height: 1;
  padding: 4px 7px;
}

.nav button[data-job-status="done"] .nav-status-badge {
  background: rgba(22, 128, 60, 0.24);
  color: #9ee0b5;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  color: #b6c1c5;
  font-size: 13px;
}

.connection-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icp-beian {
  color: #98a7ac;
  text-decoration: none;
  font-size: 12px;
  line-height: 1.35;
}

.icp-beian:hover {
  color: #d7ede7;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warn);
}

.dot.ok {
  background: var(--ok);
}

.content {
  padding: 28px;
  min-width: 0;
}

.topbar,
.section-head,
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.viewpoint-ledger-card {
  margin-bottom: 16px;
}

.viewpoint-stat-grid small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.topbar {
  margin-bottom: 22px;
}

.topbar h2,
.section-head h3,
.panel-head h3 {
  margin: 0;
}

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

.top-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.top-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: #e7ecef;
  padding: 0 10px;
}

.eyebrow {
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.08em;
}

.actions,
.inline-actions,
.path-row,
.run-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

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

.metric {
  padding: 18px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.run-strip {
  margin: 16px 0 20px;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.action-panel,
.status-panel {
  margin-bottom: 16px;
}

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

.action-grid h4 {
  margin: 0 0 10px;
  font-size: 15px;
}

.action-item {
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  background: #f7f9fa;
  padding: 11px;
  margin-bottom: 8px;
}

.action-item.buy {
  border-left-color: var(--ok);
}

.action-item.risk {
  border-left-color: var(--danger);
}

.action-item.watch {
  border-left-color: var(--warn);
}

.action-item.downgraded {
  background: #fff8e6;
}

.action-subtext {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.action-item.market {
  border-left-color: var(--warn);
}

.realtime-compact {
  border-left: 4px solid var(--muted);
}

.realtime-compact.green {
  border-left-color: var(--ok);
}

.realtime-compact.yellow {
  border-left-color: var(--warn);
}

.realtime-compact.red {
  border-left-color: var(--danger);
}

.action-item strong,
.action-item span {
  display: block;
}

.action-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.action-item p {
  margin: 8px 0 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.freshness-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.freshness-grid div {
  background: #f7f9fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

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

.freshness-grid strong {
  display: block;
  margin-top: 5px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.split {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 16px;
}

.compact-split {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 14px;
}

.panel,
.theme-card,
.job {
  padding: 18px;
}

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

.theme-list,
.compact-list,
.job-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

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

.theme-card h4 {
  margin: 0;
  font-size: 19px;
}

.raw-text-block {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #f8fbfc;
}

.media-summary-block {
  margin-top: 12px;
  border: 1px solid #d7e7dd;
  border-radius: 8px;
  padding: 10px 12px;
  background: #f7fbf8;
}

.media-summary-block strong {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  color: #256f45;
}

.media-summary-block p {
  margin: 0;
  line-height: 1.6;
  color: var(--text);
}

.media-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.media-chip {
  border: 1px solid #c9dfd1;
  border-radius: 999px;
  padding: 3px 8px;
  background: #fff;
  color: #256f45;
  font-size: 12px;
}

.raw-text-block strong {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
  color: var(--accent);
}

.raw-text-block pre {
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  font-family: inherit;
  color: var(--text);
  line-height: 1.6;
}

.economist-chat-card {
  align-content: start;
}

.persona-question {
  margin-top: 10px;
}

.persona-answer pre {
  max-height: 360px;
}

.persona-memory-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 10px;
}

.persona-memory-summary span {
  border: 1px solid #d7e7dd;
  border-radius: 999px;
  background: #ffffff;
  color: var(--accent);
  font-size: 12px;
  padding: 3px 8px;
}

.persona-thesis {
  margin: 8px 0 12px;
  color: var(--text);
  line-height: 1.65;
}

.persona-memory-sections {
  margin-top: 10px;
}

.persona-memory-sections h4 {
  font-size: 15px;
}

.expert-card .call-list li span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.compact-table {
  margin-top: 16px;
}

.forecast-box {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent-2);
  border-radius: 8px;
  background: #fffaf2;
  padding: 10px 12px;
  margin: 12px 0;
}

.forecast-box strong {
  color: var(--accent-2);
}

.forecast-box span {
  color: var(--text);
  line-height: 1.45;
}

.deep-research-box {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #f7fbfa;
  padding: 12px;
  margin: 12px 0;
}

.deep-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.deep-research-box p {
  margin: 0;
  line-height: 1.55;
  color: var(--text);
}

.deep-research-box b,
.deep-research-box strong {
  color: var(--accent);
}

.muted-box {
  border-left-color: var(--line);
  background: #f7f9fa;
  color: var(--muted);
}

.muted-box span {
  line-height: 1.45;
}

.research-split {
  margin-top: 4px;
}

.heat {
  font-size: 28px;
  font-weight: 800;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  min-height: 26px;
  padding: 0 10px;
  background: #e7ecef;
  color: var(--text);
  font-size: 13px;
}

.badge.green {
  background: #dff3e5;
  color: #126534;
}

.badge.yellow {
  background: #fff3cf;
  color: #805400;
}

.badge.red {
  background: #fde2df;
  color: #9a251b;
}

.shadow-badge {
  border-radius: 8px;
  line-height: 1.35;
  max-width: 220px;
  min-height: 0;
  padding: 6px 8px;
  white-space: normal;
}

.sample-card,
.sample-row {
  background: #f3fbf6;
}

.mini-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.mini-metrics.five {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.mini-metrics.six {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.mini-metrics div,
.compact-item {
  background: #f7f9fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.mini-metrics span,
.compact-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.mini-metrics strong {
  display: block;
  margin-top: 4px;
}

.portfolio-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 16px;
}

.portfolio-hero h3 {
  margin: 4px 0 8px;
  font-size: 24px;
}

.portfolio-score {
  min-width: 140px;
  text-align: right;
}

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

.portfolio-score strong {
  display: block;
  margin-top: 5px;
  font-size: 32px;
}

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

.portfolio-metrics article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
}

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

.portfolio-metrics strong {
  display: block;
  margin: 6px 0 4px;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.exposure-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.exposure-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fa;
  padding: 12px;
}

.exposure-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.exposure-title strong,
.exposure-title span {
  display: block;
}

.exposure-title span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.exposure-track {
  height: 10px;
  border-radius: 999px;
  background: #e3eaec;
  margin: 10px 0;
  overflow: hidden;
}

.exposure-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.exposure-row p {
  margin: 0;
  color: var(--text);
  line-height: 1.45;
}

.version-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.version-item {
  background: #f7f9fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

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

.version-item strong,
.version-item a {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.version-note {
  grid-column: 1 / -1;
}

.display-only-item {
  background: #eef8f4;
  border-color: rgba(15, 95, 84, 0.26);
  grid-column: 1 / -1;
}

.display-only-mode [data-run],
.display-only-mode [data-open-path],
.display-only-mode #addWatchRow,
.display-only-mode #saveWatchlist,
.display-only-mode #addThemeRow,
.display-only-mode #saveThemeWatchlist,
.display-only-mode #saveConfig {
  filter: saturate(0.65);
}

.names {
  color: var(--muted);
  line-height: 1.55;
}

.reflection-summary {
  margin: 14px 0 10px;
  color: var(--text);
  font-size: 18px;
  line-height: 1.75;
}

.watch-points {
  margin: 10px 0;
  padding-left: 18px;
  color: var(--text);
  line-height: 1.55;
}

.stack-gap {
  margin-top: 16px;
}

.mini-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.mini-card {
  background: #f7f9fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

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

.mini-card strong {
  overflow-wrap: anywhere;
}

.section-head {
  margin-bottom: 14px;
}

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

.pool-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.search-field input {
  width: min(260px, 52vw);
}

.pool-stats {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

button.active-filter {
  background: #d7ede7;
  color: #0f5f54;
  border-color: #9fcfc3;
}

.market-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  margin: 10px 0 12px;
}

.market-chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 9px 10px;
}

.market-chip strong,
.market-chip span {
  display: block;
}

.market-chip strong {
  font-size: 13px;
}

.market-chip span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.market-us {
  border-color: #9eb7e8;
  background: #eef4ff;
}

.market-hk {
  border-color: #ddbb78;
  background: #fff8e9;
}

.managed-table {
  max-height: calc(100vh - 260px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.managed-table table {
  min-width: 920px;
}

.managed-table th {
  position: sticky;
  top: 0;
  z-index: 2;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #f7f9fa;
}

td {
  font-size: 14px;
}

td.reason {
  max-width: 380px;
  line-height: 1.5;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.settings-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.settings-grid .toggle {
  grid-column: span 2;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle input {
  width: auto;
}

.path-row {
  margin-top: 14px;
}

.job pre {
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  background: #11181b;
  color: #e6eef0;
  border-radius: 8px;
  padding: 12px;
  line-height: 1.5;
}

.wide-card {
  margin-bottom: 16px;
}

.flat-table {
  margin-top: 12px;
  box-shadow: none;
}

.flat-table table {
  min-width: 620px;
}

.job-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  background: #182124;
  color: white;
  border-radius: 8px;
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 160ms ease;
}

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

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    gap: 16px;
    padding: 18px;
    overflow: visible;
  }

  .nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }

  .nav button {
    flex: 0 0 auto;
    min-height: 36px;
    background: #273438;
    border: 1px solid rgba(255, 255, 255, 0.08);
    text-align: center;
  }

  .nav button.active {
    background: #d7ede7;
    color: #0f5f54;
  }

  .sidebar-footer {
    margin-top: 0;
    align-items: center;
  }

  .metric-grid,
  .action-grid,
  .theme-grid,
  .split,
  .settings-grid,
  .portfolio-metrics {
    grid-template-columns: 1fr;
  }

  .portfolio-hero {
    flex-direction: column;
  }

  .portfolio-score {
    text-align: left;
  }

  .pool-stats {
    width: 100%;
    margin-left: 0;
  }

  .managed-table {
    max-height: none;
  }

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

@media (max-width: 620px) {
  .content {
    padding: 18px;
  }

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

  .actions,
  .inline-actions {
    width: 100%;
  }

  .actions button,
  .inline-actions button,
  .run-strip button {
    flex: 1 1 160px;
  }

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