:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --text: #111827;
  --muted: #687386;
  --line: #e5e9ef;
  --line-strong: #d8dee8;
  --accent: #0f766e;
  --accent-soft: #e8f5f2;
  --accent-strong: #0b5d56;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --warn: #9a6700;
  --warn-soft: #fff8db;
  --success: #11734b;
  --success-soft: #eaf8f0;
  --shadow: 0 12px 40px rgba(15, 23, 42, 0.07);
  --radius: 18px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(15, 118, 110, 0.05), transparent 28rem),
    var(--bg);
}

button,
select {
  font: inherit;
}

button,
select,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
select:focus-visible,
a:focus-visible,
tr[tabindex]:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: 2px;
}

.app-shell {
  width: min(1480px, calc(100% - 40px));
  margin: 0 auto;
  padding: 30px 0 56px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 7px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
}

.title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: clamp(30px, 4vw, 42px);
  line-height: 1;
  letter-spacing: -0.045em;
}

h2 {
  margin-bottom: 0;
  font-size: 23px;
  letter-spacing: -0.025em;
}

h3 {
  margin-bottom: 0;
  font-size: 18px;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.08em;
}

.badge-neutral {
  color: #4b5563;
  background: #e9edf2;
}

.badge-live {
  color: var(--success);
  background: var(--success-soft);
}

.topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  box-shadow: 0 0 0 5px rgba(156, 163, 175, 0.11);
}

.status-dot.live {
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(17, 115, 75, 0.11);
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 5px rgba(180, 35, 24, 0.11);
}

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

.panel {
  background: var(--panel);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.controls-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(410px, 1.7fr) auto;
  align-items: end;
  gap: 16px;
  padding: 16px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label,
.period-field legend {
  font-size: 12px;
  font-weight: 750;
  color: var(--muted);
}

select {
  width: 100%;
  min-height: 42px;
  padding: 0 38px 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  color: var(--text);
  background: var(--panel);
}

.period-field {
  margin: 0;
  padding: 0;
  border: 0;
}

.period-field legend {
  margin-bottom: 7px;
}

.segmented-control {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(70px, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
}

.segmented-control button {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.segmented-control button:hover {
  color: var(--text);
  background: #eef1f5;
}

.segmented-control button.active {
  color: var(--accent-strong);
  background: var(--panel);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.09);
}

.segmented-control.compact {
  grid-auto-columns: minmax(78px, 1fr);
}

.button {
  min-height: 42px;
  padding: 0 15px;
  border-radius: 11px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.button-secondary {
  color: #334155;
  border-color: var(--line-strong);
  background: var(--panel);
}

.button-secondary:not(:disabled):hover {
  border-color: #bdc7d5;
  background: #f8fafc;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.kpi-card {
  min-width: 0;
  padding: 19px;
  border: 1px solid rgba(226, 232, 240, 0.92);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 7px 28px rgba(15, 23, 42, 0.045);
}

.kpi-label {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.kpi-value {
  margin-bottom: 7px;
  font-size: clamp(28px, 4vw, 38px);
  line-height: 1;
  font-weight: 780;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.kpi-meta {
  color: #9aa3b1;
  font-size: 11px;
}

.coverage-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 76px;
  padding: 15px 18px;
  border: 1px solid #f0d58b;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
}

.coverage-card.complete {
  border-color: #bee8d1;
  background: var(--success-soft);
}

.coverage-title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 4px;
  font-size: 13px;
}

.coverage-icon {
  color: var(--warn);
  font-size: 9px;
}

.coverage-card.complete .coverage-icon {
  color: var(--success);
}

.coverage-card p {
  margin: 0;
  color: #765912;
  font-size: 12px;
}

.coverage-card.complete p {
  color: #35654e;
}

.coverage-range {
  flex: 0 0 auto;
  color: #765912;
  font-size: 12px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.coverage-card.complete .coverage-range {
  color: #35654e;
}

.alert {
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
}

.alert-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: #8d2119;
  border: 1px solid #f3c6c2;
  background: var(--danger-soft);
}

.button-error-retry {
  flex: 0 0 auto;
  min-height: 34px;
  padding-inline: 12px;
  color: #8d2119;
  border-color: #e7aaa5;
  background: #ffffff;
}

.button-error-retry:hover {
  background: #fff8f7;
}

.hidden {
  display: none !important;
}

.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 19px 20px 15px;
}

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

.inline-field {
  min-width: 125px;
}

.inline-field select {
  min-height: 42px;
}

.table-status {
  min-height: 26px;
  padding: 0 20px 8px;
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transition: opacity 140ms ease;
}

.table-wrap.is-loading {
  opacity: 0.52;
  pointer-events: none;
}

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

th,
td {
  height: 54px;
  padding: 10px 14px;
  border-bottom: 1px solid #edf0f4;
  text-align: left;
  vertical-align: middle;
  font-size: 12.5px;
}

th {
  height: 43px;
  color: var(--muted);
  background: #fbfcfd;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.035em;
  text-transform: uppercase;
}

.sort-header {
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}

.sort-header:hover,
.sort-header.active {
  color: var(--accent-strong);
}

tbody tr {
  cursor: pointer;
  transition: background 120ms ease;
}

tbody tr:hover {
  background: #f8fbfa;
}

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

.title-col {
  width: 42%;
}

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

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

.listing-cell-content {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.listing-title {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 720;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.listing-id {
  color: #9aa3b1;
  font-size: 10.5px;
  line-height: 1.15;
}

.account-cell {
  overflow: hidden;
  color: #475569;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  color: #475569;
  background: #eef2f6;
  font-size: 10.5px;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill.active,
.status-pill.enabled {
  color: var(--success);
  background: var(--success-soft);
}

.empty-state {
  min-height: 180px;
  display: grid;
  place-content: center;
  gap: 5px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.empty-state strong {
  color: var(--text);
  font-size: 15px;
}

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

.pagination #pageInfo {
  min-width: 88px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.detail-dialog {
  width: min(1020px, calc(100% - 28px));
  max-height: calc(100vh - 36px);
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 20px;
  background: var(--panel);
  box-shadow: 0 28px 90px rgba(15, 23, 42, 0.28);
}

.detail-dialog::backdrop {
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
}

.detail-shell {
  max-height: calc(100vh - 36px);
  overflow: auto;
}

.detail-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
}

.detail-heading {
  min-width: 0;
}

.detail-heading h2 {
  max-width: 760px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
}

.icon-button {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: #475569;
  background: var(--panel);
  font-size: 25px;
  line-height: 1;
  cursor: pointer;
}

.detail-loading {
  padding: 18px 20px;
  color: var(--muted);
  font-size: 13px;
}

.detail-dialog .alert {
  margin: 18px 20px 0;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 20px;
}

.mini-card {
  display: grid;
  gap: 8px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-soft);
}

.mini-card span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
}

.mini-card strong {
  font-size: 24px;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.detail-facts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  margin: 0 20px 20px;
  border: 1px solid var(--line);
  border-radius: 13px;
  overflow: hidden;
}

.detail-facts > div {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 12px;
  min-height: 48px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.detail-facts > div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.detail-facts > div:nth-child(odd) {
  border-right: 1px solid var(--line);
}

.detail-facts span {
  color: var(--muted);
  font-size: 11px;
}

.detail-facts strong,
.detail-facts a {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-facts a {
  color: var(--accent-strong);
}

.detail-link-row {
  grid-column: 1 / -1;
  border-right: 0 !important;
}

.history-section {
  padding-bottom: 22px;
}

.history-header {
  align-items: center;
  padding-top: 4px;
}

.history-note {
  max-width: 360px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.history-table-wrap {
  margin: 0 20px;
  width: auto;
  border: 1px solid var(--line);
  border-radius: 13px;
}

.history-table-wrap table {
  min-width: 600px;
}

.history-table-wrap tbody tr {
  cursor: default;
}

@media (max-width: 920px) {
  .app-shell {
    width: min(100% - 24px, 1480px);
    padding-top: 20px;
  }

  .controls-panel {
    grid-template-columns: 1fr 1.4fr;
  }

  .controls-panel > .button {
    grid-column: 1 / -1;
  }

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

  .title-col {
    width: 34%;
  }
}

@media (max-width: 660px) {
  .app-shell {
    width: min(100% - 16px, 1480px);
    padding-top: 16px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .topbar-status {
    align-self: flex-start;
  }

  .controls-panel {
    grid-template-columns: 1fr;
    padding: 13px;
  }

  .controls-panel > .button {
    grid-column: auto;
  }

  .segmented-control {
    width: 100%;
    grid-auto-columns: 1fr;
  }

  .segmented-control button {
    padding-inline: 7px;
  }

  .kpi-grid {
    gap: 8px;
  }

  .kpi-card {
    padding: 15px;
    border-radius: 14px;
  }

  .kpi-value {
    font-size: 28px;
  }

  .coverage-card {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .section-header {
    align-items: stretch;
    flex-direction: column;
    padding: 16px 14px 12px;
  }

  .ranking-controls {
    width: 100%;
  }

  .ranking-controls .segmented-control {
    flex: 1 1 auto;
  }

  .inline-field {
    min-width: 108px;
  }

  .table-status {
    padding-inline: 14px;
  }

  table {
    min-width: 650px;
  }

  .table-wrap:not(.history-table-wrap) th:first-child,
  .table-wrap:not(.history-table-wrap) td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--panel);
    box-shadow: 8px 0 14px rgba(15, 23, 42, 0.04);
  }

  .table-wrap:not(.history-table-wrap) th:first-child {
    z-index: 2;
    background: #fbfcfd;
  }

  tbody tr:hover td:first-child {
    background: #f8fbfa;
  }

  th,
  td {
    padding-inline: 10px;
  }

  .pagination {
    justify-content: space-between;
    padding: 12px 14px;
  }

  .detail-dialog {
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  .detail-shell {
    max-height: 100vh;
  }

  .detail-header {
    padding: 16px;
  }

  .detail-heading h2 {
    max-width: calc(100vw - 88px);
    white-space: normal;
  }

  .detail-grid {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .detail-facts {
    grid-template-columns: 1fr;
    margin-inline: 16px;
  }

  .detail-facts > div,
  .detail-facts > div:nth-child(odd) {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .detail-facts > div:last-child {
    border-bottom: 0;
  }

  .history-header {
    padding-inline: 16px;
  }

  .history-note {
    text-align: left;
  }

  .history-table-wrap {
    margin-inline: 16px;
  }
}

@media (max-width: 430px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

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

  .button-error-retry {
    width: 100%;
  }

  .pagination {
    gap: 8px;
  }

  .pagination .button {
    padding-inline: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}

.controls-panel.is-busy,
.ranking-controls.is-busy {
  opacity: 0.76;
}

body.is-busy {
  cursor: progress;
}

body.is-busy button,
body.is-busy select {
  cursor: progress;
}
