/* ── Reset & Base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --accent: #34a853;
    --danger: #ea4335;
    --bg: #f5f6fa;
    --white: #ffffff;
    --text: #202124;
    --text-light: #5f6368;
    --border: #e0e0e0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-hover: 0 4px 12px rgba(0,0,0,0.15);
    --radius: 8px;
    --max-width: 1280px;
}

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

/* ── Header ──────────────────────────────────────── */
.header {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 24px;
    height: 60px;
}

.logo {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
}
.logo:hover { text-decoration: none; }

.search-box {
    flex: 1;
    max-width: 480px;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 8px 40px 8px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}
.search-box input:focus { border-color: var(--primary); }

.search-box button {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 10px;
    color: var(--text-light);
    font-size: 1.1rem;
}

.nav-links {
    display: flex;
    gap: 8px;
    list-style: none;
}
.nav-links a {
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.85rem;
    color: var(--text);
    white-space: nowrap;
    transition: background 0.2s;
}
.nav-links a:hover {
    background: var(--bg);
    text-decoration: none;
}

/* ── Hero ─────────────────────────────────────────── */
.hero {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: var(--white);
    text-align: center;
    padding: 48px 16px;
}
.hero h1 { font-size: 1.8rem; margin-bottom: 8px; }
.hero p { font-size: 1.1rem; opacity: 0.9; }

/* ── Container ────────────────────────────────────── */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 24px 16px;
}

/* ── Section titles ───────────────────────────────── */
.section-title {
    font-size: 1.3rem;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary);
    display: inline-block;
}

/* ── Category Grid (homepage) ─────────────────────── */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 40px;
}

.category-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px 16px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s, transform 0.2s;
    cursor: pointer;
    display: block;
    color: var(--text);
}
.category-card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
    text-decoration: none;
}

.category-card .cat-icon {
    font-size: 2.2rem;
    margin-bottom: 8px;
}

.category-card .cat-name {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.category-card .cat-count {
    font-size: 0.8rem;
    color: var(--text-light);
}

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

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

.product-card a {
    color: inherit;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.product-card .card-img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    padding: 12px;
    background: #fafafa;
}

.product-card .card-body {
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.product-card .card-title {
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 8px;
}

.product-card .card-price {
    margin-top: auto;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--primary);
}

.product-card .card-meta {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 4px;
}

.product-card .discount-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--danger);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.product-card .card-img-wrap {
    position: relative;
}

/* ── Category Page Layout ─────────────────────────── */
.category-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 24px;
    align-items: start;
}

/* ── Sidebar ──────────────────────────────────────── */
.sidebar {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    position: sticky;
    top: 76px;
}

.sidebar h3 {
    font-size: 0.95rem;
    margin-bottom: 12px;
    color: var(--text);
}

.filter-group {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.filter-group:last-child { border-bottom: none; }

.filter-group label {
    display: block;
    font-size: 0.85rem;
    margin-bottom: 6px;
    color: var(--text-light);
}

.filter-group input[type="number"] {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.9rem;
    outline: none;
}
.filter-group input[type="number"]:focus { border-color: var(--primary); }

.price-inputs {
    display: flex;
    gap: 8px;
    align-items: center;
}
.price-inputs input { flex: 1; }
.price-inputs span { color: var(--text-light); font-size: 0.85rem; }

.filter-group select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.9rem;
    outline: none;
    background: var(--white);
}

.brand-list {
    max-height: 200px;
    overflow-y: auto;
    list-style: none;
}

.brand-list li {
    margin-bottom: 4px;
}

.brand-list label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text);
    margin-bottom: 0;
}

.brand-list input[type="checkbox"] {
    accent-color: var(--primary);
}

.btn-filter {
    width: 100%;
    padding: 8px;
    background: var(--primary);
    color: var(--white);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.2s;
}
.btn-filter:hover { background: var(--primary-dark); }

.btn-clear {
    width: 100%;
    padding: 8px;
    background: none;
    color: var(--text-light);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    margin-top: 8px;
    transition: background 0.2s;
}
.btn-clear:hover { background: var(--bg); }

/* ── Pagination ───────────────────────────────────── */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.pagination button {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--white);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}
.pagination button:hover { background: var(--bg); }
.pagination button.active {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}
.pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Product Detail ───────────────────────────────── */
.product-detail {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
}

.product-image-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fafafa;
    border-radius: var(--radius);
    padding: 24px;
}

.product-image-wrap img {
    max-height: 400px;
    object-fit: contain;
}

.product-info h1 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.product-meta {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-bottom: 20px;
}

.product-meta span {
    display: inline-block;
    margin-right: 16px;
}

.breadcrumb {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 16px;
}
.breadcrumb a { color: var(--primary); }

/* ── Price Table ──────────────────────────────────── */
.price-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
}

.price-table th {
    text-align: left;
    padding: 10px 12px;
    background: var(--bg);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-light);
    border-bottom: 2px solid var(--border);
}

.price-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
}

.price-table tr:last-child td { border-bottom: none; }

.price-table .best-price {
    background: #e8f5e9;
}

.price-table .best-badge {
    display: inline-block;
    background: var(--accent);
    color: white;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
    font-weight: 600;
}

.price-table .old-price {
    text-decoration: line-through;
    color: var(--text-light);
    font-size: 0.85rem;
}

.btn-retailer {
    display: inline-block;
    padding: 6px 16px;
    background: var(--primary);
    color: var(--white);
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.2s;
}
.btn-retailer:hover {
    background: var(--primary-dark);
    text-decoration: none;
}

.last-updated {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 12px;
}

.price-chart-wrap {
    margin-top: 32px;
}
.price-chart-wrap canvas {
    width: 100% !important;
    height: 300px !important;
}

/* ── Footer ───────────────────────────────────────── */
.footer {
    background: var(--white);
    border-top: 1px solid var(--border);
    padding: 24px 16px;
    margin-top: 48px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-light);
}
.footer p { margin-bottom: 4px; }

/* ── Loading / Empty ──────────────────────────────── */
.loading {
    text-align: center;
    padding: 48px;
    color: var(--text-light);
}
.loading::after {
    content: '';
    display: block;
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 16px auto 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
    text-align: center;
    padding: 48px;
    color: var(--text-light);
}
.empty-state p { margin-bottom: 8px; }

/* ── Category page title bar ──────────────────────── */
.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.category-header h1 {
    font-size: 1.3rem;
}

.results-count {
    font-size: 0.85rem;
    color: var(--text-light);
}

/* ── Mobile nav toggle ────────────────────────────── */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px;
    color: var(--text);
}

.sidebar-toggle {
    display: none;
    width: 100%;
    padding: 10px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    margin-bottom: 12px;
    text-align: center;
}

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 900px) {
    .category-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        display: none;
    }
    .sidebar.open { display: block; }
    .sidebar-toggle { display: block; }
}

@media (max-width: 768px) {
    .nav-links { display: none; }
    .nav-links.open { display: flex; flex-wrap: wrap; }
    .nav-toggle { display: block; }

    .header-inner { flex-wrap: wrap; }

    .hero h1 { font-size: 1.3rem; }
    .hero p { font-size: 0.95rem; }

    .product-detail {
        grid-template-columns: 1fr;
    }

    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 12px;
    }

    .category-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}

@media (max-width: 480px) {
    .search-box { max-width: 100%; order: 3; width: 100%; margin-top: 8px; }
    .header-inner { height: auto; padding: 10px 16px; }

    .product-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .product-card .card-body { padding: 8px; }
    .product-card .card-title { font-size: 0.8rem; }
    .product-card .card-price { font-size: 0.9rem; }
}
