/* Rich content styling for HTML content from CMS */
.rich-content {
    color: #4a5568;
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    line-height: 1.7;
    font-size: 16px;
    
    /* Better text rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Headings with better hierarchy */
.rich-content h1,
.rich-content h2,
.rich-content h3,
.rich-content h4,
.rich-content h5,
.rich-content h6 {
    color: #01306e;
    font-weight: 600;
    line-height: 1.3;
    margin-top: 2rem;
    margin-bottom: 1rem;
    font-family: 'Poppins', sans-serif;
}

.rich-content h1 { 
    font-size: 2.25rem;
    font-weight: 700;
    margin-top: 0;
}
.rich-content h2 { 
    font-size: 1.875rem;
    font-weight: 650;
}
.rich-content h3 { 
    font-size: 1.5rem;
    font-weight: 600;
}
.rich-content h4 { 
    font-size: 1.25rem;
    font-weight: 600;
}
.rich-content h5 { 
    font-size: 1.125rem;
    font-weight: 600;
}
.rich-content h6 { 
    font-size: 1rem;
    font-weight: 600;
}

/* Paragraphs with better spacing */
.rich-content p {
    margin-bottom: 1.5rem;
    line-height: 1.75;
}

.rich-content p:last-child {
    margin-bottom: 0;
}

/* Better handling of br tags */
.rich-content br {
    display: block;
    content: "";
    margin-top: 0.75rem;
}

/* Double br tags (common in user content) */
.rich-content br + br {
    margin-top: 1.5rem;
}

/* When br is followed by text that looks like a heading */
.rich-content p > br:first-child {
    display: none; /* Remove leading br tags */
}

/* Style text after br that appears to be a subtitle/heading */
.rich-content p {
    position: relative;
}

 

/* Lists with proper styling */
.rich-content ul,
.rich-content ol {
    margin: 1.5rem 0;
    padding-left: 0;
    list-style: none;
}

.rich-content ul {
    position: relative;
}

.rich-content ul li {
    position: relative;
    margin-bottom: 0.75rem;
    padding-left: 1.75rem;
    line-height: 1.7;
}

.rich-content ul li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.75rem;
    width: 6px;
    height: 6px;
    background-color: #0086e9;
    border-radius: 50%;
    transform: translateY(-50%);
}

.rich-content ol {
    counter-reset: list-counter;
}

.rich-content ol li {
    position: relative;
    margin-bottom: 0.75rem;
    padding-left: 2rem;
    line-height: 1.7;
    counter-increment: list-counter;
}

.rich-content ol li::before {
    content: counter(list-counter) '.';
    position: absolute;
    left: 0;
    top: 0;
    color: #0086e9;
    font-weight: 600;
    font-size: 0.95rem;
}

/* Nested lists */
.rich-content ul ul,
.rich-content ol ol,
.rich-content ul ol,
.rich-content ol ul {
    margin: 0.5rem 0;
    margin-left: 1rem;
}

.rich-content ul ul li::before {
    width: 4px;
    height: 4px;
    background-color: #6b7280;
}

/* Inline elements */
.rich-content strong,
.rich-content b {
    font-weight: 600;
    color: #01306e;
}

.rich-content em,
.rich-content i {
    font-style: italic;
    color: #374151;
}

/* Links with better styling */
.rich-content a {
    color: #0086e9;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: all 0.2s ease;
}

.rich-content a:hover {
    color: #006bb8;
    text-decoration-thickness: 2px;
}

/* Blockquotes */
.rich-content blockquote {
    border-left: 4px solid #0086e9;
    margin: 2rem 0;
    padding: 1rem 1.5rem;
    background: #f8fafc;
    border-radius: 0 8px 8px 0;
    font-style: italic;
    color: #4a5568;
    font-size: 1.1rem;
    line-height: 1.6;
}

.rich-content blockquote p {
    margin-bottom: 0;
}

/* Code elements */
.rich-content code {
    background: #f1f5f9;
    color: #e11d48;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 0.9rem;
    font-weight: 500;
}

.rich-content pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1.5rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 2rem 0;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 0.9rem;
    line-height: 1.5;
}

.rich-content pre code {
    background: none;
    color: inherit;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

/* Tables */
.rich-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 2rem 0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.rich-content th,
.rich-content td {
    border: 1px solid #e5e7eb;
    padding: 0.75rem 1rem;
    text-align: left;
    line-height: 1.5;
}

.rich-content th {
    background: #f8fafc;
    font-weight: 600;
    color: #01306e;
    border-bottom: 2px solid #d1d5db;
}

.rich-content tr:nth-child(even) {
    background: #f9fafb;
}

.rich-content tr:hover {
    background: #f3f4f6;
}

/* Images */
.rich-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1.5rem 0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Horizontal rules */
.rich-content hr {
    border: none;
    height: 1px;
    background: linear-gradient(to right, transparent, #d1d5db, transparent);
    margin: 3rem 0;
}

/* Better spacing for first and last elements */
.rich-content > *:first-child {
    margin-top: 0;
}

.rich-content > *:last-child {
    margin-bottom: 0;
}

/* Handle empty paragraphs (common in WYSIWYG content) */
.rich-content p:empty {
    display: none;
}

/* Handle paragraphs that only contain br tags */
/* .rich-content p:has(br):not(:has(text)):not(:has(*:not(br))) {
    margin: 0.5rem 0;
    height: 0.5rem;
} */

/* Fix spacing when multiple empty elements */
.rich-content p + p:empty + p {
    margin-top: 0;
}

/* Handle inline styles from editors (normalize them) */
.rich-content p[style*="text-align: center"] {
    text-align: center;
}

.rich-content p[style*="text-align: right"] {
    text-align: right;
}

/* Remove excessive spacing from nested elements */
.rich-content p > span {
    line-height: inherit;
}

/* Fix common WYSIWYG patterns */
.rich-content p > span > br {
    margin-top: 0.5rem;
}

/* Handle non-breaking spaces */
.rich-content p {
    white-space: pre-line;
}

/* Clean up extra whitespace while preserving intentional breaks */
.rich-content {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .rich-content {
        font-size: 15px;
    }
    
    .rich-content h1 { font-size: 1.875rem; }
    .rich-content h2 { font-size: 1.5rem; }
    .rich-content h3 { font-size: 1.25rem; }
    
    .rich-content ul li,
    .rich-content ol li {
        padding-left: 1.5rem;
    }
    
    .rich-content blockquote {
        padding: 0.75rem 1rem;
        margin: 1.5rem 0;
    }
    
    .rich-content pre {
        padding: 1rem;
        font-size: 0.85rem;
    }
}