/**
 * 모바일 반응형 스타일
 * 버전: 1.0.0
 * 
 * 브레이크포인트:
 * - 태블릿: 768px ~ 1024px
 * - 모바일: 768px 이하
 */

/* ========================================
   CSS 변수 (모바일)
   ======================================== */
:root {
    --mobile-nav-height: 60px;
    --mobile-header-height: 50px;
    --bottom-sheet-radius: 20px;
    --touch-target-min: 44px;
}

/* ========================================
   태블릿 (768px ~ 1024px)
   ======================================== */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 300px;
    }
    
    .left-sidebar {
        width: var(--sidebar-width) !important;
    }
}

/* ========================================
   모바일 (768px 이하)
   ======================================== */
@media (max-width: 768px) {
    /* 기본 레이아웃 */
    body {
        overflow-x: hidden;
    }
    
    /* ========================================
       사이드바 숨김 → 바텀시트로 대체
       ======================================== */
    .left-sidebar {
        display: none !important;
    }
    
    /* 지도 전체 화면 */
    #map {
        position: fixed !important;
        top: var(--mobile-header-height) !important;
        left: 0 !important;
        right: 0 !important;
        bottom: var(--mobile-nav-height) !important;
        width: 100% !important;
        height: calc(100vh - var(--mobile-header-height) - var(--mobile-nav-height)) !important;
        z-index: 1 !important;
    }
    
    /* ========================================
       모바일 헤더 (통합 다크 테마)
       ======================================== */
    .mobile-header {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 50px;
        background: rgba(40, 40, 40, 0.95);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        color: white;
        align-items: center;
        justify-content: space-between;
        padding: 0;
        z-index: 10000;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    }
    
    .mobile-header-logo {
        font-size: 18px;
        font-weight: 700;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .mobile-header-actions {
        display: flex;
        gap: 8px;
    }
    
    .mobile-header-btn {
        background: rgba(255, 255, 255, 0.15);
        border: none;
        color: white;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        font-size: 18px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .mobile-header-btn:active {
        background: rgba(255, 255, 255, 0.25);
    }
    
    /* ========================================
       모바일 하단 네비게이션
       ======================================== */
    .mobile-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--mobile-nav-height);
        background: white;
        border-top: 1px solid #e5e7eb;
        z-index: 1000;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }
    
    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        color: #64748b;
        text-decoration: none;
        font-size: 11px;
        padding: 8px 4px;
        transition: color 0.2s;
        cursor: pointer;
        border: none;
        background: none;
    }
    
    .mobile-nav-item.active,
    .mobile-nav-item:active {
        color: #3b82f6;
    }
    
    .mobile-nav-icon {
        font-size: 22px;
    }
    
    .mobile-nav-badge {
        position: absolute;
        top: 6px;
        right: calc(50% - 18px);
        background: #ef4444;
        color: white;
        font-size: 10px;
        min-width: 16px;
        height: 16px;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 600;
    }
    
    /* ========================================
       모바일 검색바 (상단 - 숨김 처리, 하단 검색 탭 사용)
       ======================================== */
    .mobile-search-bar {
        display: none !important; /* 하단 검색 탭으로 대체 */
    }
    
    .mobile-search-input {
        width: 100%;
        height: 48px;
        padding: 0 48px 0 16px;
        border: none;
        border-radius: 24px;
        background: white;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
        font-size: 15px;
        outline: none;
    }
    
    .mobile-search-input:focus {
        box-shadow: 0 2px 16px rgba(59, 130, 246, 0.3);
    }
    
    .mobile-search-btn {
        position: absolute;
        right: 4px;
        top: 4px;
        width: 40px;
        height: 40px;
        border: none;
        border-radius: 50%;
        background: linear-gradient(135deg, #3b82f6, #2563eb);
        color: white;
        font-size: 18px;
        cursor: pointer;
    }
    
    /* ========================================
       바텀시트 (청약 정보, 상세 분석)
       ======================================== */
    .mobile-bottom-sheet {
        position: fixed;
        left: 0;
        right: 0;
        bottom: var(--mobile-nav-height);
        background: white;
        border-radius: var(--bottom-sheet-radius) var(--bottom-sheet-radius) 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        z-index: 500;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        max-height: 70vh;
        overflow: hidden;
    }
    
    .mobile-bottom-sheet.active {
        transform: translateY(0);
    }
    
    .mobile-bottom-sheet.expanded {
        max-height: calc(100vh - var(--mobile-header-height) - var(--mobile-nav-height));
    }
    
    .bottom-sheet-handle {
        width: 40px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
        margin: 12px auto;
    }
    
    .bottom-sheet-header {
        padding: 0 20px 16px;
        border-bottom: 1px solid #f1f5f9;
    }
    
    .bottom-sheet-title {
        font-size: 18px;
        font-weight: 700;
        color: #1e293b;
        margin: 0;
    }
    
    .bottom-sheet-subtitle {
        font-size: 13px;
        color: #64748b;
        margin-top: 4px;
    }
    
    .bottom-sheet-content {
        padding: 16px 20px;
        overflow-y: auto;
        max-height: calc(70vh - 80px);
        -webkit-overflow-scrolling: touch;
    }
    
    .bottom-sheet-close {
        position: absolute;
        top: 16px;
        right: 16px;
        width: 32px;
        height: 32px;
        border: none;
        border-radius: 50%;
        background: #f1f5f9;
        color: #64748b;
        font-size: 18px;
        cursor: pointer;
    }
    
    /* ========================================
       모바일 카드 스타일
       ======================================== */
    .mobile-card {
        background: white;
        border-radius: 16px;
        padding: 16px;
        margin-bottom: 12px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }
    
    .mobile-card-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 12px;
    }
    
    .mobile-card-title {
        font-size: 16px;
        font-weight: 600;
        color: #1e293b;
    }
    
    .mobile-card-badge {
        padding: 4px 10px;
        border-radius: 12px;
        font-size: 12px;
        font-weight: 600;
    }
    
    .mobile-card-badge.ongoing {
        background: #dcfce7;
        color: #16a34a;
    }
    
    .mobile-card-badge.upcoming {
        background: #fef3c7;
        color: #d97706;
    }
    
    .mobile-card-info {
        display: flex;
        flex-direction: column;
        gap: 8px;
        font-size: 14px;
        color: #64748b;
    }
    
    .mobile-card-info-row {
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .mobile-card-actions {
        display: flex;
        gap: 8px;
        margin-top: 16px;
    }
    
    .mobile-card-btn {
        flex: 1;
        height: 44px;
        border: none;
        border-radius: 12px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
    }
    
    .mobile-card-btn.primary {
        background: linear-gradient(135deg, #3b82f6, #2563eb);
        color: white;
    }
    
    .mobile-card-btn.secondary {
        background: #f1f5f9;
        color: #475569;
    }
    
    /* ========================================
       필터 버튼 (지역/유형 선택)
       ======================================== */
    .mobile-filter-btn {
        padding: 10px 16px;
        border: 1px solid #e5e7eb;
        border-radius: 20px;
        background: white;
        color: #374151;
        font-size: 13px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s;
        white-space: nowrap;
    }
    
    .mobile-filter-btn:hover,
    .mobile-filter-btn:active {
        background: #3b82f6;
        color: white;
        border-color: #3b82f6;
        transform: scale(1.02);
    }
    
    .mobile-filter-btn.active {
        background: #3b82f6;
        color: white;
        border-color: #3b82f6;
    }
    
    /* ========================================
       분석 메뉴 버튼
       ======================================== */
    .mobile-analysis-btn {
        display: flex;
        align-items: center;
        gap: 14px;
        padding: 16px 18px;
        border: none;
        border-radius: 16px;
        color: white;
        cursor: pointer;
        transition: all 0.2s;
        text-align: left;
        width: 100%;
    }
    
    .mobile-analysis-btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    .mobile-analysis-btn-icon {
        font-size: 28px;
        flex-shrink: 0;
    }
    
    .mobile-analysis-btn-content {
        flex: 1;
    }
    
    .mobile-analysis-btn-title {
        font-size: 16px;
        font-weight: 700;
        margin-bottom: 4px;
    }
    
    .mobile-analysis-btn-desc {
        font-size: 12px;
        opacity: 0.85;
    }
    
    /* ========================================
       지도 컨트롤 버튼 (모바일 최적화)
       ======================================== */
    .map-controls {
        position: fixed;
        right: 10px;
        bottom: calc(var(--mobile-nav-height) + 20px);
        display: flex;
        flex-direction: column;
        gap: 8px;
        z-index: 500;
    }
    
    .map-control-btn {
        width: 48px;
        height: 48px;
        border: none;
        border-radius: 50%;
        background: white;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        font-size: 20px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .map-control-btn:active {
        background: #f1f5f9;
    }
    
    .map-control-btn.primary {
        background: linear-gradient(135deg, #3b82f6, #2563eb);
        color: white;
    }
    
    /* ========================================
       기존 UI 숨김/조정
       ======================================== */
    /* 데스크톱 전용 요소 숨김 */
    .desktop-only,
    .sidebar-toggle-btn,
    .navbar:not(.mobile-header) {
        display: none !important;
    }
    
    /* 기존 사이드바 위젯들 숨김 */
    .sidebar-ai-widget,
    .sidebar-compare-widget,
    .sidebar-favorite-widget {
        display: none !important;
    }
    
    /* ✅ 왼쪽 사이드바 전체 숨김 */
    .left-sidebar,
    #left-sidebar,
    #sidebar,
    .sidebar:not(.mobile-bottom-sheet),
    .sidebar-container,
    .sidebar-wrapper,
    .main-container > .sidebar {
        display: none !important;
        width: 0 !important;
        min-width: 0 !important;
        max-width: 0 !important;
        visibility: hidden !important;
        position: absolute !important;
        left: -9999px !important;
    }
    
    /* ✅ 필터 패널 숨김 (지도 위 필터 버튼들) */
    .filter-panel,
    .filter-container,
    .subscription-filter,
    .map-filter-panel,
    #filter-panel,
    [class*="filter-panel"],
    .dropdown-menu.show,
    #subscriptionMapContainer > div[style*="position: absolute"][style*="top: 10px"] {
        display: none !important;
        visibility: hidden !important;
    }
    
    /* ✅ 상단 네비게이션/헤더 숨김 (모바일 헤더로 대체) */
    .navbar,
    .top-navbar,
    header:not(.mobile-header),
    nav:not(.mobile-nav):not(.mobile-bottom-sheet) {
        display: none !important;
    }
    
    /* ✅ 플로팅 버튼들 숨김 */
    .floating-btn,
    .float-button,
    .quick-menu,
    .sidebar-toggle,
    .mobile-toggle,
    #mobileToggle {
        display: none !important;
    }
    
    /* ✅ 메인 컨테이너 전체 화면 */
    .main-container {
        display: block !important;
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    /* ✅ 지도 컨테이너 전체 화면 */
    .naver-frame-container,
    #subscriptionMapContainer {
        position: fixed !important;
        top: var(--mobile-header-height) !important;
        left: 0 !important;
        right: 0 !important;
        bottom: var(--mobile-nav-height) !important;
        width: 100% !important;
        height: calc(100vh - var(--mobile-header-height) - var(--mobile-nav-height)) !important;
        z-index: 1 !important;
    }
    
    #kakaoMap {
        width: 100% !important;
        height: 100% !important;
    }
    
    /* ✅ 지도 위 범례/필터 숨김 */
    #kakaoMap + div,
    #subscriptionMapContainer > div:not(#kakaoMap):not(.map-controls):not(.mobile-search-bar),
    .marker-legend,
    #propertyTagsLegend {
        display: none !important;
    }
    
    /* 인포윈도우 모바일 최적화 */
    .subscription-infowindow {
        max-width: calc(100vw - 40px) !important;
        font-size: 14px !important;
    }
    
    /* 모달 모바일 최적화 */
    .modal-dialog {
        margin: 10px;
        max-width: calc(100vw - 20px);
    }
    
    .modal-content {
        border-radius: 16px;
    }
    
    /* 비교 모달 */
    #compare-modal-overlay .compare-modal {
        width: 95vw !important;
        max-width: none !important;
        margin: 10px;
        max-height: 90vh;
    }
    
    #compare-modal-overlay .compare-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* AI 상세 모달 */
    #ai-detail-modal > div {
        width: 95vw !important;
        max-width: none !important;
        margin: 10px;
    }
    
    /* 슬라이드 패널 전체 화면 */
    .slide-panel {
        width: 100vw !important;
    }
    
    /* ========================================
       터치 친화적 UI
       ======================================== */
    /* 모든 버튼 최소 터치 영역 */
    button, 
    .btn,
    [role="button"],
    a.nav-link {
        min-height: var(--touch-target-min);
        min-width: var(--touch-target-min);
    }
    
    /* 체크박스, 라디오 버튼 확대 */
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px;
        height: 24px;
    }
    
    /* 입력 필드 */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important; /* iOS 줌 방지 */
        min-height: 48px;
        padding: 12px 16px;
    }
    
    /* ========================================
       스크롤 최적화
       ======================================== */
    .scroll-container {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    
    /* 스크롤바 숨김 (모바일) */
    ::-webkit-scrollbar {
        width: 0;
        height: 0;
    }
}

/* ========================================
   모바일 전용 컴포넌트 (데스크톱에서 숨김)
   ======================================== */
@media (min-width: 769px) {
    .mobile-header,
    .mobile-nav,
    .mobile-search-bar,
    .mobile-bottom-sheet,
    .map-controls {
        display: none !important;
    }
}

/* 모바일에서 표시 */
@media (max-width: 768px) {
    .mobile-header {
        display: flex !important;
    }
    
    .mobile-nav {
        display: flex !important;
    }
    
    .mobile-search-bar {
        display: block !important;
    }
    
    .map-controls {
        display: flex !important;
    }
}

/* ========================================
   Safe Area (노치 대응)
   ======================================== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .mobile-nav {
            padding-bottom: env(safe-area-inset-bottom);
            height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
        }
        
        #map {
            bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom)) !important;
        }
        
        .mobile-bottom-sheet {
            bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
        }
    }
}

/* ========================================
   가로 모드 (Landscape)
   ======================================== */
@media (max-width: 768px) and (orientation: landscape) {
    :root {
        --mobile-nav-height: 50px;
        --mobile-header-height: 48px;
    }
    
    .mobile-bottom-sheet {
        max-height: 60vh;
    }
}

/* ========================================
   페이지 전환 버튼 (청약/매물/상권)
   ======================================== */
@media (max-width: 768px) {
    .page-switch-container {
        position: fixed;
        top: 100px;
        left: 10px;
        display: flex;
        flex-direction: column;
        gap: 8px;
        z-index: 9998;
    }
    
    .page-switch-btn {
        padding: 8px 14px;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        border: none;
        border-radius: 20px;
        font-size: 12px;
        font-weight: 600;
        box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
        cursor: pointer;
        transition: all 0.2s;
        text-decoration: none;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        min-width: 70px;
    }
    
    .page-switch-btn:active {
        transform: scale(0.95);
        box-shadow: 0 1px 4px rgba(102, 126, 234, 0.3);
    }
}

/* 데스크톱에서 숨김 */
@media (min-width: 769px) {
    .page-switch-container {
        display: none !important;
    }
}

/* ========================================
   다크모드 지원
   ======================================== */
@media (max-width: 768px) and (prefers-color-scheme: dark) {
    .mobile-nav {
        background: #1e293b;
        border-top-color: #334155;
    }
    
    .mobile-nav-item {
        color: #94a3b8;
    }
    
    .mobile-nav-item.active {
        color: #60a5fa;
    }
    
    .mobile-bottom-sheet {
        background: #1e293b;
    }
    
    .bottom-sheet-title {
        color: #f1f5f9;
    }
    
    .mobile-search-input {
        background: #334155;
        color: #f1f5f9;
    }
    
    .mobile-card {
        background: #334155;
    }
    
    .mobile-card-title {
        color: #f1f5f9;
    }
}
