/* ─── KPI Grid ──────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.kpi-label { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 24px; font-weight: 800; color: var(--text-main); line-height: 1.1; }
.kpi-sub { font-size: 12px; color: var(--text-faint); margin-top: 4px; }
.kpi-card.highlight { border-left: 4px solid var(--danger); }

/* ─── Insight Grid ──────────────────────────────────── */
.insight-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.insight-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.insight-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.insight-card-title { font-size: 13px; font-weight: 700; color: var(--text-main); margin-bottom: 14px; }

/* ─── Insight Card Header ────────────────────────────── */
.insight-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }

/* ─── Insight Card Full (동별 없을 때 전체 폭) ──────── */
.insight-card-full { grid-column: 1 / -1; }

/* ─── Insight Divider ────────────────────────────────── */
.insight-divider { border: none; border-top: 1px solid var(--border); margin: 16px 0 14px; }

/* ─── Card Pagination ────────────────────────────────── */
.card-pagination {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pagination-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 14px;
    transition: all 0.2s;
    padding: 0;
}

.pagination-btn:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.pagination-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.pagination-info {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-main);
    min-width: 40px;
    text-align: center;
}

/* 6개월 추이 */
.trend-chart { display: flex; align-items: flex-end; gap: 6px; height: 90px; margin-bottom: 4px; }
.trend-bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; height: 100%; justify-content: flex-end; }
.trend-bar-num { font-size: 12px; font-weight: 700; color: var(--text-muted); line-height: 1; }
.trend-bar-group:last-child .trend-bar-num { color: var(--primary); }
.trend-bar { width: 100%; border-radius: 3px 3px 0 0; background: #93c5fd; min-height: 4px; }
.trend-bar-group:last-child .trend-bar { background: var(--primary); }
.trend-label { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.trend-summary { font-size: 12px; color: var(--text-muted); padding-top: 8px; }
.trend-summary strong { color: var(--text-main); }

/* 면적대 */
.area-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 12px; }
.area-row:last-child { margin-bottom: 0; }
.area-label { width: 100px; color: var(--text-muted); font-weight: 600; flex-shrink: 0; white-space: nowrap; }
.area-meta { flex-shrink: 0; text-align: right; font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.area-meta strong { color: var(--text-main); font-weight: 700; }
.area-stack-wrap { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.area-stack-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; margin-bottom: 8px; }
.area-stack-legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 11px; color: var(--text-muted); }
.area-stack-legend span { display: flex; align-items: center; gap: 4px; }
.area-stack-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

/* 지역별 스택 바 */
.dong-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 12px; }
.dong-row:last-child { margin-bottom: 0; }
.dong-name { font-weight: 700; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dong-name a { max-width: 100%; display: block; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.dong-name-link { color: var(--primary); text-decoration: none; }
.dong-name-link:hover { text-decoration: underline; }
.dong-bottom { display: flex; align-items: center; gap: 8px; }
.dong-stack-track { flex: 1; height: 10px; border-radius: 9999px; overflow: hidden; display: flex; background: var(--bg); border: 1px solid var(--border); }
.dong-stack-up { background: #fca5a5; height: 100%; }
.dong-stack-down { background: #60a5fa; height: 100%; }
.dong-stack-other { background: #cbd5e1; height: 100%; }
.dong-meta { flex-shrink: 0; text-align: right; font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.dong-meta strong { color: var(--text-main); font-weight: 700; }
.legend { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-faint); display: flex; gap: 12px; }
.legend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; vertical-align: middle; margin-right: 3px; }

/* ─── Apt Filter ────────────────────────────────────── */
.apt-filter-link { color: var(--primary); text-decoration: none; cursor: pointer; }
.apt-filter-link:hover { text-decoration: underline; }
.apt-filter-active { display: flex; align-items: center; gap: 8px; padding: 8px 14px; margin-bottom: 12px; background: var(--primary-light); border: 1px solid var(--primary); border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--primary); }
.apt-filter-clear { margin-left: auto; font-size: 12px; color: var(--text-muted); text-decoration: underline; cursor: pointer; }

/* ─── Filter Bar ────────────────────────────────────── */
.filter-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 18px; margin-bottom: 20px; }
.filter-select { font-size: 13px; font-weight: 600; color: var(--text-muted); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; background: var(--surface); cursor: pointer; font-family: 'Pretendard', -apple-system, sans-serif; }
.filter-select:focus { outline: none; border-color: var(--primary); }
.filter-checkbox { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--text-muted); margin-left: auto; cursor: pointer; }
.filter-checkbox input { cursor: pointer; accent-color: var(--primary); }
.filter-divider { width: 1px; height: 20px; background: var(--border); }

/* ─── Trade Table ───────────────────────────────────── */
.trade-table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.trade-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.trade-table th { text-align: left; padding: 12px; color: var(--text-muted); font-weight: 600; border-bottom: 2px solid var(--border); white-space: nowrap; font-size: 12px; }
.trade-table th.r { text-align: right; } .trade-table th.c { text-align: center; }
.trade-table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.trade-table tr:last-child td { border-bottom: none; }
.trade-table tr:hover td { background: var(--bg); }
.trade-table td.r { text-align: right; } .trade-table td.c { text-align: center; }
.trade-table td.seq { color: var(--text-faint); font-weight: 700; text-align: center; width: 32px; }
.trade-table td.date { color: var(--text-faint); font-weight: 700; font-size: 12px; white-space: nowrap; text-align: center; }
.trade-table td.apt { font-weight: 700; max-width: 180px; overflow: hidden; }
.apt-cell { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.apt-cell .apt-filter-link { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.apt-count { font-size: 11px; font-weight: 600; color: var(--primary); background: var(--primary-light); border-radius: 4px; padding: 1px 5px; white-space: nowrap; flex-shrink: 0; }
.trade-table td.dong { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.trade-table td.area { white-space: nowrap; font-size: 12px; }
.trade-table td.area .pyeong { color: var(--text-faint); }
.trade-table td.floor { text-align: center; }
.trade-table td.price { text-align: right; font-weight: 800; font-size: 14px; white-space: nowrap; }
.trade-table td.pyeong-price { text-align: right; font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.trade-table td.change { text-align: right; font-size: 12px; font-weight: 600; white-space: nowrap; }
.trade-table td.age { text-align: center; font-size: 12px; color: var(--text-muted); }

/* 행 스타일 */
.trade-table tr.row-new-high td:first-child { box-shadow: inset 3px 0 0 #DC2626; }
.trade-table tr.row-cancelled td { opacity: 0.55; }
.trade-table tr.row-cancelled td.price { text-decoration: line-through; }

/* ─── Badge ─────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-new-high  { background: #FDE8E8; color: #DC2626; }
.badge-up        { background: #FEF3C7; color: #D97706; }
.badge-flat      { background: #F3F4F6; color: #6B7280; }
.badge-down      { background: #DBEAFE; color: #2563EB; }
.badge-first     { background: #E0E7FF; color: #4F46E5; }
.badge-cancelled { background: #FEE2E2; color: #991B1B; }

/* 변동 색상 */
.change-up   { color: #DC2626; }
.change-down { color: #2563EB; }
.change-flat { color: var(--text-faint); }

/* ─── Load More ─────────────────────────────────────── */
.load-more-wrap { margin-top: 24px; text-align: center; }
.load-more-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; max-width: 480px; padding: 14px 24px;
  border-radius: 10px; border: 1px dashed var(--border);
  background: var(--surface); color: var(--text-muted);
  font-size: 14px; font-weight: 700; cursor: pointer;
  font-family: 'Pretendard', -apple-system, sans-serif;
  transition: all 0.15s;
}
.load-more-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.load-more-btn .spinner { display: none; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.6s linear infinite; }
.load-more-btn.loading .spinner { display: inline-block; }
.load-more-btn.loading .btn-text { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.load-more-done { font-size: 13px; color: var(--text-faint); padding: 16px 0; text-align: center; border-top: 1px solid var(--border); margin-top: 20px; }

/* ─── Bottom Nav ────────────────────────────────────── */
.bottom-nav { margin-top: 36px; display: flex; flex-direction: column; gap: 16px; }
.back-link { font-size: 14px; font-weight: 600; color: var(--primary); text-decoration: none; cursor: pointer; }
.back-link:hover { text-decoration: underline; }
.month-nav { display: flex; justify-content: space-between; align-items: center; }
.month-link { font-size: 13px; font-weight: 600; color: var(--text-muted); text-decoration: none; padding: 8px 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; }
.month-link:hover { border-color: var(--primary); color: var(--primary); }
.month-current { font-size: 14px; font-weight: 700; }
.month-select  { font-size: 14px; font-weight: 700; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer; }

/* ─── Responsive ────────────────────────────────────── */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .insight-grid, .insight-grid.cols-2 { grid-template-columns: 1fr; }
  .insight-grid > :last-child { grid-column: span 1; }
  .filter-bar { gap: 8px; }
  .filter-checkbox { margin-left: 0; }

  /* 테이블 → 카드 전환 */
  .trade-table-wrap { background: none; border: none; border-radius: 0; overflow: visible; }
  .trade-table, .trade-table thead, .trade-table tbody, .trade-table th, .trade-table tr { display: block; }
  .trade-table thead { display: none; }
  .trade-table tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    margin-bottom: 12px; padding: 16px; display: flex; flex-wrap: wrap; gap: 4px 0;
    position: relative;
  }
  .trade-table tr:hover { background: var(--surface); }
  .trade-table tr.row-new-high { border-left: 3px solid #DC2626; }
  .trade-table tr.row-new-high td:first-child { box-shadow: none; }
  .trade-table td { border: none; padding: 0; }

  .trade-table td.seq { display: none; }
  .trade-table td.apt { order: 1; width: auto; max-width: none; flex: 1; font-size: 14px; }
  .trade-table td.dong { order: 2; width: auto; margin-left: 6px; }
  .trade-table td.dong::before { content: "· "; }
  .trade-table td.status { order: 3; margin-left: auto; }
  .trade-table td.price { order: 4; width: 100%; text-align: left; font-size: 18px; margin-top: 8px; }
  .trade-table td.change { order: 5; width: 100%; text-align: left; font-size: 13px; }
  .trade-table td.area { order: 6; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
  .trade-table td.floor { order: 7; text-align: left; }
  .trade-table td.floor::before { content: "· "; color: var(--text-faint); }
  .trade-table td.age { order: 8; text-align: left; }
  .trade-table td.age::before { content: "· "; color: var(--text-faint); }
  .trade-table td.pyeong-price { order: 9; margin-left: auto; }
  .trade-table td.pyeong-price::before { content: "평당 "; }
  .trade-table td.date { order: 10; margin-left: 12px; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 20px; }
}
