/* "On the map" (#543): the one legend for every layer (map-legend.js), and
   the popup a clicked Floods past cell opens (#547). */

/* Bottom left, above the scale and the attribution; it moves 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; }
body.workbench-mode .map-legends { display: none; }
/* Where the time bar would run into it, it goes to the top, beside the map tools. */
@media (max-width: 1100px) {
  .map-legends { top: 10px; bottom: auto; left: 56px; }
}

.map-legend {
  width: 17rem; max-width: calc(100vw - 24px); max-height: calc(100vh - 220px); overflow-y: auto;
  overscroll-behavior: contain;
  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);
  font-size: .74rem; color: var(--ink); padding: .2rem .3rem .3rem;
}
.map-legend[hidden] { display: none; }
.map-legend.folded { width: auto; padding: 0; border-radius: 999px; }

/* the head: a chip that folds the legend away and brings it back */
.ml-chip {
  font: inherit; display: flex; align-items: center; gap: .35rem; width: 100%;
  padding: .28rem .35rem; border: 0; background: none; color: var(--ink-2); cursor: pointer;
  font-size: .7rem; font-weight: 620; letter-spacing: .02em; text-transform: uppercase; border-radius: var(--radius-xs);
}
.ml-chip:hover { color: var(--ink); }
.ml-chip > svg { width: 13px; height: 13px; flex: none; }
.ml-chip-text { flex: 1 1 auto; text-align: left; white-space: nowrap; }
.ml-chev { display: inline-grid; place-items: center; width: 14px; height: 14px; flex: none; color: var(--muted);
  transition: transform .15s ease; }
.ml-chev svg { width: 12px; height: 12px; }
.ml-chip[aria-expanded="true"] .ml-chev { transform: rotate(90deg); }
.map-legend.folded .ml-chip { padding: .32rem .6rem .32rem .5rem; text-transform: none; letter-spacing: 0; font-size: .74rem; }

/* a row: toggle, mark, name and a few words; open, its key */
.ml-rows { display: flex; flex-direction: column; }
.ml-row { border-top: 1px solid var(--line-soft); }
.ml-line { display: flex; align-items: center; gap: .4rem; min-height: 26px; padding: 0 .2rem 0 .3rem; }
.ml-toggle { margin: 0; width: 13px; height: 13px; flex: none; accent-color: var(--blue); cursor: pointer; }
.ml-clear {
  font: inherit; width: 13px; height: 13px; padding: 0; flex: none; display: grid; place-items: center;
  border: 0; background: none; color: var(--muted); cursor: pointer; font-size: .9rem; line-height: 1;
}
.ml-clear:hover { color: var(--ink); }
.ml-mark { width: 22px; flex: none; display: inline-flex; align-items: center; justify-content: center; }
.ml-name {
  font: inherit; color: inherit; flex: 1 1 auto; min-width: 0; display: flex; align-items: baseline; gap: .4rem;
  padding: .25rem 0; border: 0; background: none; text-align: left; cursor: pointer;
}
.ml-name.static { cursor: default; }
.ml-title { font-weight: 600; white-space: nowrap; }
.ml-sum { color: var(--muted); font-size: .7rem; font-variant-numeric: tabular-nums; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1 1 auto; }
/* the job behind the layer is late (#593): a few words after the summary */
.ml-late { color: var(--warn-ink); font-size: .68rem; white-space: nowrap; flex: none; font-variant-numeric: tabular-nums; }
.ml-name .ml-chev { align-self: center; margin-left: auto; }
.ml-name[aria-expanded="true"] .ml-chev { transform: rotate(90deg); }
.ml-name:hover .ml-title { color: var(--blue); }
.ml-row.off .ml-title, .ml-row.empty .ml-title { font-weight: 500; color: var(--muted); }
.ml-row.off .ml-mark, .ml-row.empty .ml-mark { opacity: .4; filter: grayscale(1); }

.ml-body { padding: .1rem .45rem .5rem calc(13px + 22px + 1.1rem); }
.ml-body p { margin: .3rem 0 0; line-height: 1.38; }
.ml-when { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.ml-src { color: var(--muted); font-size: .66rem; }
.ml-link { font: inherit; padding: 0; border: 0; background: none; color: var(--blue); cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px; }
.ml-actions { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .4rem; }
.ml-btn {
  font: inherit; font-size: .7rem; padding: .16rem .55rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: transparent; color: var(--blue);
}
.ml-btn:hover { background: var(--bg-soft); }
.ml-btn[aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: #fff; }
.ml-btn.quiet { color: var(--ink-2); }
.ml-check { display: flex; align-items: center; gap: .35rem; margin-top: .35rem; color: var(--ink-2); cursor: pointer; }
.ml-check input { margin: 0; accent-color: var(--blue); }

/* the marks */
.sl-bar { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; height: 8px; }
.sl-bar i { background: var(--c); border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(127, 140, 153, .18); }
.sl-bar i:first-child { border-radius: 4px 2px 2px 4px; }
.sl-bar i:last-child { border-radius: 2px 4px 4px 2px; }
.sl-bar.mini { width: 22px; height: 7px; gap: 1px; }
.ml-check + .sl-bar { margin-top: .45rem; }   /* a key under a checkbox (Flow vs normal, #559) */
.sl-bar i.off { opacity: .22; }   /* a class Ask the map left off (#561) */
.sl-focus { color: var(--ink-2); margin: .3rem 0 0; }
.sl-ends { display: flex; justify-content: space-between; color: var(--muted); font-size: .64rem; margin-top: .15rem; }
.ml-dot { width: 8px; height: 8px; border-radius: 50%; background: #2b7fc4; box-shadow: 0 0 0 1.5px #fff, 0 0 0 2.2px rgba(29,58,85,.25); }
.ml-dot.now { background: conic-gradient(#a6611a 0 25%, #dfc27d 0 50%, #80cdc1 0 75%, #018571 0); }
.ml-dots { display: grid; grid-template-columns: repeat(5, 1fr); justify-items: center; }
.ml-dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 1.5px #fff; }
.ml-line-mark { display: block; width: 20px; height: 3px; border-radius: 2px;
  background: repeating-linear-gradient(90deg, var(--c) 0 7px, color-mix(in srgb, var(--c) 35%, #fff) 7px 9px); }
.rk-pair { display: inline-flex; gap: 2px; }
.rk-pair i { width: 9px; height: 3px; border-radius: 2px; }
.rk-row { display: flex; align-items: center; gap: .35rem; }
.rk-row b { font-weight: 600; white-space: nowrap; }
.rk-sw { width: 16px; height: 4px; border-radius: 2px; flex: none; display: inline-block; }
.fp-key { width: 15px; height: 15px; flex: none; }
.ml-mark .fp-key { width: 21px; height: 15px; }
.fp-row { display: flex; align-items: center; gap: .4rem; padding: .1rem 0; margin-top: .25rem; }
.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: .7rem; }
.fp-note { color: var(--warn-ink); }
.ml-body .fa-scale { margin: .3rem 0 .1rem; }
.ml-mark .fa-mini { display: inline-flex; gap: 0; border-radius: 3px; overflow: hidden; }
.ml-mark .fa-mini i { width: 4px; height: 7px; border-radius: 0; }
.ml-body .swatches { margin-top: .2rem; }

@media (prefers-reduced-motion: reduce) {
  .map-legends, .ml-chev { transition: none; }
}

/* 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 map is a strip above the sheet, so the legend starts as one small chip at the top right and,
   opened, stays inside a quarter of the screen. */
@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; }
  .map-legend { width: min(15rem, calc(100vw - 72px)); max-height: 34vh; }
  .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; }
}
