:root {
  --bg: #f3f5f7;
  --surface: #fff;
  --surface-dark: #111417;
  --text: #161a1d;
  --muted: #667078;
  --line: #dce1e5;
  --accent: #5aa7d9;
  --accent-soft: #eaf5fb;
  --positive: #d94b4b;
  --negative: #15906a;
  --warning: #d99a2b;
}

* {
  box-sizing: border-box;
}

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

button,
table {
  font: inherit;
}

.mono {
  font-family: "SFMono-Regular", Consolas, monospace;
}

.muted {
  color: #8f9aa1;
}

.topbar {
  min-height: 112px;
  padding: 24px 40px;
  background: var(--surface-dark);
  border-bottom: 1px solid #2c3237;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand,
.brand-row,
.status {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-row {
  gap: 10px;
  margin-bottom: 7px;
}

.brand-row strong {
  font-size: 24px;
}

.logo {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #0a0a0a;
  font-weight: 800;
}

.badge {
  padding: 5px 8px;
  border: 1px solid #436071;
  background: #25333c;
  color: #9ed8fa;
  font: 600 10px "SFMono-Regular", Consolas, monospace;
  letter-spacing: 1px;
}

.status {
  gap: 8px;
  color: #e9eef1;
  font-size: 12px;
  font-weight: 600;
}

.status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
}

.system-navigation {
  max-width: 1440px;
  min-height: 56px;
  margin: 0 auto;
  padding: 9px 40px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.business-tabs,
.stage-tabs {
  display: flex;
  align-items: center;
}

.business-tabs a,
.stage-tabs a {
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 650;
}

.business-tabs a + a,
.stage-tabs a + a {
  border-left: 0;
}

.business-tabs a.active,
.business-tabs a:hover,
.stage-tabs a:hover {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.stage-tabs > span {
  margin-right: 8px;
  color: var(--muted);
  font: 650 9px "SFMono-Regular", Consolas, monospace;
}

main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 40px 40px;
}

.page-title,
.panel-heading,
.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 29px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
}

.page-title p,
.panel-heading span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
}

.period-tabs {
  display: flex;
}

.period-tabs button {
  height: 34px;
  padding: 0 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.period-tabs button + button {
  border-left: 0;
}

.period-tabs .active {
  background: var(--surface-dark);
  color: #fff;
  border-color: var(--surface-dark);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.metric {
  min-height: 108px;
  padding: 18px 20px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 7px;
}

.metric:last-child {
  border-right: 0;
}

.metric-label,
.metric-note {
  color: var(--muted);
}

.metric-label {
  font: 600 10px "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.6px;
}

.metric-value {
  font: 650 25px "SFMono-Regular", Consolas, monospace;
}

.metric-note {
  font-size: 10px;
}

.overview-grid,
.split-grid {
  display: grid;
  gap: 18px;
  margin-top: 20px;
}

.overview-grid {
  grid-template-columns: 1.25fr 1fr;
}

.split-grid {
  grid-template-columns: 1.2fr 0.8fr;
}

.panel,
.dark-card {
  border: 1px solid var(--line);
}

.panel {
  margin-top: 20px;
  background: var(--surface);
}

.overview-grid .panel,
.split-grid .panel {
  margin-top: 0;
}

.dark-card {
  min-height: 220px;
  padding: 22px 24px;
  background: var(--surface-dark);
  border-color: #2c3237;
  color: #fff;
}

.dark-card > p {
  margin-top: 20px;
  color: #d7dee2;
  font-size: 13px;
  line-height: 1.55;
}

.keep,
.state {
  padding: 5px 8px;
  font: 650 9px "SFMono-Regular", Consolas, monospace;
}

.keep {
  border: 1px solid #496451;
  background: #2a352d;
  color: #a9e0b8;
}

.policy-note {
  margin-top: 18px;
  padding: 11px 13px;
  border: 1px solid #2c3237;
  background: #192127;
  color: #aab4ba;
  font-size: 10px;
}

.panel-heading {
  min-height: 54px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}

#maturity {
  padding: 8px 16px 14px;
}

.progress-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 76px;
  align-items: center;
  gap: 12px;
  min-height: 36px;
  font: 600 10px "SFMono-Regular", Consolas, monospace;
}

.progress-track,
.rank-track {
  background: #eef1f3;
}

.progress-track {
  height: 7px;
}

.progress-bar,
.rank-bar {
  height: 100%;
  background: var(--accent);
}

.progress-row.pending .progress-bar {
  background: var(--warning);
}

.rank-chart {
  padding: 18px 24px 22px;
}

.rank-row {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr) 70px 56px;
  align-items: center;
  gap: 12px;
  min-height: 38px;
  font: 600 9px "SFMono-Regular", Consolas, monospace;
}

.rank-track {
  height: 10px;
}

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

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

.warning {
  color: var(--warning);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  font-size: 10px;
}

th {
  height: 36px;
  background: #f7f8f9;
  color: var(--muted);
  font: 650 8px "SFMono-Regular", Consolas, monospace;
}

.state {
  border: 1px solid var(--line);
  background: #f7f8f9;
}

.case-item {
  min-height: 92px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.case-item strong {
  display: block;
  font-size: 13px;
}

.case-item small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 9px;
}

.case-return {
  font: 650 15px "SFMono-Regular", Consolas, monospace;
}

.attribution-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
  padding: 18px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  padding: 18px;
}

.status-item {
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: #fafbfb;
}

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

.status-item span {
  color: var(--muted);
  font-size: 9px;
}

.status-item strong {
  margin-top: 8px;
  font: 650 18px "SFMono-Regular", Consolas, monospace;
}

.attribution-item {
  min-height: 126px;
  padding: 16px;
  border: 1px solid var(--line);
  background: #fafbfb;
}

.attribution-item span,
.attribution-item small {
  display: block;
  color: var(--muted);
}

.attribution-item span {
  font: 650 9px "SFMono-Regular", Consolas, monospace;
}

.attribution-item strong {
  display: block;
  margin: 10px 0;
  font: 650 22px "SFMono-Regular", Consolas, monospace;
}

.attribution-item small {
  font-size: 9px;
}

footer {
  margin-top: 20px;
  padding: 18px;
  border: 1px solid var(--line);
  background: #fafbfb;
  color: var(--muted);
  font: 9px/1.5 "SFMono-Regular", Consolas, monospace;
}

.history-days { display: flex; flex-direction: column; gap: 8px; }
.history-group { border: 1px solid var(--line); background: #f7f8f9; }
.history-group-header { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; background: none; border: none; cursor: pointer; color: var(--text); font: inherit; text-align: left; }
.history-group-header:hover { background: var(--accent-soft); }
.history-group-left { display: flex; align-items: center; gap: 8px; }
.history-group-left strong { font: 600 13px/1.2 "SFMono-Regular", Consolas, monospace; }
.history-caret { display: inline-block; color: var(--muted); font-size: 10px; transition: transform .15s ease; }
.history-group.is-open .history-caret { transform: rotate(90deg); }
.history-group-count { color: var(--muted); font-size: 11px; }
.history-run-list { display: none; flex-direction: column; border-top: 1px solid var(--line); }
.history-group.is-open .history-run-list { display: flex; }
.history-run { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px 9px 16px; text-decoration: none; color: var(--text); border-top: 1px solid var(--line); }
.history-run:first-child { border-top: none; }
.history-run:hover { background: var(--accent-soft); }
.history-run-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.history-run-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.history-run-time { font: 12px/1.2 "SFMono-Regular", Consolas, monospace; }
.history-run-note { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-run-open { color: var(--accent); font-size: 11px; white-space: nowrap; }
.empty-state { color: var(--muted); font-size: 11px; padding: 6px 2px; }

@media (max-width: 700px) {
  .topbar {
    min-height: 72px;
    padding: 0 16px;
  }

  .logo {
    width: 27px;
    height: 27px;
  }

  .brand-row strong {
    font-size: 16px;
  }

  .badge {
    display: none;
  }

  #period {
    font-size: 8px;
  }

  .system-navigation {
    min-height: 96px;
    padding: 9px 14px;
    display: block;
  }

  .business-tabs,
  .stage-tabs {
    width: 100%;
  }

  .business-tabs a,
  .stage-tabs a {
    flex: 1;
    min-width: 0;
    min-height: 36px;
    padding: 0 4px;
    font-size: 9px;
    text-align: center;
  }

  .stage-tabs {
    margin-top: 7px;
  }

  .stage-tabs > span {
    display: none;
  }

  main {
    padding: 20px 14px 24px;
  }

  .page-title {
    display: block;
  }

  h1 {
    font-size: 23px;
  }

  .period-tabs {
    margin-top: 14px;
  }

  .period-tabs button {
    flex: 1;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    border: 0;
    background: transparent;
  }

  .metric {
    min-height: 96px;
    border: 1px solid var(--line);
    background: var(--surface);
  }

  .metric:last-child {
    grid-column: 1 / -1;
  }

  .overview-grid,
  .split-grid {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 14px;
  }

  .panel {
    margin-top: 14px;
  }

  .rank-row {
    grid-template-columns: 84px minmax(0, 1fr) 50px;
  }

  .rank-row .rank-count {
    display: none;
  }

  th:nth-child(2),
  td:nth-child(2),
  th:nth-child(4),
  td:nth-child(4) {
    display: none;
  }

  .attribution-grid {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0;
  }

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

  .attribution-item {
    min-height: 52px;
    border: 0;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .attribution-item strong {
    margin: 0;
  }

  .attribution-item small {
    display: none;
  }
}
