:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #66727f;
  --line: #d9e0e6;
  --blue: #2863e6;
  --green: #168a62;
  --amber: #a46a00;
  --red: #b42318;
  --shadow: 0 18px 42px rgba(25, 36, 52, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #eef4f6 0, rgba(238, 244, 246, 0) 420px),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(32px, 5vw, 62px);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 6px;
  font-size: 18px;
}

.status-pill,
.controls,
.metric-card,
.panel,
.notes article {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.status-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 13px;
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  position: sticky;
  top: 8px;
  z-index: 10;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
  backdrop-filter: blur(16px);
}

.search-label {
  grid-column: span 2;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.control-help {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  text-transform: none;
}

select,
input {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font-size: 14px;
  font-weight: 600;
  text-transform: none;
}

.cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.metric-card {
  min-height: 118px;
  border-radius: 8px;
  padding: 16px;
}

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

.metric-card span {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 700;
}

.metric-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1;
}

.metric-card small {
  display: block;
  min-height: 32px;
  font-size: 12px;
  line-height: 1.35;
}

.metric-card.accent {
  border-color: rgba(40, 99, 230, 0.35);
  background: #f7fbff;
}

.visuals {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.55fr);
  gap: 16px;
  margin-bottom: 16px;
}

.panel,
.notes article {
  border-radius: 8px;
  padding: 16px;
}

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

.panel-header p,
.callout p,
.notes p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.chart-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: end;
  gap: 10px;
}

.chart-tools label {
  min-width: 150px;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
  font-weight: 700;
}

button.active {
  border-color: var(--blue);
  color: var(--blue);
}

#scatter,
#timeline,
#ramTimeline {
  display: block;
  width: 100%;
  height: 420px;
  border-radius: 8px;
  background: #fbfcfd;
}

#timeline {
  height: 360px;
}

.market-panel,
.ram-lanes-panel,
.shock-panel,
.timeline-panel,
.buyer-panel {
  margin-bottom: 16px;
}

.stack-panel {
  margin-bottom: 16px;
}

.axis {
  stroke: #9aa7b3;
  stroke-width: 1;
}

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

.dot {
  stroke: #fff;
  stroke-width: 1.5;
}

.best-dot {
  stroke: var(--ink);
  stroke-width: 2.5;
}

.period-line {
  fill: none;
  stroke: #9aa7b3;
  stroke-width: 1.4;
  opacity: 0.5;
}

.dot-label,
.axis-label {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(23, 33, 43, 0.12);
}

.value-legend {
  justify-content: flex-end;
}

.callout-grid {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.mini-fact {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.mini-fact strong {
  display: block;
  margin-bottom: 4px;
}

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

.market-unit {
  width: min(520px, 100%);
}

.market-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.market-output {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
}

.market-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.market-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.market-card strong {
  display: block;
  margin: 6px 0 5px;
  font-size: 22px;
}

.market-card small,
.market-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.market-card p {
  margin: 0;
}

.market-card.verdict {
  grid-column: span 2;
}

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

.market-card.positive strong {
  color: var(--green);
}

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

.shock-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.shock-card time,
.shock-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.shock-card strong {
  display: block;
  margin: 5px 0;
}

.shock-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.stack-custom {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.custom-stack-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.custom-stack-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.stack-picker-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.custom-stack-result {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 12px;
}

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

.component-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.component-row strong {
  display: block;
  color: var(--ink);
  font-size: 13px;
}

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

.stack-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.stack-card strong {
  display: block;
  margin-bottom: 8px;
}

.stack-card dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 10px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.stack-card dt {
  font-weight: 800;
}

.stack-card dd {
  margin: 0;
}

.matrix-wrap {
  overflow: auto;
}

.buyer-table {
  min-width: 1180px;
}

.buyer-cell strong {
  display: block;
  margin-bottom: 3px;
}

.alternative-row + .alternative-row {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.buyer-need {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 900;
}

.table-panel {
  padding: 0;
  overflow: hidden;
}

.table-panel .panel-header {
  margin: 0;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.sort-wrap {
  width: min(220px, 100%);
}

.table-wrap {
  overflow: auto;
  max-height: 640px;
}

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

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f9fbfc;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #f7fafc;
}

.mac-name {
  font-weight: 800;
}

.subtext {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.chip {
  font-weight: 800;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
}

.badge.current {
  background: #e8f6ef;
  color: var(--green);
}

.badge.discontinued {
  background: #f1f4f7;
  color: #596775;
}

.badge.removed {
  background: #fff4e0;
  color: var(--amber);
}

.badge.projected {
  background: #eef2ff;
  color: #5346b8;
}

.badge.unavailable {
  background: #fcebea;
  color: var(--red);
}

.source-cell {
  max-width: 160px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.notes {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 16px;
  margin-top: 16px;
}

.notes ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.notes a {
  color: var(--blue);
}

@media (max-width: 1080px) {
  .controls,
  .cards,
  .visuals,
  .stack-grid,
  .stack-picker-grid,
  .custom-stack-result,
  .market-grid,
  .market-output,
  .shock-grid,
  .notes {
    grid-template-columns: 1fr 1fr;
  }

  .search-label,
  .chart-panel,
  .table-panel,
  .timeline-panel,
  .ram-lanes-panel,
  .buyer-panel,
  .notes article {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 20px, 720px);
    padding-top: 18px;
  }

  .topbar,
  .panel-header {
    display: grid;
  }

  .chart-tools {
    justify-content: stretch;
  }

  .custom-stack-head {
    display: grid;
  }

  .preset-buttons {
    justify-content: stretch;
  }

  .preset-buttons button {
    width: 100%;
  }

  .chart-tools label,
  .chart-tools button {
    width: 100%;
  }

  .controls,
  .cards,
  .visuals,
  .stack-grid,
  .stack-picker-grid,
  .custom-stack-result,
  .market-grid,
  .market-output,
  .shock-grid,
  .notes {
    grid-template-columns: 1fr;
  }

  .market-card.verdict {
    grid-column: auto;
  }

  .controls {
    position: static;
  }

  .search-label,
  .chart-panel,
  .table-panel,
  .timeline-panel,
  .ram-lanes-panel,
  .buyer-panel,
  .notes article {
    grid-column: auto;
  }

  #scatter {
    height: 360px;
  }

  #timeline {
    height: 320px;
  }

  #ramTimeline {
    height: 360px;
  }
}
