:root {
  /* USLGE brand: flag navy + crimson + charcoal, white chrome (uslge.org) */
  --bg: #f4f4f6;
  --surface: #ffffff;
  --surface-2: #f4f4f6;
  --navy: #1a1966;
  --red: #9d1c1c;
  --ocean: #dce2ef;
  --land: #fafafb;
  --land-stroke: #c6cbd8;
  --hairline: #e3e3ea;
  --text: #1c1c22;
  --muted: #63636e;
  --tag: #ffd24d;
  --tag-ink: #201804;
  --focus: #1a1966;

  /* validated species palette (light surface #ffffff) */
  --sp-dairy: #2a78d6;
  --sp-sheep: #1baf7a;
  --sp-goat: #4a3aa7;
  --sp-beef: #e34948;
  --sp-swine: #e87ba4;
  --sp-equine: #eb6834;

  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --display: "Zilla Slab", Georgia, serif;
  --body: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 14px;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  grid-template-columns: 264px 1fr;
  grid-template-areas:
    "top top"
    "side map"
    "side tl"
    "foot foot";
  height: 100vh;
  overflow: hidden;
}

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

/* ---------- top bar ---------- */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { height: 40px; width: auto; flex: none; }
.brand h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 19px;
  margin: 0;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.brand-sub { margin: 1px 0 0; color: var(--muted); font-size: 11.5px; white-space: nowrap; }

.stats { display: flex; gap: 26px; margin-left: auto; }
.stat { text-align: right; }
.stat .v {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.3px;
}
.stat .k {
  color: var(--muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.top-actions { display: flex; gap: 8px; }

.btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--hairline);
  border-radius: 7px;
  padding: 7px 12px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.icon { padding: 5px 9px; line-height: 1; }
.link-btn {
  background: none; border: none; color: var(--muted);
  font: inherit; font-size: 11.5px; cursor: pointer; padding: 2px 4px;
}
.link-btn:hover { color: var(--text); }

/* ---------- sidebar ---------- */
.sidebar {
  grid-area: side;
  border-right: 1px solid var(--hairline);
  background: var(--surface);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.side-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.side-block h2 {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  margin: 0;
  font-weight: 600;
}
#countrySearch, #orgSelect {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 7px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
}
.search-results {
  list-style: none; margin: 6px 0 0; padding: 0;
  border: 1px solid var(--hairline); border-radius: 7px;
  background: var(--surface-2); max-height: 180px; overflow-y: auto;
}
.search-results li button {
  display: flex; justify-content: space-between; width: 100%;
  background: none; border: none; color: var(--text);
  font: inherit; font-size: 13px; padding: 7px 10px; cursor: pointer; text-align: left;
}
.search-results li button:hover { background: #ecedf6; }
.search-results .n { font-family: var(--mono); color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  color: var(--text);
  font: inherit; font-size: 12.5px;
  padding: 5px 11px 5px 8px;
  cursor: pointer;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.chip .n { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.chip[aria-pressed="true"] {
  border-color: var(--navy);
  background: #ecedf6;
}
.chip:hover { border-color: var(--muted); }

/* ---------- map ---------- */
.map-wrap { grid-area: map; position: relative; overflow: hidden; background: var(--ocean); }
#map { width: 100%; height: 100%; display: block; cursor: grab; }
#map:active { cursor: grabbing; }
.country { fill: var(--land); stroke: var(--land-stroke); stroke-width: 0.6; }
.country.active { fill: #e9ecf7; }

.tag-marker { cursor: pointer; }
.tag-marker .plate { fill: var(--tag); stroke: rgba(32,24,4,0.4); stroke-width: 1; }
.tag-marker .tab { fill: var(--tag); stroke: rgba(32,24,4,0.4); stroke-width: 1; }
.tag-marker .hole { fill: var(--ocean); }
.tag-marker text {
  font-family: var(--mono);
  font-weight: 600;
  fill: var(--tag-ink);
  text-anchor: middle;
  pointer-events: none;
}
.tag-marker:hover .plate, .tag-marker:hover .tab,
.tag-marker.selected .plate, .tag-marker.selected .tab { fill: #ffe28a; }
.tag-marker.selected .plate { stroke: var(--navy); stroke-width: 1.5; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 10px 12px;
  max-width: 240px;
  box-shadow: 0 6px 24px rgba(20,22,78,0.28);
  z-index: 20;
}
.tooltip h3 { margin: 0 0 2px; font-family: var(--display); font-size: 14.5px; font-weight: 600; }
.tooltip .tt-total { color: var(--muted); font-size: 11.5px; margin-bottom: 7px; }
.tt-row { display: flex; align-items: center; gap: 7px; font-size: 12px; padding: 1.5px 0; }
.tt-row .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.tt-row .n { margin-left: auto; font-family: var(--mono); color: var(--muted); }
.tt-value { margin-top: 7px; padding-top: 7px; border-top: 1px solid var(--hairline); font-size: 11.5px; color: var(--muted); }
.tt-value b { color: var(--text); font-family: var(--mono); font-weight: 600; }

/* ---------- timeline ---------- */
.timeline {
  grid-area: tl;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px 12px;
  border-top: 1px solid var(--hairline);
  background: var(--surface);
}
.play-btn {
  width: 34px; height: 34px; flex: none;
  border-radius: 50%;
  border: none;
  background: var(--red);
  color: #ffffff;
  cursor: pointer;
  display: grid; place-items: center;
}
.play-btn:hover { background: #b62f2f; }
.timeline-body { flex: 1; min-width: 0; }
.timeline-label {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 2px;
}
.timeline-label b { color: var(--text); font-weight: 600; }
#tlChart { width: 100%; height: 46px; display: block; }
#tlChart .q-bar { fill: #cdced9; }
#tlChart .q-bar.in-range { fill: var(--navy); }
#tlChart .brush .selection { fill: rgba(26,25,102,0.08); stroke: var(--navy); stroke-width: 1; }
#tlChart .axis text { font-family: var(--mono); font-size: 9.5px; fill: var(--muted); }
#tlChart .axis line, #tlChart .axis path { stroke: var(--hairline); }

/* ---------- country panel ---------- */
.panel {
  position: fixed;
  top: 76px; right: 16px; bottom: 86px;
  width: 340px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(20,22,78,0.22);
  z-index: 30;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--hairline);
}
.eyebrow {
  margin: 0; font-size: 10px; letter-spacing: 1.4px;
  text-transform: uppercase; color: var(--muted);
}
.panel-head h2 { margin: 2px 0 2px; font-family: var(--display); font-size: 21px; font-weight: 600; }
.panel-sub { margin: 0; color: var(--muted); font-size: 12px; }
.panel-mix { padding: 12px 16px; border-bottom: 1px solid var(--hairline); }
.mix-row { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 2px 0; }
.mix-row .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.mix-row .bar-track { display: block; flex: 1; height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.mix-row .bar { display: block; height: 100%; border-radius: 3px; }
.mix-row .n { font-family: var(--mono); font-size: 11px; color: var(--muted); width: 26px; text-align: right; }
.panel-list { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }

.trip-card {
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 9px;
  padding: 11px 12px;
}
.trip-card h3 { margin: 0 0 3px; font-size: 13.5px; font-weight: 600; line-height: 1.35; }
.trip-meta { color: var(--muted); font-size: 11.5px; margin-bottom: 6px; }
.trip-meta .val { font-family: var(--mono); color: var(--navy); font-weight: 600; }
.trip-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; color: var(--muted);
  border: 1px solid var(--hairline); border-radius: 999px;
  padding: 2px 8px;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; }
.trip-sum { font-size: 12px; line-height: 1.5; color: #45454e; margin: 0; }
.trip-sum.clamped { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.trip-more { margin-top: 4px; }

/* ---------- modal (table + about) ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20,22,78,0.45);
  display: grid; place-items: center;
  padding: 30px;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  width: min(1080px, 100%);
  max-height: 100%;
  display: flex; flex-direction: column;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--hairline);
}
.modal-head h2 { margin: 0; font-family: var(--display); font-size: 19px; font-weight: 600; }
.modal-body { overflow: auto; padding: 0 20px 20px; }
.modal-body.prose { padding-top: 16px; max-width: 720px; font-size: 14px; line-height: 1.65; }
.modal-body.prose p { margin: 0 0 12px; }

table.trips {
  width: 100%; border-collapse: collapse; font-size: 12.5px;
}
table.trips th {
  position: sticky; top: 0; background: var(--surface);
  text-align: left; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--muted);
  padding: 12px 10px 8px; border-bottom: 1px solid var(--hairline);
}
table.trips td { padding: 8px 10px; border-bottom: 1px solid var(--hairline); vertical-align: top; }
table.trips td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---------- footer ---------- */
.footnote {
  grid-area: foot;
  padding: 7px 20px;
  font-size: 10.5px;
  color: var(--muted);
  border-top: 1px solid var(--hairline);
  background: var(--surface);
}

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  body {
    grid-template-columns: 1fr;
    grid-template-areas: "top" "map" "tl" "foot";
    overflow: auto;
    height: auto;
  }
  .sidebar { display: none; }
  .map-wrap { height: 62vh; }
  .stats { display: none; }
  .panel { left: 12px; right: 12px; width: auto; top: 90px; bottom: 120px; }
}

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