/* 
 * Bakery Block Frontend Styles
 * Smart responsive grid layouts for taxonomy terms display
 * Follows user memory preference for CSS files over inline styles
 */

.bakery-block-container {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    margin: 20px 0;
}

.bakery-block-empty {
    padding: 40px 20px;
    text-align: center;
    color: #6c757d;
    font-style: italic;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

/* Base Grid Container */
.bakery-grid {
    display: grid;
    gap: 20px;
    width: 100%;
}

/* Smart Grid Layouts */

/* Single item - centered */
.bakery-grid.grid-1 {
    grid-template-columns: 1fr;
    max-width: 300px;
    margin: 0 auto;
}

/* Two items - side by side */
.bakery-grid.grid-2 {
    grid-template-columns: 1fr 1fr;
}

/* Three items - all in one row */
.bakery-grid.grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

/* Four items - 2x2 grid */
.bakery-grid.grid-2-2 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

/* Five items - 2 on top, 3 on bottom */
.bakery-grid.grid-2-3 {
    grid-template-areas: 
        "item1 item2"
        "item3 item4"
        "item5 item5";
    grid-template-columns: 1fr 1fr;
}

.bakery-grid.grid-2-3 .bakery-grid-item:nth-child(1) { grid-area: item1; }
.bakery-grid.grid-2-3 .bakery-grid-item:nth-child(2) { grid-area: item2; }
.bakery-grid.grid-2-3 .bakery-grid-item:nth-child(3) { grid-area: item3; }
.bakery-grid.grid-2-3 .bakery-grid-item:nth-child(4) { grid-area: item4; }
.bakery-grid.grid-2-3 .bakery-grid-item:nth-child(5) { grid-area: item5; }

/* Six items - 3x2 grid */
.bakery-grid.grid-3-3 {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

/* Auto layout for more than 6 items */
.bakery-grid.grid-auto {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

/* Grid Items */
.bakery-grid-item {
    position: relative;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.bakery-grid-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

/* Term Link */
.bakery-term-link {
    display: block;
    text-decoration: none;
    color: inherit;
    height: 100%;
}

.bakery-term-link:hover {
    text-decoration: none;
    color: inherit;
}

/* Term Card */
.bakery-term-card {
    background: #ffffff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    border: 1px solid #f0f0f0;
    height: 100%;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    position: relative;
}

.bakery-term-card:hover {
    border-color: #007aff;
    box-shadow: 0 8px 30px rgba(0, 122, 255, 0.15);
}

/* Term Images - Full Card Coverage */
.bakery-term-images {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #f8f9fa;
    z-index: 1;
}

.bakery-term-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.bakery-term-card:hover .bakery-term-image {
    transform: scale(1.05);
}

.bakery-image-count {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    z-index: 3;
}

/* Term Placeholder */
.bakery-term-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.bakery-placeholder-icon {
    font-size: 48px;
    opacity: 0.5;
}

/* Term Info - Overlay on Image */
.bakery-term-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    z-index: 2;    
}

.bakery-term-name {
    font-size: 15px;
    font-weight: 400;
    color: black;
    margin: 0;
    line-height: 1.3;
    background: #fff;
    padding:7px 10px;
    border-radius:30px;
    display: inline-block;
}

/* Hide product count on frontend */
.bakery-term-count {
    display: none;
}

/* Responsive Design */

/* Large screens (1200px+) */
@media (min-width: 1200px) {
    .bakery-grid {
        gap: 24px;
    }
    
    .bakery-term-card {
        min-height: 220px;
    }
    
}

/* Medium screens (768px - 1199px) */
@media (max-width: 1199px) and (min-width: 768px) {
    .bakery-grid.grid-3,
    .bakery-grid.grid-3-3 {
        grid-template-columns: 1fr 1fr;
    }
    
    .bakery-grid.grid-2-3 {
        grid-template-areas: 
            "item1 item2"
            "item3 item4"
            "item5 item5";
    }
    
    .bakery-term-card {
        min-height: 180px;
    }
}

/* Small screens (576px - 767px) */
@media (max-width: 767px) and (min-width: 576px) {
    .bakery-grid {
        gap: 16px;
    }
    
    /* Ensure minimum 2 per row */
    .bakery-grid.grid-1 {
        max-width: none;
        grid-template-columns: 1fr 1fr;
    }
    
    .bakery-grid.grid-2,
    .bakery-grid.grid-2-2 {
        grid-template-columns: 1fr 1fr;
    }
    
    .bakery-grid.grid-3,
    .bakery-grid.grid-3-3 {
        grid-template-columns: 1fr 1fr;
    }
    
    .bakery-grid.grid-2-3 {
        grid-template-areas: 
            "item1 item2"
            "item3 item4"
            "item5 item5";
        grid-template-columns: 1fr 1fr;
    }
    
    .bakery-grid.grid-auto {
        grid-template-columns: 1fr 1fr;
    }
    
    .bakery-term-card {
        min-height: 160px;
    }
    
    .bakery-term-info {
        padding: 16px;
    }
    
    .bakery-term-name {
        font-size: 16px;
    }
}

/* Extra small screens (up to 575px) */
@media (max-width: 575px) {
    .bakery-grid {
        gap: 12px;
    }
    
    /* Maintain minimum 2 per row even on very small screens */
    .bakery-grid.grid-1,
    .bakery-grid.grid-2,
    .bakery-grid.grid-2-2,
    .bakery-grid.grid-3,
    .bakery-grid.grid-2-3,
    .bakery-grid.grid-3-3,
    .bakery-grid.grid-auto {
        grid-template-columns: 1fr 1fr;
        grid-template-areas: none;
    }
    
    .bakery-term-card {
        min-height: 140px;
    }
    
    .bakery-term-info {
        padding: 12px;
    }
    
    .bakery-term-name {
        font-size: 14px;
    }
    
    .bakery-image-count {
        font-size: 11px;
        padding: 3px 6px;
    }
    
    .bakery-placeholder-icon {
        font-size: 36px;
    }
}

/* High DPI screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .bakery-term-card {
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    }
    
    .bakery-term-card:hover {
        box-shadow: 0 4px 20px rgba(0, 122, 255, 0.12);
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .bakery-term-card {
        background: #2d2d2d;
        border-color: #404040;
        color: #ffffff;
    }
    
    .bakery-term-name {
        color: #ffffff;
    }
    
    .bakery-term-count {
        color: #a0a0a0;
    }
    
    .bakery-term-placeholder {
        background: linear-gradient(135deg, #404040 0%, #2d2d2d 100%);
    }
    
    .bakery-block-empty {
        background: #2d2d2d;
        border-color: #404040;
        color: #a0a0a0;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .bakery-grid-item,
    .bakery-term-card,
    .bakery-term-image {
        transition: none;
    }
    
    .bakery-grid-item:hover {
        transform: none;
    }
    
    .bakery-term-card:hover .bakery-term-image {
        transform: none;
    }
}

/* Print styles */
@media print {
    .bakery-grid {
        display: block;
    }
    
    .bakery-grid-item {
        break-inside: avoid;
        margin-bottom: 20px;
    }
    
    .bakery-term-card {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .bakery-term-images {
        height: auto;
        max-height: 150px;
    }
}
