/* 레이아웃: 좌측 2×2 지표 카드 보드 + 우측 지역 가격변동률 지도 패널 */
:root {
  --bg: #f2f3f6;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --map-bg: #e9eef5;
  --ink: #141a2b;
  --ink-2: #4a5164;
  --muted: #8b91a1;
  --line: #e5e7ed;
  --grid: #eef0f4;
  --bar: #3d4660;
  --bar-dim: #b9bfcc;
  --mom: #ef4f75;
  --avg: #9aa0ad;
  --up: #e3344e;
  --down: #2b68de;
  --accent: #f2304c;
  --accent-ink: #ffffff;
  --chip-max-bg: #fde9ec;
  --chip-max: #d42c47;
  --chip-min-bg: #e7efff;
  --chip-min: #275dd0;
  --pill: #2a3042;
  --pill-ink: #ffffff;
  --warn-bg: #fff4e0;
  --warn: #9a5b00;
  --ok: #138a52;
  --shadow: 0 1px 2px rgba(20, 26, 43, .04), 0 8px 24px rgba(20, 26, 43, .05);
  --font: 'IBM Plex Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', system-ui, sans-serif;
  --radius: 20px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1117; --surface: #161a23; --surface-2: #1c212c; --map-bg: #121925; --ink: #e9ebf1; --ink-2: #b4b9c6;
    --muted: #7d8495; --line: #272c38; --grid: #20252f; --bar: #93a0c2; --bar-dim: #3c4354; --mom: #ff7896; --avg: #6f7686;
    --up: #ff5d71; --down: #5b93ff; --accent: #ff4560; --chip-max-bg: #3a1c24; --chip-max: #ff8a9c; --chip-min-bg: #172742;
    --chip-min: #8cb2ff; --pill: #e9ebf1; --pill-ink: #141a2b; --warn-bg: #3a2a10; --warn: #f2b25c; --ok: #49c88a;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1117; --surface: #161a23; --surface-2: #1c212c; --map-bg: #121925; --ink: #e9ebf1; --ink-2: #b4b9c6;
  --muted: #7d8495; --line: #272c38; --grid: #20252f; --bar: #93a0c2; --bar-dim: #3c4354; --mom: #ff7896; --avg: #6f7686;
  --up: #ff5d71; --down: #5b93ff; --accent: #ff4560; --chip-max-bg: #3a1c24; --chip-max: #ff8a9c; --chip-min-bg: #172742;
  --chip-min: #8cb2ff; --pill: #e9ebf1; --pill-ink: #141a2b; --warn-bg: #3a2a10; --warn: #f2b25c; --ok: #49c88a;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14px; line-height: 1.45; margin: 0; -webkit-font-smoothing: antialiased; }
button, select { font: inherit; color: inherit; }
.num, .tabnum { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--down); outline-offset: 2px; }

.app { max-width: 1680px; margin: 0 auto; padding-block: 16px 32px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: grid; gap: 14px; }

/* 상단 */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand small { font-weight: 500; font-size: 12.5px; color: var(--muted); letter-spacing: 0; }
/* BI (포스코이앤씨) — 다크 모드에서는 흰색으로 */
.brand { align-items: center; }
.bi-link { display: inline-flex; align-items: center; line-height: 0; border-radius: 4px; }
.bi { height: 32px; width: auto; display: block; }
.bi-sep { width: 1px; height: 18px; background: var(--line); margin: 0 2px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bi { filter: brightness(0) invert(1); } }
:root[data-theme="dark"] .bi { filter: brightness(0) invert(1); }
@media (max-width: 520px) { .brand small { display: none; } .bi { height: 28px; } }
.batch { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.batch .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
.batch .dot.warn { background: #e59a1c; }
.batch .dot.bad { background: var(--up); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge.mock { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.prov { background: var(--chip-min-bg); color: var(--chip-min); border-color: transparent; }
.badge.fix { background: var(--surface-2); }
.badge.stale { background: var(--chip-max-bg); color: var(--chip-max); border-color: transparent; }
.note { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 10px 14px; font-size: 13px; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 0.56fr); gap: 16px; align-items: start; }
.board { background: var(--surface); border-radius: 24px; padding: 22px; box-shadow: var(--shadow); min-width: 0; display: grid; gap: 18px; }

/* 컨트롤 */
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.tabs { display: inline-flex; gap: 6px; }
.tabs button { min-width: 92px; height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 15px; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.tabs button:hover:not([aria-selected="true"]) { background: var(--surface-2); }
.select { position: relative; display: inline-flex; }
.select select { appearance: none; height: 46px; min-width: 168px; padding: 0 40px 0 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 15px; font-weight: 500; cursor: pointer; }
.select select:disabled { color: var(--muted); background: var(--surface-2); cursor: not-allowed; }
.select::after { content: ''; position: absolute; right: 16px; top: 50%; width: 8px; height: 8px; border-right: 2px solid var(--ink-2); border-bottom: 2px solid var(--ink-2); transform: translateY(-70%) rotate(45deg); pointer-events: none; }
.scope-note { font-size: 12.5px; color: var(--muted); }
.scope-link { font-weight: 600; color: var(--ink-2); text-decoration: none; }
.scope-link:hover { color: var(--ink); text-decoration: underline; }

/* 카드 */
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 22px 16px; display: grid; gap: 12px; min-width: 0; background: var(--surface); position: relative; }
.card-head { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 18px; font-weight: 700; margin: 0; letter-spacing: -.02em; flex: 1 1 auto; white-space: nowrap; }
.card-head .ctrls { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.card-head .region-tag { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 6px; white-space: nowrap; }
.mini-select select { height: 36px; min-width: 96px; font-size: 13.5px; border-radius: 10px; padding: 0 32px 0 12px; }
.mini-select::after { right: 12px; width: 7px; height: 7px; }
.iconset { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.iconbtn { width: 36px; height: 34px; display: grid; place-items: center; border: 0; background: var(--surface); cursor: pointer; color: var(--muted); }
.iconset .iconbtn + .iconbtn { border-left: 1px solid var(--line); }
.iconbtn[aria-pressed="true"] { color: var(--ink); background: var(--surface-2); }
.iconbtn:hover { color: var(--ink); }
.kebab { border: 0; background: none; width: 30px; height: 34px; border-radius: 8px; cursor: pointer; color: var(--ink); display: grid; place-items: center; }
.kebab:hover { background: var(--surface-2); }
.menu { position: absolute; right: 16px; top: 62px; z-index: 30; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.14); padding: 6px; min-width: 180px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 13.5px; }
.menu button:hover { background: var(--surface-2); }
.info { position: absolute; inset: 60px 14px auto 14px; z-index: 29; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 32px rgba(0,0,0,.14); padding: 14px 16px; font-size: 13px; display: grid; gap: 6px; }
.info dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.info dt { color: var(--muted); }
.info dd { margin: 0; }
.info .close { justify-self: end; border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 12.5px; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 13.5px; color: var(--ink-2); }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.legend .sep { width: 1px; height: 14px; background: var(--line); }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 0; cursor: default; font-size: 13.5px; color: var(--ink-2); }
.chip b { font-weight: 600; font-size: 12.5px; padding: 3px 8px; border-radius: 6px; }
.chip.max b { background: var(--chip-max-bg); color: var(--chip-max); }
.chip.min b { background: var(--chip-min-bg); color: var(--chip-min); }
.chip:hover span { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }

.chart-wrap { position: relative; min-height: 236px; }
.chart-wrap svg { display: block; width: 100%; overflow: visible; }
.chart-wrap svg:focus { outline: none; }
.chart-wrap svg:focus-visible { outline: 2px solid var(--down); outline-offset: 4px; border-radius: 6px; }
.axis text { fill: var(--muted); font-size: 11.5px; font-family: var(--font); }
.axis-title { fill: var(--muted); font-size: 11.5px; }
.empty { display: grid; place-items: center; min-height: 236px; color: var(--muted); font-size: 13.5px; text-align: center; }

.table-wrap { max-height: 252px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.table-wrap th, .table-wrap td { padding: 7px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table-wrap th:first-child, .table-wrap td:first-child { text-align: left; }
.table-wrap thead th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; color: var(--ink-2); }

.card-foot { display: grid; gap: 8px; font-size: 12px; color: var(--muted); }
.card-foot .badges { display: flex; gap: 6px; flex-wrap: wrap; }
.card-foot .foot-line { display: flex; justify-content: space-between; gap: 4px 12px; flex-wrap: wrap; }
.card-foot .left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.card-foot .left::before { content: ''; width: 4px; height: 4px; border-radius: 50%; background: var(--muted); }
.card-foot .right { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.fallback { font-size: 12.5px; color: var(--warn); background: var(--warn-bg); padding: 6px 10px; border-radius: 8px; }

/* 툴팁 */
.tip { position: fixed; z-index: 100; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 14px 40px rgba(14, 18, 30, .18); padding: 12px 14px; width: max-content; max-width: min(320px, calc(100vw - 24px)); font-size: 13px; }
.tip .t-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 2px; }
.tip .t-period { font-weight: 700; font-size: 13.5px; }
.tip .t-sub { color: var(--muted); font-size: 12px; }
.tip .t-value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0 8px; font-variant-numeric: tabular-nums; }
.tip .t-value small { font-size: 13px; font-weight: 500; color: var(--ink-2); margin-left: 3px; }
.tip .t-rows { display: grid; grid-template-columns: auto auto; gap: 4px 16px; font-variant-numeric: tabular-nums; }
.tip .t-rows dt { color: var(--ink-2); }
.tip .t-rows dd { margin: 0; text-align: right; font-weight: 600; }
.tip .t-rows dd .s { display: block; font-weight: 400; font-size: 11.5px; color: var(--muted); }
.tip hr { border: 0; border-top: 1px solid var(--line); margin: 9px 0; }
.tip .up { color: var(--up); }
.tip .down { color: var(--down); }
.tip .t-list { display: grid; gap: 6px; margin-top: 2px; }
.tip .t-list div { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; }
.tip .t-list .m { grid-column: 1; color: var(--muted); font-size: 11.5px; }
.tip .t-label { color: var(--ink-2); margin-bottom: 4px; }

/* 지도 패널 */
.mapPanel { position: sticky; top: max(12px, env(safe-area-inset-top, 0px)); background: var(--map-bg); border-radius: 24px; overflow: hidden; display: grid; grid-template-columns: minmax(0, 1fr); box-shadow: var(--shadow); }
.map-stage { position: relative; height: clamp(560px, 74vh, 760px); }
.map-stage > .summary { position: absolute; left: 16px; top: 16px; z-index: 3; }
.map-stage > .scale { position: absolute; right: 16px; top: 16px; z-index: 3; }
.map-zoom { position: absolute; right: 16px; bottom: 16px; z-index: 3; display: grid; background: var(--surface); border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,.12); overflow: hidden; }
.map-zoom button { width: 40px; height: 38px; border: 0; background: var(--surface); font-size: 20px; cursor: pointer; color: var(--ink); }
.map-zoom button + button { border-top: 1px solid var(--line); }
.map-zoom button.txt { font-size: 12px; font-weight: 600; }
.map-zoom button:hover { background: var(--surface-2); }
.map-credit { position: absolute; left: 12px; bottom: 8px; z-index: 2; font-size: 10.5px; color: var(--muted); pointer-events: none; }
.summary { background: var(--surface); border-radius: 16px; padding: 16px 16px 14px; width: 212px; box-shadow: 0 6px 22px rgba(20, 26, 43, .1); display: grid; gap: 10px; }
.summary h3 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.02em; }
.summary .base { font-size: 11.5px; color: var(--muted); margin-top: -6px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); height: 32px; cursor: pointer; font-size: 13.5px; color: var(--ink-2); }
.seg button[aria-pressed="true"] { outline: 1.5px solid var(--ink); outline-offset: -1.5px; border-radius: 8px; color: var(--ink); font-weight: 600; }
.summary dl { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin: 0; font-size: 13px; }
.summary dt { color: var(--ink-2); }
.summary dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }
.cta { height: 42px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 14px; cursor: pointer; }
.cta:hover { filter: brightness(1.05); }
.scale { background: var(--pill); color: var(--pill-ink); border-radius: 12px; padding: 10px 10px 10px 8px; display: flex; gap: 8px; font-size: 10.5px; font-variant-numeric: tabular-nums; }
.scale .bar { width: 6px; border-radius: 3px; }
.scale .ticks { display: flex; flex-direction: column; justify-content: space-between; }
.map-canvas { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.map-canvas svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.map-hint { position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--surface); border-radius: 8px; padding: 6px 12px; font-size: 12px; color: var(--ink-2); box-shadow: 0 2px 10px rgba(0,0,0,.08); white-space: nowrap; }
.tile { cursor: pointer; }
.tile rect { stroke: var(--map-bg); stroke-width: 3; transition: opacity .15s; }
.tile.sel rect { stroke: var(--ink); stroke-width: 2.5; }
.tile text { pointer-events: none; font-family: var(--font); }
.tile:focus { outline: none; }
.tile:focus-visible rect { stroke: var(--down); stroke-width: 3; }
.geo-path { stroke: var(--surface); stroke-width: .6; stroke-linejoin: round; cursor: pointer; }
.geo-path:hover { filter: brightness(.93); }
.geo-path.sel { filter: brightness(.9); }
.sido-line { stroke: var(--surface); stroke-width: 1; stroke-linejoin: round; }
.sel-line { stroke: var(--ink); stroke-linejoin: round; }
.geo-label { pointer-events: none; font-family: var(--font); }
.pill rect { fill: var(--pill); }
.pill text { font-size: 12px; font-weight: 600; fill: var(--pill-ink); font-variant-numeric: tabular-nums; }
.pill .v.up { fill: #ff6b81; }
.pill .v.down { fill: #6aa0ff; }
.sgg-label { fill: var(--ink); paint-order: stroke; stroke: var(--surface); stroke-linejoin: round; font-weight: 600; }
.sgg-label .v { font-weight: 700; }
.sgg-label .v.up { fill: var(--up); }
.sgg-label .v.down { fill: var(--down); }

.sgg { background: var(--surface); margin: 0 12px 12px; border-radius: 16px; padding: 14px; display: grid; gap: 10px; }
.sgg-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sgg-head h4 { margin: 0; font-size: 14.5px; font-weight: 700; }
.sgg-head span { font-size: 12px; color: var(--muted); }
.sgg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 4px; max-height: 236px; overflow: auto; }
.sgg-cell { border: 0; border-radius: 8px; padding: 7px 8px; text-align: left; cursor: pointer; display: grid; gap: 1px; font-size: 12px; }
.sgg-cell b { font-weight: 600; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sgg-cell span { font-variant-numeric: tabular-nums; }
.sgg-cell.sel { outline: 2px solid var(--ink); outline-offset: -2px; }
.rank { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rank h5 { margin: 0 0 6px; font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.rank ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; counter-reset: r; }
.rank li { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; padding: 5px 6px; border-radius: 6px; cursor: pointer; counter-increment: r; }
.rank li::before { content: counter(r); color: var(--muted); width: 14px; }
.rank li span:first-of-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank li:hover { background: var(--surface-2); }

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--grid), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 12px; min-height: 236px; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } * { transition: none !important; } }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr; }
  .mapPanel { position: relative; top: 0; }
}
@media (max-width: 760px) {
  .cards { grid-template-columns: 1fr; }
  .board { padding: 14px; border-radius: 18px; }
  .card { padding: 16px 14px 12px; }
  .tabs button { min-width: 72px; height: 42px; }
  .select select { min-width: 0; width: 100%; height: 42px; }
  .controls .select { flex: 1 1 140px; }
  .summary { width: 196px; padding: 12px; gap: 8px; }
  .map-stage { height: auto; display: grid; grid-template-columns: minmax(0, 1fr); }
  .map-stage > .summary { position: relative; left: auto; top: auto; width: auto; margin: 12px 12px 0; order: -1; }
  .map-stage > .scale { display: none; } /* 모바일: 지역마다 값이 표시되므로 범례 생략 */
  .map-hint { bottom: auto; top: 8px; }
  .map-canvas { position: relative; inset: auto; height: 540px; }
  .map-stage > .map-zoom { bottom: 36px; }
}

/* 카드 폭이 좁으면 모든 카드가 같은 모양으로 컨트롤을 둘째 줄에 배치 */
.card { container-type: inline-size; }
@container (max-width: 500px) {
  .card-head .ctrls { width: 100%; margin-left: 0; }
  .card-head .ctrls .kebab { margin-left: auto; }
}
.no-survey { margin: -2px 0 10px; line-height: 1.5; font-size: 12px; color: var(--muted); }
