@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Cairo:wght@400;600;700&display=swap');

* {
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

:root {
    /* Primary Colors */
    --primary: hsl(210, 100%, 50%);
    --primary-rgb: 0, 122, 255;
    --primary-hover: hsl(210, 100%, 60%);
    --primary-light: rgba(var(--primary-rgb), 0.1);

    /* Light Mode (Default) */
    --bg-color: hsl(220, 20%, 97%);
    --bg-secondary: #f1f2f6;
    --text-color: hsl(220, 20%, 20%);
    --text-secondary: #57606f;
    --card-bg: rgba(255, 255, 255, 0.7);
    --card-shadow: rgba(0, 0, 0, 0.05);
    --border-color: rgba(0, 0, 0, 0.1);
    --input-bg: #ffffff;
    --qty-btn-bg: #f8f9fa;
    --card-title: #000000;

    --font-en: 'Outfit', sans-serif;
    --font-ar: 'Cairo', sans-serif;
}

body.dark-mode {
    --bg-color: hsl(220, 20%, 8%);
    --bg-secondary: hsl(220, 20%, 12%);
    --text-color: hsl(220, 20%, 95%);
    --text-secondary: hsl(220, 15%, 70%);
    --card-bg: rgba(25, 30, 45, 0.7);
    --card-shadow: rgba(0, 0, 0, 0.4);
    --border-color: rgba(255, 255, 255, 0.1);
    --input-bg: hsl(220, 20%, 15%);
    --qty-btn-bg: hsl(220, 20%, 18%);
    --card-title: #ffffff;
}

[dir="rtl"] {
    font-family: var(--font-ar);
}

[dir="ltr"] {
    font-family: var(--font-en);
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background 0.3s ease, color 0.3s ease;
    min-height: 100vh;
}

.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.3s ease, border-color 0.3s ease;
}

.glass-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px var(--card-shadow);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    padding: 24px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    border-bottom: 1px solid var(--border-color);
}

.btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s ease;
    text-decoration: none;
    display: inline-block;
}

.btn:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.btn-loading {
    position: relative;
    pointer-events: none;
    color: transparent !important;
}

.btn-loading>* {
    visibility: hidden !important;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin-top: -10px;
    margin-left: -10px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: btn-spinner 0.6s linear infinite;
}

/* Wishlist & Floating Buttons */
.wishlist-btn {
    background: rgba(255, 255, 255, 0.85);
    /* Default glassy */
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: #94a3b8;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    padding: 0;
}

.wishlist-btn.active {
    color: #ef4444;
}

.wishlist-btn .heart-icon,
.wishlist-btn svg {
    width: 20px;
    height: 20px;
}

.compact-overlay {
    width: 32px !important;
    height: 32px !important;
    background: rgba(255, 255, 255, 0.6) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
}

.compact-overlay svg,
.compact-overlay .heart-icon {
    width: 16px !important;
    height: 16px !important;
}

@keyframes btn-spinner {
    to {
        transform: rotate(360deg);
    }
}

.title {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(90deg, var(--primary), #8a2be2);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.2rem;
    opacity: 0.8;
    margin-bottom: 30px;
}

.img-fluid {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 16px;
}

.badge {
    background: #ff4757;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Responsive Media Queries */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 15px;
    }

    .navbar nav {
        flex-wrap: wrap;
        justify-content: center;
    }

    .title {
        font-size: 2rem;
        text-align: center;
    }

    .grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        padding: 15px 0;
        gap: 15px;
    }
}

@media (max-width: 480px) {
    .glass-card {
        padding: 16px;
    }

    .btn {
        padding: 8px 15px;
        font-size: 0.85rem;
    }

    .container {
        padding: 0 10px;
    }
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

/* Offer Grid & Card */
.offer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    padding: 24px;
    width: 100%;
    box-sizing: border-box;
}

.offer-card {
    background: var(--bg-secondary);
    border-radius: 28px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid rgba(0, 0, 0, 0.02);
    text-decoration: none;
    color: inherit;
    align-items: center;
    /* Center children horizontally */
    text-align: center;
}

.offer-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px var(--card-shadow);
}

.offer-card .offer-image-container {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--input-bg);
    border-radius: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 5px;
    overflow: hidden;
    padding: 0;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
}

.offer-card.out-of-stock {
    opacity: 0.7;
    filter: grayscale(0.5);
}

.offer-card.out-of-stock a {
    pointer-events: auto;
}

.sold-out-badge {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-15deg);
    background: rgba(255, 71, 87, 0.95);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 900;
    font-size: 1.1rem;
    z-index: 10;
    box-shadow: 0 4px 15px rgba(255, 71, 87, 0.4);
    border: 2px solid white;
    white-space: nowrap;
    text-transform: uppercase;
}

.stock-alert {
    width: 100%;
    text-align: center;
    padding: 8px;
    background: #f1f2f6;
    color: #57606f;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    border: 1px dashed #ced6e0;
}

[data-theme="dark"] .stock-alert {
    background: rgba(255, 255, 255, 0.05);
    color: #a4b0be;
    border-color: rgba(255, 255, 255, 0.1);
}

.offer-card .offer-image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Fill the entire container */
}

.offer-card .offer-title {
    font-size: 1.1rem;
    font-weight: 800;
    margin-bottom: 4px;
    color: var(--card-title);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 2.8em;
    /* Consistent height for 2 lines */
    line-height: 1.4;
}

.offer-card .offer-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0px;
    line-height: 1.4;
    flex-grow: 1;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.offer-card .offer-footer {
    display: flex !important;
    direction: ltr !important;
    justify-content: center !important;
    align-items: center;
    margin-top: auto;
    width: 100% !important;
    align-self: stretch !important;
    padding: 0 !important;
}

.qty-selector {
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* Basket far left, Counter far right */
    background: var(--input-bg);
    border: 1.5px solid var(--border-color);
    border-radius: 20px;
    padding: 2px;
    gap: 0;
    width: 100% !important;
    margin: 0 !important;
    box-shadow: 0 2px 5px var(--card-shadow);
}

.qty-controls-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.offer-card .offer-price {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--primary);
    margin: 4px 0;
}

.offer-card .offer-cart-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: transparent;
    border: 1.5px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    color: #2f3542;
    transition: all 0.2s;
}

.offer-card .offer-cart-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Quantity Selector Buttons and Elements */

.qty-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--qty-btn-bg);
    border-radius: 50%;
    /* Perfect circle */
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s;
}

.qty-btn:hover {
    background: var(--bg-color);
}

.qty-val {
    min-width: 20px;
    text-align: center;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-color);
}

.qty-add-btn {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    /* Perfect circle */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: 2px;
    transition: transform 0.2s;
}

.qty-add-btn:hover {
    transform: scale(1.1);
    background: var(--primary-hover);
}

@media (max-width: 768px) {
    .offer-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px;
        /* Extra tight gap */
        row-gap: 12px;
        /* Extra tight row gap */
        padding: 8px;
    }

    .offer-card {
        padding: 0;
        /* Let image container reach edges */
        border-radius: 24px;
        margin-bottom: 4px;
        align-items: flex-start;
        text-align: right;
        overflow: hidden;
        /* Ensure image corners respect card radius */
        background: var(--card-bg);
        display: flex;
        flex-direction: column;
    }

    .offer-card .offer-image-container {
        border-radius: 0;
        /* Fully edge-to-edge top part */
        margin-bottom: 8px;
        /* Reduced */
        aspect-ratio: 1 / 1;
    }

    /* Add back padding for the text area only */
    .offer-card .offer-title,
    .offer-card .offer-price,
    .offer-card .offer-footer,
    .offer-card .offer-desc,
    .offer-card>div {
        padding-left: 8px;
        /* Tighter padding */
        padding-right: 8px;
    }

    .offer-card .offer-title {
        font-size: 0.9rem;
        /* Reduced per user request */
        font-weight: 700;
        margin-bottom: 2px;
        /* Extra tight margin */
        line-height: 1.3;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        height: 2.6em;
        /* Consistent height for mobile */
    }

    .offer-card .offer-footer {
        padding-bottom: 8px;
        /* Reduced */
    }

    .compact-overlay {
        width: 28px !important;
        /* Even smaller for mobile */
        height: 28px !important;
    }

    .compact-overlay svg,
    .compact-overlay .heart-icon {
        width: 14px !important;
        height: 14px !important;
    }
}

@media (max-width: 350px) {
    .offer-grid {
        gap: 6px;
        row-gap: 12px;
        /* Reduced */
        padding: 6px;
    }

    .offer-card {
        padding: 6px;
        border-radius: 16px;
        align-items: center;
        text-align: center;
    }

    .offer-card .offer-image-container {
        padding: 5px;
    }

    .offer-card .offer-title {
        font-size: 0.9rem;
    }

    .offer-card .offer-desc {
        font-size: 0.65rem;
        margin-bottom: 0px;
        -webkit-line-clamp: 1;
        line-clamp: 1;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .offer-card .offer-price {
        font-size: 0.85rem;
    }

    .offer-card .offer-cart-btn {
        width: 32px;
        height: 32px;
    }
}