/* =========================================
   1. CSS Variables & Theming
   ========================================= */
/* Scope variables to the wrapper or root if needed globally (but here we scope to avoid pollution) */
.tinymce-scope{
    /* Base Colors (Dark Default) */
    --bg-color: #222222;
    --text-color: #ffffff;
    --text-muted: #aaaaaa;
    --link-color: #4691ff;

    /* Code Blocks */
    --code-bg: #1e1e1e;
    --code-header-bg: #2d2d2d;
    --code-text: #cccccc;

    /* Components - Borders & Backgrounds */
    --border-color: #444444;
    --table-border: #ffffff;
    --table-head-border: #007bff;

    /* Component Colors (Box Accents/Borders) */
    --box-accent-highlight: #ffffff;
    --box-accent-warning: #ffc107;
    --box-accent-info: #0dcaf0;
    --box-accent-success: #28a745;
    --box-accent-error: #dc3545;
    --box-accent-thinking: #2196f3;
    --box-accent-tag: #6f42c1;
    --box-accent-note: #adb5bd;

    /* Component Subtle Backgrounds (Adaptive) */
    --box-bg-highlight: rgba(255, 255, 255, 0.2); /* Very subtle white tint */
    --box-bg-warning: rgba(255, 193, 7, 0.2);
    --box-bg-info: rgba(13, 202, 240, 0.2);
    --box-bg-success: rgba(40, 167, 69, 0.2);
    --box-bg-error: rgba(220, 53, 69, 0.2);
    --box-bg-thinking: rgba(33, 150, 243, 0.2);
    --box-bg-tag: rgba(111, 66, 193, 0.2);
    --box-bg-note: rgba(128, 128, 128, 0.2);

    /* Interactive Elements */
    --hover-bg: rgba(255, 255, 255, 0.1);

    padding: 25px;
}

/* Light Mode Overrides */
.tinymce-scope.light-mode {
    --bg-color: #ffffff;
    --text-color: #333333;
    --text-muted: #666666;
    --link-color: #007bff;

    /* Code Blocks */
    --code-bg: #f5f5f5;
    --code-header-bg: #e9ecef;
    --code-text: #333333;

    /* Components */
    --border-color: #dddddd;
    --table-border: #cccccc;

    /* Box Backgrounds (Adjust for Light Mode if needed) */
    --box-bg-highlight: rgba(0, 0, 0, 0.05); /* Dark tint for light background */
    --hover-bg: rgba(0, 0, 0, 0.05);
}


.tox-tinymce {
    height: auto;
    max-height: 90dvh;
    position: relative;
}

body.tinymce-scope {
    background-color: var(--bg-color);
    color: var(--text-color) !important;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 1.5rem !important;
    font-size: 16px;
    box-sizing: border-box;
    overflow-y: auto !important;
    height: auto;
    
}

/* Typography */
.tinymce-scope h1,
.tinymce-scope h2,
.tinymce-scope h3,
.tinymce-scope h4,
.tinymce-scope h5,
.tinymce-scope h6 {
    color: var(--text-color);
    font-weight: 700;
    line-height: 1.2;
    display: block;
    margin: 0.5em 0;
    width: auto;
    word-break: break-word;
}

.tinymce-scope h1 {
    font-size: 2.25rem;
}

.tinymce-scope h2 {
    font-size: 1.875rem;
}

.tinymce-scope h3 {
    font-size: 1.5rem;
}

.tinymce-scope h4 {
    font-size: 1.25rem;
}

.tinymce-scope h5 {
    font-size: 1.125rem;
}

.tinymce-scope h6 {
    font-size: 1rem;
}

.tinymce-scope div {
    color: var(--text-color);
    margin: 0.5em 0;
    margin-bottom: 1em;
    font-size: 1.1rem;
    text-align: justify;
    word-break: break-word;
}

.tinymce-scope p {
    color: var(--text-color);
    margin: 0.5em 0;
    font-size: 1.1rem;
    text-align: justify;
    word-break: break-word;
}

.tinymce-scope strong {
    color: var(--box-accent-info);
    font-weight: 700;
}

.tinymce-scope a {
    color: var(--link-color);
    text-decoration: none;
}

.tinymce-scope a:hover {
    text-decoration: underline;
}

/* Lists */
.tinymce-scope ul,
.tinymce-scope ol {
    padding-left: 2em;
    margin-bottom: 1rem;
}

.tinymce-scope li {
    margin-bottom: 0.5em;
}

/* Blockquote */
.tinymce-scope blockquote {
    border-left: 4px solid var(--border-color);
    margin: 1.5em 0;
    padding: 0.5em 1em;
    color: var(--text-muted);
    font-style: italic;
    background: rgba(128, 128, 128, 0.05);
}


/* =========================================
   3. Tables
   ========================================= */
.tinymce-scope table {
    width: 100%;
    margin-bottom: 1.5rem;
    border-collapse: collapse;
    background-color: transparent;
}

.tinymce-scope table td,
.tinymce-scope table th {
    padding: 0.75rem;
    border: 1px solid var(--table-border);
    vertical-align: top;
}

.tinymce-scope table thead th {
    vertical-align: bottom;
    border-bottom: 2px solid var(--table-head-border);
    font-weight: bold;
    text-align: center;
}

.tinymce-scope table caption {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    caption-side: bottom;
}

/* =========================================
   4. Images
   ========================================= */
.tinymce-scope img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1.5rem auto;
    border-radius: 4px;
}

.tinymce-scope figure {
    margin: 0;
}

.tinymce-scope figcaption {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9em;
    margin-top: 0.5em;
}

/* Image Styles */
.tinymce-scope .rounded-img {
    border-radius: 12px;
}

.tinymce-scope .shadow-img {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.tinymce-scope .bordered-img {
    border: 2px solid var(--border-color);
}

.tinymce-scope .background-img {
    background-color: var(--border-color);
    padding: 5px;
}

.tinymce-scope .flip-horizontal {
    transform: scaleX(-1);
}

.tinymce-scope .flip-vertical {
    transform: scaleY(-1);
}

/* =========================================
   5. Code Blocks
   ========================================= */
.tinymce-scope pre[class*=language-] {
    position: relative;
    background: var(--code-bg) !important;
    color: var(--code-text);
    font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
    font-size: 15px;
    line-height: 1.5;
    padding: 20px;
    overflow: hidden;
    overflow-x: auto;
    margin: 0;
}


.tinymce-scope.dark-mode pre[class*=language-] {
    border: 1px solid #c0c0c0;
    /* Slightly darker border for visibility */
}

/* Light Mode Code Header Text Override */
.tinymce-scope.light-mode pre[class*=language-] {
    border: 1px solid #c0c0c0;
    /* Slightly darker border for visibility */
}

/* Inline code */
.tinymce-scope :not(pre)>code {
    background-color: var(--hover-bg);
    color: var(--box-accent-thinking);
    padding: 0.2em 0.4em;
    border-radius: 4px;
}

/* Code Container with Header */
.tinymce-scope .code-container {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin: 1.5rem 0;
    overflow: hidden;
}

.tinymce-scope .code-header {
    height: 40px;
    background: var(--code-header-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    font-family: monospace;
    font-size: 13px;
    color: #ccc;
}


.tinymce-scope .copy-button {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8em;
    transition: all 0.2s;
}

.tinymce-scope .copy-button:hover {
    background: var(--hover-bg);
}


/* =========================================
   6. Custom Boxes (Components)
   ========================================= */
/* Base Box Style */
[class$="-box-tinymce"] {
    padding: 1em;
    margin: 1em 0;
    border-radius: 6px;
    border-left-width: 6px;
    border-left-style: solid;
    position: relative;
    color: #ffffff;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05); /* Softer shadow */
    background: transparent; /* Default, overridden by specific classes */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Box Variants with Icons */
.highlight-box-tinymce {
    border-left-color: var(--box-accent-highlight);
    background-color: var(--box-bg-highlight);
}

.warning-box-tinymce {
    border-left-color: var(--box-accent-warning);
    background-color: var(--box-bg-warning);
}

.info-box-tinymce {
    border-left-color: var(--box-accent-info);
    background-color: var(--box-bg-info);
}

.success-box-tinymce {
    border-left-color: var(--box-accent-success);
    background-color: var(--box-bg-success);
}

.error-box-tinymce {
    border-left-color: var(--box-accent-error);
    background-color: var(--box-bg-error);
}

.thinking-box-tinymce {
    border-left-color: var(--box-accent-thinking);
    background-color: var(--box-bg-thinking);
}

.tag-box-tinymce {
    border-left-color: var(--box-accent-tag);
    background-color: var(--box-bg-tag);
}

.note-box-tinymce {
    border-left-color: var(--box-accent-note);
    background-color: var(--box-bg-note);
}

.custom-box-tinymce {
    border: 2px dashed var(--text-muted);
    border-left: 2px dashed var(--text-muted);
    border-radius: 10px;
    background-color: var(--box-bg-note); /* Use note bg as fallback */
}

.question-box-tinymce {
    background-color: rgba(0, 123, 255, 0.1);
    border: 2px dashed #007bff;
    border-radius: 12px;
}

.answer-box-tinymce {
    background-color: rgba(23, 162, 184, 0.1);
    border: 2px dashed #17a2b8;
    border-radius: 12px;
}

.todo-box-tinymce {
    background-color: rgba(173, 181, 189, 0.1);
    border: 2px dashed #adb5bd;
    border-radius: 12px;
}

.done-box-tinymce {
    background-color: rgba(40, 167, 69, 0.1);
    border: 2px dashed #28a745;
    border-radius: 12px;
}

.reminder-box-tinymce {
    background-color: rgba(255, 193, 7, 0.1);
    border: 2px dashed #ffc107;
    border-radius: 12px;
}

.alert-box-tinymce {
    background-color: rgba(220, 53, 69, 0.1);
    border: 2px solid #dc3545;
    border-radius: 12px;
    box-shadow: 0 0 15px rgba(220, 53, 69, 0.1);
}

/* =========================================
   7. Inline Text Styles & Icons
   ========================================= */
span[data-icon]::before {
    content: attr(data-icon) " ";
    margin-right: 0.25em;
}

.success-text-tinymce {
    color: #28a745;
}

.error-text-tinymce {
    color: #dc3545;
}

.info-text-tinymce {
    color: #0dcaf0;
}

.highlight-text-tinymce {
    color: #f8f9fa;
}

.warning-text-tinymce {
    color: #ffc107;
}

.tag-text-tinymce {
    color: #9b73e5;
}

.thinking-text-tinymce {
    color: #008eff;
}

.question-text-tinymce {
    color: #007bff;
}

.answer-text-tinymce {
    color: #17a2b8;
}

.reminder-text-tinymce {
    color: #ffc107;
}

.alert-text-tinymce {
    color: #dc3545;
}

.note-text-tinymce {
    color: #6c757d;
}

.search-text-tinymce {
    color: #17a2b8;
}

.category-text-tinymce {
    color: #fd7e14;
}


/* =========================================
   8. List Styles
   ========================================= */
.tinymce-scope ul.check-list {
    list-style: none;
}

.tinymce-scope ul.check-list li::before {
    content: "✅ ";
    margin-right: 0.5em;
}

.tinymce-scope ul.star-list {
    list-style: none;
}

.tinymce-scope ul.star-list li::before {
    content: "⭐ ";
    margin-right: 0.5em;
}

.tinymce-scope ul.button-list {
    list-style: none;
}

.tinymce-scope ul.button-list li::before {
    content: "🔘 ";
    margin-right: 0.5em;
}


@media (max-width: 768px) {
    body.tinymce-scope {
        padding: 1rem !important;
        font-size: 15px;
    }

    .tinymce-scope h1 { font-size: 1.75rem; }
    .tinymce-scope h2 { font-size: 1.5rem; }
    .tinymce-scope h3 { font-size: 1.35rem; }
    .tinymce-scope h4 { font-size: 1.2rem; }
    
    /* Optimize Table Display */
    .tinymce-scope table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }

    .tinymce-scope .columns-box {
        flex-direction: column;
    }

    /* Adjust Code Blocks */
    .tinymce-scope pre[class*=language-] {
        padding: 15px;
        font-size: 13px;
        border-radius: 6px;
    }
    
    /* Adjust Images */
    .tinymce-scope img {
        margin: 1rem auto;
    }
}

@media (max-width: 480px) {
    body.tinymce-scope {
        padding: 0.75rem !important;
    }

    .tinymce-scope h1 { font-size: 1.5rem; }
    .tinymce-scope h2 { font-size: 1.35rem; }
    
    .tinymce-scope p, 
    .tinymce-scope li {
        text-align: left; /* Justify can look weird on narrow screens */
        font-size: 1rem;
    }

    /* Adjust Boxes for small screens */
    [class$="-box-tinymce"] {
        padding: 0.75em;
        margin: 0.75em 0;
        border-left-width: 4px;
    }

    /* Tweak lists indentation */
    .tinymce-scope ul,
    .tinymce-scope ol {
        padding-left: 1.5em;
    }
}