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

: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;
    --success: #10b981;
    --danger: #ef4444;
    --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 {
    font-family: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Segoe UI', sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ==================== 컨테이너 ==================== */
.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0 16px;
    padding-bottom: calc(60px + env(safe-area-inset-bottom));
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ==================== 헤더 ==================== */
header {
    text-align: center;
    padding: 16px 20px 12px;
    background: var(--bg-primary);
    margin: 0 -16px;
    margin-bottom: 16px;
}

header h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 4px 0;
    letter-spacing: -0.3px;
}

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

/* ==================== 검색 카드 ==================== */
.glass-card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--border-light);
}

.search-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 12px 0;
    text-align: center;
}

.search-box {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* 필터가 접혔을 때 간격 줄이기 */
.search-box.filter-collapsed {
    gap: 6px;
}

/* 상세 필터 토글 */
.filter-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.filter-toggle:active {
    background: var(--border-light);
}

.filter-toggle svg {
    transition: transform 0.3s ease;
}

.filter-options {
    overflow: hidden;
    max-height: 200px;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.filter-options.collapsed {
    max-height: 0;
    opacity: 0;
}

.input-row {
    display: flex;
    gap: 10px;
}

.input-row .input-group {
    flex: 1;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-left: 2px;
}

/* ==================== 입력 필드 ==================== */
select,
input[type="text"] {
    width: 100%;
    height: 44px;
    padding: 0 14px;
    font-size: 15px;
    font-family: inherit;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color 0.2s;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' 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 12px center;
    padding-right: 40px;
}

select:focus,
input[type="text"]:focus {
    border-color: var(--primary);
}

input[type="text"]::placeholder {
    color: var(--text-muted);
}

/* ==================== 버튼 ==================== */
button {
    height: 44px;
    padding: 0 20px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    color: white;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.2s;
}

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

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 검색 버튼 - 모바일에서 전체 너비 */
.search-btn {
    width: 100%;
    margin-top: 4px;
}

/* 검색 입력 그룹 */
.search-input-group {
    /* 기본 input-group 스타일 유지 */
}

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

.search-input-wrapper input {
    flex: 1;
}

/* 아이콘만 있는 검색 버튼 */
.search-icon-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    flex-shrink: 0;
}

/* ==================== 결과 테이블 ==================== */
.table-wrapper {
    margin-top: 4px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    min-height: 0; /* flexbox 내에서 스크롤 작동을 위해 */
    display: flex;
    flex-direction: column;
    padding-bottom: calc(60px + env(safe-area-inset-bottom)); /* 푸터 높이만큼 하단 여백 */
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 8px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

thead {
    display: none;
}

tbody {
    flex: 1;
    display: flex;
    flex-direction: column;
}

tbody tr {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 10px;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

tbody tr:active {
    transform: scale(0.98);
    box-shadow: none;
}

tbody tr:not(.empty-row):not(:has(td.empty-row)):active {
    background: var(--bg-secondary);
}

tbody tr.empty-row,
tbody tr:has(td.empty-row) {
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    display: flex !important;
    flex: 1 !important;
    min-height: 100% !important;
}

tbody tr td.empty-row {
    text-align: center !important;
    width: 100% !important;
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 50px 20px !important;
    border: none !important;
    background: transparent !important;
    color: var(--text-muted) !important;
}

tbody tr td.empty-row::before {
    display: none !important;
    content: none !important;
}

tbody tr td.empty-row div {
    text-align: center !important;
    width: 100% !important;
}

tbody tr td.empty-row div:first-child {
    font-size: 48px !important;
    margin-bottom: 16px !important;
    opacity: 0.7 !important;
}

tbody tr td.empty-row div:nth-child(2) {
    font-size: 15px !important;
    font-weight: 600 !important;
    color: var(--text-secondary) !important;
    margin-bottom: 6px !important;
}

tbody tr td.empty-row div:nth-child(3) {
    font-size: 13px !important;
    color: var(--text-muted) !important;
    opacity: 0.8 !important;
}

/* 접근성 개선용 클래스 */
.empty-icon {
    font-size: 48px !important;
    margin-bottom: 16px !important;
    opacity: 0.7 !important;
}

.empty-title {
    font-size: 15px !important;
    font-weight: 600 !important;
    color: var(--text-secondary) !important;
    margin-bottom: 6px !important;
}

.empty-desc {
    font-size: 13px !important;
    color: var(--text-muted) !important;
    opacity: 0.8 !important;
    line-height: 1.5;
}

td {
    display: block;
    padding: 0;
    border: none;
    font-size: 14px;
}

td[data-label="주소"] {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: block !important;
    max-width: 100% !important;
}

.merchant-address {
    font-size: 13px;
    color: var(--text-secondary);
    display: inline !important;
    white-space: nowrap !important;
}

td:first-child {
    margin-bottom: 6px;
}

td:nth-child(1)::before {
    display: none;
}

td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-right: 6px;
}

.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;
}

.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;
}

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

/* 태그별 색상 - 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-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;
}

.map-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    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;
    flex-shrink: 0;
}

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

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

/* 온누리앱 링크 */
.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);
}

/* 거리 표시 태그 */
.distance-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 6px 12px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
    white-space: nowrap;
}

/* ==================== 안내 문구 ==================== */
.disclaimer {
    text-align: center;
    padding: 20px 16px;
    margin-top: 16px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.7;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-radius: var(--radius-lg);
    border: 1px solid #fcd34d;
}

.disclaimer-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.disclaimer-title {
    font-size: 14px;
    font-weight: 700;
    color: #92400e;
    margin-bottom: 8px !important;
}

.disclaimer p {
    margin: 4px 0;
    color: #78350f;
}

.disclaimer-link {
    display: inline-block;
    margin-top: 12px;
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    color: #92400e;
    background: rgba(255, 255, 255, 0.6);
    border-radius: var(--radius-full);
    text-decoration: none;
    transition: all 0.2s ease;
}

.disclaimer-link:active {
    background: rgba(255, 255, 255, 0.9);
    transform: scale(0.96);
}

/* ==================== 뱃지 ==================== */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    margin-top: 4px;
}

.badge.success {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
}

.badge.danger {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

/* ==================== 로더 ==================== */
.loader {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==================== 플로팅 버튼 (지도 이동) ==================== */
.nav-fab {
    position: fixed;
    bottom: calc(60px + env(safe-area-inset-bottom));
    right: 20px;
    width: 52px;
    height: 52px;
    background: var(--primary);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    color: white;
    text-decoration: none;
    z-index: 100;
    transition: all 0.2s ease;
}

.nav-fab:active {
    transform: scale(0.9);
    background: var(--primary-dark);
}

.nav-fab svg {
    stroke: white;
}

/* ==================== 안전 영역 ==================== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .footer {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
}

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

    header h1 {
        font-size: 17px;
    }

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

    .glass-card {
        padding: 14px;
    }

    .search-box {
        gap: 10px;
    }

    select,
    input[type="text"],
    button {
        height: 40px;
        font-size: 14px;
    }

    tbody tr {
        padding: 12px;
    }

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

/* ==================== 데스크톱 ==================== */
@media screen and (min-width: 768px) {
    .container {
        max-width: 600px;
        padding: 40px 20px;
    }

    header {
        margin: 0;
        margin-bottom: 24px;
        border-radius: var(--radius-lg);
        padding: 32px 24px;
    }

    header h1 {
        font-size: 26px;
    }

    header .subtitle {
        font-size: 14px;
    }

    .search-box {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .input-row {
        display: flex;
        gap: 12px;
    }

    .input-row .input-group {
        flex: 1;
    }

    .input-group:last-child {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
        gap: 6px 8px;
        align-items: center;
    }

    .input-group:last-child label {
        grid-column: 1 / -1;
    }

    .input-group:last-child input {
        flex: 1;
        width: 100%;
    }

    .input-group:last-child button {
        width: auto;
        padding: 0 24px;
    }

    .nav-fab {
        bottom: calc(70px + env(safe-area-inset-bottom));
        right: 32px;
    }
}

/* ==================== Footer ==================== */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    text-align: center;
    border-top: 1px solid var(--border-light);
    z-index: 50;
}

.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);
}
