/* --- 기본 CSS 변수 및 리셋 --- */
:root {
    --primary-color: #2563eb;
    --accent-color: #10b981;
    --bg-light: #f3f4f6;
    --text-dark: #1f2937;
    --text-gray: #6b7280;
    --white: #ffffff;
    --header-height: 60px;
    --bottom-nav-height: 65px;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { background-color: var(--bg-light); color: var(--text-dark); padding-bottom: var(--bottom-nav-height); }
a { text-decoration: none; color: inherit; }
ul { list-style: none; }

/* --- 헤더 --- */
.header { position: fixed; top: 0; left: 0; width: 100%; height: var(--header-height); background: var(--white); display: flex; align-items: center; justify-content: center; border-bottom: 1px solid #e5e7eb; z-index: 100; }
.header-logo { font-size: 1.2rem; font-weight: 800; color: var(--primary-color); }
.header-logo span { color: var(--accent-color); }
.desktop-nav { display: none; }

/* --- 메인 컨테이너 --- */
.container { max-width: 1024px; margin: 0 auto; padding: 0 16px; margin-top: var(--header-height); }

/* --- [수정됨] 검색 섹션 --- */
.search-hero {
    padding: 30px 0 20px;
    text-align: center;
}

.search-hero h2 {
    font-size: 1.5rem;
    margin-bottom: 24px;
    font-weight: 700;
    line-height: 1.3;
}

/* [핵심] 세로 정렬 컨테이너 (이름 변경됨) */
.search-stack-container {
    display: flex;
    flex-direction: column; /* 무조건 세로 정렬 */
    gap: 12px; /* 요소 사이 간격 */
    width: 100%;
    max-width: 500px; /* 모바일에서 너무 넓어지지 않도록 */
    margin: 0 auto 30px; /* 아래 여백 */
}

/* --- [신규 추가] 아파트명 검색 텍스트 입력창 --- */
.search-input {
    width: 100%;
    height: 54px;
    padding: 0 20px;
    font-size: 1rem;
    color: var(--text-dark);
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    background-color: var(--white);
    transition: border-color 0.2s;
}
.search-input:focus {
    border-color: var(--primary-color);
    outline: none;
}
.search-input::placeholder { color: #9ca3af; }



/* Select 박스 스타일 */
.search-select {
    width: 100%; /* 부모 너비 가득 채움 */
    height: 54px; /* 터치하기 편한 높이 */
    padding: 0 20px;
    font-size: 1rem;
    color: var(--text-dark);
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    background-color: var(--white);

    /* 브라우저 기본 화살표 제거 및 커스텀 */
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232563eb' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 15px center;
    background-size: 16px;
    cursor: pointer;
}

.search-select:focus {
    border-color: var(--primary-color);
    outline: none;
}

/* 검색 버튼 (텍스트 깨짐 방지: 너비 100%) */
.search-btn-large {
    width: 100%;
    height: 54px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px; /* 텍스트와 아이콘 사이 간격 */
}
.search-btn-large:active { transform: scale(0.98); }

/* --- 칩 필터 --- */
.filter-chips-container { overflow-x: auto; white-space: nowrap; padding: 0 0 20px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.filter-chips-container::-webkit-scrollbar { display: none; }
.chip { display: inline-block; padding: 8px 16px; margin-right: 8px; background: var(--white); border: 1px solid #d1d5db; border-radius: 20px; font-size: 0.9rem; color: var(--text-gray); cursor: pointer; transition: all 0.2s; }
.chip.active { background: var(--primary-color); color: var(--white); border-color: var(--primary-color); font-weight: 600; }

/* --- 카드 리스트 --- */
.section-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: end; }
.section-title .sub-text { font-size: 0.9rem; color: var(--text-gray); font-weight: 400; }
.listing-grid { display: grid; grid-template-columns: 1fr; gap: 16px; padding-bottom: 20px; }
.apt-card { background: var(--white); border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1); position: relative; }
.card-image { height: 180px; background-color: #e5e7eb; position: relative; }
.card-image img { width: 100%; height: 100%; object-fit: cover; }
.badge-cheapest { position: absolute; top: 10px; left: 10px; background: var(--accent-color); color: var(--white); padding: 4px 8px; border-radius: 4px; font-size: 0.8rem; font-weight: 700; }
.card-content { padding: 16px; }
.card-price { font-size: 1.4rem; font-weight: 800; color: var(--accent-color); margin-bottom: 4px; }
.card-price .price-type { font-size: 0.9rem; color: var(--text-gray); font-weight: normal;}
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-details { display: flex; gap: 10px; font-size: 0.85rem; color: var(--text-gray); }
.card-details span { position: relative; }
.card-details span:not(:last-child)::after { content: ''; position: absolute; right: -6px; top: 50%; transform: translateY(-50%); width: 1px; height: 10px; background: #d1d5db; }

/* --- 하단 네비게이션 --- */
.bottom-nav { position: fixed; bottom: 0; left: 0; width: 100%; height: var(--bottom-nav-height); background: var(--white); display: flex; justify-content: space-around; align-items: center; border-top: 1px solid #e5e7eb; z-index: 100; }
.nav-item { display: flex; flex-direction: column; align-items: center; font-size: 0.75rem; color: var(--text-gray); padding: 8px; }
.nav-item.active { color: var(--primary-color); }
.nav-icon { font-size: 1.5rem; margin-bottom: 2px; }

/* --- 반응형 (데스크톱) --- */
@media (min-width: 768px) {
    body { padding-bottom: 0; }
    .bottom-nav { display: none; }
    .header { justify-content: space-between; padding: 0 32px; }
    .desktop-nav { display: flex; gap: 24px; }
    .desktop-nav a { font-weight: 600; color: var(--text-gray); transition: color 0.2s; }
    .desktop-nav a:hover, .desktop-nav a.active { color: var(--primary-color); }

    .search-hero h2 { font-size: 2rem; }

    /* 데스크톱에서는 가로로 펴지도록 설정 */
    .search-stack-container {
        flex-direction: row; /* 가로 방향 전환 */
        max-width: 800px;
        gap: 16px;
    }

    /* 데스크톱에서는 검색창과 버튼이 자연스럽게 배치되도록 조정 */
    .search-input { flex: 1; min-width: 200px; }
    .search-select { flex: 1; min-width: 150px; }

    .search-btn-large {
        width: 140px; /* 데스크톱에선 버튼 크기 고정 */
        flex-shrink: 0;
    }

    .listing-grid { grid-template-columns: repeat(3, 1fr); gap: 24px; }
}



/* 더 보기 버튼 스타일 */
.load-more-container {
    text-align: center;
    margin-top: 20px;
    margin-bottom: 40px;
}

.btn-load-more {
    background-color: transparent;
    border: 1px solid #d1d5db;
    color: var(--text-dark);
    padding: 12px 32px;
    border-radius: 50px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-load-more:hover {
    background-color: #f3f4f6;
    /* background-color: #2563  eb; */
    border-color: var(--text-gray);
}

.btn-load-more:active {
    transform: scale(0.96);
}

/* 회전하는 로딩 아이콘 (필요시 사용) */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top: 2px solid var(--text-dark);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    display: none; /* 평소엔 숨김 */
}

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* 페이지네이션 컨테이너 */
.pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px; /* 버튼 사이 간격 */
    margin: 30px 0 50px; /* 위아래 여백 */
}

/* 페이지 버튼 공통 스타일 */
.page-btn {
    min-width: 40px;
    height: 40px;
    padding: 0 6px;
    border: 1px solid #e5e7eb;
    background-color: var(--white);
    color: var(--text-dark);
    border-radius: 8px; /* 약간 둥근 사각형 */
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 마우스 올렸을 때 */
.page-btn:hover:not(.disabled):not(.active) {
    background-color: #eff6ff; /* 아주 연한 파란색 */
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* 현재 선택된 페이지 (Active) */
.page-btn.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: var(--white);
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

/* 비활성화 버튼 (이전/다음 페이지 없을 때) */
.page-btn.disabled {
    background-color: #f9fafb;
    color: #d1d5db;
    border-color: #e5e7eb;
    cursor: not-allowed;
}

/* 모바일 대응: 화면이 좁을 때 일부 숫자 숨기기 */
@media (max-width: 400px) {
    .page-btn.desktop-only {
        display: none;
    }
    .page-btn {
        min-width: 36px; /* 버튼 크기 약간 축소 */
        height: 36px;
        font-size: 0.9rem;
    }
}



/* --- 월별 컨트롤러 컨테이너 (레이아웃) --- */
.month-controls {
    display: flex;
    justify-content: center; /* 중앙 정렬 */
    align-items: center;     /* 수직 중앙 정렬 */
    gap: 10px;               /* 버튼과 박스 사이 간격 */
    margin-top: 10px;        /* (선택사항) 타이틀과의 간격 */
}

/* --- [버튼] 이전/다음 (<, >) 스타일 --- */
/* 원본의 button 스타일을 가져와서 .month-nav-btn에만 적용 */
.month-nav-btn {
    padding: 10px 20px;
    background-color: #2563eb; /* 파란색 배경 */
    color: white;              /* 흰색 글씨 */
    border: none;
    border-radius: 4px;        /* 둥근 모서리 */
    cursor: pointer;
    font-size: 16px;
    font-family: 'Malgun Gothic', sans-serif; /* 폰트 일치 */
}

.month-nav-btn:hover {
    background-color: #2980b9; /* 호버 시 진한 파란색 */
}

/* --- [셀렉트 박스] 월 선택 스타일 --- */
/* 원본의 input/select 공통 스타일과 .month-controls 전용 스타일 병합 */
.month-controls select {
    /* 1. 기본 input 스타일 (원본의 input[type=...], select 부분) */
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    background-color: #fff;
    font-size: 14px; /* 글자 크기 조정 */

    /* 2. month-controls 내부 전용 스타일 (원본 하단 부분) */
    width: auto;      /* 100% 대신 내용물 크기에 맞춤 */
    min-width: 150px; /* 최소 너비 확보 */
}

/* --- [폼 그룹] 감싸는 태그 여백 제거 --- */
.month-controls .form-group {
    margin-bottom: 0; /* 원본의 .form-group 마진 제거 (수직 정렬 유지를 위해) */
}

.popup-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: none;
    justify-content: center;
    align-items: flex-end;
    z-index: 9000;
}


.popup-layer {
    width: 100%;
    max-width: 480px;
    background: #ffffff;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -4px 10px rgba(0,0,0,0.15);
    padding: 20px;
    animation: slideUp 0.25s ease-out;
}


@keyframes slideUp {
    from { transform: translateY(40px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}


.popup-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: #1f2937;
}


.popup-option {
    padding: 14px 10px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.15s;
}


.popup-option:hover {
    background: #f3f4f6;
}


.popup-close-btn {
    margin-top: 16px;
    width: 100%;
    padding: 14px;
    background: #2563eb;
    color: #fff;
    text-align: center;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
}

.listing-grid hr {
    grid-column: 1 / -1; /* 모든 열을 차지하도록 설정 (핵심) */
    border: 0;
    height: 1px;
    background-color: #e5e7eb; /* 선 색상 */
    margin: 10px 0; /* 위아래 여백 */
    width: 100%;
}

@media (max-width: 767px) {
    .hide-on-mobile {
        display: none !important;
    }
}

/* PC 화면(768px 이상)일 때 더보기 버튼 숨김 */
@media (min-width: 768px) {
    .load-more-container {
        display: none !important;
    }
}