/* ============================================================
   Brand & Store — Shopper Insight · By Dimension section
   bs-shopper-insight-dimension.css  (FE-035 slice 2)
   Namespaced .bs-si-dimension, .bs-si-rank-*, .bs-si-plat-*.
   Tokens only — cohort colors via var(--bs-cohort-new / --bs-cohort-ret),
   defined once on .bs-si-page (bs-shopper-insight.css):
     New  = cyan   (--bs-cohort-new)
     Ret  = orange (--bs-cohort-ret)
   .card / .card__header / .card-title-sep / .pnl-compare-toggle /
   .pnl-compare-btn / .bs-si-state are inherited from shared CSS.
   ============================================================ */

/* ---- root wrapper ---- */
.bs-si-dimension {
  display: flex;
  flex-direction: column;
  gap: var(--space-5, 20px);
}

/* ================================================================
   "By Dimension" — TWO equal-width, equal-height rows (feedback 2026-06-04):
     row 1 = NMV-by-Province map  |  Detail-by-Province table
     row 2 = By Platform | NMV by Payment | Shoppers by Day Type
   align-items:stretch → cards in a row share the tallest height.
================================================================ */
.bs-si-dim-row {
  display: grid;
  gap: var(--space-4, 16px);
  align-items: stretch;
}
.bs-si-dim-row--2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.bs-si-dim-row--3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); }
.bs-si-dim-row > .card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin: 0;
}
/* The 3-card row (By Platform | Payment | Day Type) carries wide numeric values
   (cohort counts up to ~7 digits) → it needs ~1300px to fit 3-up without leaking
   width to the page. The 2-card row fits down to 980px. (overflow fix 2026-06-09) */
@media (max-width: 1300px) {
  .bs-si-dim-row--3 { grid-template-columns: 1fr; }
}
@media (max-width: 980px) {
  .bs-si-dim-row--2 { grid-template-columns: 1fr; }
}

/* Small dimension-row cards (NMV-by-Province, Detail-by-Province, By-Platform):
   the toggle(s) drop to their OWN line, centered, below the title — these cards
   are too narrow to hold a title + toggle on one row (feedback 2026-06-04). */
.bs-si-dim-row .card__header--split {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;   /* override .card__header space-between → no vertical spread */
  gap: var(--space-2, 8px);
}
/* the title block must NOT grow vertically (it has flex:1 for the row layout) —
   else it expands and shoves the toggles to the bottom of the card (big top gap). */
.bs-si-dim-row .card__header--split > div:first-child { flex: 0 0 auto; }
.bs-si-dim-row .card__header--split .card__actions {
  margin-left: 0;
  justify-content: center;
  flex-wrap: wrap;
  row-gap: var(--space-2, 8px);
}

/* Map + table fill their stretched cards so the two row-1 cards match height. */
.bs-si-map-card .bs-vn-map { flex: 1; display: flex; flex-direction: column; min-height: 0; }
/* table-wrap is NOT flex-grow (its own max-height governs the scroll cap); the
   card stretches to the row height via grid align-items:stretch instead. */

/* ---- NMV by Province · Leaflet map (left panel) ---- */
.bs-vn-map__canvas {
  flex: 1;
  height: auto;
  min-height: 360px;
  width: 100%;
  border-radius: var(--radius-sm, 6px);
  overflow: hidden;
  background: var(--bg-inset, rgba(148, 163, 184, 0.08));
}
/* Hoàng Sa / Trường Sa territorial labels on the map */
.bs-vn-archi {
  font-size: 9px;
  font-weight: 600;
  line-height: 1.15;
  color: #1D4ED8;
  text-align: center;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff;
  pointer-events: none;
  white-space: nowrap;
}
.bs-vn-archi span { display: block; font-weight: 400; font-size: 8px; opacity: 0.85; }
html[data-theme="dark"] .bs-vn-archi { color: #93B4FF; text-shadow: 0 0 3px #0b0e14, 0 0 3px #0b0e14; }
.bs-vn-map__fallback {
  padding: var(--space-3, 12px) 0 0;
  font-size: 12px;
  color: var(--text-tertiary);
}
.bs-vn-map__legend {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: var(--space-3, 12px);
  font-size: 11px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.bs-vn-map__legend-lbl { color: var(--text-tertiary); margin-right: 2px; }
.bs-vn-map__dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.bs-vn-map__dot--min { background: rgba(37, 99, 235, 0.30); }
.bs-vn-map__dot--max { background: rgba(37, 99, 235, 0.85); }
.bs-vn-map__arrow { color: var(--text-tertiary); }
.bs-vn-map__val { font-family: var(--font-mono, 'Geist Mono', monospace); color: var(--text-primary); }
/* Keep Leaflet panes/controls beneath app chrome (modals/dropdowns z>=1000). */
.bs-vn-map__canvas .leaflet-pane,
.bs-vn-map__canvas .leaflet-top,
.bs-vn-map__canvas .leaflet-bottom { z-index: 1; }
.bs-vn-map__canvas .leaflet-control-zoom { z-index: 2; }

/* ---- Detail by Province · ranked table — portfolio table standard
   (matches #overall-performance: bordered cells, bold/UPPERCASE/centered
   headers on --bg-inset, zebra rows, right-aligned mono numerics). ---- */
/* Cap at ~20 rows then scroll (header is sticky). The cap also stops the table
   from forcing the whole row taller than the map in the stretched 2-up layout. */
.bs-si-prov-table-wrap { overflow-y: auto; overflow-x: hidden; max-height: 560px; border: 1px solid var(--border-default); border-radius: var(--radius-md); }
.bs-si-prov-table { width: 100%; border-collapse: collapse; font-size: var(--font-data, 13px); }
.bs-si-prov-table thead { position: sticky; top: 0; z-index: 2; }   /* stick the thead, not the cells */
.bs-si-prov-table th,
.bs-si-prov-table td {
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.18));
  padding: 6px var(--space-3, 12px);
  white-space: nowrap;
}
.bs-si-prov-table thead th {
  background: var(--bg-inset, #EAEBEE);
  font-size: var(--font-xs, 11px);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary, #5F6775);
  text-align: center;
}
.bs-si-prov-table tbody td { color: var(--text-primary); }
.bs-si-prov-table tbody tr:nth-of-type(even) td { background: color-mix(in srgb, var(--text-primary) 3.5%, transparent); }
.bs-si-prov-table tbody tr:hover td { background: var(--bg-hover, rgba(148, 163, 184, 0.10)); }
.bs-si-prov-rank, .bs-si-prov-num { text-align: right; }
.bs-si-prov-table th.bs-si-prov-rank,
.bs-si-prov-table td.bs-si-prov-rank { width: 40px; color: var(--text-tertiary); }
.bs-si-prov-name { text-align: left; max-width: 0; overflow: hidden; text-overflow: ellipsis; }
.bs-si-prov-num {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono, 'Geist Mono', monospace);
}
.bs-si-prov-pct { color: var(--text-tertiary); width: 76px; }
/* Day-type paired bars: wider name slot for "Mid-month payday" / "End-month payday" */
.bs-si-plat-wrap--daytype .bs-si-plat-block { grid-template-columns: 132px 1fr; }
.bs-si-daytype-note {
  margin: 0;
  padding: 0 var(--space-5, 20px) var(--space-4, 16px);
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-tertiary);
}
.bs-si-daytype-note strong { color: var(--text-secondary); }
.bs-si-daytype-note p { margin: 0 0 4px; }
.bs-si-daytype-note ul { margin: 0; padding-left: 16px; }
.bs-si-daytype-note li { margin: 2px 0; }

/* ================================================================
   Ranked bar rows — shared by Panel A (province) + Panel B (payment)
   Row layout: [label 1fr] [track flex-1] [money right] [pct fixed]
================================================================ */
.bs-si-rank-list {
  padding: var(--space-3, 12px) var(--space-5, 20px) var(--space-4, 16px);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.bs-si-rank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) auto auto;
  align-items: center;
  gap: var(--space-3, 12px);
  min-height: 32px;          /* grows when a long label wraps */
  padding: 3px 0;
}

.bs-si-rank-label {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.3;
  word-break: break-word;    /* full label, wraps — never truncated */
  min-width: 0;
}

.bs-si-rank-track {
  position: relative;
  height: 12px;
  border-radius: 3px;
  background: var(--bg-inset, rgba(148, 163, 184, 0.08));
  overflow: hidden;
}

.bs-si-rank-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 3px;
  transition: width 0.25s ease;
}

/* Panel A: action blue */
.bs-si-rank-fill--action { background: var(--color-action, #2563eb); }
/* Panel B: cohort-new teal */
.bs-si-rank-fill--teal   { background: var(--bs-cohort-new); }

.bs-si-rank-val {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono, 'Geist Mono', monospace);
  font-style: normal;
  color: var(--text-primary);
  text-align: right;
  white-space: nowrap;
}

.bs-si-rank-pct {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono, 'Geist Mono', monospace);
  font-style: normal;
  color: var(--text-tertiary);
  text-align: right;
  white-space: nowrap;
  width: 52px;
}

/* Panel B footnote */
.bs-si-pay-footnote {
  margin: var(--space-3, 12px) 0 0;
  font-size: 11px;
  color: var(--text-tertiary);
  font-style: normal;
}

/* ================================================================
   By-platform metric toggle — chevron clip-path restyle.
   Scoped to .bs-si-dimension so the shared .pnl-compare-btn used
   elsewhere is untouched. Cohort colors already match; this only
   reshapes the buttons into chevrons. Right padding compensates for
   the clipped point so labels stay centered.
================================================================ */
/* Chevron shape: flat left edge, pointed right tip. Applied ONLY to the
   By-Platform card's metric toggle — scoped via :has(.bs-si-plat-wrap)
   so no other toggle in the dimension section is affected.
   First button: square left + right chevron point.
   Middle buttons: left chevron indent + right chevron point.
   Last button: left chevron indent + square right edge. */
.bs-si-dimension .card:has(.bs-si-plat-wrap) .pnl-compare-toggle {
  gap: 0;
  padding: 0;
  overflow: visible;
  background: transparent;
  border: none;
}
.bs-si-dimension .card:has(.bs-si-plat-wrap) .pnl-compare-btn {
  position: relative;
  padding: 0 18px 0 22px;
  border-radius: 0;
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 0 100%, 8px 50%);
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  border-right: none;
  z-index: 1;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.bs-si-dimension .card:has(.bs-si-plat-wrap) .pnl-compare-btn:first-child {
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 0 100%);
  padding-left: var(--space-3, 12px);
  border-radius: calc(var(--radius-sm, 6px) - 1px) 0 0 calc(var(--radius-sm, 6px) - 1px);
}
.bs-si-dimension .card:has(.bs-si-plat-wrap) .pnl-compare-btn:last-child {
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 8px 50%);
  padding-right: var(--space-3, 12px);
  border-right: 1px solid var(--border-default);
  border-radius: 0 calc(var(--radius-sm, 6px) - 1px) calc(var(--radius-sm, 6px) - 1px) 0;
}
.bs-si-dimension .card:has(.bs-si-plat-wrap) .pnl-compare-btn--active {
  background: var(--color-action);
  color: var(--text-on-action);
  z-index: 2;
  border-color: var(--color-action);
}

/* ================================================================
   Platform bars — Panel C
   Structure: legend row, then per-platform blocks.
   Each block: platform name row + two bar rows (New / Returning).
================================================================ */
.bs-si-plat-wrap {
  padding: var(--space-3, 12px) var(--space-5, 20px) var(--space-4, 16px);
}

/* Legend: top-center, swatches + labels */
.bs-si-plat-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3, 12px);
  margin-bottom: var(--space-4, 16px);
  font-size: 12px;
  color: var(--text-secondary);
}

.bs-si-plat-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
.bs-si-plat-swatch--new { background: var(--bs-cohort-new); }
.bs-si-plat-swatch--ret { background: var(--bs-cohort-ret); }
.bs-si-plat-legend-lbl  { color: var(--text-secondary); }

/* Per-platform block */
.bs-si-plat-block {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: var(--space-3, 12px);
  padding: var(--space-2, 8px) 0;
  border-bottom: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.12));
}
.bs-si-plat-block:last-child { border-bottom: none; }

.bs-si-plat-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.bs-si-plat-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Each bar row: [cohort label] [track] [value] */
.bs-si-plat-row {
  display: grid;
  grid-template-columns: 60px minmax(0, 1fr) auto auto;   /* cohort | bar | value | % */
  align-items: center;
  gap: var(--space-2, 8px);
  height: 22px;
}
.bs-si-plat-pct {
  font-size: 11px;
  color: var(--text-tertiary);
  text-align: right;
  white-space: nowrap;
  min-width: 44px;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono, 'Geist Mono', monospace);
}

.bs-si-plat-cohort-lbl {
  font-size: 11px;
  color: var(--text-tertiary);
  text-align: right;
  white-space: nowrap;
}

.bs-si-plat-track {
  position: relative;
  height: 14px;
  border-radius: 3px;
  background: var(--bg-inset, rgba(148, 163, 184, 0.08));
  overflow: hidden;
}

.bs-si-plat-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 3px;
  transition: width 0.25s ease;
}
.bs-si-plat-fill--new { background: var(--bs-cohort-new); }
.bs-si-plat-fill--ret { background: var(--bs-cohort-ret); }

.bs-si-plat-val {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono, 'Geist Mono', monospace);
  font-style: normal;
  color: var(--text-primary);
  text-align: right;
  white-space: nowrap;
  min-width: 80px;
}

/* ---- Responsive: 390px mobile ---- */
@media (max-width: 560px) {
  .bs-si-rank-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    height: auto;
    padding: 4px 0;
  }
  /* Drop the pct column on very small screens */
  .bs-si-rank-pct { display: none; }

  .bs-si-plat-block {
    grid-template-columns: 1fr;
    gap: var(--space-2, 8px);
  }
  .bs-si-plat-name { font-size: 12px; }
  .bs-si-plat-row {
    grid-template-columns: 52px 1fr auto auto;
  }
  .bs-si-plat-val { min-width: 60px; }
}

/* ================================================================
   Compare-mode button visual states — scoped to .bs-si-page so
   the shared .pnl-compare-btn in other pages is untouched.
   :active = press-down feedback (transform + dim).
   [aria-selected="true"] = selected state synonym (for assistive
   tech that reads aria-selected, mirrors pnl-compare-btn--active).
================================================================ */
.bs-si-page .pnl-compare-btn:active {
  transform: scale(0.96);
  opacity: 0.85;
}
.bs-si-page .pnl-compare-btn[aria-selected="true"] {
  background: var(--color-action);
  color: var(--text-on-action);
}
.bs-si-page .pnl-compare-btn[aria-selected="true"]:hover {
  background: var(--color-action-hover);
  color: var(--text-on-action);
}
.bs-si-page .pnl-compare-btn[aria-selected="true"]:active {
  opacity: 0.9;
  transform: scale(0.97);
}
