/* ==========================================================================
   CarLink Main Stylesheet (Full Version)
   - Layout & Reset
   - Sidebar & Search (PC/Mobile)
   - Hero Card (Compact & Animation)
   - Detail Modal (Graph & Table)
   - My Page & Navigation Modal
   ========================================================================== */

/* === [1] Root Variables & Reset (기본 설정) === */
:root {
    --bg-color: #F7F8FA;
    --sidebar-bg: #FFFFFF;
    --primary: #191F28;        /* 메인 텍스트 (다크네이비) */
    --text-sub: #8B95A1;       /* 서브 텍스트 (회색) */
    --accent: #4C6EF5;         /* 강조색 (파랑) */
    --border: #E5E8EB;         /* 테두리 */
    --hover-bg: #F2F4F6;       /* 호버/배경 */
    --input-bg: #F9FAFB;
    --primary-btn: #191F28;
    --shadow: 0 4px 20px rgba(0,0,0,0.08);
    
    /* 아이폰 노치 대응 (Safe Area) */
    --safe-bottom: env(safe-area-inset-bottom, 20px);
    --safe-top: env(safe-area-inset-top, 20px);
}

[data-theme="dark"] {
    --bg-color: #000000;
    --sidebar-bg: #1C1C1E;
    --primary: #F2F2F7;
    --text-sub: #98989D;
    --accent: #0A84FF;
    --border: #2C2C2E;
    --hover-bg: #2C2C2E;
    --input-bg: #1C1C1E;
    --primary-btn: #3A3A3C;
    --shadow: 0 4px 20px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: "Pretendard", -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--primary);
    height: 100vh;
    height: 100dvh; /* 모바일 브라우저 주소창 대응 */
    overflow: hidden; 
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; }

/* 베타 태그 스타일 */
.beta-tag {
    font-size: 10px; color: #fff; background: #FF3B30;
    padding: 2px 5px; border-radius: 4px; vertical-align: middle; margin-left: 4px; font-weight: 700;
}

/* 전체 레이아웃 컨테이너 */
.layout-container { 
    display: flex; 
    width: 100%; 
    height: 100%; 
    overflow: hidden; 
    position: relative; 
}


/* === [2] Mobile UI Layer (상단 검색창) === */
.mobile-ui-layer {
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    z-index: 50; /* 지도 바로 위에 위치 */
    pointer-events: none; /* 터치는 지도로 통과 */
    display: flex; 
    flex-direction: column;
}

/* 플로팅 검색바 */
.mobile-floating-search {
    margin: 0 20px; 
    margin-top: calc(20px + var(--safe-top));
    background: var(--sidebar-bg); 
    border-radius: 12px;
    padding: 12px 16px; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    display: flex; 
    align-items: center; 
    pointer-events: auto; /* 검색창은 터치 가능해야 함 */
    border: 1px solid var(--border); 
    cursor: pointer;
}
.placeholder-text { 
    color: var(--text-sub); 
    font-size: 14px; 
    margin-left: 8px; 
}


/* === [3] Sidebar & List (PC: Sidebar, Mobile: Bottom Sheet) === */
.sidebar {
    width: 400px;
    background: var(--sidebar-bg);
    display: flex; 
    flex-direction: column;
    z-index: 1000;
    position: relative;
    transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1), width 0.3s ease;
    flex-shrink: 0;
}

.mobile-handle-area { display: none; } /* PC에선 숨김 */

.sidebar-header { 
    padding: 24px 24px 10px 24px; 
    display: flex; 
    justify-content: space-between; 
    align-items: flex-start; 
}
.brand-info h1 { 
    font-size: 22px; font-weight: 800; margin-bottom: 4px; color: var(--accent); letter-spacing: -0.5px; 
}
.brand-info .desc { font-size: 12px; color: var(--text-sub); }

.sidebar-close-btn {
    background: var(--hover-bg); border: none; border-radius: 50%;
    width: 32px; height: 32px; font-size: 16px; color: var(--text-sub);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    z-index: 10;
}

/* 검색 입력창 (사이드바 내부) */
.search-container { padding: 0 24px 16px; }
.search-box { 
    display: flex; align-items: center; background: var(--input-bg); 
    border: 1px solid transparent; border-radius: 12px; padding: 0 12px; 
    position: relative; height: 48px; transition: border 0.2s; 
}
.search-box:focus-within { border-color: var(--accent); background: var(--sidebar-bg); }
.search-icon-svg { width: 20px; height: 20px; color: var(--text-sub); margin-right: 8px; flex-shrink: 0; }
.search-box input { 
    flex: 1; border: none; outline: none; font-size: 15px; 
    background: transparent; color: var(--primary); 
    height: 100%; width: 100%; 
}

/* 검색창 X 버튼 (입력 시 등장) */
.clear-btn { 
    background: #C4C8D0; border: none; border-radius: 50%; width: 20px; height: 20px; 
    display: flex; align-items: center; justify-content: center; cursor: pointer; color: #fff; 
    font-size: 14px; font-weight: 700; margin-left: 8px; 
    visibility: hidden; opacity: 0; 
    transition: all 0.2s; flex-shrink: 0;
}
.clear-btn.visible { visibility: visible; opacity: 1; }
.search-box button#search-btn { display: none; } /* 실제 검색 버튼은 숨김 (엔터키 사용) */

/* 필터 영역 (가로 스크롤) */
.filter-wrapper { 
    padding: 0 24px; border-bottom: 1px solid var(--border); margin-bottom: 8px; 
    position: relative; z-index: 50; 
}
.filter-toggle-btn { display: none; } /* 예전 토글 버튼 숨김 */

.filter-scroll-area {
    display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px;
    -webkit-overflow-scrolling: touch; /* 부드러운 스크롤 */
    scrollbar-width: none; /* 스크롤바 숨김 */
}
.filter-scroll-area::-webkit-scrollbar { display: none; }

.filter-btn { 
    background: var(--hover-bg); border: none; padding: 8px 16px; border-radius: 20px; 
    font-size: 13px; font-weight: 500; cursor: pointer; color: var(--text-sub); 
    flex-shrink: 0; white-space: nowrap; transition: all 0.2s;
}
.filter-btn.active { 
    background: var(--primary); color: #fff; font-weight: 700; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.2); 
}

/* 매장 리스트 스타일 */
.place-list { flex: 1; overflow-y: auto; background: var(--sidebar-bg); padding: 0 24px; }
.empty-message { padding: 60px 20px; text-align: center; color: var(--text-sub); font-size: 14px; line-height: 1.5; }

.shop-card {
    display: flex; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--border);
    cursor: pointer; position: relative; transition: background 0.2s;
}
.shop-card:hover { background: rgba(0,0,0,0.02); }
.shop-card-thumb {
    width: 80px; height: 80px; border-radius: 12px;
    background-color: var(--hover-bg); background-size: cover; background-position: center;
    flex-shrink: 0; border: 1px solid rgba(0,0,0,0.05);
}
.shop-card-info { flex: 1; display: flex; flex-direction: column; justify-content: space-between; }
.shop-name { font-size: 16px; font-weight: 700; color: var(--primary); margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.shop-dist { font-size: 12px; color: var(--accent); font-weight: 600; }
.shop-meta { font-size: 13px; color: var(--text-sub); margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.star-rate { color: #FFD700; font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 2px; }
.shop-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag-chip { font-size: 11px; padding: 3px 6px; border-radius: 4px; background: var(--hover-bg); color: var(--text-sub); font-weight: 500; }
.tag-chip.hot { background: #FFF5F5; color: #FA5252; }
.tag-chip.open { background: #E6FCF5; color: #0CA678; }

.load-more-btn { 
    display: block; width: calc(100% - 48px); margin: 10px 24px; padding: 12px; 
    background: var(--hover-bg); border: none; border-radius: 12px; color: var(--primary); 
    font-weight: 600; cursor: pointer; text-align: center; 
}
.load-more-btn.hidden { display: none; }

.sidebar-footer { 
    padding: 16px 24px; border-top: 1px solid var(--border); background: var(--sidebar-bg); 
    display: flex; flex-direction: column; gap: 8px; 
}
.sidebar-footer a, .report-link { 
    text-decoration: none; font-size: 12px; color: var(--text-sub); display: block; 
    text-align: center; padding: 12px; border-radius: 12px; background: var(--hover-bg); font-weight: 500; 
}

/* 지도 컨테이너 */
.map-container { flex: 1; position: relative; z-index: 1; overflow: hidden; min-width: 0; }
#map { width: 100%; height: 100%; }


/* === [4] Hero Card (Compact Design) === */
.overlay-card {
    background: #fff;
    width: 100% !important; margin: 0 !important; left: 0 !important; bottom: 0 !important;
    border-radius: 24px 24px 0 0 !important;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.15);
    position: fixed; overflow: hidden; display: flex; flex-direction: column;
    z-index: 10001; /* 사이드바(10000)보다 위에 */
    animation: slideUp 0.3s ease-out;
    height: auto !important; max-height: 85vh; padding-bottom: var(--safe-bottom);
}

.card-hero {
    height: 120px; flex-shrink: 0; /* 높이 120px로 축소 */
    border-radius: 24px 24px 0 0; position: relative;
    background-color: #333; background-size: cover; background-position: center;
}
.close-btn {
    position: absolute; top: 12px; right: 12px;
    background: rgba(0,0,0,0.5); border: none; width: 28px; height: 28px; border-radius: 50%;
    color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 20;
}

/* 즐겨찾기 별표 버튼 */
.btn-fav { 
    position: absolute; bottom: 12px; right: 12px; 
    width: 36px; height: 36px; border-radius: 50%; 
    background: rgba(255,255,255,0.9); border: none; 
    display: flex; align-items: center; justify-content: center; 
    cursor: pointer; z-index: 20; box-shadow: 0 2px 8px rgba(0,0,0,0.1); 
    font-size: 18px; color: #ccc; transition: all 0.2s; 
}
.btn-fav.active { color: #FFD700; background: #fff; transform: scale(1.1); }

.card-body { padding: 16px 20px; overflow-y: auto; background: #fff; padding-bottom: calc(20px + var(--safe-bottom)); }

.hero-header { display: flex; align-items: center; margin-bottom: 8px; }
.place-title { font-size: 18px; font-weight: 800; color: #111; margin: 0; display: flex; align-items: center; gap: 8px; }
.type-badge { font-size: 11px; background: #E8F5FE; color: #1C7ED6; padding: 2px 5px; border-radius: 4px; font-weight: 600; }

/* 혼잡도 배지 */
.hero-congestion-badge { 
    position: absolute; bottom: 12px; left: 12px; 
    display: flex; align-items: center; gap: 6px; 
    padding: 4px 10px; border-radius: 20px; 
    background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(4px); 
    box-shadow: 0 2px 8px rgba(0,0,0,0.2); 
    font-size: 11px; font-weight: 600; color: #FFFFFF; z-index: 10; pointer-events: none; 
}
.hero-congestion-badge .status-dot { width: 8px; height: 8px; border-radius: 50%; display: block; box-shadow: 0 0 6px rgba(0,0,0,0.5); }
.hero-congestion-badge.green .status-dot { background-color: #4CAF50; }
.hero-congestion-badge.yellow .status-dot { background-color: #FFC107; }
.hero-congestion-badge.red .status-dot { background-color: #FF5252; }

/* 전광판 (Marquee) */
.hero-notice-box {
    background: #FFF5F5; border: 1px solid #FFE3E3; border-radius: 8px;
    padding: 8px 10px; display: flex; align-items: center; gap: 8px; margin-bottom: 10px; overflow: hidden;
}
.notice-icon { flex-shrink: 0; font-size: 13px; }
.marquee-wrapper {
    flex: 1; overflow: hidden; white-space: nowrap; position: relative;
    mask-image: linear-gradient(to right, transparent, black 5%, black 95%, transparent);
    -webkit-mask-image: linear-gradient(to right, transparent, black 5%, black 95%, transparent);
}
.marquee-text {
    display: inline-block; padding-left: 100%;
    animation: marquee 12s linear infinite; font-size: 12px; color: #FA5252; font-weight: 600;
}
@keyframes marquee { 0% { transform: translate(0, 0); } 100% { transform: translate(-100%, 0); } }

.info-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 14px; color: #333; font-weight: 500; }
.hero-tags-container { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.hero-tag { font-size: 11px; padding: 3px 8px; border-radius: 6px; font-weight: 500; background: #F1F3F5; color: #495057; }
.hero-tag.green { background: #E6FCF5; color: #087F5B; }
.hero-tag.pink { background: #FFF0F6; color: #C2255C; }
.hero-tag.blue { background: #E7F5FF; color: #1971C2; }

/* 2x2 기능 버튼 */
.action-grid-2x2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.act-btn { padding: 10px; border-radius: 8px; border: none; font-size: 13px; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 4px; }
.act-btn.dark { background: #343A40; color: #fff; }
.act-btn.light { background: #F1F3F5; color: #495057; }

.btn-detail-full { width: 100%; padding: 12px; background: #E7F5FF; color: #1971C2; border: 1px solid #D0EBFF; border-radius: 10px; font-size: 13px; font-weight: 700; cursor: pointer; transition: background 0.2s; }
.btn-detail-full:active { background: #D0EBFF; }


/* === [5] Detail Modal (Full Screen, z-index 20000) === */
.detail-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--sidebar-bg); z-index: 20000 !important;
    display: flex; flex-direction: column;
    transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.detail-modal.active { transform: translateX(0); }
.detail-modal.hidden { display: none; }

.detail-header {
    height: 56px; display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px; border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,0.9); backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 10;
}
.header-title { font-weight: 700; font-size: 16px; }
.btn-back, .btn-share { background: none; border: none; color: var(--primary); cursor: pointer; padding: 8px; }

.detail-content { flex: 1; overflow-y: auto; padding-bottom: 80px; }
.detail-hero-img { width: 100%; height: 240px; background-size: cover; background-position: center; background-color: #eee; position: relative; }
.detail-section { padding: 24px 20px; border-bottom: 8px solid var(--hover-bg); }
.detail-section:last-child { border-bottom: none; }

.detail-title-box h2 { font-size: 24px; font-weight: 800; margin-bottom: 8px; }
.detail-desc { font-size: 14px; color: var(--text-sub); line-height: 1.5; }

/* 그래프 & 표 스타일 */
.graph-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; display: flex; align-items: center; gap: 6px; }
.graph-container { display: flex; align-items: flex-end; justify-content: space-between; height: 120px; padding: 10px 0; }
.bar-col { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1; }
.bar-val { width: 100%; background: var(--hover-bg); border-radius: 4px; position: relative; transition: height 0.5s; max-width: 30px; }
.bar-val.high { background: var(--accent); }
.bar-label { font-size: 11px; color: var(--text-sub); }

.congestion-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 10px; }
.congestion-table th, .congestion-table td { padding: 8px; border-bottom: 1px solid var(--border); text-align: center; }
.congestion-table th { background: var(--hover-bg); color: var(--text-sub); font-weight: 600; }

.cardoc-insight { background: var(--hover-bg); padding: 15px; border-radius: 12px; font-size: 13px; color: var(--primary); font-weight: 500; display: flex; align-items: center; gap: 10px; margin-top: 20px; }
.menu-item { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 14px; }

.detail-footer {
    position: absolute; bottom: 0; left: 0; width: 100%; padding: 16px 20px;
    background: var(--sidebar-bg); border-top: 1px solid var(--border);
    display: flex; gap: 10px; padding-bottom: calc(16px + var(--safe-bottom));
}
.btn-call-fixed { flex: 1; padding: 16px; border-radius: 12px; background: var(--hover-bg); color: var(--primary); font-weight: 700; border: none; cursor: pointer; }
.btn-book-fixed { flex: 2; padding: 16px; border-radius: 12px; background: var(--accent); color: white; font-weight: 700; border: none; cursor: pointer; }


/* === [6] Nav Modal (Deep Link) === */
.nav-modal-content { 
    position: relative; background: var(--sidebar-bg); width: 85%; max-width: 320px; 
    border-radius: 20px; padding: 24px; box-shadow: 0 10px 40px rgba(0,0,0,0.3); text-align: center; 
}
.nav-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 15px; margin: 20px 0; }
.nav-app-btn { background: none; border: none; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.nav-icon { width: 50px; height: 50px; object-fit: contain; }
.nav-app-btn span { font-size: 12px; color: var(--primary); font-weight: 600; }
.modal-cancel-btn { width: 100%; padding: 12px; background: var(--hover-bg); border: none; border-radius: 12px; font-weight: 700; cursor: pointer; color: var(--text-sub); }


/* === [7] Common Components & Media Queries === */
#gps-btn { position: fixed; bottom: 30px; right: 30px; width: 48px; height: 48px; border-radius: 50%; background: #FFFFFF; border: 1px solid rgba(0,0,0,0.1); box-shadow: 0 4px 12px rgba(0,0,0,0.15); color: var(--primary); cursor: pointer; z-index: 2000; display: flex; justify-content: center; align-items: center; transition: opacity 0.3s ease, transform 0.3s ease; }
#gps-btn.hidden { opacity: 0; transform: scale(0.8); pointer-events: none; }

/* PC Specific */
@media screen and (min-width: 769px) {
    .layout-container { padding: 20px; gap: 20px; background-color: var(--bg-color); }
    .sidebar { width: 420px; border-right: 1px solid var(--border); border-radius: 24px; box-shadow: 0 10px 30px rgba(0,0,0,0.05); }
    #sidebar-close-btn { display: none !important; }
    .mobile-ui-layer { display: none !important; }
    .map-container { border-radius: 24px; box-shadow: 0 10px 30px rgba(0,0,0,0.05); }
    #gps-btn { bottom: 100px; right: 40px; }
    
    .overlay-card { width: 360px !important; margin: 0 !important; left: auto !important; right: 20px !important; bottom: 30px !important; border-radius: 20px !important; position: absolute; }
    .card-hero { border-radius: 20px 20px 0 0; }
    .detail-modal { width: 480px; left: auto; right: 0; box-shadow: -4px 0 30px rgba(0,0,0,0.1); }
}

/* Mobile Specific */
@media screen and (max-width: 768px) {
    /* [수정] 사이드바 높이 제한 (50dvh) 및 하단 패딩 */
    .sidebar {
        position: fixed; bottom: 0; left: 0; width: 100%; height: auto; 
        max-height: 50dvh; /* 검색창 가리지 않도록 제한 */
        background: var(--sidebar-bg); border-radius: 24px 24px 0 0; 
        z-index: 10000; transition: transform 0.3s cubic-bezier(0.19, 1, 0.22, 1); 
        transform: translateY(110%); box-shadow: 0 -4px 30px rgba(0,0,0,0.15); 
        padding-top: 10px; border-right: none; padding-bottom: 90px;
    }
    .sidebar.active { transform: translateY(0); }
    .mobile-handle-area { display: flex; justify-content: center; align-items: center; height: 20px; width: 100%; cursor: pointer; flex-shrink: 0; }
    .handle-bar { width: 48px; height: 5px; background: #E0E0E0; border-radius: 10px; }
    #gps-btn { bottom: calc(142px + var(--safe-bottom)); right: 16px; z-index: 2500; }
}

@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* MY Page Styles */
.my-header { background: #fff; padding: 24px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.user-info h2 { font-size: 20px; font-weight: 800; margin-bottom: 4px; color: var(--primary); }
.user-info p { font-size: 13px; color: var(--text-sub); }
.btn-logout { font-size: 12px; color: var(--text-sub); text-decoration: underline; background: none; border: none; cursor: pointer; }
.my-tabs { display: flex; background: #fff; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.my-tab { flex: 1; text-align: center; padding: 14px 0; font-size: 14px; font-weight: 600; color: var(--text-sub); cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.2s; }
.my-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.content-area { padding: 20px; min-height: 200px; }

/* Modal Basics */
.sheet-backdrop { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 2900; background: transparent; }
.sheet-backdrop.active { display: block; pointer-events: auto; }
.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 12000 !important; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.modal-content { position: relative; background: var(--sidebar-bg); width: 90%; max-width: 400px; max-height: 80vh; border-radius: 20px; padding: 24px; box-shadow: 0 10px 40px rgba(0,0,0,0.2); color: var(--primary); display: flex; flex-direction: column; align-items: center; overflow: hidden; }
.modal-content img { max-width: 100%; max-height: 60vh; border-radius: 8px; object-fit: contain; }
.modal-close-btn { position: absolute; top: 16px; right: 16px; width: 32px; height: 32px; background: var(--hover-bg); border-radius: 50%; border: none; color: var(--primary); font-size: 18px; font-weight: bold; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: background 0.2s; }

/* Bay Info List */
.bay-list-container { width: 100%; overflow-y: auto; max-height: 60vh; display: flex; flex-direction: column; gap: 10px; }
.bay-item-box { display: flex; justify-content: space-between; align-items: center; background: var(--sidebar-bg); border-bottom: 1px solid var(--border); padding: 8px 4px; font-size: 14px; }
.bay-item-box:last-child { border-bottom: none; }
.bay-number { font-weight: 700; color: var(--accent); background: var(--hover-bg); padding: 4px 8px; border-radius: 6px; font-size: 12px; margin-right: auto; }
.bay-desc { font-size: 14px; color: var(--primary); font-weight: 500; }
.fee-header { font-weight: 800; margin-top: 10px; margin-bottom: 6px; color: var(--primary); border-bottom: 2px solid var(--border); padding-bottom: 6px; font-size: 15px; width: 100%; }
