/**
 * MS Freshora — Homepage presentation layer
 * All class names preserved for JS/backend hooks.
 */

:root {
    --fresh-green: #16a34a;
    --fresh-green-2: #22c55e;
    --fresh-green-3: #86efac;
    --fresh-dark: #0f172a;
    --fresh-ink: #111827;
    --fresh-muted: #64748b;
    --fresh-soft: #f8fafc;
    --fresh-line: #e2e8f0;
    --fresh-card: #ffffff;
    --fresh-gold: #f59e0b;
    --fresh-blue: #0ea5e9;
    --fresh-red: #dc2626;
    --fresh-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    --fresh-shadow-heavy: 0 16px 40px rgba(15, 23, 42, 0.08);
    --mf-radius: 14px;
    --mf-radius-lg: 18px;
    --mf-touch: 40px;
}

/* ─── Page shell ─── */
.grocery-page {
    background: linear-gradient(180deg, #f6faf7 0%, #f8fafc 48%, #f1f5f3 100%);
    padding: 16px 0 64px;
    min-height: 100vh;
}

.grocery-wrap {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ─── Compact hero ─── */
.top-hero {
    background: var(--fresh-card);
    border: 1px solid #e8f0ea;
    border-radius: var(--mf-radius-lg);
    padding: 20px 22px;
    display: grid;
    grid-template-columns: 1fr minmax(200px, 280px);
    gap: 20px;
    align-items: center;
    box-shadow: var(--fresh-shadow);
    margin-bottom: 16px;
}

.hero-content {
    min-width: 0;
}

.hero-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #ecfdf5;
    color: #15803d;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    margin-bottom: 10px;
    border: 1px solid #bbf7d0;
    letter-spacing: 0.02em;
}

.hero-tag::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--fresh-green-2);
}

.top-hero h1 {
    font-size: clamp(22px, 3.2vw, 34px);
    font-weight: 800;
    color: var(--fresh-dark);
    margin: 0 0 8px;
    line-height: 1.15;
    letter-spacing: -0.04em;
    max-width: 560px;
}

.top-hero p {
    color: var(--fresh-muted);
    font-size: 14px;
    margin-bottom: 14px;
    line-height: 1.55;
    font-weight: 500;
    max-width: 520px;
}

/* ─── Search ─── */
.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--fresh-soft);
    border: 1px solid var(--fresh-line);
    border-radius: var(--mf-radius);
    padding: 4px 4px 4px 12px;
    max-width: 100%;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-box:focus-within {
    border-color: var(--fresh-green-2);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14);
    background: #fff;
}

.search-box span {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #ecfdf5;
    border: none;
    flex: 0 0 auto;
    font-size: 0;
}

.search-box span::before {
    content: "⌕";
    font-size: 17px;
    color: var(--fresh-green);
    font-weight: 800;
}

.search-box input {
    width: 100%;
    border: none;
    outline: none;
    font-size: 14px;
    background: transparent;
    color: var(--fresh-ink);
    font-weight: 600;
    min-width: 0;
}

.search-box input::placeholder {
    color: #94a3b8;
    font-weight: 500;
}

.search-box button,
.filter-btn,
.add-cart-btn,
.go-cart-btn {
    border: none;
    background: var(--fresh-green);
    color: #fff;
    border-radius: 10px;
    padding: 10px 16px;
    font-weight: 800;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
    white-space: nowrap;
}

.search-box button:hover,
.filter-btn:hover,
.add-cart-btn:hover,
.go-cart-btn:hover {
    background: #15803d;
    color: #fff;
    transform: translateY(-1px);
}

.hero-card {
    background: linear-gradient(145deg, #0f172a 0%, #14532d 100%);
    color: #fff;
    border-radius: var(--mf-radius-lg);
    padding: 18px 20px;
    min-height: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.hero-card h3 {
    font-size: 18px;
    font-weight: 800;
    margin: 0 0 6px;
    letter-spacing: -0.02em;
}

.hero-card p {
    color: #bbf7d0;
    margin: 0;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.5;
}

/* ─── Trust strip ─── */
.mini-info-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.mini-info {
    background: var(--fresh-card);
    border-radius: var(--mf-radius);
    padding: 12px 14px;
    box-shadow: var(--fresh-shadow);
    border: 1px solid #eef2f6;
    transition: border-color 0.2s ease;
}

.mini-info:hover {
    border-color: #bbf7d0;
}

.mini-info strong {
    display: block;
    font-size: 12px;
    color: var(--fresh-ink);
    margin-bottom: 2px;
    font-weight: 800;
    line-height: 1.3;
}

.mini-info span {
    font-size: 11px;
    color: var(--fresh-muted);
    font-weight: 600;
    line-height: 1.35;
}

/* ─── Section headings ─── */
.section-title {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
    margin: 28px 0 12px;
}

.section-title h2 {
    font-size: clamp(18px, 2.2vw, 22px);
    font-weight: 800;
    color: var(--fresh-dark);
    margin: 0;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.section-title p {
    margin: 4px 0 0;
    color: var(--fresh-muted);
    font-size: 12px;
    font-weight: 600;
}

.clear-filter {
    text-decoration: none;
    color: #15803d;
    font-weight: 800;
    font-size: 12px;
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
    padding: 8px 14px;
    border-radius: 999px;
    transition: background 0.15s ease, color 0.15s ease;
    white-space: nowrap;
}

.clear-filter:hover {
    background: var(--fresh-green);
    color: #fff;
}

.clear-filter:focus-visible {
    outline: 2px solid var(--fresh-green-2);
    outline-offset: 2px;
}

/* ─── Categories ─── */
.category-row {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 2px 2px 10px;
    margin-bottom: 16px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #86efac #f1f5f9;
}

.category-row::-webkit-scrollbar {
    height: 5px;
}

.category-row::-webkit-scrollbar-thumb {
    background: #86efac;
    border-radius: 999px;
}

.category-pill {
    min-width: 100px;
    max-width: 120px;
    flex: 0 0 auto;
    background: var(--fresh-card);
    border: 1px solid var(--fresh-line);
    border-radius: var(--mf-radius);
    padding: 8px;
    text-decoration: none;
    color: var(--fresh-ink);
    box-shadow: var(--fresh-shadow);
    transition: border-color 0.15s ease, transform 0.15s ease;
    scroll-snap-align: start;
}

.category-pill:hover {
    transform: translateY(-2px);
    border-color: #86efac;
    color: var(--fresh-ink);
}

.category-pill.active {
    border: 2px solid var(--fresh-green-2);
    background: #ecfdf5;
    box-shadow: 0 4px 16px rgba(34, 197, 94, 0.15);
}

.category-pill:focus-visible {
    outline: 2px solid var(--fresh-green-2);
    outline-offset: 2px;
}

.category-pill img {
    width: 100%;
    height: 64px;
    object-fit: cover;
    border-radius: 10px;
    margin-bottom: 6px;
    background: var(--fresh-soft);
}

.category-pill h6 {
    font-size: 11px;
    font-weight: 800;
    margin: 0;
    text-align: center;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ─── Filter panel ─── */
.filter-panel {
    background: var(--fresh-card);
    border: 1px solid #e8f0ea;
    border-radius: var(--mf-radius-lg);
    padding: 14px;
    margin: 12px 0 20px;
    display: grid;
    grid-template-columns: 1fr 150px 150px auto;
    gap: 10px;
    align-items: end;
    box-shadow: var(--fresh-shadow);
    position: sticky;
    top: 8px;
    z-index: 5;
}

.filter-field label {
    display: block;
    font-size: 11px;
    color: var(--fresh-muted);
    font-weight: 800;
    margin-bottom: 5px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.filter-field input,
.filter-field select {
    width: 100%;
    height: 40px;
    border: 1px solid var(--fresh-line);
    border-radius: 10px;
    padding: 0 12px;
    outline: none;
    color: var(--fresh-ink);
    font-size: 13px;
    font-weight: 600;
    background: var(--fresh-soft);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.filter-field input:focus,
.filter-field select:focus {
    border-color: var(--fresh-green-2);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.12);
    background: #fff;
}

.filter-btn {
    height: 40px;
    min-width: 88px;
}

/* ─── Product grids ─── */
.product-strip,
.product-grid {
    display: grid;
    gap: 12px;
}

.product-strip {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.product-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

/* ─── Product card ─── */
.product-card {
    background: var(--fresh-card);
    border: 1px solid #eef2f6;
    border-radius: var(--mf-radius);
    overflow: hidden;
    box-shadow: var(--fresh-shadow);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0;
}

.product-card:hover {
    border-color: #bbf7d0;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
    transform: translateY(-2px);
}

.product-img {
    height: 118px;
    background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
    position: relative;
    overflow: hidden;
    padding: 8px;
}

.product-img img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.2s ease;
}

.product-card:hover .product-img img {
    transform: scale(1.03);
}

.deal-label,
.type-label,
.section-label {
    position: absolute;
    border-radius: 999px;
    padding: 3px 7px;
    font-size: 9px;
    font-weight: 800;
    z-index: 2;
    line-height: 1.2;
    letter-spacing: 0.02em;
}

.deal-label {
    left: 6px;
    top: 6px;
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.type-label {
    right: 6px;
    top: 6px;
    background: #e0f2fe;
    color: #0369a1;
    border: 1px solid #bae6fd;
}

.type-label.loose {
    background: #fff7ed;
    color: #9a3412;
    border-color: #fed7aa;
}

.section-label {
    left: 6px;
    bottom: 6px;
    background: rgba(15, 23, 42, 0.88);
    color: #fff;
    border: none;
}

.product-body {
    padding: 10px;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    gap: 0;
}

.product-name {
    font-size: 12px;
    font-weight: 800;
    color: var(--fresh-ink);
    margin-bottom: 4px;
    line-height: 1.3;
    min-height: 31px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    order: 1;
}

.product-meta {
    color: var(--fresh-muted);
    font-size: 10px;
    margin-bottom: 4px;
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    order: 2;
}

.unit-meta {
    display: inline-flex;
    width: fit-content;
    max-width: 100%;
    background: var(--fresh-soft);
    border: 1px solid var(--fresh-line);
    color: #475569;
    border-radius: 999px;
    padding: 3px 7px;
    font-size: 9px;
    font-weight: 800;
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    order: 3;
}

.price-row {
    display: flex;
    align-items: baseline;
    gap: 5px;
    margin-bottom: 2px;
    flex-wrap: wrap;
    order: 4;
}

.sell-price {
    color: var(--fresh-green);
    font-size: 15px;
    font-weight: 900;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.mrp {
    color: #94a3b8;
    font-size: 10px;
    text-decoration: line-through;
    font-weight: 600;
}

.price-unit {
    color: var(--fresh-muted);
    font-size: 9px;
    font-weight: 600;
    margin-bottom: 5px;
    line-height: 1.2;
    order: 5;
}

.stock-line {
    color: #15803d;
    font-size: 9px;
    margin-bottom: 6px;
    font-weight: 700;
    background: #f0fdf4;
    border: 1px solid #dcfce7;
    padding: 4px 6px;
    border-radius: 8px;
    width: fit-content;
    max-width: 100%;
    line-height: 1.25;
    order: 6;
}

.low-stock {
    color: var(--fresh-red);
    background: #fff1f2;
    border-color: #fecdd3;
}

.add-cart-form {
    margin-top: auto;
    order: 8;
}

.qty-row {
    display: grid;
    grid-template-columns: var(--mf-touch) 1fr var(--mf-touch);
    gap: 6px;
    margin-bottom: 6px;
}

.qty-btn {
    min-height: 36px;
    height: 36px;
    border: 1px solid var(--fresh-green-2);
    background: #f0fdf4;
    color: #15803d;
    border-radius: 10px;
    font-weight: 800;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.qty-btn:hover:not(:disabled) {
    background: var(--fresh-green-2);
    color: #fff;
}

.qty-btn:focus-visible {
    outline: 2px solid var(--fresh-green-2);
    outline-offset: 2px;
}

.qty-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: var(--fresh-soft);
    color: #94a3b8;
    border-color: var(--fresh-line);
}

.qty-input {
    height: 36px;
    min-height: 36px;
    border: 1px solid var(--fresh-line);
    border-radius: 10px;
    text-align: center;
    font-weight: 800;
    color: var(--fresh-ink);
    background: #fff;
    width: 100%;
    font-size: 13px;
}

.qty-input:focus-visible {
    outline: 2px solid var(--fresh-green-2);
    outline-offset: 1px;
}

.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.selected-qty-text {
    font-size: 9px;
    color: var(--fresh-muted);
    font-weight: 700;
    margin-bottom: 6px;
    text-align: center;
    background: var(--fresh-soft);
    border: 1px solid #edf2f7;
    border-radius: 8px;
    padding: 4px 6px;
    line-height: 1.25;
}

.add-cart-btn,
.go-cart-btn {
    width: 100%;
    display: block;
    text-align: center;
    text-decoration: none;
    font-size: 12px;
    padding: 9px 8px;
    border-radius: 10px;
    font-weight: 800;
    line-height: 1.2;
}

.go-cart-btn {
    background: var(--fresh-dark);
    margin-top: auto;
    order: 8;
}

.go-cart-btn:hover {
    background: #020617;
}

.view-link {
    display: block;
    text-align: center;
    border: 1px solid var(--fresh-green-2);
    color: var(--fresh-green);
    background: #fff;
    border-radius: 10px;
    padding: 7px 8px;
    font-weight: 800;
    font-size: 11px;
    text-decoration: none;
    margin-top: 6px;
    transition: background 0.15s ease, color 0.15s ease;
    order: 9;
}

.view-link:hover {
    background: var(--fresh-green);
    color: #fff;
}

.view-link:focus-visible {
    outline: 2px solid var(--fresh-green-2);
    outline-offset: 2px;
}

.empty-state {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
    border-radius: var(--mf-radius-lg);
    padding: 20px;
    grid-column: 1 / -1;
    font-weight: 600;
    font-size: 14px;
    line-height: 1.6;
}

.empty-state a {
    color: #15803d;
    font-weight: 800;
    text-decoration: none;
}

.empty-state a:hover {
    text-decoration: underline;
}

/* ─── Section rhythm: curated strips vs main catalog ─── */
.product-strip {
    padding-bottom: 4px;
}

/* Deals section accent via adjacent structure — strip cards slightly warmer border */
section:has(.product-strip) .product-card {
    border-color: #f0f4f2;
}

section:has(.product-grid) .section-title {
    margin-top: 32px;
    padding-top: 8px;
    border-top: 1px solid #e8f0ea;
}

/* ─── Large desktop density ─── */
@media (min-width: 1600px) {
    .grocery-wrap {
        max-width: 1520px;
    }

    .product-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }

    .product-strip {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}

@media (min-width: 1920px) {
    .grocery-wrap {
        max-width: 1600px;
        padding: 0 20px;
    }

    .product-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 14px;
    }
}

/* ─── Desktop breakpoints ─── */
@media (max-width: 1440px) {
    .product-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}

@media (max-width: 1280px) {
    .product-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .product-strip {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 1024px) {
    .top-hero {
        grid-template-columns: 1fr;
    }

    .hero-card {
        max-width: 100%;
    }

    .mini-info-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .product-grid,
    .product-strip {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .filter-panel {
        grid-template-columns: 1fr 1fr;
        position: relative;
        top: auto;
    }
}

@media (max-width: 820px) {
    .product-grid,
    .product-strip {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* ─── Mobile: 2-col grid + horizontal strip rails ─── */
@media (max-width: 768px) {
    .grocery-page {
        padding: 12px 0 72px;
    }

    .grocery-wrap {
        padding: 0 12px;
    }

    .top-hero {
        padding: 16px;
        gap: 14px;
    }

    .top-hero h1 {
        font-size: 22px;
    }

    .top-hero p {
        font-size: 13px;
        margin-bottom: 12px;
    }

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

    .mini-info {
        padding: 10px 12px;
    }

    .filter-panel {
        grid-template-columns: 1fr;
        padding: 12px;
        top: auto;
    }

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

    /* Curated sections: horizontal scroll rail */
    .product-strip {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 10px;
        padding-bottom: 8px;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .product-strip::-webkit-scrollbar {
        display: none;
    }

    .product-strip .product-card {
        flex: 0 0 calc(50% - 5px);
        min-width: 158px;
        max-width: 200px;
        scroll-snap-align: start;
    }

    .product-img {
        height: 108px;
    }

    .product-body {
        padding: 8px;
    }

    .sell-price {
        font-size: 14px;
    }

    .qty-row {
        grid-template-columns: 36px 1fr 36px;
    }

    .qty-btn,
    .qty-input {
        min-height: 38px;
        height: 38px;
    }

    .search-box {
        flex-wrap: wrap;
        padding: 8px;
    }

    .search-box button {
        width: 100%;
    }

    .section-title {
        margin-top: 22px;
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (max-width: 430px) {
    .grocery-wrap {
        padding: 0 10px;
    }

    .product-grid {
        gap: 8px;
    }

    .product-strip .product-card {
        flex: 0 0 46%;
        min-width: 148px;
    }

    .product-img {
        height: 100px;
    }

    .product-name {
        font-size: 11px;
        min-height: 28px;
    }

    .category-pill {
        min-width: 88px;
        max-width: 100px;
        padding: 6px;
    }

    .category-pill img {
        height: 56px;
    }

    .category-pill h6 {
        font-size: 10px;
    }
}

@media (max-width: 360px) {
    .qty-row {
        grid-template-columns: 34px 1fr 34px;
        gap: 4px;
    }

    .add-cart-btn,
    .go-cart-btn,
    .view-link {
        font-size: 11px;
        padding: 8px 6px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .product-card,
    .category-pill,
    .mini-info,
    .search-box button,
    .filter-btn,
    .add-cart-btn,
    .go-cart-btn,
    .view-link,
    .qty-btn,
    .product-img img {
        transition: none;
    }

    .product-card:hover {
        transform: none;
    }
}
