/* Cosmo: navy dark theme (Sentry-ish), 3D buttons, section tabs.
   Plain CSS on stock Bootstrap 5.3.3; no build step. */

/* 3 shades. raised = panels/cards/buttons, base = page, edge (darkest) = borders. */
[data-bs-theme="dark"] .cosmo {
  /* Stock blue shaded to ~old GFA navy, so shades keep their look. */
  --cosmo-blue: color-mix(in srgb, var(--bs-blue) 55%, var(--bs-black));
  --cosmo-base: color-mix(in srgb, var(--cosmo-blue) 18%, var(--bs-gray-900));
  --cosmo-raised: color-mix(in srgb, var(--bs-white) 6%, var(--cosmo-base));
  --cosmo-edge: color-mix(in srgb, var(--bs-black) 45%, var(--cosmo-base));
  /* Primary = BS mid-dark blue (dark primary-border-subtle, #084298); rgb must be literal. */
  --bs-primary: var(--bs-primary-border-subtle);
  --bs-primary-rgb: 8, 66, 152;
  --cosmo-active: var(--bs-primary);
  /* Source links: turquoise, a bit darker than source tag fg. No Bootstrap turquoise. */
  --cosmo-source: hsl(180 70% 72%);
  /* Graph: black canvas, light navy lines (read by index.html JS). ~1.9:1 on black. */
  --cosmo-graph-edge: color-mix(in srgb, var(--bs-white) 3%, var(--cosmo-raised));
  /* DB redirect nodes (graph JS): light blue, apart from 3xx primary. */
  --cosmo-graph-db-redirect: color-mix(in srgb, var(--bs-primary) 75%, var(--bs-white));
  /* Short link nodes (graph JS): light purple. */
  --cosmo-graph-shortlink: color-mix(in srgb, var(--bs-purple) 70%, var(--bs-white));
  --bs-body-bg: var(--cosmo-base);
  --bs-secondary-bg: var(--cosmo-raised);
  --bs-tertiary-bg: var(--cosmo-raised);
  --bs-border-color: var(--cosmo-edge);
  --bs-border-color-translucent: var(--cosmo-edge);
  /* Page = raised; body-bg var stays base -> inputs/tables/cards darker, stick out. */
  background-color: var(--cosmo-raised);
}

/* No -rgb triple from color-mix, so .bg-body reads the color direct (bg-opacity unused). */
[data-bs-theme="dark"] .cosmo .bg-body {
  background-color: var(--bs-body-bg) !important;
}

[data-bs-theme="dark"] .cosmo .card {
  --bs-card-bg: var(--cosmo-base);
  --bs-card-border-color: var(--cosmo-edge);
}

[data-bs-theme="dark"] .cosmo .graph-panel,
[data-bs-theme="dark"] .cosmo .graph-details {
  background-color: var(--cosmo-raised);
}

[data-bs-theme="dark"] .cosmo #graph {
  background-color: var(--bs-black);
}

/* 3D button: solid bottom lip, pressed = drop 2px + lose lip. */
[data-bs-theme="dark"] .cosmo .btn {
  --bs-btn-color: var(--bs-body-color);
  --bs-btn-bg: var(--cosmo-raised);
  --bs-btn-border-color: var(--cosmo-edge);
  --bs-btn-hover-color: var(--bs-emphasis-color);
  --bs-btn-hover-bg: color-mix(in srgb, var(--bs-white) 6%, var(--cosmo-raised));
  --bs-btn-hover-border-color: var(--cosmo-edge);
  --bs-btn-active-color: var(--bs-emphasis-color);
  --bs-btn-active-bg: var(--cosmo-active);
  --bs-btn-active-border-color: var(--cosmo-edge);
  --bs-btn-disabled-border-color: var(--cosmo-edge);
  /* Via the var so .btn-group can still square the inner corners. */
  --bs-btn-border-radius: var(--bs-border-radius);
  background-image: linear-gradient(rgba(var(--bs-white-rgb), .06), rgba(var(--bs-white-rgb), 0));
  box-shadow: inset 0 1px 0 rgba(var(--bs-white-rgb), .08), 0 2px 0 var(--cosmo-edge);
  transition: transform .08s, box-shadow .08s, background-color .15s;
}

[data-bs-theme="dark"] .cosmo .btn:active,
[data-bs-theme="dark"] .cosmo .btn.active {
  transform: translateY(2px);
  background-image: none;
  box-shadow: inset 0 1px 2px rgba(var(--bs-black-rgb), .4);
}

/* Disabled: flat, no gradient / lip. */
[data-bs-theme="dark"] .cosmo .btn:disabled,
[data-bs-theme="dark"] .cosmo .btn.disabled {
  background-image: none;
  box-shadow: none;
}

/* Sans headings everywhere. */
.cosmo h1, .cosmo h2, .cosmo h3, .cosmo h4, .cosmo h5, .cosmo h6,
.cosmo .h1, .cosmo .h2, .cosmo .h3, .cosmo .h4, .cosmo .h5, .cosmo .h6 {
  font-family: var(--bs-body-font-family);
}

#cosmo-nav {
  top: 0;
  /* Full width: bleed past container-fluid gutter. */
  padding-inline: calc(var(--bs-gutter-x) * .5);
  margin-inline: calc(var(--bs-gutter-x) * -.5);
}

/* View switch: sunken track, current view = raised thumb. */
.cosmo-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background-color: var(--cosmo-edge);
  border-radius: var(--bs-border-radius-pill);
  box-shadow: inset 0 1px 3px rgba(var(--bs-black-rgb), .5);
}

.cosmo-switch-option {
  padding: .2rem .9rem;
  font-size: .875rem;
  color: var(--bs-secondary-color);
  text-decoration: none;
  white-space: nowrap;
  border-radius: var(--bs-border-radius-pill);
}

.cosmo-switch-option:hover {
  color: var(--bs-emphasis-color);
}

.cosmo-switch-option.active {
  color: var(--bs-emphasis-color);
  background-color: var(--cosmo-active);
  background-image: linear-gradient(rgba(var(--bs-white-rgb), .1), rgba(var(--bs-white-rgb), 0));
  box-shadow: inset 0 1px 0 rgba(var(--bs-white-rgb), .15), 0 1px 2px rgba(var(--bs-black-rgb), .6);
}

.cosmo-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 992px) {
  .cosmo-layout {
    flex-direction: row;
    align-items: flex-start;
    gap: 1.5rem;
  }
}

.cosmo-content {
  flex-grow: 1;
  min-width: 0;
}

/* Section tabs: scrolling row on small screens, sticky column from lg. */
.cosmo-tabs {
  display: flex;
  gap: .5rem;
  overflow-x: auto;
  padding-bottom: 4px; /* room for the lip */
}

@media (min-width: 992px) {
  .cosmo-tabs {
    position: sticky;
    top: calc(var(--cosmo-nav-height, 4rem) + 1rem);
    flex-direction: column;
    flex-shrink: 0;
    width: 12rem;
    max-height: calc(100vh - var(--cosmo-nav-height, 4rem) - 2rem);
    overflow: visible auto;
  }
}

@media (min-width: 1200px) {
  .cosmo-tabs {
    width: 15rem;
  }
}

.cosmo-tab {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  text-align: start;
  white-space: nowrap;
}

.cosmo-tab-count {
  font-size: .75em;
  font-variant-numeric: tabular-nums;
  color: var(--bs-secondary-color);
}

.active > .cosmo-tab-count {
  color: inherit;
}

.cosmo-tabs-group {
  align-self: center;
  font-size: .75rem;
  color: var(--bs-secondary-color);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}

@media (min-width: 992px) {
  .cosmo-tabs-group {
    align-self: auto;
    margin-top: .75rem;
  }
}

/* Tables: every column fits (fixed layout, wrap anywhere). */
.cosmo-table {
  table-layout: fixed;
  width: 100%;
  font-size: .75rem;
  /* Separate: th radius works. No outer border (console sits on top). */
  border-spacing: 0;
  border-collapse: separate;
}

.cosmo-table > :not(caption) > * > * {
  padding: .35rem .4rem;
  overflow-wrap: anywhere;
}

.cosmo-table .badge {
  white-space: normal;
  text-align: start;
}

/* Sorted column: brighter + faint tint, same size. */
.cosmo-sorted {
  --bs-table-bg-type: rgba(var(--bs-primary-rgb), .1);
  color: var(--bs-emphasis-color);
}

/* Header label = 3D button; sorted one is .active (pressed). Arrow faint until sorted. */
.cosmo-sort.btn {
  --bs-btn-font-size: .75rem;
  --bs-btn-font-weight: 600;
  --bs-btn-padding-y: .15rem;
  --bs-btn-padding-x: .45rem;
  display: flex;
  gap: .25rem;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: start;
  white-space: nowrap;
}

/* Never wraps; cut with "..." (full label in title). */
.cosmo-sort.btn > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* FA icon in a fixed slot so swapping can't change width.
   Unsorted = faint sort, asc = arrow-down-a-z, desc = arrow-up-z-a. */
.cosmo-sort.btn::after {
  flex: 0 0 1.25em;
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  text-align: center;
  content: "\f0dc";
  opacity: .4;
}

[aria-sort] > .cosmo-sort.btn::after {
  opacity: 1;
}

[aria-sort="ascending"] > .cosmo-sort.btn::after {
  content: "\f15d";
}

[aria-sort="descending"] > .cosmo-sort.btn::after {
  content: "\f882";
}

/* URLs pink (code color, linked ones too), file paths blue. */
.cosmo code,
.cosmo a > code {
  color: var(--bs-code-color);
}

.cosmo code.cosmo-file {
  color: var(--bs-primary-text-emphasis);
}

/* 2-line comment; full text in title. */
.cosmo-clip {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Console: recessed housing. thead (same bg) = its bottom row; both sticky under nav. */
.cosmo-console {
  position: sticky;
  top: var(--cosmo-nav-height, 4rem);
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  padding: .5rem;
  background: var(--cosmo-edge);
  border-radius: var(--bs-border-radius) var(--bs-border-radius) 0 0;
  box-shadow: inset 0 1px 4px rgba(var(--bs-black-rgb), .35);
}

/* Phones: thead hidden -> console stands alone. */
@media (max-width: 767.98px) {
  .cosmo-console {
    margin-bottom: .75rem;
    border-radius: var(--bs-border-radius);
  }
}

.cosmo-console .form-select {
  width: auto;
}

.cosmo-console [data-cosmo-search] {
  flex: 1 1 12rem;
  order: 1;
  width: auto;
  min-width: 6rem; /* shrinks for pinned keys */
}

/* Order: title, search, (pinned keys), Filters, sort, N of M; open keypads last. */
.cosmo-console > .cosmo-filters-toggle {
  order: 3;
}

.cosmo-console > .cosmo-sort-select {
  order: 4;
}

.cosmo-console > .cosmo-table-count,
.cosmo-console > .cosmo-reset-filters {
  order: 5;
}

.cosmo-console > .cosmo-keypad {
  order: 6;
}

.cosmo-console-title {
  margin: 0;
  white-space: nowrap;
}

.cosmo-console-title[title] {
  cursor: help;
}

.cosmo-table-count {
  font-size: .75rem;
  color: var(--bs-secondary-color);
}

/* Reset filters: amber while a filter is on; faded when disabled. */
.cosmo-reset-filters:not(:disabled) {
  --bs-btn-color: var(--bs-warning);
  --bs-btn-hover-color: var(--bs-warning);
}

/* Keypads (cosmo-tables.js): one row of toggle keys per filter, label first. */
.cosmo-keypad {
  display: flex;
  flex-basis: 100%;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  padding-bottom: 4px; /* room for the lip */
}

/* Filters closed: only pressed keys, inline on the search line, no row label. */
.cosmo-console:not(.cosmo-filters-open) > .cosmo-keypad {
  flex-basis: auto;
  order: 2; /* between search and Filters, so Filters / N of M don't shift */
}

.cosmo-console:not(.cosmo-filters-open) .cosmo-keypad:not(:has([aria-pressed="true"])),
.cosmo-console:not(.cosmo-filters-open) .cosmo-keypad-label,
.cosmo-console:not(.cosmo-filters-open) .cosmo-key:not([aria-pressed="true"]) {
  display: none;
}

/* Filters toggle: caret flips when open. */
.cosmo-filters-toggle i {
  font-size: .75em;
  transition: transform .15s;
}

[aria-expanded="true"] > .cosmo-filters-toggle i {
  transform: rotate(180deg);
}

/* Fixed width so rows' keys line up. */
.cosmo-keypad-label {
  flex: 0 0 5.5rem;
  font-size: .7rem;
  font-weight: 600;
  color: var(--bs-secondary-color);
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* Key = tag as 3D button; lip in tag border color. One pressed = it sinks + fills
   light (tag fg face, dark text), others dim + desaturate. */
.cosmo-key {
  display: inline-flex;
  gap: .35rem;
  align-items: baseline;
  padding: .2rem .45rem;
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--cosmo-tag-fg);
  white-space: nowrap;
  background: var(--cosmo-tag-bg);
  border: 1px solid var(--cosmo-tag-border);
  border-radius: 3px;
  box-shadow: 0 3px 0 var(--cosmo-tag-border);
  transition: transform .06s, box-shadow .06s, opacity .15s, filter .15s;
}

.cosmo-key::before {
  font-family: "Font Awesome 6 Free";
  font-size: .85em;
  font-weight: 900;
  opacity: .75;
}

/* Hover: up 1px, lip 1px taller. */
.cosmo-key:not([aria-pressed="true"]):hover {
  box-shadow: 0 4px 0 var(--cosmo-tag-border);
  transform: translateY(-1px);
}

/* Independent toggles: no dimming. */
.cosmo-keypad:not(.cosmo-keypad-toggles):has([aria-pressed="true"]) > .cosmo-key:not([aria-pressed="true"]) {
  opacity: .5;
  filter: saturate(.4);
}

.cosmo-keypad:not(.cosmo-keypad-toggles):has([aria-pressed="true"]) > .cosmo-key:not([aria-pressed="true"]):hover {
  opacity: 1;
  filter: none;
}

.cosmo-key:focus-visible {
  outline: 2px solid var(--cosmo-tag-fg);
  outline-offset: 2px;
}

.cosmo-key[aria-pressed="true"] {
  color: var(--cosmo-tag-bg);
  background: var(--cosmo-tag-fg);
  border-color: var(--cosmo-tag-fg);
  box-shadow: none;
  transform: translateY(3px);
}

/* Hover: half pops up -> clickable (unpress). */
.cosmo-key[aria-pressed="true"]:hover {
  box-shadow: 0 1px 0 var(--cosmo-tag-border);
  transform: translateY(2px);
}

/* Radio (one always pressed): click does nothing -> no hover. */
.cosmo-keypad-radio > .cosmo-key[aria-pressed="true"]:hover {
  cursor: default;
  box-shadow: none;
  transform: translateY(3px);
}

.cosmo-key-count {
  font-size: .9em;
  font-variant-numeric: tabular-nums;
  opacity: .75;
}

@media (min-width: 768px) {
  .cosmo-sort-select,
  .cosmo-select.cosmo-sort-select {
    display: none;
  }
}

/* Phones: each row = card, header text as cell labels. */
@media (max-width: 767.98px) {
  .cosmo-table,
  .cosmo-table tbody,
  .cosmo-table tr,
  .cosmo-table td {
    display: block;
    width: 100%;
  }

  .cosmo-table thead,
  .cosmo-table colgroup {
    display: none;
  }

  .cosmo-table tr {
    padding: .25rem 0;
    margin-bottom: .5rem;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
  }

  .cosmo-table > :not(caption) > * > * {
    display: grid;
    grid-template-columns: 6rem minmax(0, 1fr);
    gap: .5rem;
    border: 0;
  }

  .cosmo-table td::before {
    font-weight: 600;
    color: var(--bs-secondary-color);
    content: attr(data-label);
  }
}

/* Chunked render (cosmo-tables.js): [Show all] row; more on scroll. */
.cosmo-table > tbody > .cosmo-more > td {
  padding: .75rem;
  color: var(--bs-secondary-color);
  text-align: center;
}

@media (max-width: 767.98px) {
  .cosmo-table > tbody > .cosmo-more > td {
    display: block;
  }

  .cosmo-table > tbody > .cosmo-more > td::before {
    content: none;
  }
}

@media (max-width: 767.98px) {
  .cosmo-table > tbody > .cosmo-more {
    border: 0;
  }
}

/* "X of N rows loaded". lg+ table tabs: in page's bottom gutter. Else sticky to window bottom. */
.cosmo-loaded {
  position: sticky;
  bottom: 0;
  flex-shrink: 0;
  padding: .15rem .25rem;
  font-size: .7rem;
  font-variant-numeric: tabular-nums;
  color: var(--bs-secondary-color);
  text-align: end;
  background: var(--cosmo-raised);
}

@media (min-width: 992px) {
  .cosmo-fill .cosmo-loaded {
    position: fixed;
    right: calc(var(--bs-gutter-x) * .5);
    bottom: .25rem;
    padding: 0;
    background: none;
  }
}

/* URL links (cosmo_url tag): look like URL code, click = radial menu. */
.cosmo a.cosmo-url {
  font-family: var(--bs-font-monospace);
  font-size: .875em;
  color: var(--bs-code-color);
  overflow-wrap: anywhere;
  text-decoration: none;
}

.cosmo a.cosmo-url:hover,
.cosmo a.cosmo-url:focus-visible {
  text-decoration: underline;
}

/* Link set: yellow like its graph node. */
.cosmo a.cosmo-url.cosmo-set {
  color: var(--bs-yellow);
}

/* Source: turquoise = source tag fg family. */
.cosmo a.cosmo-url.cosmo-source {
  color: var(--cosmo-source);
}

/* Radial menu: donut of 3 wedge buttons (JS clips each with clip-path). */
.cosmo-radial {
  position: fixed;
  z-index: 1070; /* popover */
  border-radius: 50%;
  filter: drop-shadow(0 0 1px var(--cosmo-edge)) drop-shadow(0 8px 14px rgba(var(--bs-black-rgb), .5));
  animation: cosmo-radial-open .14s ease-out;
}

/* Dark donut under wedges: fills gaps, backs disabled wedges. Darker than lips so they show. */
.cosmo-radial::before {
  position: absolute;
  inset: 0;
  content: "";
  background: radial-gradient(circle closest-side, transparent 33%, color-mix(in srgb, var(--bs-black) 40%, var(--cosmo-edge)) 34%);
  border-radius: 50%;
}

@keyframes cosmo-radial-open {
  from {
    opacity: 0;
    transform: scale(.6);
  }
}

.cosmo-radial-item.btn {
  position: absolute;
  inset: 0;
  padding: 0;
  pointer-events: auto;
  border: 0;
  border-radius: 0;
}

/* Focus ring would be clipped: brighten instead. */
.cosmo-radial-item.btn:focus-visible {
  background-color: var(--cosmo-active);
  outline: 0;
}

/* Disabled still eats clicks, just no press. Menu in selector beats theme .btn:active.
   No face: donut shows through, only icon + label (faded). */
.cosmo-radial .cosmo-radial-item.btn:disabled {
  /* Bootstrap's :active colors still match disabled: keep the disabled ones. */
  --bs-btn-disabled-bg: transparent;
  --bs-btn-active-bg: transparent;
  --bs-btn-active-color: var(--bs-btn-disabled-color);
  --bs-btn-active-border-color: var(--bs-btn-disabled-border-color);
  background-image: none;
  cursor: default;
  opacity: .35;
  transform: none;
}

/* Icon + label at wedge middle (left/top set by JS). */
.cosmo-radial-label {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: .1rem;
  align-items: center;
  font-size: .65rem;
  font-weight: 600;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

/* File paths: one line, cut at start so filename shows (rtl box; LRM marks keep
   "/" and ":line" in order). Hover = full path overlay, click = copy. */
.cosmo code.cosmo-file {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  cursor: pointer;
  direction: rtl;
}

.cosmo code.cosmo-file::before,
.cosmo code.cosmo-file::after {
  content: "\200E";
}

.cosmo code.cosmo-file:hover {
  text-decoration: underline;
}

/* Right-cut one-liner; hover = full text in place. */
.cosmo .cosmo-expand {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Hover overlay: full text over same spot (JS copies font + color). Ring via
   box-shadow, not padding/border, so text lines up with what's under it. */
.cosmo .cosmo-full {
  position: fixed;
  z-index: 1000; /* dropdown */
  width: max-content;
  max-width: calc(100vw - 1rem);
  overflow-wrap: anywhere;
  background: var(--cosmo-raised);
  border-radius: 2px;
  box-shadow: 0 0 0 3px var(--cosmo-raised), 0 0 0 4px var(--cosmo-edge), 0 4px 10px 3px rgba(var(--bs-black-rgb), .4);
}

.cosmo .cosmo-file-full {
  text-decoration: underline;
  cursor: pointer;
}

.cosmo-copied {
  position: fixed;
  z-index: 1080; /* tooltip */
  padding: .15rem .45rem;
  font-size: .7rem;
  font-weight: 600;
  color: var(--bs-emphasis-color);
  pointer-events: none;
  background: var(--cosmo-active);
  border: 1px solid var(--cosmo-edge);
  border-radius: var(--bs-border-radius);
  transform: translate(-50%, -100%);
  animation: cosmo-copied 1.2s ease-out forwards;
}

@keyframes cosmo-copied {
  70% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

/* Link cards (table Links cell + graph panel): path [-> target] ... via. */
.cosmo-links-section > summary {
  margin: .4rem 0 .15rem;
  font-weight: 600;
}

.cosmo-link {
  display: flex;
  flex-wrap: wrap;
  gap: 0 .4rem;
  align-items: baseline;
  padding: .05rem .35rem;
  margin-bottom: 2px;
  background: var(--cosmo-raised);
  border: 1px solid var(--cosmo-edge);
  border-radius: 3px;
}

.cosmo-link-to {
  color: var(--bs-secondary-color);
}

.cosmo-link-via {
  margin-left: auto;
  font-size: .85em;
  color: var(--bs-secondary-color);
}

/* Tags (cosmo/tags.py): icon = type, color = tone (good/info/muted/bad) or fact. */
.cosmo-tags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: .2rem;
}

.cosmo-tag {
  display: inline-flex;
  gap: .25rem;
  align-items: baseline;
  padding: .05rem .35rem;
  font-size: .7rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--cosmo-tag-fg);
  overflow-wrap: anywhere;
  background: var(--cosmo-tag-bg);
  border: 1px solid var(--cosmo-tag-border);
  border-radius: 3px;
}

.cosmo-tag::before {
  font-family: "Font Awesome 6 Free";
  font-size: .85em;
  font-weight: 900;
  opacity: .75;
}

.cosmo-t-crawl::before {
  content: "\f717"; /* spider */
}

.cosmo-t-page::before {
  content: "\f15c"; /* file-lines */
}

.cosmo-t-broken::before {
  content: "\f127"; /* link-slash */
}

.cosmo-t-redirect::before {
  content: "\f064"; /* share */
}

.cosmo-t-status::before {
  content: "\f233"; /* server */
}

.cosmo-c-good {
  --cosmo-tag-bg: var(--bs-success-bg-subtle);
  --cosmo-tag-fg: var(--bs-success-text-emphasis);
  --cosmo-tag-border: var(--bs-success-border-subtle);
}

.cosmo-c-info {
  --cosmo-tag-bg: var(--bs-primary-bg-subtle);
  --cosmo-tag-fg: var(--bs-primary-text-emphasis);
  --cosmo-tag-border: var(--bs-primary-border-subtle);
}

.cosmo-c-muted {
  --cosmo-tag-bg: var(--bs-secondary-bg-subtle);
  --cosmo-tag-fg: var(--bs-secondary-text-emphasis);
  --cosmo-tag-border: var(--bs-secondary-border-subtle);
}

.cosmo-c-bad {
  --cosmo-tag-bg: var(--bs-danger-bg-subtle);
  --cosmo-tag-fg: var(--bs-danger-text-emphasis);
  --cosmo-tag-border: var(--bs-danger-border-subtle);
}

/* Hue tones, no red/green: fact = amber (tags.FACT), source = turquoise.
   No Bootstrap vars for these: one hue each. */
.cosmo-c-fact {
  --cosmo-tag-hue: 30;
}

.cosmo-c-source {
  --cosmo-tag-hue: 180;
}

.cosmo-c-fact,
.cosmo-c-source {
  --cosmo-tag-bg: hsl(var(--cosmo-tag-hue) 45% 20%);
  --cosmo-tag-fg: hsl(var(--cosmo-tag-hue) 70% 78%);
  --cosmo-tag-border: hsl(var(--cosmo-tag-hue) 45% 32%);
}

/* Tags with a text detail: click copies, so link look. */
.cosmo-tag-copy {
  cursor: pointer;
}

.cosmo-tag-copy:hover {
  text-decoration: underline;
}

.cosmo .cosmo-full-pre {
  max-width: min(40rem, calc(100vw - 1rem));
  max-height: 60vh;
  overflow: auto;
  font-family: var(--bs-font-monospace);
  font-size: .7rem;
  color: var(--bs-body-color);
  white-space: pre-wrap;
  cursor: pointer;
}

.cosmo .cosmo-full-cards {
  max-width: min(28rem, calc(100vw - 1rem));
  font-size: .75rem;
}

/* Broken link card: red left edge. */
.cosmo-link-broken {
  border-left: 3px solid var(--bs-danger-border-subtle);
}

/* Hover text colors: same as URL / file path code. */
.cosmo-hl-url {
  color: var(--bs-code-color);
}

.cosmo-hl-file {
  color: var(--bs-primary-text-emphasis);
}

.cosmo .cosmo-full-url {
  font-size: .75rem;
}

/* Sticky column labels = console's bottom row, stuck under it.
   --cosmo-console-height set by cosmo-tables.js. */
.cosmo-table > thead > tr > th {
  position: sticky;
  top: calc(var(--cosmo-nav-height, 4rem) + var(--cosmo-console-height, 0px));
  z-index: 2;
  background-color: var(--cosmo-edge);
  border-bottom: 0;
}

/* lg+ table tabs: main = viewport-high flex column, page doesn't scroll; table
   scrolls in own box. No nav-height math, so font loads can't make page scroll. */
.cosmo-table-scroll {
  scrollbar-color: color-mix(in srgb, var(--bs-white) 20%, var(--cosmo-raised)) transparent;
}

@media (min-width: 992px) {
  .cosmo-fill {
    display: flex;
    flex-direction: column;
    height: 100dvh;
  }

  .cosmo-fill #cosmo-nav {
    flex-shrink: 0;
  }

  .cosmo-fill .cosmo-layout {
    flex: 1 1 auto;
    min-height: 0;
  }

  .cosmo-fill .cosmo-tabs {
    max-height: 100%;
  }

  .cosmo-fill .cosmo-content {
    display: flex;
    flex-direction: column;
    align-self: stretch;
  }

  .cosmo-fill .cosmo-table-wrap {
    display: flex;
    flex: 0 1 auto;
    flex-direction: column;
    min-height: 0;
  }

  .cosmo-fill .cosmo-table-scroll {
    flex: 0 1 auto;
    min-height: 0;
    overflow-y: auto;
  }

  .cosmo-fill .cosmo-console {
    position: static;
  }

  .cosmo-fill .cosmo-table > thead > tr > th {
    top: 0;
  }
}

/* Custom dropdowns (cosmo-select.js): native select hidden; 3D .btn shows the
   choice (.active while open) over a list panel. */
.cosmo-select {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

/* Graph page layout (was inline <style> in index.html). */
.graph-layout {
  min-height: 0;
}

.graph-panel {
  width: 17rem;
}

.graph-details {
  width: 22rem;
}

/* Graph date range (.cosmo-c-fact = amber tag vars). Scope screen: black,
   recessed; per-year bars lit in range. Bars inset by half a
   handle so years line up with the track. */
.graph-date-bars {
  display: flex;
  align-items: flex-end;
  gap: 1px;
  height: 2.5rem;
  padding: .35rem .5rem 0;
  background: var(--bs-black);
  border: 1px solid var(--cosmo-edge);
  border-radius: 3px 3px 0 0;
  box-shadow: inset 0 2px 4px rgba(var(--bs-black-rgb), .8);
}

.graph-date-bars > div {
  flex: 1;
  min-height: 1px;
  background-color: var(--cosmo-tag-border);
  opacity: .45;
}

.graph-date-bars > .graph-date-in {
  background-color: var(--cosmo-tag-fg);
  opacity: 1;
}

/* Two native range inputs stacked; native tracks hidden, only the handles
   take the pointer. The drawn track below: recessed groove + lit band. */
.graph-date-range {
  position: relative;
  height: 2rem;
}

.graph-date-track {
  position: absolute;
  top: 50%;
  right: 0;
  left: 0;
  height: .5rem;
  background: var(--bs-black);
  border-radius: 1rem;
  box-shadow: inset 0 1px 3px rgba(var(--bs-black-rgb), .9), 0 1px 0 rgba(var(--bs-white-rgb), .06);
  transform: translateY(-50%);
}

.graph-date-fill {
  position: absolute;
  top: 1px;
  bottom: 1px;
  left: calc(.5rem + (100% - 1rem) * var(--from, 0));
  right: calc(.5rem + (100% - 1rem) * (1 - var(--to, 1)));
  background: var(--cosmo-tag-fg);
  border-radius: 1rem;
}

.graph-date-range input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  pointer-events: none;
  background: transparent;
  appearance: none;
}

.graph-date-range input:focus {
  outline: none;
}

.graph-date-range input::-webkit-slider-runnable-track {
  height: .5rem;
  background: transparent;
}

.graph-date-range input::-moz-range-track {
  height: .5rem;
  background: transparent;
}

/* Handle = fader cap with the keys' 3D lip and a lit grip line; sinks while
   dragged. */
.graph-date-range input::-webkit-slider-thumb {
  width: 1rem;
  height: 1.35rem;
  margin-top: -.425rem;
  pointer-events: auto;
  cursor: grab;
  background:
    linear-gradient(90deg, transparent 42%, var(--cosmo-tag-fg) 42% 58%, transparent 58%) center / 100% 60% no-repeat,
    var(--cosmo-tag-bg);
  border: 1px solid var(--cosmo-tag-border);
  border-radius: 3px;
  box-shadow: 0 3px 0 var(--cosmo-tag-border);
  appearance: none;
  transition: transform .06s, box-shadow .06s;
}

.graph-date-range input::-moz-range-thumb {
  box-sizing: border-box;
  width: 1rem;
  height: 1.35rem;
  pointer-events: auto;
  cursor: grab;
  background:
    linear-gradient(90deg, transparent 42%, var(--cosmo-tag-fg) 42% 58%, transparent 58%) center / 100% 60% no-repeat,
    var(--cosmo-tag-bg);
  border: 1px solid var(--cosmo-tag-border);
  border-radius: 3px;
  box-shadow: 0 3px 0 var(--cosmo-tag-border);
  transition: transform .06s, box-shadow .06s;
}

.graph-date-range input::-webkit-slider-thumb:hover {
  box-shadow: 0 4px 0 var(--cosmo-tag-border);
  transform: translateY(-1px);
}

.graph-date-range input::-moz-range-thumb:hover {
  box-shadow: 0 4px 0 var(--cosmo-tag-border);
  transform: translateY(-1px);
}

.graph-date-range input:active::-webkit-slider-thumb {
  cursor: grabbing;
  box-shadow: 0 1px 0 var(--cosmo-tag-border);
  transform: translateY(2px);
}

.graph-date-range input:active::-moz-range-thumb {
  cursor: grabbing;
  box-shadow: 0 1px 0 var(--cosmo-tag-border);
  transform: translateY(2px);
}

.graph-date-range input:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--cosmo-tag-fg);
  outline-offset: 2px;
}

.graph-date-range input:focus-visible::-moz-range-thumb {
  outline: 2px solid var(--cosmo-tag-fg);
  outline-offset: 2px;
}

.graph-date-range .graph-date-top {
  z-index: 1;
}

/* Mission-clock readout under the slider. */
.graph-date-readout {
  padding: .15rem .5rem;
  font-family: var(--bs-font-monospace);
  font-size: .75rem;
  color: var(--cosmo-tag-fg);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .08em;
  background: var(--bs-black);
  border: 1px solid var(--cosmo-edge);
  border-radius: 3px;
  box-shadow: inset 0 2px 4px rgba(var(--bs-black-rgb), .8);
}

/* Nothing selected: faint grey logo in the blank panel. */
.graph-details:empty {
  position: relative;
}

.graph-details:empty::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("cosmo.svg") center 4rem / 8rem no-repeat;
  filter: grayscale(1);
  opacity: .12;
}

.graph-dot {
  display: inline-block;
  width: .75rem;
  height: .75rem;
  border-radius: 50%;
}

/* Graph search: X button inside the box, right edge. */
.graph-search {
  position: relative;
}

.graph-search .form-control {
  padding-right: 1.75rem;
}

.graph-search-clear {
  position: absolute;
  top: 50%;
  right: .4rem;
  padding: 0 .2rem;
  line-height: 1;
  color: var(--bs-secondary-color);
  background: none;
  border: 0;
  transform: translateY(-50%);
}

.graph-search-clear:hover {
  color: var(--bs-body-color);
}

/* Link-direction dots (index.html setFlow): sigma canvas layer after edges. */
.graph-flow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.graph-panel-group + .graph-panel-group {
  padding-top: 1rem;
  margin-top: .25rem;
  border-top: 1px solid var(--bs-border-color);
}

.cosmo-select-btn.btn {
  display: flex;
  gap: .5rem;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: start;
}

.cosmo-select-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cosmo-select-caret {
  font-size: .7em;
  opacity: .7;
  transition: transform .15s;
}

.active > .cosmo-select-caret {
  transform: rotate(180deg);
}

.cosmo-select-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 1000; /* dropdown */
  min-width: 100%;
  max-height: 60vh;
  padding: .25rem;
  overflow: auto;
  background: var(--cosmo-raised);
  border: 1px solid var(--cosmo-edge);
  border-radius: var(--bs-border-radius);
  box-shadow: 0 6px 16px rgba(var(--bs-black-rgb), .5);
}

/* Settings gear (nav): panel = dropdown list look, sized to content. */
.cosmo-settings {
  position: relative;
}

.cosmo-settings-menu {
  width: max-content;
  padding: .75rem;
}

.cosmo-select-menu.cosmo-select-menu-end {
  right: 0;
  left: auto;
}

.cosmo-select-item {
  display: block;
  width: 100%;
  padding: .25rem .6rem;
  font-size: .875rem;
  color: var(--bs-body-color);
  text-align: start;
  white-space: nowrap;
  background: none;
  border: 0;
  border-radius: calc(var(--bs-border-radius) - 2px);
}

.cosmo-select-item:hover,
.cosmo-select-item:focus-visible {
  background: color-mix(in srgb, var(--bs-white) 8%, var(--cosmo-raised));
  outline: 0;
}

.cosmo-select-item[aria-selected="true"] {
  font-weight: 600;
  color: var(--bs-emphasis-color);
}

/* Reduce: no motion at all, fades too. Beats .cosmo .btn transition (outranks Bootstrap's own reduce rule). */
@media (prefers-reduced-motion: reduce) {
  [data-bs-theme="dark"] .cosmo .btn,
  .cosmo-key,
  .cosmo-filters-toggle i,
  .cosmo-select-caret {
    transition: none;
  }

  .graph-date-range input::-webkit-slider-thumb {
    transition: none;
  }

  .graph-date-range input::-moz-range-thumb {
    transition: none;
  }

  .cosmo-radial,
  .cosmo-copied {
    animation: none;
  }
}
