:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #657180;
  --line: #d9e1e8;
  --soft: #f5f7f9;
  --panel: #ffffff;
  --accent: #1f7a6d;
  --accent-dark: #155a51;
  --gold: #b9822b;
  --danger: #ad3d3d;
}

* {
  box-sizing: border-box;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
}

nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

nav a,
.button,
button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
  border-radius: 6px;
  padding: 9px 12px;
  text-decoration: none;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

nav a.active,
.button,
button {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

nav a:hover,
.button:hover,
button:hover {
  border-color: var(--accent-dark);
}

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

.button.small,
button.small {
  display: inline-block;
  padding: 5px 8px;
  font-size: 13px;
}

.bulk-actions,
.row-actions {
  display: flex;
  gap: 8px;
}

.bulk-actions {
  flex-wrap: wrap;
  margin: 0 0 10px;
}

.row-actions {
  align-items: flex-start;
  flex-direction: column;
}

.settings-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin: 12px 0 18px;
}

.settings-table {
  min-width: 1120px;
}

.settings-table th:first-child,
.settings-table td:first-child {
  width: 52px;
}

.settings-table input,
.settings-table select {
  min-height: 34px;
}

.criteria-add-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  margin: 12px 0;
}

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

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
}

.filter-actions {
  align-self: center;
  display: flex;
  gap: 8px;
  grid-column: 5;
  grid-row: 1 / span 2;
  justify-content: flex-end;
}

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

.checkbox-filter {
  align-items: center;
  display: flex;
  min-height: 38px;
}

.checkbox-filter input {
  min-height: auto;
  width: auto;
}

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

.filter-popover-button {
  width: 100%;
  min-height: 38px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}

.filter-popover {
  width: min(420px, calc(100vw - 32px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(23, 32, 42, 0.2);
}

.filter-popover::backdrop {
  background: transparent;
}

.filter-popover p {
  margin-top: 10px;
  font-size: 13px;
  text-transform: none;
}

select,
input,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  font: inherit;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

select[multiple] {
  min-height: 98px;
  padding: 6px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metrics div,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metrics div {
  padding: 15px;
}

.metrics span {
  display: block;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metrics strong {
  display: block;
  font-size: 26px;
  line-height: 1.2;
}

.grid {
  display: grid;
  gap: 18px;
}

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

.panel {
  padding: 18px;
  overflow: hidden;
}

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

h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

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

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

.bar-list {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(110px, 1.4fr) 82px 82px 104px;
  gap: 12px;
  align-items: center;
}

.bar-label,
.bar-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.bar-header {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.bar-header div {
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-header div:first-child {
  text-align: left;
}

.bar-track {
  height: 12px;
  background: #edf1f4;
  border-radius: 999px;
  overflow: hidden;
}

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

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 12px 0;
  color: var(--muted);
  flex-wrap: wrap;
}

.pagination form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination select {
  min-height: 34px;
  min-width: 86px;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.compact-table-wrap {
  overflow-x: hidden;
}

.compact-table {
  min-width: 0;
  table-layout: fixed;
}

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

.compact-table th:nth-child(1),
.compact-table td:nth-child(1) {
  width: 34%;
}

.compact-table th:nth-child(2),
.compact-table td:nth-child(2) {
  width: 25%;
}

.compact-table th:nth-child(3),
.compact-table td:nth-child(3) {
  width: 15%;
}

.compact-table th:nth-child(4),
.compact-table td:nth-child(4) {
  width: 13%;
}

.compact-table th:nth-child(5),
.compact-table td:nth-child(5) {
  width: 13%;
  text-align: right;
}

.compact-table td:nth-child(3),
.compact-table td:nth-child(4) {
  text-align: right;
  white-space: nowrap;
}

.compact-table .table-link,
.compact-table td {
  overflow-wrap: anywhere;
}

.compact-table .score {
  min-width: 34px;
}

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

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

.sort-link {
  color: inherit;
  text-decoration: none;
}

.sort-link::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 6px;
  vertical-align: middle;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}

.sort-link.down::after {
  border-top: 5px solid var(--accent);
}

.sort-link.up::after {
  border-bottom: 5px solid var(--accent);
}

.table-link {
  color: var(--accent-dark);
  font-weight: 700;
  text-decoration: none;
}

.table-link:hover {
  text-decoration: underline;
}

td {
  line-height: 1.35;
}

td span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.score {
  display: inline-block;
  min-width: 38px;
  padding: 4px 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--gold);
  font-weight: 700;
  text-align: center;
}

.danger-link {
  color: var(--danger);
  font-weight: 700;
  text-decoration: none;
}

.danger-link:hover {
  text-decoration: underline;
}

.disabled {
  pointer-events: none;
  opacity: 0.65;
}

.busy-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(23, 32, 42, 0.42);
  z-index: 20;
}

.busy-overlay.visible {
  display: flex;
}

.busy-box {
  width: min(420px, 100%);
  padding: 28px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 18px 60px rgba(23, 32, 42, 0.22);
  text-align: center;
}

.busy-box strong {
  display: block;
  margin-top: 14px;
  font-size: 20px;
}

.busy-box p {
  margin-top: 8px;
}

.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto;
  border: 4px solid #d8e5e2;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.notice,
.empty {
  padding: 12px 14px;
  border-radius: 6px;
  background: #edf7f5;
  color: var(--accent-dark);
  margin-bottom: 14px;
}

.empty {
  color: var(--muted);
  background: var(--soft);
}

.import-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.upload-form {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(260px, 420px) auto;
  margin-bottom: 16px;
}

.detail-sections {
  margin: 18px 0;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
}

.detail-grid div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}

.detail-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.detail-grid strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.35;
}

.notes-form {
  display: grid;
  gap: 12px;
}

.notes-form button {
  justify-self: start;
}

@media (max-width: 980px) {
  .topbar,
  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .filters,
  .metrics,
  .grid.two,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .filter-actions {
    grid-column: auto;
    grid-row: auto;
    justify-content: flex-start;
  }

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

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

  .pagination,
  .page-actions,
  .settings-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .criteria-add-grid {
    grid-template-columns: 1fr;
  }

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