/* Layout: one column of cards, max 1100px; tables and charts scroll inside their own boxes. */
:root {
  color-scheme: light;
  --page: #f9f9f7; --surface: #fcfcfb; --ink: #0b0b0b; --ink-2: #52514e; --muted: #6c6a65;
  --grid: #e1e0d9; --axis: #c3c2b7; --border: rgba(11,11,11,0.10); --accent: #2a78d6; --accent-soft: #e3ecf8; --q1: #86b6ef; --q2: #5598e7; --q3: #2a78d6; --q4: #1c5cab; --q5: #0d366b;
  --up: #006300; --down: #b4302f; --hatch: #c3c2b7;
  --f-bev: #1baf7a; --f-phev: #2b9fbf; --f-hev: #2a78d6; --f-petrol: #eda100; --f-diesel: #7a756c; --f-gas: #8b6fd6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #5f6b7a; --s7: #4a3aa7; --s8: #e34948;
  --font: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", sans-serif;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10); --accent: #3987e5; --accent-soft: #1c3048; --q1: #184f95; --q2: #256abf; --q3: #3987e5; --q4: #6da7ec; --q5: #b7d3f6;
  --up: #0ca30c; --down: #e66767; --hatch: #4a4a46;
  --f-bev: #199e70; --f-phev: #36a9c9; --f-hev: #3987e5; --f-petrol: #c98500; --f-diesel: #8f8a80; --f-gas: #9085e9;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #9aa5b4; --s7: #9085e9; --s8: #e66767;
} }
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10); --accent: #3987e5; --accent-soft: #1c3048; --q1: #184f95; --q2: #256abf; --q3: #3987e5; --q4: #6da7ec; --q5: #b7d3f6;
  --up: #0ca30c; --down: #e66767; --hatch: #4a4a46;
  --f-bev: #199e70; --f-phev: #36a9c9; --f-hev: #3987e5; --f-petrol: #c98500; --f-diesel: #8f8a80; --f-gas: #9085e9;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #9aa5b4; --s7: #9085e9; --s8: #e66767;
}
* { box-sizing: border-box; }
html { background: var(--page); }
body { margin: 0; background: var(--page); color: var(--ink); font: 15px/1.6 var(--font); }
.page { max-width: 1100px; margin: 0 auto; padding-inline: 16px; padding-block: 24px 48px; display: grid; gap: 16px; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.3; text-wrap: balance; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; margin-bottom: 6px; color: var(--ink-2); }
.sub { font-weight: 400; color: var(--muted); font-size: .8em; margin-left: 4px; }
.lede { margin: 6px 0 0; color: var(--ink-2); max-width: 68ch; }
.note { margin: 2px 0 0; color: var(--muted); font-size: .85rem; }
.top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: flex-end; }
.top > div { min-width: 0; }
.links { display: flex; gap: 14px; font-size: .9rem; }
.status { color: var(--muted); font-size: .9rem; }
.status.error { color: var(--down); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; display: grid; gap: 2px; }
.tile .label { color: var(--muted); font-size: .8rem; }
.tile .value { font-size: 1.6rem; font-weight: 600; }
.tile .detail { color: var(--ink-2); font-size: .82rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; display: grid; gap: 12px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card-head > div { min-width: 0; }
.chart-box { position: relative; height: 300px; min-width: 0; }
.chart-box.tall { height: 340px; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.two > div { min-width: 0; }
.table-wrap { overflow-x: auto; max-height: 460px; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-size: .87rem; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: .78rem; position: sticky; top: 0; background: var(--surface); }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
td.up { color: var(--up); } td.down { color: var(--down); } td.na { color: var(--muted); }
tr.missing td { color: var(--muted); font-style: italic; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--ink); cursor: pointer; text-align: left; }
.linkbtn:hover, .linkbtn:focus-visible { color: var(--accent); text-decoration: underline; }
.linkbtn[aria-pressed="true"]::after { content: " ✓"; color: var(--accent); }
.field { display: grid; gap: 2px; font-size: .8rem; color: var(--muted); }
select, input[type="search"] { font: inherit; font-size: .9rem; color: var(--ink); background: var(--page); border: 1px solid var(--axis); border-radius: 6px; padding: 5px 8px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--axis); border-radius: 6px; overflow: hidden; }
.seg button { font: inherit; font-size: .85rem; border: 0; background: var(--page); color: var(--ink-2); padding: 5px 10px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: .84rem; background: var(--page); }
.chip i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.chip button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 4px; }
.btn { justify-self: start; font: inherit; font-size: .88rem; border: 1px solid var(--axis); background: var(--page); color: var(--ink); border-radius: 6px; padding: 5px 12px; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
details summary { cursor: pointer; color: var(--ink-2); font-size: .88rem; }
.prose p, .prose ul { margin: 0; }
pre { margin: 0; white-space: pre-wrap; background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: .82rem; overflow-x: auto; }
.foot { color: var(--muted); font-size: .82rem; text-align: center; }
@media (max-width: 520px) { h1 { font-size: 1.35rem; } .chart-box, .chart-box.tall { height: 260px; } }
/* detail pages */
.home-link { color: inherit; text-decoration: none; }
.crumbs { font-size: .85rem; color: var(--muted); }
.page-title { font-size: 1.5rem; }
td.name { display: flex; align-items: center; gap: 6px; }
td.name a { color: var(--ink); text-decoration: none; }
td.name a:hover, td.name a:focus-visible { color: var(--accent); text-decoration: underline; }
.plus { border: 1px solid var(--axis); background: var(--page); color: var(--ink-2); border-radius: 4px; width: 22px; height: 22px; padding: 0; font-size: .8rem; line-height: 1; cursor: pointer; flex: none; }
.plus[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-link { color: var(--ink); text-decoration: none; }
.chip-link:hover { text-decoration: underline; }
a.btn { text-decoration: none; display: inline-block; }
a.btn.disabled { pointer-events: none; opacity: .5; }
table.compare th[scope="row"] { color: var(--ink-2); font-size: .85rem; text-transform: none; white-space: normal; min-width: 130px; }
table.compare td { white-space: normal; min-width: 140px; }
td.best { font-weight: 600; background: var(--accent-soft); }
h3 { margin-top: 4px; }
/* market explorer */
.filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; }
.custom-range { display: inline-flex; gap: 8px; }
.custom-range[hidden] { display: none; }
.chip.toggle { cursor: pointer; font: inherit; font-size: .84rem; color: var(--ink); padding: 3px 10px; }
.chip.toggle[aria-pressed="false"] { opacity: .45; text-decoration: line-through; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.stat { border-left: 3px solid var(--accent); padding: 2px 10px; display: grid; gap: 1px; min-width: 0; }
.stat .label { color: var(--muted); font-size: .78rem; }
.stat .value { font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .detail { color: var(--ink-2); font-size: .8rem; }
.stat .detail.up { color: var(--up); } .stat .detail.down { color: var(--down); }
.map-wrap { position: relative; max-width: 340px; margin: 0 auto; }
.map-wrap svg { width: 100%; height: auto; display: block; }
.prov { stroke: var(--surface); stroke-width: .4; cursor: pointer; }
.prov:hover, .prov:focus-visible { stroke: var(--ink); stroke-width: 1; outline: none; }
.prov.sel { stroke: var(--ink); stroke-width: 1.2; }
.map-tip { position: absolute; z-index: 2; background: var(--surface); border: 1px solid var(--axis); border-radius: 6px; padding: 6px 8px; font-size: .78rem; color: var(--ink); pointer-events: none; max-width: 200px; }
.map-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; justify-content: center; font-size: .75rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.map-legend span { display: inline-flex; align-items: center; gap: 4px; }
.map-legend i { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.map-credit { text-align: center; font-size: .72rem; }
tr.sel-row td { background: var(--accent-soft); }
#regionBox { height: 300px; }
.filters .seg { flex-wrap: wrap; }
.filters .seg button { white-space: nowrap; }
@media (max-width: 520px) { .stats { grid-template-columns: 1fr 1fr; } .stat .value { font-size: 1.1rem; } }
/* home: one filter bar for every section */
.filterbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--page); padding-block: 8px; border-bottom: 1px solid var(--border); }
.filter-echo { color: var(--ink-2); }
.two.wide-left { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; }
td.move { font-size: .8rem; }
td.move.up { color: var(--up); } td.move.down { color: var(--down); }
#rankChart, #hotChart { cursor: pointer; }
@media (max-width: 700px) { .filterbar { position: static; border-bottom: 0; } }
/* grid children must be allowed to shrink, or a wide table pushes the card (and the page) wider */
.card > *, details { min-width: 0; }
/* page tabs */
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: thin; border-bottom: 1px solid var(--border); padding-bottom: 2px; }
.tabs a { white-space: nowrap; text-decoration: none; color: var(--ink-2); padding: 7px 12px; border-radius: 8px 8px 0 0; font-size: .92rem; border-bottom: 2px solid transparent; }
.tabs a:hover { color: var(--ink); background: var(--surface); }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
[data-page][hidden], .filterbar[hidden] { display: none !important; }
/* heatmap tables */
.heatmap td.heat { font-variant-numeric: tabular-nums; color: var(--ink); min-width: 56px; }
.heatmap th[scope="row"] { position: static; text-align: left; color: var(--ink); font-size: .85rem; }
.heat-wrap { max-height: none; }
.prose p { margin: 4px 0; font-size: .88rem; }
.geo-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.filters .share { margin-left: auto; }
@media (max-width: 520px) { .tiles { grid-template-columns: 1fr 1fr; gap: 8px; } .tile .value { font-size: 1.15rem; } .tile { padding: 10px; } }
.lang-switch { display: inline-flex; border: 1px solid var(--axis); border-radius: 6px; overflow: hidden; }
.lang-switch a { padding: 2px 9px; text-decoration: none; color: var(--ink-2); font-size: .82rem; }
.lang-switch a[aria-current="true"] { background: var(--accent); color: #fff; }
.links { align-items: center; }
/* grid rows of the page must be allowed to shrink to the viewport */
.page > * { min-width: 0; }
/* phones: keep the filter bar to a few rows so the first chart is near the top */
@media (max-width: 520px) {
  .filters { gap: 6px 8px; }
  .filters .seg { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; min-width: 0; scrollbar-width: none; }
  .filters .seg::-webkit-scrollbar { display: none; }
  .filters .seg button { padding: 5px 9px; }
  .filters .field { grid-template-columns: auto 1fr; align-items: center; gap: 6px; }
  .filters .share { margin-left: 0; }
  .page { gap: 12px; padding-block: 16px 40px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
/* compare page */
table.compare th[scope="row"], table.compare thead th:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
table.compare thead th:first-child { z-index: 3; }
table.compare thead th { z-index: 2; color: var(--ink); font-size: .85rem; white-space: normal; min-width: 140px; vertical-align: bottom; }
table.compare thead th a { color: var(--ink); text-decoration: none; font-weight: 600; }
table.compare thead th a:hover { text-decoration: underline; }
table.compare tr.group th { position: static; padding-top: 14px; color: var(--ink); font-weight: 600; font-size: .8rem; background: none; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.combo { position: relative; width: min(320px, 100%); }
.combo input { width: 100%; font: inherit; font-size: .9rem; color: var(--ink); background: var(--page); border: 1px solid var(--axis); border-radius: 6px; padding: 5px 10px; }
.combo input:disabled { opacity: .6; }
.combo-list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none; background: var(--surface); border: 1px solid var(--axis); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-height: 320px; overflow-y: auto; }
.combo-list li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: .9rem; }
.combo-list li .sub { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.combo-list li[aria-selected="true"], .combo-list li:hover { background: var(--accent-soft); }
.combo-list li.empty { color: var(--muted); cursor: default; background: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .84rem; color: var(--muted); }
.chip.add { cursor: pointer; font: inherit; font-size: .84rem; color: var(--ink); padding: 3px 10px; }
.chip.add::before { content: "+ "; color: var(--accent); }
.chip-link.quick { border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; background: var(--page); }
@media (max-width: 520px) {
  .combo { width: 100%; }
  table.compare th[scope="row"] { min-width: 96px; max-width: 120px; font-size: .8rem; }
  table.compare thead th, table.compare td { min-width: 96px; font-size: .82rem; }
}
/* filters a page does not use are hidden (the .seg/.chips display rules would otherwise override [hidden]) */
.filters [hidden] { display: none !important; }
.seg[hidden] { display: none !important; }
/* heatmaps: compact cells so a year of months and its total fit without scrolling */
.heatmap td, .heatmap th { padding-inline: 5px; }
.heatmap td.heat { min-width: 44px; }
/* brand origin table: a total row per group */
tr.origin-group td { font-weight: 600; color: var(--ink); background: color-mix(in srgb, var(--grid) 45%, var(--surface)); border-top: 1px solid var(--axis); }
tr.origin-group td.up { color: var(--up); } tr.origin-group td.down { color: var(--down); }
#originBrands td.name .country { color: var(--muted); font-size: .78rem; }
@media (max-width: 520px) {
  #originBrands th:nth-child(4), #originBrands td:nth-child(4) { display: none; }   /* share of group: larger screens only */
  #originBrands th, #originBrands td { padding-inline: 5px; }
  #originBrands th { white-space: normal; vertical-align: bottom; }
  #originBrands td:first-child { white-space: normal; }
  #originBrands td.name { display: table-cell; }
  #originBrands td.name .country { display: block; }
}
