/* COG Place Explorer: the finder (map, search, list) and the breadcrumb.
 *
 * Colours are Bootstrap custom properties, which bslib derives from
 * _brand.yml. No literals here: brand lives in one file.
 */

.cog-explore { padding: .5rem 1rem 2rem; }

/* -- Breadcrumb ----------------------------------------------------------- */
.cog-crumbs {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem .4rem;
  font-size: .9rem; padding: .25rem 0 .5rem;
}
.cog-crumb { color: var(--bs-primary); text-decoration: none; }
.cog-crumb:hover, .cog-crumb:focus-visible { text-decoration: underline; }
.cog-crumb-sep { color: var(--cog-muted); }
.cog-crumb-here { font-weight: 600; }

/* -- The heading: what to do at this step --------------------------------- */
/* Tall enough for two lines at every step, so a one-line heading does not
   pull the map up when the level changes. */
.cog-heading {
  text-align: center; font-weight: 800; line-height: 1.15;
  font-size: clamp(1.45rem, 3.4vw, 2.3rem);
  max-width: 46rem; min-height: 2.3em; margin: .5rem auto 1rem;
  animation: cog-heading-in 250ms ease-out both;
}
.cog-accent { color: var(--bs-secondary); }
/* The front page's heading says what the app is; the line under it says what
   to do. Together they stand taller than the two-line minimum the other levels
   reserve, so the map moves up a little when a reader opens a state. */
.cog-heading-lead {
  min-height: 0; max-width: 52rem; margin-bottom: .35rem; text-wrap: balance;
}
.cog-subheading {
  text-align: center; max-width: 40rem; margin: 0 auto 1rem; text-wrap: balance;
  font-size: clamp(1rem, 1.6vw, 1.15rem); color: var(--cog-muted);
  animation: cog-heading-in 250ms ease-out both;
}
@media (prefers-reduced-motion: reduce) { .cog-subheading { animation: none; } }
@keyframes cog-heading-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .cog-heading { animation: none; } }

/* -- Map and search ------------------------------------------------------- */
.cog-finder {
  position: relative;
  --cog-map-h: min(80vh, 860px);
  --cog-map-aspect: 1.6;
}
/* As tall as the screen allows, and no wider than the country needs at that
   height (it is about 1.6 times as wide as tall), so a wide screen gets no
   empty frame either side. */
.cog-map {
  position: relative; height: var(--cog-map-h); min-height: 360px;
  width: min(100%, calc(var(--cog-map-h) * var(--cog-map-aspect))); margin: 0 auto;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color); border-radius: .5rem; overflow: hidden;
}
.cog-map canvas, .cog-map svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.cog-map .cog-state, .cog-map .cog-county {
  fill: var(--bs-tertiary-bg); stroke: var(--bs-border-color); stroke-width: .75;
  cursor: pointer; vector-effect: non-scaling-stroke;
}
.cog-map .cog-state:hover, .cog-map .cog-county:hover,
.cog-map .cog-state:focus-visible, .cog-map .cog-county:focus-visible {
  fill: var(--bs-primary-bg-subtle); stroke: var(--bs-primary); outline: none;
}
.cog-map .cog-state.cog-current { fill: none; stroke: var(--bs-primary); cursor: default; }
/* A county clicked on the map lifts for a moment before the map moves. */
.cog-map .cog-county.cog-lift { fill: var(--bs-primary-bg-subtle); stroke: var(--bs-primary); stroke-width: 2.4; }
.cog-map-error {
  position: absolute; inset: auto 1rem 1rem auto; margin: 0; max-width: 24rem;
  background: var(--bs-body-bg); border: 1px solid var(--bs-border-color);
  border-radius: .25rem; padding: .5rem .75rem; font-size: .85rem;
}
/* Names on the map (www/map_labels.js): counties where they fit, and the
   state's five largest cities, which pop in one after another. */
.cog-map svg.cog-map-labels {
  pointer-events: none; z-index: 2; opacity: 0; transition: opacity 150ms ease-out;
}
.cog-map svg.cog-map-labels.cog-shown { opacity: 1; }
/* Faded out for a move: no longer clickable, since the map moves under it. */
.cog-map-labels:not(.cog-shown) .cog-map-city { pointer-events: none; }
.cog-map-labels text {
  paint-order: stroke; stroke: var(--bs-body-bg); stroke-width: 3px; stroke-linejoin: round;
}
.cog-map-county { font-size: 11px; font-weight: 500; fill: var(--cog-muted); text-anchor: middle; }
.cog-map-city { pointer-events: auto; cursor: pointer; }
.cog-map-city circle { fill: var(--bs-secondary); stroke: var(--bs-body-bg); stroke-width: 1.5; }
.cog-map-city text { font-size: 13px; font-weight: 700; fill: var(--bs-body-color); }
.cog-map-city-pop {
  animation: cog-city-pop 500ms cubic-bezier(.3, 1.6, .5, 1) both;
  animation-delay: calc(150ms + var(--i, 0) * 140ms);
}
@keyframes cog-city-pop { from { transform: scale(0); } to { transform: scale(1); } }
.cog-map-labels.cog-still .cog-map-city-pop { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .cog-map svg.cog-map-labels { transition: none; }
  .cog-map-city-pop { animation: none; }
}
.cog-map-tip {
  position: absolute; pointer-events: none; z-index: 3;
  background: var(--bs-body-bg); border: 1px solid var(--bs-border-color);
  border-radius: .25rem; padding: 2px 6px; font-size: .8rem; white-space: nowrap;
}

/* The search sits centred above the map, so the map takes the full width.
   Results drop down over the map's top rather than pushing it down. */
.cog-search {
  position: relative; z-index: 4;
  width: min(560px, 100%); margin: 0 auto .75rem;
}
.cog-search .shiny-input-container { margin-bottom: 0; }
.cog-search .cog-results, .cog-search .cog-empty {
  position: absolute; top: calc(100% + .25rem); left: 0; right: 0;
  background: var(--bs-body-bg); border: 1px solid var(--bs-border-color);
  border-radius: .5rem; padding: .5rem; box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
}
/* Bootstrap's placeholder colour is its secondary colour, which is ember here. */
.cog-search input::placeholder { color: var(--cog-muted); opacity: 1; }
.cog-search .cog-results { max-height: 50vh; }
.cog-result-state { font-weight: 400; color: var(--cog-muted); margin-left: .35rem; }

@media (max-width: 575.98px) {
  .cog-explore { padding: .5rem .5rem 2rem; }
  .cog-search { margin-bottom: .5rem; }
  /* A phone is narrow, so the width sets the size; a little taller than
     the country's shape leaves room for a zoomed state such as Texas. */
  .cog-map { width: 100%; height: calc((100vw - 1rem) / 1.3); min-height: 240px; }
}

/* -- The stage: the map, and its list under it or beside it --------------- */
/* At county level the list moves into a column beside the map on a wide
   screen; map.js toggles .cog-split and waits for the slide before it
   zooms. On a narrower screen the map pins to the top instead and the list
   scrolls beneath it. */
.cog-stage { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 0fr); gap: 0; }
.cog-stage > .cog-map { grid-column: 1; grid-row: 1; }
/* Shiny draws an output's wrapper as display: contents, which would hand the
   list itself to the grid's auto-placement and its zero-width column. */
.cog-stage-list { display: block; grid-column: 1 / -1; grid-row: 2; min-width: 0; }
@media (min-width: 992px) {
  .cog-stage {
    transition: grid-template-columns 450ms cubic-bezier(.2, .8, .2, 1),
                gap 450ms cubic-bezier(.2, .8, .2, 1);
  }
  .cog-stage.cog-split { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1rem; }
  .cog-stage.cog-split > .cog-map { width: 100%; }
  .cog-stage.cog-split > .cog-stage-list { grid-column: 2; grid-row: 1; overflow: hidden; }
  .cog-stage.cog-split .cog-levels {
    margin-top: 0; columns: auto; height: var(--cog-map-h); min-height: 360px;
    overflow: auto; padding: 1rem; background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color); border-radius: .5rem;
  }
}
@media (max-width: 991.98px) {
  .cog-stage.cog-split { --cog-pin-h: 45vh; }
  .cog-stage.cog-split > .cog-map {
    /* Above the list scrolling under it, below the search results (z-index 4). */
    position: sticky; top: 0; z-index: 3; height: var(--cog-pin-h);
    box-shadow: 0 8px 14px -10px rgba(0, 0, 0, .35);
  }
}
@media (max-width: 575.98px) {
  .cog-stage.cog-split { --cog-pin-h: calc((100vw - 1rem) / 1.3); }
}
/* The county's rows cascade in, numbered by R (level_list_ui). */
.cog-county-list .cog-result {
  animation: cog-row-in 450ms cubic-bezier(.3, 1.5, .5, 1) both;
  animation-delay: calc(var(--i, 0) * 35ms);
}
@keyframes cog-row-in {
  from { opacity: 0; transform: translateX(18px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .cog-stage { transition: none; }
  .cog-county-list .cog-result { animation: none; }
}

/* -- The list beside the map, and the note under it ----------------------- */
.cog-levels { max-height: none; margin-top: 1rem; columns: 16rem; column-gap: 1rem; }
.cog-levels .cog-result { break-inside: avoid; }
.cog-levels-heading { column-span: all; font-size: 1rem; margin: 0 0 .5rem; }
.cog-level-row .cog-result-name { font-weight: 400; }
/* A row the map is pointing at (www/map_link.js). */
.cog-levels .cog-result.cog-lit { background: var(--bs-primary-bg-subtle); }
.cog-finder-note { max-width: 44rem; margin-top: 1rem; font-size: .9rem; }
.cog-dot-caption { font-weight: 600; }
