/* The chemotype map. The page is a HUD, not a dashboard: one field of points,
   one pinned dossier, and a toolbar that changes the lens rather than the
   underlying corpus. The existing green accent is the active signal; amber is
   a partial profile and red is a failed panel. */

.chemotype-map {
  --chemotype-map-mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Menlo, Consolas, monospace;
  /* A recall is a status marker, not a category. Keep this red brighter than
     the cluster red and the failed-panel red so it cannot be read as either. */
  --chemotype-map-recall: #ff3b30;
  box-sizing: border-box;
  /* The board's frame, repeated rather than inherited: this stylesheet loads
     before application.css (`yield :head` precedes the manifest), so a shared
     `.board` class would lose its padding to the later rule at the 640px
     breakpoint. Same edges and rhythm as every other top-level page. */
  width: 100%;
  max-width: 74rem;
  margin: 0 auto;
  /* The bottom gap is inside a viewport-tall frame rather than after a
     scrolling document, so it is one breath below the footer, not the 4rem a
     board reserves at the end of its content. */
  padding: 2rem 1.25rem 1.25rem;
  /* Body is a column flex container, so the chemotype map takes the height the menu
     actually leaves instead of guessing the chrome with `100vh - 5rem`: the
     menu wraps to a second row at narrower widths, and the guess both
     overflowed then and left a dead band on a single row. The extra height
     goes to the shell, which is where the dossier lives. */
  flex: 1 1 auto;
  height: auto;
  min-height: 42rem;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: 1.25rem;
}

/* The head is the board's masthead. The map title is two lines (kicker and
   h1), so baseline alignment would put the status beside the kicker; bottom
   alignment keeps it beside the title. */
.chemotype-map .masthead {
  align-items: end;
}

.chemotype-map .masthead h1 {
  margin-top: 0.1rem;
}

.chemotype-map-kicker {
  margin: 0;
  color: var(--muted);
  font-family: var(--chemotype-map-mono);
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.chemotype-map-kicker--section {
  margin-top: 0.8rem;
}

.chemotype-map-status {
  text-align: right;
}

.chemotype-map-stamp {
  margin: 0;
  color: var(--muted);
  font-family: var(--chemotype-map-mono);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
}

.chemotype-map-stamp--dim {
  color: #5f6878;
  margin-top: 0.15rem;
}

.chemotype-map-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 0.65rem;
  /* The panel box: same corners and inner padding as `.panel` on the other
     pages, so the filter strip reads as the first pane rather than a bar. */
  padding: 1rem 1.125rem 1.125rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.chemotype-map-projections,
.chemotype-map-lenses {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.lens,
.chemotype-map-action {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-family: var(--chemotype-map-mono);
  font-size: 0.6rem;
  letter-spacing: 0.07em;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

.lens:hover,
.chemotype-map-action:hover {
  color: var(--ink);
  border-color: #465164;
}

.lens.is-active,
.chemotype-map-action.is-active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(127, 209, 174, 0.08);
}

.chemotype-map-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.65rem;
  margin-left: auto;
}

.chemotype-map-filter {
  display: grid;
  gap: 0.2rem;
  color: var(--muted);
  font-family: var(--chemotype-map-mono);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
}

.chemotype-map-filter select,
.chemotype-map-filter input {
  min-width: 7.5rem;
  padding: 0.32rem 0.4rem;
  border: 1px solid var(--line);
  background: #0d1117;
  color: var(--ink);
  font: 0.72rem/1.4 var(--chemotype-map-mono);
  outline: none;
}

.chemotype-map-filter input {
  min-width: 11rem;
}

.chemotype-map-filter select:focus,
.chemotype-map-filter input:focus {
  border-color: var(--accent);
}

.chemotype-map-chart-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 0.15rem;
  color: var(--muted);
  font-family: var(--chemotype-map-mono);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.chemotype-map-chart-label strong {
  color: var(--accent);
  font-weight: 500;
}

.chemotype-map-shell {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 22rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.chemotype-map-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  cursor: crosshair;
  background:
    radial-gradient(circle at 50% 48%, rgba(127, 209, 174, 0.06), transparent 58%),
    linear-gradient(180deg, #0c1014, #090c10);
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.55);
}

.chemotype-map-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.018) 0,
    rgba(255, 255, 255, 0.018) 1px,
    transparent 1px,
    transparent 3px
  );
  opacity: 0.55;
}

.chemotype-map-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
}

.chemotype-map-frame {
  position: absolute;
  inset: 0.55rem;
  z-index: 5;
  pointer-events: none;
}

.chemotype-map-frame i {
  position: absolute;
  width: 14px;
  height: 14px;
  border-color: rgba(127, 209, 174, 0.48);
  border-style: solid;
}

.chemotype-map-frame i:nth-child(1) {
  top: 0;
  left: 0;
  border-width: 1px 0 0 1px;
}

.chemotype-map-frame i:nth-child(2) {
  top: 0;
  right: 0;
  border-width: 1px 1px 0 0;
}

.chemotype-map-frame i:nth-child(3) {
  bottom: 0;
  left: 0;
  border-width: 0 0 1px 1px;
}

.chemotype-map-frame i:nth-child(4) {
  right: 0;
  bottom: 0;
  border-width: 0 1px 1px 0;
}

.chemotype-map-hud {
  position: absolute;
  z-index: 6;
  color: #6f7a8b;
  font-family: var(--chemotype-map-mono);
  font-size: 0.58rem;
  letter-spacing: 0.09em;
  line-height: 1.55;
  pointer-events: none;
}

.chemotype-map-hud strong {
  display: block;
  color: var(--accent);
  font-weight: 500;
}

.chemotype-map-hud--tl {
  top: 0.8rem;
  left: 0.85rem;
}

.chemotype-map-hud--br {
  right: 0.85rem;
  bottom: 0.8rem;
  text-align: right;
}

.chemotype-map-tooltip {
  position: absolute;
  z-index: 20;
  max-width: 24rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid rgba(127, 209, 174, 0.55);
  background: rgba(9, 13, 17, 0.97);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  color: var(--ink);
  font-size: 0.72rem;
  line-height: 1.45;
  pointer-events: none;
}

.chemotype-map-tooltip[hidden] {
  display: none;
}

.chemotype-map-tooltip-body {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
}

.chemotype-map-tooltip-image {
  width: 3rem;
  height: 3rem;
  flex: none;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.03);
}

.chemotype-map-tooltip-text {
  min-width: 0;
}

.chemotype-map-tooltip b {
  display: block;
  margin-bottom: 0.15rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.chemotype-map-tooltip span {
  display: block;
  color: var(--muted);
}

.chemotype-map-tooltip .hi {
  color: var(--ink);
}

.chemotype-map-tooltip .warn {
  color: #d6a756;
}

.chemotype-map-tooltip .bad {
  color: var(--bad);
}

.chemotype-map-tooltip .recall {
  color: var(--chemotype-map-recall);
  font-family: var(--chemotype-map-mono);
  font-size: 0.6rem;
  letter-spacing: 0.08em;
}

.chemotype-map-stamp .recall {
  color: var(--chemotype-map-recall);
}

.chemotype-map-recall {
  margin: 0 0 0.7rem;
  padding: 0.38rem 0.45rem;
  border: 1px solid rgba(255, 59, 48, 0.55);
  background: rgba(255, 59, 48, 0.08);
  color: #ff8178;
  font-family: var(--chemotype-map-mono);
  font-size: 0.6rem;
  letter-spacing: 0.03em;
  line-height: 1.5;
}

.chemotype-map-recall strong {
  color: var(--chemotype-map-recall);
  letter-spacing: 0.08em;
}

.chemotype-map-recall a {
  color: #ff9b93;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 155, 147, 0.4);
}

.chemotype-map-recall a:hover {
  color: var(--ink);
}

.chemotype-map-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 7;
  width: min(26rem, 80%);
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-family: var(--chemotype-map-mono);
  font-size: 0.7rem;
  line-height: 1.6;
  text-align: center;
  pointer-events: none;
}

.chemotype-map-dossier {
  min-width: 0;
  min-height: 0;
  padding: 0.9rem 1rem 1.1rem;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: rgba(20, 24, 31, 0.72);
}

.chemotype-map-dossier-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding-bottom: 0.45rem;
  margin-bottom: 0.7rem;
  border-bottom: 1px solid var(--line);
}

.chemotype-map-pin {
  margin: 0;
  padding: 0.12rem 0.32rem;
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--chemotype-map-mono);
  font-size: 0.55rem;
  letter-spacing: 0.1em;
}

.chemotype-map-pin.is-pinned {
  color: var(--accent);
  border-color: var(--accent);
}

.chemotype-map-muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.chemotype-map-when-coarse {
  display: none;
}

.chemotype-map-dossier h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

/* The image sits beside the product name, as on the product page: it is the
   label the name describes, not a page banner. No image means no box, so the
   heading takes the width instead of leaving a hole. */
.chemotype-map-dossier-title {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  margin-bottom: 0.5rem;
}

.chemotype-map-dossier-title h2 {
  min-width: 0;
  margin: 0;
}

.chemotype-map-dossier-image {
  width: 5.5rem;
  height: 5.5rem;
  flex: none;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
}

.chemotype-map-lines {
  display: grid;
  gap: 0.28rem;
  margin: 0;
  font-size: 0.74rem;
}

.chemotype-map-line {
  display: grid;
  grid-template-columns: 4.6rem 1fr;
  gap: 0.5rem;
}

.chemotype-map-line .k {
  color: var(--muted);
}

.chemotype-map-line .v {
  overflow-wrap: anywhere;
}

/* An entity value with a catalog record links to it. The green line is the
   clickability signal -- the accent marks the active/selected thing -- so the
   text keeps the value color and only the underline is green. */
.chemotype-map-ref {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--ref-line);
}

.chemotype-map-ref:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.chemotype-map-badge {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0.1rem 0.28rem;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--chemotype-map-mono);
  font-size: 0.55rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  vertical-align: middle;
}

.chemotype-map-badge.is-partial {
  color: #d6a756;
  border-color: #d6a756;
}

.chemotype-map-badge.is-fail {
  color: var(--bad);
  border-color: var(--bad);
}

.chemotype-map-bars {
  display: grid;
  gap: 0.24rem;
  margin: 0.8rem 0 0;
  padding: 0;
  list-style: none;
}

.chemotype-map-bar {
  display: grid;
  grid-template-columns: 4.2rem minmax(0, 1fr) 3rem;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.66rem;
}

.chemotype-map-bar .track {
  display: block;
  width: 100%;
  height: 5px;
  overflow: hidden;
  border-radius: 2px;
  background: #232a33;
}

.chemotype-map-bar .fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, rgba(127, 209, 174, 0.35), var(--accent));
}

.chemotype-map-bar .num {
  color: var(--ink);
  text-align: right;
}

/* A terpene name is longer than a cannabinoid's and the amount carries a unit
   ("12.4 mg/g"), so both the label and number columns widen. The name
   ellipsises rather than pushing the bar to nothing; the full name is the
   row's title. */
.chemotype-map-bars--terpenes .chemotype-map-bar {
  grid-template-columns: 6.6rem minmax(0, 1fr) 4.6rem;
}

.chemotype-map-bars--terpenes .chemotype-map-bar > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chemotype-map-panels {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0.7rem 0 0;
  padding: 0;
  list-style: none;
}

.chemotype-map-panel {
  padding: 0.14rem 0.32rem;
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--chemotype-map-mono);
  font-size: 0.58rem;
  letter-spacing: 0.03em;
}

.chemotype-map-panel.is-pass {
  border-color: rgba(127, 209, 174, 0.35);
}

.chemotype-map-panel.is-fail {
  color: var(--bad);
  border-color: var(--bad);
}

.chemotype-map-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.8rem;
}

.chemotype-map-link {
  display: inline-block;
  margin-top: 0.8rem;
  color: var(--accent);
  font-family: var(--chemotype-map-mono);
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  text-decoration: none;
  border-bottom: 1px solid rgba(127, 209, 174, 0.35);
}

.chemotype-map-link:hover {
  color: var(--ink);
}

.chemotype-map-footer {
  box-sizing: border-box;
  /* The legend usually needs two rows, not the old fixed six: cap it so a
     long legend still scrolls instead of pushing the shell down, but let the
     slack go to the dossier. */
  max-height: 6rem;
  overflow-y: auto;
  display: grid;
  gap: 0.3rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  background: var(--panel);
}

.chemotype-map-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.9rem;
  font-size: 0.66rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-family: var(--chemotype-map-mono);
  font-size: 0.62rem;
}

.legend-item .swatch {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex: none;
}

.legend-item strong {
  color: var(--ink);
  font-weight: 500;
}

.legend-item .n {
  color: var(--muted);
}

.legend-item.is-selected {
  color: var(--accent);
}

.legend-empty {
  color: var(--muted);
  font-family: var(--chemotype-map-mono);
  font-size: 0.62rem;
}

.chemotype-map-note {
  margin: 0;
  color: #6f7a8b;
  font-size: 0.63rem;
  line-height: 1.5;
}

.chemotype-map-recall-key {
  color: #ff8178;
  white-space: nowrap;
}

.chemotype-map-recall-key i {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  margin-right: 0.3rem;
  border: 1px solid var(--chemotype-map-recall);
  border-radius: 50%;
  opacity: 0.72;
  vertical-align: -0.1rem;
}

.chemotype-map-note kbd {
  padding: 0.02rem 0.2rem;
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--chemotype-map-mono);
  font-size: 0.58rem;
}

/* Interactive text on the map is a link or a button, and a touch should not
   wait out the double-tap-zoom window before it acts. */
.chemotype-map-ref,
.chemotype-map-link,
.chemotype-map-recall a,
.lens,
.chemotype-map-action {
  touch-action: manipulation;
}

/* A finger needs more than the desktop underline. The entity link's row
   carries the height and its ::after fills it; the button controls get a
   full-height target. */
@media (pointer: coarse) {
  .chemotype-map-when-fine {
    display: none;
  }

  .chemotype-map-when-coarse {
    display: inline;
  }

  /* A finger needs the whole fact, not the word. The row carries the height and
     the link's ::after fills it, so the underline stays against the text and the
     label is tappable too. */
  .chemotype-map-lines {
    gap: 0;
  }

  .chemotype-map-line {
    position: relative;
    align-items: center;
    padding: 0.75rem 0;
  }

  .chemotype-map-line .chemotype-map-ref::after {
    content: "";
    position: absolute;
    inset: 0;
  }

  /* These two stand on their own, so the padding is on the link and the border
     would read as a divider; a text decoration keeps the line with the word. */
  .chemotype-map-link,
  .chemotype-map-recall a {
    display: inline-block;
    padding: 0.75rem 0;
    border-bottom: 0;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    text-decoration-color: rgba(127, 209, 174, 0.35);
  }

  .chemotype-map-recall a {
    text-decoration-color: rgba(255, 155, 147, 0.4);
  }

  .lens,
  .chemotype-map-action {
    min-height: 2.75rem;
  }
}

@media (max-width: 980px) {
  .chemotype-map {
    /* Stacked, the chemotype map is taller than the viewport, so it is content-sized
       and scrolls as a normal document rather than being squeezed into the
       body's viewport height (the shell's overflow:hidden would clip the
       dossier). */
    flex: none;
    min-height: calc(100dvh - 4rem);
  }

  .chemotype-map-footer {
    /* Stacked, the footer no longer competes with the shell for viewport
       height, so it grows with the legend instead of scrolling. */
    max-height: none;
    overflow-y: visible;
  }

  .chemotype-map-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .chemotype-map-stage {
    min-height: 28rem;
  }

  .chemotype-map-dossier {
    /* Stacked, the dossier is part of the page scroll. Its own 24rem viewport
       hid the last rows (and OPEN COA) below an inner fold, and a tap inside a
       nested scroller competes with the page's own scroll gesture. */
    height: auto;
    max-height: none;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .chemotype-map-filters {
    width: 100%;
    margin-left: 0;
  }
}

@media (max-width: 640px) {
  .chemotype-map {
    padding: 1.25rem 0.875rem 1.25rem;
  }

  .chemotype-map-toolbar {
    padding: 0.875rem;
  }

  .chemotype-map-filter {
    width: 100%;
  }

  .chemotype-map-filter select,
  .chemotype-map-filter input {
    width: 100%;
  }

  .chemotype-map-stage {
    min-height: 24rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lens,
  .chemotype-map-action {
    transition: none;
  }
}
