/* ==========================================================================
   components.css — charts, map, bar-tables, donuts, filters, insights
   All sized fluidly; chart canvases live in position:relative wrappers and
   use Chart.js {responsive:true, maintainAspectRatio:false}.
   ========================================================================== */

/* ---- demographics: survey sub-header ------------------------------------ */
.survey-head { text-align: center; margin: 6px 0 28px; }
.survey-head .survey-name { color: var(--cimi-blue); font-weight: 700; font-size: 1.05rem; }
.survey-head .sample { color: var(--text-soft); font-size: .85rem; margin-top: 2px; }
.survey-head .sample b { color: var(--cimi-bluedark); font-size: 1.05rem; }

/* ---- responsive grids --------------------------------------------------- */
.grid-demo-top {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  align-items: start;
}
.grid-4 {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}
.grid-2 {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.tile { text-align: center; }
.tile > h4 {
  font-size: .82rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); margin-bottom: 14px; font-weight: 800;
}

/* ---- sex-at-birth figures ---------------------------------------------- */
.sex-figs { display: flex; justify-content: center; gap: clamp(20px, 6vw, 56px); }
.sex-fig { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.sex-fig .pct { font-size: 1.6rem; font-weight: 800; }
.sex-fig .sex-icon { width: 104px; height: 104px; display: block; }
.sex-fig.f .pct { color: var(--cimi-purple); }
.sex-fig.f .sex-icon { color: var(--cimi-purple); }
.sex-fig.m .pct { color: var(--cimi-blue); }
.sex-fig.m .sex-icon { color: var(--cimi-blue); }
.sex-fig .lbl { font-size: .8rem; color: var(--text-muted); font-weight: 600; }

/* ---- donut -------------------------------------------------------------- */
.donut-box { position: relative; width: 100%; max-width: 260px; aspect-ratio: 1; margin: 0 auto; }

/* ---- Canada map (MapLibre GL — no basemap) ------------------------------ */
.map-card { margin-top: 30px; }
.map-wrap { position: relative; max-width: 760px; margin: 0 auto; }
#canada-map {
  width: 100%; height: 500px; border-radius: var(--radius-sm);
  overflow: hidden; border: 1px solid var(--border); background: #f5f8fc;
}
.maplibregl-ctrl-group { box-shadow: var(--shadow) !important; }
/* region labels rendered as HTML markers (no glyph server needed) */
.map-marker {
  pointer-events: none; text-align: center; line-height: 1.05;
  font-family: "Lato", sans-serif; color: var(--text); white-space: nowrap;
  text-shadow: 0 1px 2px rgba(255,255,255,.9), 0 0 2px rgba(255,255,255,.9);
}
.map-marker .mk-name { display: block; font-size: 11px; font-weight: 700; }
.map-marker .mk-val { display: block; font-size: 12px; font-weight: 800; }
.map-marker.on-dark { color: #fff; text-shadow: 0 1px 3px rgba(16,42,75,.6); }
/* legend */
.map-legend { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 14px; font-size: .76rem; color: var(--text-muted); }
.map-legend .bar { height: 10px; width: 160px; border-radius: 5px;
  background: linear-gradient(90deg, var(--scale-lo), var(--scale-hi)); }

/* tooltip (shared by map + others) */
.tooltip {
  position: fixed; z-index: 60; pointer-events: none; opacity: 0;
  background: #fff; border: 1px solid var(--border); box-shadow: var(--shadow-md);
  border-radius: 8px; padding: 7px 11px; font-size: .8rem; color: var(--text);
  transition: opacity .1s; white-space: nowrap;
}
.tooltip b { color: var(--cimi-blue); }

/* ---- demographic formatted tables (Age / Ethnicity / Education / Income) -
   image-2 style: label + a full-width teal-shaded cell with the value inside  */
.demotable { display: flex; flex-direction: column; gap: 2px; text-align: left; }
.demotable-row { display: grid; grid-template-columns: minmax(64px, 44%) 1fr; align-items: stretch; gap: 10px; }
.demotable-row .lbl { font-size: .8rem; color: var(--text); font-weight: 600; line-height: 1.25; align-self: center; }
.demotable-row .cell { min-height: 42px; border-radius: 0; display: flex; align-items: center; justify-content: flex-end; padding: 0 14px; }
.demotable-row .val { font-size: .85rem; font-weight: 800; color: #fff !important; text-shadow: 0 1px 2px rgba(0,0,0,.4); }

/* ---- chart wrappers (Chart.js) ----------------------------------------- */
.chart-box { position: relative; width: 100%; }
.chart-box.summary { height: 200px; }
.chart-box.breakdown { height: 440px; }      /* JS may raise this per category count */
.chart-box.covid-bars { height: 260px; }

/* ---- filter pills ------------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 4px 0 18px; }
.filter-btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 700; font-size: .8rem;
  padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: #fff; color: var(--text-muted); transition: all .14s;
}
.filter-btn:hover { border-color: var(--cimi-teal); color: var(--cimi-blue); }
.filter-btn.active { background: var(--cimi-blue); border-color: var(--cimi-blue); color: #fff; }

/* ---- summary bar groups (outcome tabs) --------------------------------- */
/* immigrant status | immigrant type: two wide columns (~50% each) when there's
   room, dropping to ONE full-width column when the container is narrow so the
   bars/labels never clip. The .wrap max-width caps this at two columns (no 25%
   squeeze next to the full-width status×sex row); .bar-group.wide always spans
   the full row. */
.summary-grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr)); margin-bottom: 6px; }
.bar-group { background: var(--surface-alt); border-radius: var(--radius-sm); padding: 16px 16px 8px; }
.bar-group > h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); text-align: center; margin-bottom: 10px; font-weight: 800; }
.bar-group.wide { grid-column: 1 / -1; }

/* ---- COVID legend ------------------------------------------------------- */
.covid-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 22px; margin: 4px 0 22px; }
.covid-legend .item { display: inline-flex; align-items: center; gap: 7px; font-size: .85rem; font-weight: 600; color: var(--text-muted); }
.covid-legend .dot { width: 13px; height: 13px; border-radius: 3px; }

.covid-donut-tile { text-align: center; }
.covid-donut-tile > h4 { font-size: .82rem; color: var(--text-muted); margin-bottom: 8px; font-weight: 800; }

/* ---- insight box -------------------------------------------------------- */
.insight {
  margin-top: 30px; background: var(--surface-alt);
  border-left: 4px solid var(--cimi-blue); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 18px 22px;
}
.insight .insight-title { font-weight: 800; color: var(--cimi-blue); margin-bottom: 10px; font-size: 1rem; }
.insight ul { margin: 0; padding-left: 20px; color: var(--text); }
.insight li { margin-bottom: 8px; font-size: .92rem; }
.insight li:last-child { margin-bottom: 0; }

/* ---- small screens ------------------------------------------------------ */
@media (max-width: 560px) {
  .page-title { padding-top: 16px; font-size: 1.15rem; }
  .chart-box.summary { height: 170px; }
  .sex-fig .sex-icon { width: 84px; height: 84px; }
  #canada-map { height: 360px; }
}
