:root {
  color-scheme: light;
  --bg: #faf9f5;
  --surface: #ffffff;
  --line: #e5e2d9;
  --ink: #2c2c2a;
  --secondary: #6b6a63;
  --muted: #b4b2a9;
  --accent: #d97757;
  --accent-text: #4a1b0c;
  --soft: #f1efe8;
  --strong-bg: #e1f5ee;
  --strong-text: #085041;
  --strong-line: #0f6e56;
  --hold-bg: #eaf3de;
  --hold-text: #27500a;
  --hold-line: #3b6d11;
  --watch-bg: #f1efe8;
  --watch-text: #444441;
  --watch-line: #5f5e5a;
  --reduce-bg: #faeeda;
  --reduce-text: #633806;
  --reduce-line: #854f0b;
  --exit-bg: #fcebeb;
  --exit-text: #791f1f;
  --exit-line: #a32d2d;
  --power-bg: #e6f1fb;
  --power-text: #0c447c;
  --grid-bg: #eaf3de;
  --grid-text: #27500a;
  --data-bg: #eeedfe;
  --data-text: #3c3489;
  --thermal-bg: #faece7;
  --thermal-text: #712b13;
  --ai-bg: #e1f5ee;
  --ai-text: #085041;
  --etf-bg: #f1efe8;
  --etf-text: #444441;
}

* {
  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;
}

.dashboard-shell {
  min-height: 100vh;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 18px;
  border-bottom: 0.5px solid var(--line);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand-logo {
  display: block;
  width: 111px;
  height: 55px;
  border-radius: 10px;
  object-fit: cover;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--secondary);
  font-size: 13px;
  font-weight: 500;
}

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

h1 {
  color: var(--ink);
  font-size: 30px;
  font-weight: 520;
  letter-spacing: 0;
}

h2 {
  color: var(--ink);
  font-size: 17px;
  font-weight: 540;
}

h3 {
  color: var(--ink);
  font-size: 15px;
  font-weight: 540;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--secondary);
  font-size: 13px;
}

.status-strip span {
  border: 0.5px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 7px 10px;
}

.refresh-button {
  min-height: 32px;
  border: 0.5px solid var(--accent);
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 540;
  cursor: pointer;
}

.refresh-button:hover {
  filter: brightness(0.98);
}

.refresh-button[data-state="loading"] {
  cursor: wait;
  opacity: 0.76;
}

.refresh-button[data-state="success"],
.refresh-button[data-state="copied"] {
  background: var(--strong-bg);
  border-color: var(--strong-line);
  color: var(--strong-text);
}

main {
  display: grid;
  gap: 18px;
  padding-top: 18px;
}

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

.metrics-grid article,
.panel,
.positions-section {
  background: var(--surface);
  border: 0.5px solid var(--line);
  border-radius: 24px;
  box-shadow: none;
}

.metrics-grid article {
  min-height: 104px;
  border-radius: 20px;
  padding: 18px;
}

.metrics-grid span {
  display: block;
  color: var(--secondary);
  font-size: 13px;
  margin-bottom: 8px;
}

.metrics-grid strong {
  color: var(--ink);
  font-size: 22px;
  font-weight: 540;
}

.history-section,
.workflow-section,
.rulebook-section,
.engineering-section,
.rotation-section,
.alternatives-section,
.cluster-section {
  display: grid;
  gap: 12px;
}

.workflow-panel {
  border-radius: 24px;
}

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

.workflow-item {
  display: grid;
  gap: 5px;
  min-height: 92px;
  align-content: start;
  border: 0.5px solid var(--line);
  border-radius: 20px;
  background: var(--bg);
  padding: 12px;
}

.workflow-item span {
  color: var(--secondary);
  font-size: 12px;
}

.workflow-item strong {
  color: var(--ink);
  font-size: 15px;
  font-weight: 540;
  overflow-wrap: anywhere;
}

.workflow-item small {
  color: var(--secondary);
  font-size: 12px;
  line-height: 1.35;
}

.rulebook-panel {
  border-radius: 24px;
}

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

.rulebook-item {
  display: grid;
  gap: 5px;
  min-height: 118px;
  align-content: start;
  border: 0.5px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  padding: 12px;
}

.rulebook-item span {
  color: var(--secondary);
  font-size: 12px;
}

.rulebook-item strong {
  color: var(--ink);
  font-size: 14px;
  font-weight: 540;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.rulebook-item small {
  color: var(--secondary);
  font-size: 12px;
  line-height: 1.35;
}

.engineering-panel {
  border-radius: 24px;
}

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

.engineering-item {
  display: grid;
  gap: 5px;
  min-height: 104px;
  align-content: start;
  border: 0.5px solid var(--line);
  border-radius: 20px;
  background: var(--bg);
  padding: 12px;
}

.engineering-item span {
  color: var(--secondary);
  font-size: 12px;
}

.engineering-item strong {
  color: var(--ink);
  font-size: 15px;
  font-weight: 540;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.engineering-item small {
  color: var(--secondary);
  font-size: 12px;
  line-height: 1.35;
}

.history-panel {
  min-height: 250px;
  border-radius: 24px;
}

.history-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: 16px;
  align-items: stretch;
}

.chart-wrap {
  display: grid;
  gap: 8px;
  min-width: 0;
}

#weeklyChart {
  width: 100%;
  height: 170px;
  border: 0.5px solid var(--line);
  border-radius: 20px;
  background: var(--bg);
  overflow: visible;
}

.chart-line {
  fill: none;
  stroke: var(--power-text);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-area {
  fill: rgba(12, 68, 124, 0.08);
}

.chart-point {
  fill: var(--surface);
  stroke: var(--power-text);
  stroke-width: 1.1;
}

.chart-point.proxy {
  stroke: var(--reduce-line);
  stroke-dasharray: 2 1;
}

.chart-axis {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--secondary);
  font-size: 12px;
}

.history-stats {
  display: grid;
  gap: 10px;
}

.history-stats div,
.profile-item,
.action {
  border: 0.5px solid var(--line);
  border-radius: 20px;
  background: var(--bg);
}

.history-stats div {
  padding: 12px;
}

.history-stats span,
.profile-item span {
  display: block;
  color: var(--secondary);
  font-size: 12px;
  margin-bottom: 5px;
}

.history-stats strong,
.profile-item strong {
  color: var(--ink);
  font-weight: 540;
  font-variant-numeric: tabular-nums;
}

.history-stats strong {
  font-size: 17px;
}

.work-grid,
.advisor-section {
  display: grid;
  gap: 14px;
}

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

.advisor-section {
  grid-template-columns: 0.9fr 1.1fr;
}

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

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

.section-badge {
  border-radius: 999px;
  background: var(--surface);
  border: 0.5px solid var(--line);
  color: var(--secondary);
  padding: 6px 10px;
  font-size: 13px;
}

.panel {
  padding: 16px;
}

.data-error {
  display: grid;
  gap: 8px;
}

.data-error p {
  color: var(--secondary);
  font-size: 14px;
}

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

.panel-head > span {
  min-width: 28px;
  border-radius: 999px;
  background: var(--watch-bg);
  border: 0.5px solid var(--line);
  padding: 4px 9px;
  text-align: center;
  color: var(--secondary);
  font-weight: 540;
}

.action-list {
  display: grid;
  gap: 9px;
}

.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.profile-item {
  padding: 10px;
}

.profile-item strong {
  font-size: 14px;
}

.action {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 10px;
  padding: 11px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-top: 4px;
}

.dot.red {
  background: var(--exit-line);
}

.dot.amber {
  background: var(--reduce-line);
}

.dot.green {
  background: var(--strong-line);
}

.action strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
  font-weight: 540;
}

.action span {
  display: block;
  margin-top: 3px;
  color: var(--secondary);
  font-size: 13px;
}

.segmented {
  display: flex;
  gap: 4px;
  border: 0.5px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 4px;
}

.segmented button {
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--secondary);
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.segmented button.active {
  background: var(--ink);
  color: var(--surface);
}

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

.cluster-card {
  background: var(--surface);
  border: 0.5px solid var(--line);
  border-radius: 20px;
  padding: 14px;
}

.cluster-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.cluster-meta {
  color: var(--secondary);
  font-size: 13px;
}

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--watch-bg);
  overflow: hidden;
  margin: 10px 0 12px;
}

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

.ticker-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ticker-row span,
.score-pill,
.measure-pill,
.cluster-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 540;
  line-height: 1.2;
}

.ticker-row span:not(.cluster-pill) {
  background: var(--watch-bg);
  color: var(--watch-text);
}

.score-strong {
  background: var(--strong-bg);
  color: var(--strong-text);
}

.score-hold {
  background: var(--hold-bg);
  color: var(--hold-text);
}

.score-watch {
  background: var(--watch-bg);
  color: var(--watch-text);
}

.score-reduce {
  background: var(--reduce-bg);
  color: var(--reduce-text);
}

.score-exit {
  background: var(--exit-bg);
  color: var(--exit-text);
}

.measure-pill {
  background: var(--watch-bg);
  color: var(--watch-text);
}

.measure-pill.action-needed {
  background: var(--accent);
  color: var(--accent-text);
}

.cluster-power-semi {
  background: var(--power-bg);
  color: var(--power-text);
}

.cluster-grid-auto {
  background: var(--grid-bg);
  color: var(--grid-text);
}

.cluster-data-ctr {
  background: var(--data-bg);
  color: var(--data-text);
}

.cluster-thermal {
  background: var(--thermal-bg);
  color: var(--thermal-text);
}

.cluster-ai-layer {
  background: var(--ai-bg);
  color: var(--ai-text);
}

.cluster-etf-rohst {
  background: var(--etf-bg);
  color: var(--etf-text);
}

.positions-section {
  padding: 16px;
  border-radius: 24px;
}

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

.search-box input {
  width: 220px;
  max-width: 48vw;
  border: 0.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 10px;
  font: inherit;
}

.search-box input::placeholder {
  color: var(--muted);
}

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

.positions-cards {
  display: none;
}

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

th,
td {
  border-bottom: 0.5px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  color: var(--secondary);
  font-weight: 540;
}

td.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.subtle {
  color: var(--secondary);
  font-size: 12px;
}

.positive {
  color: var(--strong-line);
}

.negative {
  color: var(--exit-line);
}

@media (max-width: 980px) {
  .metrics-grid,
  .workflow-grid,
  .rulebook-grid,
  .engineering-grid,
  .history-layout,
  .work-grid,
  .advisor-section,
  .rotation-grid,
  .alternatives-list,
  .cluster-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 680px) {
  .dashboard-shell {
    padding: 16px;
  }

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

  .brand-lockup {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .brand-logo {
    width: 101px;
    height: 50px;
  }

  .metrics-grid,
  .workflow-grid,
  .rulebook-grid,
  .engineering-grid,
  .history-layout,
  .work-grid,
  .advisor-section,
  .rotation-grid,
  .alternatives-list,
  .cluster-grid {
    grid-template-columns: 1fr;
  }

  .segmented {
    width: 100%;
    overflow-x: auto;
  }

  .search-box {
    width: 100%;
    align-items: flex-start;
    flex-direction: column;
  }

  .search-box input {
    width: 100%;
    max-width: none;
  }

  .table-wrap {
    display: none;
  }

  .positions-cards {
    display: grid;
    gap: 10px;
  }

  .position-card {
    display: grid;
    gap: 12px;
    border: 0.5px solid var(--line);
    border-radius: 20px;
    background: var(--surface);
    padding: 14px;
  }

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

  .position-card-top div {
    display: grid;
    min-width: 0;
    gap: 3px;
  }

  .position-card-top strong {
    color: var(--ink);
    font-size: 16px;
    font-weight: 540;
  }

  .position-card-top span:not(.score-pill) {
    color: var(--secondary);
    font-size: 13px;
    line-height: 1.3;
    overflow-wrap: anywhere;
  }

  .position-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .position-card-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .position-card-grid div {
    display: grid;
    gap: 4px;
    min-height: 58px;
    border: 0.5px solid var(--line);
    border-radius: 16px;
    background: var(--bg);
    padding: 10px;
  }

  .position-card-grid span {
    color: var(--secondary);
    font-size: 12px;
  }

  .position-card-grid strong {
    color: var(--ink);
    font-size: 14px;
    font-weight: 540;
    font-variant-numeric: tabular-nums;
  }

  .position-card-grid strong.positive {
    color: var(--strong-line);
  }

  .position-card-grid strong.negative {
    color: var(--exit-line);
  }

  .position-card p {
    color: var(--secondary);
    font-size: 13px;
    line-height: 1.4;
    overflow-wrap: anywhere;
  }
}
