/* ============================================================
   18-sites-hub.css - Sites page (region selector + site matrix)
   ============================================================ */

/* The hub is one tall block: size its row to content instead of the
   default equal-fraction rows, so nothing stretches or clips. */
.page-grid:has(> .grid-block[data-type="sites-hub"]) {
  grid-template-rows: auto;
  grid-auto-rows: auto;
}

.sh-root {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.sh-loading {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.sh-error { color: var(--rag-red); }

/* ---- Header: region selector + period ---- */
.sh-head {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  justify-content: space-between;
  gap: 12px;
}

.sh-regions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.sh-region {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 170px;
  padding: 12px 18px;
  background: var(--cad-panel);
  border: var(--cad-line);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}
.sh-region:hover { border-color: var(--accent-line-soft); }
.sh-region.is-active {
  background: var(--accent-fill);
  border-color: var(--accent-line);
  color: var(--accent-on-fill);
}
.sh-region-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
}
.sh-region-count {
  font-size: 11px;
  color: var(--text-muted);
}
.sh-region.is-active .sh-region-count { color: rgba(0, 0, 0, 0.65); }

.sh-period {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
}
.sh-period-range {
  margin-top: 2px;
}

/* ---- Section tabs ---- */
.sh-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--cad-border);
  overflow-x: auto;
}
.sh-tab {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  padding: 9px 16px;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.sh-tab:hover { color: var(--text-primary); }
.sh-tab.is-active {
  color: var(--text-primary);
  border-bottom-color: var(--accent-line);
}

/* ---- Matrix table ---- */
.sh-table-wrap {
  overflow: auto;
  max-height: calc(100vh - 300px);
  border: var(--cad-line);
  border-radius: var(--radius-sm);
  background: var(--cad-panel);
}

.sh-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  color: var(--text-primary);
}

.sh-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--cad-subpanel);
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  text-align: right;
  padding: 9px 12px;
  border-bottom: 1px solid var(--cad-border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.sh-table thead .sh-group-row + tr th { top: var(--sh-row1-h, 33px); }
.sh-table thead th.sh-group {
  cursor: default;
  text-align: center;
  color: var(--text-muted);
  border-bottom: 1px solid var(--cad-border-subtle);
}
.sh-table thead th:hover:not(.sh-group) { color: var(--text-primary); }

.sh-table .sh-name {
  position: sticky;
  left: 0;
  z-index: 2;
  text-align: left;
  min-width: 220px;
  max-width: 280px;
  background: var(--cad-panel);
  border-right: 1px solid var(--cad-border-subtle);
}
.sh-table thead .sh-name { z-index: 4; background: var(--cad-subpanel); }

.sh-table tbody th,
.sh-table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--cad-border-subtle);
  white-space: nowrap;
  vertical-align: middle;
}

.sh-name-main {
  display: block;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sh-name-sub {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
}

.sh-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.sh-cell.is-zero { color: var(--text-muted); }

/* Heatmap (top 3 per column only). Text stays the theme's primary colour
   -- white on dark, black on light -- over a pink (bad) or translucent
   green (good) fill that fades by rank: 1st full, 2nd 60%, 3rd 30%. */
.sh-table { --heat-bad: 255, 150, 150; --heat-bad-a: 0.55; --heat-good: 0, 230, 118; --heat-good-a: 0.32; }
[data-theme="light"] .sh-table { --heat-bad: 255, 170, 170; --heat-bad-a: 0.8; --heat-good: 0, 200, 100; --heat-good-a: 0.38; }

.sh-row td.sh-cell.is-heat-bad,
.sh-row td.sh-cell.is-heat-good {
  color: var(--text-primary);
  font-weight: 700;
}
.sh-row td.sh-cell.is-heat-bad.heat-1 { background: rgba(var(--heat-bad), var(--heat-bad-a)); }
.sh-row td.sh-cell.is-heat-bad.heat-2 { background: rgba(var(--heat-bad), calc(var(--heat-bad-a) * 0.6)); }
.sh-row td.sh-cell.is-heat-bad.heat-3 { background: rgba(var(--heat-bad), calc(var(--heat-bad-a) * 0.3)); }
.sh-row td.sh-cell.is-heat-good.heat-1 { background: rgba(var(--heat-good), var(--heat-good-a)); }
.sh-row td.sh-cell.is-heat-good.heat-2 { background: rgba(var(--heat-good), calc(var(--heat-good-a) * 0.6)); }
.sh-row td.sh-cell.is-heat-good.heat-3 { background: rgba(var(--heat-good), calc(var(--heat-good-a) * 0.3)); }
.sh-row td.sh-cell.is-heat-bad .sh-trend,
.sh-row td.sh-cell.is-heat-good .sh-trend { color: var(--text-primary); }

/* Region block: North / South rows (worse region per column in pink),
   then the All Sites total */
.sh-region-row.is-selected .sh-name { box-shadow: inset 4px 0 0 var(--accent-line); }
.sh-region-row.is-selected .sh-name-main::after {
  content: "  ▸ showing below";
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
}

/* All Sites total: standard RJM yellow so it stands out */
.sh-table .sh-total th,
.sh-table .sh-total td {
  background: var(--accent-fill);
  color: var(--accent-on-fill);
  font-weight: 700;
  border-top: 1px solid var(--accent-line);
  border-bottom: 1px solid var(--accent-line);
}
.sh-total td.sh-cell.is-zero,
.sh-total .sh-name-sub { color: rgba(0, 0, 0, 0.65); }
.sh-total .sh-trend { color: #000000; }

/* Mild gap between the region block and the site breakdown */
.sh-gap td {
  height: 30px;
  padding: 14px 12px 4px;
  background: var(--cad-bg);
  border-bottom: 1px solid var(--cad-border);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: left;
}
.sh-gap span {
  position: sticky;
  left: 12px;
}

.sh-row { cursor: pointer; }
.sh-row:hover th,
.sh-row:hover td,
.sh-row:focus th,
.sh-row:focus td { background: var(--cad-hover); }
.sh-row:focus { outline: none; }
.sh-row:focus .sh-name { box-shadow: inset 3px 0 0 var(--accent-line); }

.sh-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 24px;
}

.sh-spark { vertical-align: middle; }
.sh-trend {
  margin-left: 6px;
  font-size: 11px;
  font-weight: 700;
}
.sh-trend.bad { color: var(--rag-red); }
.sh-trend.good { color: var(--rag-green); }
.sh-trend.neutral { color: var(--text-secondary); }

.sh-note {
  margin: 0;
  font-size: 11px;
  color: var(--text-muted);
}

@media (max-width: 700px) {
  .sh-head { flex-direction: column; }
  .sh-period { align-items: flex-start; }
  .sh-region { min-width: 0; flex: 1 1 140px; }
  .sh-table .sh-name { min-width: 150px; }
}
