/* NO COMMENTS NO DEBUGGING - CODE ONLY */
.editor-container {
    padding: 0;
    border: none;
    max-width: 100%;
    margin: 0;
    background-color: #fff;
    display: flex;
    flex-direction: column;
}

.editor-header {
    padding: 15px;
    border-bottom: 1px solid #e9ecef;
    margin-bottom: 15px;
    text-align: center;
}

.editor-header h1 {
    font-size: 24px;
    margin-bottom: 5px;
}

.editor-header p {
    font-size: 14px;
    color: #6c757d;
}

.theme-dark .editor-header {
    border-bottom-color: #444;
}

.theme-dark .editor-header p {
    color: #ccc;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .editor-header {
        border-bottom-color: #444;
    }
    :root:not(.theme-light) .editor-header p {
        color: #ccc;
    }
    :root:not(.theme-light) .editor-container {
        background-color: #333;
    }
}

.editor-layout {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    border: 1px solid #ccc;
    border-radius: 8px;
    overflow: hidden;
    padding: 15px;
    align-items: stretch;
}

.theme-dark .editor-layout {
    border-color: #666;
    background-color: #3a3a3a;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .editor-layout {
        border-color: #666;
    }
}

.pane {
    padding: 15px;
    border-right: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    flex-shrink: 1;
    flex-basis: 0;
}

.pane:last-child {
    border-right: none;
}

.theme-dark .pane {
    border-right-color: #444;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .pane {
        border-right-color: #444;
    }
}

.document-list-pane {
    flex: 0 0 240px;
    background-color: #f8f9fa;
    position: relative;
    min-height: 200px;
}

.theme-dark .document-list-pane {
    background-color: #444;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .document-list-pane {
        background-color: #444;
    }
}

.document-list-pane h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 18px;
    color: #333;
}

.theme-dark .document-list-pane h3 {
    color: #fff;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .document-list-pane h3 {
        color: #fff;
    }
}

#new-document-btn {
    width: 100%;
    padding: 8px 10px;
    margin-bottom: 15px;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    background-color: #f0f0f0;
    color: #333;
    transition: background-color 0.2s ease;
}

#new-document-btn:hover {
    background-color: #e0e0e0;
}

.theme-dark #new-document-btn {
    background-color: #555;
    color: #fff;
    border-color: #666;
}

.theme-dark #new-document-btn:hover {
    background-color: #666;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) #new-document-btn {
        background-color: #555;
        color: #fff;
        border-color: #666;
    }
    :root:not(.theme-light) #new-document-btn:hover {
        background-color: #666;
    }
}

.document-list {
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 5px;
}

.document-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 5px;
    margin-bottom: 5px;
    background-color: #fff;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 14px;
    line-height: 1.2;
    word-break: break-all;
}

.document-item.read-only-item {
    background-color: #e9ecef;
    color: #6c757d;
    cursor: default;
}

.document-item.read-only-item:hover {
    background-color: #e9ecef; /* No hover effect for read-only */
}

.theme-dark .document-item.read-only-item {
    background-color: #4a4a4a;
    color: #888;
    border-color: #555;
}

.theme-dark .document-item.read-only-item:hover {
    background-color: #4a4a4a;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .document-item.read-only-item {
        background-color: #4a4a4a;
        color: #888;
        border-color: #555;
    }

    :root:not(.theme-light) .document-item.read-only-item:hover {
        background-color: #4a4a4a;
    }
}

.document-item:hover {
    background-color: #e2e6ea;
}

.document-item.selected {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

.document-item.selected:hover {
    background-color: #0069d9;
}

.theme-dark .document-item {
    background-color: #555;
    border-color: #666;
    color: #fff;
}

.theme-dark .document-item:hover {
    background-color: #666;
}

.theme-dark .document-item.selected {
    background-color: #0056b3;
    border-color: #0056b3;
}

.theme-dark .document-item.selected:hover {
    background-color: #004085;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .document-item {
        background-color: #555;
        border-color: #666;
        color: #fff;
    }
    :root:not(.theme-light) .document-item:hover {
        background-color: #666;
    }
    :root:not(.theme-light) .document-item.selected {
        background-color: #0056b3;
        border-color: #0056b3;
    }
    :root:not(.theme-light) .document-item.selected:hover {
        background-color: #004085;
    }
}

.document-item span {
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.editor-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.editor-pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.editor-pane-header h3 {
    margin-top: 0;
    margin-bottom: 0;
    font-size: 18px;
    color: #333;
}

.theme-dark .editor-pane-header h3 {
    color: #fff;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .editor-pane-header h3 {
        color: #fff;
    }
}

/* Styles for the editor controls (font size buttons and delete button) */
.editor-controls {
    display: flex;
    align-items: center;
    gap: 8px; /* Spacing between buttons */
}

.control-btn {
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    background-color: #f0f0f0;
    color: #333;
    font-size: 14px;
    transition: all 0.2s ease;
    min-width: 32px; /* Ensure uniform width for 'A+', 'A-' */
    text-align: center;
}

.control-btn:hover {
    background-color: #e0e0e0;
    transform: translateY(-1px);
}

.control-btn:disabled {
    background-color: #e9ecef;
    color: #6c757d;
    cursor: not-allowed;
    border-color: #ccc;
}

.theme-dark .control-btn:disabled {
    background-color: #4a4a4a;
    color: #888;
    border-color: #555;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .control-btn:disabled {
        background-color: #4a4a4a;
        color: #888;
        border-color: #555;
    }
}

.theme-dark .control-btn {
    background-color: #555;
    color: #fff;
    border-color: #666;
}

.theme-dark .control-btn:hover {
    background-color: #666;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .control-btn {
        background-color: #555;
        color: #fff;
        border-color: #666;
    }
    :root:not(.theme-light) .control-btn:hover {
        background-color: #666;
    }
}

#delete-document-btn {
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    background-color: #f0f0f0;
    color: #dc3545;
    font-size: 14px;
    transition: background-color 0.2s ease;
}

#delete-document-btn:hover:not(:disabled) {
    background-color: #e0e0e0;
}

#delete-document-btn:disabled {
    background-color: #e9ecef;
    color: #6c757d;
    cursor: not-allowed;
    border-color: #ccc;
}

.theme-dark #delete-document-btn {
    background-color: #555;
    color: #ffb3ba;
    border-color: #666;
}

.theme-dark #delete-document-btn:hover:not(:disabled) {
    background-color: #666;
}

.theme-dark #delete-document-btn:disabled {
    background-color: #4a4a4a;
    color: #888;
    border-color: #555;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) #delete-document-btn {
        background-color: #555;
        color: #ffb3ba;
        border-color: #666;
    }
    :root:not(.theme-light) #delete-document-btn:hover:not(:disabled) {
        background-color: #666;
    }
    :root:not(.theme-light) #delete-document-btn:disabled {
        background-color: #4a4a4a;
        color: #888;
        border-color: #555;
    }
}

/* Preview toggle button styles */
.preview-toggle-btn {
    background-color: #f0f0f0;
    color: #333;
    border: 1px solid #ccc;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s ease;
    min-width: 32px;
    text-align: center;
}

.theme-dark .preview-toggle-btn {
    background-color: #555;
    color: #fff;
    border-color: #666;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .preview-toggle-btn {
        background-color: #555;
        color: #fff;
        border-color: #666;
    }
}

.preview-toggle-btn:hover {
    background-color: #e0e0e0;
    transform: translateY(-1px);
}

.theme-dark .preview-toggle-btn:hover {
    background-color: #666;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .preview-toggle-btn:hover {
        background-color: #666;
    }
}

.preview-toggle-btn.preview-active {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.3);
}

.preview-toggle-btn.preview-active:hover {
    background-color: #0069d9;
    border-color: #0069d9;
}

.theme-dark .preview-toggle-btn.preview-active {
    background-color: #0056b3;
    color: white;
    border-color: #0056b3;
    box-shadow: 0 2px 4px rgba(0, 86, 179, 0.4);
}

.theme-dark .preview-toggle-btn.preview-active:hover {
    background-color: #004085;
    border-color: #004085;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .preview-toggle-btn.preview-active {
        background-color: #0056b3;
        color: white;
        border-color: #0056b3;
        box-shadow: 0 2px 4px rgba(0, 86, 179, 0.4);
    }
    :root:not(.theme-light) .preview-toggle-btn.preview-active:hover {
        background-color: #004085;
        border-color: #004085;
    }
}

/* Hide the old toggle button */
#toggle-preview-btn {
    display: none;
}

/* The wrapper div now becomes a grid container that grows. */
#editor-wrapper {
    display: grid;
    flex-grow: 1;
    /* Define CSS variable for font size to be controlled by JS */
    --textarea-font-size: 16px; /* Default value, will be updated by JS */
}

/*
 * The textarea and this pseudo-element sit in the same grid cell.
 * The pseudo-element is invisible but mirrors the textarea's content,
 * forcing the grid cell to grow to the height of the content.
*/
#editor-wrapper::after {
    content: attr(data-replicated-value) " ";
    white-space: pre-wrap;
    word-break: break-word;
    visibility: hidden;

    /* These properties must match the textarea exactly for correct sizing. */
    padding: 10px;
    border: 1px solid transparent; /* Match border width for box-sizing consistency */
    font-family: "Consolas", "Monaco", monospace;
    font-size: var(--textarea-font-size); /* Use the CSS variable */
    grid-area: 1 / 1 / 2 / 2;
}

#markdown-input {
    /* Place the textarea in the same grid cell. */
    grid-area: 1 / 1 / 2 / 2;

    /* Allow the textarea to auto-resize. */
    resize: none;
    overflow: hidden;

    /* Keep original styles. */
    width: 100%;
    min-height: 200px; /* Explicit min-height for the textarea itself */
    padding: 10px;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    font-family: "Consolas", "Monaco", monospace;
    font-size: var(--textarea-font-size); /* Use CSS variable */
    outline: none;
    background-color: #f8f9fa;
    color: #333;
}

#markdown-input:disabled {
    background-color: #e9ecef;
    color: #6c757d;
    cursor: not-allowed;
    opacity: 0.6;
}

.theme-dark #markdown-input:disabled {
    background-color: #4a4a4a;
    color: #888;
    border-color: #555;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) #markdown-input:disabled {
        background-color: #4a4a4a;
        color: #fff;
        border-color: #555;
    }
}

.theme-dark #markdown-input {
    background-color: #444;
    color: #fff;
    border-color: #666;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) #markdown-input {
        background-color: #444;
        color: #fff;
        border-color: #666;
    }
}

.preview-pane {
    flex: 1;
    position: relative;
    background-color: #f8f9fa;
    transition:
        opacity 0.3s ease,
        visibility 0.3s ease,
        flex 0.3s ease;
    opacity: 1;
    visibility: visible;
}

.preview-pane.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    flex: 0 0 0; /* Collapse the preview pane completely */
}

.theme-dark .preview-pane {
    background-color: #444;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .preview-pane {
        background-color: #444;
    }
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.preview-header h3 {
    margin-top: 0;
    margin-bottom: 0;
    font-size: 18px;
    color: #333;
}

.theme-dark .preview-header h3 {
    color: #fff;
}

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .preview-header h3 {
        color: #fff;
    }
}

#markdown-preview {
    overflow-y: auto;
    padding: 10px;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    background-color: #f8f9fa;
    color: #333;
    font-size: 16px;
    line-height: 1.6;
    height: auto;
    min-height: 200px;
    flex-grow: 1;
    overflow-wrap: break-word;
    word-break: break-word;
}

.markdown-preview.hidden {
    display: none;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4,
.markdown-preview h5,
.markdown-preview h6 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: bold;
    line-height: 1.25;
}

.markdown-preview h1 {
    font-size: 2em;
}
.markdown-preview h2 {
    font-size: 1.5em;
}
.markdown-preview h3 {
    font-size: 1.25em;
}
.markdown-preview h4 {
    font-size: 1em;
}
.markdown-preview h5 {
    font-size: 0.875em;
}
.markdown-preview h6 {
    font-size: 0.85em;
}

.markdown-preview p {
    margin-bottom: 1em;
}

.markdown-preview ul,
.markdown-preview ol {
    margin-left: 20px;
    margin-bottom: 1em;
}

.markdown-preview li {
    margin-bottom: 0.5em;
}

.markdown-preview pre {
    background-color: #f6f8fa;
    padding: 1em;
    border-radius: 4px;
    overflow-x: auto;
    font-family: "Consolas", "Monaco", monospace;
    font-size: 0.9em;
    margin-bottom: 1em;
    white-space: pre-wrap; /* Ensure text wraps */
    word-break: break-word; /* Break long words */
}

.markdown-preview code {
    font-family: "Consolas", "Monaco", monospace;
    background-color: rgba(27, 31, 35, 0.05);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-size: 0.9em;
}

.markdown-preview pre code {
    background-color: transparent;
    padding: 0;
    font-size: 1em;
    white-space: pre-wrap; /* Ensure text wraps */
    word-break: break-word; /* Break long words */
}

.markdown-preview blockquote {
    margin: 0 0 1em;
    padding: 0 1em;
    color: #6a737d;
    border-left: 0.25em solid #dfe2e5;
}

.markdown-preview table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1em;
}

.markdown-preview th,
.markdown-preview td {
    border: 1px solid #dfe2e5;
    padding: 0.6em 1em;
    text-align: left;
}

.markdown-preview th {
    background-color: #f6f8fa;
    font-weight: bold;
}

.markdown-preview img {
    max-width: 100%;
    height: auto;
}

.theme-dark .preview-pane {
    background-color: #444;
}

.theme-dark #markdown-preview {
    background-color: #3a3a3a;
    color: #fff;
    border-color: #666;
}

.theme-dark .markdown-preview h1,
.theme-dark .markdown-preview h2,
.theme-dark .markdown-preview h3,
.theme-dark .markdown-preview h4,
.theme-dark .markdown-preview h5,
.theme-dark .markdown-preview h6,
.theme-dark .markdown-preview p,
.theme-dark .markdown-preview ul,
.theme-dark .markdown-preview ol,
.theme-dark .markdown-preview li,
.theme-dark .markdown-preview a {
    color: #fff;
}

.theme-dark .markdown-preview pre {
    background-color: #2a2a2a;
    color: #fff;
}

.theme-dark .markdown-preview code {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.theme-dark .markdown-preview blockquote {
    color: #999;
    border-left-color: #555;
}

.theme-dark .markdown-preview th,
.theme-dark .markdown-preview td {
    border-color: #555;
}

.theme-dark .markdown-preview th {
    background-color: #2a2a2a;
}

@media (prefers-color-scheme: dark) {
    html:root:not(.theme-light) .preview-pane {
        background-color: #444;
    }

    html:root:not(.theme-light) #markdown-preview {
        background-color: #3a3a3a;
        color: #fff;
        border-color: #666;
    }

    :root:not(.theme-light) .markdown-preview h1,
    :root:not(.theme-light) .markdown-preview h2,
    :root:not(.theme-light) .markdown-preview h3,
    :root:not(.theme-light) .markdown-preview h4,
    :root:not(.theme-light) .markdown-preview h5,
    :root:not(.theme-light) .markdown-preview h6,
    :root:not(.theme-light) .markdown-preview p,
    :root:not(.theme-light) .markdown-preview ul,
    :root:not(.theme-light) .markdown-preview ol,
    :root:not(.theme-light) .markdown-preview li,
    :root:not(.theme-light) .markdown-preview a {
        color: #fff;
    }

    :root:not(.theme-light) .markdown-preview code {
        background-color: rgba(255, 255, 255, 0.1);
        color: #fff;
    }
    :root:not(.theme-light) .markdown-preview blockquote {
        color: #999;
        border-left-color: #555;
    }
    :root:not(.theme-light) .markdown-preview th,
    :root:not(.theme-light) .markdown-preview td {
        border-color: #555;
    }
    :root:not(.theme-light) .markdown-preview th {
        background-color: #2a2a2a;
    }
}

@media (max-width: 768px) {
    .editor-layout {
        flex-direction: column;
    }

    .pane {
        border-right: none;
        border-bottom: 1px solid #e9ecef;
    }

    .pane:last-child {
        border-bottom: none;
    }

    .theme-dark .pane {
        border-bottom-color: #444;
    }

    @media (prefers-color-scheme: dark) {
        :root:not(.theme-light) .pane {
            border-bottom-color: #444;
        }
    }

    .document-list-pane {
        flex: none;
        width: 100%;
        max-height: 200px;
    }

    .editor-controls {
        gap: 6px;
    }

    .preview-toggle-btn {
        padding: 4px 8px;
        font-size: 14px;
    }

    .editor-pane,
    .preview-pane {
        flex: 1 1 auto;
        width: 100%;
    }

    .preview-pane.hidden {
        flex: 0 0 0; /* Ensure collapse on mobile too */
    }
}
