:root {
  --accent: #0f4c81;
  --accent-soft: #eef4fa;
  --accent-border: #b6cce4;
  --ink: #141920;
  --ink-2: #36404e;
  --muted: #626d7d;
  --positive: #0d6e4e;
  --positive-soft: #ecf6f2;
  --negative: #b4232c;
  --negative-soft: #fdf0f1;
  --page: #f4f5f7;
  --surface: #ffffff;
  --surface-sub: #f7f8fa;
  --surface-hover: #f1f5f9;
  --line: #dfe3ea;
  --line-strong: #c6cdd8;
  --pct: 4.12%;
  --touch-size: 2.75rem;
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  --tblr-body-bg: var(--page);
  --tblr-body-color: var(--ink);
  --tblr-font-sans-serif: var(--font);
  --tblr-primary: var(--accent);
  --tblr-primary-rgb: 15, 76, 129;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: .84375rem;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ul, dl { margin: 0; }
ul { padding: 0; list-style: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.shell {
  width: min(88rem, calc(100% - 2rem));
  margin-inline: auto;
}

/* Header */
.atlas-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.site-disclaimer {
  color: var(--ink-2);
  font-size: .75rem;
}
.site-disclaimer summary {
  width: fit-content;
  padding-block: .25rem;
  cursor: pointer;
}
.site-disclaimer p {
  max-width: 68ch;
  margin: .25rem 0 .5rem;
  line-height: 1.6;
}
.atlas-header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  min-height: 2.75rem;
}
.atlas-header h1 {
  font-size: 1.0625rem;
  font-weight: 750;
  letter-spacing: -.03em;
  color: var(--ink);
}
.header-meta {
  font-size: .75rem;
  color: var(--muted);
  white-space: nowrap;
}
.meta-num {
  color: var(--muted);
  font-size: .75rem;
  white-space: nowrap;
}

.atlas-main {
  padding-top: .75rem;
  padding-bottom: 1.5rem;
}

/* Query Ribbon */
.query-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem 1.25rem;
  padding: .625rem .875rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 4px 4px 0 0;
}
.query-group {
  display: flex;
  align-items: center;
  gap: .625rem;
}
.area-group {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  row-gap: .375rem;
}
.query-label {
  font-size: .75rem;
  font-weight: 650;
  color: var(--ink-2);
  white-space: nowrap;
  margin: 0;
}
.query-divider {
  width: 1px;
  height: 1.5rem;
  background: var(--line);
}

/* Segmented controls */
.segmented {
  display: inline-flex;
  background: #eceff4;
  padding: 2px;
  border-radius: 4px;
  border: 1px solid var(--line);
  gap: 2px;
}
.area-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(3.625rem, 1fr));
  justify-self: end;
}
.large-area-options {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 600;
  padding: .25rem .625rem;
  border-radius: 3px;
  line-height: 1.3;
  cursor: pointer;
  white-space: nowrap;
  transition: color .12s ease, background .12s ease;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn[aria-pressed=true] {
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(20, 25, 32, .08);
}

/* Budget Controls */
.budget-group { flex: 1 1 auto; min-width: 0; }
.budget-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .75rem;
  flex: 1 1 auto;
  min-width: 0;
}
.budget-field {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  height: 1.875rem;
  padding-inline: .5rem;
  gap: .25rem;
}
.budget-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 76, 129, .14);
}
.budget-field input {
  width: 3.75rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: .875rem;
  font-weight: 700;
  text-align: right;
  padding: 0;
  outline: none;
  appearance: textfield;
}
.budget-field input::-webkit-inner-spin-button,
.budget-field input::-webkit-outer-spin-button { appearance: none; }
.budget-unit {
  font-size: .75rem;
  color: var(--muted);
  white-space: nowrap;
}

.slider-block {
  width: 9.5rem;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.slider-block input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) 0%, var(--accent) var(--pct), #d7dde7 var(--pct), #d7dde7 100%);
  cursor: pointer;
  margin: .375rem 0 .125rem;
}
.slider-block input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  box-shadow: 0 1px 2px rgba(20, 25, 32, .16);
}
.slider-block input[type=range]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  box-shadow: 0 1px 2px rgba(20, 25, 32, .16);
}
.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: .625rem;
  color: var(--muted);
  line-height: 1;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
}
.preset-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-sub);
  color: var(--ink-2);
  font-size: .75rem;
  font-weight: 600;
  height: 1.75rem;
  padding-inline: .5rem;
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
}
.preset-btn:hover {
  border-color: var(--line-strong);
  background: #edf0f5;
}
.preset-btn[aria-pressed=true] {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

/* Unified Workbench */
.workbench {
  display: grid;
  grid-template-columns: 17.5rem minmax(0, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0 0 4px 4px;
  align-items: stretch;
}

/* Left Region Rail */
.region-rail {
  border-right: 1px solid var(--line);
  background: var(--surface-sub);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.rail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .625rem .75rem .5rem;
}
.rail-head h2 {
  font-size: .8125rem;
  font-weight: 700;
  color: var(--ink);
}
.rail-controls {
  display: grid;
  gap: .5rem;
  padding: 0 .75rem .625rem;
  border-bottom: 1px solid var(--line);
}
.rail-controls .provinces {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.ctrl-select {
  appearance: none;
  height: 1.875rem;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23626d7d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right .5rem center;
  color: var(--ink);
  font-size: .78125rem;
  font-weight: 500;
  padding: 0 1.75rem 0 .5625rem;
  min-width: 0;
  max-width: 100%;
  cursor: pointer;
}
.ctrl-select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px rgba(15, 76, 129, .14);
}

.region-toggle,
.region-count-label { display: none; }

.rail-list-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}
.rail-subhead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .4375rem .75rem;
  font-size: .6875rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: #f2f4f7;
}
.clear-link {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: .6875rem;
  font-weight: 650;
  padding: 0;
  cursor: pointer;
}
.clear-link:hover { text-decoration: underline; }

.region-list {
  overflow-y: auto;
  max-height: clamp(22rem, calc(100dvh - 15.5rem), 52rem);
}
.region-list li + li {
  border-top: 1px solid #eceff4;
}
.region-list button {
  display: grid;
  grid-template-columns: 1.75rem minmax(0, 1fr) auto;
  align-items: center;
  gap: .4375rem;
  width: 100%;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  padding: .4375rem .75rem .4375rem .5625rem;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}
.region-list button:hover {
  background: var(--surface-hover);
}
.region-list button[aria-pressed=true] {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}
.region-list button.is-empty {
  opacity: .5;
}
.region-list button.is-empty:hover {
  opacity: .85;
}
.region-list button:focus-visible { outline-offset: -2px; }
.region-name {
  font-size: .78125rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.region-list button[aria-pressed=true] .region-name {
  color: var(--accent);
  font-weight: 700;
}
.region-count {
  color: var(--muted);
  font-size: .71875rem;
  white-space: nowrap;
}

/* Grade Marks */
.grade {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.375rem;
  height: 1.25rem;
  padding-inline: .25rem;
  border-radius: 3px;
  font-size: .6875rem;
  font-weight: 750;
  line-height: 1;
  white-space: nowrap;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
}
.grade-S {
  background: #14284b;
  border-color: #14284b;
  color: #ffffff;
}
.grade-A {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}
.grade-B {
  background: #f2f4f7;
  border-color: #cfd6e0;
  color: #2f3a48;
}
.grade-C {
  background: #ffffff;
  border-color: #dce1e8;
  color: #5b6675;
}
.grade-D {
  background: #ffffff;
  border-color: #e6e9ef;
  color: #7b8492;
}
.grade-missing {
  font-size: .71875rem;
  color: var(--muted);
  white-space: nowrap;
}
#region-list .grade-missing { font-size: .625rem; }

/* Right Results Pane */
.results-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.region-signal-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem 1rem;
  padding: .5rem .875rem;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent-border);
  font-size: .78125rem;
}
.signal-identity {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 700;
  color: var(--ink);
}
.signal-metrics {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .375rem 1rem;
  margin-right: auto;
}
.signal-item {
  display: inline-flex;
  align-items: baseline;
  gap: .3125rem;
}
.signal-item span { color: var(--muted); font-size: .71875rem; }
.signal-item strong { color: var(--ink); font-weight: 700; }
.signal-reset {
  appearance: none;
  border: 1px solid var(--accent-border);
  background: var(--surface);
  color: var(--accent);
  font-size: .71875rem;
  font-weight: 650;
  padding: .1875rem .5rem;
  border-radius: 3px;
  cursor: pointer;
}
.signal-reset:hover { background: #ffffff; border-color: var(--accent); }

.results-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem .75rem;
  padding: .5625rem .875rem;
  border-bottom: 1px solid var(--line);
}
.market-count {
  font-size: .78125rem;
  color: var(--muted);
  white-space: nowrap;
}
.market-count strong {
  color: var(--ink);
  font-size: .9375rem;
  font-weight: 750;
}
.sort-guide-toggle {
  margin-inline-start: auto;
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: .375rem .25rem;
  font-size: .75rem;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}
.sort-guide-toggle::after {
  content: "";
  display: inline-block;
  width: .375rem;
  height: .375rem;
  margin-inline-start: .4375rem;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: translateY(-.125rem) rotate(45deg);
}
.sort-guide-toggle[aria-expanded=true]::after {
  transform: rotate(225deg);
}
.sort-guide {
  flex-basis: 100%;
  padding: .625rem .75rem;
  background: var(--surface-sub);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink-2);
  font-size: .8125rem;
  line-height: 1.55;
}
.sort-guide p + p { margin-top: .375rem; }
.sort-guide-periods { color: var(--muted); }
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-width: 0;
}
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 14.5rem;
}
.search-icon {
  position: absolute;
  left: .5625rem;
  color: var(--muted);
  pointer-events: none;
  display: flex;
}
.search-wrap input {
  width: 100%;
  height: 1.875rem;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font-size: .78125rem;
  padding: 0 1.625rem 0 1.875rem;
}
.search-wrap input::-webkit-search-cancel-button { display: none; }
.search-wrap input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px rgba(15, 76, 129, .14);
}
.search-clear {
  position: absolute;
  right: .3125rem;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 3px;
  cursor: pointer;
}
.search-clear:hover { color: var(--ink); background: #eceff4; }

.toolbar-actions .ctrl-select {
  width: 10.5rem;
}

/* Results Table */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}
.results-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
}
.results-table thead th {
  background: var(--surface-sub);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: .71875rem;
  font-weight: 650;
  padding: .4375rem .75rem;
  white-space: nowrap;
  text-align: left;
}
.results-table thead th:first-child { padding-left: .875rem; }
.results-table thead th:last-child { padding-right: .875rem; }
.results-table thead th.col-center { text-align: center; }
.results-table thead th.col-end { text-align: right; }

.th-sort {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  color: inherit;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .25rem;
}
.th-sort:hover { color: var(--ink); }
.th-sort[data-active=true] { color: var(--accent); font-weight: 700; }
.th-sort[data-active=true]::after { content: "↓"; font-size: .6875rem; }
.th-sort[data-active=true][data-dir=asc]::after { content: "↑"; }

.results-table tbody tr {
  border-bottom: 1px solid #edf0f4;
  cursor: pointer;
  transition: background .08s ease;
}
.results-table tbody tr:hover {
  background: var(--surface-hover);
}
.results-table tbody td {
  padding: .4375rem .75rem;
  vertical-align: middle;
  white-space: nowrap;
}
.results-table tbody td:first-child {
  padding-left: .875rem;
  width: 42%;
  white-space: normal;
}
.results-table tbody td:last-child {
  padding-right: .75rem;
  width: 1.5rem;
  text-align: right;
}
.results-table tbody td.col-center { text-align: center; }
.results-table tbody td.col-end { text-align: right; }

.complex-cell {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.complex-name {
  appearance: none;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-size: .84375rem;
  font-weight: 700;
  line-height: 1.3;
  cursor: pointer;
}
.results-table tbody tr:hover .complex-name,
.complex-name:hover {
  color: var(--accent);
}
.complex-place {
  color: var(--muted);
  font-size: .71875rem;
  line-height: 1.3;
}

.local-grade {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  white-space: nowrap;
}
.rank {
  color: var(--muted);
  font-size: .75rem;
}
.price {
  font-size: .875rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
}
.submetric {
  color: var(--muted);
  font-size: .6875rem;
  line-height: 1.25;
}
.trend {
  font-size: .84375rem;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.25;
}
.trend.plus { color: var(--positive); }
.trend.minus { color: var(--negative); }

.mobile-tag { display: none; }
.row-chevron {
  color: #a0aab8;
  font-size: 1rem;
  line-height: 1;
}
.results-table tbody tr:hover .row-chevron { color: var(--accent); }

.list-state {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
  font-size: .84375rem;
}

/* Pagination */
.page-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  padding: .5625rem .875rem;
  background: var(--surface-sub);
  border-top: 1px solid var(--line);
}
.page-nav {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}
.page-btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: .75rem;
  font-weight: 600;
  height: 1.75rem;
  padding-inline: .625rem;
  border-radius: 3px;
  cursor: pointer;
}
.page-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.page-btn:disabled {
  opacity: .42;
  cursor: default;
}

.atlas-footer {
  color: var(--muted);
  font-size: .71875rem;
  padding-top: .625rem;
}
.footer-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: .25rem 1rem;
}
.footer-meta a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: .15em;
}

/* Detail Dialog */
dialog {
  width: min(46rem, calc(100% - 2rem));
  max-height: 90dvh;
  margin: auto;
  padding: 0;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 18px 48px rgba(15, 23, 36, .18);
  overflow: hidden;
}
dialog[open] {
  display: flex;
  flex-direction: column;
}
dialog::backdrop {
  background: rgba(18, 24, 34, .48);
}
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: .875rem 1.125rem;
  background: var(--surface-sub);
  border-bottom: 1px solid var(--line);
}
.detail-loc {
  font-size: .75rem;
  color: var(--muted);
}
.dialog-head h2 {
  margin-top: .1875rem;
  font-size: 1.125rem;
  font-weight: 750;
  letter-spacing: -.02em;
}
.dialog-close {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 4px;
  font-size: 1.125rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.dialog-close:hover {
  background: #eceff4;
  color: var(--ink);
}
#detail-content {
  padding: 1rem 1.125rem 1.25rem;
  overflow-y: auto;
}

.detail-metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
}
.detail-metrics > div {
  min-width: 0;
  padding: .625rem .75rem;
}
.detail-metrics > div + div {
  border-left: 1px solid var(--line);
}
.detail-kpi-label {
  font-size: .6875rem;
  color: var(--muted);
  margin-bottom: .25rem;
}
.detail-kpi-val {
  font-size: .9375rem;
  font-weight: 700;
  line-height: 1.3;
}
.detail-metrics .submetric {
  margin-top: .1875rem;
}

.detail-section {
  margin-top: 1rem;
}
.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .75rem;
}
.detail-section h3 {
  font-size: .84375rem;
  font-weight: 700;
  color: var(--ink);
}
.chart-readout {
  font-size: .75rem;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}
.chart-wrap {
  border: 1px solid var(--line);
  border-radius: 4px;
  margin-top: .375rem;
  padding: .625rem .75rem .5rem;
  background: var(--surface);
}
.chart {
  display: block;
  width: 100%;
  height: 12rem;
  cursor: crosshair;
  touch-action: pan-y pinch-zoom;
}
.section-sub {
  font-size: .71875rem;
  color: var(--muted);
  margin-top: .125rem;
}
.deals-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: .375rem;
  font-size: .78125rem;
  border: 1px solid var(--line);
}
.deals-table thead th {
  background: var(--surface-sub);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: .71875rem;
  font-weight: 650;
  padding: .375rem .625rem;
  text-align: left;
}
.deals-table thead th.num,
.deals-table tbody td.num {
  text-align: right;
}
.deals-table tbody td {
  padding: .375rem .625rem;
  border-bottom: 1px solid #edf0f4;
}
.deals-table tbody tr:last-child td { border-bottom: 0; }
.monthly-details {
  font-size: .78125rem;
  margin-top: .5rem;
}
.monthly-details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  padding-block: .25rem;
  user-select: none;
}

/* Responsive Breakpoints */
@media (max-width: 68rem) {
  .workbench { grid-template-columns: 15.5rem minmax(0, 1fr); }
  .query-divider { display: none; }
  .query-bar { gap: .5rem 1rem; }
}

@media (max-width: 54rem) {
  .workbench { grid-template-columns: minmax(0, 1fr); }
  .region-rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .rail-head { display: none; }
  .rail-controls {
    display: flex;
    align-items: center;
    padding: .5rem .75rem;
    border-bottom: 0;
    min-width: 0;
  }
  .rail-controls .provinces {
    width: auto;
    flex: none;
  }
  .rail-controls .ctrl-select {
    flex: 1 1 0%;
    min-width: 0;
  }
  .region-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: var(--touch-size);
    padding: .5rem .875rem .5rem .75rem;
    border: 0;
    border-top: 1px solid var(--line);
    background: var(--surface-sub);
    color: var(--ink);
    font-size: .8125rem;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
  }
  .region-toggle::after {
    content: "";
    width: .5rem;
    height: .5rem;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: translateY(-25%) rotate(45deg);
  }
  .region-toggle[aria-expanded=true]::after {
    transform: translateY(25%) rotate(225deg);
  }
  .region-toggle[aria-expanded=false] + .rail-list-wrap,
  #region-ranking-title { display: none; }
  .region-count-label {
    display: inline;
    margin-inline-start: auto;
  }
  .region-list { max-height: min(42dvh, 20rem); }
}

@media (max-width: 44rem) {
  .shell { width: calc(100% - 1rem); }
  .atlas-main { padding-top: .5rem; }
  .query-bar {
    flex-direction: column;
    align-items: stretch;
    gap: .5rem;
    padding: .625rem .75rem;
    min-width: 0;
  }
  .query-group {
    flex-wrap: wrap;
    justify-content: space-between;
    min-width: 0;
  }
  .budget-group {
    flex-direction: column;
    align-items: stretch;
    gap: .375rem;
  }
  .budget-controls {
    gap: .5rem;
    width: 100%;
    min-width: 0;
  }
  .slider-block {
    flex: 1 1 8rem;
    width: auto;
    min-width: 0;
  }
  .presets {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: .25rem;
  }
  .preset-btn {
    padding-inline: .25rem;
    font-size: .71875rem;
    text-align: center;
  }
  .results-toolbar {
    padding: .5rem .75rem;
    gap: .5rem;
  }
  .toolbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .4375rem;
  }
  .search-wrap { width: 100%; min-width: 0; }
  .toolbar-actions .ctrl-select { width: auto; min-width: 8.5rem; }
}

@media (max-width: 54rem) {
  .table-wrap { overflow-x: visible; }
  .results-table, .results-table tbody { display: block; width: 100%; }
  .results-table thead, .results-table thead tr {
    display: block;
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .results-table tbody tr {
    display: grid;
    grid-template-columns: minmax(3.5rem, 1fr) repeat(2, minmax(0, 1fr)) minmax(4.25rem, 1fr);
    grid-template-rows: auto auto auto;
    gap: .375rem .625rem;
    padding: .625rem .75rem;
    align-items: center;
    width: 100%;
  }
  .results-table tbody td {
    padding: 0 !important;
    border: 0;
    min-width: 0;
    white-space: nowrap;
  }
  .results-table tbody td:nth-child(1) {
    grid-column: 1 / 4;
    grid-row: 1;
    width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .results-table tbody td:nth-child(4) {
    grid-column: 4 / 5;
    grid-row: 1;
    text-align: right !important;
    align-self: start;
  }
  .results-table tbody td:nth-child(2) {
    grid-column: 1 / 2;
    grid-row: 2;
    text-align: left !important;
  }
  .results-table tbody td:nth-child(3) {
    grid-column: 2 / 5;
    grid-row: 2;
    white-space: normal;
  }
  .results-table .local-grade {
    flex-wrap: wrap;
    max-width: 100%;
    gap: .125rem .375rem;
    white-space: normal;
  }
  .results-table tbody td:nth-child(5) {
    grid-column: 1 / 3;
    grid-row: 3;
    text-align: left;
  }
  .results-table tbody td:nth-child(6) {
    grid-column: 3 / 5;
    grid-row: 3;
  }
  .results-table tbody td:nth-child(7) {
    display: none;
  }
  .mobile-tag {
    display: inline;
    color: var(--muted);
    font-size: .6875rem;
    margin-right: .25rem;
  }
  .results-table tbody .col-end .submetric {
    margin-top: .125rem;
  }
}

@media (max-width: 38rem) {
  dialog {
    width: calc(100% - 1rem);
    max-height: 92dvh;
  }
  .detail-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .detail-metrics > div:nth-child(3) { grid-column: 1 / -1; }
  .detail-metrics > div:is(:nth-child(3), :nth-child(4)) { border-left: 0; }
  .detail-metrics > div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .chart-head {
    flex-wrap: wrap;
    gap: .25rem .75rem;
  }
  .deals-table :is(th, td) { padding-inline: .375rem; }
}

@media (max-width: 54rem), (pointer: coarse) {
  .site-disclaimer summary,
  .seg-btn,
  .preset-btn,
  .budget-field input,
  .ctrl-select,
  .clear-link,
  .region-list button,
  .signal-reset,
  .search-wrap input,
  .search-clear,
  .sort-guide-toggle,
  .page-btn,
  .dialog-close,
  .monthly-details summary {
    min-height: var(--touch-size);
  }
  .seg-btn,
  .preset-btn,
  .clear-link,
  .page-btn,
  .dialog-close,
  .search-clear {
    min-width: var(--touch-size);
  }
  .site-disclaimer summary,
  .monthly-details summary { padding-block: .75rem; }
  .budget-field { height: auto; }
  .budget-field input,
  .search-wrap input { font-size: 1rem; }
  .slider-block input[type=range] {
    height: var(--touch-size);
    margin: 0;
    background-size: 100% 4px;
    background-position: center;
    background-repeat: no-repeat;
  }
  .slider-block input[type=range]::-webkit-slider-thumb {
    width: 1.25rem;
    height: 1.25rem;
  }
  .slider-block input[type=range]::-moz-range-thumb {
    width: 1.25rem;
    height: 1.25rem;
  }
  .search-wrap input:placeholder-shown { padding-inline-end: .5rem; }
  .search-wrap input:not(:placeholder-shown) { padding-inline-end: var(--touch-size); }
  .search-clear { right: 0; }
}
