/* compare-districts.css: compare-districts.html (js/compare-districts.js). Class prefix cdx-.
   Colors come from the tokens in css/pages.css (light and dark) plus the few below.
   Wide screens show the table (sticky header row); under 760px the same measures show as stacked cards. */

.cdx-page {
  --cdx-a: #14324F; --cdx-b: #0F6464; --cdx-c: #6B3FA0; --cdx-d: #8A4B00;
  --cdx-hi-bg: #E8F0FB; --cdx-hi: #1F4F8F; --cdx-lo-bg: #F1EEF7; --cdx-lo: #574A73;
  --cdx-fill: #2F6DAA; --cdx-tick: #14324F; --cdx-head: #F5F7FA;
}
[data-theme="dark"] .cdx-page {
  --cdx-a: #9EC5F8; --cdx-b: #7FDCD2; --cdx-c: #CDB3F5; --cdx-d: #F5C76B;
  --cdx-hi-bg: rgba(108,176,240,.16); --cdx-hi: #A9D0F5; --cdx-lo-bg: rgba(190,170,230,.15); --cdx-lo: #D2C4EE;
  --cdx-fill: #6CB0F0; --cdx-tick: #F2B33D; --cdx-head: #172736;
}
.cdx-page .wrap { max-width: 1160px; }
.cdx-page main { padding-bottom: 8px; }
.cdx-h2 { margin: 0 0 12px; font-size: 1.2rem; font-weight: 800; color: var(--ink); }

/* ------------------------------------------------------------ intro + picker */
.cdx-intro { padding: 28px 0 18px; }
.cdx-intro h1 { margin: 4px 0 8px; font-size: 1.85rem; font-weight: 800; }
.cdx-lead { margin: 0; max-width: 760px; color: var(--muted); font-size: 1rem; }

.cdx-picker { display: grid; grid-template-columns: 1fr auto; gap: 12px 20px; align-items: end; margin-bottom: 18px; }
.cdx-picker .cdx-h2 { grid-column: 1 / -1; margin: 0; font-size: 1.05rem; }
.cdx-chips { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.cdx-chips[hidden] { display: none; }
.cdx-chip { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 4px 4px 4px 6px; border: 1px solid var(--border);
  border-radius: 999px; background: var(--surface-2); max-width: 100%; }
.cdx-chip-name { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.cdx-x { display: inline-grid; place-items: center; width: 32px; height: 32px; flex: none; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.cdx-x:hover { background: var(--hover); color: var(--ink); }
.cdx-x svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.cdx-add { min-width: 0; }
.cdx-label { display: block; margin-bottom: 6px; font-size: .86rem; font-weight: 700; color: var(--ink); }
.cdx-combo { position: relative; }
.cdx-combo input { min-height: 46px; }
.cdx-combo input[readonly] { background: var(--surface-2); }
.cdx-list { position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none; max-height: 320px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.cdx-list[hidden] { display: none; }
.cdx-opt { display: flex; flex-direction: column; gap: 1px; min-height: 44px; justify-content: center; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.cdx-opt.is-active, .cdx-opt:hover { background: var(--hover); }
.cdx-opt.is-active { box-shadow: inset 3px 0 0 var(--accent); }
.cdx-opt-name { font-weight: 600; color: var(--ink); }
.cdx-opt-sub { font-size: .8rem; color: var(--muted); }
.cdx-opt-none { padding: 10px; color: var(--muted); }
.cdx-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cdx-actions .btn { min-height: 46px; }

/* letter badges: one color per column */
.cdx-letter { display: inline-grid; place-items: center; width: 26px; height: 26px; flex: none; border-radius: 7px; font-size: .8rem; font-weight: 800;
  color: #fff; background: var(--cdx-a); }
.cdx-letter[data-col="1"] { background: var(--cdx-b); }
.cdx-letter[data-col="2"] { background: var(--cdx-c); }
.cdx-letter[data-col="3"] { background: var(--cdx-d); }
[data-theme="dark"] .cdx-letter { color: #0B1520; }

.cdx-loading { padding: 24px 0; }
.cdx-empty p { margin: 0 0 10px; }
.cdx-quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.cdx-quick .btn { min-height: 44px; white-space: normal; text-align: left; }
.cdx-one { margin: 0 0 12px; }
.cdx-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 12px; font-size: .84rem; color: var(--muted); }

/* ------------------------------------------------------------ values */
.cdx-val { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.cdx-sub { display: block; margin-top: 3px; font-size: .78rem; color: var(--muted); line-height: 1.35; }
.cdx-na, .cdx-wait { color: var(--muted); font-size: .86rem; }
.cdx-wait { font-style: italic; }
.cdx-tag { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: .7rem; font-weight: 700; letter-spacing: .02em; vertical-align: 1px;
  background: var(--cdx-hi-bg); color: var(--cdx-hi); }
.cdx-legend .cdx-tag { margin-left: 0; }
.cdx-tag-lo { background: var(--cdx-lo-bg); color: var(--cdx-lo); }
.cdx-bar { position: relative; display: block; height: 6px; margin-top: 6px; max-width: 180px; border-radius: 3px; background: var(--track); }
.cdx-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; background: var(--cdx-fill); }
.cdx-tick { position: absolute; top: -3px; width: 2px; height: 12px; margin-left: -1px; border-radius: 1px; background: var(--cdx-tick); }
.cdx-msrc { display: block; margin-top: 2px; font-size: .74rem; font-weight: 400; color: var(--muted); }
.cdx-msrc a { color: var(--muted); text-decoration: underline; display: inline-block; min-height: 24px; line-height: 24px; }
.cdx-msrc a:hover { color: var(--accent); }
.cdx-dlinks { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 6px; font-size: .8rem; font-weight: 600; }
.cdx-dlinks a, .cdx-linkbtn { display: inline-flex; align-items: center; min-height: 24px; }
.cdx-linkbtn { padding: 0; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; }
.cdx-linkbtn:hover { color: var(--bad); }
td a, .cdx-card a { overflow-wrap: anywhere; }
td a, .cdx-card-list a { display: inline-block; min-height: 24px; line-height: 24px; }

/* ------------------------------------------------------------ table (wide) */
.cdx-tablewrap { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-sm); }
.cdx-table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.cdx-table th, .cdx-table td { padding: 12px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.cdx-table thead th { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 2px solid var(--border); }
.cdx-table thead th:first-child { border-top-left-radius: 16px; }
.cdx-table thead th:last-child { border-top-right-radius: 16px; }
.cdx-corner { width: 25%; }
.cdx-table .cdx-state { width: 120px; background: var(--cdx-head); color: var(--muted); font-size: .9rem; }
.cdx-table thead .cdx-state { background: var(--cdx-head); font-weight: 700; color: var(--ink); }
.cdx-table td.cdx-state .cdx-val, .cdx-table td.cdx-state { font-weight: 600; }
.cdx-dhead { display: flex; align-items: flex-start; gap: 8px; }
.cdx-dname { font-weight: 800; color: var(--ink); line-height: 1.25; overflow-wrap: anywhere; }
.cdx-grp th { padding: 14px 14px 8px; background: var(--surface-2); font-size: .74rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink); }
.cdx-row th { font-weight: 600; color: var(--ink); }
.cdx-mlabel { display: block; line-height: 1.3; }
.cdx-table td.cdx-hi { background: color-mix(in srgb, var(--cdx-hi-bg) 55%, transparent); }
.cdx-table td.cdx-lo { background: color-mix(in srgb, var(--cdx-lo-bg) 55%, transparent); }
.cdx-table tbody:last-of-type tr:last-child > * { border-bottom: 0; }

/* ------------------------------------------------------------ cards (narrow) */
.cdx-narrow { display: none; }
.cdx-dcards { display: grid; gap: 8px; margin: 0 0 16px; padding: 0; list-style: none; }
.cdx-dcard { display: flex; gap: 10px; align-items: flex-start; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.cdx-dcard-text { min-width: 0; flex: 1; }
.cdx-cgroup { margin: 0 0 18px; }
.cdx-cgroup-h { margin: 0 0 8px; font-size: .78rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink); }
.cdx-card { padding: 14px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-sm); }
.cdx-card-h { margin: 0; font-size: .98rem; font-weight: 700; }
.cdx-card-list { margin: 8px 0 0; padding: 0; list-style: none; }
.cdx-card-list li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 10px; padding: 8px 6px; border-top: 1px solid var(--border); }
.cdx-card-list li.cdx-hi { background: var(--cdx-hi-bg); border-radius: 8px; }
.cdx-card-list li.cdx-lo { background: var(--cdx-lo-bg); border-radius: 8px; }
.cdx-cname { display: flex; gap: 8px; align-items: flex-start; font-size: .86rem; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; min-width: 0; }
.cdx-cname .cdx-letter { width: 22px; height: 22px; font-size: .72rem; border-radius: 6px; }
.cdx-cval { min-width: 0; overflow-wrap: anywhere; }
.cdx-card-state .cdx-cname { color: var(--muted); padding-left: 30px; }
.cdx-card-state .cdx-val { font-weight: 600; color: var(--muted); }

@media (max-width: 759px) {
  .cdx-wide { display: none; }
  .cdx-narrow { display: block; }
  .cdx-picker { grid-template-columns: 1fr; }
  .cdx-actions .btn { flex: 1; }
  .cdx-intro h1 { font-size: 1.5rem; }
  .cdx-page .wrap { padding-left: 16px; padding-right: 16px; }
  .cdx-legend { font-size: .8rem; }
}

/* ------------------------------------------------------------ sources + about */
.cdx-sources { margin-top: 28px; }
.cdx-sources ol { margin: 0; padding-left: 22px; display: grid; gap: 8px; font-size: .86rem; }
.cdx-sources li { overflow-wrap: anywhere; }
.cdx-sources li:target, .cdx-sources li:focus { outline: 2px solid var(--gold); outline-offset: 3px; border-radius: 4px; }
.cdx-src-meta, .cdx-src-note { display: block; color: var(--muted); font-size: .8rem; }
.cdx-src-legal { margin: 12px 0 0; font-size: .8rem; color: var(--muted); }
.cdx-about { margin-top: 28px; }
.cdx-about ul { margin: 0; padding-left: 20px; color: var(--text); font-size: .9rem; display: grid; gap: 6px; }

/* ------------------------------------------------------------ print: always the table, black on white */
@media print {
  .cdx-page { --cdx-head: #F2F2F2; }
  .cdx-wide { display: block !important; }
  .cdx-narrow, .cdx-linkbtn { display: none !important; }
  .cdx-intro { padding: 0 0 8px; }
  .cdx-intro h1 { font-size: 1.3rem; }
  .cdx-lead { font-size: .85rem; }
  .cdx-tablewrap { border: 0; box-shadow: none; border-radius: 0; }
  .cdx-table thead th { position: static; }
  .cdx-table th, .cdx-table td { padding: 6px 8px; font-size: 10pt; }
  .cdx-table tr { break-inside: avoid; }
  .cdx-table thead { display: table-header-group; }
  .cdx-bar, .cdx-letter, .cdx-tag, .cdx-table td.cdx-hi, .cdx-table td.cdx-lo { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .cdx-dlinks a::after { content: none; }
  .cdx-about { break-inside: avoid; }
  .cdx-sources a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 8pt; color: #555; }
}
