/* ==================== 모바일 최적화 지도 페이지 ==================== */

:root {
    --primary: #667eea;
    --primary-dark: #5a67d8;
    --accent: #764ba2;
    --text-primary: #1a1a2e;
    --text-secondary: #646e8a;
    --text-muted: #9ca3af;
    --bg-primary: #ffffff;
    --bg-secondary: #f7f8fc;
    --bg-card: #ffffff;
    --border-light: #e8eaf0;
    --shadow-sm: 0 2px 8px rgba(102, 126, 234, 0.08);
    --shadow-md: 0 4px 16px rgba(102, 126, 234, 0.12);
    --shadow-lg: 0 8px 32px rgba(102, 126, 234, 0.16);
    --radius-full: 9999px;
    --radius-xl: 20px;
    --radius-lg: 16px;
    --radius-md: 12px;

    /* 색상 코드 변수 (JS에서 동적으로 덮어쓰기 가능) */
    --color-sangsaeng: #10b981;
    --color-gwangsan: #8b5cf6;
    --color-donggu: #f59e0b;
    --color-namgu: #ef4444;
    --color-bookgu: #06b6d4;
    --color-onnuri: #3b82f6;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Segoe UI', sans-serif;
    background: var(--bg-secondary);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

/* ==================== 헤더 ==================== */
.map-header {
    background: var(--bg-primary);
    padding: 16px 20px 12px;
    text-align: center;
    flex-shrink: 0;
    position: relative;
    z-index: 100;
}

.map-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 4px 0;
    letter-spacing: -0.3px;
}

.map-header .subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
    font-weight: 500;
}

/* ==================== 카테고리 바 ==================== */
.category-bar {
    background: var(--bg-primary);
    padding: 10px 16px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.category-bar::-webkit-scrollbar {
    display: none;
}

.category-btn {
    flex-shrink: 0;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.category-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.category-btn:active {
    transform: scale(0.95);
}

/* ==================== 지도 영역 ==================== */
.map-container {
    position: relative;
    flex: 1;
    min-height: 200px;
    z-index: 1;
}

#map {
    width: 100%;
    height: 100%;
}

/* 센터 핀 */
.center-pin {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -100%);
    z-index: 10;
    pointer-events: none;
    filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.3));
}

/* ==================== 플로팅 버튼 ==================== */
.map-fabs {
    position: absolute;
    bottom: 50px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 50;
}

.fab-btn {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--bg-primary);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-primary);
}

.fab-btn:active {
    transform: scale(0.9);
}

.fab-btn.my-loc-fab {
    background: var(--primary);
    color: white;
}

.fab-btn.my-loc-fab svg {
    stroke: white;
}

/* ==================== 하단 목록 시트 ==================== */
.bottom-list-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    max-height: 60vh;
    height: 60vh;
    flex-shrink: 0;
    z-index: 100;
    transform: translateY(calc(100% - 34px));
    transition: transform 0.3s ease;
    touch-action: none;
}

.bottom-list-container.expanded {
    transform: translateY(0);
}

/* 드래그 핸들 */
.drag-handle {
    width: 100%;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    flex-shrink: 0;
}

.drag-handle::before {
    content: '';
    width: 36px;
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
}

.drag-handle:active {
    cursor: grabbing;
}

.list-header {
    padding: 20px 16px 12px;
    flex-shrink: 0;
}

.list-header h2 {
    margin: 0 0 12px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.search-box {
    display: flex;
    gap: 8px;
}

.search-box input {
    flex: 1;
    height: 40px;
    padding: 0 14px;
    font-size: 14px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    outline: none;
    transition: border-color 0.2s;
}

.search-box input:focus {
    border-color: var(--primary);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-box button {
    height: 40px;
    padding: 0 16px;
    font-size: 13px;
    font-weight: 600;
    color: white;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.2s;
}

.search-box button:active {
    background: var(--primary-dark);
}

/* ==================== 가맹점 목록 ==================== */
#merchant-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 16px 16px;
    -webkit-overflow-scrolling: touch;
}

.loading-placeholder {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 0;
    font-size: 14px;
}

/* 가맹점 카드 */
.merchant-item {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.merchant-item:active {
    background: var(--bg-secondary);
    transform: scale(0.98);
}

.merchant-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: nowrap;
}

.merchant-name-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    flex: 1;
    min-width: 0;
}

.card-icon {
    width: 15px;
    height: 15px;
    object-fit: contain;
    flex-shrink: 0;
}

.merchant-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.benefit-tag {
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    font-weight: 700;
    color: white;
    background: #10b981;
    padding: 3px 8px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
    white-space: nowrap;
    margin-left: 6px;
}

/* 태그별 색상 - CSS 변수 사용 */
.benefit-tag.tag-sangsaeng {
    background: var(--color-sangsaeng);
}

.benefit-tag.tag-extra-refund {
    background: #f43f5e; /* 빨강/핑크 */
}

.benefit-tag.tag-gwangsan {
    background: var(--color-gwangsan);
}

.benefit-tag.tag-donggu {
    background: var(--color-donggu);
}

.benefit-tag.tag-namgu {
    background: var(--color-namgu);
}

.benefit-tag.tag-bookgu {
    background: var(--color-bookgu);
}

.benefit-tag.tag-onnuri {
    background: var(--color-onnuri);
}

/* 버튼 컨테이너 */
.merchant-btns {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* 거리 표시 태그 */
.distance-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    color: #646e8a;
    background: #f7f8fc;
    padding: 6px 12px;
    border-radius: 9999px;
    flex-shrink: 0;
    white-space: nowrap;
}

/* 온누리앱 링크 */
.map-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    color: #667eea;
    text-decoration: none;
    padding: 6px 12px;
    background: rgba(102, 126, 234, 0.08);
    border-radius: 9999px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.map-link:active {
    background: rgba(102, 126, 234, 0.15);
    transform: scale(0.96);
}

.map-link.onnuri-link {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.map-link.onnuri-link:active {
    background: rgba(59, 130, 246, 0.2);
}

/* ==================== 인포윈도우 태그 ==================== */
.iw-tag {
    display: inline-flex;
    align-items: center;
    font-size: 10px;
    font-weight: 700;
    color: white;
    padding: 2px 6px;
    border-radius: 10px;
    white-space: nowrap;
}

.iw-tag.tag-sangsaeng {
    background: var(--color-sangsaeng);
}

.iw-tag.tag-gwangsan {
    background: var(--color-gwangsan);
}

.iw-tag.tag-donggu {
    background: var(--color-donggu);
}

.iw-tag.tag-namgu {
    background: var(--color-namgu);
}

.iw-tag.tag-bookgu {
    background: var(--color-bookgu);
}

.iw-tag.tag-onnuri {
    background: var(--color-onnuri);
}

/* 인포윈도우 온누리앱 버튼 */
.iw-onnuri-btn {
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    font-weight: 600;
    color: #3b82f6;
    background: rgba(59, 130, 246, 0.1);
    padding: 4px 10px;
    border-radius: 9999px;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.2s;
}

.iw-onnuri-btn:active {
    background: rgba(59, 130, 246, 0.2);
}

.merchant-category {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    background: rgba(102, 126, 234, 0.1);
    padding: 4px 10px;
    border-radius: var(--radius-full);
    margin-bottom: 10px;
}

.district-tag {
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    background: rgba(102, 126, 234, 0.1);
    padding: 3px 8px;
    border-radius: var(--radius-full);
    white-space: nowrap;
    margin-left: 8px;
    flex-shrink: 0;
}

.merchant-address {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.merchant-item .address {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: flex-start;
    gap: 4px;
    line-height: 1.4;
}

.merchant-item .address svg {
    flex-shrink: 0;
    margin-top: 2px;
}

/* ==================== 인포윈도우 ==================== */
.iw-content {
    padding: 4px;
    min-width: 180px;
}

.iw-content .title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.iw-content .desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ==================== 아이폰 안전영역 ==================== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .bottom-list-container {
        padding-bottom: env(safe-area-inset-bottom);
    }
    .footer {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
}

/* ==================== 작은 화면 (SE, 미니) ==================== */
@media screen and (max-height: 700px) {
    .map-header {
        padding: 12px 16px 8px;
    }

    .map-header h2 {
        font-size: 16px;
    }

    .map-header .subtitle {
        font-size: 12px;
    }

    .category-bar {
        padding: 8px 12px;
    }

    .category-btn {
        padding: 6px 12px;
        font-size: 12px;
    }

    .bottom-list-container {
        max-height: 45vh;
        min-height: 160px;
    }

    .list-header {
        padding: 16px 12px 10px;
    }

    .list-header h2 {
        font-size: 14px;
        margin-bottom: 8px;
    }

    .search-box input,
    .search-box button {
        height: 36px;
        font-size: 13px;
    }

    .merchant-item {
        padding: 12px;
        margin-bottom: 8px;
    }

    .merchant-item .name {
        font-size: 14px;
    }
}

/* ==================== 가로모드 ==================== */
@media screen and (orientation: landscape) and (max-height: 500px) {
    .map-header {
        display: none;
    }

    .category-bar {
        padding: 6px 12px;
    }

    .bottom-list-container {
        max-height: 60vh;
    }
}

/* ==================== Footer ==================== */
.footer {
    background: var(--bg-primary);
    padding: 12px 16px;
    text-align: center;
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
}

.error-report-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
    padding: 6px 12px;
    background: rgba(102, 126, 234, 0.08);
    border-radius: var(--radius-full);
    transition: all 0.2s ease;
}

.error-report-btn:active {
    background: rgba(102, 126, 234, 0.15);
    transform: scale(0.96);
}

.error-report-btn svg {
    stroke: var(--primary);
}

/* ==================== 공유 버튼 ==================== */
.iw-share-btn {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.iw-share-btn:hover {
    background: rgba(102, 126, 234, 0.1);
}

.iw-share-btn:active {
    background: rgba(102, 126, 234, 0.2);
    transform: scale(0.9);
}

/* ==================== 토스트 메시지 ==================== */
.share-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    z-index: 10000;
    animation: toastFadeIn 0.3s ease;
    max-width: 90%;
    text-align: center;
}

@keyframes toastFadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes toastFadeOut {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
}

/* ==================== 마커 애니메이션 ==================== */
.custom-marker-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transform: translate(-50%, -100%);
    transform-origin: center bottom;
    z-index: 10;
    transition: z-index 0s;
}

.custom-marker-wrap.expanded {
    z-index: 1000;
}

.marker-body {
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border: 1px solid #eee;
    font-family: 'Pretendard', sans-serif;
    overflow: hidden;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 기본 마커 상태 */
.marker-basic {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    font-weight: 600;
    font-size: 14px;
    color: #222;
    white-space: nowrap;
    letter-spacing: -0.5px;
}

.marker-basic .marker-name {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.marker-basic .marker-tags {
    display: flex;
    align-items: center;
    margin-left: 4px;
}

/* 상세 마커 상태 (기본적으로 숨김) */
.marker-detail {
    display: none;
    padding: 16px;
    min-width: 220px;
    max-width: 280px;
}

.marker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.marker-title {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a2e;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.marker-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.marker-tags-detail {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}

.marker-category {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: #667eea;
    background: rgba(102,126,234,0.1);
    padding: 4px 10px;
    border-radius: 9999px;
    margin-bottom: 8px;
}

.marker-address {
    font-size: 13px;
    color: #646e8a;
}

/* 마커 핀 (아래 화살표) */
.marker-pin {
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 12px solid white;
    margin-top: -1px;
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.1));
}

/* 확장된 상태 */
.custom-marker-wrap.expanded .marker-body {
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.custom-marker-wrap.expanded .marker-basic {
    display: none;
}

.custom-marker-wrap.expanded .marker-detail {
    display: block;
}

/* 확장 시 핀 그림자 강화 */
.custom-marker-wrap.expanded .marker-pin {
    filter: drop-shadow(0 3px 4px rgba(0,0,0,0.15));
}
