:root {
  --ink: #1d2327;
  --muted: #5f6b73;
  --line: #d9dee2;
  --ground: #f5f7f8;
  --card: #fff;
  --accent: #1f6feb;
  --good: #1a7f37;
  --warn: #9a6700;
  --bad: #cf222e;
  font-family:
    system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
  color: var(--ink);
  background: var(--ground);
}

[x-cloak] {
  display: none !important;
}

body {
  margin: 0;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

header h1 {
  margin: 0;
  font-size: 1.25rem;
}

header h1 span {
  color: var(--muted);
  font-weight: 400;
}

.who {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  color: var(--muted);
}

main {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.5rem;
}

h2 {
  font-size: 1.05rem;
  margin: 1.5rem 0 0.75rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
}

.login {
  max-width: 22rem;
  margin: 3rem auto;
  display: grid;
  gap: 0.75rem;
}

.login h2 {
  margin: 0;
}

label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}

input {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
}

button {
  font: inherit;
  padding: 0.45rem 1rem;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

button.link {
  background: none;
  color: var(--accent);
  padding: 0;
}

.drop {
  border: 2px dashed var(--line);
  border-radius: 10px;
  background: var(--card);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s;
}

.drop.over {
  border-color: var(--accent);
  background: #eef4ff;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.problem {
  color: var(--bad);
}

.job-head {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  flex-wrap: wrap;
}

.size {
  color: var(--muted);
  font-size: 0.9rem;
}

.status {
  margin-left: auto;
  font-size: 0.9rem;
}

.status.done {
  color: var(--good);
}

.status.failed {
  color: var(--bad);
}

progress {
  width: 100%;
  margin-top: 0.5rem;
}

.counts {
  margin: 0.5rem 0;
}

.table {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
  background: var(--card);
}

th,
td {
  text-align: left;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
}

/* A scroll container of its own, because the page's overflow-x on .table would otherwise
   pin the header to a box that never scrolls. The shadow stands in for the bottom border,
   which a collapsed border leaves behind when the header sticks. */
.table.scroll {
  max-height: calc(100vh - 9rem);
  overflow: auto;
}

.table.scroll thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--card);
  box-shadow: inset 0 -1px 0 var(--line);
}

button.sort {
  display: inline-flex;
  gap: 0.3rem;
  align-items: baseline;
  padding: 0;
  background: none;
  color: inherit;
  font-weight: inherit;
  white-space: nowrap;
}

th[aria-sort='ascending'],
th[aria-sort='descending'] {
  color: var(--ink);
}

button.sort .arrow {
  font-size: 0.75em;
}

th[aria-sort='none'] button.sort .arrow {
  opacity: 0.35;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.path {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
  font-size: 0.85rem;
  word-break: break-all;
}

tr.failed td {
  color: var(--bad);
}

.badge {
  display: inline-block;
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--ground);
}

.badge.added {
  background: #dafbe1;
  color: var(--good);
}

.badge.replaced {
  background: #fff8c5;
  color: var(--warn);
}

.badge.failed {
  background: #ffebe9;
  color: var(--bad);
}

/* ── Monitor ─────────────────────────────────────────────────────────────── */

nav {
  display: flex;
  gap: 1.25rem;
}

nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
}

nav a.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

main.wide {
  max-width: none;
}

/* ── the overview's flow chart ──────────────────────────────────────────── */

/* Below the width its text stays legible at, the chart scrolls inside its card. */
.flow {
  overflow-x: auto;
}

/* What opens over the chart is placed in it, so the chart is what it is placed against. */
.flow-canvas {
  position: relative;
  min-width: 56rem;
}

.flow-canvas > svg {
  display: block;
  width: 100%;
  height: auto;
  font-size: 12px;
}

.flow .cog {
  cursor: pointer;
}

.flow .cog rect {
  fill: transparent;
  stroke: none;
}

.flow .cog:hover rect,
.flow .cog:focus-visible rect {
  fill: var(--ground);
}

.flow .cog:focus-visible {
  outline: none;
}

.flow .cog:focus-visible rect {
  stroke: var(--accent);
  stroke-width: 1.5;
}

/* Inherited by the symbol's shape, like the other icons. */
.flow .cog use,
.flow use.cog-icon {
  fill: var(--muted);
  stroke: none;
}

.flow .cog:hover use {
  fill: var(--ink);
}

.flow-popup {
  position: absolute;
  z-index: 10;
  width: 20rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.flow-popup-title {
  margin: 0 0 0.5rem;
  font-weight: 600;
}

.flow-popup .hint {
  margin: 0.5rem 0 0;
}

.flow-popup .held {
  color: var(--warn);
}

.flow .phase {
  fill: none;
}

.flow .phase.shaded {
  fill: var(--ground);
}

/* The cloud: a band of its own over home, outlined rather than shaded like a column. */
.flow .phase.cloud {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.5;
  stroke-dasharray: 6 4;
}

/* The other side, while home and the cloud are not linked: nothing of it is known. */
.flow .away {
  opacity: 0.45;
}

.flow .phase-title {
  fill: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-anchor: middle;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.flow .edge {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.5;
  marker-end: url(#flow-arrow);
}

.flow .edge.both {
  marker-start: url(#flow-arrow);
}

/* Something waits to go along it: the dashes march towards where it goes. */
.flow .edge.active {
  stroke: var(--accent);
  stroke-dasharray: 6 4;
  animation: flow-march 0.8s linear infinite;
  marker-end: url(#flow-arrow-active);
}

@keyframes flow-march {
  to {
    stroke-dashoffset: -10;
  }
}

.flow .arrowhead {
  fill: var(--muted);
}

.flow .arrowhead.active {
  fill: var(--accent);
}

/* A halo of the card's colour, so a label stays readable where it crosses a line. */
.flow .edge-label {
  fill: var(--ink);
  font-size: 11px;
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--card);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.flow .edge-label.start {
  text-anchor: start;
}

.flow .edge-label.end {
  text-anchor: end;
}

.flow .edge-label .n {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.flow .edge-label.problem {
  fill: var(--bad);
}

.flow .node rect {
  fill: var(--card);
  stroke: var(--line);
  stroke-width: 1.5;
}

.flow a.node:hover rect {
  stroke: var(--muted);
}

.flow .node.busy rect {
  stroke: var(--accent);
}

.flow .node.down rect {
  stroke-dasharray: 5 4;
}

.flow .node.down text {
  fill: var(--muted);
}

.flow .node .title {
  fill: var(--ink);
  font-size: 14px;
  font-weight: 600;
}

.flow .node .stat {
  fill: var(--ink);
  font-variant-numeric: tabular-nums;
}

.flow .node .rule {
  stroke: var(--line);
}

.flow .vitals {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.flow .node.down .vitals {
  fill: var(--warn);
}

.flow .spinner {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 14 30;
  transform-box: fill-box;
  transform-origin: center;
  animation: flow-spin 0.9s linear infinite;
}

@keyframes flow-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Inherited by the shapes of the symbol it draws; see the note on the symbols. */
.flow use.icon {
  fill: var(--card);
  stroke: var(--muted);
  stroke-width: 1.5;
}

.flow .db-link {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.flow .store-label {
  fill: var(--ink);
  font-size: 11px;
  font-weight: 600;
  text-anchor: middle;
}

.flow .store-note {
  fill: var(--muted);
  font-size: 11px;
  text-anchor: middle;
}

.flow .brace {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.5;
}

.flow-legend {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}

.flow-legend:hover {
  color: var(--ink);
}

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

.flow-legend .legend-keys {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.flow-legend.open .legend-keys {
  flex-direction: column;
}

.flow-legend li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.flow-legend svg {
  width: 1.1rem;
  height: 1.1rem;
  flex: none;
  overflow: visible;
}

.flow-legend .legend-down {
  fill: var(--card);
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
}

.flow-legend .legend-away {
  fill: var(--card);
  stroke: var(--line);
  stroke-width: 1.5;
  opacity: 0.45;
}
/* At the far right, on the first line however far the keys wrap. */
.flow-legend .chevron {
  margin-top: 0.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.15s;
}

.flow-legend.open .chevron {
  transform: rotate(180deg);
}

@media (prefers-reduced-motion: reduce) {
  .flow .edge.active,
  .flow .spinner {
    animation: none;
  }
}

.filters {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: end;
  margin-bottom: 0.75rem;
}

select {
  font: inherit;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
}

button.quiet {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
}

.sev {
  display: inline-block;
  min-width: 4.2rem;
  text-align: center;
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
}

.sev.info {
  background: #ddf4ff;
  color: #0969da;
}

.sev.warning {
  background: #fff8c5;
  color: var(--warn);
}

.sev.error {
  background: #ffebe9;
  color: var(--bad);
}

tr.clickable {
  cursor: pointer;
}

tr.clickable:hover td {
  background: #f6f8fa;
}

.day-page {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.day-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 26rem;
  gap: 1rem;
  align-items: start;
}

@media (width <= 70rem) {
  .day-layout {
    grid-template-columns: 1fr;
  }
}

#map {
  height: 72vh;
  border: 1px solid var(--line);
  border-radius: 8px;
}

/* A day fits the window rather than scrolling it: the map takes whatever height the header
   and the timeline leave, and the sidebar scrolls on its own. Stacked on a narrow window
   there is no room for that, and the page scrolls as the others do. */
@media (width > 70rem) {
  body.fit {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.fit main {
    flex: 1;
    min-height: 0;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    padding: 0.75rem 1rem;
  }

  body.fit .day-page {
    flex: 1;
    min-height: 0;
  }

  body.fit .day-layout {
    flex: 1;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
  }

  body.fit .day-main {
    min-height: 0;
  }

  body.fit #map {
    flex: 1;
    height: auto;
    min-height: 12rem;
  }

  body.fit .side {
    max-height: none;
    min-height: 0;
  }
}

/* Leaflet keeps a tooltip on one line, and an issue message makes that line very long.
   Tooltips sit in a pane with no width, so without max-content they would wrap at every word. */
.leaflet-tooltip {
  width: max-content;
  max-width: 300px;
  white-space: normal;
}

.side {
  max-height: 72vh;
  overflow-y: auto;
}

details.panel > summary {
  cursor: pointer;
}

details.panel[open] > summary {
  margin-bottom: 0.5rem;
}

.layers label {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  color: var(--ink);
}

.swatch {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 3px;
  vertical-align: middle;
}

.day-head {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.day-head h2 {
  margin: 0;
}

.bar {
  display: flex;
  height: 0.6rem;
  border-radius: 3px;
  overflow: hidden;
  min-width: 8rem;
  background: var(--ground);
}

.issue {
  border-left: 3px solid var(--line);
  padding: 0.25rem 0.6rem;
  margin: 0.4rem 0;
  cursor: pointer;
}

.issue.warning {
  border-left-color: var(--warn);
}

.issue.error {
  border-left-color: var(--bad);
}

/* Removed issues stay readable, but step back behind the open ones. */
.issue.removed,
tr.removed {
  opacity: 0.6;
}

.issue.removed {
  cursor: default;
}

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

pre.json {
  font-size: 0.8rem;
  background: var(--ground);
  padding: 0.5rem;
  border-radius: 6px;
  overflow-x: auto;
}

.notice {
  background: #ddf4ff;
  border: 1px solid #b6e3ff;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

/* What the last action came to, fixed to the window so a button far down the page still shows
   it. Above Leaflet's controls (1000) and the timeline's popup, below the calendar's tip. */
.toast {
  position: fixed;
  z-index: 1500;
  right: 1rem;
  bottom: 1rem;
  max-width: min(28rem, calc(100vw - 2rem));
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem 0.6rem 0.9rem;
  border-radius: 6px;
  border: 1px solid #aceebb;
  border-left: 4px solid var(--good);
  background: #dafbe1;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.15);
}

.toast.failed {
  border-color: #ffcecb;
  border-left-color: var(--bad);
  background: #ffebe9;
}

.toast button.link {
  color: var(--muted);
  line-height: 1.4;
}

/* x-for leaves no whitespace between items, so each is its own box to wrap at. */
.legend-item {
  display: inline-block;
  margin-right: 0.6rem;
  white-space: nowrap;
}

a[href^='#/day/'] {
  white-space: nowrap;
}

/* ── labels ─────────────────────────────────────────────────────────────── */

.label-pick {
  font-size: 0.8rem;
  padding: 0.1rem 0.2rem;
}

.label-row {
  margin: 0.35rem 0;
}

.label-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-top: 0.6rem;
}

/* ── the day's timeline ─────────────────────────────────────────────────── */

.day-main {
  /* The popup of modes opens over the map or the timeline, placed from here. */
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

.timeline-card {
  position: relative;
  /* .day-main spaces its children with a gap. */
  margin-bottom: 0;
}

.timeline-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.9rem;
  margin-bottom: 0.5rem;
}

.timeline-zoom {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.timeline-tools button[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.timeline-save {
  display: inline-flex;
  gap: 0.5rem;
  margin-left: auto;
}

.timeline {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.35rem;
}

.timeline-track {
  position: relative;
  min-width: 100%;
  height: 4.4rem;
  user-select: none;
}

.timeline-track.splitting,
.timeline-track.splitting .tl-span {
  cursor: crosshair;
}

.tl-ruler {
  position: absolute;
  inset: 0 0 auto 0;
  height: 1.5rem;
  border-bottom: 1px solid var(--line);
}

.tl-tick {
  position: absolute;
  bottom: 0;
  width: 1px;
  height: 0.3rem;
  background: var(--line);
}

.tl-tick.major {
  height: 0.55rem;
  background: var(--muted);
}

.tl-tick span {
  position: absolute;
  bottom: 0.6rem;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Where no stretch lies the day has no data, and the lane shows through. */
.tl-lane {
  position: absolute;
  inset: 1.9rem 0 0.2rem 0;
  border-radius: 4px;
  background: var(--ground);
}

.tl-span {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-right: 1px solid rgba(255, 255, 255, 0.7);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

/* As estimated: striped, so what a label settled stands out solid beside it. */
.tl-span:not(.labelled) {
  background-image: repeating-linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.35) 0 4px,
    transparent 4px 9px
  );
}

/* A long stretch drawn shorter than it lasted, so the rest of the day keeps its room: thin
   dark lines across all of it, the other way from the estimate's stripes. Over the colour
   rather than in the background image, which the stripes already take. */
.tl-span.shortened::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(45deg, rgba(0, 0, 0, 0.4) 0 1px, transparent 1px 6px);
}

.tl-icon {
  position: relative;
}

.tl-span.changed {
  outline: 2px dashed var(--ink);
  outline-offset: -2px;
}

.tl-span.picked {
  box-shadow: inset 0 0 0 3px var(--accent);
}

.tl-edge {
  position: absolute;
  top: -0.25rem;
  bottom: -0.25rem;
  z-index: 2;
  width: 12px;
  margin-left: -6px;
  cursor: col-resize;
  touch-action: none;
}

.tl-edge::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 5px;
  width: 2px;
  background: var(--ink);
  opacity: 0;
}

.tl-edge:hover::after,
.tl-edge:focus-visible::after,
.tl-edge.active::after {
  opacity: 0.9;
}

.tl-edge:focus {
  outline: none;
}

.tl-time {
  display: none;
  position: absolute;
  bottom: calc(100% + 0.2rem);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  background: var(--ink);
  color: var(--card);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tl-edge.active .tl-time,
.tl-edge:focus-visible .tl-time {
  display: block;
}

.tl-popup {
  position: absolute;
  /* Above Leaflet's controls, which are at 1000. */
  z-index: 1100;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.tl-info {
  max-width: 24rem;
  margin: 0 0 0.35rem;
  padding: 0.1rem 0.3rem 0.4rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
  user-select: text;
  cursor: text;
}

.tl-modes {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 0.2rem;
}

.tl-popup button {
  padding: 0.25rem 0.5rem;
  border: 1px solid transparent;
  background: none;
  color: var(--ink);
  text-align: left;
  white-space: nowrap;
}

.tl-popup button:hover,
.tl-popup button:focus-visible {
  border-color: var(--line);
  background: var(--ground);
}

.tl-popup button.current {
  font-weight: 600;
}

/* Apart from the modes, since it is not one. */
.tl-popup button.delete {
  grid-column: 1 / -1;
  margin-top: 0.15rem;
  border-top: 1px solid var(--line);
  border-radius: 0;
  color: var(--bad);
}

/* Every digit as wide as the next, so the parts stay put while they change. */
.time-field {
  width: 6.5em;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

table.matrix td.agree {
  font-weight: 600;
  color: var(--good);
}

/* ── heat ───────────────────────────────────────────────────────────────── */

#heat-map {
  height: 80vh;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.heat-controls {
  display: grid;
  gap: 0.5rem;
}

.heat-controls .sub {
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* Near home that is hundreds of days; the list scrolls rather than pushing the page down. */
.heat-days {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.heat-days .table.scroll {
  max-height: 14rem;
}

/* The legend sits on the map, above the attribution, as narrow as it can be read. */
.heat-legend {
  width: 16rem;
  padding: 0.4rem 0.6rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 1px 4px rgb(0 0 0 / 15%);
}

.heat-popup .leaflet-popup-content {
  font-size: 0.9rem;
}

.heat-popup .leaflet-popup-content p {
  margin: 0 0 0.5rem;
}

.heat-popup table {
  font-size: 0.85rem;
}

.heat-note {
  margin: 0;
  font-size: 0.85rem;
}

label.check {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  color: var(--ink);
}

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

label.inline {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.checks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 0.2rem 0.75rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 0.75rem;
}

.grid2 input,
.grid2 select {
  width: 100%;
  box-sizing: border-box;
}

.stops {
  display: grid;
  gap: 0.35rem;
}

.stop {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.stop input[type='color'] {
  padding: 0;
  width: 2.5rem;
  height: 1.8rem;
}

/* A checkerboard behind the ramp, so its see-through end looks see-through. */
.ramp {
  height: 1rem;
  border-radius: 4px;
  border: 1px solid var(--line);
}

.ramp-ends {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--muted);
}

.wheel-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.wheel-row p {
  margin: 0;
  font-size: 0.85rem;
}

.wheel {
  flex: none;
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 50%;
  border: 1px solid var(--line);
}

.copy-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.copy-row input {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}

.layer-name {
  flex: none;
  width: 5.5rem;
  font-size: 0.85rem;
}

.tile-grid {
  box-sizing: border-box;
  border: 1px solid rgba(31, 111, 235, 0.45);
  color: #0a3069;
  font:
    11px ui-monospace,
    SFMono-Regular,
    Menlo,
    monospace;
  padding: 2px 4px;
  text-shadow: 0 0 2px #fff;
}

/* ── calendar ───────────────────────────────────────────────────────────── */

/* The key stays at the top of the window, so a calendar several screens long still says what
   its colours mean wherever the reader is in it. */
.cal-key {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  align-items: center;
  margin: 0.75rem 0;
  padding: 0.5rem 0;
  background: var(--ground);
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
  color: var(--muted);
}

.cal-ramp {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.cal-ramp .ramp {
  display: inline-block;
  width: 10rem;
  height: 0.8rem;
}

.cal-swatch {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 3px;
  vertical-align: middle;
}

.cal-section + .cal-section > .cal-year {
  margin-top: 1rem;
}

.cal-year h3 {
  margin: 0 0 0.4rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

/* One grid per line of months, all --sheet-columns wide: the count is measured in
   calendar.js, because only a whole line can be left out. The gap is SHEET_GAP_REM. */
.cal-sheets {
  display: grid;
  grid-template-columns: repeat(var(--sheet-columns, 3), minmax(0, 1fr));
  column-gap: 1rem;
}

.cal-sheets + .cal-sheets {
  margin-top: 0.75rem;
}

.cal-sheet h4 {
  margin: 0 0 0.25rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.cal-weekdays,
.cal-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.1875rem;
}

.cal-weekdays {
  margin-bottom: 0.1875rem;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.cal-days .day {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  min-width: 0;
  border-radius: 0.1875rem;
  background: var(--cell-fill);
  color: var(--cell-ink);
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  overflow: hidden;
  /* The reading is sized off the cell as laid out, which is what a size container is for. */
  container-type: size;
}

.cal-days a.day[href] {
  cursor: pointer;
}

.cal-days a.day[href]:hover {
  outline: 2px solid var(--ink);
  outline-offset: -1px;
}

/* As large as its cell can carry: capped by the type size, by the height, and by the width
   shared between the characters of a tabular figure (about 0.62 em each). */
.cal-days .reading {
  font-size: min(
    0.75rem,
    calc(100cqb * 0.8),
    calc(100cqi / (max(1, var(--reading-length, 1)) * 0.62))
  );
  line-height: 1;
  white-space: nowrap;
}

/* How far a day is labelled, drawn in the cell's own ink: dashed for part of it, solid for all. */
.cal-check {
  width: 68%;
  height: 68%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cal-check.some {
  stroke-dasharray: 2.2 1.9;
}

.cal-check.key {
  width: 1rem;
  height: 1rem;
  vertical-align: -0.2em;
  color: var(--ink);
}

/* A day with nothing recorded, which is not the bottom of the ramp: on a colour scale a zero is
   a colour. A cross in it, so the cell reads as an answer rather than as one that failed to
   draw. */
.cal-days .day.blank,
.cal-swatch.blank {
  position: relative;
  background: #eef1f3;
}

.cal-days .day.blank::before,
.cal-days .day.blank::after,
.cal-swatch.blank::before,
.cal-swatch.blank::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  height: 62%;
  width: min(0.16rem, 7%);
  min-width: 1px;
  border-radius: 999px;
  background: #b8c0c7;
}

.cal-days .day.blank::before,
.cal-swatch.blank::before {
  transform: rotate(45deg);
}

.cal-days .day.blank::after,
.cal-swatch.blank::after {
  transform: rotate(-45deg);
}

/* There is data, but not yet the number: the day has not been processed. */
.cal-days .day.unknown,
.cal-swatch.unknown {
  background: repeating-linear-gradient(45deg, #eef1f3 0 2px, #d9dee2 2px 3px);
}

/* Before the first day with data, or after today: a place held, so the days keep their
   weekday columns. */
.cal-days .day.pad {
  background: none;
}

/* A stretch with nothing in it, said in a line instead of drawn as a hundred empty cells. */
.cal-gap {
  margin: 0.75rem 0;
  padding: 0.375rem 0;
  border-top: 1px dashed var(--line);
  border-bottom: 1px dashed var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}

.cal-tip {
  position: fixed;
  z-index: 2000;
  max-width: 20rem;
  padding: 0.375rem 0.5rem;
  border-radius: 0.375rem;
  background: var(--ink);
  color: #fff;
  font-size: 0.8rem;
  pointer-events: none;
}

.cal-tip strong {
  display: block;
  margin-bottom: 0.15rem;
}

/* The body is several lines, and a newline is how it says so. */
.cal-tip span {
  white-space: pre-line;
}

/* The page's input box, padding and border, on a slider shortens the track the thumb can
   travel inside the box that is drawn: its ends looked out of reach. */
.heat-controls input[type='range'] {
  padding: 0;
  border: 0;
  margin: 0.35rem 0;
  background: transparent;
  accent-color: var(--accent);
}

/* ── statistics ─────────────────────────────────────────────────────────── */

/* Buttons of which one is chosen, side by side as one control. */
.toggles {
  display: inline-flex;
}

/* Square where two buttons meet, round only at the ends of the group. Of-type rather than
   child: x-for leaves its template in front of the first button. */
.toggles button {
  border-radius: 0;
  margin-left: -1px;
}

.toggles button:first-of-type {
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
  margin-left: 0;
}

.toggles button:last-of-type {
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
}

.toggles button[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  /* Its border over the neighbours' it overlaps. */
  position: relative;
  z-index: 1;
}

.toggles button[aria-pressed='false']:hover {
  background: var(--ground);
}

/* The statistics fit the window: the filters stay put, and only the table scrolls, under its
   header and above its total. A window too short for that scrolls as the other pages do. */
@media (height > 30rem) {
  body.fills {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.fills main {
    flex: 1;
    min-height: 0;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    padding-bottom: 1rem;
  }

  body.fills .fills-rest {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  body.fills .table.scroll {
    flex: 0 1 auto;
    min-height: 8rem;
    max-height: none;
  }
}

/* Fixed widths, so the columns hold still while rows come and go as the table scrolls. */
table.statistics {
  table-layout: fixed;
}

table.statistics th,
table.statistics td {
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* One height for every row: the rows out of view are stood in for by their number times it. */
table.statistics tbody tr.line td {
  height: 2rem;
  padding-top: 0;
  padding-bottom: 0;
  box-sizing: border-box;
}

table.statistics tr.pad td {
  padding: 0;
  border: 0;
}

table.statistics .bar {
  min-width: 0;
}

table.statistics th {
  cursor: grab;
}

table.statistics th .head {
  display: inline-flex;
  gap: 0.3rem;
}

.table.scroll.loading table {
  opacity: 0.5;
  transition: opacity 0.2s 0.2s;
}

.loading-spinner {
  width: 1.1rem;
  height: 1.1rem;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: loading-spin 0.8s linear infinite;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

table.statistics th.dragging {
  opacity: 0.4;
}

/* Where a dragged column goes. The header keeps its bottom line, which is a shadow too. */
table.statistics th.drop-before {
  box-shadow:
    inset 3px 0 0 var(--accent),
    inset 0 -1px 0 var(--line);
}

table.statistics th.drop-after {
  box-shadow:
    inset -3px 0 0 var(--accent),
    inset 0 -1px 0 var(--line);
}

/* The total stays at the bottom of the scroller, as the header stays at its top. Its line is a
   shadow for the same reason as the header's. */
table.statistics tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 1;
  background: var(--card);
  font-weight: 600;
  border-bottom: 0;
  box-shadow: inset 0 2px 0 var(--line);
}

table.statistics .period {
  display: inline-flex;
  gap: 0.4rem;
}

/* A day as it went: each stretch placed at its time of day, with nothing where nothing is known. */
.bar.placed {
  display: block;
  position: relative;
}

.bar.placed span {
  position: absolute;
  top: 0;
  bottom: 0;
}

@media (prefers-reduced-motion: reduce) {
  .loading-spinner {
    animation-duration: 3s;
  }
}
