:root {
  color-scheme: light;
  --canvas: oklch(0.965 0.008 105);
  --surface: oklch(0.992 0.004 105);
  --surface-alt: oklch(0.972 0.006 105);
  --surface-strong: oklch(0.945 0.01 105);
  --ink: oklch(0.19 0.014 160);
  --ink-soft: oklch(0.36 0.014 160);
  --muted: oklch(0.49 0.012 160);
  --line: oklch(0.86 0.012 105);
  --line-strong: oklch(0.76 0.018 105);
  --success: oklch(0.47 0.13 160);
  --success-soft: oklch(0.93 0.035 160);
  --danger: oklch(0.5 0.15 28);
  --danger-soft: oklch(0.94 0.035 28);
  --info: oklch(0.48 0.1 245);
  --info-soft: oklch(0.93 0.035 245);
  --warning: oklch(0.58 0.12 72);
  --warning-soft: oklch(0.94 0.04 72);
  --focus: oklch(0.58 0.14 245);
  --shadow-sm: 0 1px 2px oklch(0.2 0.01 160 / 0.08);
  --shadow-md: 0 16px 36px oklch(0.2 0.01 160 / 0.08);
  --radius: 8px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --content: 1480px;
  --safe-x: max(16px, env(safe-area-inset-left));
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  overflow-x: clip;
  background:
    linear-gradient(180deg, oklch(0.99 0.004 105), transparent 280px),
    var(--canvas);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

body,
button,
input,
select,
textarea {
  letter-spacing: 0;
}

h1,
h2,
h3,
p,
dl,
dd,
ol {
  margin: 0;
}

h1 {
  max-width: 760px;
  font-size: 2.75rem;
  line-height: 1.04;
  font-weight: 760;
}

h2 {
  font-size: 1.18rem;
  line-height: 1.25;
  font-weight: 720;
}

h3 {
  font-size: 1rem;
  line-height: 1.3;
  font-weight: 700;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  left: 16px;
  top: 12px;
  z-index: 20;
  transform: translateY(-150%);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--surface);
  padding: 10px 14px;
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

.app-header {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.header-main {
  width: min(var(--content), calc(100% - 40px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: var(--space-8);
  padding: var(--space-8) 0 var(--space-6);
}

.header-copy {
  min-width: 0;
}

.section-kicker {
  color: var(--warning);
  font-size: 0.75rem;
  font-weight: 780;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.subtitle,
.section-note {
  max-width: 72ch;
  color: var(--muted);
}

.subtitle {
  margin-top: var(--space-3);
}

.source-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(128px, auto));
  gap: var(--space-3);
}

.source-summary div {
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
  padding: var(--space-3);
}

.source-summary dt {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.source-summary dd {
  margin-top: var(--space-1);
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-weight: 720;
}

.section-nav {
  width: min(var(--content), calc(100% - 40px));
  margin: 0 auto;
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding: 0 0 var(--space-3);
  scrollbar-width: none;
}

.section-nav::-webkit-scrollbar {
  display: none;
}

.section-nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
  padding: 0 var(--space-4);
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: background 180ms ease-out, border-color 180ms ease-out, color 180ms ease-out;
}

.section-nav a:hover {
  border-color: var(--line-strong);
  background: var(--surface-strong);
  color: var(--ink);
}

main {
  width: min(var(--content), calc(100% - 40px));
  margin: 0 auto;
  padding: var(--space-6) 0 56px;
}

.dashboard-section {
  scroll-margin-top: 18px;
  margin-bottom: var(--space-6);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.full-span {
  grid-column: 1 / -1;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: var(--space-3);
}

.kpi-card,
.panel,
.executive-summary {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.kpi-card {
  min-height: 132px;
  padding: var(--space-4);
  display: grid;
  align-content: space-between;
  gap: var(--space-3);
}

.kpi-card dt {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 760;
  text-transform: uppercase;
}

.kpi-card dd {
  margin-top: var(--space-2);
  color: var(--ink);
  font-size: 1.42rem;
  font-weight: 780;
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.kpi-note {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.kpi-status {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--accent, var(--info));
}

.split-layout,
.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 0.85fr);
  gap: var(--space-4);
}

.detail-layout {
  grid-template-columns: minmax(360px, 0.82fr) minmax(0, 1.18fr);
}

.panel,
.executive-summary {
  padding: var(--space-5);
}

.panel-wide {
  min-height: 430px;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--warning-soft);
  color: oklch(0.38 0.09 72);
  padding: 0 var(--space-3);
  font-size: 0.78rem;
  font-weight: 760;
  white-space: nowrap;
}

.chart {
  width: 100%;
  min-height: 280px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-color: var(--line-strong) transparent;
}

.chart svg {
  display: block;
  width: 100%;
  min-width: 680px;
  height: 100%;
  min-height: 320px;
}

.chart-line svg {
  min-height: 360px;
}

.chart-compact {
  min-height: auto;
}

.chart-compact .bar-row {
  grid-template-columns: minmax(110px, 0.7fr) minmax(120px, 1fr) minmax(110px, 0.55fr);
}

.axis-label {
  fill: var(--muted);
  font-size: 12px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
  color: var(--muted);
  font-size: 0.84rem;
}

.legend span::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 2px;
  background: var(--legend);
}

.bar-list {
  display: grid;
  gap: var(--space-3);
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.85fr) minmax(170px, 1.35fr) minmax(96px, 0.55fr);
  align-items: center;
  gap: var(--space-3);
}

.bar-label {
  min-width: 0;
  color: var(--ink-soft);
  font-weight: 720;
  overflow-wrap: anywhere;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-strong);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: var(--w);
  border-radius: 999px;
  background: var(--bar, var(--info));
}

.bar-value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

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

caption {
  text-align: left;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 780;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

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

tbody tr:hover {
  background: var(--surface-alt);
}

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

.positive {
  color: var(--success);
  font-weight: 780;
}

.negative {
  color: var(--danger);
  font-weight: 780;
}

.diagnostic-list,
.numbered,
.block-list,
.insight-list {
  display: grid;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
}

.numbered {
  padding-left: 1.35rem;
}

.numbered li {
  color: var(--ink-soft);
  line-height: 1.5;
  padding-left: var(--space-1);
}

.diagnostic-item,
.block-item,
.insight-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
  padding: var(--space-4);
}

.diagnostic-item h3,
.block-item h3,
.insight-item h3 {
  margin-bottom: var(--space-2);
}

.diagnostic-item p,
.block-item p,
.insight-item p {
  color: var(--ink-soft);
  line-height: 1.5;
}

.diagnostic-item p + p,
.insight-item p + p {
  margin-top: var(--space-2);
}

.decision-label {
  color: var(--success);
  font-weight: 760;
}

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

.insight-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-bottom: var(--space-3);
  border-radius: 999px;
  background: var(--info-soft);
  color: var(--info);
  font-size: 0.78rem;
  font-weight: 800;
}

.formula-code {
  display: block;
  width: max-content;
  max-width: 620px;
  border-radius: 6px;
  background: var(--surface-strong);
  color: var(--ink-soft);
  padding: 8px 10px;
  font-family: "SFMono-Regular", "Cascadia Mono", "Consolas", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: normal;
  overflow-wrap: anywhere;
}

.executive-summary {
  display: grid;
  gap: var(--space-3);
  background: var(--info-soft);
  border-color: oklch(0.82 0.035 245);
  box-shadow: var(--shadow-md);
}

.executive-summary p:last-child {
  max-width: 75ch;
  color: oklch(0.25 0.04 245);
  font-size: 1.12rem;
  line-height: 1.55;
}

@media (max-width: 1180px) {
  .header-main {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .source-summary {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .split-layout,
  .two-col,
  .detail-layout,
  .insight-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  h1 {
    font-size: 2rem;
  }

  h2 {
    font-size: 1.08rem;
  }

  body {
    font-size: 15px;
  }

  .header-main,
  .section-nav,
  main {
    width: calc(100% - 24px);
  }

  .header-main {
    gap: var(--space-4);
    padding: var(--space-6) 0 var(--space-4);
  }

  .source-summary {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
  }

  .source-summary div {
    min-height: 64px;
    padding: var(--space-3);
  }

  .section-nav {
    position: sticky;
    top: 0;
    z-index: 8;
    margin-inline: 0;
    width: 100%;
    padding: var(--space-2) 12px;
    background: color-mix(in oklch, var(--surface) 94%, transparent);
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  main {
    padding-top: var(--space-4);
  }

  .dashboard-section {
    margin-bottom: var(--space-5);
    scroll-margin-top: 66px;
  }

  .section-heading,
  .panel-head {
    align-items: start;
    flex-direction: column;
    gap: var(--space-2);
  }

  .kpi-grid {
    display: flex;
    gap: var(--space-3);
    margin-inline: -12px;
    padding: 0 12px var(--space-2);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }

  .kpi-grid::-webkit-scrollbar {
    display: none;
  }

  .kpi-card {
    flex: 0 0 min(82vw, 320px);
    min-height: 142px;
    scroll-snap-align: start;
  }

  .split-layout,
  .two-col,
  .detail-layout {
    gap: var(--space-3);
  }

  .panel,
  .executive-summary {
    padding: var(--space-4);
  }

  .panel-wide {
    min-height: 0;
  }

  .chart {
    margin-inline: -8px;
    padding-inline: 8px;
  }

  .chart svg {
    min-width: 620px;
    min-height: 300px;
  }

  .bar-row {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  .chart-compact .bar-row {
    grid-template-columns: 1fr;
  }

  .bar-track {
    height: 12px;
  }

  .bar-value {
    text-align: left;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  table {
    min-width: 0;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  tbody {
    display: grid;
    gap: var(--space-3);
  }

  tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
  }

  tbody tr:hover {
    background: var(--surface);
  }

  td {
    display: grid;
    grid-template-columns: minmax(106px, 0.46fr) minmax(0, 1fr);
    gap: var(--space-3);
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    text-align: left;
    overflow-wrap: anywhere;
  }

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

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 780;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  td.numeric {
    text-align: left;
  }

  .formula-code {
    width: 100%;
    max-width: 100%;
  }
}

@media (max-width: 430px) {
  h1 {
    font-size: 1.72rem;
  }

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

  .section-nav a {
    padding-inline: var(--space-3);
  }

  .kpi-card {
    flex-basis: 88vw;
  }

  td {
    grid-template-columns: 1fr;
    gap: var(--space-1);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
