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

:root {
    --bg:          #f5f5f7;
    --surface:     #ffffff;
    --border:      #d2d2d7;
    --text:        #1d1d1f;
    --muted:       #6e6e73;
    --accent:      #0071e3;
    --accent-h:    #0077ed;
    --red:         #ff3b30;
    --green:       #30a230;
    --radius:      12px;
    --shadow:      0 2px 12px rgba(0,0,0,.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Header ── */
header {
    background: rgba(255,255,255,.85);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 0 24px;
    display: flex;
    align-items: center;
    height: 52px;
    gap: 16px;
}

.logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo svg { width: 22px; height: 22px; }

.header-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.last-updated {
    font-size: 12px;
    color: var(--muted);
}

/* ── Layout ── */
.layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 0;
    max-width: 1440px;
    margin: 0 auto;
}

/* ── Sidebar / Filters ── */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 24px 20px;
    position: sticky;
    top: 52px;
    height: calc(100vh - 52px);
    overflow-y: auto;
}

.filter-section { margin-bottom: 28px; }

.filter-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 10px;
    display: block;
}

.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
    padding: 5px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    font-size: 13px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
    white-space: nowrap;
}

.chip:hover { border-color: var(--accent); color: var(--accent); }

.chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* Price Range */
.price-inputs { display: flex; gap: 8px; align-items: center; }

.price-input {
    flex: 1;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    width: 100%;
}

.price-input:focus { border-color: var(--accent); }

.price-sep { color: var(--muted); font-size: 13px; }

.apply-btn {
    width: 100%;
    margin-top: 10px;
    padding: 8px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s;
}

.apply-btn:hover { background: var(--accent-h); }

/* ── View toggle ── */
.view-toggle { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 8px; }

.view-btn {
    padding: 5px 14px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    background: transparent;
    color: var(--muted);
    transition: background .15s, color .15s;
}

.view-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ── Main content ── */
.main {
    padding: 24px;
    min-height: calc(100vh - 52px);
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.result-count { font-size: 14px; color: var(--muted); }

.sort-select {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    outline: none;
    margin-left: auto;
}

/* ── Product Grid ── */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.product-card {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform .2s, box-shadow .2s;
    display: flex;
    flex-direction: column;
}

.product-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
}

.product-image {
    aspect-ratio: 1 / 1;
    background: #f0f0f3;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 16px;
}

.product-image .no-img {
    font-size: 48px;
    opacity: .3;
}

.product-info { padding: 12px; flex: 1; display: flex; flex-direction: column; gap: 6px; }

.product-store {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.product-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-price { margin-top: auto; }

.price-current {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.price-original {
    font-size: 12px;
    color: var(--muted);
    text-decoration: line-through;
}

.price-discount {
    font-size: 12px;
    font-weight: 600;
    color: var(--red);
}

.buy-btn {
    display: block;
    margin: 10px 12px 12px;
    padding: 8px;
    background: var(--accent);
    color: #fff;
    border-radius: 8px;
    text-align: center;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: background .15s;
}

.buy-btn:hover { background: var(--accent-h); }

/* ── Grouped View ── */
.group-grid { display: flex; flex-direction: column; gap: 16px; }

.group-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.group-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.group-thumb {
    width: 72px;
    height: 72px;
    border-radius: 8px;
    object-fit: contain;
    background: #f0f0f3;
    flex-shrink: 0;
    padding: 8px;
}

.group-thumb-placeholder {
    width: 72px;
    height: 72px;
    border-radius: 8px;
    background: #f0f0f3;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    flex-shrink: 0;
}

.group-meta { flex: 1 }

.group-name { font-size: 15px; font-weight: 600; margin-bottom: 4px; }

.group-category {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.group-min-price {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
}

.group-body { padding: 12px 16px; display: flex; gap: 8px; flex-wrap: wrap; }

.store-price-tag {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text);
    font-size: 13px;
    transition: border-color .15s, background .15s;
    flex: 1;
    min-width: 140px;
    max-width: 220px;
}

.store-price-tag:hover { border-color: var(--accent); background: #f0f5ff; }

.store-price-tag.cheapest { border-color: var(--green); background: #f0fff4; }

.store-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--bg);
}

.store-tag-price { font-weight: 700; margin-left: auto; }

/* ── Loading / Empty ── */
.loading, .empty {
    text-align: center;
    padding: 80px 20px;
    color: var(--muted);
}

.loading::after {
    content: '';
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

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

/* ── Pagination ── */
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 32px;
    flex-wrap: wrap;
}

.page-btn {
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}

.page-btn:hover { border-color: var(--accent); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: default; }

/* ── Store color badges ── */
.store-himart  { background: #fff0f0; color: #c00; }
.store-ssg     { background: #fff8e1; color: #b7670b; }
.store-coupang { background: #e8f4fd; color: #0062c4; }

/* ── Footer ── */
.site-footer {
    grid-column: 1 / -1;
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.site-footer p {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.6;
}

/* ── Search ── */
.search-wrap {
    position: relative;
    flex: 1;
    max-width: 320px;
}

.search-input {
    width: 100%;
    padding: 7px 32px 7px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: var(--surface);
    color: var(--text);
    outline: none;
}

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

.search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 13px;
    padding: 0 2px;
    line-height: 1;
}

/* ── Vote Buttons ── */
.vote-row {
    display: flex;
    gap: 6px;
    margin: 6px 12px 10px;
}

.vote-btn {
    flex: 1;
    padding: 6px 4px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: background .15s, border-color .15s, color .15s;
}

.vote-btn:hover { border-color: var(--accent); color: var(--accent); }

.vote-btn.voted-up   { background: #f0fff4; border-color: var(--green); color: var(--green); font-weight: 600; }
.vote-btn.voted-down { background: #fff0f0; border-color: var(--red);   color: var(--red);   font-weight: 600; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
    .product-grid { grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); }
}
