:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef4f3;
  --surface-strong: #13211f;
  --text: #15201e;
  --muted: #687672;
  --subtle: #8b9793;
  --border: #dce5e2;
  --border-strong: #c6d2ce;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #dff3ef;
  --green: #12805c;
  --amber: #b7791f;
  --red: #c2413a;
  --blue: #2f6f9f;
  --shadow: 0 18px 45px rgba(16, 33, 30, 0.09);
  --radius: 8px;
  --sidebar: 248px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

section,
article {
  scroll-margin-top: 86px;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(223, 243, 239, 0.55) 0, rgba(245, 247, 248, 0) 360px),
    var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  display: block;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 24px 18px;
  background: #ffffff;
  border-right: 1px solid var(--border);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  color: white;
  background: var(--surface-strong);
}

.brand-mark svg {
  width: 22px;
  height: 22px;
}

.brand-mark path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 16px;
  line-height: 1.2;
}

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 8px;
  color: #43504d;
  text-decoration: none;
  font-size: 14px;
  font-weight: 650;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-item:hover,
.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.nav-item:hover {
  transform: translateX(2px);
}

.nav-icon,
[data-icon] {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.nav-icon svg,
[data-icon] svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.sidebar-note {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 14px;
  border-radius: var(--radius);
  background: #f3f6f5;
  border: 1px solid var(--border);
}

.sidebar-note span,
.sidebar-note small {
  color: var(--muted);
  font-size: 12px;
}

.sidebar-note strong {
  font-size: 14px;
  line-height: 1.45;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: -20px -24px 18px;
  padding: 16px 24px;
  background: rgba(245, 247, 248, 0.86);
  border-bottom: 1px solid rgba(220, 229, 226, 0.78);
  backdrop-filter: blur(18px);
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 9px;
  width: min(580px, 100%);
  padding: 8px 8px 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(27, 45, 42, 0.05);
}

.top-icon {
  color: var(--muted);
}

.search-wrap input {
  min-width: 88px;
  flex: 1;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 14px;
  font-weight: 750;
  text-transform: uppercase;
}

.market-state {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 190px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

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

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

.market-state span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.pulse {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 6px rgba(18, 128, 92, 0.12);
}

.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 18px;
}

.hero-row h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.18;
  letter-spacing: 0;
}

.hero-row p {
  max-width: 680px;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
}

.quick-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 750;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.primary-button {
  padding: 0 14px;
  color: #ffffff;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.secondary-button,
.ghost-button {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}

.secondary-button {
  padding: 0 13px;
}

.ghost-button {
  min-height: 32px;
  padding: 0 10px;
  color: var(--accent-strong);
}

.secondary-button:hover,
.ghost-button:hover,
.icon-button:hover {
  border-color: var(--border-strong);
  background: #f8faf9;
  transform: translateY(-1px);
}

.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.icon-button {
  width: 36px;
  height: 36px;
  color: var(--accent-strong);
  background: var(--surface);
  border-color: var(--border);
}

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

.metric {
  min-height: 116px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 25px rgba(31, 52, 48, 0.04);
}

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

.metric span {
  font-size: 12px;
  font-weight: 750;
}

.metric strong {
  display: block;
  margin-top: 12px;
  font-size: 28px;
  line-height: 1;
}

.metric small {
  margin-top: 10px;
  font-size: 12px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.65fr);
  gap: 14px;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.market-panel,
.screener-panel,
.alerts-panel,
.automation-panel {
  grid-column: 1;
}

.ai-panel,
.risk-panel,
.macro-panel {
  grid-column: 2;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-head.compact {
  margin-bottom: 12px;
}

.section-label {
  display: block;
  margin-bottom: 5px;
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 850;
}

.panel h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.28;
  letter-spacing: 0;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: #edf2f1;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.segmented button {
  min-width: 44px;
  min-height: 30px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 800;
}

.segmented button.is-selected {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 4px 12px rgba(17, 29, 26, 0.08);
}

.ticker-strip {
  display: grid;
  grid-template-columns: 1.35fr repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.ticker-strip > div {
  min-height: 70px;
  padding: 12px;
  border-radius: 8px;
  background: #f7faf9;
  border: 1px solid var(--border);
}

.ticker-strip span,
.ticker-strip strong {
  display: block;
}

.ticker-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ticker-strip strong {
  margin-top: 8px;
  font-size: 20px;
  line-height: 1.1;
}

.chart-wrap {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(239, 247, 245, 0.42)),
    #fbfdfc;
}

#performanceChart {
  width: 100%;
  height: auto;
  aspect-ratio: 820 / 310;
  min-height: 300px;
}

.grid-line {
  stroke: #dce5e2;
  stroke-width: 1;
}

.axis-label {
  fill: #76817e;
  font-size: 11px;
  font-weight: 650;
}

.strategy-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.benchmark-line {
  fill: none;
  stroke: #9aa6a2;
  stroke-width: 2;
  stroke-dasharray: 7 7;
  stroke-linecap: round;
}

.area-fill {
  fill: url(#chartArea);
}

.chart-dot {
  fill: #ffffff;
  stroke: var(--accent);
  stroke-width: 3;
}

.backtest-controls,
.filter-bar {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

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

.filter-bar {
  grid-template-columns: 1.15fr 1fr 0.95fr 1fr;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

select,
input[type="range"] {
  width: 100%;
}

select {
  height: 36px;
  padding: 0 10px;
  color: var(--text);
  background: #fbfdfc;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: 0;
  font-size: 13px;
  font-weight: 700;
}

input[type="range"] {
  accent-color: var(--accent);
}

.range-field {
  align-content: center;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdfc;
  color: var(--text);
}

.checkbox-field input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.filter-count {
  min-width: 82px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

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

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #f7faf9;
  font-size: 11px;
  font-weight: 850;
}

td {
  font-size: 13px;
  font-weight: 650;
}

tbody tr {
  transition: background 160ms ease;
}

tbody tr:hover {
  background: #f8fbfa;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.ticker-cell {
  display: grid;
  gap: 3px;
}

.ticker-cell strong {
  font-size: 13px;
}

.ticker-cell span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.score-pill,
.signal-pill,
.risk-badge,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 850;
}

.score-pill {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.signal-pill.buy,
.status-pill.good {
  color: #0f684d;
  background: #ddf5eb;
}

.signal-pill.watch,
.status-pill.watch {
  color: #8a5a10;
  background: #fff2cf;
}

.signal-pill.reduce,
.status-pill.risk {
  color: #aa302a;
  background: #fee3e0;
}

.factor-cell {
  min-width: 72px;
}

.bar {
  position: relative;
  height: 6px;
  width: 58px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7eeeb;
}

.bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.summary-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: #f7faf9;
  border: 1px solid var(--border);
}

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

.summary-score span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.summary-score strong {
  color: var(--green);
  font-size: 15px;
}

.summary-card p {
  margin: 0;
  color: #2e3b38;
  font-size: 13px;
  line-height: 1.75;
}

.news-list,
.alert-list,
.macro-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.news-item,
.alert-item,
.macro-item {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.news-item strong,
.alert-item strong,
.macro-item strong {
  font-size: 13px;
  line-height: 1.35;
}

.news-item span,
.alert-item span,
.macro-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.risk-badge {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.allocation-chart {
  display: grid;
  gap: 9px;
}

.allocation-row {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 800;
}

.allocation-row span:first-child {
  color: var(--muted);
}

.allocation-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6eeeb;
}

.allocation-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.risk-controls {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.advice-box {
  padding: 12px;
  border-radius: 8px;
  background: #fffaf0;
  border: 1px solid #f2dfb3;
}

.advice-box span {
  color: var(--amber);
  font-size: 12px;
  font-weight: 850;
}

.advice-box p {
  margin: 6px 0 0;
  color: #4d3a15;
  font-size: 13px;
  line-height: 1.6;
}

.macro-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.macro-item span {
  grid-column: 1 / -1;
}

.macro-value {
  color: var(--text);
  font-size: 18px;
  font-weight: 850;
}

.alert-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.alert-item span {
  grid-column: 1;
}

.alert-toggle {
  position: relative;
  width: 42px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  background: #d9e2df;
}

.alert-toggle::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(18, 32, 29, 0.18);
  transition: transform 160ms ease;
}

.alert-toggle.is-on {
  background: var(--accent);
}

.alert-toggle.is-on::after {
  transform: translateX(18px);
}

.automation-flow {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.flow-step {
  min-height: 112px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fbfa;
}

.flow-step span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-bottom: 10px;
  border-radius: 999px;
  color: var(--muted);
  background: #e8efed;
  font-size: 12px;
  font-weight: 850;
}

.flow-step strong,
.flow-step small {
  display: block;
}

.flow-step strong {
  font-size: 13px;
}

.flow-step small {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.flow-step.is-complete {
  border-color: #b8ded4;
  background: #eef9f5;
}

.flow-step.is-complete span,
.flow-step.is-active span {
  color: #ffffff;
  background: var(--accent);
}

.flow-step.is-active {
  border-color: var(--accent);
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.11);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 48px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #ffffff;
  background: #13211f;
  box-shadow: 0 18px 45px rgba(15, 24, 22, 0.2);
  font-size: 13px;
  font-weight: 750;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

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

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    overflow-x: auto;
    padding: 14px 16px;
  }

  .brand {
    flex: 0 0 auto;
  }

  .nav-list {
    display: flex;
    gap: 6px;
    min-width: max-content;
  }

  .sidebar-note {
    display: none;
  }

  .main {
    padding: 18px 16px 30px;
  }

  .topbar {
    margin: -18px -16px 16px;
    padding: 14px 16px;
  }

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

  .market-panel,
  .screener-panel,
  .alerts-panel,
  .automation-panel,
  .ai-panel,
  .risk-panel,
  .macro-panel {
    grid-column: auto;
  }

  .ai-panel {
    order: 2;
  }

  .screener-panel {
    order: 3;
  }

  .risk-panel {
    order: 4;
  }
}

@media (max-width: 780px) {
  .topbar,
  .hero-row {
    align-items: stretch;
    flex-direction: column;
  }

  .market-state {
    width: 100%;
  }

  .kpi-grid,
  .ticker-strip,
  .backtest-controls,
  .filter-bar,
  .automation-flow {
    grid-template-columns: 1fr;
  }

  .hero-row h1 {
    font-size: 25px;
  }

  .quick-actions,
  .quick-actions > button {
    width: 100%;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-head .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }

  .metric {
    min-height: 100px;
  }

  #performanceChart {
    min-height: 250px;
  }
}
