:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #17201b;
  --muted: #647067;
  --line: #dfe5dc;
  --accent: #1d6f5f;
  --accent-2: #8b5e34;
  --bad: #b34040;
  --good: #16704a;
  --warn: #a46b12;
  --shadow: 0 14px 34px rgba(34, 42, 35, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background: #fbfcf8;
  padding: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: white;
  font-weight: 800;
  border-radius: 8px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 19px;
}

h2 {
  font-size: 24px;
  line-height: 1.2;
}

h3 {
  font-size: 18px;
}

.brand p,
.description,
.note-list,
.field span,
.stat span,
.metric span,
.crowding-grid span,
.eyebrow {
  color: var(--muted);
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}

select,
input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

.note-list {
  display: grid;
  gap: 10px;
  margin-top: 28px;
  font-size: 12px;
  line-height: 1.55;
}

main {
  padding: 28px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 22px;
}

.eyebrow {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  margin-bottom: 6px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 12px;
}

.best-factor strong {
  color: var(--accent);
  font-size: 15px;
}

.stat,
.metric,
.crowding-grid > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}

.stat strong,
.metric strong,
.crowding-grid strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(620px, 1.35fr) minmax(420px, 0.9fr);
  gap: 18px;
  align-items: start;
}

.table-panel,
.detail-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.detail-panel {
  padding: 18px;
}

.panel-head {
  min-height: 62px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.detail-panel .panel-head {
  padding: 0 0 16px;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 172px);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  height: 48px;
  padding: 0 14px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  background: #fbfcf8;
  color: var(--muted);
  font-weight: 600;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 0;
}

.sort-button::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  opacity: 0.35;
}

.sort-button[data-direction="desc"]::after {
  border-top: 6px solid currentColor;
}

.sort-button[data-direction="asc"]::after {
  border-bottom: 6px solid currentColor;
}

.sort-button.active {
  color: var(--accent);
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.active {
  background: #eef5f0;
}

.factor-name {
  display: grid;
  gap: 2px;
}

.factor-name strong {
  font-size: 14px;
}

.factor-name span {
  color: var(--muted);
  font-size: 11px;
}

.pill,
.risk {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #edf2ec;
  color: var(--muted);
  font-size: 12px;
}

.risk.high {
  color: var(--bad);
  background: #faece9;
}

.risk.mid {
  color: var(--warn);
  background: #f7efe0;
}

.risk.low {
  color: var(--good);
  background: #e8f3ed;
}

.description-title {
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
}

.description {
  padding: 8px 0 16px;
  line-height: 1.55;
  font-size: 13px;
  white-space: pre-line;
}

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

.metric,
.crowding-grid > div {
  padding: 10px;
}

.metric strong,
.crowding-grid strong {
  font-size: 16px;
}

.chart-block {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.chart-title {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

svg {
  display: block;
  width: 100%;
  height: auto;
}

.axis {
  stroke: var(--line);
  stroke-width: 1;
}

.line-ic {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
}

.line-ls {
  fill: none;
  stroke: var(--accent-2);
  stroke-width: 3;
}

.line-mv {
  fill: none;
  stroke: #5f668c;
  stroke-width: 3;
}

.dot-ic {
  fill: var(--accent);
}

.dot-ls {
  fill: var(--accent-2);
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: end;
  gap: 8px;
  min-height: 150px;
}

.bar-item {
  display: grid;
  align-content: end;
  gap: 6px;
  height: 150px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.bar {
  min-height: 4px;
  border-radius: 6px 6px 0 0;
  background: var(--accent);
}

.bar.neg {
  background: var(--bad);
}

.stocks-wrap {
  overflow: auto;
  max-height: 320px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stocks-table th,
.stocks-table td {
  height: 38px;
  font-size: 12px;
}

.empty-cell,
.empty-text {
  color: var(--muted);
  font-size: 12px;
}

.empty-cell {
  text-align: center;
}

.exposure-list {
  display: grid;
  gap: 8px;
}

.exposure-row {
  display: grid;
  grid-template-columns: minmax(80px, 120px) 1fr 34px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.exposure-track {
  height: 9px;
  background: #edf2ec;
  border-radius: 999px;
  overflow: hidden;
}

.exposure-track div {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

.crowding-grid {
  margin-top: 16px;
}

.pos {
  color: var(--good);
}

.neg {
  color: var(--bad);
}

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

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .layout-grid,
  .topbar {
    grid-template-columns: 1fr;
    display: grid;
  }
}

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

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

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

  th,
  td {
    padding: 0 10px;
  }
}
