:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --border: #d8dee4;
  --text: #1f2933;
  --muted: #62707c;
  --green: #147a5c;
  --green-dark: #0d5d47;
  --blue: #2357a4;
  --red: #b42318;
  --amber: #8a5a00;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
a {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

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

button:hover {
  border-color: #9aa7b2;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

button.primary {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

button.primary:hover {
  background: var(--green-dark);
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 12px;
}

.app {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.runtime-info {
  position: fixed;
  right: 16px;
  bottom: 12px;
  z-index: 20;
  max-width: min(520px, calc(100vw - 32px));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  box-shadow: 0 8px 22px rgba(31, 41, 51, 0.12);
  font-size: 12px;
  line-height: 1.4;
  padding: 7px 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.nav-tabs a,
.nav-more summary {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border-radius: 6px;
  padding: 0 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

.nav-more {
  position: relative;
}

.nav-more summary {
  cursor: pointer;
  list-style: none;
}

.nav-more summary::-webkit-details-marker {
  display: none;
}

.nav-more[open] summary,
.nav-more.active summary,
.nav-tabs a.active {
  background: var(--green);
  color: #fff;
}

.nav-more-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 10;
  display: grid;
  min-width: 168px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 24px rgba(31, 41, 51, 0.12);
}

.nav-more-menu a {
  min-height: 38px;
  border-radius: 0;
  padding: 0 14px;
}

.nav-more-menu a.active {
  background: #fff;
  color: var(--green);
}

.view[hidden] {
  display: none;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.metric-card,
.link-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.metric-card {
  display: flex;
  min-height: 132px;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px;
}

.metric-card strong {
  display: block;
  margin: 8px 0;
  font-size: 30px;
  line-height: 1.1;
}

.metric-label,
.metric-card span:last-child,
.link-card span {
  color: var(--muted);
  font-size: 14px;
}

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

.link-card {
  display: flex;
  min-height: 96px;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 16px;
}

.link-card strong {
  font-size: 16px;
}

.link-more {
  margin-top: 12px;
}

.link-more summary {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 650;
  list-style: none;
  padding: 0 12px;
}

.link-more summary::-webkit-details-marker {
  display: none;
}

.link-more .link-card {
  margin-top: 10px;
  max-width: 620px;
}

h1,
h2,
p {
  margin: 0;
}

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

h2 {
  font-size: 18px;
  line-height: 1.3;
}

.topbar p,
.status {
  color: var(--muted);
  font-size: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 14px;
  padding: 16px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.section-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.url-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 8px;
}

.discovery-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.crawl-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.crawl-controls label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.crawl-controls input {
  width: 72px;
}

.revenue-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
}

.segmented-control {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
}

.segmented-control button {
  min-height: 36px;
  border: 0;
  border-radius: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-weight: 650;
}

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

.segmented-control button.active {
  background: var(--green);
  color: #fff;
}

.revenue-controls label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.revenue-controls .check-control {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  gap: 7px;
}

.check-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.revenue-controls input:not([type="checkbox"]) {
  width: 140px;
}

.revenue-controls input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
}

.check-control input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
}

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

.run-status-grid > div {
  display: grid;
  gap: 6px;
}

.run-status-grid strong {
  font-size: 24px;
}

.note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

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

.revenue-summary .panel {
  display: grid;
  gap: 6px;
}

.revenue-summary strong {
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1;
}

.progress {
  width: 100%;
  height: 10px;
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #eef2f4;
}

.progress > div {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 0.25s ease;
}

.validation {
  min-height: 24px;
  margin-top: 10px;
  font-size: 14px;
  color: var(--muted);
}

.validation.ok {
  color: var(--green);
}

.validation.error {
  color: var(--red);
}

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

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

#coursesView table th:nth-child(1),
#coursesView table td:nth-child(1) {
  width: 72px;
}

#coursesView table th:nth-child(3),
#coursesView table td:nth-child(3) {
  width: 120px;
}

#coursesView table th:nth-child(4),
#coursesView table td:nth-child(4) {
  width: 150px;
}

#coursesView table th:nth-child(5),
#coursesView table td:nth-child(5) {
  width: 90px;
}

.daily-table {
  min-width: 980px;
}

.daily-table th:nth-child(1),
.daily-table td:nth-child(1) {
  width: 130px;
}

.daily-table th:nth-child(3),
.daily-table td:nth-child(3),
.daily-table th:nth-child(4),
.daily-table td:nth-child(4) {
  width: 120px;
}

.daily-table th:nth-child(5),
.daily-table td:nth-child(5) {
  width: 150px;
}

.records-table {
  min-width: 900px;
}

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

.runs-table {
  min-width: 980px;
}

.records-table th:nth-child(1),
.records-table td:nth-child(1) {
  width: 210px;
}

.records-table th:nth-child(3),
.records-table td:nth-child(3),
.records-table th:nth-child(4),
.records-table td:nth-child(4) {
  width: 150px;
}

.revenue-table th:nth-child(2),
.revenue-table td:nth-child(2),
.revenue-table th:nth-child(3),
.revenue-table td:nth-child(3),
.revenue-table th:nth-child(4),
.revenue-table td:nth-child(4) {
  width: 150px;
}

.revenue-table th:nth-child(5),
.revenue-table td:nth-child(5) {
  width: 170px;
}

.runs-table th:nth-child(1),
.runs-table td:nth-child(1) {
  width: 210px;
}

.runs-table th:nth-child(2),
.runs-table td:nth-child(2),
.runs-table th:nth-child(3),
.runs-table td:nth-child(3),
.runs-table th:nth-child(4),
.runs-table td:nth-child(4),
.runs-table th:nth-child(5),
.runs-table td:nth-child(5) {
  width: 100px;
}

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

th {
  color: var(--muted);
  font-weight: 600;
}

.sort-heading {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sort-buttons {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.sort-buttons button {
  width: 26px;
  min-width: 26px;
  min-height: 26px;
  border-radius: 5px;
  padding: 0;
  font-size: 13px;
  line-height: 1;
}

.sort-buttons button.active {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

tbody tr.row-highlight {
  background: #e8f7ef;
}

tbody tr.row-highlight td {
  border-top-color: #b7e4ca;
}

td input[type="url"],
td input[type="text"] {
  min-width: 0;
}

.course-cell {
  min-width: 0;
}

.number-cell,
.time-cell,
.date-cell {
  white-space: nowrap;
}

.course-title {
  display: inline-block;
  font-weight: 650;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.course-link {
  color: var(--text);
  text-decoration: none;
}

.course-link:hover {
  color: var(--blue);
  text-decoration: underline;
}

.course-id {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

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

.badge.ok {
  background: #e6f4ee;
  color: var(--green);
}

.badge.off {
  background: #f2f4f7;
  color: var(--muted);
}

.badge.warn {
  background: #fff3d6;
  color: var(--amber);
}

.revenue-amount {
  color: var(--green);
  font-weight: 750;
}

.delta {
  font-weight: 700;
}

.delta.plus {
  color: var(--green);
}

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

.delta.blank {
  color: var(--amber);
}

.delta-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  margin-top: 3px;
  white-space: nowrap;
}

.run-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  margin-top: 3px;
  white-space: nowrap;
}

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

.danger {
  color: var(--red);
}

.small {
  color: var(--muted);
  font-size: 12px;
}

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

.pagination-info {
  display: grid;
  gap: 2px;
  min-width: 190px;
}

.pagination-info span {
  font-size: 12px;
}

.pagination-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

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

.pagination-buttons button {
  min-width: 38px;
  padding: 0 10px;
}

.pagination-buttons button.current {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.pagination-jump {
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.pagination-jump input {
  width: 88px;
  min-height: 36px;
}

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

.api-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.api-actions {
  display: flex;
  align-items: end;
  gap: 8px;
  grid-column: 1 / -1;
}

.api-request {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f7faf9;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.api-request:empty {
  display: none;
}

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

.api-result-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.api-result-card a {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  min-height: 126px;
}

.api-result-card img,
.api-thumb-placeholder {
  width: 100%;
  height: 100%;
  min-height: 126px;
  object-fit: cover;
  background: #e8edf0;
}

.api-result-body {
  display: grid;
  align-content: start;
  gap: 7px;
  min-width: 0;
  padding: 12px;
}

.api-result-body strong {
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.api-result-body > span {
  color: var(--muted);
  font-size: 13px;
}

.api-meta,
.api-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.api-meta span,
.api-tags span {
  border-radius: 999px;
  background: #eef3f1;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  padding: 6px 8px;
}

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

@media (max-width: 760px) {
  .topbar,
  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

  .nav-tabs {
    width: 100%;
    justify-content: stretch;
  }

  .nav-tabs a,
  .nav-more summary {
    flex: 1;
    justify-content: center;
  }

  .nav-more {
    display: flex;
    flex: 1;
  }

  .nav-more-menu {
    right: 0;
  }

  .metric-grid,
  .link-grid {
    grid-template-columns: 1fr;
  }

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

  .api-form,
  .api-results,
  .revenue-summary,
  .run-status-grid {
    grid-template-columns: 1fr;
  }

  .api-actions,
  .revenue-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .revenue-controls label,
  .revenue-controls select,
  .revenue-controls input {
    width: 100%;
  }

  .api-result-card a {
    grid-template-columns: 128px minmax(0, 1fr);
  }

  .discovery-actions {
    flex-direction: column;
  }

  .crawl-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .crawl-controls label {
    justify-content: space-between;
  }

  table {
    min-width: 980px;
  }

  .pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .pagination-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .pagination-buttons {
    justify-content: flex-start;
  }

  .pagination-jump {
    justify-content: space-between;
  }
}
