:root {
  --ink: #17211f;
  --muted: #66736f;
  --soft: #8a9692;
  --line: #d8dfdc;
  --line-strong: #bec9c5;
  --paper: #ffffff;
  --canvas: #f3f6f4;
  --header: #17332f;
  --teal: #168477;
  --teal-soft: #dcefeb;
  --blue: #4d73bd;
  --purple: #7258a5;
  --orange: #cc7a26;
  --red: #b54e4a;
  --cash: #7e8985;
  --shadow: 0 1px 2px rgba(20, 34, 31, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  color: inherit;
}

.topbar {
  min-height: 64px;
  padding: 10px 24px;
  background: var(--header);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid #0e2723;
}

.brand-block,
.topbar-actions,
.rail-header,
.experiment-title-row,
.metric-line,
.decision-meta,
.section-heading,
.source-name {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 11px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border: 2px solid #86d5c9;
  border-radius: 4px;
  position: relative;
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  background: #f2b35f;
}

.brand-mark::before {
  width: 3px;
  height: 15px;
  left: 6px;
  bottom: 4px;
}

.brand-mark::after {
  width: 3px;
  height: 9px;
  right: 6px;
  bottom: 4px;
}

.brand-name {
  font-size: 15px;
  font-weight: 700;
}

.brand-section {
  color: #a9c5bf;
  font-size: 11px;
  text-transform: uppercase;
}

.topbar-actions {
  gap: 14px;
}

.sync-label {
  color: #b9cac6;
  font-size: 12px;
  white-space: nowrap;
}

.auto-refresh {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #d7e2df;
  font-size: 12px;
  cursor: pointer;
}

.auto-refresh input {
  accent-color: #62b9ac;
}

.command-button {
  min-height: 34px;
  padding: 6px 13px;
  color: white;
  background: transparent;
  border: 1px solid #6f8d87;
  border-radius: 4px;
  cursor: pointer;
}

.command-button:hover,
.command-button:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  border-color: #a7c4be;
}

.metric-label,
.eyebrow,
.table-note,
.event-time,
.tool-meta {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.metric-value {
  margin-top: 4px;
  font-size: 22px;
  font-weight: 680;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

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

.positive {
  color: var(--teal);
}

.negative {
  color: var(--red);
}

.workspace {
  min-height: calc(100vh - 64px);
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
}

.experiment-rail {
  min-width: 0;
  padding: 18px 14px;
  background: #eef2f0;
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.rail-header {
  justify-content: space-between;
  padding: 0 6px 12px;
}

.rail-header h1 {
  margin: 0;
  font-size: 15px;
}

.count-label {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.segmented-control {
  height: 32px;
  margin: 0 4px 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  overflow: hidden;
}

.source-control {
  margin-top: -8px;
}

.segmented-control button,
.detail-tabs button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.segmented-control button {
  color: var(--muted);
  border-right: 1px solid var(--line-strong);
  font-size: 12px;
}

.segmented-control button:last-child {
  border-right: 0;
}

.segmented-control button.active {
  color: var(--ink);
  background: white;
  font-weight: 650;
}

.experiment-list {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.experiment-item {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 76px;
  padding: 10px 11px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}

.experiment-item:hover {
  background: rgba(255, 255, 255, 0.58);
  border-color: var(--line);
}

.experiment-item.selected {
  background: white;
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

.experiment-title-row {
  width: 100%;
  min-width: 0;
  align-items: flex-start;
  gap: 8px;
}

.health-dot {
  width: 8px;
  height: 8px;
  margin-top: 5px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--teal);
}

.health-dot.active {
  background: var(--orange);
  box-shadow: 0 0 0 3px rgba(204, 122, 38, 0.15);
}

.health-dot.error {
  background: var(--red);
}

.experiment-name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 650;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.experiment-subline,
.experiment-result {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
}

.experiment-subline > :first-child,
.experiment-result > :first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.experiment-subline {
  margin: 7px 0 4px 16px;
  color: var(--muted);
}

.experiment-result {
  margin-left: 16px;
  font-variant-numeric: tabular-nums;
}

.detail-surface {
  min-width: 0;
  background: var(--paper);
}

.state-message {
  min-height: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
}

#loading-state::before {
  content: "";
  width: 20px;
  height: 20px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: loading-spin 0.75s linear infinite;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.error-message {
  color: var(--red);
}

.experiment-header {
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--line);
}

.experiment-header h2 {
  margin: 3px 0 5px;
  font-size: 24px;
  line-height: 1.2;
}

.header-meta {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 7px 15px;
  font-size: 12px;
}

.header-kpis {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(5, minmax(100px, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.header-kpi {
  padding: 12px 14px;
  border-right: 1px solid var(--line);
}

.header-kpi:first-child {
  padding-left: 0;
}

.header-kpi:last-child {
  border-right: 0;
}

.header-kpi strong {
  display: block;
  margin-top: 3px;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.detail-tabs {
  height: 48px;
  padding: 0 28px;
  display: flex;
  align-items: stretch;
  gap: 28px;
  border-bottom: 1px solid var(--line);
}

.detail-tabs button {
  position: relative;
  color: var(--muted);
  font-size: 13px;
}

.detail-tabs button.active {
  color: var(--ink);
  font-weight: 680;
}

.detail-tabs button.active::after {
  content: "";
  height: 3px;
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  background: var(--teal);
}

.tab-content {
  padding: 24px 28px 48px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr);
  gap: 30px;
}

.content-grid > * {
  min-width: 0;
}

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

.section-heading {
  min-height: 28px;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-heading h3 {
  margin: 0;
  font-size: 15px;
}

.chart-toolbar {
  min-height: 36px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 10px;
}

.chart-toolbar h3 {
  margin: 0 0 3px;
  font-size: 15px;
}

.view-switch {
  display: inline-grid;
  grid-template-columns: repeat(3, auto);
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  overflow: hidden;
}

.view-switch button {
  min-height: 30px;
  padding: 0 11px;
  border-right: 1px solid var(--line-strong);
  color: var(--muted);
  background: #f7f9f8;
  font-size: 12px;
  white-space: nowrap;
}

.view-switch button:last-child {
  border-right: 0;
}

.view-switch button:hover {
  color: var(--ink);
  background: #edf3f1;
}

.view-switch button.active {
  color: white;
  background: #1d5f56;
  font-weight: 700;
}

.chart-legend {
  min-height: 25px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 0 2px 8px;
  color: var(--muted);
  font-size: 11px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.chart-legend i {
  width: 16px;
  height: 3px;
  display: inline-block;
  border-radius: 1px;
}

.chart-frame {
  width: 100%;
  height: 310px;
  position: relative;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.line-chart {
  width: 100%;
  height: 100%;
  display: block;
}

.interactive-chart {
  cursor: col-resize;
  outline: none;
  touch-action: none;
  user-select: none;
}

.interactive-chart:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(22, 132, 119, 0.42);
}

.chart-grid {
  stroke: #e5eae8;
  stroke-width: 1;
}

.chart-axis-label {
  fill: #798480;
  font-size: 11px;
  font-family: inherit;
}

.chart-line,
.series-line,
.asset-price-line {
  fill: none;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.chart-line,
.series-line.agent {
  stroke: var(--teal);
  stroke-width: 2.6;
}

.series-line.equal-weight {
  stroke: #4d73bd;
}

.series-line.buy-hold {
  stroke: #cc7a26;
}

.chart-area {
  fill: rgba(22, 132, 119, 0.08);
}

.allocation-area {
  opacity: 0.88;
  stroke: rgba(255, 255, 255, 0.72);
  stroke-width: 0.7;
  vector-effect: non-scaling-stroke;
}

.index-base {
  stroke: #86918e;
  stroke-width: 1;
  stroke-dasharray: 3 4;
  vector-effect: non-scaling-stroke;
}

.chart-point {
  fill: var(--teal);
}

.chart-cursor-line {
  stroke: #344743;
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.chart-cursor-line.light {
  stroke: white;
  stroke-width: 2;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.75));
}

.chart-cursor-point {
  fill: white;
  stroke: #233d38;
  stroke-width: 2.5;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.chart-cursor-label {
  pointer-events: none;
}

.chart-cursor-label rect {
  fill: #263d38;
  stroke: white;
  stroke-width: 1;
}

.chart-cursor-label text {
  fill: white;
  font-family: inherit;
  font-size: 11px;
}

#chart-cursor-primary {
  fill: #b9dcd5;
  font-weight: 700;
}

.chart-note {
  min-height: 16px;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.empty-chart,
.empty-section {
  min-height: 180px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.allocation-list {
  border-top: 1px solid var(--line);
}

.allocation-row {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr) 58px;
  align-items: center;
  gap: 10px;
  min-height: 37px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.allocation-bar {
  height: 8px;
  background: #e5eae8;
  border-radius: 2px;
  overflow: hidden;
}

.allocation-fill {
  height: 100%;
  min-width: 2px;
  background: var(--blue);
}

.allocation-row.cash .allocation-fill {
  background: var(--cash);
}

.allocation-value {
  text-align: right;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  border-top: 1px solid var(--line-strong);
}

.table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}

.table-scroll .data-table {
  min-width: 470px;
}

.data-table th,
.data-table td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.data-table th:first-child,
.data-table td:first-child {
  padding-left: 0;
}

.data-table th:last-child,
.data-table td:last-child {
  padding-right: 0;
  text-align: right;
}

.number {
  font-variant-numeric: tabular-nums;
  text-align: right !important;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 2px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  color: var(--muted);
  background: #fafcfb;
  font-size: 11px;
}

.badge.buy,
.badge.trade {
  color: #0d665c;
  border-color: #a9d7d0;
  background: #eef9f7;
}

.badge.sell,
.badge.error {
  color: #943c39;
  border-color: #e2b6b4;
  background: #fff3f2;
}

.badge.hold,
.badge.no_trade {
  color: #6f5a26;
  border-color: #ded0a9;
  background: #fff9e9;
}

.timeline {
  border-top: 1px solid var(--line-strong);
}

.timeline-item {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.decision-meta {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.decision-date {
  font-weight: 680;
}

.decision-summary,
.plan-content {
  margin: 10px 0 0;
  max-width: 980px;
  color: #33413e;
  line-height: 1.55;
}

.decision-stats {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

details {
  margin-top: 12px;
}

summary {
  color: var(--teal);
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

.tool-list {
  margin-top: 10px;
  border-top: 1px solid var(--line);
}

.tool-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.tool-name {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  font-weight: 700;
}

.tool-observation,
.event-payload {
  margin-top: 6px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
}

.strategy-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr);
  gap: 30px;
}

.plan-scope {
  color: var(--purple);
  font-size: 12px;
  font-weight: 680;
}

.source-list,
.event-list {
  border-top: 1px solid var(--line-strong);
}

.source-row {
  min-height: 54px;
  padding: 9px 0;
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 80px minmax(180px, 2fr);
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.source-name {
  gap: 8px;
  font-weight: 650;
}

.source-error {
  color: var(--red);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-row {
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.event-name {
  margin-top: 3px;
  font-weight: 650;
}

.status-block {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 28px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.status-cell {
  min-height: 76px;
  padding: 12px;
  border-right: 1px solid var(--line);
}

.status-cell:last-child {
  border-right: 0;
}

.status-cell strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

@media (max-width: 1050px) {
  .workspace {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .content-grid,
  .strategy-grid {
    grid-template-columns: 1fr;
  }

  .header-kpis {
    grid-template-columns: repeat(3, 1fr);
  }

  .header-kpi:nth-child(3) {
    border-right: 0;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    padding: 12px 16px;
  }

  .topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .sync-label {
    width: 100%;
    text-align: right;
  }

  .workspace {
    display: block;
  }

  .experiment-rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .experiment-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .experiment-item {
    min-width: 240px;
  }

  .experiment-header,
  .tab-content {
    padding-right: 16px;
    padding-left: 16px;
  }

  .detail-tabs {
    padding: 0 16px;
    gap: 20px;
    overflow-x: auto;
  }

  .chart-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .view-switch {
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .view-switch button {
    padding: 0 6px;
  }

  .header-kpis {
    grid-template-columns: repeat(2, 1fr);
  }

  .header-kpi:nth-child(3) {
    border-right: 1px solid var(--line);
  }

  .header-kpi:nth-child(even) {
    border-right: 0;
  }

  .source-row {
    grid-template-columns: 1fr auto;
  }

  .source-error {
    grid-column: 1 / -1;
  }

  .status-block {
    grid-template-columns: 1fr;
  }

  .status-cell {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .status-cell:last-child {
    border-bottom: 0;
  }
}
