:root {
  --stox-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --stox-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --stox-accent: #2c6fe4;
  --stox-up: #187a33;
  --stox-down: #cc2531;
  --stox-flat: #6b7585;
  --stox-warn: #96660a;
  --stox-surface: #ffffff;
  --stox-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.04);
  --stox-shadow-lg: 0 12px 40px rgba(16, 24, 40, 0.16);
  --stox-radius: 0.625rem;
  --bs-body-bg: #f6f7f9;
  --bs-body-color: #1b2330;
  --bs-secondary-color: #5d6878;
  --bs-border-color: #e4e8ee;
  --bs-tertiary-bg: #eef1f5;
  --bs-secondary-bg: #e6eaf0;
  --bs-success: var(--stox-up);
  --bs-success-rgb: 24, 122, 51;
  --bs-danger: var(--stox-down);
  --bs-danger-rgb: 204, 37, 49;
  --bs-warning: var(--stox-warn);
  --bs-warning-rgb: 150, 102, 10;
  --bs-primary: var(--stox-accent);
  --bs-primary-rgb: 44, 111, 228;
  --bs-info: var(--stox-accent);
  --bs-info-rgb: 44, 111, 228;
}

[data-bs-theme="dark"] {
  --stox-accent: #58a6ff;
  --stox-up: #3fb950;
  --stox-down: #f85149;
  --stox-flat: #8b949e;
  --stox-warn: #d29922;
  --stox-surface: #10151d;
  --stox-shadow: none;
  --stox-shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
  --bs-body-bg: #0b0f15;
  --bs-body-color: #dbe2ea;
  --bs-secondary-color: #93a0b0;
  --bs-border-color: #222a36;
  --bs-tertiary-bg: #121823;
  --bs-secondary-bg: #1a2230;
  --bs-success: var(--stox-up);
  --bs-success-rgb: 63, 185, 80;
  --bs-danger: var(--stox-down);
  --bs-danger-rgb: 248, 81, 73;
  --bs-warning: var(--stox-warn);
  --bs-warning-rgb: 210, 153, 34;
  --bs-primary: var(--stox-accent);
  --bs-primary-rgb: 88, 166, 255;
  --bs-info: var(--stox-accent);
  --bs-info-rgb: 88, 166, 255;
}

body {
  font-family: var(--stox-font);
  font-size: 0.9375rem;
  background-color: var(--bs-body-bg);
  transition: background-color 0.2s ease, color 0.2s ease;
}

body[data-density="compact"] {
  font-size: 0.8125rem;
}

body[data-density="compact"] .card-body,
body[data-density="compact"] .panel-body {
  padding: 0.625rem 0.75rem;
}

body[data-density="compact"] .table > :not(caption) > * > * {
  padding: 0.25rem 0.5rem;
}

.num {
  font-family: var(--stox-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.num-lg {
  font-family: var(--stox-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.1;
}

.num-xl {
  font-family: var(--stox-mono);
  font-variant-numeric: tabular-nums;
  font-size: 3rem;
  font-weight: 650;
  line-height: 1;
  letter-spacing: -0.025em;
}

body[data-density="compact"] .num-xl {
  font-size: 2.25rem;
}

.hero {
  padding: 1.25rem 0 1.5rem;
  border-bottom: 1px solid var(--bs-border-color);
  margin-bottom: 2rem;
}

.hero-label {
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
  margin-bottom: 0.25rem;
}

.hero-verdict {
  font-size: 1.125rem;
  font-weight: 600;
}

.section {
  margin-bottom: 2.5rem;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.section-title {
  font-size: 0.9375rem;
  font-weight: 600;
  margin: 0;
}

.section-sub {
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1rem 2.5rem;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--bs-secondary-color);
  margin-bottom: 0.15rem;
}

.stat-delta {
  font-size: 0.8125rem;
}

.stat-note {
  font-size: 0.75rem;
  color: var(--bs-secondary-color);
}

.cov-dot {
  display: inline-block;
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--stox-up);
  margin-left: 0.4rem;
  vertical-align: 0.15em;
}

.cov-dot.ok { background: var(--stox-warn); }
.cov-dot.bad { background: var(--stox-down); }

.cov-dot.sourced {
  border-bottom: 0;
  cursor: help;
}

.issuer-nav-divider {
  width: 1px;
  align-self: stretch;
  background: var(--bs-border-color);
  margin: 0 0.5rem;
  flex-shrink: 0;
}

.issuer-nav-label {
  font-family: var(--stox-mono);
  font-size: 0.7rem;
  color: var(--bs-secondary-color);
  align-self: center;
  margin-right: 0.25rem;
  flex-shrink: 0;
}

.ledger-anchor {
  font-size: 0.9375rem;
  color: var(--bs-body-color);
}

.ledger-fade {
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
}

.muted-value {
  color: var(--bs-secondary-color);
}

.up { color: var(--stox-up); }
.down { color: var(--stox-down); }
.flat { color: var(--stox-flat); }

.delta-pill {
  font-family: var(--stox-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: var(--bs-secondary-bg);
}

.sourced {
  border-bottom: 1px dotted var(--bs-secondary-color);
  cursor: help;
  text-decoration: none;
  color: inherit;
}

.sourced:hover {
  border-bottom-color: var(--stox-accent);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  font-family: var(--stox-mono);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--bs-border-color);
  background: var(--bs-body-bg);
  color: var(--bs-secondary-color);
  white-space: nowrap;
}

.chip .dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--stox-flat);
}

.chip-good .dot { background: var(--stox-up); }
.chip-ok .dot { background: var(--stox-warn); }
.chip-bad .dot { background: var(--stox-down); }

.scope-chip {
  font-size: 0.7rem;
  font-family: var(--stox-mono);
  padding: 0.1rem 0.45rem;
  border-radius: 0.25rem;
  border: 1px dashed var(--stox-warn);
  color: var(--stox-warn);
  white-space: nowrap;
}

.explain {
  display: none;
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
  background: var(--bs-tertiary-bg);
  border-left: 3px solid var(--stox-accent);
  border-radius: 0 var(--stox-radius) var(--stox-radius) 0;
  padding: 0.5rem 0.75rem;
  margin-top: 0.5rem;
}

body[data-explain="on"] .explain {
  display: block;
}

.panel {
  background: var(--stox-surface);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--stox-radius);
  box-shadow: var(--stox-shadow);
}

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem 0.25rem;
}

.panel-title {
  font-size: 0.9375rem;
  font-weight: 600;
  margin: 0;
}

.panel-sub {
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
}

.panel-body {
  padding: 0.75rem 1rem 1rem;
}

/* The record browsers put their filters in a column beside the table. On a
   long page the selects have to stay reachable without scrolling back up, and
   below the lg breakpoint the column drops under the rows and sticking it
   would pin it over them. */
@media (min-width: 992px) {
  .filter-panel {
    position: sticky;
    top: 4.5rem;
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
  }
}

.ledger-table {
  font-size: 0.875rem;
}

.ledger-table th {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--bs-secondary-color);
  border-bottom-width: 1px;
  white-space: nowrap;
}

.ledger-table td {
  vertical-align: middle;
}

.ledger-table td.num, .ledger-table th.num {
  text-align: right;
}

.ledger-table tbody tr:hover {
  background: var(--bs-tertiary-bg);
  box-shadow: inset 2px 0 0 var(--stox-accent);
}

.ledger-table tbody tr:focus-within {
  outline: 2px solid var(--stox-accent);
  outline-offset: -2px;
}

.sparkline {
  width: 100%;
  height: 34px;
}

.stox-topbar {
  border-bottom: 1px solid var(--bs-border-color);
  background: color-mix(in srgb, var(--bs-body-bg) 84%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 1030;
}

.brand {
  font-family: var(--stox-mono);
  font-weight: 700;
  text-decoration: none;
  color: var(--bs-body-color);
}

.brand span {
  color: var(--stox-accent);
}

.stox-topbar .brand {
  font-size: 1rem;
}

.stox-topbar .nav-link {
  font-size: 0.875rem;
  padding: 0.9rem 0.75rem;
  color: var(--bs-secondary-color);
  border-bottom: 2px solid transparent;
}

.stox-topbar .nav-link:hover {
  color: var(--bs-body-color);
}

.stox-topbar .nav-link.active {
  color: var(--bs-body-color);
  border-bottom-color: var(--stox-accent);
}

.welcome-strip {
  background: color-mix(in srgb, var(--stox-accent) 7%, var(--bs-body-bg));
  border-bottom: 1px solid var(--bs-border-color);
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
}

.prov-table {
  font-family: var(--stox-mono);
  font-size: 0.75rem;
  margin: 0;
}

.prov-table td {
  padding: 0.15rem 0.5rem 0.15rem 0;
  border: 0;
  color: var(--bs-secondary-color);
}

.prov-table td:last-child {
  color: var(--bs-body-color);
  text-align: right;
  padding-right: 0;
}

.vintage-slider {
  accent-color: var(--stox-accent);
}

.quarter-track {
  height: 0.5rem;
  border-radius: 999px;
  background: var(--bs-secondary-bg);
  overflow: hidden;
}

.quarter-track .fill {
  height: 100%;
  background: var(--stox-accent);
  border-radius: inherit;
  transition: width 0.3s ease;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}

.footer-note {
  font-size: 0.75rem;
  color: var(--bs-secondary-color);
  font-family: var(--stox-mono);
}

@media (max-width: 767px) {
  .num-lg { font-size: 1.35rem; }
  .num-xl { font-size: 2.25rem; }
  .stox-topbar .nav-link { padding: 0.6rem 0.5rem; }
}

a,
button,
.nav-link,
.chip,
.btn,
.list-group-item {
  transition: color 0.12s ease, background-color 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

:focus-visible {
  outline: 2px solid var(--stox-accent);
  outline-offset: 2px;
}

.nav-pills .nav-link {
  color: var(--bs-secondary-color);
  border-radius: 0.4rem;
}

.nav-pills .nav-link:hover {
  color: var(--bs-body-color);
  background: var(--bs-tertiary-bg);
}

.nav-pills .nav-link.active {
  color: var(--stox-accent);
  background: color-mix(in srgb, var(--stox-accent) 13%, transparent);
  font-weight: 600;
}

.btn-outline-secondary {
  --bs-btn-color: var(--bs-secondary-color);
  --bs-btn-border-color: var(--bs-border-color);
  --bs-btn-hover-color: var(--bs-body-color);
  --bs-btn-hover-bg: var(--bs-tertiary-bg);
  --bs-btn-hover-border-color: var(--bs-border-color);
  --bs-btn-active-color: var(--bs-body-color);
  --bs-btn-active-bg: var(--bs-secondary-bg);
  --bs-btn-active-border-color: var(--bs-border-color);
}

.popover {
  --bs-popover-bg: var(--stox-surface);
  --bs-popover-border-color: var(--bs-border-color);
  --bs-popover-border-radius: 0.5rem;
  --bs-popover-body-padding-x: 0.75rem;
  --bs-popover-body-padding-y: 0.5rem;
  box-shadow: var(--stox-shadow-lg);
}

.dropdown-menu {
  --bs-dropdown-bg: var(--stox-surface);
  --bs-dropdown-border-color: var(--bs-border-color);
  --bs-dropdown-border-radius: 0.5rem;
  --bs-dropdown-link-color: var(--bs-body-color);
  --bs-dropdown-link-hover-color: var(--bs-body-color);
  --bs-dropdown-link-hover-bg: var(--bs-tertiary-bg);
  --bs-dropdown-link-active-color: var(--bs-body-color);
  --bs-dropdown-link-active-bg: var(--bs-secondary-bg);
  --bs-dropdown-header-color: var(--bs-secondary-color);
  box-shadow: var(--stox-shadow-lg);
}

.modal-content {
  background: var(--stox-surface);
  box-shadow: var(--stox-shadow-lg);
}

@keyframes stox-rise {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.hero > * {
  animation: stox-rise 0.32s ease-out both;
}

.hero > *:nth-child(2) { animation-delay: 0.04s; }
.hero > *:nth-child(3) { animation-delay: 0.08s; }

.stat-row > * {
  animation: stox-rise 0.32s ease-out both;
}

.stat-row > *:nth-child(2) { animation-delay: 0.05s; }
.stat-row > *:nth-child(3) { animation-delay: 0.1s; }
.stat-row > *:nth-child(4) { animation-delay: 0.15s; }
.stat-row > *:nth-child(5) { animation-delay: 0.2s; }
.stat-row > *:nth-child(6) { animation-delay: 0.25s; }
.stat-row > *:nth-child(7) { animation-delay: 0.3s; }

.ref-rail {
  max-height: calc(100vh - 9rem);
  overflow-y: auto;
  padding: 0 0.5rem 0.75rem;
  scrollbar-width: thin;
  scrollbar-color: var(--bs-border-color) transparent;
}

.ref-rail::-webkit-scrollbar {
  width: 6px;
}

.ref-rail::-webkit-scrollbar-thumb {
  background: var(--bs-border-color);
  border-radius: 999px;
}

.ref-rail::-webkit-scrollbar-track {
  background: transparent;
}

.ref-rail .stat-label {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--stox-surface);
  font-family: var(--stox-mono);
  letter-spacing: 0.05em;
  padding: 0.35rem 0.5rem 0.25rem;
  margin: 0;
  border-bottom: 1px solid var(--bs-border-color);
}

.ref-rail .stat-label:not(:first-child) {
  margin-top: 0.6rem;
}

.ref-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--bs-body-color);
  text-align: left;
  padding: 0.28rem 0.5rem;
  border-radius: 0.35rem;
  cursor: pointer;
}

.ref-item .font-monospace {
  font-family: var(--stox-mono);
  font-size: 0.78rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ref-item:hover {
  background: var(--bs-tertiary-bg);
  box-shadow: inset 2px 0 0 var(--stox-accent);
}

.ref-item:hover .font-monospace {
  color: var(--stox-accent);
}

.ref-item:active {
  background: var(--bs-secondary-bg);
}

.ref-item.inserted {
  background: color-mix(in srgb, var(--stox-accent) 16%, transparent);
  box-shadow: inset 2px 0 0 var(--stox-accent);
}

.ref-item .ref-hint {
  color: var(--bs-secondary-color);
  font-size: 0.7rem;
  text-align: right;
  white-space: nowrap;
  flex-shrink: 0;
}

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