/* ============================================================
   William E-Shop — Mobile-first redesign
   ============================================================ */
:root {
    --bg: #f4f1ea;
    --surface: #ffffff;
    --accent: #8b0000;
    --accent-dark: #6f1d1b;
    --whatsapp: #25d366;
    --text: #2c2c2c;
    --text-light: #777;
    --border: #e5e1d8;
    --radius: 12px;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 -4px 24px rgba(0, 0, 0, 0.18);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

body {
    font-family: 'Noto Sans SC', 'Poppins', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

body.no-scroll { overflow: hidden; }

button { font-family: inherit; cursor: pointer; border: none; background: none; }
img { display: block; max-width: 100%; }

/* ============ Header ============ */
.site-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #1a1f24 0%, #2b343c 100%);
    color: #fff;
}

.header-logo { width: 42px; height: 42px; object-fit: contain; border-radius: 8px; }

.header-text h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.3px; }
.header-text p { font-size: 0.75rem; color: #b8c2cc; }

/* ============ Store banner ============ */
.store-banner {
    background: var(--bg);
    overflow: hidden;
}

.store-banner img {
    width: 100%;
    height: auto;
    aspect-ratio: 1900 / 377;
    object-fit: cover;
    object-position: center;
}

@media (max-width: 600px) {
    .store-banner img {
        height: 96px;
        object-position: 42% center;
    }
}

/* ============ Sticky toolbar (search + filter) ============ */
.toolbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--surface);
    padding: 10px 12px 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
}

.toolbar-row { display: flex; gap: 8px; align-items: center; }

.search-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    background: #f1efe9;
    border-radius: 22px;
    padding: 0 12px;
    height: 42px;
}

.search-icon { color: #999; flex-shrink: 0; }

.search-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0 10px;
    font-size: 16px; /* prevents iOS zoom */
    outline: none;
    min-width: 0;
}
.search-input::-webkit-search-cancel-button { display: none; }

.search-clear-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #ddd8cc;
    color: #555;
    font-size: 16px;
    flex-shrink: 0;
}

.filter-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 5px;
    height: 42px;
    padding: 0 16px;
    border-radius: 22px;
    background: var(--accent);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 500;
    flex-shrink: 0;
}
.filter-btn:active { transform: scale(0.96); }

.filter-badge {
    position: absolute;
    top: -4px;
    right: -2px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: #ffc107;
    color: #5d4000;
    font-size: 0.7rem;
    font-weight: 700;
    border: 2px solid var(--surface);
}

/* Active filter chips below search */
.active-filters { display: flex; gap: 6px; flex-wrap: wrap; padding-top: 8px; }

.active-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #fdeaea;
    color: var(--accent);
    border: 1px solid #f1c5c5;
    border-radius: 16px;
    padding: 4px 6px 4px 12px;
    font-size: 0.82rem;
    font-weight: 500;
}
.active-chip button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
}

.result-info {
    padding: 10px 16px 0;
    font-size: 0.85rem;
    color: var(--text-light);
    display: none;
}

/* ============ Product grid ============ */
.product-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 12px;
    max-width: 1200px;
    margin: 0 auto;
}

@media (min-width: 600px)  { .product-grid { grid-template-columns: repeat(3, 1fr); gap: 14px; } }
@media (min-width: 900px)  { .product-grid { grid-template-columns: repeat(4, 1fr); gap: 16px; } }
@media (min-width: 1150px) { .product-grid { grid-template-columns: repeat(5, 1fr); } }

.product {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.15s ease;
    display: flex;
    flex-direction: column;
}
.product:active { transform: scale(0.98); }

.product-cover {
    aspect-ratio: 3 / 4;
    background: #f7f5f0;
    overflow: hidden;
}
.product-cover img { width: 100%; height: 100%; object-fit: cover; }

.product-info {
    padding: 8px 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.category-badge {
    align-self: flex-start;
    background: #fdeaea;
    color: var(--accent);
    font-size: 0.68rem;
    font-weight: 600;
    border-radius: 4px;
    padding: 2px 6px;
    white-space: nowrap;
}

.product-name {
    font-size: 0.86rem;
    font-weight: 500;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.3em;
}

.product-bottom {
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.product-price {
    color: var(--accent);
    font-weight: 700;
    font-size: 0.95rem;
}

.quick-add-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    flex-shrink: 0;
    transition: transform 0.15s ease, background 0.2s;
}
.quick-add-btn:active, .quick-add-btn.btn-clicked {
    transform: scale(1.15);
    background: var(--accent-dark);
}

/* Empty state */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}
.empty-icon { font-size: 2.6rem; margin-bottom: 10px; }
.btn-reset-inline {
    margin-top: 14px;
    padding: 10px 22px;
    border-radius: 22px;
    background: var(--accent);
    color: #fff;
    font-size: 0.9rem;
}

/* Load status */
#scroll-sentinel { height: 1px; }
.load-status {
    text-align: center;
    color: var(--text-light);
    font-size: 0.82rem;
    padding: 16px 0 90px;
}

/* ============ Bottom sheets (shared) ============ */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 90;
}
.sheet-backdrop.show { opacity: 1; pointer-events: auto; }

.filter-sheet, .detail-sheet, .cart-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--surface);
    border-radius: 18px 18px 0 0;
    box-shadow: var(--shadow-lg);
    transform: translateY(105%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 100;
    display: flex;
    flex-direction: column;
    max-height: 88vh;
    max-height: 88dvh;
}
.filter-sheet.open, .detail-sheet.open, .cart-sheet.open { transform: translateY(0); }

.sheet-handle {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: #d9d4c8;
    margin: 10px auto 2px;
    flex-shrink: 0;
}

.sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 18px 10px;
    flex-shrink: 0;
}
.sheet-header h2 { font-size: 1.05rem; font-weight: 700; }

.sheet-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #f1efe9;
    color: #555;
    font-size: 20px;
}

/* ============ Filter sheet ============ */
.sheet-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 16px 16px;
    flex: 1;
}

.filter-group { margin-bottom: 16px; }

.filter-group-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 8px;
    display: flex;
    align-items: baseline;
    gap: 8px;
}
.group-total { font-size: 0.75rem; font-weight: 400; color: var(--text-light); }

.filter-chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 9px 14px;
    border-radius: 20px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.86rem;
    transition: all 0.15s ease;
}
.chip-count { font-size: 0.72rem; color: var(--text-light); }

.chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}
.chip.active .chip-count { color: rgba(255, 255, 255, 0.8); }

.sheet-footer {
    display: flex;
    gap: 10px;
    padding: 12px 16px calc(12px + var(--safe-bottom));
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--surface);
}

.btn-reset {
    flex: 1;
    height: 46px;
    border-radius: 23px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    font-size: 0.95rem;
    color: var(--text);
}

.btn-apply {
    flex: 2;
    height: 46px;
    border-radius: 23px;
    background: var(--accent);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
}
.btn-apply:active { background: var(--accent-dark); }

/* ============ Detail sheet ============ */
.detail-close {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 2;
}

.detail-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 6px 18px 16px;
    flex: 1;
}

.detail-cover {
    position: relative;
    width: 55%;
    max-width: 220px;
    margin: 4px auto 14px;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
    cursor: zoom-in;
}
.detail-cover img { width: 100%; aspect-ratio: 3/4; object-fit: cover; }

.zoom-hint {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 0.68rem;
    padding: 3px 8px;
    border-radius: 10px;
}

.detail-info h2 { font-size: 1.1rem; line-height: 1.4; margin: 6px 0 4px; }

.detail-price {
    color: var(--accent);
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.detail-desc { font-size: 0.9rem; color: #555; line-height: 1.7; }

.detail-meta {
    margin-top: 12px;
    font-size: 0.8rem;
    color: var(--text-light);
    background: #f7f5f0;
    border-radius: 8px;
    padding: 8px 12px;
}

.detail-footer {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px 16px calc(12px + var(--safe-bottom));
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--surface);
}

.detail-qty {
    display: flex;
    align-items: center;
    gap: 4px;
    border: 1.5px solid var(--border);
    border-radius: 23px;
    padding: 4px;
}
.detail-qty span { min-width: 32px; text-align: center; font-weight: 600; }

.qty-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #f1efe9;
    color: var(--text);
    font-size: 18px;
    line-height: 1;
}
.qty-btn:active { background: #e3dfd3; }

.btn-add-detail {
    flex: 1;
    height: 48px;
    border-radius: 24px;
    background: var(--accent);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
}
.btn-add-detail:active { background: var(--accent-dark); }

/* ============ Cart sheet ============ */
.cart-header-count { color: var(--text-light); font-size: 0.85rem; font-weight: 400; }

.cart-items {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 16px;
    flex: 1;
    min-height: 80px;
}

.cart-empty {
    text-align: center;
    color: var(--text-light);
    padding: 36px 0;
    font-size: 0.95rem;
}
.cart-empty small { color: #aaa; }

.cart-item {
    display: flex;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid #f0ede5;
    align-items: flex-start;
}

.cart-item-img {
    width: 54px;
    height: 72px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

.cart-item-details { flex: 1; min-width: 0; }

.cart-item-title {
    font-size: 0.86rem;
    font-weight: 500;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cart-item-price-unit { font-size: 0.78rem; color: var(--text-light); margin: 2px 0 6px; }

.cart-item-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.cart-qty-control {
    display: flex;
    align-items: center;
    gap: 2px;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 2px;
}
.cart-qty-control .qty-btn { width: 28px; height: 28px; font-size: 15px; }
.cart-qty-control span { min-width: 26px; text-align: center; font-size: 0.9rem; font-weight: 600; }

.cart-item-total-price { font-weight: 700; color: var(--accent); font-size: 0.9rem; }

.remove-btn-icon {
    color: #b9b3a6;
    padding: 4px;
    flex-shrink: 0;
}
.remove-btn-icon:active { color: var(--accent); }

.customer-info {
    padding: 10px 16px 0;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
}

.form-row { display: flex; gap: 8px; }
.form-row .form-control { flex: 1; min-width: 0; }

.form-control {
    width: 100%;
    height: 42px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 0 12px;
    font-size: 16px;
    font-family: inherit;
    margin-bottom: 8px;
    outline: none;
    background: #fbfaf6;
}
.form-control:focus { border-color: var(--accent); background: #fff; }

.cart-footer {
    padding: 8px 16px calc(12px + var(--safe-bottom));
    flex-shrink: 0;
    background: var(--surface);
}

.cart-total-line {
    display: flex;
    justify-content: space-between;
    font-size: 1rem;
    font-weight: 700;
    padding: 6px 2px 10px;
}
#cart-total { color: var(--accent); font-size: 1.2rem; }

.cart-actions { display: flex; gap: 10px; }

.copy-btn {
    flex: 1;
    height: 48px;
    border-radius: 24px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    font-size: 0.92rem;
    color: var(--text);
}

.checkout-btn {
    flex: 2;
    height: 48px;
    border-radius: 24px;
    background: var(--whatsapp);
    color: #fff;
    font-size: 0.98rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.checkout-btn:active { background: #1eb858; }

/* ============ Sticky checkout bar ============ */
.checkout-bar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + var(--safe-bottom));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: var(--accent);
    color: #fff;
    border-radius: 28px;
    padding: 10px 8px 10px 18px;
    box-shadow: 0 6px 20px rgba(139, 0, 0, 0.45);
    cursor: pointer;
    z-index: 85;
    transform: translateY(120%);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.3s;
}
.checkout-bar.show { transform: translateY(0); opacity: 1; }
.checkout-bar:active { transform: scale(0.98); }

.checkout-bar-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    min-width: 0;
}

.checkout-bar-total { font-weight: 700; font-size: 1.05rem; }

.checkout-bar-btn {
    flex-shrink: 0;
    background: #fff;
    color: var(--accent);
    font-weight: 700;
    font-size: 0.95rem;
    border-radius: 22px;
    padding: 10px 20px;
}

/* Push floating helpers up when bar is visible */
body.has-checkout-bar .back-to-top { bottom: calc(150px + var(--safe-bottom)); }

@media (min-width: 768px) {
    .checkout-bar { left: 50%; right: auto; transform: translate(-50%, 120%); width: 420px; }
    .checkout-bar.show { transform: translate(-50%, 0); }
}

/* ============ Floating buttons ============ */
.cart-toggle-btn {
    position: fixed;
    right: 16px;
    bottom: calc(20px + var(--safe-bottom));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(139, 0, 0, 0.4);
    z-index: 80;
    transition: transform 0.2s ease;
}
.cart-toggle-btn:active { transform: scale(0.94); }
.cart-toggle-btn.bounce { animation: cartBounce 0.5s ease; }

@keyframes cartBounce {
    0%, 100% { transform: scale(1); }
    35% { transform: scale(1.18); }
    65% { transform: scale(0.94); }
}

.cart-count {
    position: absolute;
    top: -2px;
    right: -2px;
    display: none;
    align-items: center;
    justify-content: center;
    min-width: 21px;
    height: 21px;
    padding: 0 5px;
    border-radius: 11px;
    background: #ffc107;
    color: #5d4000;
    font-size: 0.74rem;
    font-weight: 700;
    border: 2px solid #fff;
}

.back-to-top {
    position: fixed;
    right: 18px;
    bottom: calc(90px + var(--safe-bottom));
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(44, 44, 44, 0.78);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 79;
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 0.25s, transform 0.25s;
}
.back-to-top.show { opacity: 1; pointer-events: auto; transform: translateY(0); }

/* ============ Image modal ============ */
.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.88);
    z-index: 200;
    opacity: 0;
    transition: opacity 0.25s ease;
    padding: 20px;
}
.modal.show { opacity: 1; }

.modal-img {
    max-width: 92vw;
    max-height: 78vh;
    object-fit: contain;
    border-radius: 8px;
}

.modal-caption { color: #ddd; font-size: 0.9rem; margin-top: 12px; text-align: center; }

.close-modal {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 24px;
}

/* ============ Notifications ============ */
#notification-container {
    position: fixed;
    top: 64px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
    width: max-content;
    max-width: 90vw;
}

.notification-card {
    background: rgba(34, 34, 34, 0.92);
    color: #fff;
    border-radius: 22px;
    padding: 10px 18px;
    font-size: 0.86rem;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.25s, transform 0.25s;
    max-width: 90vw;
    text-align: center;
}
.notification-card.show { opacity: 1; transform: translateY(0); }
.notification-card.error { background: rgba(183, 28, 28, 0.95); }
.notification-card.warning { background: rgba(230, 145, 0, 0.95); }

/* ============ Footer ============ */
.site-footer {
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-light);
    padding: 24px 16px calc(90px + var(--safe-bottom));
}
.site-footer a { color: var(--accent); }

/* ============ Desktop refinements ============ */
@media (min-width: 768px) {
    .site-header { padding: 18px 32px; }
    .header-text h1 { font-size: 1.3rem; }

    .toolbar { padding: 12px 32px 10px; }
    .toolbar-row { max-width: 760px; margin: 0 auto; }

    /* Sheets become centered dialogs on desktop */
    .filter-sheet, .detail-sheet, .cart-sheet {
        left: 50%;
        right: auto;
        bottom: auto;
        top: 50%;
        width: 560px;
        max-height: 82vh;
        border-radius: 18px;
        transform: translate(-50%, -45%) scale(0.96);
        opacity: 0;
        pointer-events: none;
    }
    .filter-sheet.open, .detail-sheet.open, .cart-sheet.open {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
        pointer-events: auto;
    }
    .sheet-handle { display: none; }

    .cart-sheet { width: 480px; }

    .detail-body { padding: 20px 28px 16px; }
    .detail-cover { width: 40%; }

    .product:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.13); }
    .quick-add-btn:hover { background: var(--accent-dark); }
    .chip:hover { border-color: var(--accent); }
}
