/* In-Content Ads Styles */
.matribhumi-incontent-ad {
    margin: 15px 0;
    padding: 10px;
    position: relative;
    clear: both;
    /* Ensure ads don't exceed content width */
    max-width: 100%;
    overflow: hidden;
}

/* Alignment classes with impressive layout effects */
.matribhumi-incontent-ad.align-left {
    float: left;
    margin-right: 20px;
    margin-bottom: 15px;
    /* Limit floating ad width to prevent content overflow */
    max-width: 40%;
}

.matribhumi-incontent-ad.align-center {
    text-align: center;
    display: block;
    margin: 20px auto;
    /* Center ads can be wider but still contained */
    max-width: 100%;
}

.matribhumi-incontent-ad.align-right {
    float: right;
    margin-left: 20px;
    margin-bottom: 15px;
    /* Limit floating ad width to prevent content overflow */
    max-width: 40%;
}

.matribhumi-incontent-ad a {
    display: inline-block;
    text-decoration: none;
    border: none;
}

/* Special handling for very large images */
.matribhumi-incontent-ad img {
    width: auto;
    height: auto;
    display: block;
    transition: transform 0.3s ease;
    /* Constrain image to container width */
    max-width: 100%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-radius: 4px;
}

/* Override for images that should maintain actual size but not exceed container */
.matribhumi-incontent-ad.actual-size img {
    /* Allow actual size but never exceed the ad container */
    max-width: 100%;
    width: auto;
    height: auto;
}

.matribhumi-incontent-ad:hover img {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Clear float after ads to prevent layout issues */
.matribhumi-incontent-ad + * {
    clear: both;
}

/* Single post content area constraints */
.col-md-8 .detail-left .new-box {
    overflow: hidden; /* Prevent content overflow */
    word-wrap: break-word;
}

/* Ensure in-content ads respect the content container */
.col-md-8 .matribhumi-incontent-ad {
    max-width: 100%;
    box-sizing: border-box;
}

.col-md-8 .matribhumi-incontent-ad.align-left,
.col-md-8 .matribhumi-incontent-ad.align-right {
    /* Floating ads take maximum 40% of content width */
    max-width: 40%;
}

.col-md-8 .matribhumi-incontent-ad.align-center {
    /* Centered ads can be larger but still contained */
    max-width: 100%;
}

/* Ensure proper text flow around floating ads */
.entry-content p,
.col-md-8 .detail-left p {
    line-height: 1.6;
    margin-bottom: 1em;
    text-align: justify;
}

/* Add some visual improvements for the floating effect */
.matribhumi-incontent-ad.align-left + p,
.matribhumi-incontent-ad.align-right + p {
    text-align: justify;
    line-height: 1.7;
}

/* Create impressive text wrapping effect */
@media (min-width: 768px) {
    .matribhumi-incontent-ad.align-left ~ p:first-of-type,
    .matribhumi-incontent-ad.align-right ~ p:first-of-type {
        margin-top: 0;
        padding-top: 10px;
    }
    
    /* Text flows around left-aligned ads */
    .matribhumi-incontent-ad.align-left ~ p {
        text-align: justify;
        margin-left: 0;
    }
    
    /* Text flows around right-aligned ads */  
    .matribhumi-incontent-ad.align-right ~ p {
        text-align: justify;
        margin-right: 0;
    }
}

/* Responsive adjustments */
@media (max-width: 767px) {
    /* Reset floating on mobile for better readability */
    .matribhumi-incontent-ad.align-left,
    .matribhumi-incontent-ad.align-right {
        float: none;
        margin: 15px auto;
        text-align: center;
        max-width: 90%; /* Allow more width on mobile */
    }
    
    .matribhumi-incontent-ad {
        margin: 15px 0;
        padding: 10px;
        max-width: 95%; /* Ensure mobile ads don't touch edges */
    }
    
    .col-md-8 .matribhumi-incontent-ad.align-center {
        max-width: 100%;
    }
    
    .matribhumi-incontent-ad.desktop-only {
        display: none !important;
    }
    
    .matribhumi-incontent-ad.mobile-only {
        display: block !important;
    }
    
    /* On very small screens, prevent images from breaking layout */
    .matribhumi-incontent-ad img {
        max-width: 100% !important;
    }
    
    /* Override for images that should always show actual size */
    .matribhumi-incontent-ad.actual-size img {
        /* max-width: none !important; */
        width: auto !important;
    }
}

@media (min-width: 768px) {
    .matribhumi-incontent-ad.mobile-only {
        display: none !important;
    }
    
    .matribhumi-incontent-ad.desktop-only {
        display: block !important;
    }
}

/* Admin page styles */
.matribhumi-ads-admin .form-table th {
    width: 200px;
    font-weight: 600;
}

.matribhumi-ads-admin .ads-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.matribhumi-ads-admin .ads-table th,
.matribhumi-ads-admin .ads-table td {
    padding: 12px;
    border: 1px solid #ddd;
    text-align: left;
}

.matribhumi-ads-admin .ads-table th {
    background-color: #f1f1f1;
    font-weight: 600;
}

.matribhumi-ads-admin .ads-table img {
    max-width: 100px;
    height: auto;
    border-radius: 3px;
}

.matribhumi-ads-admin .ad-actions {
    white-space: nowrap;
}

.matribhumi-ads-admin .ad-actions button {
    margin-right: 5px;
    font-size: 12px;
    padding: 4px 8px;
}

.matribhumi-ads-admin #image_preview img {
    max-width: 300px;
    height: auto;
    border: 2px solid #ddd;
    border-radius: 4px;
    padding: 5px;
    background: white;
}

.matribhumi-ads-admin .notice {
    margin: 20px 0;
}
