/* Floods past (#547): the legend card on the map and the popup a clicked cell
   opens. Its own file so the layer's look lives next to its module. */

/* Legend cards for map layers stack in the bottom-left corner, above the scale
   and the attribution, and move right with the rail like the map controls. */
.map-legends {
  position: absolute; left: 10px; bottom: 70px; z-index: 5;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
  pointer-events: none; transition: left .16s ease;
}
body.rail-open .map-legends { left: calc(var(--rail-w) + var(--gap) + 10px); }
.map-legends > * { pointer-events: auto; }
/* Where the time bar would run into the stack, it goes to the top, beside the map tools. */
@media (max-width: 1100px) {
  .map-legends { top: 10px; bottom: auto; left: 56px; }
}

.fp-legend {
  width: 16.5rem; max-width: calc(100vw - 24px);
  background: var(--surface); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-1);
  padding: .45rem .55rem .4rem; font-size: .76rem; color: var(--ink);
}
.fp-legend[hidden] { display: none; }
.fp-head { display: flex; align-items: center; gap: .15rem; }
.fp-head h3 { margin: 0 auto 0 0; font-size: .8rem; font-weight: 680; letter-spacing: .01em; }
.fp-sub { margin: .05rem 0 .3rem; font-size: .72rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.fp-legend.busy .fp-sub::after {
  content: ""; display: inline-block; width: .5rem; height: .5rem; margin-left: .35rem; border-radius: 50%;
  border: 1.5px solid var(--muted); border-right-color: transparent; vertical-align: -1px;
  animation: fp-spin .8s linear infinite;
}
@keyframes fp-spin { to { transform: rotate(360deg); } }
.fp-row { display: flex; align-items: center; gap: .4rem; padding: .08rem 0; }
.fp-key { width: 15px; height: 15px; flex: none; }
.fp-what { flex: 1 1 auto; white-space: nowrap; }
.fp-n { color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: .72rem; }
.fp-note { margin: .25rem 0 0; font-size: .7rem; color: var(--warn-ink); }
.fp-foot { margin: .3rem 0 0; font-size: .66rem; }
.fp-btn {
  font: inherit; width: 24px; height: 24px; display: grid; place-items: center; padding: 0;
  border: 1px solid transparent; border-radius: var(--radius-xs); background: transparent; color: var(--ink-2); cursor: pointer;
}
.fp-btn:hover { background: var(--bg-soft); border-color: var(--line); color: var(--ink); }
.fp-btn svg { width: 13px; height: 13px; }
.fp-play { color: var(--blue); }
.fp-play[aria-pressed="true"] { background: var(--blue); color: #fff; border-color: var(--blue); }
.fp-link {
  font: inherit; padding: 0; border: 0; background: none; color: var(--blue); cursor: pointer; text-decoration: underline;
  text-underline-offset: 2px;
}

/* the popup of a clicked cell, above the time bar and the legend */
.fp-popup { z-index: 7; }
.fp-popup .maplibregl-popup-content { padding: .55rem .7rem .5rem; }
.fp-pop { font-size: .76rem; line-height: 1.4; color: var(--ink); min-width: 13rem; }
.fp-pop-head { display: flex; flex-direction: column; gap: .05rem; margin: 0 1rem .3rem 0; }
.fp-pop-head strong { font-size: .82rem; }
.fp-pop-head .muted { font-size: .7rem; font-variant-numeric: tabular-nums; }
.fp-pop-counts { display: flex; flex-direction: column; gap: .1rem; margin-bottom: .3rem; }
.fp-pop-counts span { display: inline-flex; align-items: center; gap: .35rem; }
.fp-events { list-style: none; margin: .2rem 0; padding: 0; max-height: 9.5rem; overflow-y: auto;
  border-top: 1px solid var(--line-soft); }
.fp-events li { display: flex; justify-content: space-between; gap: .6rem; padding: .16rem 0;
  border-bottom: 1px solid var(--line-soft); font-variant-numeric: tabular-nums; }
.fp-pop-note { margin: .25rem 0; font-size: .72rem; }
.fp-pop-src { margin: .3rem 0 .35rem; font-size: .66rem; }

/* A phone: the inspector is a bottom sheet and the time bar sits above it, so
   the legend moves up under the map tools, and says less. */
@media (max-width: 520px) {
  .map-legends { top: 10px; bottom: auto; left: auto; right: 10px; align-items: flex-end; }
  body.rail-open .map-legends { left: auto; }
  .fp-legend { width: 12.6rem; padding: .35rem .45rem .3rem; font-size: .72rem; }
  .fp-foot { font-size: .62rem; }
  .fp-events { max-height: 3.7rem; }
  /* the map is a strip here: while a cell's card is open, the legend steps aside for it */
  body.fp-pop-open .map-legends { visibility: hidden; }
  .fp-pop-src { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .map-legends { transition: none; }
  .fp-legend.busy .fp-sub::after { animation: none; }
}

/* Folded: the two marks and the months on one line. */
.fp-mini { display: none; margin: .1rem 0 0; align-items: center; gap: .3rem; flex-wrap: wrap; font-size: .72rem; color: var(--ink-2); }
.fp-mini .fp-key { width: 12px; height: 12px; }
.fp-mini-when { flex-basis: 100%; font-variant-numeric: tabular-nums; }
.fp-legend.folded { width: max-content; min-width: 11rem; max-width: min(16rem, calc(100vw - 72px)); }
.fp-legend.folded .fp-mini { display: flex; }
.fp-legend.folded .fp-sub, .fp-legend.folded .fp-row, .fp-legend.folded .fp-foot, .fp-legend.folded .fp-note { display: none; }
