/* Base layout and component styles. Tokens come from /ui/tokens.css. */
* {
  box-sizing: border-box;
}
html {
  background: var(--bg);
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-body) / 1.5 var(--font-sans);
  transition:
    background-color var(--motion),
    color var(--motion);
}
a {
  color: var(--text);
  text-decoration: underline;
}
.mono {
  font-family: var(--font-mono);
}
.tnum {
  font-variant-numeric: tabular-nums;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
[hidden] {
  display: none !important;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--sp-2) var(--gutter);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3) var(--sp-4);
}
.brand {
  font-size: var(--fs-section);
  font-weight: 600;
  margin-right: auto;
}
.tabs {
  display: flex;
  gap: var(--sp-1);
}
.tab {
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-control);
  color: var(--text-2);
  text-decoration: none;
}
.tab[aria-current="page"] {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}
.meta {
  font-size: var(--fs-meta);
  color: var(--text-2);
}

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--sp-5) var(--gutter) var(--sp-7);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}
h1 {
  font-size: var(--fs-title);
  font-weight: 600;
  margin: 0;
}
h2 {
  font-size: var(--fs-section);
  font-weight: 600;
  margin: 0;
}

/* Controls */
.btn,
select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: var(--sp-1) var(--sp-3);
  min-height: 32px;
  cursor: pointer;
  transition: background-color var(--motion);
}
.btn:hover,
select:hover {
  background: var(--surface-2);
}
.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  overflow: hidden;
}
.segmented button {
  font: inherit;
  color: var(--text-2);
  background: var(--surface);
  border: 0;
  padding: var(--sp-1) var(--sp-3);
  min-height: 32px;
  cursor: pointer;
}
.segmented button[aria-pressed="true"] {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}

/* Panel / card */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--card-pad);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-width: 0;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
}
@media (min-width: 1024px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

/* Verdict */
.verdict {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: var(--radius-card);
  padding: var(--sp-4);
  flex-wrap: wrap;
}
.verdict[data-state="ok"] {
  border-left-color: var(--good);
}
.verdict[data-state="degraded"] {
  border-left-color: var(--warning);
}
.verdict[data-state="down"] {
  border-left-color: var(--critical);
}
.verdict-icon {
  font-size: var(--fs-title);
  font-weight: 700;
  width: 28px;
  text-align: center;
}
.verdict-word {
  font-size: var(--fs-title);
  font-weight: 600;
}
.verdict-text {
  color: var(--text-2);
}

/* KPI tiles */
.kpis {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
}
@media (min-width: 640px) {
  .kpis {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (min-width: 1024px) {
  .kpis {
    grid-template-columns: repeat(4, 1fr);
  }
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--card-pad);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  min-width: 0;
}
.overline {
  font-size: var(--fs-overline);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.kpi-value {
  font-size: var(--fs-hero);
  font-weight: 600;
  line-height: 1.2;
}
.kpi-unit {
  font-size: var(--fs-body);
  font-weight: 400;
  color: var(--text-2);
  margin-left: var(--sp-1);
}
.kpi-delta {
  font-size: var(--fs-meta);
  color: var(--text-2);
}
.kpi-spark {
  margin-top: var(--sp-1);
}

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 20px;
  padding: 0 var(--sp-2);
  border-radius: var(--radius-pill);
  font-size: var(--fs-meta);
  color: var(--text);
  background: color-mix(in srgb, var(--pill-color, var(--muted)) 12%, transparent);
  white-space: nowrap;
}
.pill-icon {
  color: var(--pill-color, var(--muted));
  font-weight: 700;
}
.pill[data-state="ok"] {
  --pill-color: var(--good);
}
.pill[data-state="degraded"] {
  --pill-color: var(--warning);
}
.pill[data-state="down"] {
  --pill-color: var(--critical);
}
.pill[data-state="unknown"] {
  --pill-color: var(--muted);
}
.pill[data-stage] {
  --pill-color: var(--accent);
}
.pill[data-stage="Unused"] {
  --pill-color: var(--muted);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th,
td {
  height: 36px;
  padding: 0 var(--sp-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  font-size: var(--fs-meta);
  font-weight: 600;
  color: var(--muted);
}
th.num,
td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
tbody tr:hover {
  background: var(--surface-2);
}
th button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
@media (max-width: 639px) {
  th:first-child,
  td:first-child {
    position: sticky;
    left: 0;
    background: var(--surface);
  }
}

/* Data states */
.skeleton {
  background: var(--surface-2);
  border-radius: var(--radius-control);
  min-height: 48px;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  50% {
    opacity: 0.5;
  }
}
.state-empty {
  text-align: center;
  color: var(--text-2);
  padding: var(--sp-6) var(--sp-4);
}
.badge-stale {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 20px;
  padding: 0 var(--sp-2);
  border-radius: var(--radius-pill);
  font-size: var(--fs-meta);
  background: color-mix(in srgb, var(--warning) 12%, transparent);
}
.error-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-left: 4px solid var(--critical);
  border-radius: var(--radius-control);
  background: var(--surface);
}

.error-body {
  flex: 1 1 20rem;
}
.error-body p {
  margin: var(--sp-1) 0 0;
  color: var(--text-2);
}

/* Charts */
.chart {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.chart svg {
  width: 100%;
  height: auto;
  display: block;
}
.chart .axis {
  font-size: var(--fs-meta);
  fill: var(--muted);
}
.chart .grid {
  stroke: var(--grid);
  stroke-width: 1;
}
.legend {
  display: flex;
  gap: var(--sp-4);
  flex-wrap: wrap;
  font-size: var(--fs-meta);
  color: var(--text-2);
}
.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 6px;
}
/* A series that is intentionally absent (for example "Pro: Payments off"): hollow, muted. */
.legend-swatch[data-off] {
  border: 1px dashed var(--muted);
}
.legend-note[data-muted] {
  color: var(--muted);
}
.strip {
  display: flex;
  gap: 2px;
  align-items: center;
}
.strip-cell {
  flex: 1 1 0;
  min-width: 2px;
  max-width: 6px;
  height: 20px;
  border-radius: 1px;
  background: var(--surface-2);
}
.strip-cell[data-state="ok"] {
  background: var(--good);
}
.strip-cell[data-state="degraded"] {
  background: var(--warning);
}
.strip-cell[data-state="down"] {
  background: var(--critical);
}
.strip-wrap {
  overflow-x: auto;
}

/* Tablist (WAI-ARIA tabs, manual activation) */
.tabset [role="tablist"] {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-4);
  overflow-x: auto;
}
.tabset [role="tab"] {
  padding: var(--sp-2) var(--sp-3);
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-2);
  font: inherit;
  cursor: pointer;
}
.tabset [role="tab"][aria-selected="true"] {
  border-bottom-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

/* Glossary toggletip */
.toggletip {
  position: relative;
  display: inline-flex;
  vertical-align: middle;
  margin-left: var(--sp-1);
}
.term-button {
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: var(--fs-meta);
  line-height: 1;
  text-transform: none;
  cursor: pointer;
}
.term-button[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--text);
}
.toggletip-bubble {
  position: absolute;
  top: calc(100% + var(--sp-1));
  left: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  width: max-content;
  max-width: min(20rem, 80vw);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-meta);
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
  white-space: normal;
}
.toggletip-line {
  display: block;
}

/* Shared chart tooltip */
.chart-plot {
  position: relative;
}
.chart-tooltip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  max-width: min(18rem, 90%);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-meta);
  pointer-events: none;
}
.chart-tooltip-title {
  font-weight: 600;
}
.chart-tooltip-row {
  display: block;
}

/* KPI delta tones: a marker plus the "Better"/"Worse" text, never color alone */
.kpi-delta[data-tone="good"],
.kpi-delta[data-tone="bad"] {
  padding-left: var(--sp-2);
  border-left: 3px solid var(--good);
  color: var(--text);
}
.kpi-delta[data-tone="bad"] {
  border-left-color: var(--critical);
}
.kpi-tone {
  font-weight: 600;
}

/* Paginated table */
.table-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}
.table-tools input[type="search"] {
  padding: var(--sp-1) var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.table-tools p {
  margin: 0;
  font-size: var(--fs-meta);
  color: var(--text-2);
}
.table-pager {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
.chart {
  margin: 0;
}
.chart .axis-strong {
  fill: var(--text);
}

/* Muted tile (for example "Payments off") */
.kpi[data-muted="true"] {
  background: var(--surface-2);
}
.kpi[data-muted="true"] .kpi-value {
  color: var(--muted);
}

/* Coverage notices */
.notice {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-left: 4px solid var(--warning);
  border-radius: var(--radius-control);
  background: var(--surface);
}
.notice[data-kind="info"] {
  border-left-color: var(--accent);
}
.notice-title {
  font-weight: 600;
}
.notice p {
  margin: 0;
  color: var(--text-2);
}

/* Forms */
.field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-3);
}
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
input[type="date"] {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: var(--sp-1) var(--sp-3);
  min-height: 32px;
}
.mono-cell {
  font-family: var(--font-mono);
}
.notices {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

/* Landing page MCP command block: scrolls inside itself at 360 px, never widens the page. */
.code-block {
  overflow-x: auto;
  max-width: 100%;
  margin: 0;
  padding: var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  font-family: var(--font-mono);
}

/* Threshold progress meter (shared component ProgressMeter) */
.meter {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.meter-head {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
}
.meter-bar {
  appearance: none;
  width: 100%;
  height: var(--sp-2);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  accent-color: var(--accent);
}
.meter-bar::-webkit-progress-bar {
  background: var(--surface-2);
  border-radius: var(--radius-pill);
}
.meter-bar::-webkit-progress-value {
  background: var(--accent);
  border-radius: var(--radius-pill);
}
.meter-bar::-moz-progress-bar {
  background: var(--accent);
  border-radius: var(--radius-pill);
}

/* Admin shell: skip link, sidebar, header bar, breadcrumb, page template, alerts */
.skip-link {
  position: absolute;
  left: var(--sp-2);
  top: var(--sp-2);
  z-index: 20;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  transform: translateY(-200%);
}
.skip-link:focus {
  transform: none;
}
.shell {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  max-width: var(--max-width);
  margin: 0 auto;
}
.shell-main {
  min-width: 0;
}
.shell-main main {
  max-width: none;
}
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  width: 240px;
  padding: var(--sp-4) var(--sp-3);
  border-right: 1px solid var(--border);
}
.sidebar[data-collapsed="true"] {
  width: 72px;
}
.sidebar-phone {
  display: none;
}
.sidebar-collapse {
  align-self: flex-end;
}
.sidebar-group ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.sidebar-heading {
  font-size: var(--fs-overline);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 var(--sp-1);
}
.sidebar-link {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1) var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-control);
  color: var(--text-2);
  text-decoration: none;
}
.sidebar-link:hover {
  background: var(--surface-2);
}
.sidebar-link[aria-current="page"] {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}
.sidebar-icon {
  width: 1.25em;
  text-align: center;
}
.sidebar-short {
  display: none;
  font-size: var(--fs-overline);
}
.sidebar-status {
  flex-basis: 100%;
  font-size: var(--fs-meta);
  color: var(--text-2);
}
.sidebar-status[data-state="ok"] {
  color: var(--good);
}
.sidebar[data-collapsed="true"] .sidebar-short {
  display: block;
}
.sidebar[data-collapsed="true"] .sidebar-label,
.sidebar[data-collapsed="true"] .sidebar-status,
.sidebar[data-collapsed="true"] .sidebar-heading {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.header-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-4);
  padding: var(--sp-3) var(--gutter);
  border-bottom: 1px solid var(--border);
}
.header-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}
.header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1) var(--sp-4);
  flex-basis: 100%;
}
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: var(--fs-meta);
  color: var(--text-2);
}
.breadcrumb li {
  display: inline-flex;
  gap: var(--sp-1);
}
.breadcrumb-sep {
  color: var(--muted);
}
.breadcrumb [aria-current="page"] {
  color: var(--text);
  font-weight: 600;
}
.page,
.page-pane {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-width: 0;
}
.page-header {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.page-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
}
.page-subtitle,
.page-summary {
  margin: 0;
  color: var(--text-2);
}
.page-summary {
  color: var(--text);
}
.scope-badge {
  display: inline-block;
  padding: 0 var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-meta);
}
.section {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--card-pad);
}
.section-title {
  margin: 0;
}
.section-toggle {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.section-desc {
  margin: 0;
  color: var(--text-2);
}
.section-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
}
.page-skeleton {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
.page-skeleton-title {
  min-height: 32px;
  max-width: 320px;
}
.page-skeleton-kpi {
  min-height: 88px;
}
.page-skeleton-section {
  min-height: 160px;
}
.alert {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-left: 4px solid var(--warning);
  border-radius: var(--radius-control);
  background: var(--surface);
}
.alert[data-state="degraded"] {
  border-left-color: var(--warning);
}
.alert[data-state="down"] {
  border-left-color: var(--critical);
}
.alert-icon {
  font-weight: 700;
  width: 1.25em;
  text-align: center;
}
.alert-body p {
  margin: var(--sp-1) 0 0;
  color: var(--text-2);
}
.alert-title {
  font-weight: 600;
}
.alert-detail {
  color: var(--text);
}

@media (max-width: 600px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar,
  .sidebar[data-collapsed="true"] {
    position: static;
    width: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-phone {
    display: block;
  }
  .sidebar-collapse {
    display: none;
  }
  .sidebar nav[data-open="false"] {
    display: none;
  }
  .header-controls {
    margin-left: 0;
  }
}
