:root {
  --ink: #17202a;
  --muted: #627084;
  --line: #d8dee7;
  --panel: #f4f7fa;
  --warn: #9a4d00;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  color: var(--ink);
  background: #fff;
}

header {
  padding: 26px 32px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

main {
  padding: 24px 32px 42px;
}

h1 {
  font-size: 28px;
  margin: 0 0 7px;
  font-weight: 720;
}

h2 {
  font-size: 17px;
  margin: 0 0 12px;
}

p {
  color: var(--muted);
  margin: 0;
}

#metadata {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.metadata-item {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  padding: 6px 8px;
}

.metadata-item strong {
  color: var(--ink);
  font-weight: 680;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 5px;
}

select {
  width: 100%;
  min-width: 220px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  font-size: 14px;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  white-space: nowrap;
}

th {
  background: #eef2f6;
  font-weight: 650;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: inherit;
  padding: 0;
  white-space: nowrap;
}

.sort-button:hover {
  color: #2f6f4e;
}

.sort-marker {
  display: inline-block;
  min-width: 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
}

tbody tr:hover td {
  background: #f8fafc;
}

.expandable-row {
  cursor: pointer;
}

.expand-cell {
  width: 32px;
}

.expand-button {
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  line-height: 1;
  padding: 0;
}

.expand-button:hover {
  border-color: #2f6f4e;
  color: #2f6f4e;
}

.detail-row td {
  background: #f8fafc;
  padding: 10px 10px 14px 42px;
}

.detail-row:hover td {
  background: #f8fafc;
}

.outcome-detail {
  max-width: 560px;
}

.outcome-detail table {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.outcome-detail th {
  background: #f1f4f8;
}

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

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 340px) minmax(260px, 1fr);
  gap: 16px;
  align-items: end;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 680;
  padding: 9px 12px 10px;
}

.tab:hover {
  color: var(--ink);
}

.tab.active {
  border-bottom-color: #2f6f4e;
  color: var(--ink);
}

.hidden {
  display: none;
}

.band {
  border-top: 1px solid var(--line);
  padding-top: 20px;
  overflow-x: auto;
}

.primary-band {
  border-top: 0;
  padding-top: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin-bottom: 0;
}

.panel-control {
  width: min(320px, 100%);
  flex: 0 0 auto;
}

.panel-control select {
  min-width: 0;
}

.whatif-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
}

.whatif-head p {
  margin-top: 4px;
  font-size: 13px;
}

.whatif-actions {
  display: grid;
  grid-template-columns: minmax(120px, 150px) auto auto;
  gap: 8px;
  align-items: end;
}

.whatif-actions label {
  grid-column: 1;
}

.whatif-actions select {
  grid-column: 1;
  min-width: 120px;
}

.action-button,
.secondary-button,
.score-expand {
  min-height: 36px;
  border: 1px solid #2f6f4e;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 680;
  padding: 0 12px;
}

.action-button {
  background: #2f6f4e;
  color: #fff;
}

.secondary-button,
.score-expand {
  background: #fff;
  color: #2f6f4e;
}

.whatif-grid {
  display: grid;
  grid-template-columns: minmax(310px, 0.72fr) minmax(420px, 1fr);
  gap: 22px;
  align-items: start;
}

.whatif-results,
.whatif-matches {
  min-width: 0;
}

.whatif-matches h2,
.mini-section h2 {
  margin-top: 0;
}

.match-control {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
}

.match-control-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 10px;
}

.match-control-head strong,
.match-control-head span {
  display: block;
}

.match-control-head span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.score-expand {
  min-height: 30px;
  white-space: nowrap;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segmented button {
  min-height: 34px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  padding: 0 8px;
}

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

.segmented button:hover {
  background: #f0f6f2;
}

.segmented button.active {
  background: #dceee4;
  color: #17472f;
  font-weight: 700;
}

.score-row {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(90px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 10px;
}

.score-row.hidden {
  display: none;
}

.score-row label {
  margin: 0;
}

.score-row span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-row input[type="number"] {
  width: 100%;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  padding: 0 8px;
}

.score-check {
  display: flex;
  gap: 7px;
  align-items: center;
  min-height: 34px;
  color: var(--ink);
  font-size: 13px;
  white-space: nowrap;
}

.whatif-metric {
  border-left: 4px solid #2f6f4e;
  background: #f4f8f5;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.mini-section {
  margin-top: 18px;
  overflow-x: auto;
}

.compact-table th,
.compact-table td {
  padding: 7px 8px;
}

.delta-positive {
  color: #1f6b43;
  font-weight: 700;
}

.delta-negative {
  color: #a33b3b;
  font-weight: 700;
}

.delta-neutral {
  color: var(--muted);
}

.error-banner {
  border-left: 4px solid #a33b3b;
  background: #fff1f1;
  color: #711f1f;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.team-summary {
  min-height: 36px;
  border-left: 1px solid var(--line);
  padding-left: 16px;
}

.metric-label,
.metric-note {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.metric-label {
  font-weight: 650;
  margin-bottom: 3px;
}

.metric-value {
  display: block;
  font-size: 22px;
  line-height: 1.05;
  font-weight: 760;
}

.finish-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.finish-strip strong {
  color: var(--ink);
  font-weight: 650;
}

.route-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}

.route-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-height: 92px;
}

.route-card.good {
  border-left: 4px solid #2f6f4e;
}

.route-card.bad {
  border-left: 4px solid #a33b3b;
}

.route-card span,
.route-card small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.route-card strong {
  display: block;
  font-size: 24px;
  line-height: 1.05;
  margin: 6px 0;
}

.guide-section {
  overflow-x: auto;
}

.empty {
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
}

.warnings {
  border-left: 4px solid var(--warn);
  background: #fff7ed;
  padding: 12px 16px;
  color: #603711;
  margin-top: 16px;
}

.warnings ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.num {
  font-variant-numeric: tabular-nums;
}

@media (max-width: 680px) {
  header,
  main {
    padding-left: 18px;
    padding-right: 18px;
  }

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

  .team-summary {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-left: 0;
    padding-top: 14px;
  }

  .tabs {
    overflow-x: auto;
  }

  .panel-head {
    display: block;
  }

  .panel-control {
    margin-top: 12px;
    width: 100%;
  }

  .whatif-head,
  .match-control-head {
    display: block;
  }

  .whatif-actions {
    grid-template-columns: 1fr 1fr;
    margin-top: 14px;
  }

  .whatif-actions label,
  .whatif-actions select {
    grid-column: 1 / -1;
  }

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

  .score-expand {
    margin-top: 9px;
  }

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

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

  .score-check {
    grid-column: 1 / -1;
  }

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

@media (max-width: 460px) {
  .whatif-actions,
  .score-row {
    grid-template-columns: 1fr;
  }

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

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

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

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