/**
 * Launchmind Blog - Adaptive Design v2.3
 * Inherits website styling automatically
 * 
 * Priority: Website CSS > Custom accent_color > Default
 */

/* ============================================
   CSS Variables - Easily Overridable
   Website can override these in their CSS
   ============================================ */

.launchmind-blog-list,
.launchmind-blog-intro,
.launchmind-single-wrapper {
    /* Accent color - defaults to link color or green */
    --lm-accent: var(--theme-primary, var(--wp--preset--color--primary, currentColor));
    --lm-accent-hover: var(--theme-primary-dark, var(--lm-accent));
    
    /* Text colors - inherit from website */
    --lm-text-primary: inherit;
    --lm-text-secondary: currentColor;
    --lm-text-muted: currentColor;
    
    /* Card styling */
    --lm-card-bg: rgba(255, 255, 255, 0.95);
    --lm-card-border: rgba(0, 0, 0, 0.08);
    --lm-card-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --lm-card-shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.15);
    --lm-card-radius: 12px;
    
    /* Spacing */
    --lm-gap: 1.5rem;
}

/* ============================================
   Automatic Dark/Light Mode Detection
   Detects user's system preference (phone/computer)
   Only applies when theme="auto" (default)
   ============================================ */

/* 
 * Automatic Dark Mode Detection
 * 
 * IMPORTANT: Only activates when theme="auto" is explicitly set AND no custom CSS overrides exist.
 * For backward compatibility: If no theme parameter is set, dark mode is DISABLED by default.
 * This ensures existing sites (like Broadwick) with custom CSS don't break.
 * 
 * To enable automatic dark mode, explicitly use: [launchmind_blog theme="auto"]
 */
@media (prefers-color-scheme: dark) {
    /* Auto-detect dark mode - ONLY when theme="auto" is explicitly set */
    .launchmind-blog-list.lm-theme-auto:not(.lm-dark):not(.lm-light),
    .launchmind-blog-intro.lm-theme-auto:not(.lm-dark):not(.lm-light),
    .launchmind-single-wrapper.lm-theme-auto:not(.lm-dark):not(.lm-light) {
        --lm-card-bg: rgba(30, 30, 30, 0.9);
        --lm-card-border: rgba(255, 255, 255, 0.1);
        --lm-card-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
        --lm-card-shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.4);
        --lm-text-primary: rgba(255, 255, 255, 0.95);
        --lm-text-secondary: rgba(255, 255, 255, 0.8);
        --lm-text-muted: rgba(255, 255, 255, 0.6);
    }
    
    /* Dark mode for single post container - only when theme="auto" */
    .launchmind-single-wrapper.lm-theme-auto:not(.lm-dark):not(.lm-light) .launchmind-post-single {
        background: rgba(30, 30, 30, 0.9);
        border-color: rgba(255, 255, 255, 0.1);
        color: rgba(255, 255, 255, 0.95);
    }
    
    /* Dark mode for tags - only when theme="auto" */
    .launchmind-blog-list.lm-theme-auto:not(.lm-dark):not(.lm-light) .launchmind-tag,
    .launchmind-single-wrapper.lm-theme-auto:not(.lm-dark):not(.lm-light) .launchmind-tag {
        background: rgba(255, 255, 255, 0.15);
        color: rgba(255, 255, 255, 0.9);
    }
    
    /* Dark mode for links - only when theme="auto" */
    .launchmind-single-wrapper.lm-theme-auto:not(.lm-dark):not(.lm-light) .launchmind-post-body a,
    .launchmind-blog-list.lm-theme-auto:not(.lm-dark):not(.lm-light) .launchmind-read-more {
        color: rgba(100, 200, 255, 0.9);
    }
}

/* ============================================
   Force Dark Mode (theme="dark")
   Overrides automatic detection
   ============================================ */
.lm-dark,
.launchmind-blog-list.lm-dark,
.launchmind-blog-intro.lm-dark,
.launchmind-single-wrapper.lm-dark {
    --lm-card-bg: rgba(30, 30, 30, 0.9) !important;
    --lm-card-border: rgba(255, 255, 255, 0.1) !important;
    --lm-card-shadow: 0 4px 20px rgba(0, 0, 0, 0.3) !important;
    --lm-card-shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.4) !important;
    --lm-text-primary: rgba(255, 255, 255, 0.95) !important;
    --lm-text-secondary: rgba(255, 255, 255, 0.8) !important;
    --lm-text-muted: rgba(255, 255, 255, 0.6) !important;
}

.lm-dark .launchmind-post-single {
    background: rgba(30, 30, 30, 0.9) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    color: rgba(255, 255, 255, 0.95) !important;
}

.lm-dark .launchmind-tag {
    background: rgba(255, 255, 255, 0.15) !important;
    color: rgba(255, 255, 255, 0.9) !important;
}

.lm-dark .launchmind-post-body a,
.lm-dark .launchmind-read-more {
    color: rgba(100, 200, 255, 0.9) !important;
}

/* ============================================
   Force Light Mode (theme="light")
   Overrides automatic detection
   ============================================ */
.lm-light,
.launchmind-blog-list.lm-light,
.launchmind-blog-intro.lm-light,
.launchmind-single-wrapper.lm-light {
    --lm-card-bg: rgba(255, 255, 255, 0.98) !important;
    --lm-card-border: rgba(0, 0, 0, 0.08) !important;
    --lm-card-shadow: 0 4px 20px rgba(0, 0, 0, 0.08) !important;
    --lm-text-primary: inherit !important;
    --lm-text-secondary: currentColor !important;
    --lm-text-muted: currentColor !important;
}

.lm-light .launchmind-post-single {
    background: rgba(255, 255, 255, 0.98) !important;
    border-color: rgba(0, 0, 0, 0.08) !important;
    color: inherit !important;
}

/* ============================================
   Blog Intro - Inherits website typography
   ============================================ */

.launchmind-blog-intro {
    max-width: 800px;
    margin: 0 auto 1.5rem;
    padding: 0 2%;
}

.launchmind-blog-intro p {
    font-size: 1.1rem;
    line-height: 1.7;
    color: inherit;
    opacity: 0.8;
    margin: 0;
    font-family: inherit;
}

.launchmind-blog-intro .launchmind-site-name {
    color: var(--lm-accent);
    font-weight: 700;
    opacity: 1;
}

@media (max-width: 768px) {
    .launchmind-blog-intro {
        padding: 0 1rem;
        margin-bottom: 1rem;
    }
    
    .launchmind-blog-intro p {
        font-size: 1rem;
    }
}

/* ============================================
   Blog Grid
   ============================================ */

.launchmind-blog-list {
    display: grid;
    gap: var(--lm-gap);
    margin: 0 auto 2rem;
    padding: 0 2%;
    width: 100%;
    max-width: 1600px;
}

.launchmind-columns-1 { grid-template-columns: 1fr; }
.launchmind-columns-2 { grid-template-columns: repeat(2, 1fr); }
.launchmind-columns-3 { grid-template-columns: repeat(3, 1fr); }
.launchmind-columns-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1400px) {
    .launchmind-columns-4 { grid-template-columns: repeat(3, 1fr); }
    }
    
@media (max-width: 1024px) {
    .launchmind-columns-3,
    .launchmind-columns-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
    .launchmind-columns-2,
    .launchmind-columns-3,
    .launchmind-columns-4 { grid-template-columns: 1fr; }
    
    .launchmind-blog-list {
        padding: 0 1rem;
    }
}

/* ============================================
   Card - Clean & Adaptive
   ============================================ */

.launchmind-post-card {
    background: var(--lm-card-bg);
    border-radius: var(--lm-card-radius);
    overflow: hidden;
    box-shadow: var(--lm-card-shadow);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    height: 100%;
    border: 1px solid var(--lm-card-border);
}

.launchmind-post-card:hover {
    box-shadow: var(--lm-card-shadow-hover);
    transform: translateY(-4px);
}

/* Image */
.launchmind-post-image {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    background: linear-gradient(135deg, #f0f0f0 0%, #e0e0e0 100%);
}

.launchmind-post-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.launchmind-post-card:hover .launchmind-post-image img {
    transform: scale(1.05);
}

/* Content */
.launchmind-post-content {
    padding: 1.25rem 1.5rem 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Title - Inherits website font */
.launchmind-post-title {
    font-size: 1.15rem;
    font-weight: 600;
    line-height: 1.35;
    margin: 0;
    color: var(--lm-text-primary, inherit);
    font-family: inherit;
}

.launchmind-post-title a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s ease;
}

.launchmind-post-title a:hover {
    color: var(--lm-accent);
}

/* Meta */
.launchmind-post-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--lm-text-secondary, inherit);
    opacity: 0.6;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-family: inherit;
}

.launchmind-post-author::before {
    content: "·";
    margin-right: 0.5rem;
}

/* Excerpt */
.launchmind-post-excerpt {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--lm-text-secondary, inherit);
    opacity: 0.75;
    margin: 0.25rem 0 0;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-family: inherit;
}

/* Tags */
.launchmind-post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: auto;
    padding-top: 0.5rem;
}

.launchmind-tag {
    padding: 0.25rem 0.6rem;
    font-size: 0.65rem;
    font-weight: 600;
    background: var(--lm-accent);
    opacity: 0.15;
    color: inherit;
    border-radius: 4px;
    text-transform: capitalize;
    letter-spacing: 0.02em;
}

/* Read More - Uses website accent color */
.launchmind-read-more {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--lm-accent);
    text-decoration: none;
    margin-top: 0.75rem;
    transition: all 0.2s ease;
    font-family: inherit;
}

.launchmind-read-more:hover {
    gap: 0.6rem;
}

.launchmind-read-more::after {
    content: "→";
    font-size: 1rem;
    transition: transform 0.2s ease;
}

.launchmind-read-more:hover::after {
    transform: translateX(3px);
}

/* ============================================
   Single Post
   ============================================ */

.launchmind-single-wrapper {
    width: 100%;
    margin: 0 auto;
    padding: 2rem 4%;
}

.launchmind-post-single {
    max-width: 800px;
    margin: 0 auto;
    background: var(--lm-card-bg);
    padding: 2.5rem;
    border-radius: var(--lm-card-radius);
    box-shadow: var(--lm-card-shadow);
    border: 1px solid var(--lm-card-border);
}

.launchmind-post-featured-image {
    margin: -2.5rem -2.5rem 2rem -2.5rem;
    border-radius: var(--lm-card-radius) var(--lm-card-radius) 0 0;
    overflow: hidden;
}

.launchmind-post-featured-image img {
    width: 100%;
    height: auto;
    display: block;
}

.launchmind-post-single .launchmind-post-title {
    font-size: clamp(1.5rem, 4vw, 2.25rem);
    font-weight: 700;
    line-height: 1.2;
    margin: 0 0 1rem;
    color: var(--lm-text-primary, inherit);
    font-family: inherit;
}

.launchmind-post-single .launchmind-post-meta {
    font-size: 0.85rem;
    color: var(--lm-text-secondary, inherit);
    opacity: 0.6;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--lm-card-border);
}

/* Post body - Inherits all typography */
.launchmind-post-body {
    font-size: 1rem;
    line-height: 1.75;
    color: var(--lm-text-primary, inherit);
    font-family: inherit;
}

.launchmind-post-body h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 2rem 0 0.75rem;
    color: inherit;
}

.launchmind-post-body h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 1.5rem 0 0.5rem;
    color: inherit;
}

.launchmind-post-body p {
    margin-bottom: 1.25rem;
}

.launchmind-post-body ul,
.launchmind-post-body ol {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.launchmind-post-body li {
    margin-bottom: 0.5rem;
}

.launchmind-post-body a {
    color: var(--lm-accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.launchmind-post-body a:hover {
    text-decoration: none;
}

.launchmind-post-body strong {
    font-weight: 700;
}

.launchmind-post-body img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1.5rem 0;
}

.launchmind-post-single .launchmind-post-tags {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--lm-card-border);
}

.launchmind-tags-label {
    font-weight: 600;
    margin-right: 0.5rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    opacity: 0.7;
}

.launchmind-back-link {
    display: inline-flex !important;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--lm-accent);
    color: white !important;
    text-decoration: none !important;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    font-family: inherit;
}

.launchmind-back-link:hover {
    opacity: 0.9;
    transform: translateY(-2px);
}

/* ============================================
   Language Switcher
   ============================================ */

.launchmind-language-switcher,
.launchmind-language-switcher-inline {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 2rem 0;
    padding: 1.5rem 0;
    border-top: 1px solid var(--lm-card-border);
    border-bottom: 1px solid var(--lm-card-border);
    flex-wrap: wrap;
    justify-content: center;
}

/* Inline version (between paragraphs) has slightly different styling */
.launchmind-language-switcher-inline {
    margin: 2.5rem 0;
    padding: 1.5rem;
    background: var(--lm-card-bg, rgba(255, 255, 255, 0.5));
    border-radius: 12px;
    border-top: 1px solid var(--lm-card-border);
    border-bottom: 1px solid var(--lm-card-border);
    border-left: none;
    border-right: none;
}

.launchmind-language-label {
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--lm-text-secondary, inherit);
    opacity: 0.7;
    margin-right: 0.5rem;
}

.launchmind-language-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.launchmind-language-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--lm-card-bg, rgba(255, 255, 255, 0.95));
    border: 1px solid var(--lm-card-border, rgba(0, 0, 0, 0.08));
    border-radius: 8px;
    text-decoration: none;
    color: var(--lm-text-primary, inherit);
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
    font-family: inherit;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.launchmind-language-button:hover {
    background: var(--lm-card-bg, rgba(255, 255, 255, 0.98));
    border-color: var(--lm-accent);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.launchmind-language-active {
    background: var(--lm-accent) !important;
    color: white !important;
    border-color: var(--lm-accent) !important;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.launchmind-language-active:hover {
    background: var(--lm-accent-hover, var(--lm-accent)) !important;
    transform: translateY(-1px);
}

.launchmind-language-flag {
    font-size: 1.1rem;
    line-height: 1;
}

.launchmind-language-code {
    font-size: 0.8rem;
    letter-spacing: 0.05em;
}

.launchmind-language-check {
    margin-left: 0.25rem;
    font-size: 0.9rem;
    font-weight: 700;
}

/* Dark mode support for language switcher */
@media (prefers-color-scheme: dark) {
    .launchmind-single-wrapper:not(.lm-dark):not(.lm-light) .launchmind-language-button {
        background: rgba(40, 40, 40, 0.9);
        border-color: rgba(255, 255, 255, 0.1);
        color: rgba(255, 255, 255, 0.9);
    }
    
    .launchmind-single-wrapper:not(.lm-dark):not(.lm-light) .launchmind-language-button:hover {
        background: rgba(50, 50, 50, 0.95);
        border-color: rgba(100, 200, 255, 0.5);
    }
}

.lm-dark .launchmind-language-button {
    background: rgba(40, 40, 40, 0.9) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    color: rgba(255, 255, 255, 0.9) !important;
}

.lm-dark .launchmind-language-button:hover {
    background: rgba(50, 50, 50, 0.95) !important;
    border-color: rgba(100, 200, 255, 0.5) !important;
}

/* Mobile responsive */
@media (max-width: 640px) {
    .launchmind-language-switcher {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    
    .launchmind-language-buttons {
        width: 100%;
        gap: 0.5rem;
    }
    
    .launchmind-language-button {
        flex: 1;
        min-width: 0;
        justify-content: center;
        padding: 0.6rem 0.8rem;
    }
}

/* ============================================
   Mobile
   ============================================ */

@media (max-width: 768px) {
    .launchmind-single-wrapper {
        padding: 1rem;
    }
    
    .launchmind-post-single {
        padding: 1.5rem;
    }
    
    .launchmind-post-featured-image {
        margin: -1.5rem -1.5rem 1rem -1.5rem;
    }
    
    .launchmind-post-single .launchmind-post-title {
        font-size: 1.5rem;
    }
    
    .launchmind-post-content {
        padding: 1rem 1.25rem 1.25rem;
    }
    
    .launchmind-post-title {
        font-size: 1.05rem;
    }
}

@media (max-width: 480px) {
    .launchmind-post-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
    
    .launchmind-post-author::before {
        display: none;
    }
}

/* ============================================
   Error States
   ============================================ */

.launchmind-error,
.launchmind-empty {
    padding: 2rem;
    text-align: center;
    border-radius: var(--lm-card-radius);
    margin: 2rem auto;
    max-width: 500px;
}

.launchmind-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
}

.launchmind-empty {
    background: var(--lm-card-bg);
    border: 1px dashed var(--lm-card-border);
    opacity: 0.7;
}

/* ============================================
   Custom Accent Color Support
   Add class like: lm-accent-teal, lm-accent-blue, etc.
   Or use inline style: style="--lm-accent: #00a69c"
   ============================================ */

.lm-accent-teal { --lm-accent: #00a69c !important; }
.lm-accent-blue { --lm-accent: #2563eb !important; }
.lm-accent-purple { --lm-accent: #7c3aed !important; }
.lm-accent-red { --lm-accent: #dc2626 !important; }
.lm-accent-orange { --lm-accent: #ea580c !important; }
.lm-accent-gold { --lm-accent: #d4a84b !important; }
.lm-accent-green { --lm-accent: #10b981 !important; }

/* ============================================
   Table Styling - Clean & Readable
   ============================================ */

.launchmind-single-wrapper table,
.launchmind-single-wrapper .lm-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.95rem;
    background: var(--lm-card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.launchmind-single-wrapper table thead,
.launchmind-single-wrapper .lm-table thead {
    background: rgba(0, 0, 0, 0.05);
}

.lm-dark .launchmind-single-wrapper table thead,
.lm-dark .launchmind-single-wrapper .lm-table thead {
    background: rgba(255, 255, 255, 0.08);
}

.launchmind-single-wrapper table th,
.launchmind-single-wrapper .lm-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--lm-card-border);
}

.launchmind-single-wrapper table td,
.launchmind-single-wrapper .lm-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--lm-card-border);
    }
    
.launchmind-single-wrapper table tr:last-child td,
.launchmind-single-wrapper .lm-table tr:last-child td {
    border-bottom: none;
}

.launchmind-single-wrapper table tr:hover,
.launchmind-single-wrapper .lm-table tr:hover {
    background: rgba(0, 0, 0, 0.02);
}

.lm-dark .launchmind-single-wrapper table tr:hover,
.lm-dark .launchmind-single-wrapper .lm-table tr:hover {
    background: rgba(255, 255, 255, 0.03);
    }
    
/* Right-align numeric columns (last column often has amounts) */
.launchmind-single-wrapper table td:last-child,
.launchmind-single-wrapper .lm-table td:last-child {
    font-weight: 500;
}

/* Mobile table - horizontal scroll */
@media (max-width: 640px) {
    .launchmind-single-wrapper table,
    .launchmind-single-wrapper .lm-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    
    .launchmind-single-wrapper table th,
    .launchmind-single-wrapper .lm-table th,
    .launchmind-single-wrapper table td,
    .launchmind-single-wrapper .lm-table td {
        padding: 10px 12px;
        font-size: 0.9rem;
    }
}
