/* Street address interpolation sample.
   Full-bleed map with floating Calcite overlays; this file covers the map symbology and the
   bits Calcite does not draw (pins, tooltips, tables). */

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--calcite-sans-family, system-ui, sans-serif);
  color: var(--calcite-color-text-1);
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  background: var(--calcite-color-foreground-2);
}

code {
  font-family: var(--calcite-code-family, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 0.85em;
}

/* --- floating overlays ---------------------------------------------------- */

.overlay {
  position: absolute;
  /* Above Leaflet's own controls (1000), so the details sheet covers the attribution */
  z-index: 1100;
  box-shadow: 0 2px 12px rgb(0 0 0 / 18%);
  border-radius: 4px;
}

/* Left column: address card on top, legend below. On a wide screen they read as two cards at
   opposite ends of the column; in a small viewport they merge into one continuous panel. */

.side {
  position: absolute;
  z-index: 1100;
  inset-block-start: 1rem;
  inset-inline-start: 1rem;
  inline-size: 17rem;
  max-inline-size: calc(100vw - 2rem);
  /* Height follows the content; it only scrolls if it would run past the map. */
  max-block-size: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  pointer-events: none;
}

.side > * {
  pointer-events: auto;
  background: var(--calcite-color-foreground-1);
  border-radius: 4px;
  box-shadow: 0 2px 12px rgb(0 0 0 / 18%);
}

.side-address {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.6rem 0.9rem;
}

/* Only present with ?picker=1 */
.side-picker {
  margin-block-end: 0.35rem;
}

.side-picker[hidden] {
  display: none;
}

.side-eyebrow {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--calcite-color-text-3);
}

.side-address-value {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.25;
}

.side-note {
  font-size: 0.75rem;
  color: var(--calcite-color-text-3);
}

/* Long parameter names must wrap rather than widen the column */
.side code {
  overflow-wrap: anywhere;
}

.overlay--modes {
  inset-block-start: 1rem;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem 0.35rem 0.75rem;
  background: var(--calcite-color-foreground-1);
  white-space: nowrap;
}

.overlay--modes .modes-label {
  font-size: 0.75rem;
  color: var(--calcite-color-text-3);
}

.overlay--links {
  inset-block-start: 1rem;
  inset-inline-end: 1rem;
  display: flex;
  gap: 0.4rem;
  box-shadow: none;
}

.overlay--links calcite-button {
  box-shadow: 0 2px 8px rgb(0 0 0 / 20%);
}

.about p {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  line-height: 1.5;
}

.about-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
  border-block-start: 1px solid var(--calcite-color-border-3);
  padding-block-start: 0.75rem;
}

.about-links span {
  display: block;
  font-size: 0.75rem;
  color: var(--calcite-color-text-3);
}

/* Lives inside the links row in the markup; on a larger screen it sits in the bottom corner. */
.overlay--attribution {
  position: fixed;
  inset-block-start: auto;
  inset-block-end: 0.75rem;
  inset-inline-end: 0.75rem;
  box-shadow: 0 2px 8px rgb(0 0 0 / 20%);
}

/* The modal has to cover the floating overlays, which sit above Leaflet's controls. */
calcite-modal {
  z-index: 2000;
}

/* Leaflet's attribution control, revealed by the icon above (visibility is toggled from JS).
   esri-leaflet adds .esri-truncated-attribution, which clips the text to one line — undo that so
   the credits can be read in full. */
.leaflet-control-attribution,
.leaflet-control-attribution.esri-truncated-attribution,
.leaflet-control-attribution.esri-truncated-attribution:hover {
  font-size: 0.7rem;
  line-height: 1.4;
  max-inline-size: min(32rem, calc(100vw - 5rem));
  max-block-size: none;
  margin: 0 3.25rem 0.9rem 0 !important;
  border-radius: 4px;
  padding: 0.3rem 0.6rem !important;
  box-shadow: 0 2px 8px rgb(0 0 0 / 18%);
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

.overlay--hint {
  inset-block-end: 1.75rem;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  background: var(--calcite-color-foreground-1);
  font-size: 0.8rem;
  color: var(--calcite-color-text-2);
  white-space: nowrap;
  animation: hint-in 0.4s ease-out both 0.6s;
}

@keyframes hint-in {
  from {
    opacity: 0;
    transform: translate(-50%, 0.5rem);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .overlay--hint {
    animation: none;
  }
}

.overlay--details {
  inset-block-end: 1.75rem;
  inset-inline-end: 1rem;
  inline-size: min(54rem, calc(100vw - 21rem));
  max-block-size: min(26rem, calc(100vh - 9rem));
}

.overlay--details[closed] {
  display: none;
}

#map-error {
  position: absolute;
  inset-block-start: 1rem;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  max-inline-size: 28rem;
}

.pad {
  padding: 0.75rem;
}

/* --- legend --------------------------------------------------------------- */

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
  font-size: 0.8rem;
}

.legend li {
  display: grid;
  grid-template-columns: 1.5rem 1fr;
  align-items: start;
}

.legend-sub {
  display: block;
  color: var(--calcite-color-text-3);
  font-size: 0.75rem;
}

.swatch {
  display: inline-block;
  inline-size: 1rem;
  block-size: 1rem;
}

.swatch--false,
.swatch--true {
  inline-size: 0.85rem;
  block-size: 1.15rem;
  clip-path: polygon(50% 100%, 0 42%, 0 0, 100% 0, 100% 42%);
}

.swatch--false {
  background: #c7522a;
}

.swatch--true {
  background: #137a4c;
}

.swatch--rooftop {
  border-radius: 50%;
  background: #fff;
  border: 2px solid #2b2b2b;
}

.swatch--interpolated {
  border-radius: 50%;
  background: #8fd3b2;
  border: 2px solid #137a4c;
  inline-size: 0.8rem;
  block-size: 0.8rem;
  margin-block-start: 0.15rem;
}

.swatch--street {
  block-size: 0;
  margin-block-start: 0.45rem;
  border-block-start: 7px solid rgb(112 72 232 / 45%);
  border-radius: 3px;
}

.swatch--line {
  block-size: 0;
  margin-block-start: 0.5rem;
  border-block-start: 3px dotted #137a4c;
}

/* --- map symbology -------------------------------------------------------- */

.pin {
  display: block;
  inline-size: 22px;
  block-size: 22px;
  border: 3px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  margin: 6px 0 0 2px;
  box-shadow: 0 1px 4px rgb(0 0 0 / 45%);
}

.pin--false {
  background: #c7522a;
}

.pin--true {
  background: #137a4c;
}

.leaflet-tooltip.tip {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 2px 6px;
  border: none;
  border-radius: 3px;
  box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
}

/* Candidate pins: house number + Addr_type on one line, the parameter under it */
.tip-head {
  display: block;
  white-space: nowrap;
}

.tip-num {
  display: inline-block;
  margin-inline-end: 0.35em;
  padding-inline: 0.35em;
  border-radius: 2px;
  background: rgb(255 255 255 / 25%);
  font-variant-numeric: tabular-nums;
}

.tip-param {
  display: block;
  font-size: 0.68rem;
  font-weight: 400;
  opacity: 0.85;
  white-space: nowrap;
}

/* Not enough room for the parameter line — the colour and the legend already say it */
@media (max-width: 640px), (max-height: 520px) {
  .tip-param {
    display: none;
  }
}

.tip--false {
  background: #c7522a;
  color: #fff;
}

.tip--false::before {
  border-right-color: #c7522a;
}

.tip--true {
  background: #137a4c;
  color: #fff;
}

.tip--true::before {
  border-right-color: #137a4c;
}

.tip--range {
  background: rgb(255 255 255 / 90%);
  color: #2b2b2b;
}

.tip--range::before {
  border-left-color: rgb(255 255 255 / 90%);
}

/* Ends of the street segment: same violet as the line they belong to */
.tip--street {
  background: #7048e8;
  color: #fff;
}

.tip--street::before {
  border-right-color: #7048e8;
  border-left-color: #7048e8;
}

.tip--line {
  background: #137a4c;
  color: #fff;
}

/* --- candidate details ---------------------------------------------------- */

.details-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 15rem;
  gap: 1.25rem;
  align-items: start;
}

.details-title {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--calcite-color-text-2);
}

.details-sub {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--calcite-color-text-3);
  margin-inline-start: 0.4rem;
}

.narrative-scroll {
  overflow-x: auto;
}

table.narrative,
table.attributes {
  border-collapse: collapse;
  font-size: 0.78rem;
  inline-size: 100%;
}

table.narrative th,
table.attributes th {
  text-align: start;
  font-weight: 500;
  color: var(--calcite-color-text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.68rem;
  white-space: nowrap;
  padding: 0.4rem 0.6rem 0.4rem 0;
  vertical-align: middle;
}

table.narrative td,
table.attributes td {
  padding: 0.4rem 0.6rem;
  border-block-end: 1px solid var(--calcite-color-border-3);
  vertical-align: middle;
}

table.narrative tr:nth-child(odd) td,
table.narrative tr:nth-child(odd) th {
  background: var(--calcite-color-foreground-2);
}

.narrative-token {
  font-family: var(--calcite-code-family, ui-monospace, monospace);
  white-space: pre;
}

/* Character-level diff between input and matched value */

.diff-case,
.diff-add,
.diff-del {
  border-radius: 2px;
}

.diff-case {
  background: #f2e0c2;
  color: #7a4b0c;
}

.diff-add {
  background: #c9e9cd;
  color: #10662c;
}

.diff-del {
  background: #f6d2d2;
  color: #9c1f1f;
}

.diff-key {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin: 0.5rem 0 0;
  font-size: 0.7rem;
  color: var(--calcite-color-text-3);
}

.diff-key span {
  font-family: var(--calcite-code-family, ui-monospace, monospace);
  padding: 0 0.25rem;
  margin-inline-start: 0.5rem;
}

.diff-key span:first-child {
  margin-inline-start: 0;
}

.code-raw {
  font-family: var(--calcite-code-family, ui-monospace, monospace);
  color: var(--calcite-color-text-3);
  margin-inline-end: 0.35rem;
}

.code-cell {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.2rem;
}

.plus {
  color: var(--calcite-color-text-3);
}

.code-tooltip {
  max-inline-size: 22rem;
}

.code-tooltip-letter {
  display: block;
  margin-block-end: 0.2rem;
  opacity: 0.75;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.muted {
  color: var(--calcite-color-text-3);
}

/* --- responsive ----------------------------------------------------------- */

@media (max-width: 1100px) {
  .details-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Address card and legend merge into a single full-height panel, so the vertical space is
     used instead of scrolling two separate boxes. */
  .side {
    inset-block-start: 0.75rem;
    inset-inline-start: 0.75rem;
    inline-size: 14.5rem;
    max-block-size: calc(100vh - 1.5rem);
    gap: 0;
    overflow-y: auto;
    background: var(--calcite-color-foreground-1);
    border-radius: 4px;
    box-shadow: 0 2px 12px rgb(0 0 0 / 18%);
  }

  .side > * {
    box-shadow: none;
    border-radius: 0;
  }

  .side-legend {
    border-block-start: 1px solid var(--calcite-color-border-3);
  }

  /* No room to centre the control between the column and the buttons: park it beside them. */
  .overlay--modes {
    inset-inline-start: auto;
    inset-inline-end: 5.75rem;
    transform: none;
    padding: 0.3rem;
  }

  .overlay--modes .modes-label {
    display: none;
  }

  /* Keep the details panel clear of the column. */
  .overlay--details {
    inline-size: auto;
    inset-inline: 16rem 0.75rem;
  }
}

/* Short viewport (a small embed): trim the secondary lines so the column needs no scrollbar. */
@media (max-height: 520px) {
  .side-note,
  .side .legend-sub {
    display: none;
  }

  .side .legend {
    gap: 0.45rem;
  }
}

/* --- phones ---------------------------------------------------------------- *
 * Everything spans the width of the screen: the address and legend as a bar at the top, the
 * mode switch pinned to the bottom where a thumb reaches it, and the details as a sheet above it.
 * -------------------------------------------------------------------------- */

@media (max-width: 640px) {
  /* The bar spans the whole width; every control moves to the bottom row, within thumb reach. */
  .side {
    inset-block-start: 0.5rem;
    inset-inline: 0.5rem;
    inline-size: auto;
    max-inline-size: none;
    max-block-size: calc(100vh - 9rem);
  }

  .overlay--links {
    inset-block-start: auto;
    inset-block-end: 0.5rem;
    inset-inline-start: 0.5rem;
    inset-inline-end: auto;
  }

  .overlay--attribution {
    position: static;
  }

  .overlay--modes {
    inset-block-start: auto;
    inset-block-end: 0.5rem;
    inset-inline-start: auto;
    inset-inline-end: 0.5rem;
    transform: none;
    padding: 0.3rem;
  }

  .overlay--modes .modes-label {
    display: none;
  }

  .overlay--hint {
    inset-block-end: 3.75rem;
    max-inline-size: calc(100vw - 1rem);
    white-space: normal;
    text-align: center;
  }

  .overlay--details {
    inset-block-end: 3.75rem;
    inset-inline: 0.5rem;
    inline-size: auto;
    max-block-size: 55vh;
  }

  /* Full width above the bottom row, wrapping instead of running off the screen */
  .leaflet-control-attribution,
  .leaflet-control-attribution.esri-truncated-attribution {
    position: fixed;
    inset-inline: 0.5rem;
    inset-block-end: 3.75rem;
    max-inline-size: none;
    margin: 0 !important;
  }
}
