/* ==========================================================================
   components.css — CIMI Comparison (builds on theme.css)
   ORIGINAL palette preserved: accent #4B9E9E, active #bfdbfe, blue→brown ranks.
   ========================================================================== */

:root { --accent: #4B9E9E; --accent-dark: #3a8b8b; --active: #bfdbfe; }

main { padding: 22px 0 56px; }
.subtitle { text-align: center; color: var(--text-muted); margin: 4px auto 22px; max-width: 760px; padding: 0 20px; }

/* ---- mode toggle (Province / CMA) + Help -------------------------------- */
.mode-bar { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 26px; flex-wrap: wrap; }
.mode-pills { display: flex; justify-content: center; }
.mode-pills .inner { display: inline-flex; gap: 4px; padding: 4px; background: #eef2f7; border-radius: 12px; }
.mode-pills button { appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 700; padding: 9px 22px; border-radius: 9px; background: transparent; color: var(--text-muted); transition: all .15s; }
.mode-pills button.active { background: var(--accent); color: #fff; }

/* ---- dimension selector ------------------------------------------------- */
.dims { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 26px; }
.dim-button { appearance: none; cursor: pointer; font: inherit; border: 2px solid transparent; border-radius: 12px; padding: 20px; text-align: center; font-weight: 800; font-size: var(--fs-lg); background: var(--accent); color: #fff; transition: all .18s; display: flex; align-items: center; justify-content: center; gap: 10px; }
.dim-button:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(16,42,75,.12); }
.dim-button.active { background: var(--active); border-color: var(--active); color: #1e3a5f; }
/* no data for the current comparison group → greyed + unclickable (the icon is
   fill=currentColor, so it greys with the text). Hover lift is suppressed. */
.dim-button:disabled { background: #d9dde3; border-color: transparent; color: #8a929e; cursor: not-allowed; }
.dim-button:disabled:hover { transform: none; box-shadow: none; }
.dim-button .dim-ico { display: inline-flex; flex: none; }
.dim-button .ms-ico { width: 24px; height: 24px; display: block; }   /* fill=currentColor → matches button text colour (white / active navy) */

/* ---- indicator definition (white inside, accent-coloured frame) --------- */
.def-box { background: #fff; color: var(--text); border: 2px solid var(--accent); border-radius: var(--radius); padding: 18px 24px; margin-bottom: 24px; display: flex; align-items: center; gap: 22px; }
.def-ico { flex: none; width: 60px; height: 60px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }
.def-ico .ms-ico { width: 32px; height: 32px; display: block; }
.def-content { flex: 1; min-width: 0; }
.def-content h3 { color: var(--accent-dark); margin-bottom: 6px; font-size: 1.1rem; }
.def-content p { font-size: var(--fs-min); line-height: 1.55; color: var(--text); }

/* ---- filters ------------------------------------------------------------ */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 26px; }
/* min-height reserves ~2 lines so a 1-line and a 2-line label still line their
   selects up (labels grew to 16px and now wrap at some widths). */
.filters label { display: block; font-size: var(--fs-min); font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--accent-dark); margin-bottom: 6px; min-height: 2.5em; }
.filters select {
  width: 100%; appearance: none; font: inherit; font-weight: 600; color: #1e293b;
  padding: 10px 36px 10px 12px; border: 1.5px solid var(--accent); border-radius: var(--radius-sm);
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%234B9E9E' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  cursor: pointer;
}
.filters select:focus { outline: none; border-color: var(--accent-dark); box-shadow: 0 0 0 3px rgba(75,158,158,.18); }

/* ---- map ---------------------------------------------------------------- */
.map-head { background: var(--accent); color: #fff; border-radius: var(--radius) var(--radius) 0 0; padding: 14px 18px; text-align: center; }
.map-head .title { font-weight: 800; font-size: 1.1rem; display: flex; align-items: center; justify-content: center; gap: 8px; }
.map-head .title .map-ico { display: inline-flex; flex: none; color: #fff; }
.map-head .title .ms-ico { width: 22px; height: 22px; display: block; }
.map-head .sub { font-size: var(--fs-min); opacity: .9; }
/* grey description strip between the map title and the map (image 1) */
.map-desc { background: #f1f5f9; border-left: 1px solid var(--border); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border-soft); padding: 12px 18px; text-align: center; font-size: var(--fs-min); color: var(--text-muted); line-height: 1.55; }
.map-desc:empty { display: none; }
.map-desc .text-red-600 { color: #a80000; font-weight: 700; }
.map-body { border: 1px solid var(--border); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); padding: 16px; }
#comp-map { width: 100%; height: 460px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); background: #f5f8fc; }
.map-legend { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: var(--fs-min); color: var(--text-muted); }
.map-legend .bar { height: 10px; width: 200px; border-radius: 5px; background: linear-gradient(to right, #003066, #004d99, #1a75ff, #4d94ff, #99c2ff, #cce0ff, #ffe0cc, #ffb380, #ff8533, #e65c00, #b34700); }
.maplibregl-ctrl-group { box-shadow: var(--shadow) !important; }
.cma-pin { cursor: pointer; line-height: 0; filter: drop-shadow(0 1px 1.5px rgba(0,0,0,.3)); }
.cma-pin svg { display: block; }

/* ---- time series -------------------------------------------------------- */
.ts-card { margin-top: 24px; }
.ts-card h3 { font-size: 1.1rem; margin-bottom: 16px; }
.ts-flex { display: flex; flex-wrap: wrap; gap: 20px; }
.ts-chart { position: relative; flex: 1 1 60%; min-width: 280px; height: 460px; }
.ts-legend { flex: 1 1 200px; max-height: 460px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.ts-leg { display: flex; align-items: center; gap: 8px; appearance: none; border: 0; background: none; cursor: pointer; font: inherit; font-size: var(--fs-min); padding: 4px 6px; border-radius: 6px; text-align: left; color: var(--text); }
.ts-leg:hover { background: var(--surface-alt); }
.ts-leg .sw { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; }
.ts-leg.off { opacity: .4; text-decoration: line-through; }

/* ---- ranking heatmap table --------------------------------------------- */
.heatmap-card { margin-top: 24px; }
.heatmap-card h3 { font-size: 1.1rem; margin-bottom: 14px; }
.table-scroll { overflow-x: auto; scrollbar-width: none; }   /* native bar hidden — replaced by the always-visible .hscroll below */
.table-scroll::-webkit-scrollbar { display: none; }

/* --- custom always-visible horizontal scrollbar (only while the matrix overflows) ---
   macOS overlay scrollbars auto-hide until you scroll and can't be forced visible
   cross-browser, so we draw our own: a slim always-visible track + draggable thumb
   under the matrix, shown only while it overflows. /apps/_shared/hscrollbar.js builds
   the track/thumb and keeps them in sync (scroll · drag · track-click · keyboard). */
.hscroll {
  display: none;                      /* shown by JS only when the matrix overflows */
  height: 12px; margin: 10px 2px 0; border-radius: 999px; overflow: hidden;
  background: var(--border-soft); touch-action: none; cursor: pointer;
}
.hscroll.is-scrollable { display: block; }
.hscroll-thumb {
  width: 40px; height: 100%; border-radius: 999px; background: #9aa7b8;
  cursor: grab; transition: background .15s ease;
}
.hscroll-thumb:hover { background: #8391a5; }
.hscroll-thumb.dragging { background: #7c8ba0; cursor: grabbing; }
.hscroll-thumb:focus-visible { outline: 2px solid var(--cimi-blue); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .hscroll-thumb { transition: none; } }
#rankingTable { width: 100%; border-collapse: collapse; font-size: var(--fs-min); }
#rankingTable th { background: var(--accent); color: #fff; font-weight: 700; padding: 8px; text-align: center; font-size: var(--fs-min); line-height: 1.2; vertical-align: middle; min-width: 92px; }
#rankingTable th.geo-col { text-align: left; position: sticky; left: 0; z-index: 5; min-width: 150px; }
#rankingTable th.sel { background: var(--accent-dark); }
#rankingTable td { text-align: center; height: 46px; font-weight: 700; border: 1px solid #eef2f7; }
#rankingTable td.geo-col { text-align: left; font-weight: 700; background: #fff; position: sticky; left: 0; z-index: 4; border-right: 1px solid var(--border); white-space: nowrap; padding: 6px 12px; color: var(--text); }
#rankingTable td.rank { cursor: default; }
#rankingTable td.rank.sel { outline: 2px solid #1e293b; outline-offset: -2px; }
#rankingTable td.empty { color: var(--text-soft); }
#rankingTable tbody tr:hover td.geo-col { background: var(--surface-alt); }
/* On phones, don't freeze the Geography column — let the whole table scroll
   horizontally (the sticky column otherwise eats most of a narrow viewport). */
@media (max-width: 640px) {
  #rankingTable th.geo-col,
  #rankingTable td.geo-col { position: static; min-width: 120px; }
}

/* ---- help modal --------------------------------------------------------- */
.help-btn { appearance: none; cursor: pointer; font: inherit; font-weight: 700; font-size: var(--fs-min); padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: #fff; color: var(--accent-dark); display: inline-flex; align-items: center; gap: 6px; }
.help-btn:hover { border-color: var(--accent); }
.help-modal { display: none; position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.55); overflow-y: auto; padding: 40px 20px; }
.help-modal.open { display: block; }
.help-modal .panel { display: block; background: #fff; border-radius: 16px; width: min(760px, 100%); margin: 0 auto; box-shadow: 0 20px 50px rgba(0,0,0,.35); overflow: hidden; }
.help-modal .panel-head { background: var(--accent); color: #fff; padding: 18px 22px; display: flex; justify-content: space-between; align-items: center; }
.help-modal .panel-head h2 { color: #fff; font-size: 1.3rem; }
.help-modal .panel-head button { appearance: none; border: 0; background: rgba(255,255,255,.2); color: #fff; cursor: pointer; width: 32px; height: 32px; border-radius: 50%; font-size: 1.1rem; }
.help-modal .panel-body { padding: 24px; color: var(--text); line-height: 1.6; font-size: var(--fs-min); }
.help-modal .panel-body p { margin: 0 0 14px; }
.help-modal .panel-body p:last-child { margin-bottom: 0; }
.help-modal .panel-body .text-red-600, .help-modal .panel-body .hl-red { color: #c0392b; font-weight: 700; }
.hl-red { color: var(--cimi-red); font-weight: 700; }
/* Notes modal: small reference table (scrolls horizontally on narrow screens, never clips) */
.help-modal .panel-body .table-wrap { overflow-x: auto; margin: 4px 0 16px; -webkit-overflow-scrolling: touch; }
.help-modal .panel-body table { width: 100%; border-collapse: collapse; font-size: var(--fs-min); }
.help-modal .panel-body th, .help-modal .panel-body td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.help-modal .panel-body thead th { border-bottom: 2px solid var(--border); font-weight: 700; }
/* Combined Help modal — tab strip + panes */
.help-modal .modal-tabs { display: flex; gap: 4px; padding: 12px 22px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.help-modal .modal-tab { appearance: none; border: 0; background: transparent; cursor: pointer; font: inherit; font-weight: 700; font-size: var(--fs-min); color: var(--text-muted); padding: 10px 14px; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.help-modal .modal-tab:hover { color: var(--accent-dark); }
.help-modal .modal-tab.active { color: var(--accent-dark); border-bottom-color: var(--accent); }
.help-modal .tab-pane { display: none; }
.help-modal .tab-pane.active { display: block; }

/* ---- map tooltip -------------------------------------------------------- */
.map-tooltip { position: fixed; z-index: 90; pointer-events: none; opacity: 0; transition: opacity .1s; background: #fff; border: 1px solid var(--border); box-shadow: var(--shadow-md); border-radius: 8px; padding: 9px 12px; font-size: var(--fs-min); color: var(--text); min-width: 140px; }
.map-tooltip .tt-title { font-weight: 800; color: var(--accent-dark); margin-bottom: 4px; }
.map-tooltip .tt-row { display: flex; justify-content: space-between; gap: 12px; }
.map-tooltip .tt-score { font-size: var(--fs-min); color: var(--text-soft); }

@media (max-width: 640px) {
  .dims { grid-template-columns: 1fr; }
  .def-box { flex-direction: column; gap: 14px; }
  .def-content { text-align: center; }
  #comp-map { height: 340px; }
  .ts-chart { flex-basis: 100%; height: 360px; }
}
