/* ============================================
   mobile.css — 모바일 독립 구현
   body.mobile-layout 클래스 기반 완전 분리
   데스크탑 CSS와 전혀 겹치지 않음
   ============================================ */

/* ── 1. 레이아웃 해체: 데스크탑 구조 무력화 ── */

body.mobile-layout {
    overflow: hidden;
    height: 100dvh;
    height: 100vh; /* fallback */
}

/* 좌측 사이드바 제거 */
body.mobile-layout #left-sidebar {
    display: none !important;
}

/* main 영역 전체화면 */
body.mobile-layout #main-content {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100dvh !important;
    height: 100vh !important;
    overflow: hidden !important;
    position: relative !important;
}

/* ── 2. 헤더: 슬림 고정, 지도 위 반투명 오버레이 ── */

body.mobile-layout #main-header {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 50px !important;
    min-height: 50px !important;
    z-index: 100 !important;
    background: rgba(13, 18, 40, 0.90) !important;
    backdrop-filter: blur(14px) !important;
    -webkit-backdrop-filter: blur(14px) !important;
    border-bottom: 1px solid rgba(169, 199, 255, 0.08) !important;
    padding: 0 12px !important;
}

body.mobile-layout .header-subtitle {
    display: none !important;
}

/* ── 3. 지도: 전체화면 고정 (Layer 1) ── */

body.mobile-layout #map-section {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 1 !important;
    overflow: hidden !important;
}

/* 지도 라벨(선거유형): 칩으로 대체, 숨김 */
body.mobile-layout .map-election-type-label {
    display: none !important;
}

/* 재보궐 안내 노트: 칩 아래 자리 */
body.mobile-layout .map-byelection-note {
    position: fixed !important;
    top: 120px !important;
    left: 12px !important;
    right: 60px !important;
    bottom: auto !important;
    z-index: 28 !important;
    font-size: 0.72rem !important;
}

/* ── 4. 선거유형 칩: 헤더 바로 아래 플로팅 (Layer 3) ── */

body.mobile-layout .mobile-election-chips {
    display: flex !important;
    position: fixed !important;
    top: 50px !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 30 !important;
    padding: 8px 12px 12px !important;
    gap: 6px !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior-x: contain !important;
    scrollbar-width: none !important;
    /* 칩 아래로 지도가 자연스럽게 보이도록 그라디언트 */
    background: linear-gradient(
        to bottom,
        rgba(13, 18, 40, 0.85) 0%,
        rgba(13, 18, 40, 0.60) 70%,
        rgba(13, 18, 40, 0.00) 100%
    ) !important;
    pointer-events: auto;
}

body.mobile-layout .mobile-election-chips::-webkit-scrollbar {
    display: none;
}

body.mobile-layout .mobile-election-chip {
    padding: 5px 11px !important;
    font-size: 0.74rem !important;
    height: 30px !important;
    border-radius: 15px !important;
    flex-shrink: 0 !important;
    box-shadow: 0 1px 6px rgba(0,0,0,0.25) !important;
}

/* ── 5. 지도 컨트롤: 줌 버튼 모바일 제거 (핀치줌으로 대체) ── */

body.mobile-layout .map-zoom-controls {
    display: none !important;
}

/* ── 6. 범례 토글 버튼 & 범례 패널 (Layer 3) ── */

body.mobile-layout .legend-toggle-btn {
    display: flex !important;
    position: fixed !important;
    right: 12px !important;
    bottom: 100px !important;
    z-index: 30 !important;
    width: 36px !important;
    height: 36px !important;
}

body.mobile-layout #map-legend {
    position: fixed !important;
    bottom: 100px !important;
    right: 56px !important;
    left: auto !important;
    top: auto !important;
    max-width: 162px !important;
    z-index: 29 !important;
    display: none !important;
}

body.mobile-layout #map-legend.legend-visible {
    display: block !important;
}

/* ── 7. 브레드크럼: 시도 진입 시만, 칩 아래 (Layer 2) ── */

body.mobile-layout #map-breadcrumb {
    display: none !important;
    position: fixed !important;
    top: 108px !important;
    left: 12px !important;
    bottom: auto !important;
    right: auto !important;
    z-index: 25 !important;
    font-size: 0.7rem !important;
    padding: 3px 8px !important;
}

body.mobile-layout #map-breadcrumb.breadcrumb-in-province {
    display: flex !important;
}

/* ── 8. 백드롭: 바텀 시트 열릴 때 지도 위 반투명 (Layer 4) ── */

body.mobile-layout #bs-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 495;
    background: transparent;
    pointer-events: none;
    transition: background 0.3s ease;
}

body.mobile-layout #bs-backdrop.active {
    background: rgba(0, 0, 0, 0.28);
    pointer-events: auto;
}

/* ── 9. 바텀 시트: 완전 새 구현 (Layer 5) ── */

body.mobile-layout #detail-panel {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    height: 92vh !important;
    max-width: 100% !important;
    width: 100% !important;
    z-index: 500 !important;
    border-radius: 20px 20px 0 0 !important;
    border-top: 1px solid rgba(169, 199, 255, 0.10) !important;
    box-shadow: 0 -4px 32px rgba(0, 0, 0, 0.35) !important;
    background: var(--bg-secondary) !important;
    will-change: transform !important;
    overflow: hidden !important;
    /* 기본: 완전 숨김 */
    transform: translateY(100%) !important;
    transition: none !important;
}

/* 애니메이션 활성화 클래스 */
body.mobile-layout #detail-panel.panel-animating {
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1) !important;
}

/* ── 바텀 시트 4단계 상태 ── */

/* HIDDEN: 완전 아래 */
body.mobile-layout #detail-panel.collapsed {
    transform: translateY(100%) !important;
}

/* PEEK: 130px 노출 — 핸들 + 지역명 + 선거 선택 칩 */
body.mobile-layout #detail-panel.panel-peek {
    transform: translateY(calc(92vh - 130px)) !important;
}

/* HALF: 55vh 노출 */
body.mobile-layout #detail-panel.panel-half {
    transform: translateY(calc(92vh - 55vh)) !important;
}

/* FULL: 전체 열림 */
body.mobile-layout #detail-panel.panel-full {
    transform: translateY(0) !important;
}

/* PEEK 상태: 탭·콘텐츠·웰컴 숨김, peek-chips 표시 */
body.mobile-layout #detail-panel.panel-peek .panel-tabs,
body.mobile-layout #detail-panel.panel-peek .panel-content,
body.mobile-layout #detail-panel.panel-peek #panel-welcome {
    opacity: 0 !important;
    pointer-events: none !important;
    transition: opacity 0.15s !important;
}

body.mobile-layout #detail-panel.panel-peek .peek-election-chips {
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* HALF·FULL 상태: peek-chips 숨김 */
body.mobile-layout #detail-panel.panel-half .peek-election-chips,
body.mobile-layout #detail-panel.panel-full .peek-election-chips {
    opacity: 0 !important;
    pointer-events: none !important;
    height: 0 !important;
    overflow: hidden !important;
}

/* peek-election-chips 기본 스타일 */
body.mobile-layout .peek-election-chips {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    gap: 6px !important;
    padding: 6px 16px 10px !important;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s !important;
    flex-shrink: 0 !important;
}

body.mobile-layout .peek-election-chips::-webkit-scrollbar { display: none; }

body.mobile-layout .peek-chip {
    flex-shrink: 0 !important;
    padding: 5px 12px !important;
    font-size: 0.74rem !important;
    height: 30px !important;
    border-radius: 15px !important;
    border: 1px solid rgba(169, 199, 255, 0.25) !important;
    background: rgba(169, 199, 255, 0.08) !important;
    color: var(--text-secondary) !important;
    cursor: pointer !important;
    white-space: nowrap !important;
    display: flex !important;
    align-items: center !important;
    gap: 5px !important;
    transition: background 0.15s, color 0.15s !important;
}

body.mobile-layout .peek-chip:active,
body.mobile-layout .peek-chip.active {
    background: rgba(169, 199, 255, 0.22) !important;
    color: var(--text-primary) !important;
    border-color: rgba(169, 199, 255, 0.5) !important;
}

/* HALF·FULL 상태: 탭·콘텐츠 표시 */
body.mobile-layout #detail-panel.panel-half .panel-tabs,
body.mobile-layout #detail-panel.panel-half .panel-content,
body.mobile-layout #detail-panel.panel-full .panel-tabs,
body.mobile-layout #detail-panel.panel-full .panel-content {
    opacity: 1 !important;
    pointer-events: auto !important;
    transition: opacity 0.2s 0.08s !important;
}

/* 모바일: 웰컴 화면 제거 (지역 선택 전엔 패널 자체가 없음) */
body.mobile-layout #panel-welcome {
    display: none !important;
}

/* ── 10. 드래그 핸들 ── */

body.mobile-layout .drag-handle {
    display: block !important;
    width: 36px !important;
    height: 4px !important;
    border-radius: 2px !important;
    background: rgba(169, 199, 255, 0.22) !important;
    margin: 12px auto 2px !important;
    cursor: grab !important;
    flex-shrink: 0 !important;
}

/* ── 11. 패널 헤더: PEEK에서도 표시 ── */

body.mobile-layout .panel-header {
    display: flex !important;
    padding: 6px 16px 10px !important;
    min-height: 48px !important;
    flex-shrink: 0 !important;
    cursor: pointer; /* PEEK → HALF 탭 확장 */
}

body.mobile-layout #panel-region-name {
    font-size: 1rem !important;
}

body.mobile-layout .panel-subtitle {
    font-size: 0.78rem !important;
}

/* ── 12. 패널 탭 ── */

body.mobile-layout .panel-tabs {
    display: flex !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    flex-shrink: 0 !important;
    border-bottom: 1px solid var(--border-color) !important;
}

body.mobile-layout .panel-tabs::-webkit-scrollbar { display: none; }

body.mobile-layout .panel-tab {
    flex: 0 0 auto !important;
    padding: 10px 14px !important;
    font-size: 0.78rem !important;
    min-height: 44px !important;
    white-space: nowrap !important;
}

/* ── 13. 패널 콘텐츠 스크롤 ── */

body.mobile-layout .panel-content {
    flex: 1 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior: contain !important;
    padding-bottom: env(safe-area-inset-bottom, 24px) !important;
}

/* ── 14. 미니카드: 바텀 시트 열리기 전 지도 하단 ── */

body.mobile-layout #map-mini-card {
    position: fixed !important;
    bottom: 24px !important;
    left: 12px !important;
    right: 12px !important;
    z-index: 40 !important;
}

/* ── 15. 기타 ── */

/* 리사이즈 핸들: 데스크탑 전용 */
body.mobile-layout .panel-resize-handle {
    display: none !important;
}

/* 선거 배너: 지도 위 상단 고정 */
body.mobile-layout #election-banner {
    position: fixed !important;
    top: 50px !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 95 !important;
}

/* 툴팁: 지도 위 표시 */
body.mobile-layout #map-tooltip {
    z-index: 50 !important;
}

/* ── 라이트 모드 오버라이드 ── */

body.mobile-layout.light-mode #main-header {
    background: rgba(247, 243, 237, 0.94) !important;
    border-bottom: 1px solid rgba(120, 100, 70, 0.14) !important;
}

body.mobile-layout.light-mode .mobile-election-chips {
    background: linear-gradient(
        to bottom,
        rgba(247, 243, 237, 0.92) 0%,
        rgba(247, 243, 237, 0.65) 70%,
        rgba(247, 243, 237, 0.00) 100%
    ) !important;
}

/* peek 칩: 라이트모드 */
body.mobile-layout.light-mode .peek-chip {
    border-color: rgba(92, 80, 64, 0.25) !important;
    background: rgba(92, 80, 64, 0.06) !important;
    color: var(--text-secondary) !important;
}

body.mobile-layout.light-mode .peek-chip:active,
body.mobile-layout.light-mode .peek-chip.active {
    background: rgba(92, 80, 64, 0.14) !important;
    color: var(--text-primary) !important;
    border-color: rgba(92, 80, 64, 0.4) !important;
}

/* 드래그 핸들: 라이트모드 */
body.mobile-layout.light-mode .drag-handle {
    background: rgba(92, 80, 64, 0.25) !important;
}

/* 바텀시트 상단 구분선: 라이트모드 */
body.mobile-layout.light-mode #detail-panel {
    border-top-color: rgba(120, 100, 70, 0.15) !important;
    box-shadow: 0 -4px 32px rgba(80, 60, 30, 0.12) !important;
}

/* 백드롭: 라이트모드 약간 어둡게 */
body.mobile-layout.light-mode #bs-backdrop.active {
    background: rgba(0, 0, 0, 0.18) !important;
}
