:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --line: #dfe5dc;
  --text: #20251f;
  --muted: #667064;
  --green: #2f7d57;
  --amber: #9f6b16;
  --red: #b33a3a;
  --blue: #2f5f98;
  --shadow: 0 8px 24px rgba(45, 54, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: rgba(247, 248, 245, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  flex: 0 0 auto;
  font-weight: 800;
  color: var(--green);
}

.nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  white-space: nowrap;
}

.nav a {
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
}

.nav a:hover {
  background: #eaf0e7;
  color: var(--text);
}

.page {
  width: min(1060px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: center;
  padding: 28px 0 22px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 10px;
  font-size: 34px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
}

h3 {
  margin-bottom: 6px;
  font-size: 16px;
}

.hero-summary {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
}

.section {
  padding: 18px 0;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title span,
.section-title a {
  color: var(--muted);
  font-size: 14px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.signal-list,
.card-list {
  display: grid;
  gap: 12px;
}

.signal,
.row-card,
.portfolio-card,
.compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
}

.signal p,
.row-card p,
.portfolio-card p,
.compact p {
  margin-bottom: 0;
  color: var(--muted);
}

.badge {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.signal.risk {
  border-left: 4px solid var(--red);
}

.signal.watch {
  border-left: 4px solid var(--amber);
}

.signal.info {
  border-left: 4px solid var(--blue);
}

.metric {
  flex: 0 0 auto;
  min-width: 92px;
  text-align: right;
}

.metric strong {
  display: block;
  font-size: 22px;
}

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

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

.compact .reason {
  margin-top: 6px;
  color: var(--text);
  font-size: 13px;
}

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

.trend-card {
  display: grid;
  gap: 12px;
  padding: 14px;
}

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

.trend-head p,
.trend-current span {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.trend-current {
  flex: 0 0 auto;
  text-align: right;
}

.trend-current strong {
  display: block;
  font-size: 20px;
  line-height: 1.2;
}

.sparkline {
  position: relative;
  width: 100%;
  min-height: 118px;
}

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

.spark-bg {
  fill: #f8faf7;
}

.spark-band {
  stroke: rgba(159, 107, 22, 0.36);
  stroke-dasharray: 4 4;
  stroke-width: 1.2;
}

.spark-area {
  fill: rgba(47, 95, 152, 0.12);
}

.spark-line {
  fill: none;
  stroke: var(--blue);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.6;
}

.spark-dot {
  fill: var(--surface);
  stroke: var(--blue);
  stroke-width: 2;
}

.spark-hover-line {
  stroke: rgba(32, 37, 31, 0.34);
  stroke-dasharray: 3 3;
  stroke-width: 1.2;
}

.spark-hover-dot {
  fill: var(--surface);
  stroke: var(--red);
  stroke-width: 2.4;
}

.spark-tooltip {
  position: absolute;
  top: 8px;
  z-index: 1;
  min-width: 112px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 12px;
  pointer-events: none;
  transform: translateX(-50%);
}

.spark-tooltip strong,
.spark-tooltip span {
  display: block;
  white-space: nowrap;
}

.spark-tooltip span {
  color: var(--muted);
}

.spark-label {
  fill: var(--muted);
  font-size: 11px;
}

.spark-label.end {
  text-anchor: end;
}

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

.trend-deltas span {
  min-height: 28px;
  padding: 5px 7px;
  border-radius: 8px;
  background: #edf0eb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.trend-deltas .up {
  background: #fde8e8;
  color: var(--red);
}

.trend-deltas .down {
  background: #e6f4ec;
  color: var(--green);
}

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

.threshold-note > div {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.threshold-note p {
  margin-bottom: 0;
  color: var(--muted);
}

.core-plan {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) 92px;
  align-items: center;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--green);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.core-plan-current strong,
.plan-progress strong {
  display: block;
  font-size: 30px;
  line-height: 1.1;
}

.core-plan-current span,
.core-plan-state p,
.plan-progress span,
.plan-summary p,
.tranche-copy p,
.tranche-status span {
  margin-bottom: 0;
  color: var(--muted);
}

.core-plan-state h3 {
  margin-bottom: 4px;
  font-size: 18px;
}

.plan-link {
  display: grid;
  justify-items: end;
  color: var(--green);
}

.plan-link strong {
  font-size: 22px;
}

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

.plan-summary {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 0 18px;
}

.plan-progress {
  flex: 0 0 auto;
  text-align: right;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: #dfe5dc;
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.plan-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 18px 0;
  padding: 16px;
  border: 1px solid #e7c97d;
  border-radius: 8px;
  background: #fff8e8;
}

.plan-action.ready {
  border-color: #94c9ab;
  background: #eaf6ef;
}

.plan-action.complete {
  border-color: #94c9ab;
  background: #eaf6ef;
}

.plan-action p {
  margin-bottom: 0;
  color: var(--muted);
}

.tranche-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.tranche {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.tranche.completed {
  border-color: #b9dac7;
  background: #f0f8f3;
}

.tranche.notified {
  border-color: #e7c97d;
  background: #fffaf0;
}

.tranche-index {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: #edf0eb;
  color: var(--muted);
  font-weight: 800;
}

.tranche.completed .tranche-index {
  background: var(--green);
  color: #fff;
}

.tranche-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.tranche-copy h3 {
  margin-bottom: 3px;
}

.tranche-status {
  flex: 0 0 auto;
  text-align: right;
}

.tranche-status strong,
.tranche-status span {
  display: block;
}

.plan-undo {
  margin-top: 18px;
  text-align: right;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.status.good {
  background: #e6f4ec;
  color: var(--green);
}

.status.watch {
  background: #fff3d9;
  color: var(--amber);
}

.status.risk {
  background: #fde8e8;
  color: var(--red);
}

.status.muted {
  background: #edf0eb;
  color: var(--muted);
}

.risk-text {
  color: var(--red) !important;
}

.empty {
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.65);
  color: var(--muted);
}

button,
.primary {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--green);
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  color: var(--green);
}

button.secondary {
  border-color: var(--line);
  background: #eef2ec;
  color: var(--text);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

input,
select {
  min-width: 0;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

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

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

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

  .page {
    padding: 14px;
  }

  .hero,
  .compact-grid,
  .trend-grid,
  .threshold-note,
  .core-plan {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 28px;
  }

  .signal,
  .row-card,
  .portfolio-card,
  .compact,
  .plan-summary,
  .plan-action {
    align-items: flex-start;
    flex-direction: column;
  }

  .plan-link,
  .plan-progress {
    justify-items: start;
    text-align: left;
  }

  .tranche-copy {
    align-items: flex-start;
  }

  .metric {
    width: 100%;
    text-align: left;
  }

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