/* 시장 리포트·공인중개사 도구가 함께 쓰는 스타일. 페이지 전용 스타일은 각 html의 <style>에 둔다. */
  :root {
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --brand-tint: #eff6ff;
    --ink: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --bg: #f8fafc;
    --card: #ffffff;
    --danger: #dc2626;
    --danger-tint: #fef2f2;
    --success: #047857;
    --success-tint: #ecfdf5;
  }
  * { box-sizing: border-box; }
  [hidden] { display: none !important; }
  html, body { background: var(--bg); }
  body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
    color: var(--ink);
    line-height: 1.5;
  }
  a { color: var(--brand); }

  #topbar {
    position: sticky; top: 0; z-index: 10;
    background: var(--card);
    border-bottom: 1px solid var(--border);
  }
  #topbar-inner {
    max-width: 880px; margin: 0 auto; padding: 14px 20px;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
  }
  #brand { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; }
  #brand em { color: var(--brand); font-style: normal; }
  #brand a { display: inline-flex; align-items: center; gap: 8px; }
  #brand .brand-mark { width: 30px; height: 30px; }
  #brand .brand-sub { font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: 0; line-height: 1; }
  @media (max-width: 640px) { #brand .brand-sub { display: none; } }
  #user-info { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); flex-wrap: wrap; row-gap: 6px; }
  #user-info > * { white-space: nowrap; }

  .shell { max-width: 880px; margin: 0 auto; padding: 28px 20px 72px; }

  button {
    font-family: inherit; font-size: 14px; cursor: pointer;
    border-radius: 8px; border: 1px solid transparent; padding: 10px 16px;
  }
  .btn-primary { background: var(--brand); color: #fff; font-weight: 600; }
  .btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
  .btn-primary:disabled { background: #cbd5e1; cursor: default; }
  .btn-secondary { background: #fff; color: var(--ink); border-color: var(--border); }
  .btn-secondary:hover:not(:disabled) { background: #f1f5f9; }
  .btn-secondary:disabled { background: #f8fafc; color: #94a3b8; cursor: default; }
  .btn-ghost { background: transparent; color: var(--muted); border: none; padding: 6px 10px; }
  .btn-ghost:hover { color: var(--ink); }
  select:focus, input:focus {
    outline: none; border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-tint);
  }

  /* 로그인 창: 내보내기·개인 기능을 쓸 때만 뜬다 */
  #auth-view {
    display: none; position: fixed; inset: 0; z-index: 9000; background: rgba(15, 23, 42, 0.55);
    align-items: center; justify-content: center; padding: 20px;
  }
  #auth-view.open { display: flex; }
  .auth-card h2 { margin: 0 0 6px; font-size: 18px; letter-spacing: -0.02em; }
  #auth-reason { margin: 0 0 14px; font-size: 13px; }
  .auth-close { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; }
  .auth-card {
    position: relative; width: 100%; max-width: 360px; margin: 0 auto;
    background: var(--card); border: 1px solid var(--border); border-radius: 14px;
    padding: 24px; box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
  }
  .auth-card .field { margin-bottom: 12px; }
  .auth-card .field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
  .field-help { font-size: 12px; color: var(--muted); margin: 0 0 8px; line-height: 1.5; }
  .auth-actions { display: flex; gap: 8px; margin-top: 4px; }
  .auth-actions button { flex: 1; }
  #auth-status { min-height: 18px; font-size: 13px; color: var(--muted); margin-top: 10px; text-align: center; }

  #app-view { display: block; }
  .step-title {
    display: flex; align-items: center; gap: 8px;
    font-size: 14px; font-weight: 700; color: var(--ink); margin: 0 0 12px;
  }
  .step-num {
    display: inline-flex; align-items: center; justify-content: center;
    width: 20px; height: 20px; border-radius: 999px;
    background: var(--brand); color: #fff; font-size: 11px; font-weight: 700;
  }
  section.step { margin-bottom: 28px; }

  #category-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px;
  }
  .category-card:hover { border-color: #c7d2fe; box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06); }
  .category-card.active {
    border-color: var(--brand); background: var(--brand-tint);
    box-shadow: 0 0 0 3px var(--brand-tint);
  }
  .category-card .icon {
    width: 36px; height: 36px; border-radius: 9px;
    background: #eef2ff; color: var(--brand);
    display: flex; align-items: center; justify-content: center;
  }
  .category-card.active .icon { background: var(--brand); color: #fff; }
  .category-card h3 { font-size: 14px; margin: 0; }
  .category-card p { font-size: 12px; color: var(--muted); margin: 0; line-height: 1.4; }

  #panel {
    background: var(--card); border: 1px solid var(--border); border-radius: 14px;
    padding: 20px; box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
  }
  #panel[hidden] { display: none; }
  .field-label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
  .panel-row { margin-bottom: 16px; }
  .panel-row:last-child { margin-bottom: 0; }
  .generate-row { display: flex; align-items: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }

  #status-line { display: flex; align-items: center; gap: 8px; min-height: 20px; margin-top: 14px; font-size: 13px; color: var(--muted); }
  .progress-bar {
    position: relative; height: 4px; border-radius: 999px; margin-top: 8px;
    background: var(--border); overflow: hidden; display: none;
  }
  .progress-bar.on { display: block; }
  .progress-bar::after {
    content: ''; position: absolute; top: 0; left: -40%; height: 100%; width: 40%;
    border-radius: 999px; background: var(--brand);
    animation: progress-slide 1.1s ease-in-out infinite;
  }
  @keyframes progress-slide {
    0% { left: -40%; }
    100% { left: 100%; }
  }
  #error {
    display: none; margin-top: 12px; padding: 10px 14px;
    background: var(--danger-tint); color: var(--danger); border-radius: 8px; font-size: 13px;
  }
  #error.on { display: block; }

  #result-wrap { margin-top: 24px; }

  .map-modal {
    position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 100; padding: 20px;
  }
  .map-modal-inner {
    background: var(--card); border-radius: 14px; width: 100%; max-width: 1120px;
    display: flex; flex-direction: column; box-shadow: 0 8px 32px rgba(15, 23, 42, 0.2);
  }
  .map-modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 14px;
  }
  .map-status { padding: 8px 18px; font-size: 12px; color: var(--muted); min-height: 16px; }
  .modal-search-row { padding: 12px 18px 0; }
  .modal-search-input {
    width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 13px; box-sizing: border-box; background: #fff;
  }
  .modal-search-input:focus { outline: none; border-color: var(--brand); }
  .table-container { width: 100%; height: 70vh; min-height: 360px; overflow-y: auto; padding: 8px 18px 18px; }

  .table-group { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; overflow: hidden; }
  .table-group summary {
    padding: 10px 12px; cursor: pointer; font-size: 13px; font-weight: 700;
    background: #f8fafc; list-style: none;
  }
  .table-group summary::-webkit-details-marker { display: none; }
  .table-group-row { display: flex; align-items: center; gap: 8px; }
  .table-group-row > span:first-child {
    flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .table-group-arrow::after { content: '▾'; color: var(--muted); font-weight: 400; }
  .table-group[open] .table-group-arrow::after { content: '▴'; }
  .table-group-count {
    font-weight: 400; color: var(--muted); font-size: 12px;
    min-width: 34px; text-align: right; font-variant-numeric: tabular-nums;
  }
  .table-group-status-summary {
    margin-top: 4px; font-size: 11.5px; font-weight: 400; color: var(--muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .table-subgroup { padding: 10px 12px 4px; }
  .table-subgroup-label { font-size: 12px; font-weight: 700; color: var(--brand); margin-bottom: 6px; }
  .table-scroll { overflow-x: auto; margin-bottom: 10px; }
  .data-table { border-collapse: collapse; width: 100%; font-size: 12px; white-space: nowrap; }
  .data-table th, .data-table td { padding: 5px 6px; border-bottom: 1px solid var(--border); text-align: left; }
  .data-table th { background: #fafbfc; color: var(--muted); font-weight: 700; position: sticky; top: 0; white-space: normal; word-break: keep-all; line-height: 1.25; vertical-align: bottom; }
  .data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
  .data-table th.sortable { cursor: pointer; user-select: none; }
  .data-table th.sortable:hover { color: var(--ink); }
  #actions { display: none; gap: 8px; margin-bottom: 12px; }
  #result {
    display: none;
    background: var(--card); border: 1px solid var(--border); border-radius: 14px;
    padding: 22px; box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
    overflow-x: auto;
  }

  .rpt-header { margin-bottom: 18px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
  .rpt-eyebrow { font-size: 12px; font-weight: 700; color: var(--brand); letter-spacing: 0.02em; margin: 0 0 4px; }
  .rpt-title { font-size: 21px; font-weight: 800; color: var(--ink); margin: 0; line-height: 1.35; }
  .rpt-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }

  .rpt-stats { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0; }
  .rpt-stat { flex: 1 1 140px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
  .rpt-stat-label { font-size: 12px; color: var(--muted); margin: 0 0 4px; }
  .rpt-stat-value { font-size: 19px; font-weight: 800; color: var(--ink); margin: 0; font-variant-numeric: tabular-nums; }
  .rpt-up { color: #cc3333; }
  .rpt-down { color: #2b6cb0; }
  .rpt-stat-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

  .rpt-narrative {
    background: var(--brand-tint); border-radius: 10px;
    padding: 14px 16px; font-size: 14px; line-height: 1.7; color: var(--ink); margin: 18px 0;
  }

  .rpt-section { margin-top: 26px; }
  .rpt-section-title {
    font-size: 15px; font-weight: 800; color: var(--ink); margin: 0 0 10px;
    display: flex; align-items: center; gap: 7px;
  }
  .rpt-section-title::before { content: ''; width: 4px; height: 14px; background: var(--brand); border-radius: 2px; }

  .rpt-highlight {
    background: #fff; border: 1px solid var(--border); border-radius: 10px;
    padding: 12px 14px; font-size: 13.5px; line-height: 1.65; margin-bottom: 8px;
  }
  .rpt-highlight b { color: var(--brand); }

  .rpt-table-wrap { overflow-x: auto; }
  .rpt-table { width: 100%; border-collapse: collapse; font-size: 13px; }
  .rpt-table th {
    background: var(--bg); color: var(--muted); font-weight: 700; text-align: left;
    padding: 8px 10px; border-bottom: 2px solid var(--border); white-space: nowrap;
  }
  .rpt-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
  .rpt-table td.num, .rpt-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

  .rpt-source { margin-top: 22px; padding-top: 12px; border-top: 1px dashed var(--border); font-size: 11.5px; color: var(--muted); }

  @media (max-width: 520px) {
    #topbar-inner { align-items: center; gap: 8px; }   /* 한 줄 유지: 로그인·로그아웃 버튼을 로고 오른쪽에 둔다 */
    #whoami-email { display: none; }
    .generate-row { flex-direction: column; align-items: stretch; }
    .generate-row button { width: 100%; }
  }

.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover td { background: var(--brand-tint); }

/* 색으로 구분하는 그룹(예: 시장 활황도 등급) */
.table-group.colored { border-color: var(--gc); }   /* 그룹 색은 얇은 테두리 한 겹과 머리글 배경으로만 나타낸다(왼쪽 세로 선 없음) */
.table-group.colored > summary { background: var(--gbg); }
.table-group.colored > summary .table-group-row > span:first-child { color: var(--gfg); font-weight: 800; }
.temp-legend { flex-basis: 100%; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding-top: 2px; }
.temp-legend i { display: inline-block; width: 180px; max-width: 40vw; height: 10px; border-radius: 6px; background: linear-gradient(90deg, rgb(37,99,235), rgb(56,189,248), rgb(203,213,225), rgb(251,146,60), rgb(220,38,38)); }

/* ---- 가로로 넓은 표: 스크롤 도구, 가장자리 그늘, 이름 열 고정 ---- */
.ts-box { margin-bottom: 10px; }
.ts-tools { display: flex; align-items: center; gap: 8px; padding: 6px 2px 4px; }
.ts-hint { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.ts-btn { width: 26px; height: 24px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: #475569; font-size: 10px; line-height: 1; cursor: pointer; flex: none; }
.ts-btn:hover { border-color: var(--brand); color: var(--brand); }
.ts-top { flex: 1; min-width: 0; overflow-x: auto; overflow-y: hidden; height: 14px; }
.ts-spacer { height: 1px; }
.ts-body { position: relative; }
.ts-body .table-scroll { margin-bottom: 0; }
.table-scroll, .ts-top { scrollbar-width: auto; scrollbar-color: #94a3b8 #e2e8f0; }
.table-scroll::-webkit-scrollbar, .ts-top::-webkit-scrollbar { height: 12px; }
.table-scroll::-webkit-scrollbar-track, .ts-top::-webkit-scrollbar-track { background: #e2e8f0; border-radius: 6px; }
.table-scroll::-webkit-scrollbar-thumb, .ts-top::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 6px; }
.table-scroll::-webkit-scrollbar-thumb:hover, .ts-top::-webkit-scrollbar-thumb:hover { background: #64748b; }
.ts-fade { position: absolute; top: 0; bottom: 12px; width: 26px; pointer-events: none; opacity: 0; transition: opacity .15s; z-index: 6; }
.ts-fade.left { left: 0; background: linear-gradient(to right, rgba(15, 23, 42, .16), transparent); }
.ts-fade.right { right: 0; background: linear-gradient(to left, rgba(15, 23, 42, .22), transparent); }
.ts-box.can-left .ts-fade.left, .ts-box.can-right .ts-fade.right { opacity: 1; }
.table-scroll.has-drag, .ts-box.has-scroll .table-scroll { cursor: grab; }
.table-scroll.dragging { cursor: grabbing; user-select: none; }
.table-scroll.dragging * { cursor: grabbing !important; }

/* 이름 열 고정: 스크롤해도 어느 행인지 보이게 */
.data-table .frz { position: sticky; left: 0; z-index: 2; background: #fff; }
.data-table th.frz { z-index: 5; background: #f1f5f9; }
.data-table tbody tr:nth-child(even) td.frz { background: #fafcff; }
.data-table tbody tr:hover td.frz { background: #f1f5f9; }
.data-table tr.clickable:hover td.frz { background: var(--brand-tint); }
.data-table tr.hl td.frz { background: #fef9c3; }
.ts-box.can-left .data-table .frz { box-shadow: 3px 0 5px -2px rgba(15, 23, 42, .25); }

/* 묶음 안에서 모두 같은 값(자치구·법정동·물건유형)은 표 위에 한 줄로 */
.table-common { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 12px 2px; font-size: 13px; }
.table-common .tc-label { font-size: 11.5px; font-weight: 700; color: var(--muted); }
.table-common b { background: #f1f5f9; border-radius: 999px; padding: 2px 10px; font-weight: 700; color: #334155; }

/* 단지 머리글: 왼쪽에 요약·6개월 합계, 오른쪽에 6개월 거래 건수 그래프 */
.table-group-sub { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: 2px 28px; }
.table-group-sub .tg-left { flex: 0 0 270px; max-width: 100%; display: flex; flex-direction: column; gap: 3px; }
.table-group-sub .tg-left .table-group-status-summary { margin-top: 4px; }
.sp-text { font-size: 12px; font-weight: 700; white-space: nowrap; color: var(--ink); }
svg.spark { flex: 0 0 auto; display: block; overflow: visible; margin-top: 2px; }
svg.spark .sp-ax { font-size: 9.5px; fill: #94a3b8; }

/* 단지 안의 거래 표는 내용 폭만큼만 차지해 열 사이가 벌어지지 않게 한다 */
.table-subgroup .data-table { width: auto; min-width: 360px; }
.table-subgroup .data-table th, .table-subgroup .data-table td { padding: 6px 18px 6px 12px; }
.table-subgroup .data-table th { padding-top: 7px; padding-bottom: 7px; }
@media (max-width: 640px) {
  .table-subgroup .data-table { min-width: 0; }
  .table-subgroup .data-table th, .table-subgroup .data-table td { padding: 6px 7px; }
}
.table-group-sub .tg-label { color: #64748b; font-weight: 700; margin-right: 2px; }
svg.spark .sp-st { font-size: 10.5px; font-weight: 800; }

/* 긴 글 열(사건번호·소재지): 칸 안에서 줄바꿈 */
.data-table td.wrap { white-space: normal; min-width: 110px; max-width: 320px; overflow-wrap: anywhere; line-height: 1.45; }

/* 열이 10개 이상인 표: 칸 여백을 줄여 좌우 스크롤 없이 한 화면에 담는다 */
.table-subgroup .data-table.dense th, .table-subgroup .data-table.dense td, .data-table.dense th, .data-table.dense td { padding-left: 7px; padding-right: 7px; }
