/* 🌙 기본 다크 모드 테마 변수 */
:root {
    --bg: #0f0f13;
    --surface: #17171f;
    --surface2: #1e1e28;
    --border: #2a2a38;
    --accent: #6c63ff;
    --accent2: #ff6584;
    --accent3: #43e97b;
    --text: #e8e8f0;
    --muted: #7b7b99;

    --lvl-4: #34a853;
    --lvl-3: #fbbc04;
    --lvl-2: #ff9f43;
    --lvl-1: #ea4335;
}

/* ☀️ 라이트 모드 변수 전환 바인딩 (🚨 경계선 선명화 대수술) */
body.light-mode {
    --bg: #f8f9fa;
    --surface: #ffffff;
    --surface2: #f1f2f6;
    --border: #7f8c8d; /* 🎯 [변경]: 선이 확실히 보이도록 어두운 흑회색으로 강제 락인 */
    --text: #1e2229;
    --muted: #57606f;
    --accent: #3c3cef;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Noto Sans KR', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column; /* 푸터를 하단 고정하기 위한 플렉스 레이아웃 구성 */
    transition: background 0.2s, color 0.2s;
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    background: transparent;
    outline: none;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.15s;
    pointer-events: auto;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.3); }

input[type=range]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.15s;
    pointer-events: auto;
}
input[type=range]::-moz-range-thumb:hover { transform: scale(1.3); }
input[type=range]::-moz-range-track { background: transparent; border: none; }

.slider-calories input[type=range]::-webkit-slider-thumb { background: var(--accent); box-shadow: 0 0 8px rgba(108,99,255,0.6); }
.slider-calories input[type=range]::-moz-range-thumb { background: var(--accent); box-shadow: 0 0 8px rgba(108,99,255,0.6); }

.slider-protein input[type=range]::-webkit-slider-thumb { background: #43e97b; box-shadow: 0 0 8px rgba(67,233,123,0.6); }
.slider-protein input[type=range]::-moz-range-thumb { background: #43e97b; box-shadow: 0 0 8px rgba(67,233,123,0.6); }

.slider-carbs input[type=range]::-webkit-slider-thumb { background: #f9c74f; box-shadow: 0 0 8px rgba(249,199,79,0.6); }
.slider-carbs input[type=range]::-moz-range-thumb { background: #f9c74f; box-shadow: 0 0 8px rgba(249,199,79,0.6); }

.slider-sodium input[type=range]::-webkit-slider-thumb { background: #ff6584; box-shadow: 0 0 8px rgba(255,101,132,0.6); }
.slider-sodium input[type=range]::-moz-range-thumb { background: #ff6584; box-shadow: 0 0 8px rgba(255,101,132,0.6); }

.check-item input[type=checkbox] { display: none; }
.check-item label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--muted);
    transition: color 0.15s;
    user-select: none;
    margin-bottom: 5px;
}
.check-item label:hover { color: var(--text); }
.check-box {
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
    background: transparent;
}

/* ☀️ 라이트 모드일 때 선택 안된 일반 체크박스 선 굵기 보강 테두리 */
body.light-mode .check-box {
    border-width: 2px;
}

.check-item input:checked + label .check-box { border-color: transparent; }
.check-item input:checked + label .check-box::after {
    content: '';
    display: block;
    width: 5px;
    height: 9px;
    border: 2px solid white;
    border-top: none;
    border-left: none;
    transform: rotate(45deg) translateY(-1px);
}
.check-item input:checked + label { color: var(--text); }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    border: 1.5px solid var(--border);
    background: var(--surface2);
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.active {
    background: rgba(108,99,255,0.15);
    border-color: var(--accent);
    color: #a5a0ff;
}

body.light-mode .chip {
    border-width: 2px; /* 라이트모드 가시성 칩 두께 강화 */
}
body.light-mode .chip.active {
    background: rgba(75,75,223,0.1);
    color: var(--accent);
}

/* ❌ 블랙리스트 제외 원재료 커스텀 전용 레드 칩 스타일 정의 */
.chip-blacklist {
    background: rgba(234,67,53,0.1);
    border-color: var(--lvl-1);
    color: #ff7675;
}
body.light-mode .chip-blacklist {
    background: rgba(234,67,53,0.08);
    border-color: var(--lvl-1);
    color: var(--lvl-1);
}

/* 직접 입력 인풋 필드 스타일 정의 */
.custom-append-input {
    background: var(--surface2);
    border: 1.5px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 12px;
    outline: none;
    padding: 6px 10px;
    width: 100%;
    transition: border-color 0.2s;
    margin-top: 5px;
    margin-bottom: 5px;
}
.custom-append-input:focus { border-color: var(--accent); }

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 12px 0;
    border-bottom: 1.5px solid var(--border); /* 🎯 라이트모드 가시성 가드 */
    user-select: none;
}
.section-header:hover .section-title { color: var(--text); }
.section-title {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    transition: color 0.15s;
}
.arrow {
    width: 16px;
    height: 16px;
    color: var(--muted);
    transition: transform 0.2s;
    flex-shrink: 0;
}
.arrow.open { transform: rotate(180deg); }
.section-body {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    max-height: 0;
    opacity: 0;
}
.section-body.open { max-height: 500px; opacity: 1; }

.product-card {
    background: var(--surface);
    border: 1.5px solid var(--border); /* 🎯 1px에서 1.5px로 선 강화 */
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.product-card:hover {
    transform: translateY(-3px);
    border-color: rgba(108,99,255,0.4);
    box-shadow: 0 8px 32px rgba(108,99,255,0.05);
}

body.light-mode .product-card {
    border-width: 2px; /* 라이트모드 시 상품 카드 외곽선 대폭 강조 */
}
body.light-mode .product-card:hover {
    border-color: var(--accent);
    box-shadow: 0 8px 32px rgba(0,0,0,0.06);
}

.badge-lvl {
    font-size: 11px;
    font-weight: 900;
    padding: 4px 10px;
    border-radius: 999px;
    letter-spacing: 0.03em;
    color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.badge-lvl-4 { background: var(--lvl-4); border: 1px solid #278643; }
.badge-lvl-3 { background: var(--lvl-3); border: 1px solid #dba303; color: #111115 !important; }
.badge-lvl-2 { background: var(--lvl-2); border: 1px solid #e17e1b; }
.badge-lvl-1 { background: var(--lvl-1); border: 1px solid #cc2d21; }

.search-input {
    background: var(--surface2);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 14px;
    font-family: 'Noto Sans KR', sans-serif;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
    padding: 10px 14px 10px 38px;
}
body.light-mode .search-input {
    border-width: 2px; /* 라이트모드 검색창 선명화 */
}
.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108,99,255,0.12);
}
.search-input::placeholder { color: var(--muted); }

select {
    background: var(--surface2);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 13px;
    font-family: 'Noto Sans KR', sans-serif;
    outline: none;
    padding: 8px 12px;
    cursor: pointer;
    appearance: none;
    transition: border-color 0.2s;
}
body.light-mode select {
    border-width: 2px; /* 라이트모드 정렬 셀렉트 박스 선명화 */
}
select:focus { border-color: var(--accent); }
option { background: var(--surface2); color: var(--text); }

.active-filter {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(108,99,255,0.15);
    border: 1px solid rgba(108,99,255,0.35);
    color: var(--accent);
}
body.light-mode .active-filter {
    background: rgba(75,75,223,0.08);
    border-color: var(--border); /* 필터 칩 외곽선 확실하게 보정 */
    border-width: 1.5px;
    color: var(--accent);
}
.active-filter button {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    padding: 0;
    opacity: 0.7;
    transition: opacity 0.15s;
}
.active-filter button:hover { opacity: 1; }

.sidebar {
    width: 260px;
    flex-shrink: 0;
    position: sticky;
    top: 180px; /* 상단 고정된 검색창+필터바 높이 아래에 안착되도록 조정 */
    max-height: calc(100vh - 200px); /* 화면을 벗어나지 않게 제어 */
    overflow-y: auto; /* 사이드바 자체 내용이 길면 내부에서 스크롤 */
}
body.light-mode .sidebar > div {
    border-width: 2px !important; /* 사이드바 큰 상자 테두리선 강화 */
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 32px;
    padding-bottom: 40px;
}
.page-btn {
    min-width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    font-size: 13px;
    font-family: 'Noto Sans KR', sans-serif;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    padding: 0 8px;
}
body.light-mode .page-btn {
    border-width: 1.5px;
}
.page-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--text);
    background: rgba(108,99,255,0.08);
}
.page-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    font-weight: 700;
}
.page-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.page-ellipsis {
    color: var(--muted);
    font-size: 13px;
    padding: 0 4px;
    user-select: none;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 16px;
}

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: static;
        max-height: none;
        overflow-y: visible;
    }
    .layout { flex-direction: column !important; }
}

.font-display { font-family: 'Space Grotesk', sans-serif; }

.action-btn { transition: all 0.2s ease-in-out; }
.action-btn:hover { transform: translateY(-1px); }

.theme-switch-track {
    width: 36px;
    height: 20px;
    background: #2a2a38;
    border-radius: 999px;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
}
body.light-mode .theme-switch-track {
    background: #cbd5e1;
    border: 1px solid var(--border);
}
.theme-switch-thumb {
    width: 14px;
    height: 14px;
    background: #ffffff;
    border-radius: 50%;
    position: absolute;
    top: 3px;
    left: 3px;
    transition: transform 0.2s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
body.light-mode .theme-switch-thumb {
    transform: translateX(16px);
    background: #4b4bdf;
}

/* 🗺️ [신규 설계]: 모듈형 대형 하단 푸터(Footer) 전용 스타일 클래스 */
.site-footer {
    background: var(--surface);
    border-top: 2px solid var(--border); /* 푸터 경계선 확실하게 구분 */
    color: var(--muted);
    font-size: 12px;
    margin-top: auto; /* 본문이 짧아도 항상 맨 밑바닥에 안착 유도 */
    padding: 32px 24px;
    transition: background 0.2s, border-color 0.2s;
}
body.light-mode .site-footer {
    background: #ffffff;
}
.footer-link:hover {
    color: var(--text);
    text-decoration: underline;
}

/* 🎨 [디자인 고도화] 글자 크기 확대(text-sm 급), 패딩 및 간격 최적화 */
.active-filter {
    display: inline-flex;
    align-items: center;
    gap: 8px;                  /* 칩 내부 글자와 X 버튼 사이 간격 */
    padding: 6px 14px;         /* 칩 패딩 확대 */
    border-radius: 999px;
    font-size: 13.5px;         /* 🎯 기존 11px에서 대폭 키움 (시원한 가시성) */
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.15s;
}

.active-filter button {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 15px;           /* ✕ 버튼 크기도 확대 */
    line-height: 1;
    padding: 0;
    opacity: 0.7;
    font-weight: 700;
}
.active-filter button:hover { opacity: 1; }

/* 필터 종류별 고유 컬러 브랜딩 스타일 */
.filter-tag-search {
    background: rgba(108, 99, 255, 0.15) !important;
    border: 1px solid rgba(108, 99, 255, 0.4) !important;
    color: #a5a0ff !important;
}
body.light-mode .filter-tag-search {
    background: rgba(60, 60, 239, 0.08) !important;
    border-color: #3c3cef !important;
    color: #3c3cef !important;
}

.filter-tag-blacklist {
    background: rgba(234, 67, 53, 0.15) !important;
    border: 1px solid rgba(234, 67, 53, 0.4) !important;
    color: #ff7675 !important;
}
body.light-mode .filter-tag-blacklist {
    background: rgba(234, 67, 53, 0.08) !important;
    border-color: #ea4335 !important;
    color: #ea4335 !important;
}

.filter-tag-allergen {
    background: rgba(255, 159, 67, 0.15) !important;
    border: 1px solid rgba(255, 159, 67, 0.4) !important;
    color: #ffb142 !important;
}
body.light-mode .filter-tag-allergen {
    background: rgba(255, 159, 67, 0.08) !important;
    border-color: #ff9f43 !important;
    color: #e17e1b !important;
}

.filter-tag-origin {
    background: rgba(52, 168, 83, 0.15) !important;
    border: 1px solid rgba(52, 168, 83, 0.4) !important;
    color: #55efc4 !important;
}
body.light-mode .filter-tag-origin {
    background: rgba(52, 168, 83, 0.08) !important;
    border-color: #34a853 !important;
    color: #278643 !important;
}

.filter-tag-default {
    background: var(--surface2) !important;
    border: 1px solid var(--border) !important;
    color: var(--text) !important;
}