/* WSPR beacon statistics modal (header button) and the Band Summary WSPR tab.
   Modelled on the DX Cluster modal (see sdrconnect.css) but deliberately wide,
   since the operator asked for a large view. Loaded last in index.html, so its
   rules sit at the end of the cascade. */

.wspr-modal {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: grid;
  place-items: center;
}

.wspr-modal.hidden {
  display: none;
}

.wspr-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, .72);
  backdrop-filter: blur(6px);
}

.wspr-modal-dialog {
  position: relative;
  width: min(120rem, calc(100vw - 1.5rem));
  height: calc(100vh - 1.5rem);
  max-height: calc(100vh - 1.5rem);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  border: 1px solid rgba(148, 163, 184, .22);
  border-radius: 1rem;
  background: rgba(2, 6, 23, .96);
  box-shadow: 0 24px 60px rgba(15, 23, 42, .55);
}

.wspr-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .9rem 1.1rem .7rem;
  border-bottom: 1px solid rgba(148, 163, 184, .14);
}

.wspr-modal-eyebrow {
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: .15rem;
}

.wspr-modal-head h3 {
  margin: 0;
  font-size: 1.15rem;
}

.wspr-modal-sub {
  color: var(--muted);
  font-size: .82rem;
  margin-top: .1rem;
}

.wspr-modal-close {
  padding: .35rem .7rem;
  border-radius: .5rem;
  border: 1px solid rgba(148, 163, 184, .28);
  background: rgba(15, 23, 42, .72);
  color: #cbd5e1;
  font-weight: 700;
  cursor: pointer;
}

.wspr-modal-close:hover {
  border-color: rgba(148, 163, 184, .5);
  color: #f1f5f9;
}

/* Controls row: time-window buttons + per-band chips. */
.wspr-modal-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .7rem 1.1rem;
  border-bottom: 1px solid rgba(148, 163, 184, .1);
}

.wspr-windows,
.wspr-metrics,
.wspr-stats,
.wspr-band-chips {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
}

/* Metric toggle and the SNR-stat sub-selector, each set off with a divider. */
.wspr-metrics,
.wspr-stats {
  padding-left: .8rem;
  margin-left: .2rem;
  border-left: 1px solid rgba(148, 163, 184, .22);
}

.wspr-win,
.wspr-metric,
.wspr-stat,
.wspr-band-chip {
  padding: .3rem .65rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, .24);
  background: rgba(15, 23, 42, .72);
  color: #cbd5e1;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
}

.wspr-win.active,
.wspr-metric.active,
.wspr-stat.active {
  border-color: rgba(45, 212, 191, .75);
  background: rgba(13, 148, 136, .4);
  color: #f1f5f9;
}

.wspr-band-chip {
  opacity: .45;               /* hidden-in-chart state */
}

.wspr-band-chip.active {
  opacity: 1;
  border-color: rgba(148, 163, 184, .5);
}

.wspr-dot {
  display: inline-block;
  width: .7rem;
  height: .7rem;
  border-radius: 999px;
  flex: none;
}

/* Scrollable body: chart on top, summary tiles below. */
.wspr-modal-body {
  overflow: auto;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

/* Chart fills the remaining body height above the summary tiles; uPlot reads
   this element's clientWidth/Height to size its canvas. */
.wspr-chart {
  position: relative;
  flex: 1 1 auto;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  overflow: auto;   /* the Distance view can be taller than the flex height */
}

.wspr-chart.is-loading {
  opacity: .5;
}

.wspr-chart-empty,
.wspr-pane-empty {
  padding: 1.4rem;
  text-align: center;
  color: var(--muted);
  font-size: .85rem;
}

/* uPlot dark-theme overrides (its stylesheet defaults to light). */
.wspr-chart .uplot,
.wspr-chart .u-wrap {
  width: 100%;
}

.wspr-chart .u-legend {
  color: #cbd5e1;
  font-size: .78rem;
  margin-top: .4rem;
}

.wspr-chart .u-legend .u-value {
  color: #f1f5f9;
  font-variant-numeric: tabular-nums;
}

.wspr-chart .u-legend .u-marker {
  border-radius: 2px;
}

/* Trend badge (improving / steady / declining), shown on tiles + pane table. */
.wspr-trend {
  display: inline-flex;
  align-items: center;
  gap: .15rem;
  font-size: .72rem;
  font-weight: 800;
  padding: .05rem .35rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-variant-numeric: tabular-nums;
}

.wspr-trend-improving { color: #4ade80; background: rgba(34, 197, 94, .14); border-color: rgba(34, 197, 94, .4); }
.wspr-trend-declining { color: #fb923c; background: rgba(249, 115, 22, .14); border-color: rgba(249, 115, 22, .4); }
.wspr-trend-steady    { color: #94a3b8; background: rgba(148, 163, 184, .12); border-color: rgba(148, 163, 184, .3); }

/* Per-band summary tiles (modal). At most six bands, so auto-fit stretches the
   tiles to share the full width evenly rather than leaving empty tracks on the
   right the way auto-fill did. */
.wspr-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: .9rem;
}

.wspr-tile {
  border: 1px solid rgba(148, 163, 184, .18);
  border-radius: .7rem;
  background: rgba(15, 23, 42, .55);
  padding: .7rem .8rem;
}

.wspr-tile-head {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-weight: 800;
  font-size: 1rem;
  margin-bottom: .5rem;
}

.wspr-tile-grid {
  display: grid;
  grid-template-columns: 1fr;   /* one stat per row -- easier to scan than two columns */
  gap: .3rem;
}

.wspr-tile-grid > div {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  font-size: .8rem;
}

.wspr-tile-k { color: var(--muted); }
.wspr-tile-v { font-weight: 700; text-align: right; }

/* Footnote (the TX-ambiguity caveat). */
.wspr-modal-note {
  padding: .6rem 1.1rem .8rem;
  border-top: 1px solid rgba(148, 163, 184, .12);
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.35;
}

/* Compact table in the Band Summary WSPR tab. */
.wspr-pane-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8rem;
}

.wspr-pane-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 700;
  padding: .3rem .5rem;
  border-bottom: 1px solid rgba(148, 163, 184, .18);
  white-space: nowrap;
}

.wspr-pane-table td {
  padding: .3rem .5rem;
  border-bottom: 1px solid rgba(148, 163, 184, .08);
  white-space: nowrap;
}

.wspr-pane-table td:first-child {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-weight: 700;
}

/* ── Chart view tabs (Timeline / Wind rose / Distance) ──────────────────────*/
.wspr-views {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
  flex-basis: 100%;       /* own row above the window buttons */
  margin-bottom: .3rem;
}

.wspr-viewtab {
  padding: .35rem .85rem;
  border-radius: .5rem;
  border: 1px solid rgba(148, 163, 184, .24);
  background: rgba(15, 23, 42, .72);
  color: #cbd5e1;
  font-weight: 700;
  font-size: .82rem;
  cursor: pointer;
}

.wspr-viewtab.active {
  border-color: rgba(45, 212, 191, .75);
  background: rgba(13, 148, 136, .4);
  color: #f1f5f9;
}

/* ── Wind rose ──────────────────────────────────────────────────────────────*/
/* Fills the chart area and lets the square/quarter SVGs scale to the available
   height (bigger, and no vertical scrolling) via flex + preserveAspectRatio. */
.wspr-rose-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
}

.wspr-rose-svg { flex: 1 1 auto; min-height: 0; width: 100%; height: auto; }
.wspr-rose-ring { fill: none; stroke: rgba(148, 163, 184, .16); }
.wspr-rose-spoke { stroke: rgba(148, 163, 184, .16); }
.wspr-rose-dir { fill: var(--muted); font-size: 14px; text-anchor: middle; font-weight: 700; }
.wspr-rose-rlabel { fill: var(--muted); font-size: 11px; }
.wspr-rose-wedge { stroke: rgba(2, 6, 23, .55); stroke-width: .5; }
.wspr-rose-wedge:hover { stroke: #f1f5f9; stroke-width: 1; }

.wspr-rose-legend,
.wspr-hist-legend {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem 1rem;
  align-items: center;
  font-size: .75rem;
  color: var(--muted);
}

.wspr-hist-key { display: inline-flex; align-items: center; gap: .3rem; }

/* ── Distance distribution ──────────────────────────────────────────────────*/
.wspr-dd-wrap { display: flex; flex-direction: column; gap: 1.1rem; width: 100%; }
.wspr-dd-svg { width: 100%; height: auto; }
.wspr-dd-grid { stroke: rgba(148, 163, 184, .12); }
.wspr-dd-xlabel { fill: var(--muted); font-size: 11px; text-anchor: middle; }
.wspr-dd-band { fill: #e2e8f0; font-size: 12px; font-weight: 700; }
.wspr-dd-whisker { stroke-width: 1.5; }

.wspr-hist { display: flex; flex-direction: column; gap: .4rem; }
.wspr-hist-title { color: var(--muted); font-size: .8rem; font-weight: 700; }
.wspr-hist-row { display: flex; align-items: center; gap: .6rem; }
.wspr-hist-band {
  display: inline-flex; align-items: center; gap: .35rem;
  width: 4rem; font-weight: 700; font-size: .8rem;
}
.wspr-hist-bar {
  flex: 1; display: flex; height: 18px;
  border-radius: 4px; overflow: hidden; background: rgba(15, 23, 42, .6);
}
.wspr-hist-seg { height: 100%; }

/* Azimuth scatter dots / pattern lines + captions (share the rose wrap). */
.wspr-rose-dot { stroke: rgba(2, 6, 23, .5); stroke-width: .5; }
.wspr-rose-dot:hover { stroke: #f1f5f9; stroke-width: 1; }
.wspr-rose-line { fill: none; stroke-linecap: round; opacity: .92; }
.wspr-rose-caption {
  color: var(--muted);
  font-size: .74rem;
  text-align: center;
}

/* Map view (Leaflet in the modal). */
.wspr-map {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  border-radius: .5rem;
  overflow: hidden;
}
