/* css/analytics-panel.css
 *
 * Styles for the Analytics panel (js/features/analytics-panel.js).
 * The drawer shell and its pull tab (.analytics-dashboard, .dashboard-toggle)
 * still live in styles.css; everything inside the drawer is namespaced .apx-*
 * so it cannot collide with the map chrome.
 *
 * Chart colours are NOT set here — they come from the validated palette in the
 * JS so there is one source of truth for hue assignment.
 */

/* ── layout ──────────────────────────────────────────────────────────────── */

/* The UA sheet's [hidden] { display: none } is a bare attribute selector, so any
 * class rule here that sets `display` outranks it and the element stays visible.
 * That is exactly what happened to .apx-lock (display:flex, flex:1 1 auto): with
 * the panel unlocked it rendered as an empty stretched box below the last card.
 * .apx-filters had the same latent bug in the locked state. Restore the intent
 * once, for everything in the panel, rather than per selector.
 */
.analytics-dashboard [hidden],
.apx-tip[hidden] { display: none !important; }

.analytics-dashboard {
  display: flex;
  flex-direction: column;
  font-family: var(--nm-font);
}

.apx-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--nm-border);
  flex: 0 0 auto;
}

.apx-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: var(--nm-weight-med);
  color: var(--nm-text);
  letter-spacing: 0.2px;
}

.apx-head-actions { display: flex; gap: 4px; }

.apx-icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--nm-text-muted);
  border-radius: var(--nm-radius-sm);
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.apx-icon-btn:hover {
  background: rgba(var(--nm-blue-rgb), 0.14);
  border-color: var(--nm-border);
  color: var(--nm-text);
}
.apx-icon-btn.is-spinning i { animation: apx-spin 0.9s linear infinite; }
@keyframes apx-spin { to { transform: rotate(360deg); } }

/* ── the one filter row (never per-chart filters) ────────────────────────── */

.apx-filters {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-bottom: 1px solid var(--nm-border);
  background: rgba(var(--nm-bg-deep-rgb), 0.5);
  flex: 0 0 auto;
}

.apx-seg {
  display: inline-flex;
  background: rgba(var(--nm-bg-deep-rgb), 0.75);
  border: 1px solid var(--nm-border);
  border-radius: var(--nm-radius-md);
  padding: 2px;
  gap: 2px;
}

.apx-seg-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: 0;
  color: var(--nm-text-dim);
  font-family: inherit;
  font-size: 11px;
  font-weight: var(--nm-weight-med);
  padding: 4px 9px;
  border-radius: var(--nm-radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.apx-seg-btn:hover { color: var(--nm-text); }
.apx-seg-btn.is-on {
  background: var(--nm-accent-bright);
  color: #fff;
}

/* ── body ────────────────────────────────────────────────────────────────── */

.apx-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 14px 20px;
  transition: opacity 0.2s ease;
}
/* Hold the previous render at reduced opacity on refetch — never a skeleton
   flash, never a layout jump. */
.apx-body.is-loading { opacity: 0.45; pointer-events: none; }

.apx-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.apx-stat {
  background: var(--nm-surface-2);
  border: 1px solid var(--nm-border);
  border-radius: var(--nm-radius);
  padding: 10px 12px;
}
.apx-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--nm-text-dim);
}
.apx-stat-value {
  /* Proportional figures on standalone values — tabular-nums only in tables. */
  font-size: 22px;
  font-weight: var(--nm-weight-med);
  color: var(--nm-text);
  line-height: 1.15;
  margin-top: 2px;
}
.apx-stat-sub { font-size: 11px; color: var(--nm-text-muted); margin-top: 1px; }

.apx-card {
  background: var(--nm-surface-2);
  border: 1px solid var(--nm-border);
  border-radius: var(--nm-radius);
  padding: 12px;
  margin-bottom: 12px;
}

.apx-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.apx-card-head h3 {
  margin: 0;
  font-size: 13px;
  font-weight: var(--nm-weight-med);
  color: var(--nm-text);
}

/* Reveals the card's table-view twin. It was dim borderless text and read as a
   caption rather than a control, so the full list behind it went unnoticed. */
.apx-tabletoggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(var(--nm-blue-rgb), 0.12);
  border: 1px solid var(--nm-border);
  color: var(--nm-text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: var(--nm-weight-med);
  cursor: pointer;
  padding: 3px 9px;
  border-radius: var(--nm-radius-pill);
  white-space: nowrap;
  flex: 0 0 auto;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.apx-tabletoggle:hover {
  background: rgba(var(--nm-blue-rgb), 0.22);
  border-color: var(--nm-border-strong);
  color: var(--nm-text);
}
.apx-tabletoggle.is-on {
  background: var(--nm-accent-bright);
  border-color: var(--nm-accent-bright);
  color: #fff;
}
.apx-tabletoggle:focus-visible { outline: 1px solid var(--nm-accent); outline-offset: 2px; }

.apx-sub {
  margin: 3px 0 8px;
  font-size: 11px;
  color: var(--nm-text-muted);
  line-height: 1.4;
}

.apx-h4 {
  margin: 14px 0 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--nm-text-dim);
  font-weight: var(--nm-weight-med);
}

/* ── legend & chart chrome ───────────────────────────────────────────────── */

.apx-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 6px;
}
.apx-key {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  /* Text wears text tokens; the swatch beside it carries identity. */
  font-size: 11px;
  color: var(--nm-text-muted);
}
.apx-key i {
  width: 10px; height: 3px;
  border-radius: 2px;
  display: inline-block;
}

.apx-chart { min-height: 40px; }
.apx-chart svg { display: block; width: 100%; height: auto; }
.apx-chart text.apx-ax {
  fill: var(--nm-text-dim);
  font-size: 9px;
  font-family: var(--nm-font);
  font-variant-numeric: tabular-nums;
}
.apx-hit { cursor: crosshair; }

.apx-empty {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 18px 10px;
  font-size: 11px;
  color: var(--nm-text-dim);
  line-height: 1.4;
}

.apx-note {
  font-size: 10px;
  color: var(--nm-text-dim);
  margin-top: 4px;
  line-height: 1.4;
}

/* ── chips & deltas ──────────────────────────────────────────────────────── */

.apx-deltas { margin-top: 8px; }

.apx-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.apx-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(var(--nm-bg-deep-rgb), 0.6);
  border: 1px solid var(--nm-border);
  border-radius: var(--nm-radius-pill);
  padding: 3px 9px;
  font-size: 11px;
  color: var(--nm-text-muted);
}
.apx-chip b { color: var(--nm-text); font-weight: var(--nm-weight-med); }
.apx-chip em {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  font-style: normal;
  font-size: 10px;
  color: var(--nm-text-dim);
}
.apx-chip em.is-good { color: #1F9D55; }
.apx-chip em.is-bad  { color: #E0662A; }

/* ── movers ──────────────────────────────────────────────────────────────── */

.apx-movers { display: flex; flex-direction: column; gap: 10px; }

.apx-mover {
  cursor: pointer;
  padding: 4px 5px;
  margin: -4px -5px;
  border-radius: var(--nm-radius-sm);
  transition: background 0.15s;
}
.apx-mover:hover, .apx-mover:focus-visible {
  background: rgba(var(--nm-blue-rgb), 0.1);
  outline: none;
}

.apx-mover-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
}
.apx-mover-name {
  font-size: 11px;
  color: var(--nm-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.apx-mover-val {
  font-size: 11px;
  font-weight: var(--nm-weight-med);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

.apx-mover-track { position: relative; height: 8px; }
/* The zero reference sits ABOVE the bars: both sides butt against it, so drawn
   underneath it would be hidden by every row that has any value at all. */
.apx-mover-axis {
  position: absolute;
  left: calc(50% - 1px); top: -2px; bottom: -2px;
  width: 2px;
  background: rgba(var(--nm-bg-rgb), 0.95);
  box-shadow: 0 0 0 1px rgba(169, 192, 222, 0.35);
  z-index: 2;
}
.apx-mover-bar { position: absolute; top: 0; height: 8px; z-index: 1; }

.apx-mover-meta { font-size: 10px; color: var(--nm-text-dim); margin-top: 3px; }

/* ── transfers (deals) ───────────────────────────────────────────────────── */

.apx-deal {
  padding: 8px 0;
  border-top: 1px solid rgba(169, 192, 222, 0.12);
}
.apx-deal:first-of-type { border-top: 0; padding-top: 0; }

.apx-deal-flow {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.apx-deal-party {
  font-size: 11px;
  color: var(--nm-text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 0;
  min-width: 0;
}
.apx-deal-party.is-buyer { color: var(--nm-text); text-align: right; }
.apx-deal-flow i { flex: 0 0 auto; font-size: 14px; }

.apx-deal-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
}
.apx-deal-size {
  font-size: 11px;
  color: var(--nm-text-muted);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
  min-width: 58px;
  text-align: right;
}

.apx-deal-meta {
  font-size: 10px;
  color: var(--nm-text-faint);
  margin-top: 4px;
  line-height: 1.45;
}
.apx-deal-meta .apx-tenlink { color: var(--nm-text-dim); }
.apx-deal-meta .apx-tenlink:hover { color: var(--nm-accent); }

/* ── ground hand-offs ────────────────────────────────────────────────────── */

.apx-handoff {
  padding: 8px 0;
  border-top: 1px solid rgba(169, 192, 222, 0.12);
}
.apx-handoff:first-of-type { border-top: 0; padding-top: 0; }

.apx-handoff-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.apx-handoff-id {
  font-size: 12px;
  font-weight: var(--nm-weight-med);
  color: var(--nm-text);
  font-variant-numeric: tabular-nums;
}

/* Tenement ids are actionable: they send the tenement to the results panel and
   zoom to it. Underline on hover only, so eight stacked rows do not read as a
   wall of links. */
.apx-tenlink {
  cursor: pointer;
  border-radius: var(--nm-radius-sm);
  text-underline-offset: 2px;
}
.apx-tenlink:hover { color: var(--nm-accent); text-decoration: underline; }
.apx-tenlink:focus-visible {
  outline: 1px solid var(--nm-accent);
  outline-offset: 2px;
}
.apx-handoff-meta .apx-tenlink { color: var(--nm-text-dim); }
.apx-handoff-meta .apx-tenlink:hover { color: var(--nm-accent); }
.apx-handoff-area {
  font-size: 11px;
  color: var(--nm-text-muted);
  font-variant-numeric: tabular-nums;
}

.apx-handoff-flow {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  min-width: 0;
}
.apx-handoff-party {
  font-size: 11px;
  color: var(--nm-text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 0;
  min-width: 0;
  cursor: pointer;
  border-radius: var(--nm-radius-sm);
}
.apx-handoff-party:hover { color: var(--nm-accent); text-decoration: underline; }
.apx-handoff-party.is-new { color: var(--nm-text-muted); text-align: right; }
.apx-handoff-flow i { flex: 0 0 auto; font-size: 14px; }

.apx-handoff-meta {
  font-size: 10px;
  color: var(--nm-text-faint);
  margin-top: 3px;
  line-height: 1.45;
}

/* ── composition rows, meters ────────────────────────────────────────────── */

.apx-inline-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 10px;
  margin: 8px 0 12px;
}
.apx-inline-stats > div { display: flex; flex-direction: column; }
.apx-inline-stats b {
  font-size: 16px;
  font-weight: var(--nm-weight-med);
  color: var(--nm-text);
  line-height: 1.2;
}
.apx-inline-stats span { font-size: 10px; color: var(--nm-text-dim); }

.apx-meter { margin-bottom: 12px; }
.apx-meter-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--nm-text-muted);
  margin-bottom: 4px;
}
.apx-meter-top b { color: var(--nm-text); font-weight: var(--nm-weight-med); }
.apx-of { color: var(--nm-text-dim); font-weight: var(--nm-weight-reg); }
.apx-meter-track {
  height: 6px;
  border-radius: 3px;
  /* Lighter step of the same family as the fill, so state reads across the
     whole bar rather than only where it is filled. */
  background: rgba(169, 192, 222, 0.18);
  overflow: hidden;
}
.apx-meter-fill { height: 100%; border-radius: 3px; min-width: 2px; }

.apx-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 11px;
}
.apx-row-label {
  color: var(--nm-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
  min-width: 0;
}
.apx-row-val {
  color: var(--nm-text);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}
.apx-row-bar .apx-row-label { flex: 0 0 40%; }
.apx-bar-wrap {
  flex: 1 1 auto;
  height: 6px;
  background: rgba(169, 192, 222, 0.14);
  border-radius: 3px;
  overflow: hidden;
  min-width: 24px;
}
.apx-bar { display: block; height: 6px; border-radius: 3px; min-width: 2px; }

.apx-row.is-click {
  cursor: pointer;
  border-radius: var(--nm-radius-sm);
  padding-left: 4px; padding-right: 4px;
  margin-left: -4px; margin-right: -4px;
}
.apx-row.is-click:hover, .apx-row.is-click:focus-visible {
  background: rgba(var(--nm-blue-rgb), 0.1);
  outline: none;
}

.apx-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
  display: inline-block;
}

/* ── table view (every chart has one) ────────────────────────────────────── */

.apx-table-wrap { margin-top: 10px; overflow-x: auto; }
.apx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.apx-table th, .apx-table td {
  text-align: left;
  padding: 4px 6px;
  border-bottom: 1px solid rgba(169, 192, 222, 0.12);
  white-space: nowrap;
}
.apx-table th {
  color: var(--nm-text-dim);
  font-weight: var(--nm-weight-med);
  text-transform: uppercase;
  font-size: 9px;
  letter-spacing: 0.5px;
}
.apx-table td { color: var(--nm-text-muted); }
.apx-table td:first-child {
  white-space: normal;
  color: var(--nm-text);
}
.apx-td-num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── footer, lock, tooltip ───────────────────────────────────────────────── */

.apx-foot {
  font-size: 10px;
  color: var(--nm-text-faint);
  margin: 4px 0 0;
  line-height: 1.5;
}

.apx-lock {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px 24px;
}
.apx-lock-inner { text-align: center; color: var(--nm-text-muted); max-width: 300px; }
.apx-lock-inner i { color: var(--nm-accent); opacity: 0.75; }
.apx-lock-inner h3 {
  margin: 12px 0 6px;
  font-size: 15px;
  font-weight: var(--nm-weight-med);
  color: var(--nm-text);
}
.apx-lock-inner p { margin: 0; font-size: 12px; line-height: 1.55; }

.apx-tip {
  position: fixed;
  z-index: 10050;
  pointer-events: none;
  background: rgba(var(--nm-bg-deep-rgb), 0.97);
  border: 1px solid var(--nm-border-strong);
  border-radius: var(--nm-radius-md);
  box-shadow: var(--nm-shadow);
  padding: 7px 9px;
  font-size: 11px;
  color: var(--nm-text-muted);
  line-height: 1.5;
  max-width: 220px;
}
.apx-tip b { display: block; color: var(--nm-text); margin-bottom: 3px; font-weight: var(--nm-weight-med); }
.apx-tip span { display: flex; align-items: center; gap: 5px; }
.apx-tip span i {
  width: 8px; height: 8px;
  border-radius: 2px;
  display: inline-block;
  flex: 0 0 auto;
}

/* ── narrow screens ──────────────────────────────────────────────────────── */

@media (max-width: 520px) {
  .analytics-dashboard { width: 100vw; }
  .apx-stats { grid-template-columns: 1fr; }
}

/* Respect reduced-motion for the spinner and the drawer slide. */
@media (prefers-reduced-motion: reduce) {
  .apx-icon-btn.is-spinning i { animation: none; }
  .analytics-dashboard { transition: none; }
  .apx-body { transition: none; }
}
