/* Longshot-specific layout and third-party chrome.
   Every value comes from the Kygeek tokens in brand.css: no raw colors,
   no off-scale spacing, no shadows on in-flow surfaces. */

/* Theme choice --------------------------------------------------------- */
/* `:root { color-scheme: light dark }` leaves native chrome (date picker,
   scrollbars, form controls) to the OS; an explicit choice must move it too. */
[data-theme="dark"] {
  color-scheme: dark;
}
[data-theme="light"] {
  color-scheme: light;
}

/* Map ------------------------------------------------------------------ */
#map {
  height: 280px; /* fixed viewport for the picker; the one dimension no token covers */
  /* Leaflet's panes and controls use z-index up to 1000; without a stacking
     context here they paint over the sticky header (z-100) when the page
     scrolls. `isolation` contains them inside the map. */
  isolation: isolate;
}
.leaflet-container {
  background: var(--color-surface);
  font-family: var(--font-body-sm), system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile {
    filter: invert(1) hue-rotate(180deg) saturate(0.5) brightness(0.88) contrast(0.9);
  }
}
[data-theme="dark"] .leaflet-tile {
  filter: invert(1) hue-rotate(180deg) saturate(0.5) brightness(0.88) contrast(0.9);
}
.leaflet-bar a {
  background: var(--color-surface);
  color: var(--color-ink);
  border-color: var(--color-hairline);
}
.leaflet-bar a:hover {
  background: var(--color-surface-raised);
}
/* Leaflet's own selector is `.leaflet-container .leaflet-control-attribution`,
   so the container prefix is required to win. */
.leaflet-container .leaflet-control-attribution {
  background: var(--color-surface);
  color: var(--color-body);
}
.leaflet-container .leaflet-control-attribution a {
  color: var(--color-accent-2);
}

/* Wordmark ------------------------------------------------------------- */
/* The masthead belongs to the parent brand, so it is set in that subset face
   rather than the page's display serif; roman with an italic second word, the
   same construction lexbrief.news uses at the top of its own pages. */
.brand-mark {
  font-family: var(--font-mark);
  font-weight: 500;
  font-size: var(--text-heading-sm);
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--color-ink);
}

.brand-mark em {
  font-style: italic;
  font-weight: 400;
  color: var(--color-primary);
}

/* Results -------------------------------------------------------------- */
/* The header is 65px and, in the answer state, the folded form sticks under
   it; without the scroll margin a submit would hide the card heading behind
   both. */
#results {
  /* header + the folded form: 48px row + two 12px pads + its two 1px borders.
     Written as the tokens that build the bar so the margin follows a change
     to the row instead of drifting from a magic number. */
  scroll-margin-top: calc(65px + var(--spacing-xl) + var(--spacing-xxs) * 2 + 2px);
}
/* Answer state: the one-line form stays under the header while the result
   scrolls, so location/date/hours are never off screen. The bar swaps its
   text rather than growing, hence the fixed row height and two-line clamp. */
/* A pinned bar is a detached layer, so it leaves the flat in-flow surface
   only once it is actually stuck; at scroll 0 it still reads as the card. */
.picker[data-state="answer"][data-stuck="true"] {
  background-color: var(--color-surface-raised);
  box-shadow: var(--shadow-overlay);
}
/* zero-height marker: the observer flips data-stuck at the exact pixel the
   form detaches, without measuring layout on scroll */
#picker-sentinel {
  height: 0;
}
.picker[data-state="answer"] {
  position: sticky;
  top: 65px;
  z-index: 90;
  /* the folded bar is chrome, not a form: 12px of padding instead of the
     card's 24 keeps it to 72px while the row itself stays 48px in both
     text states */
  padding-block: var(--spacing-xxs);
}
#form-summary {
  min-height: var(--spacing-xl);
}
/* the body's space-y would add 20px below the row for the hidden fields */
.picker[data-state="answer"] #form-summary {
  margin-block-end: 0;
}
#summary-line {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.45;
}
/* htmx marks the submitting form; dim its primary button so a slow request
   looks like work in progress rather than a dead click. */
.htmx-request .kg-btn-primary {
  opacity: 0.6;
  cursor: progress;
}
.tile-grid {
  display: grid;
  gap: var(--spacing-xs);
  /* 280px tiles per the design rules, but never wider than the card on a
     narrow phone (320px viewport leaves 240px inside the result card). */
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
}
.tile-value {
  font-family: var(--font-display), system-ui, sans-serif;
  font-weight: var(--font-weight-display);
  font-size: var(--text-heading-sm);
  line-height: var(--text-heading-sm--line-height);
}
/* Temperature curves: both ends of the day on one shared axis. The SVG
   stretches to the card (preserveAspectRatio=none) and carries no text, so
   labels stay HTML at a fixed size; vector-effect keeps strokes crisp. */
.curve {
  margin: 0;
  /* 176px: three --spacing-xl plus --spacing-lg, since --spacing-xxl is not
     emitted by Tailwind (no utility references it). The taller plot is what
     lets the crossings read against the 0/50/100 gridlines instead of
     crowding them. */
  --curve-height: calc(var(--spacing-xl) * 3 + var(--spacing-lg));
}
.curve-legend {
  display: grid;
  gap: 2px;
  margin-bottom: var(--spacing-xxs);
  font-family: var(--font-caption), monospace;
  font-size: var(--text-caption);
  color: var(--color-body);
}
/* name and likely read as one phrase; the tails sit beside them on a wide
   screen and wrap beneath on a phone */
.curve-key {
  display: grid;
  grid-template-columns: 12px max-content minmax(0, 1fr);
  gap: 6px 12px;
  align-items: baseline;
}
.curve-key-name {
  color: var(--color-ink);
}
.curve-key-tails {
  color: var(--color-body);
}
.curve-swatch {
  width: 12px;
  height: 2px;
}
.curve-swatch-low {
  background: var(--color-data-cool);
}
.curve-swatch-high {
  background: var(--color-data-warm);
}
.curve-plot {
  display: grid;
  /* --spacing-xxl is not emitted (no utility uses it), so compose it */
  grid-template-columns: var(--spacing-xl) 1fr;
  gap: var(--spacing-xxs);
}
.curve-y {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-between;
  height: var(--curve-height);
  font-family: var(--font-caption), monospace;
  font-size: var(--text-caption);
  color: var(--color-body);
}
.curve-svg {
  display: block;
  width: 100%;
  height: var(--curve-height);
  overflow: visible;
}
.curve-gridline,
.curve-median,
.curve-line {
  vector-effect: non-scaling-stroke;
}
.curve-gridline {
  stroke: var(--color-hairline);
  stroke-width: 1;
}
.curve-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.curve-line-low {
  stroke: var(--color-data-cool);
}
.curve-line-high {
  stroke: var(--color-data-warm);
}
.curve-median {
  stroke-width: 1;
  stroke-dasharray: 3 3;
}
.curve-median-low {
  stroke: var(--color-data-cool);
}
.curve-median-high {
  stroke: var(--color-data-warm);
}
.curve-gridline-v {
  opacity: 0.5;
}
/* Tick labels are positioned from the data (left: N%), so they cannot live in
   the stretched SVG; each carries its own anchor to stay inside the plot. */
.curve-x {
  position: relative;
  height: var(--spacing-md);
  margin-top: var(--spacing-xxs);
  margin-left: calc(var(--spacing-xl) + var(--spacing-xxs));
  font-family: var(--font-caption), monospace;
  font-size: var(--text-caption);
  color: var(--color-body);
}
.curve-tick {
  position: absolute;
  top: 0;
  white-space: nowrap;
}
.curve-tick-center {
  transform: translateX(-50%);
}
.curve-tick-end {
  transform: translateX(-100%);
}
/* Temperature rows: labelled p10-p90 bands for the low and the high on one
   shared axis, so the uncertainty of each is visible at a glance. */
.temp-table {
  container-type: inline-size;
}
.temp-row,
.temp-axis {
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  gap: var(--spacing-xxs);
  align-items: center;
}
.wind-row {
  grid-template-columns: 68px 1fr 40px;
}
.temp-label,
.temp-range,
.temp-ticks {
  font-family: var(--font-caption), monospace;
  font-size: var(--text-caption);
}
.temp-label {
  color: var(--color-body);
}
.temp-track {
  position: relative;
  height: 14px;
  border-radius: var(--radius-xs);
  background: var(--color-surface-raised);
}
.temp-band {
  position: absolute;
  top: 3px;
  bottom: 3px;
  border-radius: var(--radius-xs);
  background: var(--color-primary);
  opacity: 0.55;
}
.temp-median {
  position: absolute;
  top: 1px;
  bottom: 1px;
  width: 2px;
  background: var(--color-ink);
}
.temp-range {
  color: var(--color-body);
  text-align: right;
}
.temp-ticks {
  display: flex;
  justify-content: space-between;
  color: var(--color-body);
  font-size: var(--text-body-sm);
}
/* Below ~200px of tile width the tick labels collide; the bands and the
   printed ranges still carry the values, so drop the scale instead. */
@container (max-width: 200px) {
  .temp-axis {
    display: none;
  }
}
.bin {
  display: grid;
  grid-template-columns: 68px 1fr 40px;
  gap: var(--spacing-xxs);
  align-items: center;
}
.bar {
  display: block;
  height: 10px;
  border-radius: var(--radius-xs);
  /* outline-only: a filled gray track read as 100% when the value was 0 */
  background: transparent;
  border: 1px solid var(--color-hairline);
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  background: var(--color-primary);
}

/* Search results ------------------------------------------------------- */
.search-hit {
  display: block;
  width: 100%;
  text-align: left;
  cursor: pointer;
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-xs);
  background: var(--color-surface);
  padding: var(--spacing-xxs) var(--spacing-xs);
  font-size: var(--text-body-sm);
  line-height: var(--text-body-sm--line-height);
}
.search-hit:hover {
  border-color: var(--color-primary);
}
.search-hit-note {
  cursor: default;
}
.search-hit-detail {
  display: block;
  font-family: var(--font-caption), monospace;
  font-size: var(--text-caption);
  color: var(--color-body);
}

/* The synced controls use accent-1 borders, which clear 3:1 on the canvas but
   only reach 2.8:1 on a card surface; keep required controls above the floor. */
.kg-input,
.kg-select,
.kg-textarea {
  border-color: var(--color-body);
}

/* Synced badge borders hardcode the previous palette's RGBAs; derive them from
   the semantic ramps so a token change cannot leave off-palette borders. */
.kg-badge-error {
  border-color: color-mix(in srgb, var(--color-error) 30%, transparent);
}
.kg-badge-success {
  border-color: color-mix(in srgb, var(--color-success) 30%, transparent);
}
.kg-badge-warning {
  border-color: color-mix(in srgb, var(--color-warning) 30%, transparent);
}
.kg-badge-info {
  border-color: color-mix(in srgb, var(--color-info) 30%, transparent);
}
.kg-badge-notice {
  border-color: color-mix(in srgb, var(--color-notice) 30%, transparent);
}
.kg-alert-error {
  border-color: color-mix(in srgb, var(--color-error) 40%, transparent);
}
.kg-alert-success {
  border-color: color-mix(in srgb, var(--color-success) 40%, transparent);
}
.kg-alert-warning {
  border-color: color-mix(in srgb, var(--color-warning) 40%, transparent);
}
.kg-alert-info {
  border-color: color-mix(in srgb, var(--color-info) 40%, transparent);
}
.kg-alert-notice {
  border-color: color-mix(in srgb, var(--color-notice) 40%, transparent);
}

/* One control height per row: a date input and a search input are taller by
   nature, otherwise they sit proud of the button beside them. 48px is on the
   spacing scale and keeps the 44px touch minimum. */
.picker .kg-input,
.picker .kg-select,
.picker .kg-btn {
  height: var(--spacing-xl);
}

/* iOS Safari zooms the viewport whenever a focused control is under 16px, which
   makes the card look like it spills past the screen margins after tapping a
   field. Keep controls at 16px on small screens. */
@media (max-width: 640px) {
  .kg-input,
  .kg-select,
  .kg-textarea {
    font-size: var(--text-body-lg);
  }
}

/* A date input carries a wide intrinsic width; without this the grid track can
   be forced wider than the card's content box on some engines. Scoped to the
   controls: a bare `.kg-field` rule would also beat a field's own min-width
   utility (the search box) because this sheet loads after the theme. */
.kg-field > .kg-input,
.kg-field > .kg-select {
  min-width: 0;
}
