/**
 * Frontend Styles for Custom Div Box Manager
 */

/* Container - inherit from theme */
.cdbm-container {
    display: grid;
    gap: 20px;
    margin: 20px 0;
    width: 100%;
    color: inherit;
    background: transparent;
}

/* Ensure proper theme color inheritance */
.cdbm-container,
.cdbm-container * {
    box-sizing: border-box;
}

/* Column Layouts */
.cdbm-columns-1 {
    grid-template-columns: 1fr;
}

.cdbm-columns-2 {
    grid-template-columns: repeat(2, 1fr);
}

.cdbm-columns-3 {
    grid-template-columns: repeat(3, 1fr);
}

/* Box Card */
.cdbm-box-item {
    width: 100%;
}

.cdbm-box-card {
    background: var(--cdbm-bg-fallback, var(--wp--preset--color--background, var(--theme-background, #ffffff)));
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease, color 0.3s ease;
    height: 100%;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--wp--preset--color--border, var(--theme-border, transparent));
    color: var(--cdbm-text-fallback, var(--wp--preset--color--text, var(--theme-text, inherit)));
}

.cdbm-box-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* Image Section (30% of card height) */
.cdbm-box-image {
    width: 100%;
    height: 200px;
    overflow: hidden;
    position: relative;
    background: var(--wp--preset--color--background-alt, var(--theme-background-alt, #f8f9fa));
}

.cdbm-box-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.cdbm-box-card:hover .cdbm-box-image img {
    transform: scale(1.05);
}

.cdbm-box-image .cdbm-no-image {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--wp--preset--color--text-alt, var(--theme-text-alt, inherit));
    font-style: italic;
    background: var(--wp--preset--color--background-alt, var(--theme-background-alt, inherit));
    opacity: 0.6;
    border-bottom: 1px solid var(--wp--preset--color--border, var(--theme-border, rgba(0, 0, 0, 0.1)));
}

/* Content Section */
.cdbm-box-content {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.cdbm-box-title {
    margin: 0 0 12px 0;
    font-size: 20px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--wp--preset--color--heading, var(--theme-heading, var(--wp--preset--color--text, inherit)));
    font-family: inherit;
}

.cdbm-box-description {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--wp--preset--color--text, var(--theme-text, inherit));
    font-family: inherit;
    opacity: 0.8;
    flex: 1;
}

.cdbm-box-description p {
    margin: 0 0 10px 0;
    color: inherit !important;
}

.cdbm-box-description p:last-child {
    margin-bottom: 0;
}

/* Better theme integration - inherit from theme context */
.cdbm-container {
    color: inherit;
}

/* Remove any hardcoded colors and let theme take precedence */
.cdbm-box-title,
.cdbm-box-content h2 {
    color: var(--wp--preset--color--heading, var(--theme-heading, inherit));
}

.cdbm-box-description,
.cdbm-box-description p,
.cdbm-box-content p {
    color: var(--wp--preset--color--text, var(--theme-text, inherit));
}

/* Ensure proper color inheritance in WordPress content areas */
.content .cdbm-box-card,
.entry-content .cdbm-box-card,
.post-content .cdbm-box-card,
.single-post .cdbm-box-card,
article .cdbm-box-card {
    background: var(--wp--preset--color--background, var(--theme-background, inherit));
    color: var(--wp--preset--color--text, var(--theme-text, inherit));
    border-color: var(--wp--preset--color--border, var(--theme-border, transparent));
}

/* Responsive Design */
@media (max-width: 1200px) {
    .cdbm-columns-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .cdbm-container {
        gap: 15px;
        margin: 15px 0;
    }
    
    .cdbm-columns-3,
    .cdbm-columns-2 {
        grid-template-columns: 1fr;
    }
    
    .cdbm-box-image {
        height: 180px;
    }
    
    .cdbm-box-content {
        padding: 15px;
    }
    
    .cdbm-box-title {
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    .cdbm-container {
        gap: 12px;
        margin: 12px 0;
    }
    
    .cdbm-box-image {
        height: 160px;
    }
    
    .cdbm-box-content {
        padding: 12px;
    }
    
    .cdbm-box-title {
        font-size: 16px;
        margin-bottom: 10px;
    }
    
    .cdbm-box-description {
        font-size: 13px;
    }
}

/* WordPress Theme Integration */
.widget .cdbm-container {
    margin: 0;
}

/* Dark theme support - inherit from theme */
@media (prefers-color-scheme: dark) {
    .cdbm-box-card {
        background: var(--wp--preset--color--background, var(--theme-background, #1a1a1a));
        color: var(--wp--preset--color--text, var(--theme-text, #ffffff));
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
        border-color: var(--wp--preset--color--border, var(--theme-border, #333));
    }
    
    .cdbm-box-card:hover {
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    }
    
    .cdbm-box-title {
        color: var(--wp--preset--color--heading, var(--theme-heading, var(--wp--preset--color--text, #ffffff)));
    }
    
    .cdbm-box-description {
        color: var(--wp--preset--color--text, var(--theme-text, #ffffff));
        opacity: 0.8;
    }
    
    .cdbm-box-description p {
        color: inherit;
    }
    
    .cdbm-box-image {
        background: var(--wp--preset--color--background-alt, var(--theme-background-alt, #2a2a2a));
    }
    
    .cdbm-box-image .cdbm-no-image {
        background: var(--wp--preset--color--background-alt, var(--theme-background-alt, #2a2a2a));
        color: var(--wp--preset--color--text-alt, var(--theme-text-alt, #ffffff));
        opacity: 0.6;
        border-color: var(--wp--preset--color--border, var(--theme-border, rgba(255, 255, 255, 0.1)));
    }
}

/* Theme-specific class support - your theme uses body.defaultcolor and body.dark */

/* Light mode - when body has 'defaultcolor' class */
body.defaultcolor .cdbm-box-card {
    background: inherit !important;
    color: none !important;
    border-color: transparent;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

body.defaultcolor .cdbm-box-title {
    color: inherit !important;
}

body.defaultcolor .cdbm-box-description,
body.defaultcolor .cdbm-box-description p {
    color: inherit !important;
    opacity: 0.8;
}

body.defaultcolor .cdbm-box-image {
    background: inherit;
}

body.defaultcolor .cdbm-box-image .cdbm-no-image {
    background: inherit;
    color: inherit;
    opacity: 0.6;
    border-color: rgba(0, 0, 0, 0.1);
}

/* Dark mode - when body has 'dark' class */
body.dark .cdbm-box-card {
    background: inherit !important;
    color: inherit !important;
    border-color: transparent;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

body.dark .cdbm-box-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

body.dark .cdbm-box-title {
    color: inherit !important;
}

body.dark .cdbm-box-description,
body.dark .cdbm-box-description p {
    color: inherit !important;
    opacity: 0.8;
}

body.dark .cdbm-box-image {
    background: inherit;
}

body.dark .cdbm-box-image .cdbm-no-image {
    background: inherit;
    color: inherit;
    opacity: 0.6;
    border-color: rgba(255, 255, 255, 0.1);
}

/* Additional dark mode support for other theme classes */
.dark-mode .cdbm-box-card,
.theme-dark .cdbm-box-card,
html[data-theme="dark"] .cdbm-box-card {
    background: var(--wp--preset--color--background, var(--theme-background, #1a1a1a));
    color: var(--wp--preset--color--text, var(--theme-text, #ffffff));
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    border-color: var(--wp--preset--color--border, var(--theme-border, #333));
}

.dark-mode .cdbm-box-card:hover,
.theme-dark .cdbm-box-card:hover,
html[data-theme="dark"] .cdbm-box-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.dark-mode .cdbm-box-title,
.theme-dark .cdbm-box-title,
html[data-theme="dark"] .cdbm-box-title {
    color: var(--wp--preset--color--heading, var(--theme-heading, var(--wp--preset--color--text, #ffffff)));
}

.dark-mode .cdbm-box-description,
.dark-mode .cdbm-box-description p,
.theme-dark .cdbm-box-description,
.theme-dark .cdbm-box-description p,
html[data-theme="dark"] .cdbm-box-description,
html[data-theme="dark"] .cdbm-box-description p {
    color: var(--wp--preset--color--text, var(--theme-text, #ffffff));
}

.dark-mode .cdbm-box-image,
.theme-dark .cdbm-box-image,
html[data-theme="dark"] .cdbm-box-image {
    background: var(--wp--preset--color--background-alt, var(--theme-background-alt, #2a2a2a));
}

.dark-mode .cdbm-box-image .cdbm-no-image,
.theme-dark .cdbm-box-image .cdbm-no-image,
html[data-theme="dark"] .cdbm-box-image .cdbm-no-image {
    background: var(--wp--preset--color--background-alt, var(--theme-background-alt, #2a2a2a));
    color: var(--wp--preset--color--text-alt, var(--theme-text-alt, #ffffff));
}

/* Accessibility improvements */
.cdbm-box-card:focus-within {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

.cdbm-box-card a:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* Loading state */
.cdbm-container.loading {
    opacity: 0.6;
    pointer-events: none;
}

.cdbm-container.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #0073aa;
    border-radius: 50%;
    animation: cdbm-spin 1s linear infinite;
}

@keyframes cdbm-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Theme Integration Overrides - Ensure theme colors take precedence */
/* This section ensures that any hardcoded colors are overridden by theme colors */

/* For WordPress content areas - inherit from parent */
.content .cdbm-box-card,
.entry-content .cdbm-box-card,
.post-content .cdbm-box-card,
.single-post .cdbm-box-card,
article .cdbm-box-card,
main .cdbm-box-card,
.page .cdbm-box-card {
    background: inherit !important;
    color: inherit !important;
}

/* For widget areas */
.widget .cdbm-box-card {
    background: inherit !important;
    color: inherit !important;
}

/* Specific theme framework support */
.twentytwentythree-body .cdbm-box-card,
.twentytwentytwo-body .cdbm-box-card,
.twentytwentyone-body .cdbm-box-card,
.astra .cdbm-box-card {
    background: inherit !important;
    color: inherit !important;
}

/* Block theme support */
.wp-block-group .cdbm-box-card,
.wp-block-column .cdbm-box-card {
    background: inherit !important;
    color: inherit !important;
}

/* Your theme's specific class support - highest priority */
body.defaultcolor .cdbm-container .cdbm-box-card,
body.dark .cdbm-container .cdbm-box-card {
    background: inherit !important;
    color: inherit !important;
}

body.defaultcolor .cdbm-container .cdbm-box-title,
body.dark .cdbm-container .cdbm-box-title {
    color: inherit !important;
}

body.defaultcolor .cdbm-container .cdbm-box-description,
body.defaultcolor .cdbm-container .cdbm-box-description p,
body.dark .cdbm-container .cdbm-box-description,
body.dark .cdbm-container .cdbm-box-description p {
    color: inherit !important;
}

.cdbm-box {
    position: relative;
    margin-bottom: 20px;
    border-radius: 12px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    /* Remove any background-color here to ensure theme default */
}

.cdbm-box:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.cdbm-box-image {
    height: 200px;
    border-radius: 12px 12px 0 0;
    overflow: hidden;
}

.cdbm-box-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cdbm-box-content {
    padding: 15px;
}

.cdbm-box-title {
    margin: 0 0 10px;
    font-size: 1.5em;
}

.cdbm-box-description {
    margin: 0;
    line-height: 1.5;
}