/* ============================================================
   Compare: the atlas (legend of places + locator map) and
   one dot-and-bar plot per shared indicator.
   A place's colour is --pc (= --viz-1..4); its kind is the marker:
   filled dot = district, ring = whole city.
   ============================================================ */

/* in-place updates (a new selection) redraw without entrance motion */
.cmp-screen.is-live > *, .cmp-screen.is-live .cc-bar, .cmp-screen.is-live :is(.cc-mark, .cc-val) { animation: none; }

/* ---------- markers (legend, plot, key) ---------- */
.cp-mark, .cc-mark, .ck-mark {
  width: 12px; height: 12px; border-radius: 50%; flex: none;
  background: var(--pc); box-shadow: 0 0 0 2px var(--surface);
}
.is-city > .cp-mark, .is-city .cc-mark, .ck-mark.is-city { background: var(--surface); border: 3px solid var(--pc); }
.ck-mark { --pc: var(--ink-dim); }

/* ---------- the atlas ---------- */
.cmp-atlas {
  display: grid; grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  padding: 0; overflow: hidden; border-radius: var(--radius-lg);
  margin-bottom: var(--section-gap);
}
.cmp-atlas.no-map { grid-template-columns: minmax(0, 1fr); }
.cmp-atlas.no-map .cmp-well { display: none; }
.cmp-legend { display: flex; flex-direction: column; gap: var(--s-3); padding: var(--s-5); min-width: 0; }
.cl-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); }
.cl-title { font-size: var(--fs-h3); line-height: var(--lh-h3); font-weight: 700; color: var(--ink-hi); }
.cl-count { font-size: var(--fs-micro); font-weight: 600; color: var(--ink-faint); white-space: nowrap; }
.cl-list { display: grid; gap: var(--s-2); margin: 0; padding: 0; list-style: none; }
.cmp-atlas.no-map .cl-list { grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
.cl-hint { display: flex; align-items: center; gap: 8px; margin-top: auto; padding-top: var(--s-2); font-size: var(--fs-micro); color: var(--ink-dim); line-height: 1.6; }
.cl-hint .ico { width: 16px; height: 16px; flex: none; color: var(--ink-faint); }
.cmp-atlas.no-map .cl-hint { display: none; }

.cmp-place {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--s-3);
  min-height: 56px; padding-block: 8px; padding-inline: 16px 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
:root[data-theme="dark"] .cmp-place { background: var(--surface-2); border-color: transparent; }
.cp-text { min-width: 0; }
.cp-text b { display: block; font-size: 14.5px; font-weight: 700; color: var(--ink-hi); line-height: 1.45; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-meta { display: block; font-size: var(--fs-micro); color: var(--ink-dim); line-height: 1.5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* the "add" chip: a dashed create target holding a native select */
.cmp-add {
  position: relative; display: flex; align-items: center; min-height: 48px;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius-sm);
  color: var(--ink-dim); transition: border-color var(--t-fast) var(--ease-std), color var(--t-fast) var(--ease-std);
}
.cmp-add:not(.is-full):hover { border-color: var(--accent); color: var(--accent); }
.cmp-add:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.cmp-add > .ico { position: absolute; inset-inline-start: 16px; width: 18px; height: 18px; pointer-events: none; }
.cmp-add::after { position: absolute; inset-inline-end: 16px; pointer-events: none; }
.cmp-add select {
  appearance: none; width: 100%; min-height: 45px; cursor: pointer;
  background-color: transparent; border: 0; outline: none; color: inherit;
  font: inherit; font-size: 14px; font-weight: 600; padding-inline: 46px 40px;
}
.cmp-add select option, .cmp-add select optgroup { background-color: var(--surface); color: var(--ink-hi); }
.cmp-add.is-full { opacity: 0.6; }
.cmp-add.is-full select { cursor: not-allowed; }

/* the locator map: a well with the city's districts */
.cmp-well {
  position: relative; display: grid; min-height: 300px; padding: var(--s-5) var(--s-5) var(--s-7);
  background: radial-gradient(80% 70% at 50% 45%, var(--accent-soft), transparent 70%), var(--bg-soft);
  border-inline-start: 1px solid var(--line);
}
.cmp-map { display: grid; place-items: center; min-height: 0; }
.cmp-map svg { width: 100%; height: 100%; max-height: 330px; display: block; overflow: visible; }
.cmp-map path { vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.cm-areas path {
  fill: var(--surface); stroke: var(--line-strong); stroke-width: 1;
  transition: fill var(--t-med) var(--ease-std), stroke var(--t-med) var(--ease-std);
}
.cm-areas path.is-pick { cursor: pointer; }
.cm-areas path.is-pick:hover { fill: var(--surface-3); }
.cm-areas path.is-on, .cm-areas path.is-on:hover { fill: var(--pc); stroke: var(--surface); stroke-width: 1.5; }
.cm-halo path { fill: none; stroke: transparent; stroke-width: 7; transition: stroke var(--t-med) var(--ease-std); }
.has-city .cm-halo path { stroke: var(--city-c); }
.cm-caption {
  position: absolute; inset-block-end: var(--s-4); inset-inline-start: var(--s-5);
  font-size: var(--fs-micro); color: var(--ink-dim);
}
.cm-caption b { color: var(--ink); font-weight: 700; }

/* ---------- results ---------- */
.cmp-sec-head {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: var(--s-3) var(--s-5); margin-bottom: var(--s-4);
}
.cmp-key {
  display: flex; flex-wrap: wrap; gap: 6px var(--s-5); margin: 0; padding: 0; list-style: none;
  font-size: var(--fs-micro); color: var(--ink-dim);
}
.cmp-key li { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.ck-cut {
  position: relative; width: 26px; height: 6px; border-radius: 99px; background: var(--ink-dim);
}
.ck-cut::after {
  content: ""; position: absolute; inset-inline-start: 13px; top: -4px; width: 5px; height: 14px;
  background: var(--bg); transform: skewX(-22deg);
}
.cmp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 460px), 1fr)); gap: var(--gap); }
.cmp-note { margin-top: var(--s-4); max-width: 80ch; font-size: var(--fs-micro); color: var(--ink-dim); line-height: 1.7; text-wrap: pretty; }

/* ---------- one indicator: head + the dot-and-bar plot ---------- */
.cmp-card { display: flex; flex-direction: column; gap: var(--s-4); padding: var(--s-5); }
.cc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); }
.cc-title { min-width: 0; }
.cc-name { display: block; font-size: var(--fs-h3); line-height: var(--lh-h3); font-weight: 700; color: var(--ink-hi); text-wrap: balance; }
.cc-name:hover { color: var(--accent); }
.cc-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; font-size: var(--fs-micro); color: var(--ink-dim); }
.cc-dir::before { margin-inline-end: 5px; font-family: var(--f-num); font-weight: 700; color: var(--ink-faint); }
.cc-dir.is-up::before { content: "↑"; }
.cc-dir.is-down::before { content: "↓"; }
.cc-dir.is-band::before { content: "↔"; }
.cc-head .code-tag { flex: none; }

.cc-plot { display: grid; margin-top: auto; }
.cc-row { display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr); align-items: center; column-gap: var(--s-4); }
.cc-place { font-size: 13px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
html[lang="ar"] .cc-place { font-size: 13.5px; }
/* the plot box: positions are % of it; the gutter at its end holds the value labels */
.cc-track { position: relative; height: 32px; margin-inline-end: 96px; }
.cc-tick { position: absolute; inset-block: 0; inset-inline-start: var(--x); width: 1px; margin-inline-start: -0.5px; background: var(--viz-grid); }
.cc-tick.is-zero { background: var(--line-strong); }
.cc-bar {
  position: absolute; top: 50%; height: 6px; margin-top: -3px; border-radius: 99px;
  inset-inline-start: var(--a); width: calc(var(--b) - var(--a)); background: var(--pc);
  transform-origin: left center; animation: cc-grow 600ms var(--ease-out) both;
}
html[dir="rtl"] .cc-bar { transform-origin: right center; }
.cc-mark {
  position: absolute; top: 50%; margin-top: -6px; inset-inline-start: var(--x); margin-inline-start: -6px;
  animation: cc-fade 300ms 420ms var(--ease-out) both;
}
/* off scale: a slanted gap cuts the bar beyond the axis end */
.cc-cut {
  position: absolute; top: 50%; width: 7px; height: 16px; margin-top: -8px;
  inset-inline-start: var(--x); margin-inline-start: -3.5px;
  background: var(--surface); transform: skewX(-22deg);
}
.cc-val {
  position: absolute; top: 50%; transform: translateY(-50%); inset-inline-start: calc(var(--x) + 13px);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-family: var(--f-num); font-variant-numeric: tabular-nums; font-size: 13.5px; font-weight: 650; color: var(--ink-hi);
  animation: cc-fade 300ms 420ms var(--ease-out) both;
}
.cc-val .unit.pct { font-size: 0.85em; }
.is-na .cc-val { inset-inline-start: 0; color: var(--ink-faint); font-weight: 500; }
.is-na .cc-place { color: var(--ink-dim); }
/* the axis: tick values under the last track */
.cc-axis .cc-track { height: 22px; }
.cc-axis .cc-track > span {
  position: absolute; top: 4px; inset-inline-start: var(--x); transform: translateX(-50%);
  font-size: 11.5px; font-weight: 600; color: var(--ink-faint); white-space: nowrap;
}
html[dir="rtl"] .cc-axis .cc-track > span { transform: translateX(50%); }

@keyframes cc-grow { from { transform: scaleX(0); } to { transform: none; } }
@keyframes cc-fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .cmp-atlas { grid-template-columns: minmax(0, 1fr); }
  .cmp-well { order: -1; min-height: 0; padding: var(--s-4) var(--s-4) var(--s-7); border-inline-start: 0; border-bottom: 1px solid var(--line); }
  .cmp-map svg { max-height: 230px; }
  .cl-hint { margin-top: 0; }
}
@media (max-width: 560px) {
  .cmp-legend { padding: var(--s-4); }
  .cmp-card { padding: var(--s-4); }
  /* names above full-width tracks */
  .cc-row { grid-template-columns: minmax(0, 1fr); }
  .cc-row:not(.cc-axis) .cc-place { margin-top: 6px; }
  .cc-axis .cc-place { display: none; }
  .cc-track { height: 26px; margin-inline-end: 88px; }
  .cmp-key { gap: 6px var(--s-4); }
  .cmp-key li { white-space: normal; }
}
