/* 아파트 실거래가 툴 전용 스코프 스타일시트 (글로벌 태그 오염 코드 전면 제거) */

:root {
    --apt-bg-color: #f1f5f9;
    --apt-card-bg: #ffffff;
    --apt-card-hover-bg: #ffffff;
    --apt-border-color: rgba(0, 0, 0, 0.08);
    --apt-border-focus: #2563eb;
    --apt-text-main: #1e293b;
    --apt-text-muted: #64748b;
    --apt-text-dark: #0f172a;
    --apt-primary: #2563eb;
    --apt-primary-gradient: linear-gradient(135deg, #2563eb, #7c3aed);
    --apt-accent: #d97706;
    --apt-danger: #dc2626;
    --apt-success: #059669;
    --apt-selector-title: #1e3a8a;
}

[data-theme="dark"] {
    --apt-bg-color: #080c14;
    --apt-card-bg: #1e293b;
    --apt-card-hover-bg: #2d3748;
    --apt-border-color: rgba(255, 255, 255, 0.08);
    --apt-border-focus: #3b82f6;
    --apt-text-main: #f9fafb;
    --apt-text-muted: #9ca3af;
    --apt-text-dark: #1f2937;
    --apt-primary: #3b82f6;
    --apt-primary-gradient: linear-gradient(135deg, #3b82f6, #8b5cf6);
    --apt-accent: #f59e0b;
    --apt-selector-title: #93c5fd;
    --apt-danger: #ef4444;
    --apt-success: #10b981;
}

/* 아파트 전용 레이아웃 래퍼 (가로폭을 보람에 표준에 매핑) */
.apt-container {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* 뒤로가기 버튼 */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--apt-text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 600;
    transition: color 0.2s ease;
    margin-bottom: 1.5rem;
}
.back-link:hover {
    color: var(--apt-primary);
}

.mobile-only-link {
    display: none;
}

/* 선택 패널 카드 (보람에 표준 admin-card/card 쉐도우 적용) */
.selector-panel {
    background: var(--apt-card-bg);
    border: 1px solid var(--apt-border-color);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.05));
    margin-bottom: 1.5rem;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.selector-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
}

.select-wrapper {
    position: relative;
}
.select-wrapper label {
    display: block;
    font-size: 0.85rem;
    color: var(--apt-text-muted);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

select {
    width: 100%;
    padding: 1rem 1.25rem;
    background: var(--apt-card-bg);
    border: 1px solid var(--apt-border-color);
    border-radius: 10px;
    color: var(--apt-text-main);
    font-size: 1rem;
    font-weight: 500;
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    transition: all 0.2s ease;
}
select:focus {
    border-color: var(--apt-border-focus);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.select-wrapper::after {
    content: "▼";
    font-size: 0.75rem;
    color: var(--apt-text-muted);
    position: absolute;
    right: 1.25rem;
    bottom: 1.2rem;
    pointer-events: none;
}

/* 아파트 검색 결과 리스트 타이틀 */
.list-section-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.list-section-title span {
    color: var(--apt-primary);
}

.apt-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.apt-card {
    background: var(--apt-card-bg);
    border: 1px solid var(--apt-border-color);
    border-radius: 12px;
    padding: 1.25rem 1.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-decoration: none;
    color: var(--apt-text-main);
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    transition: all 0.2s ease;
    cursor: pointer;
}
.apt-card:hover {
    background: var(--apt-card-hover-bg);
    border-color: rgba(37, 99, 235, 0.3);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.apt-info {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.apt-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--apt-text-main);
}
.apt-address {
    font-size: 0.9rem;
    color: var(--apt-text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.apt-address span {
    background: rgba(0, 0, 0, 0.03);
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    font-size: 0.8rem;
}
[data-theme="dark"] .apt-address span {
    background: rgba(255, 255, 255, 0.05);
}

.apt-arrow {
    font-size: 1.3rem;
    color: var(--apt-text-muted);
    transition: transform 0.2s ease;
}
.apt-card:hover .apt-arrow {
    color: var(--apt-primary);
    transform: translateX(4px);
}

.no-data {
    text-align: center;
    padding: 3rem;
    color: var(--apt-text-muted);
    background: rgba(0, 0, 0, 0.01);
    border: 1px dashed var(--apt-border-color);
    border-radius: 12px;
}

/* 상세페이지 Grid */
.detail-grid {
    display: grid;
    grid-template-columns: 1.3fr 0.7fr;
    gap: 2rem;
    align-items: start;
}
.detail-grid > div {
    min-width: 0;
}

.apt-detail-header {
    background: var(--apt-card-bg);
    border: 1px solid var(--apt-border-color);
    border-radius: 16px;
    padding: 2rem;
    margin-bottom: 1.5rem;
}
.apt-detail-header h2 {
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 0.75rem;
}

.specs-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-top: 1.5rem;
    border-top: 1px solid var(--apt-border-color);
    padding-top: 1.5rem;
}
.spec-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.spec-label {
    font-size: 0.85rem;
    color: var(--apt-text-muted);
}
.spec-val {
    font-size: 1.05rem;
    font-weight: 600;
}

/* 통계 요약 카드 */
.stat-summary-card {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.05), rgba(124, 58, 237, 0.05));
    border: 1px solid rgba(37, 99, 235, 0.1);
    border-radius: 16px;
    padding: 1.5rem;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
    margin-bottom: 1.5rem;
    text-align: center;
}
.summary-item {
    display: flex;
    flex-direction: column;
}
.summary-label {
    font-size: 0.8rem;
    color: var(--apt-text-muted);
    margin-bottom: 0.25rem;
}
.summary-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--apt-primary);
}

/* 차트 컨테이너 */
.chart-container {
    background: var(--apt-card-bg);
    border: 1px solid var(--apt-border-color);
    border-radius: 16px;
    padding: 2rem;
    margin-bottom: 1.5rem;
}
.chart-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
}
.bar-chart {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    height: 180px;
    padding-top: 20px;
    border-bottom: 1px solid var(--apt-border-color);
    gap: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.chart-bar-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    height: 100%;
    justify-content: flex-end;
    min-width: 25px;
}
.chart-bar {
    width: 65%;
    max-width: 15px;
    background: var(--apt-primary-gradient);
    border-radius: 4px 4px 0 0;
    min-height: 4px;
    transition: height 0.5s ease;
    position: relative;
}
.chart-bar:hover::after {
    content: attr(data-count);
    position: absolute;
    top: -24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--apt-text-dark);
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
}
.chart-label {
    font-size: 0.65rem;
    color: var(--apt-text-muted);
    margin-top: 0.5rem;
}

/* 실거래 내역 리스트 */
.deals-panel {
    background: var(--apt-card-bg);
    border: 1px solid var(--apt-border-color);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}
.deals-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.deals-panel-header h3 {
    font-size: 1.15rem;
    font-weight: 700;
}

.sort-btn {
    padding: 0.45rem 1rem;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--apt-border-color);
    border-radius: 8px;
    color: var(--apt-text-main);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
}
.sort-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    border-color: var(--apt-primary);
}

.deal-table-wrapper {
    width: 100%;
    max-width: 100%;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.deal-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 500px;
}
.deal-table th {
    background: rgba(0, 0, 0, 0.03);
    font-weight: 600;
    color: var(--apt-text-muted);
    font-size: 0.85rem;
    padding: 0.85rem 1rem;
}
.deal-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--apt-border-color);
    font-size: 0.95rem;
}
.amount-badge {
    font-weight: 700;
    color: var(--apt-accent);
}
.area-badge {
    font-family: monospace;
}

/* 사이드바 추천 목록 */
.sidebar-panel {
    background: var(--apt-card-bg);
    border: 1px solid var(--apt-border-color);
    border-radius: 16px;
    padding: 2rem;
    position: sticky;
    top: 2rem;
}
.sidebar-panel h3 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--apt-border-color);
    padding-bottom: 0.75rem;
}
.recommend-list {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}
.recommend-item {
    display: block;
    text-decoration: none;
    color: var(--apt-text-main);
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--apt-border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s ease;
}
.recommend-item:hover {
    background: var(--apt-card-hover-bg);
    border-color: var(--apt-primary);
    transform: translateX(2px);
}
.recommend-item span {
    display: block;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--apt-text-muted);
    margin-top: 0.25rem;
}

.spinner-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 4rem;
}
.chart-spinner {
    border: 3px solid rgba(0,0,0,0.05);
    width: 35px; height: 35px;
    border-radius: 50%;
    border-left-color: var(--apt-primary);
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 외부 네이버 부동산 버튼 */
.btn-external {
    display: inline-block;
    padding: 0.75rem 1.75rem;
    background: linear-gradient(135deg, #03cf5d, #02b34f);
    color: white;
    text-decoration: none;
    font-weight: 600;
    border-radius: 10px;
    font-size: 0.95rem;
    box-shadow: 0 4px 15px rgba(3, 207, 93, 0.15);
    transition: all 0.2s ease;
}
.btn-external:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(3, 207, 93, 0.3);
    filter: brightness(1.05);
}

.btn-reset {
    padding: 0.4rem 0.8rem;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid var(--apt-border-color);
    border-radius: 8px;
    color: var(--apt-text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-reset:hover {
    background: rgba(239, 68, 68, 0.08);
    border-color: var(--apt-danger);
    color: var(--apt-danger);
}

/* 모바일 반응형 조율 */
@media (max-width: 850px) {
    .selector-panel,
    .deals-panel,
    .chart-container,
    .apt-detail-header,
    .sidebar-panel,
    .stat-summary-card {
        padding: 1.25rem 1rem !important;
    }
    .detail-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    .selector-grid {
        grid-template-columns: 1fr;
        gap: 0.8rem;
    }
    .sidebar-panel {
        position: static;
    }
}
