/* ========================================
   COZY CAFE SHOP THEME
   ======================================== */
:root {
    --bg-primary: #FFFDF7;
    --bg-secondary: #F0EAD6;
    --text-primary: #4A2C2A;
    --text-secondary: #856f6f;
    --brand-primary: #4CAF50;
    --brand-secondary: #45a049;
    --border-color: #DED0B6;
    --wood-dark: #3a2422;
    --wood-light: #5c4240;
    --paper-white: #fdfaf2;
    --shelf-brown: #8B6B47;
    --price-red: #E74C3C;
    --sale-yellow: #F39C12;
}

/* Global Box Sizing */
*, *::before, *::after { 
    box-sizing: border-box; 
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on iOS */
}

/* Ensure proper scrolling context */
html {
    height: 100%;
    overflow: hidden;
    -webkit-text-size-adjust: 100%; /* Prevent font scaling in iOS */
}

body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Fix for iOS safe areas */
@supports (padding-top: env(safe-area-inset-top)) {
    .shop-header {
        padding-top: env(safe-area-inset-top);
    }
    
    .shop-container {
        padding-top: calc(70px + env(safe-area-inset-top));
    }
}

/* Scrolling polyfill for iOS */
.scrollable {
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

body {
    font-family: 'Lato', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
}

/* Cafe Background Pattern */
.cafe-background {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%239C92AC' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    z-index: -1;
}

/* ========================================
   HEADER (IMPROVED WOODEN BAR)
   ======================================== */
.shop-header {
    background-color: var(--wood-light);
    background-image:
        radial-gradient(circle at 10% 10%, rgba(255,255,255,0.08) 0%, transparent 40%),
        url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 40" width="80" height="40"><path fill="none" stroke="%233a2422" stroke-width="1.5" d="M-10 10 C 30 0, 50 0, 90 10 S 130 20, 170 10" opacity="0.3"></path><path fill="none" stroke="%233a2422" stroke-width="1.5" d="M-10 30 C 30 20, 50 20, 90 30 S 130 40, 170 30" opacity="0.3"></path></svg>');
    border-bottom: 3px solid var(--wood-dark);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
}

.back-to-cafe {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 700;
    font-family: 'Patrick Hand', cursive;
    font-size: 1.2rem;
    transition: all 0.3s ease;
    padding: 0.6rem 1.2rem;
    border-radius: 50px;
    background: #A3B18A; /* Sage green color */
    border: 3px solid #588157; /* Darker green border */
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.4), 0 2px 4px rgba(0,0,0,0.2);
}
.back-to-cafe:hover {
    background-color: #588157;
    color: white;
    transform: translateY(-2px);
}
.back-to-cafe svg {
    stroke: var(--text-primary);
    transition: stroke 0.3s ease;
}
.back-to-cafe:hover svg {
    stroke: white;
}

/* Wallets Grouping */
#wallets-group {
    display: flex;
    gap: 0.75rem;
}

/* Enhanced Wallet Display (Animal Crossing / Cafe Vibe) */
.wallet-container {
    display: flex;
    align-items: center;
    gap: 0.8rem; /* Space between icon and details */
    background: var(--wood-dark); /* Dark wood background */
    padding: 0.4rem 1.2rem;
    border-radius: 50px; /* Pill shape */
    border: 3px solid var(--wood-light); /* Lighter wood border */
    box-shadow: 
        inset 0 3px 5px rgba(0,0,0,0.4), /* Inner shadow for depth */
        0 2px 4px rgba(0,0,0,0.3); /* Outer shadow */
    transition: transform 0.3s ease;
}
.wallet-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(2px); /* Nudge icon down slightly */
}
.wallet-icon svg {
    filter: drop-shadow(1px 1px 1px rgba(0,0,0,0.5));
}

.wallet-details {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.wallet-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: rgba(255,253,247,0.7); /* Lighter, less prominent text */
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1;
}

.wallet-amount {
    font-family: 'Patrick Hand', cursive;
    font-size: 1.6rem;
    color: var(--bg-primary); /* Off-white text */
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    font-weight: 400;
    line-height: 1.1; /* Adjust line height for better spacing */
}

/* Wallet Hit Animation */
@keyframes walletHit {
    0% { transform: scale(1); }
    25% { transform: scale(1.1) rotate(3deg); }
    50% { transform: scale(0.95); }
    100% { transform: scale(1); }
}
.wallet-container.hit {
    animation: walletHit 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ========================================
   MAIN LAYOUT (OPTIMIZED)
   ======================================== */
.shop-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 1rem;
    overflow: hidden;
}

.shop-layout {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    overflow: hidden;
    min-height: 0;
}

/* ========================================
   STORE SECTION
   ======================================== */
.store-section {
    background-color: var(--paper-white);
    border-radius: 1rem;
    border: 2px solid var(--border-color);
    padding: 1.5rem;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.store-sign {
    text-align: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px dashed var(--border-color);
}

.store-subtitle {
    color: var(--text-secondary);
    margin: 0.5rem 0 0;
}

/* NEW: Custom Dropdown Styles */
.custom-select-wrapper {
    position: relative;
    width: auto;
    max-width: 350px;
    margin: 0 auto;
    font-family: 'Patrick Hand', cursive;
}
.hidden-select {
    display: none;
}
.select-trigger {
    font-size: 2rem;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.5rem 1.5rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center; /* FIX: Center the text */
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    position: relative;
}
.select-trigger span {
    flex: 1;
    text-align: center; /* FIX: Center the text within the span */
}
.select-trigger:hover {
    background: var(--bg-secondary);
    border-color: var(--text-secondary);
}
.custom-select-wrapper.open .select-trigger {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
}
.arrow {
    position: absolute; /* FIX: Make arrow absolute positioned */
    right: 1.5rem; /* Position it on the right */
    height: 10px;
    width: 10px;
}
.arrow::before, .arrow::after {
    content: '';
    position: absolute;
    bottom: 0px;
    width: 0.15rem;
    height: 100%;
    background-color: var(--text-secondary);
    transition: all 0.3s ease;
}
.arrow::before {
    left: -3px;
    transform: rotate(-45deg);
}
.arrow::after {
    left: 3px;
    transform: rotate(45deg);
}
.custom-select-wrapper.open .arrow::before {
    left: -3px;
    transform: rotate(45deg);
}
.custom-select-wrapper.open .arrow::after {
    left: 3px;
    transform: rotate(-45deg);
}
.custom-options {
    position: absolute;
    top: 105%;
    left: 0;
    right: 0;
    background: var(--paper-white);
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    z-index: 10;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    max-height: 300px; /* Increased default height */
    overflow-y: auto;
    overflow-x: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}
/* Custom scrollbar for dropdown */
.custom-options::-webkit-scrollbar {
    width: 8px;
}
.custom-options::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}
.custom-options::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
.custom-options::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}
.custom-select-wrapper.open .custom-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.custom-option {
    font-size: 1.5rem;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.custom-option:hover {
    background-color: var(--bg-secondary);
}
.custom-option.selected {
    background-color: var(--border-color);
    font-weight: 700;
}
.custom-option.create-new-option {
    color: var(--brand-primary);
    font-weight: 700;
    border-top: 2px dashed var(--border-color);
}

/* Delete Store Button in Dropdown */
.delete-store-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 50%;
    transition: all 0.2s ease;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}
.delete-store-btn:hover {
    background: rgba(231, 76, 60, 0.1);
    color: var(--price-red);
}
.delete-store-btn svg {
    width: 16px;
    height: 16px;
}

/* Custom Store Actions */
.custom-store-actions {
    margin-bottom: 1rem;
    text-align: center;
}

.add-item-button {
    background: var(--brand-secondary);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 0.6rem 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Nunito', sans-serif;
}

.add-item-button:hover {
    background: var(--brand-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(76, 175, 80, 0.2);
}

/* Search Bar */
.search-container {
    position: relative;
    margin-bottom: 1rem;
}
.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}
.search-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 3rem;
    border: 2px solid var(--border-color);
    border-radius: 2rem;
    font-family: 'Patrick Hand', cursive;
    font-size: 1.2rem;
    background-color: white;
    transition: all 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
}
.search-input:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
}
.search-input::placeholder {
    font-family: 'Patrick Hand', cursive;
    color: var(--text-secondary);
}


/* Category Tabs */
.category-tabs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    overflow-x: auto;
    overflow-y: hidden; /* This is the fix */
    padding: 0.5rem 0;
    margin-bottom: 1rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    min-height: 45px;
}
.category-tabs::-webkit-scrollbar {
    height: 6px;
}
.category-tabs::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 3px;
}
.category-tabs::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.category-link {
    flex-shrink: 0;
    padding: 0.6rem 1.2rem;
    background-color: var(--bg-secondary);
    border: 2px solid transparent;
    border-radius: 2rem;
    font-weight: 700;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    position: relative;
}
.category-link:hover {
    background-color: var(--border-color);
    transform: translateY(-2px);
}
.category-link.active {
    background: linear-gradient(180deg, var(--brand-primary) 0%, var(--brand-secondary) 100%);
    color: white;
    border-bottom: 3px solid #388E3C;
    padding-bottom: calc(0.6rem - 1px);
    transform: translateY(-1px);
}
.category-link:active {
    transform: translateY(1px);
    transition: transform 0.05s ease;
}

/* Item Shelves (Scrollable) */
.item-shelves {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 200px;
    padding-right: 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-secondary);
    -webkit-overflow-scrolling: touch; /* iOS smooth scrolling */
    position: relative;
}

/* iOS scroll fix */
@supports (-webkit-touch-callout: none) {
    .item-shelves {
        overflow-y: scroll;
        -webkit-overflow-scrolling: touch;
        transform: translateZ(0);
    }
}

.loading-message, .empty-message {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--brand-primary);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Item Grid Display */
.item-shelves:not(.loading-message) {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    align-content: start;
}

.item-card {
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: visible; /* Reverted to prevent clipping */
    display: flex;
    flex-direction: column;
}
.item-card:hover {
    transform: translateY(-4px) rotate(-1deg);
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
    border-color: var(--brand-primary);
    z-index: 10; /* This brings the hovered card to the front */
}

.item-emoji {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 0.5rem;
}

.item-name {
    font-weight: 600;
    font-size: 0.85rem;
    line-height: 1.3;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    min-height: 2.6em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2; 
    -webkit-box-orient: vertical;
}

.item-price-tag {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-top: auto;
}
.item-price {
    font-family: 'Patrick Hand', cursive;
    font-size: 1.1rem;
    color: var(--brand-primary);
    font-weight: 700;
}
.item-original-price {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-decoration: line-through;
}

/* Fixed Sale Badge */
.sale-badge {
    position: absolute;
    top: 2px; /* Moved down to prevent collision */
    right: -20px;
    background: var(--sale-yellow);
    color: white;
    padding: 3px 25px;
    font-size: 0.65rem;
    font-weight: 700;
    transform: rotate(45deg);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    z-index: 1;
}

/* ========================================
   BASKET SECTION
   ======================================== */
.basket-section {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 200px);
}

.basket-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-top: 4px; /* Add space for the tab to move up into */
}

.basket-tab {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 0.5rem 0.5rem 0 0;
    padding: 0.6rem 0.5rem;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
}
.basket-tab svg {
    width: 18px;
    height: 18px;
}
.basket-tab:hover {
    background: var(--border-color);
}
.basket-tab.active {
    background: var(--paper-white);
    color: var(--text-primary);
    border-bottom-color: var(--paper-white);
    position: relative;
    z-index: 2;
    transform: translateY(-4px); /* The bookmark effect */
}

.basket-content {
    background: var(--paper-white);
    border: 2px solid var(--border-color);
    border-radius: 0 0 1rem 1rem;
    margin-top: -6px; /* Adjusted to align with the raised tab */
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative; /* Ensure it's a positioning context */
    z-index: 1; /* Sit behind the active tab */
}

.tab-panel {
    display: none;
    flex-direction: column;
    height: 100%;
}
.tab-panel.active {
    display: flex;
}

/* Shopping Basket Paper */
.basket-paper, .subs-paper, .history-paper {
    padding: 1rem;
    flex: 1;
    overflow-y: auto;
    background-image: repeating-linear-gradient(
        transparent,
        transparent 27px,
        var(--border-color) 27px,
        var(--border-color) 28px
    );
    background-position: 0 3rem;
}

.basket-title {
    font-family: 'Special Elite', monospace;
    font-size: 1.3rem;
    margin: 0 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--text-primary);
}

.empty-basket {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}
.empty-basket svg {
    margin-bottom: 1rem;
}
.empty-basket p {
    font-weight: 700;
    margin: 0.5rem 0;
}
.empty-basket span {
    font-size: 0.9rem;
}

/* Cart Items */
.cart-items {
    flex: 1;
    overflow-y: auto;
}

.cart-item {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 0.9rem;
}

.cart-item.slide-in {
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

.cart-item-emoji {
    font-size: 1.2rem;
}

.cart-item-name-and-qty {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.cart-item-quantity {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.quantity-btn {
    background: #EADBC8; /* A slightly different beige */
    border: 2px solid #DAC0A3; /* A darker beige border */
    width: 24px;
    height: 24px;
    border-radius: 6px; /* Rounded corners, not a circle */
    cursor: pointer;
    font-weight: bold;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    transition: all 0.2s ease;
    box-shadow: 0 2px 0 #DAC0A3; /* 3D effect */
}

.quantity-btn:hover {
    background: #DAC0A3;
    transform: translateY(1px); /* Push button down effect */
    box-shadow: 0 1px 0 #DAC0A3;
}

.quantity-btn:active {
    transform: translateY(2px);
    box-shadow: none;
}

.quantity-display {
    font-weight: 700;
    min-width: 1.5em;
    text-align: center;
    font-size: 0.9rem;
}

.cart-item-name {
    font-weight: 600;
    font-size: 0.85rem;
}
.cart-item-price {
    font-family: 'Patrick Hand', cursive;
    color: var(--brand-primary);
    font-weight: 700;
    font-size: 1rem;
}

.cart-item-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.remove-item-btn, .add-to-subs-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 50%;
    transition: all 0.2s ease;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}
.remove-item-btn {
    font-size: 1.5rem;
    line-height: 1;
}
.remove-item-btn:hover {
    background: rgba(231, 76, 60, 0.1);
    color: var(--price-red);
}
.add-to-subs-btn:hover {
    background: rgba(76, 175, 80, 0.1);
    color: var(--brand-primary);
}

/* Checkout Section */
.checkout-section {
    padding: 1rem;
    background: var(--bg-secondary);
    border-top: 2px solid var(--border-color);
    flex-shrink: 0;
}

.total-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.75rem;
}
.total-row span:first-child {
    font-weight: 700;
    color: var(--text-secondary);
}
.total-amount {
    font-family: 'Patrick Hand', cursive;
    font-size: 1.5rem;
    color: var(--text-primary);
}

.checkout-button {
    width: 100%;
    padding: 0.75rem;
    background: linear-gradient(180deg, var(--brand-primary) 0%, var(--brand-secondary) 100%);
    color: white;
    border: none;
    border-radius: 50px;
    border-bottom: 4px solid #388E3C;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.15s ease-out;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}
.checkout-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.3);
}
.checkout-button:active:not(:disabled) {
    transform: translateY(1px);
    border-bottom-width: 2px;
    transition: transform 0.05s ease;
}
.checkout-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Subscriptions */
.subs-sections {
    flex: 1;
    overflow-y: auto;
}

.sub-section {
    margin-bottom: 1.5rem;
}
.sub-section-title {
    font-family: 'Patrick Hand', cursive;
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin: 0 0 0.75rem;
}

.sub-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}
.sub-item.ended {
    opacity: 0.6;
}
.sub-duration {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.end-sub-btn {
    margin-left: auto;
    background: var(--price-red);
    color: white;
    border: none;
    border-bottom: 3px solid #a02923; /* Darker red for 3D effect */
    padding: 0.4rem 0.8rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease-out;
}
.end-sub-btn:hover {
    transform: translateY(-2px);
    background: #eA4f3f; /* Slightly lighter red on hover */
}
.end-sub-btn:active {
    transform: translateY(1px);
    border-bottom-width: 1px;
    transition: transform 0.05s ease;
}

/* Projection Card */
.projection-card {
    margin: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    border: 1px dashed var(--text-secondary);
    flex-shrink: 0;
}
.projection-card h3 {
    font-family: 'Patrick Hand', cursive;
    font-size: 1.1rem;
    margin: 0 0 0.75rem;
    color: var(--text-primary);
}
.projection-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
}
.projection-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.5rem 0;
}
.projection-row.total {
    font-weight: 700;
}
.projection-row.total strong {
    color: var(--brand-primary);
    font-size: 1rem;
}

/* History */
.history-list {
    flex: 1;
    overflow-y: auto;
}

.history-group {
    margin-bottom: 1.5rem;
}
.history-date {
    font-family: 'Patrick Hand', cursive;
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}
.history-purchase {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}
.history-purchase-header {
    display: flex;
    justify-content: space-between;
    font-weight: 700;
    margin-bottom: 0.5rem;
}
.history-item-list {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding-left: 1rem;
    margin: 0;
}

/* ========================================
   MODAL
   ======================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.modal-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal-paper {
    background: var(--paper-white);
    border: 2px solid var(--border-color);
    border-radius: 1rem;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    text-align: center;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    transform: scale(0.95) translateY(20px);
    transition: transform 0.3s ease;
}
.modal-overlay:not(.hidden) .modal-paper {
    transform: scale(1) translateY(0);
}

.modal-pin {
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 30px;
    background: radial-gradient(circle at 30% 30%, #e74c3c, #c0392b);
    border-radius: 50% 50% 50% 0;
    transform: translateX(-50%) rotate(-45deg);
    box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
}

.modal-title {
    font-family: 'Patrick Hand', cursive;
    font-size: 1.8rem;
    margin: 0 0 1rem;
    color: var(--text-primary);
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.modal-btn {
    flex: 1;
    padding: 0.75rem;
    border: none;
    border-radius: 2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Nunito', sans-serif;
}
.modal-btn.cancel {
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.modal-btn.cancel:hover {
    background: var(--border-color);
}
.modal-btn.confirm {
    background: linear-gradient(180deg, var(--brand-primary) 0%, var(--brand-secondary) 100%);
    color: white;
    border-bottom: 3px solid #388E3C;
}
.modal-btn.confirm:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(76, 175, 80, 0.3);
}

/* Modal Form Styles */
.modal-paper .form-group {
    text-align: left;
    margin-bottom: 1rem;
}

.modal-paper .form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 700;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.modal-paper .form-group .modal-input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    font-family: 'Lato', sans-serif;
    font-size: 1rem;
    background-color: white;
    transition: all 0.3s ease;
}

.modal-paper .form-group .modal-input:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
}

/* Delete confirmation text */
.delete-warning {
    color: var(--price-red);
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.modal-btn.danger {
    background: linear-gradient(180deg, var(--price-red) 0%, #c0392b 100%);
    color: white;
    border-bottom: 3px solid #a02923;
}
.modal-btn.danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(231, 76, 60, 0.3);
}


/* ========================================
   DESKTOP RESPONSIVE
   ======================================== */
@media (min-width: 1024px) {
    .shop-container {
        padding: 1.5rem;
    }
    
    .shop-layout {
        grid-template-columns: 1fr 380px;
        gap: 1.5rem;
        height: calc(100vh - 120px);
    }
    
    .store-section {
        min-height: 0;
        display: flex;
        flex-direction: column;
    }
    
    .item-shelves:not(.loading-message) {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
    
    .item-name {
        font-size: 0.9rem;
    }
    
    .basket-section {
        height: 100%;
        overflow: hidden;
    }
    
    .basket-content {
        height: calc(100% - 60px);
    }
}

/* ========================================
   MOBILE RESPONSIVE
   ======================================== */
@media (max-width: 640px) {
    /* Prevent body scroll when modal is open */
    body {
        position: relative;
        height: 100%;
    }
    
    .shop-header {
        padding: 0.5rem 0.75rem;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
    }
    
    .back-to-cafe span {
        display: none;
    }
    
    .wallet-container {
        padding: 0.4rem 0.75rem;
    }
    
    .wallet-icon {
        font-size: 1.2rem;
    }
    
    .wallet-amount {
        font-size: 1.2rem;
    }
    
    .shop-container {
        padding: 0;
        padding-top: 70px; /* Account for fixed header */
        height: 100vh;
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    
    .shop-layout {
        display: flex;
        flex-direction: column;
        height: 100%;
        overflow: hidden;
    }
    
    /* Store section takes up remaining space */
    .store-section {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        background: var(--paper-white);
        border-radius: 1rem 1rem 0 0;
        border: 2px solid var(--border-color);
        border-bottom: none;
        padding: 1rem;
        margin: 0 0.75rem;
    }
    
    /* Make basket a fixed bottom sheet */
    .basket-section {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 35vh;
        background: var(--paper-white);
        border-radius: 1rem 1rem 0 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
        z-index: 50;
        display: flex;
        flex-direction: column;
    }
    
    .custom-select-wrapper {
        max-width: 280px;
    }
    .select-trigger {
        font-size: 1.5rem;
    }
    
    /* Fix dropdown scrolling on mobile */
    .custom-options {
        max-height: 40vh !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Store sign and search should not scroll */
    .store-sign,
    .custom-store-actions,
    .search-container,
    .category-tabs {
        flex-shrink: 0;
    }
    
    /* Item shelves container */
    .item-shelves {
        flex: 1;
        overflow-y: scroll !important; /* Force scroll */
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        position: relative;
        margin: 0 -0.5rem; /* Compensate for padding */
        padding: 0 0.5rem;
        padding-bottom: 36vh; /* Space for basket */
    }
    
    /* Ensure loading message doesn't break scrolling */
    .item-shelves.loading-message {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .item-shelves:not(.loading-message) {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.5rem;
        align-content: start;
    }
    
    .item-card {
        padding: 0.5rem;
        height: fit-content;
    }
    
    .item-emoji {
        font-size: 1.8rem;
    }
    
    .item-name {
        font-size: 0.7rem;
        min-height: 2.1em;
    }
    
    .item-price {
        font-size: 0.9rem;
    }
    
    /* Ensure categories don't take too much space */
    .category-tabs {
        max-height: 45px;
        margin-bottom: 0.5rem;
    }
    
    .basket-tabs {
        font-size: 0.8rem;
        flex-shrink: 0;
    }
    
    .basket-tab {
        padding: 0.5rem 0.3rem;
    }
    
    .basket-tab svg {
        width: 16px;
        height: 16px;
    }
    
    .basket-content {
        flex: 1;
        min-height: 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    
    .basket-paper, .subs-paper, .history-paper {
        padding: 0.5rem;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .basket-title {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }
    
    .checkout-section {
        flex-shrink: 0;
        padding: 0.75rem;
        background: var(--bg-secondary);
        border-top: 2px solid var(--border-color);
    }
    
    .total-row {
        margin-bottom: 0.5rem;
    }
    
    .projection-card {
        margin: 0.5rem;
        padding: 0.5rem;
    }
    
    /* Hide scrollbars on mobile for cleaner look */
    .item-shelves::-webkit-scrollbar,
    .basket-paper::-webkit-scrollbar,
    .subs-paper::-webkit-scrollbar,
    .history-paper::-webkit-scrollbar {
        display: none;
    }
    
    /* iOS bounce scroll fix */
    .item-shelves {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

/* iPhone Pro Max specific adjustments */
@media (max-width: 430px) and (min-height: 800px) {
    .basket-section {
        height: 30vh; /* Even smaller basket on large phones */
    }
    
    .item-shelves {
        padding-bottom: 31vh;
    }
}

/* ========================================
   SCROLLBAR STYLING
   ======================================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.hidden {
    display: none !important;
}


/* ---------------- */

/* ========================================
   CUSTOM PAYMENT SELECTOR
   ======================================== */
.custom-payment-wrapper {
    position: relative;
    background: var(--wood-dark);
    border-radius: 50px;
    border: 3px solid var(--wood-light);
    box-shadow: 
        inset 0 3px 5px rgba(0,0,0,0.4),
        0 2px 4px rgba(0,0,0,0.3);
    margin-right: 0.5rem;
}

.payment-selector-trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.8rem;
    cursor: pointer;
    position: relative;
}

.payment-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: rgba(255,253,247,0.7);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.payment-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255,253,247,0.1);
    border: 2px solid rgba(255,253,247,0.2);
    border-radius: 20px;
    padding: 0.3rem 0.8rem;
    min-width: 120px;
    transition: all 0.2s ease;
}

.custom-payment-wrapper:hover .payment-display {
    background: rgba(255,253,247,0.2);
    border-color: rgba(255,253,247,0.4);
}

.payment-value {
    font-family: 'Patrick Hand', cursive;
    font-size: 1rem;
    color: var(--bg-primary);
    flex: 1;
}

.payment-arrow {
    position: relative;
    width: 10px;
    height: 10px;
    flex-shrink: 0;
}

.payment-arrow::before,
.payment-arrow::after {
    content: '';
    position: absolute;
    bottom: 0px;
    width: 0.15rem;
    height: 70%;
    background-color: var(--bg-primary);
    transition: all 0.3s ease;
}

.payment-arrow::before {
    left: -2px;
    transform: rotate(-45deg);
}

.payment-arrow::after {
    right: -2px;
    transform: rotate(45deg);
}

.custom-payment-wrapper.open .payment-arrow::before {
    transform: rotate(45deg);
}

.custom-payment-wrapper.open .payment-arrow::after {
    transform: rotate(-45deg);
}

.payment-options {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--paper-white);
    border: 2px solid var(--border-color);
    border-radius: 0.75rem;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    z-index: 100;
    max-height: 200px;
    overflow-y: auto;
}

.custom-payment-wrapper.open .payment-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.payment-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-family: 'Patrick Hand', cursive;
    font-size: 1.1rem;
}

.payment-option:hover {
    background-color: var(--bg-secondary);
}

.option-label {
    color: var(--text-primary);
    font-weight: 600;
}

.option-balance {
    color: var(--brand-primary);
    font-weight: 700;
}

/* Selected wallet highlighting (desktop only) */
.wallet-container.selected-wallet {
    border-color: var(--brand-primary);
    box-shadow: 
        inset 0 3px 5px rgba(0,0,0,0.4),
        0 2px 4px rgba(0,0,0,0.3),
        0 0 0 2px rgba(76, 175, 80, 0.5);
}

/* Hide subscriptions tab for non-Denison students */
.basket-tab.hidden {
    display: none !important;
}

/* Disabled items when payment type mismatch */
.item-card.disabled-item {
    opacity: 0.5;
    cursor: not-allowed;
    position: relative;
}

.item-card.disabled-item:hover {
    transform: none;
    box-shadow: none;
    border-color: var(--border-color);
}

.disabled-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(231, 76, 60, 0.9);
    color: white;
    font-size: 0.7rem;
    padding: 0.3rem;
    text-align: center;
    font-weight: 700;
    border-radius: 0 0 0.5rem 0.5rem;
}

/* Mobile specific adjustments */
@media (max-width: 640px) {
    /* Hide wallet containers on mobile */
    .wallet-container {
        display: none !important;
    }
    
    #wallets-group {
        flex-direction: row;
        align-items: center;
        gap: 0;
    }
    
    .custom-payment-wrapper {
        margin-right: 0;
        flex: 1;
        max-width: none;
    }
    
    .payment-selector-trigger {
        padding: 0.35rem 0.6rem;
    }
    
    .payment-label {
        font-size: 0.7rem;
    }
    
    .payment-display {
        flex: 1;
        min-width: auto;
        padding: 0.25rem 0.6rem;
    }
    
    .payment-value {
        font-size: 0.9rem;
    }
    
    .payment-options {
        left: 0.5rem;
        right: 0.5rem;
        max-height: 40vh;
    }
    
    .payment-option {
        font-size: 1rem;
        padding: 0.6rem 0.8rem;
    }
}

/* Ensure long balance names don't break layout */
.wallet-label,
.option-label,
.payment-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Custom scrollbar for payment options */
.payment-options::-webkit-scrollbar {
    width: 6px;
}

.payment-options::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 3px;
}

.payment-options::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.payment-options::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Animation for wallet hit effect */
@keyframes walletHit {
    0% { transform: scale(1); }
    25% { transform: scale(1.1) rotate(3deg); }
    50% { transform: scale(0.95); }
    100% { transform: scale(1); }
}