/* Design System: Sarai Market Flyer Design */
/* Define Arabic Font */
@font-face {
    font-family: 'GE SS Bold';
    src: url('GE-SS-Two-Medium.otf') format('opentype');
    font-weight: bold;
    font-style: normal;
    font-display: swap;
}

/* Define Numbers/English Font */
@font-face {
    font-family: 'Lufga Bold';
    src: url('Lufga Bold.otf') format('opentype');
    font-weight: bold;
    font-style: normal;
    font-display: swap;
}

:root {
    --bg-white: #FFFFFF;
    --border-red: #b1291b;
    --text-red: #b1291b;
    --bg-green: #1B4D3E;
    --text-white: #FFFFFF;
}

body {
    background-color: var(--bg-white);
    color: #000;
    font-family: 'Cairo', 'Tajawal', sans-serif;
    overflow-x: hidden;
}

/* Header */
.main-header {
    background-color: var(--bg-white);
    position: relative;
    padding-top: 1rem;
    padding-bottom: 1rem;
}

.brand-title {
    color: var(--text-red);
    font-weight: 700;
    font-size: 2rem;
    margin: 0;
}

.header-slogan {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 0;
    color: var(--text-red);
    text-align: right;
    line-height: 1.2;
}

.header-separator {
    border-bottom: 2px solid var(--border-red);
    margin-top: 0;
    margin-bottom: 20px;
}

/* Magazine Cards */
.promo-card {
    background-color: var(--bg-white);
    border: 3px solid var(--border-red);
    border-radius: 0;
    box-shadow: none;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
}

.image-wrapper {
    position: relative;
    padding-top: 75%; /* Aspect Ratio for Web */
    background-color: var(--bg-white);
    overflow: hidden;
    text-align: center;
}

.promo-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 10px;
}

/* Card Layout & Bottom Section */
.card-body-custom {
    padding: 1rem;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    flex-grow: 1;
    gap: 15px;
}

.right-side {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.left-side {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.item-name {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 0;
    color: var(--text-red);
    text-align: right;
    line-height: 1.2;
    direction: rtl;
    font-family: 'GE SS', 'GE SS Bold',serif !important;
}

/* Price Stacking */
.price-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    direction: ltr;
    gap: 0;
}

.old-price {
    color: var(--text-red);
    font-size: 1.2rem;
    font-weight: 700;
    position: relative;
    text-decoration: none;
    margin-bottom: 0;
    padding: 0 5px;
    align-self: flex-start;
    line-height: 1;
    z-index: 1;
    font-family: 'Lufga', 'Lufga Bold', sans-serif !important;
}

/* Diagonal Green Strikethrough */
.old-price::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 3px;
    background-color: var(--bg-green);
    transform: translateY(-50%) rotate(-15deg);
    transform-origin: center;
    z-index: 2;
}

.new-price {
    background-color: var(--bg-green);
    color: var(--text-white);
    padding: 5px 15px;
    font-size: 1.6rem;
    font-weight: 700;
    display: inline-block;
    margin-top: 0;
    line-height: 1.2;
    font-family: 'Lufga', 'Lufga Bold', sans-serif !important;
}

/* Skeleton Loader Shimmer */
.skeleton-wrapper { min-height: 350px; }
.skeleton {
    background: #e0e0e0;
    background: linear-gradient(90deg, #e0e0e0 8%, #f0f0f0 18%, #e0e0e0 33%);
    background-size: 200% 100%;
    animation: shimmer 1.5s linear infinite;
}
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
.skeleton-img { height: 200px; width: 100%; }
.skeleton-text { height: 20px; margin-bottom: 10px; border-radius: 0; }
.skeleton-title { width: 80%; }
.skeleton-price { width: 40%; }

/* Responsive adjustments */
@media (max-width: 768px) {
    .col-12 { /* Force full width for col-12 on mobile */
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    .promo-card {
        margin-bottom: 0;
        height: auto; /* Override fixed heights from print layout */
        max-height: none; /* Override fixed heights from print layout */
    }
    .image-wrapper {
        height: 250px; /* Larger height for full-width mobile cards */
        padding-top: 0; /* Reset padding-top if height is fixed */
    }
    .card-body-custom {
        flex-direction: column; /* Stack item name and price vertically */
        align-items: flex-start; /* Align items to the start */
        gap: 5px; /* Reduce gap for better stacking */
    }
    .right-side {
        width: 100%; /* Take full width */
        justify-content: flex-start; /* Align item name to start */
    }
    .left-side {
        width: 100%; /* Take full width */
        justify-content: flex-start; /* Align price to start */
    }
    .item-name, .new-price { font-size: 1.3rem; }
    .old-price { font-size: 1rem; }
    .brand-title { font-size: 1.5rem; }
    .header-slogan { font-size: 0.9rem; }
}

/* Tablet and small desktop adjustments */
@media (min-width: 768px) and (max-width: 1199.98px) {
    .item-name, .new-price {
        font-size: 1.4rem; /* Adjust font size for tablets and small desktops */
    }
}

/* =========================================
   PRINT LAYOUT - STRICT A4 MEASUREMENTS
   ========================================= */
@media print {
    @page {
        size: A4 portrait;
        margin: 0mm !important; /* Force zero margins at the page level */
    }

    body {
        -webkit-print-color-adjust: exact !important; /* Force colors to print */
        print-color-adjust: exact !important;
        background-color: white !important;
    }

    #globalHeaderTemplate {
        display: none !important;
    }

    /* 1. Shrink the main page wrapper into the safe printable zone */
    .print-page {
        height: 275mm !important; /* CRITICAL: Reduced from 290mm to 275mm */
        max-height: 275mm !important;
        position: relative !important;
        page-break-after: always !important;
        overflow: hidden !important;
        margin: 0 !important;
        padding: 5mm !important;
        box-sizing: border-box !important;
    }

    .print-page:last-child {
        page-break-after: auto !important;
    }

    /* Force Bootstrap Grid in Print */
    .row {
        display: flex !important;
        flex-wrap: wrap !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        row-gap: 2px !important; /* Minimal vertical gap */
        margin-bottom: 0 !important;
    }

    .col-4 {
        flex: 0 0 33.333333% !important;
        max-width: 33.333333% !important;
        width: 33.333333% !important;
        padding: 2px !important; /* Minimal gap */
        display: block !important;
    }

    /* CRITICAL FIX: Shrink the card height further */
    .promo-card {
        height: 54mm !important; /* Reduced from 60mm to guarantee 4 rows fit */
        max-height: 54mm !important;
        page-break-inside: avoid !important; /* STRICTLY prevent splitting */
        break-inside: avoid !important;
        overflow: hidden !important;
        margin-bottom: 0 !important;
        border-width: 2px !important;
    }

    /* Adjust inner elements to fit the new 54mm height */
    .image-wrapper {
        height: 32mm !important; /* Reduced to leave room for text */
        padding-top: 0 !important;
    }

    .card-body-custom {
        height: 22mm !important;
        padding: 2px 5px !important;
        gap: 2px !important;
        align-items: center !important;
    }

    /* Typography Scaling for Print */
    .item-name {
        font-size: 11px !important; /* Drastically reduced for print */
        line-height: 1.2 !important;
        max-height: 2.4em !important; /* Max 2 lines of text */
        overflow: hidden !important;
        text-overflow: ellipsis !important; /* Add ... if too long */
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
    }

    .left-side {
        flex-shrink: 0 !important; /* Prevent prices from squeezing */
        max-width: 45% !important;
    }

    .right-side {
        flex-grow: 1 !important;
        max-width: 55% !important;
    }

    .price-container {
        transform: scale(0.85); /* Proportionally shrink the complex price UI */
        transform-origin: left center;
    }

    .new-price { font-size: 12px !important; padding: 2px 6px !important; }
    .old-price { font-size: 10px !important; }

    .brand-logo { max-height: 40px !important; }
    .header-slogan { font-size: 14px !important; }

    /* Hide the footer */
    .print-footer {
        display: none !important;
    }

    .main-header {
        padding-top: 5px !important;
        padding-bottom: 5px !important;
    }

    .header-separator {
        margin-bottom: 5px !important;
    }
}