/*
 * Public Status page layout (kpubdata-watch#78).
 *
 * Colour comes only from the tokens brand-v2.css defines (var(--...)); no hex value
 * is written here. Layout follows docs/UI.md PRD §52 (light background, simple
 * border, minimal shadow, 8-12px radius, 8px spacing grid) and PRD §46 (dense when
 * Healthy, detailed only when there is an issue to explain).
 */

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  line-height: 1.5;
  overflow-x: hidden;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--card);
  color: var(--foreground);
  padding: 8px 16px;
  border-radius: 0 0 10px 0;
  z-index: 10;
}

.skip-link:focus {
  left: 0;
}

a {
  color: var(--brand-text);
}

/* ---- Product shell (#83): one content width for header, page and footer. ---- */

.product-shell {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
}

/* ---- Shell header: brand once, product navigation first, resources last. ---- */

.shell-header {
  border-bottom: 1px solid var(--border);
}

.shell-header-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 0;
}

.shell-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: inherit;
  text-decoration: none;
  flex: none;
}

.brand-symbol {
  display: block;
  width: 24px;
  height: 24px;
}

.brand-lockup {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
}

.brand-name {
  color: var(--foreground);
}

.brand-suffix {
  color: var(--muted-foreground);
  font-weight: 500;
  margin-left: 4px;
}

.primary-nav {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
}

.primary-nav ul {
  display: flex;
  gap: 4px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-item {
  display: inline-block;
  padding: 6px 10px;
  border-radius: var(--radius);
  color: var(--muted-foreground);
  font-size: var(--text-body);
  line-height: var(--text-body--line-height);
  text-decoration: none;
  white-space: nowrap;
}

a.nav-item:hover {
  color: var(--foreground);
  background: var(--muted);
}

.nav-item[aria-current="page"] {
  color: var(--foreground);
  background: var(--muted);
  font-weight: 600;
}

/* A surface that is not built yet: visible, but not a link. */
.nav-item.is-pending {
  cursor: default;
}

.secondary-nav {
  display: flex;
  gap: 16px;
  flex: none;
  font-size: var(--text-body);
}

.secondary-nav a {
  color: var(--muted-foreground);
}

/* ---- Preview data: stated plainly as metadata, never styled as a warning. ---- */

.preview-meta {
  margin: 0 0 16px;
  color: var(--muted-foreground);
  font-size: var(--text-meta);
  line-height: var(--text-meta--line-height);
}

/* ---- Page body ---- */

main {
  padding: 24px 0 48px;
}

.status-header h1 {
  font-size: 20px;
  line-height: 1.3;
  margin: 0 0 4px;
}

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

/* ---- Compact health summary: counts, not KPI cards. ---- */

.summary {
  margin-bottom: 24px;
}

.shell-footer {
  padding: 16px 0;
  border-top: 1px solid var(--border);
  color: var(--muted-foreground);
  font-size: var(--text-meta);
  line-height: var(--text-meta--line-height);
}

.shell-footer p {
  margin: 0;
}

/* ---- Overview (#84): issues first, then changes, then datasets. ---- */

.panel-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.panel-count {
  color: var(--muted-foreground);
  font-size: var(--text-table);
  line-height: var(--text-table--line-height);
  font-weight: 600;
}

.issue-list,
.change-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.issue-row,
.change-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.issue-row:first-child,
.change-row:first-child {
  padding-top: 0;
}

.issue-row:last-child,
.change-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.issue-head,
.change-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.issue-dataset {
  font-weight: 600;
  color: var(--foreground);
}

.issue-text,
.change-summary {
  margin: 4px 0 0;
}

.issue-meta,
.issue-history {
  margin: 4px 0 0;
  color: var(--muted-foreground);
  font-size: var(--text-table);
  line-height: var(--text-table--line-height);
}

.panel .dataset-list {
  border-top: 0;
}

.view-all {
  font-weight: 600;
}

/* ---- Detail pages (#86): a header, then main panels beside a metadata column. ---- */

.page-header {
  margin: 0 0 24px;
}

.page-eyebrow {
  margin: 0 0 4px;
  color: var(--muted-foreground);
  font-size: var(--text-body);
  line-height: var(--text-body--line-height);
}

.page-header h1 {
  margin: 0;
  font-size: var(--text-page-title);
  line-height: var(--text-page-title--line-height);
  font-weight: var(--text-page-title--font-weight);
}

.page-header .technical-id {
  margin: 4px 0 12px;
  color: var(--muted-foreground);
}

.page-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}

.check-list,
.event-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.check-row {
  display: grid;
  grid-template-columns: 120px auto minmax(0, 1fr);
  align-items: baseline;
  gap: 4px 12px;
  min-height: var(--density-table-row);
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.check-row:last-child,
.event-row:last-child {
  border-bottom: 0;
}

.check-name {
  font-weight: 600;
}

.check-summary,
.event-meta,
.panel-note {
  color: var(--muted-foreground);
  font-size: var(--text-table);
  line-height: var(--text-table--line-height);
}

.panel-note {
  margin: 8px 0 0;
}

.issue + .issue {
  margin-top: 16px;
}

.issue-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 4px;
  font-size: var(--text-body);
  line-height: var(--text-body--line-height);
}

.issue-summary {
  margin: 0 0 12px;
}

.issue .contract-diff {
  margin-bottom: 12px;
}

.event-row {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.event-row .event-meta,
.event-row .contract-diff {
  grid-column: 2;
}

@media (max-width: 900px) {
  .detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 480px) {
  .check-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .check-summary {
    grid-column: 1 / -1;
  }

  .event-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .event-row .event-meta,
  .event-row .contract-diff {
    grid-column: 1;
  }
}

/* ---- Narrow screens: navigation gets its own row and scrolls inside itself. ---- */

@media (max-width: 768px) {
  .shell-header-inner {
    flex-wrap: wrap;
    gap: 8px 16px;
  }

  .primary-nav {
    order: 3;
    flex-basis: 100%;
  }
}

/* ---- No page-level horizontal scroll at 390px. ---- */

@media (max-width: 390px) {
  .product-shell {
    width: calc(100% - 24px);
  }

  main {
    padding: 16px 0 32px;
  }
}

/* ---- Incident and Change detail (#87). ---- */

.incident-status {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: var(--text-table);
  line-height: var(--text-table--line-height);
  font-weight: 600;
}

.evidence-values {
  list-style: none;
  margin: 0;
  padding: 0;
}

.evidence-values code {
  font-family: var(--font-mono);
  font-size: var(--text-technical);
  line-height: var(--text-technical--line-height);
  overflow-wrap: anywhere;
}

.raw-evidence {
  margin: 0 0 24px;
  color: var(--muted-foreground);
  font-size: var(--text-table);
}

.raw-evidence summary {
  cursor: pointer;
}

.raw-evidence pre {
  margin: 8px 0 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--muted);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-technical);
  line-height: var(--text-technical--line-height);
}

/* ---- Dataset catalog (#85): filters above a table whose whole row is a link. ---- */

.catalog-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin: 0 0 16px;
}

.catalog-filters[hidden] {
  display: none;
}

.filter {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: var(--text-table);
  line-height: var(--text-table--line-height);
}

.filter-search {
  flex: 1 1 240px;
}

.filter-label {
  color: var(--muted-foreground);
}

.filter input[type="search"],
.filter select {
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--foreground);
  font: inherit;
  font-size: var(--text-body);
}

.filter-toggle {
  flex-direction: row;
  align-items: center;
  min-height: 36px;
}

.filter input:focus-visible,
.filter select:focus-visible,
.row-link:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* A wide table scrolls inside itself; the page never scrolls sideways. */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
}

.catalog-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-table);
  line-height: var(--text-table--line-height);
}

.catalog-table th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted-foreground);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.catalog-table td {
  height: var(--density-table-row);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.catalog-row:last-child td {
  border-bottom: 0;
}

.catalog-row:hover {
  background: var(--muted);
  cursor: pointer;
}

.row-link {
  color: var(--foreground);
  font-weight: 600;
  text-decoration: none;
}

.catalog-row .technical-id {
  display: block;
  color: var(--muted-foreground);
}

.muted {
  color: var(--muted-foreground);
}

.catalog-table + .empty-state,
.table-scroll + .empty-state {
  margin-top: 16px;
}

/* ---- History (issue 109): date-grouped timeline below the heatmap. ---- */

.timeline-date {
  margin: 20px 0 4px;
  font-size: var(--text-table);
  line-height: var(--text-table--line-height);
  color: var(--muted-foreground);
  font-weight: 600;
}

.timeline-date:first-child {
  margin-top: 0;
}
