:root {
    --bg-color: #121212; /* Dark Mode Background */
    --card-bg: #1e1e1e; /* Dark Card */
    --text-primary: #f5f5f5; /* Light text */
    --text-secondary: #aaaaaa;
    --accent-color: #ffd814; /* Amazon Gold */
    --accent-hover: #f7ca00;
    --danger: #ff4d4f;
    --success: #0b9e4a;
    --border-color: #333333; /* Dark mode border */
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, sans-serif;
}

body, html {
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden !important;
    width: 100%;
}

.app-background {
    display: none;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.glass-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    margin-bottom: 20px;
    background: #1e1e1e; /* Dark Header */
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5); /* Stronger shadow on dark mode */
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo i {
    font-size: 26px;
    color: var(--accent-color);
}

.logo h1 {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

.logo h1 span {
    font-weight: 400;
    color: var(--accent-color);
}

.search-bar {
    display: flex;
    align-items: center;
    background: #2a2a2a;
    border: 1px solid #444444;
    border-radius: 30px;
    padding: 10px 20px;
    width: 40%;
    transition: border-color 0.3s;
}

.search-bar:focus-within {
    border-color: var(--accent-color);
    background: #333333;
}

.search-bar i {
    color: var(--text-secondary);
    margin-right: 12px;
}

.search-bar input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 100%;
    outline: none;
    font-size: 16px; /* 16px prevents iOS zoom */
}

.mobile-cart-toggle {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #1a1a2e;
    border: 2px solid #ffd814;
    color: white;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    font-size: 20px;
    position: fixed; /* Always floating */
    top: 16px;
    right: 16px;
    z-index: 200;
    cursor: grab;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    touch-action: none; /* needed for drag on mobile */
    user-select: none;
}

.mobile-cart-toggle:active {
    cursor: grabbing;
}

.mobile-cart-toggle ph-icon,
.mobile-cart-toggle i,
.mobile-cart-toggle svg {
    color: white !important;
    fill: white !important;
    pointer-events: none;
}

.badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: var(--danger);
    color: white;
    font-size: 11px;
    font-weight: bold;
    height: 18px;
    min-width: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid white;
}

/* Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 30px;
}

.filters {
    display: flex;
    gap: 10px;
    padding: 10px 0;
    margin-bottom: 15px;
    overflow-x: auto;
    white-space: nowrap;
}

.filters::-webkit-scrollbar {
    display: none;
}

.filter-btn {
    background: #1e1e1e;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 18px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.filter-btn:hover, .filter-btn.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: #0f1111; /* Dark text on gold button for contrast */
}

/* Category Header */
.category-header {
    background: #1e1e1e;
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
    margin-bottom: 15px;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    cursor: pointer;
    grid-column: 1 / -1;
}

.category-header i.fa-layer-group {
    color: var(--accent-color);
    margin-right: 10px;
}

/* Products Grid */
.products-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
}

.product-card {
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2); /* Darker shadow */
}

.product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.5); /* Glowing shadow effect in dark mode */
}

.product-icon {
    display: none; /* Images removed - no placeholder space */
}

.product-icon img {
    display: none;
}

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

.product-info h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    margin-bottom: 15px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-actions {
    margin-top: auto;
    width: 100%;
}

.btn-primary {
    background: var(--accent-color);
    color: #0f1111;
    border: 1px solid #fcd200;
    padding: 8px 16px;
    border-radius: 100px; /* Amazon pill */
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    width: auto;
    min-width: 100px;
    transition: background 0.2s;
    box-shadow: 0 2px 5px rgba(213,217,217,0.5);
    display: inline-block;
    text-align: center;
}

.btn-primary:active {
    background: var(--accent-hover);
    transform: scale(0.98);
}

.qty-selector {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #2a2a2a;
    border-radius: 20px;
    height: 38px;
    padding: 0 5px;
    border: 1px solid #444;
}

.qty-selector button {
    background: #1e1e1e;
    border: none;
    color: var(--accent-color);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

.qty-selector input {
    background: transparent;
    border: none;
    width: 30px;
    text-align: center;
    font-weight: 700;
    font-size: 16px; /* 16px prevents iOS zoom */
    color: var(--accent-color);
    outline: none;
}

/* Custom Item */
.custom-item-card {
    background: #1e1e1e;
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 12px;
    border: 1px dashed var(--accent-color);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.custom-item-card h3 {
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 700;
}

.custom-input-group {
    display: flex;
    gap: 10px;
}

.custom-input-group > input {
    flex-grow: 1;
    background: #2a2a2a;
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: 8px;
    font-size: 16px; /* 16px prevents iOS zoom */
    outline: none;
    width: 100%;
    min-width: 0;
    color: var(--text-primary);
}

.custom-input-group > input:focus {
    border-color: var(--accent-color);
    background: #333333;
}

/* Sidebar */
.cart-sidebar {
    background: #1e1e1e;
    border-radius: 12px;
    height: calc(100vh - 110px);
    position: sticky;
    top: 90px;
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.cart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 15px;
}

.cart-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.close-cart {
    display: none;
    background: transparent;
    border: none;
    font-size: 22px;
    color: var(--text-secondary);
}

.cart-items {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-right: 5px;
    max-height: calc(100vh - 220px);
}

.cart-items::-webkit-scrollbar {
    width: 5px;
}
.cart-items::-webkit-scrollbar-thumb {
    background: #e0e0e0;
    border-radius: 3px;
}

.empty-cart {
    text-align: center;
    color: var(--text-secondary);
    margin-top: 50px;
}

.empty-cart i {
    font-size: 40px;
    margin-bottom: 10px;
    color: #e0e0e0;
}

.cart-item {
    background: #2a2a2a;
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cart-item-info h4 {
    font-size: 14px;
    margin-bottom: 2px;
    color: var(--text-primary);
}

.cart-item-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.cart-item .qty-selector {
    height: 32px;
    width: 110px;
}

.cart-item .qty-selector button {
    width: 24px;
    height: 24px;
    font-size: 12px;
}

.cart-item-info span {
    font-size: 12px;
    color: #e0e0e0;
    font-weight: bold;
    background: #444;
    padding: 2px 6px;
    border-radius: 4px;
}

.btn-remove {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    font-size: 16px;
    padding: 5px;
    cursor: pointer;
}
.btn-remove:hover {
    color: var(--danger);
}

.cart-footer {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.cart-summary {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    font-size: 16px;
    font-weight: 700;
}

.btn-submit {
    width: 100%;
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 24px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.btn-submit:active {
    background: var(--accent-hover);
    transform: scale(0.98);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.5);
    display: flex; justify-content: center; align-items: center;
    z-index: 100;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.active {
    opacity: 1; pointer-events: all;
}

.modal {
    background: #1e1e1e;
    width: 90%; max-width: 400px;
    padding: 30px;
    border-radius: 16px;
    text-align: center;
    transform: translateY(20px);
    transition: transform 0.3s;
    border: 1px solid #333;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-icon {
    font-size: 40px; color: var(--accent-color); margin-bottom: 15px;
}

.modal input {
    background: #2a2a2a;
    border: 1px solid #444;
    color: white;
    font-size: 24px;
    text-align: center;
    padding: 12px;
    border-radius: 10px;
    width: 100%;
    margin-top: 15px;
    outline: none;
    letter-spacing: 5px;
}

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

.error-text {
    color: var(--danger); font-weight: 600; display: none; margin-top: 10px;
}

.modal-actions {
    display: flex; gap: 15px; margin-top: 20px;
}

.btn-secondary {
    background: #2a2a2a; color: #f5f5f5; border: 1px solid #444;
    padding: 12px; border-radius: 20px; flex-grow: 1; font-weight: 600;
}

/* Loader */
.loading-state {
    grid-column: 1 / -1; text-align: center; padding: 50px; color: var(--text-secondary);
}

.spinner {
    width: 40px; height: 40px;
    border: 4px solid #f3f3f3;
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite; margin: 0 auto 15px;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* RESPONSIVE BREAKPOINTS */
.cart-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 49; /* just below the cart sidebar (z-index 50) */
    cursor: pointer;
}

@media (max-width: 900px) {
    .main-content { grid-template-columns: 1fr; }
    .search-bar { width: 100%; margin-top: 15px; }
    .glass-header { flex-wrap: wrap; }

    .cart-sidebar {
        position: fixed; top: 0; right: -100%; width: 100%; max-width: 350px;
        height: 100vh; z-index: 50; border-radius: 0;
        transition: right 0.3s ease;
    }
    .cart-sidebar.open { right: 0; }
    .close-cart { display: block; }
}

@media (max-width: 600px) {
    .app-container {
        padding: 8px;
        width: 100%;
        max-width: 100vw;
        box-sizing: border-box;
        overflow: hidden;
    }
    .glass-header {
        padding: 12px;
        margin-bottom: 15px;
        width: 100%;
    }
    .logo h1 {
        font-size: 16px;
    }
    .search-bar input {
        font-size: 16px;
    }
    
    .products-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 8px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .product-card {
        border-radius: 6px;
        border: 1px solid #333333; /* Dark mode border on mobile */
        box-shadow: none;
        padding: 10px;
        align-items: flex-start;
        text-align: left;
    }
    
    .product-icon {
        display: none;
    }
    
    .product-info {
        padding: 0;
        width: 100%;
    }
    
    .product-info h3 {
        font-size: 14px;
        font-weight: 400; /* Amazon normal weight */
        min-height: 20px;
        max-height: 60px; /* Enforce 3 lines max */
        margin-bottom: 12px;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-align: left;
        line-height: 1.4;
    }

    .product-actions {
        width: 100%;
        display: flex;
        justify-content: flex-start;
        margin-top: auto;
    }
    
    .btn-primary {
        padding: 8px 12px;
        font-size: 13px;
        width: auto; /* DO NOT STRETCH */
    }
    
    .qty-selector {
        height: 34px;
        width: 100px;
    }
    .qty-selector button {
        width: 24px;
        height: 24px;
        font-size: 14px;
    }
    .category-header {
        font-size: 16px;
        margin-top: 10px;
        margin-bottom: 10px;
        box-shadow: none;
        border-bottom: 2px solid var(--accent-color);
        border-radius: 0;
        padding: 10px 5px;
    }
}
