* { box-sizing: border-box; }

[hidden] { display: none !important; }

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
}

:root {
  --horizon-muted: #667085;
  --horizon-kicker: #c2410c;
  --horizon-success: #15803d;
  --horizon-focus: #0d6efd;
}

[data-bs-theme="dark"] {
  --horizon-muted: #a7b1bf;
  --horizon-kicker: #ff9a62;
  --horizon-success: #4ade80;
  --horizon-focus: #58a6ff;
}

button,
input { font: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.btn:focus-visible,
.table-shell:focus-visible {
  outline: 2px solid var(--horizon-focus);
  outline-offset: 2px;
  box-shadow: none;
}

button.btn-primary {
  background: #0d6efd;
  border-color: #0d6efd;
  color: #fff;
}

button.btn-primary:hover:not(:disabled) {
  background: var(--btn-primary-hover-bg);
  border-color: var(--btn-primary-hover-bg);
}

.horizon-app { min-height: 100vh; }

.app-bar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 0 var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  background: color-mix(in srgb, var(--surface-0) 94%, transparent);
  backdrop-filter: blur(8px);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-primary);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  text-decoration: none;
}

.wordmark-mark {
  display: inline-grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--brand-orange);
  color: #111827;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
}

.track-label,
.environment-label,
.count-label {
  color: var(--horizon-muted);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.track-label {
  padding-left: var(--space-2);
  border-left: 1px solid var(--border-default);
}

.app-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

main {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: var(--space-8) 0 var(--space-16);
}

.loading-view,
.error-view {
  display: grid;
  min-height: calc(100vh - 180px);
  place-content: center;
  justify-items: center;
  color: var(--text-secondary);
  text-align: center;
}

.loader {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-default);
  border-top-color: var(--text-link);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(1turn); } }

.login-view {
  display: grid;
  min-height: calc(100vh - 160px);
  place-items: center;
}

.login-panel {
  width: min(100%, 380px);
  padding: var(--space-8);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  box-shadow: var(--shadow-md);
}

.section-kicker {
  margin-bottom: var(--space-2);
  color: var(--horizon-kicker);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: .08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: var(--space-2);
  font-size: var(--font-size-xl);
  line-height: var(--line-height-tight);
}

h2 {
  margin-bottom: var(--space-1);
  font-size: var(--font-size-lg);
}

.login-intro,
.page-heading p,
.section-heading p {
  color: var(--text-secondary);
  line-height: var(--line-height-normal);
}

.login-panel form {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-6);
}

.login-panel label {
  margin-top: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
}

.login-panel input {
  width: 100%;
  height: 38px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  outline: 0;
  background: var(--surface-0);
  color: var(--text-primary);
}

.login-panel input:focus {
  border-color: var(--text-link);
  outline: 2px solid var(--horizon-focus);
  outline-offset: 1px;
  box-shadow: none;
}

.login-submit { margin-top: var(--space-4); }

.form-error {
  margin: var(--space-2) 0 0;
  color: var(--status-error);
  font-size: var(--font-size-sm);
}

.trust-note {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
  color: var(--horizon-muted);
  font-size: var(--font-size-xs);
}

.page-heading,
.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-6);
}

.identity-block {
  display: grid;
  min-width: 180px;
  justify-items: end;
  color: var(--text-primary);
  font-weight: var(--font-weight-medium);
}

.identity-block small {
  margin-top: var(--space-1);
  color: var(--horizon-muted);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-normal);
}

.notice {
  margin: var(--space-5) 0;
  padding: var(--space-3) var(--space-4);
  border: 1px solid color-mix(in srgb, var(--status-info) 35%, var(--border-subtle));
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--status-info) 7%, var(--surface-0));
  color: var(--text-secondary);
  line-height: var(--line-height-normal);
}

.notice strong { color: var(--text-primary); }

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.status-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 64px;
  padding: var(--space-3) var(--space-4);
  border-right: 1px solid var(--border-subtle);
}

.status-item:last-child { border-right: 0; }

.status-item > span:last-child { display: grid; }

.status-item strong {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
}

.status-item small {
  margin-top: var(--space-1);
  color: var(--horizon-muted);
  font-size: var(--font-size-xs);
}

.status-dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot--ready { background: var(--horizon-success); }

.content-section { margin-top: var(--space-8); }

.section-heading { margin-bottom: var(--space-3); }

.section-heading p { margin-bottom: 0; }

.count-label { padding-top: var(--space-1); }

.table-shell {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.table-scroll-hint {
  display: none;
  margin: 0 0 var(--space-2);
  color: var(--horizon-muted);
  font-size: var(--font-size-xs);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface-2);
  text-align: left;
}

th,
td {
  height: 40px;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

th {
  background: var(--table-header-bg);
  color: var(--horizon-muted);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: .04em;
  text-transform: uppercase;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--hover-bg); }
.cell-primary { font-weight: var(--font-weight-medium); }

.table-empty {
  height: 72px;
  color: var(--horizon-muted);
  text-align: center;
}

.state-badge {
  display: inline-flex;
  padding: 2px 7px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  line-height: var(--line-height-normal);
}

.state-badge--success {
  border-color: color-mix(in srgb, var(--status-success) 45%, var(--border-subtle));
  background: color-mix(in srgb, var(--status-success) 8%, var(--surface-0));
  color: var(--horizon-success);
}

.state-badge--warning {
  border-color: color-mix(in srgb, var(--status-warning) 55%, var(--border-subtle));
  color: var(--text-secondary);
}

@media (max-width: 760px) {
  .app-bar { padding: 0 var(--space-4); }
  .environment-label { display: none; }
  main { width: min(100% - 32px, 1180px); padding-top: var(--space-6); }
  .page-heading { display: block; }
  .identity-block { justify-items: start; margin-top: var(--space-4); }
  .status-strip { grid-template-columns: 1fr 1fr; }
  .status-item:nth-child(2) { border-right: 0; }
  .status-item:nth-child(-n+2) { border-bottom: 1px solid var(--border-subtle); }
  .table-scroll-hint { display: block; }
}

@media (max-width: 480px) {
  .track-label { display: none; }
  .app-actions { gap: var(--space-1); }
  .login-panel { padding: var(--space-5); }
  .status-strip { grid-template-columns: 1fr; }
  .status-item { border-right: 0; border-bottom: 1px solid var(--border-subtle); }
  .status-item:nth-child(3) { border-bottom: 1px solid var(--border-subtle); }
  .status-item:last-child { border-bottom: 0; }
  .section-heading { display: block; }
  .count-label { display: inline-block; margin-top: var(--space-2); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; }
}
