/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: url(pic/background.jpg);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
}

/* Top Navigation Bar */
.top-nav {
    background-color: #00A651;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    height: var(--app-nav-height);
    flex-shrink: 0;
}

/* Dark Mode (cart) */
body.dark-mode {
    color: #e5e7eb;
    background: #0f172a;
}

body.dark-mode .cart-item,
body.dark-mode .summary-card {
    background: #111827;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

body.dark-mode .cart-item-name,
body.dark-mode .summary-title,
body.dark-mode .summary-label,
body.dark-mode .summary-value {
    color: #e5e7eb;
}

body.dark-mode .quantity-input {
    background: #0b1220;
    border-color: #1f2937;
    color: #e5e7eb;
}

body.dark-mode .empty-cart-content i {
    color: #9ca3af;
}

/* Top Navigation Bar */
.top-nav {
    background-color: #00A651;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    height: var(--app-nav-height);
    box-sizing: border-box;
}

.nav-left .back-icon {
    width: 24px;
    height: 24px;
    cursor: pointer;
    transition: transform 0.2s ease;
    filter: brightness(0) invert(1);
}

.nav-left .back-icon:hover {
    transform: scale(1.1);
}

.nav-center .nav-title {
    color: white;
    font-size: 30px;
    /* Increased font size */
    font-weight: 700;
    /* Bolder font weight */
    margin: 0;
    position: relative;
    letter-spacing: 1.5px;
    overflow: hidden;
    background: white;
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

@keyframes gradientShift {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

@keyframes scaleBounce {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 15px;
    position: relative;
}

.nav-right .clear-cart-btn {
    width: 40px;
    height: 40px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.12s ease;
    padding: 0 10px;
}

.nav-right .clear-cart-btn:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.nav-right .clear-cart-btn:active {
    transform: scale(0.96);
}

.nav-right .clear-cart-btn i {
    color: white;
    font-size: 16px;
}

.cart-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: #ff4757;
    color: white;
    font-size: 10px;
    font-weight: 600;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

/* Main Content */
.main-content {
    padding: 0 20px calc(185px + env(safe-area-inset-bottom)) 20px;
    min-height: calc(100vh - 61px - 70px);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Cart Items */
.cart-items {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.cart-item {
    background-color: white;
    border-radius: 15px;
    padding: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 15px;
    position: relative;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.cart-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.15);
}

.cart-item-image {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    /* overflow: hidden; */
    /* Removing overflow hidden can help debugging sometimes, but kept for rounded corners */
    overflow: hidden;
    border: 3px solid #00A651;
    flex-shrink: 0;
    position: relative;
    box-shadow: 0 4px 10px rgba(0, 166, 81, 0.2);
}

.cart-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cart-item-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cart-item-name {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.cart-item-price {
    font-size: 14px;
    color: #00A651;
    font-weight: 500;
    margin: 0;
}

.quantity-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 5px;
}

.quantity-btn {
    width: 32px;
    height: 32px;
    background-color: #00A651;
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.quantity-btn:hover {
    background-color: #008f45;
    transform: scale(1.1);
}

.quantity-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    transform: none;
}

.quantity-input {
    width: 50px;
    height: 32px;
    border: 2px solid #00A651;
    border-radius: 16px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    background-color: white;
}

.quantity-input:focus {
    outline: none;
    border-color: #008f45;
    box-shadow: 0 0 0 3px rgba(0, 166, 81, 0.1);
}

.cart-item-total {
    font-size: 16px;
    font-weight: 600;
    color: #00A651;
    margin: 0;
}

.remove-item-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    background-color: rgba(255, 0, 0, 0.8);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease, background-color 0.3s ease;
}

.cart-item:hover .remove-item-btn {
    opacity: 1;
}

.remove-item-btn:hover {
    background-color: rgba(255, 0, 0, 1);
    transform: scale(1.1);
}

/* Empty Cart State */
.empty-cart {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    text-align: center;
}

.empty-cart-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.empty-cart-content i {
    font-size: 64px;
    color: #3d3d3d;
}

.empty-cart-content h2 {
    font-size: 24px;
    color: #666;
    margin: 0;
}

.empty-cart-content p {
    font-size: 16px;
    color: #ffffff;
    margin: 0;
}

.continue-shopping-btn {
    background-color: #00A651;
    color: white;
    border: none;
    border-radius: 25px;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.continue-shopping-btn:hover {
    background-color: #008f45;
    transform: translateY(-2px);
}

/* Cart Summary */
.cart-summary {
    margin-top: auto;
}

.summary-card {
    background-color: white;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.summary-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    text-align: center;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.summary-row:last-child {
    margin-bottom: 0;
}

.summary-label {
    font-size: 14px;
    color: #666;
    font-weight: 500;
}

.summary-value {
    font-size: 14px;
    color: #333;
    font-weight: 600;
}

.total-row {
    border-top: 2px solid #f0f0f0;
    padding-top: 15px;
    margin-top: 15px;
}

.total-row .summary-label {
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.total-value {
    font-size: 20px;
    font-weight: 700;
    color: #00A651;
}

/* Checkout Section */
.checkout-section {
    position: fixed;
    bottom: calc(70px + env(safe-area-inset-bottom));
    left: 0;
    right: 0;
    /*  background-color: white;
     box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);*/
    padding: 20px;
    z-index: 1000;
}

.checkout-btn {
    width: 100%;
    background-color: #00A651;
    color: white;
    border: none;
    border-radius: 25px;
    padding: 16px 24px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.checkout-btn:hover {
    background-color: #008f45;
    transform: translateY(-2px);
}

.checkout-btn:active {
    transform: translateY(0);
}

.checkout-btn i {
    font-size: 16px;
}

/* Responsive Design */
@media (max-width: 480px) {
    .main-content {
        padding: 0 15px 165px 15px;
    }

    .nav-right .clear-cart-btn {
        width: auto;
        height: 36px;
        padding: 0 12px;
        border-radius: 18px;
    }

    .nav-right .clear-cart-btn i {
        font-size: 14px;
    }

    .cart-item {
        padding: 12px;
        gap: 12px;
    }

    .hanging-moon-container {
        position: absolute;
        top: 100%;
        right: 30px !important;
        display: none;
        flex-direction: column;
        align-items: center;
        z-index: 1001;
        pointer-events: none;
        transform-origin: top center;
        animation: moonSwing 4s ease-in-out infinite;
    }

    .cart-item-image {
        width: 70px;
        height: 70px;
    }

    .cart-item-name {
        font-size: 15px;
    }

    .cart-item-price {
        font-size: 13px;
    }

    .quantity-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .quantity-input {
        width: 45px;
        height: 28px;
        font-size: 13px;
    }

    .summary-card {
        padding: 15px;
    }

    .summary-title {
        font-size: 16px;
    }

    .checkout-btn {
        padding: 14px 20px;
        font-size: 16px;
    }
}

@media (max-width: 360px) {
    .top-nav {
        padding: 12px 15px;
    }

    .nav-title {
        font-size: 16px;
    }

    .main-content {
        padding: 0 12px 90px 12px;
    }

    .cart-item {
        padding: 10px;
        gap: 10px;
    }

    .cart-item-image {
        width: 60px;
        height: 60px;
    }

    .cart-item-name {
        font-size: 14px;
    }

    .quantity-btn {
        width: 26px;
        height: 26px;
        font-size: 12px;
    }

    .quantity-input {
        width: 40px;
        height: 26px;
        font-size: 12px;
    }
}

/* Animation for page load */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cart-item {
    animation: fadeInUp 0.6s ease forwards;
}

.cart-summary {
    animation: fadeInUp 0.6s ease forwards;
    animation-delay: 0.1s;
}

/* Focus states for accessibility */
.quantity-btn:focus,
.quantity-input:focus,
.checkout-btn:focus,
.continue-shopping-btn:focus {
    outline: 2px solid #00A651;
    outline-offset: 2px;
}

/* Floating Cart Button */
.floating-cart-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    background-color: #00A651;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 166, 81, 0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    z-index: 1000;
}

.floating-cart-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0, 166, 81, 0.4);
}

.floating-cart-btn i {
    color: white;
    font-size: 24px;
}

/* Main Content - Independent Scrollable Area */
.main-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    padding-bottom: calc(200px + env(safe-area-inset-bottom));
    z-index: 1;
}

/* Ensure bottom nav is fixed */
#footerContainer,
.bottom-nav {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    flex-shrink: 0;
    width: 100%;
    z-index: 3000;
    padding-bottom: calc(12px + env(safe-area-inset-bottom)) !important;
}

/* Ensure Top Nav doesn't shrink */
.top-nav {
    flex-shrink: 0;
}

/* --- HANGING MOON (DARK MODE ONLY) --- */
.hanging-moon-container {
    position: absolute;
    top: 100%;
    /* Attach to bottom of nav */
    right: 70px;
    display: none;
    /* Hidden by default */
    flex-direction: column;
    align-items: center;
    z-index: 1001;
    pointer-events: none;
    transform-origin: top center;
    animation: moonSwing 4s ease-in-out infinite;
}

/* Show only in dark mode */
html.dark-mode .hanging-moon-container,
body.dark-mode .hanging-moon-container {
    display: flex;
}

.rope {
    width: 2px;
    height: 35px;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.2));
    box-shadow: 0 0 5px rgba(255, 255, 255, 0.2);
}

.moon {
    width: 32px;
    height: 32px;
    background: radial-gradient(circle at 30% 30%, #fdfcf0, #ebe29d);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px rgba(253, 252, 240, 0.4), inset -2px -2px 5px rgba(0, 0, 0, 0.2);
    margin-top: -2px;
}

.moon i {
    font-size: 14px;
    color: #2D3436;
    opacity: 0.3;
}

@keyframes moonSwing {

    0%,
    100% {
        transform: rotate(-5deg);
    }

    50% {
        transform: rotate(5deg);
    }
}

#moonToggle.retracting {
    animation: moonRetract 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards !important;
}

@keyframes moonRetract {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }

    30% {
        transform: translateY(15px) scale(1.1);
        opacity: 1;
    }

    100% {
        transform: translateY(-150px) scale(0.5);
        opacity: 0;
    }
}

/* Database Sync Visuals */
.sync-indicator {
    display: inline-flex;
    margin-left: 10px;
    font-size: 14px;
    color: #00A651;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sync-indicator.syncing {
    opacity: 1;
    animation: rotateSync 1s linear infinite;
}

@keyframes rotateSync {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.cart-sync-loader {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 20px 40px;
    border-radius: 50px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    z-index: 4000;
    display: none;
    align-items: center;
    gap: 15px;
    pointer-events: none;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 166, 81, 0.2);
}

.cart-sync-loader.active {
    display: flex;
    animation: fadeInUp 0.4s ease;
}

.cart-sync-loader p {
    margin: 0;
    font-weight: 600;
    color: #333;
    letter-spacing: 0.5px;
}

.loader-ripple {
    width: 20px;
    height: 20px;
    border: 3px solid #00A651;
    border-top-color: transparent;
    border-radius: 50%;
    animation: rotateSync 0.8s linear infinite;
}

body.dark-mode .cart-sync-loader {
    background: rgba(45, 52, 54, 0.95);
    border-color: rgba(0, 166, 81, 0.4);
}

body.dark-mode .cart-sync-loader p {
    color: #fff;
}