/* ============================================================
   ShoppingMall 통합 스타일
   ============================================================ */
:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --text: #1f2328;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(0, 0, 0, .06);
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 20px 80px;
    flex: 1;
    width: 100%;
}

/* ---------- Header ---------- */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 50;
    flex-shrink: 0;
}
.site-header .inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 14px 20px;
}
.brand {
    font-size: 22px;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -.5px;
}
.nav {
    display: flex;
    gap: 18px;
    margin-left: auto;
    align-items: center;
    flex-wrap: wrap;
}
.nav a, .nav button.linklike {
    font-size: 15px;
    color: var(--text);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 2px;
}
.nav a:hover { color: var(--primary); }
.nav .badge-admin {
    font-size: 12px;
    background: #111827;
    color: #fff;
    padding: 2px 8px;
    border-radius: 999px;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    padding: 10px 18px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    cursor: pointer;
    font-size: 15px;
    transition: .15s;
}
.btn:hover { background: #f1f3f5; }
.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); }
.btn:disabled,
.btn-primary:disabled {
    background: #e5e7eb;
    color: #9ca3af;
    border-color: #e5e7eb;
    cursor: not-allowed;
}
.btn:disabled:hover,
.btn-primary:disabled:hover { background: #e5e7eb; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-outline-primary { border-color: var(--primary); color: var(--primary); }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ---------- Cards / grid ---------- */
.section-title { font-size: 22px; font-weight: 700; margin: 0 0 20px; }

.category-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 40px;
}
.category-cards a {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 26px 10px;
    text-align: center;
    font-weight: 600;
    box-shadow: var(--shadow);
    transition: .15s;
}
.category-cards a:hover { transform: translateY(-3px); border-color: var(--primary); }
.category-cards a:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
.category-cards a.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 4px 10px rgba(37,99,235,0.25);
}
.category-cards a.active:hover { transform: none; }
.category-cards .icon { font-size: 30px; display: block; margin-bottom: 8px; }

/* ---------- 상품 목록 툴바 (개수 + 필터 옵션) ---------- */
.list-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding-bottom: 14px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--line);
}
.list-count {
    font-size: 13.5px;
    color: var(--muted);
    font-weight: 600;
}
.list-filters {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.list-header-row {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.list-header-row .section-title { margin: 0; }
.search-clear-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--muted);
    padding: 0;
    border: none;
    background: none;
    transition: color .15s;
}
.search-clear-chip:hover {
    color: var(--danger);
    text-decoration: underline;
}
.search-clear-chip:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}
.search-clear-chip-x {
    font-size: 12px;
    line-height: 1;
}

/* ---------- 목록 필터 토글(품절 숨기기 / 재고 임박만 보기 등) ---------- */
.filter-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--muted);
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    transition: .15s;
    white-space: nowrap;
}
.filter-toggle:hover { border-color: var(--primary); color: var(--text); }
.filter-toggle-box {
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--line);
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: .15s;
}
.filter-toggle.active {
    border-color: var(--primary);
    color: var(--primary);
    background: #eff4ff;
}
.filter-toggle.active .filter-toggle-box {
    background: var(--primary);
    border-color: var(--primary);
}
.filter-toggle.active .filter-toggle-box::after {
    content: "✓";
    color: #fff;
    font-size: 11px;
    line-height: 1;
}


.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
}
.product-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: .15s;
    display: flex;
    flex-direction: column;
}
.product-card:hover { transform: translateY(-3px); }
.product-card .thumb {
    aspect-ratio: 1/1;
    background: #e9edf2 center/cover no-repeat;
    display: flex; align-items: center; justify-content: center;
    color: #aab2bd; font-size: 13px;
}
.product-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-card .body { padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.product-card .cat { font-size: 12px; color: var(--muted); }
.product-card .name { font-weight: 600; font-size: 15px; }
.product-card .price { font-weight: 700; font-size: 17px; color: #111827; }
.soldout,
.stock-low,
.stock-ok {
    display: inline-block;
    width: fit-content;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}
.soldout { color: var(--danger); background: #fef2f2; }
.stock-low { color: #d97706; background: #fffbeb; }
.stock-ok { color: #16a34a; background: #ecfdf5; font-weight: 600; }

/* 상세 페이지에서는 배지를 살짝 더 크게 표시 */
.detail .soldout,
.detail .stock-low,
.detail .stock-ok {
    font-size: 13.5px;
    padding: 5px 12px;
    margin: 4px 0 6px;
}

/* ---------- Forms ---------- */
.form-wrap {
    max-width: 460px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
}
.form-wrap.wide { max-width: 640px; }
.form-wrap h2 { margin: 0 0 24px; text-align: center; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 14px; margin-bottom: 6px; color: var(--muted); }
.field input, .field select, .field textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
}
.field textarea { min-height: 120px; resize: vertical; }
.field .inline { display: flex; gap: 8px; }
.field .inline input { flex: 1; }
.hint { font-size: 12px; margin-top: 4px; }
.hint.ok { color: #16a34a; }
.hint.no { color: var(--danger); }
.form-links { margin-top: 16px; text-align: center; font-size: 14px; color: var(--muted); }
.form-links a { color: var(--primary); }

/* ---------- Tables ---------- */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.table th, .table td { padding: 14px; border-bottom: 1px solid var(--line); text-align: left; }
.table th { background: #f3f4f6; font-size: 14px; }
.table td.r, .table th.r { text-align: right; }
.table td.c, .table th.c { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 40px; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 20px; font-size: 14px; }
.alert-success { background: #ecfdf5; color: #065f46; }
.alert-error { background: #fef2f2; color: #991b1b; }
.alert-warn { background: #fffbeb; color: #92400e; }

/* ---------- Toast (flash message) ---------- */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .12);
    opacity: 0;
    animation: toast-fade 3s ease forwards;
}
.toast-success {
    background: #e6f9f0;
    color: #1b8a5a;
    border: 1px solid #b7ecd4;
}
.toast-warn {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}
@keyframes toast-fade {
    0%   { opacity: 0; transform: translateX(-50%) translateY(-10px); }
    10%  { opacity: 1; transform: translateX(-50%) translateY(0); }
    85%  { opacity: 1; }
    100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* ---------- Detail ---------- */
.detail { display: grid; grid-template-columns: 6fr 5fr; gap: 32px; }
.detail .thumb {
    background: #eef1f4; border-radius: var(--radius);
    aspect-ratio: 1/1; display: flex; align-items: center; justify-content: center;
    color: #aab2bd; overflow: hidden;
}
.detail .thumb img { width: 100%; height: 100%; object-fit: cover; }
.detail .cat {
    font-size: 14px;
    color: var(--muted);
    transition: color .15s;
}
.detail .cat:hover,
.detail .cat:focus-visible {
    color: var(--primary);
    text-decoration: underline;
}
.detail-back-link {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 3px;
    transition: color .15s;
}
.detail-back-link:hover,
.detail-back-link:focus-visible {
    color: var(--primary);
    text-decoration: underline;
}
.detail-title {
    font-size: 30px;
    margin: 10px 0 4px;
}
.detail .price { font-size: 32px; font-weight: 800; margin: 14px 0; }
.detail-sub { font-size: 15px; margin: 6px 0; }
.detail .desc { color: #374151; white-space: pre-wrap; margin: 0; font-size: 15.5px; line-height: 1.7; }
.detail .btn { font-size: 16px; padding: 12px 22px; }
@media (max-width: 720px) { .detail { grid-template-columns: 1fr; } }

/* 상세 페이지 구매 액션 영역: 항상 가격/재고 바로 아래 고정, 설명 길이와 무관 */
.detail-actions {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid var(--line);
}
.detail-actions-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 22px;
}
.detail-actions-buttons .btn {
    flex: 1 1 160px;
}

/* 상품 설명 접기/펼치기 */
.desc-wrap {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid var(--line);
}
.desc {
    position: relative; /* 그라데이션(::after)을 desc 자신 기준으로 붙이기 위함 */
    max-height: 999px; /* 펼친 상태 값. 트랜지션이 동작하려면 두 상태 모두 구체적인 수치가 필요함 */
    overflow: hidden;
    transition: max-height .3s ease;
}
.desc-wrap.collapsed .desc {
    max-height: 8.5em; /* 대략 5줄 */
}
.desc-wrap.collapsed .desc::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    /* desc 자신의 하단에 딱 붙여서, 버튼 크기/여백과 무관하게 항상 마지막 줄 위치에 정확히 겹치도록 함 */
    height: 2.4em;
    background: linear-gradient(180deg, transparent 0%, var(--bg) 85%);
    pointer-events: none;
}
.desc-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    margin: 8px 0 0;
    padding: 12px 0;
    border: none;
    border-radius: 8px;
    background: #f8f9fa;
    color: var(--primary);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s;
}
.desc-toggle::after {
    content: "";
    width: 8px;
    height: 8px;
    border-right: 1.5px solid var(--primary);
    border-bottom: 1.5px solid var(--primary);
    transform: rotate(45deg);
    transition: transform .3s;
}
.desc-wrap:not(.collapsed) .desc-toggle::after {
    transform: rotate(-135deg);
    margin-top: 3px;
}
.desc-toggle:hover { background: #f1f3f5; }
.desc-toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* 상세 페이지 수량 스테퍼 */
.qty-stepper {
    display: flex;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}
.qty-btn {
    width: 48px;
    height: 44px;
    border: none;
    background: #f1f3f5;
    font-size: 20px;
    cursor: pointer;
    color: var(--text);
    transition: background .15s, color .15s;
}
.qty-btn:hover:not(:disabled) {
    background: var(--primary);
    color: #fff;
}
.qty-btn:disabled {
    color: #b8bfc7;
    cursor: not-allowed;
}
.qty-input {
    width: 68px;
    height: 44px;
    border: none;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    text-align: center;
    font-size: 17px;
    -moz-appearance: textfield;
    appearance: textfield;
}
.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.qty-total {
    display: inline-block;
    margin: 10px 0 0;
    font-size: 17px;
    font-weight: 800;
    color: var(--text);
}

/* ---------- Footer ---------- */
/* 상세 스타일은 fragments/footer.html 내부 <style>에서 관리 (flex 레이아웃 하단 고정용 속성만 유지) */
.site-footer {
    flex-shrink: 0;
}

/* ---------- Main(홈) 페이지 ---------- */
.home-section { margin-top: 36px; }
.home-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 14px;
}
.home-section-head .section-title { margin: 0; }
.home-more-link {
    font-size: 13px;
    color: var(--muted);
    transition: color .15s;
}
.home-more-link:hover { color: var(--primary); }

/* 랜덤 상품 마퀴 패널 */
.marquee-panel {
    background: linear-gradient(135deg, rgba(37,99,235,0.07), rgba(37,99,235,0.015) 60%);
    border: 1px solid rgba(37,99,235,0.12);
    border-radius: calc(var(--radius) + 4px);
    padding: 28px 0 14px;
}
.marquee-panel .home-section-head {
    padding: 0 26px;
    margin-bottom: 18px;
}
.marquee-title {
    display: flex;
    align-items: center;
    gap: 8px;
}
.marquee-subtitle {
    margin: 4px 0 0;
    font-size: 13.5px;
    color: var(--muted);
}

.marquee-wrap {
    position: relative;
}
.marquee-viewport {
    overflow: hidden;
    padding: 16px 26px 20px;
    /* 화살표 너비(44px)와 정확히 같은 지점에서 카드가 완전히 선명해지도록 px 기준으로 맞춤.
       (기존 %기준 마스크는 화면 폭에 따라 화살표 경계와 어긋나서, 화살표 바로 옆에서
       카드가 갑자기 튀어나온 것처럼 보이는 문제가 있었음) */
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 44px, #000 calc(100% - 44px), transparent);
    mask-image: linear-gradient(90deg, transparent, #000 44px, #000 calc(100% - 44px), transparent);
}
.marquee-track {
    display: flex;
    gap: 20px;
    width: max-content;
    /* 자동 스크롤은 main.js에서 requestAnimationFrame으로 직접 제어 */
    will-change: transform;
}
.marquee-card {
    flex: 0 0 210px;
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.marquee-card:hover {
    transform: translateY(-6px) scale(1.035);
    box-shadow: 0 12px 24px rgba(37,99,235,0.16);
    border-color: var(--primary);
    z-index: 2;
}
@media (max-width: 480px) {
    .marquee-card { flex-basis: 160px; }
}
@media (prefers-reduced-motion: reduce) {
    .marquee-viewport { overflow-x: auto; }
}

/* 마퀴 좌우 이동 화살표 */
.marquee-arrow {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 3;
    width: 44px;
    border: none;
    background: transparent;
    font-size: 24px;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    /* 카드 이미지/배경이 밝든 어둡든 아이콘이 항상 잘 보이도록 흰색 헤일로를 줌 */
    filter: drop-shadow(0 0 3px rgba(255,255,255,0.9)) drop-shadow(0 0 3px rgba(255,255,255,0.9));
    transition: background .15s;
}
.marquee-arrow:hover,
.marquee-arrow:focus-visible {
    background: rgba(107, 114, 128, 0.16);
}
.marquee-arrow:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}
.marquee-arrow-left { left: 0; border-radius: 8px 0 0 8px; }
.marquee-arrow-right { right: 0; border-radius: 0 8px 8px 0; }
@media (max-width: 480px) {
    .marquee-arrow { width: 34px; font-size: 19px; }
}

/* ---------- 상세 페이지: 같은 카테고리 추천 상품(정적 캐러셀) ---------- */
/* 메인 마퀴와 카드 비주얼(.marquee-card)은 재사용하되, 자동 스크롤은 넣지 않고
   화살표 클릭으로만 이동하는 정적인 캐러셀 */
.related-panel {
    margin-top: 40px;
    padding-top: 32px;
    border-top: 1px solid var(--line);
}
.related-wrap {
    position: relative;
    /* viewport 안쪽 padding-top(18px)을 hover 여유 공간으로 확보하되,
       바깥 레이아웃 간격은 이전과 같아 보이도록 wrap 자체를 위로 당김
       (track에 마이너스 마진을 주면 padding 공간 자체가 상쇄돼 다시 잘리므로
       반드시 overflow 영역 밖인 wrap 레벨에서 보정해야 함) */
    margin-top: -14px;
}
.related-viewport {
    overflow-x: auto;
    scroll-behavior: smooth;
    scroll-snap-type: x proximity;
    /* hover 시 카드가 translateY(-6px) + scale(1.035)로 위로 커지는데,
       overflow-x:auto를 주면 overflow-y도 auto로 강제되어 잘리는 문제가 있어
       위쪽 패딩을 넉넉히 줌 */
    padding: 18px 44px 10px;
    scrollbar-width: none;
}
.related-viewport::-webkit-scrollbar { display: none; }
.related-track {
    display: flex;
    gap: 16px;
    width: max-content;
}
.related-track .marquee-card {
    scroll-snap-align: start;
}
@media (max-width: 480px) {
    .related-viewport { padding: 18px 34px 10px; }
}

/* 전체 상품 보기 배너 */
.home-viewall-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 40px;
    padding: 22px 26px;
    background: linear-gradient(135deg, rgba(37,99,235,0.05), rgba(37,99,235,0.01) 60%);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: border-color .15s, transform .15s;
}
.home-viewall-banner:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}
.home-viewall-text { display: flex; flex-direction: column; gap: 3px; }
.home-viewall-text strong { font-size: 16px; color: var(--text); }
.home-viewall-sub { font-size: 12.5px; color: var(--muted); }
.home-viewall-arrow {
    font-size: 22px;
    color: var(--primary);
    line-height: 1;
}