#mainResizer,
#appChatResizer,
.report-preview-resizer {
    background-color: hsl(var(--b2));
    transition: background-color 0.2s ease;
}

#mainResizer:hover,
#appChatResizer:hover,
.report-preview-resizer:hover {
    background-color: hsl(var(--p));
}

#appChatResizer,
.report-preview-resizer {
    width: 6px;
    cursor: col-resize;
    flex-shrink: 0;
}

/* START: Added styles for editable preview */
.report-html-preview.editing-preview {
    outline: 2px solid hsl(var(--p));
    box-shadow: 0 0 8px hsl(var(--p) / 0.4);
}

.report-html-preview[contenteditable=true]:focus {
    outline: none;
}

/* END: Added styles for editable preview */


.EasyMDEContainer {
    border-color: hsl(var(--b3));
}

.EasyMDEContainer .editor-toolbar {
    background-color: hsl(var(--b2));
    border-bottom-color: hsl(var(--b3));
}

.EasyMDEContainer .editor-toolbar button {
    border-color: hsl(var(--b3));
    color: hsl(var(--bc));
}

.EasyMDEContainer .editor-toolbar button:hover,
.EasyMDEContainer .editor-toolbar button.active {
    background-color: hsl(var(--b3));
    border-color: hsl(var(--b3));
}

.EasyMDEContainer .editor-toolbar i.separator {
    border-color: hsl(var(--b3));
}

.EasyMDEContainer .CodeMirror {
    background-color: hsl(var(--b1));
    color: hsl(var(--bc));
    border-color: hsl(var(--b3));
    caret-color: hsl(var(--bc));
}

.EasyMDEContainer .editor-statusbar {
    background-color: hsl(var(--b2));
    color: hsl(var(--bc) / 0.6);
    border-top-color: hsl(var(--b3));
}

/* START: FIX FOR FULLSCREEN TOOLBAR */
.EasyMDEContainer.fullscreen .editor-toolbar {
    position: relative;
    /* Ensure z-index is respected */
    z-index: 1000;
    /* Higher than CodeMirror's fullscreen z-index */
    background-color: hsl(var(--b2));
    /* Ensure it has a background */
}

/* END: FIX FOR FULLSCREEN TOOLBAR */

.log-item {
    border-bottom: 1px solid hsl(var(--b3));
}

.log-item:last-child {
    border-bottom: none;
}

.log-item-header {
    padding: 6px 8px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.2s;
}

.log-item-header:hover {
    background-color: hsl(var(--b2));
}

.log-title {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: ui-sans-serif, system-ui, sans-serif;
    color: hsl(var(--bc));
    font-size: 0.8rem;
}

.log-status {
    margin-left: 8px;
    font-size: 1.1em;
}

.log-status.status-success::before {
    content: '✅';
}

.log-status.status-error::before {
    content: '❌';
}

.log-status.status-pending::before {
    content: '⏳';
}

.log-status.status-milestone::before {
    content: '🏁';
}

.log-toggle-icon {
    margin-right: 6px;
    transition: transform 0.2s;
    width: 10px;
    text-align: center;
}

.log-toggle-icon::before {
    content: '▶';
    font-size: 0.7em;
    display: inline-block;
}

.log-item-header.expanded .log-toggle-icon {
    transform: rotate(90deg);
}

.log-item-details {
    display: none;
    padding: 8px;
    background-color: hsl(var(--n));
    color: hsl(var(--nc));
}

.log-item-details pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
    font-size: 0.9em;
}


.message-control-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-right: 8px;
    margin-left: 8px;
    opacity: 0.2;
    transition: opacity 0.2s ease-in-out;
    flex-wrap: wrap;
}

.chat-bubble:hover .message-control-bar {
    opacity: 1;
}

.chat-end .message-control-bar {
    flex-direction: row-reverse;
}

.btn-details-inline,
.btn-full-report {
    opacity: 0.5;
    transition: opacity 0.2s;
}

.chat-bubble:hover .btn-details-inline,
.chat-bubble:hover .btn-full-report {
    opacity: 1;
}


.markdown-editor-container .EasyMDEContainer {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.markdown-editor-container .CodeMirror {
    flex-grow: 1;
    height: 0;
}

.markdown-editor-container .CodeMirror-scroll {
    overflow: auto !important;
}


.markdown-editor-container .EasyMDEContainer .CodeMirror {
    background-color: #ffffff !important;
    color: #1f2937 !important;
}

.markdown-editor-container .EasyMDEContainer .editor-toolbar {
    background-color: #f9fafb !important;
    border-bottom-color: #e5e7eb !important;
}

.markdown-editor-container .EasyMDEContainer .editor-toolbar button {
    color: #374151 !important;
    border-color: #e5e7eb !important;
}

.markdown-editor-container .EasyMDEContainer .editor-toolbar button:hover,
.markdown-editor-container .EasyMDEContainer .editor-toolbar button.active {
    background-color: #f3f4f6 !important;
}

.markdown-editor-container .EasyMDEContainer .editor-toolbar i.separator {
    border-color: #e5e7eb !important;
}

.markdown-editor-container .EasyMDEContainer .editor-statusbar {
    background-color: #f9fafb !important;
    color: #6b7280 !important;
    border-top-color: #e5e7eb !important;
}

/* 1. Define the blink animation */
@keyframes cmCursorBlink {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

/* 2. Apply it to all your cursor selectors */
.markdown-editor-container .EasyMDEContainer .CodeMirror-cursor,
.notebook-cell .cell-code-container .CodeMirror-cursor,
.cm-s-eclipse .CodeMirror-cursor {
    border-left: 2px solid #ffae00 !important;
    /* ensure we animate opacity instead of forcing visibility */
    opacity: 1 !important;
    animation: cmCursorBlink 1s step-start infinite !important;
}

/* Themed CodeMirror editor for Jupyter cells */
.notebook-cell .cell-code-container .CodeMirror {
    height: auto;
    border: 1px solid hsl(var(--b3));
    border-radius: var(--rounded-btn, 0.5rem);
    background-color: hsl(var(--b1));
    color: hsl(var(--bc));
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    caret-color: hsl(var(--p));
    /* ADDED: Makes the cursor visible */
}

/* START: Added for static code view */
.notebook-cell .cell-static-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    min-height: calc(40px + 0.5rem * 2 + 1px * 2); /* Match CodeMirror's min-height + padding + border */
    line-height: 1.45; /* CodeMirror's default */
    color: hsl(var(--bc));
    background-color: hsl(var(--b1));
}
.notebook-cell .cell-static-code pre {
    border: 1px solid transparent; /* To match CM layout for alignment */
}
.notebook-cell .cell-static-code code {
    white-space: pre;
}
.notebook-cell .cell-static-code .cm-s-eclipse {
    background-color: transparent !important;
}
/* END: Added for static code view */

.notebook-cell .cell-code-container .CodeMirror-scroll {
    min-height: 40px;
}

.notebook-cell .cell-code-container .CodeMirror-gutters {
    background-color: hsl(var(--b2));
    border-right: 1px solid hsl(var(--b3));
}

.notebook-cell .cell-code-container .CodeMirror-linenumber {
    color: hsl(var(--bc) / 0.4);
}


/* ——————————————————————————————————————————————————————————
   Make CodeMirror text selection visibly highlighted
   —————————————————————————————————————————————————————————— */

/* 1) CodeMirror’s internal selection spans */
.CodeMirror .CodeMirror-selected {
    background-color: rgba(255, 174, 0, 0.3) !important;
}

.CodeMirror-focused .CodeMirror-selected {
    background-color: rgba(255, 174, 0, 0.5) !important;
}

/* 2) Native text selection inside the editor */
.CodeMirror ::selection {
    background-color: rgba(255, 174, 0, 0.3) !important;
}

.CodeMirror::-moz-selection {
    background-color: rgba(255, 174, 0, 0.3) !important;
}


/* START: CSS Fix for Jupyter Notebook Theme */
.cm-s-eclipse {
    background: hsl(var(--b1)) !important;
    color: hsl(var(--bc)) !important;
    caret-color: hsl(var(--bc)) !important;
    /* ADDED: Cursor for other CM instances */
}

.cm-s-eclipse .CodeMirror-gutters {
    background: hsl(var(--b2)) !important;
    border-right-color: hsl(var(--b3)) !important;
}

.cm-s-eclipse .CodeMirror-linenumber {
    color: hsl(var(--bc) / 0.5) !important;
}

.cm-s-eclipse .CodeMirror-activeline-background {
    background: hsl(var(--b2)) !important;
}



/* END: CSS Fix for Jupyter Notebook Theme */


/* ==========================================================================
   JUPYTER CELL OUTPUT - START: IMPROVED COLORS & SCROLL
   ========================================================================== */
.cell-output {
    padding: 0.5rem 0;
    max-height: 75vh;
    overflow-y: auto;
}

.cell-output .output-item {
    color: oklch(var(--b3));
    border: 1px solid hsl(var(--b3));
    /* Use theme's border color */
    border-radius: 0.375rem;
    /* Equivalent to .rounded-md */
    padding: 0.75rem;
    margin-top: 0.5rem;
    white-space: pre-wrap;
    word-break: break-all;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.cell-output .text-error {
    color: oklch(var(--er));
    border-color: hsl(var(--er) / 0.4);
}

.cell-output .output-item pre {
    white-space: pre-wrap;
    word-break: break-all;
    background: transparent;
    color: inherit;
    padding: 0;
    margin: 0;
    font-size: 0.875em;
    /* Slightly smaller for preformatted text */
}

.copy-output-btn {
    color: hsl(var(--bc) / 0.6);
}

.copy-output-btn:hover {
    color: hsl(var(--bc));
}

/* END: IMPROVED COLORS & SCROLL */
.notebook-cell .cell-controls {
    opacity: 0.2;
    transition: opacity 0.2s ease-in-out;
}

.notebook-cell:hover .cell-controls,
.notebook-cell .cell-controls:hover {
    opacity: 1;
}

/* START: New styles for fixed Jupyter scroll buttons */
.jupyter-scroll-buttons {
    position: absolute;
    bottom: 1.5rem;
    right: 1.5rem; /* Adjusted for better mobile fit */
    z-index: 40; /* Below dropdowns, but above content */
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    opacity: 0.3;
    transition: opacity 0.2s ease-in-out;
}

.jupyter-panel-content:hover .jupyter-scroll-buttons {
    opacity: 1;
}

.jupyter-scroll-buttons.hidden {
    display: none;
}
/* START: Jupyter inter-cell inserter bar */
.cell-inserter-bar {
    position: absolute;
    bottom: -16px;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
    pointer-events: none;
    z-index: 20;
}

/* Show on hover of parent cell OR if the bar itself is hovered */
.notebook-cell:hover .cell-inserter-bar,
.cell-inserter-bar:hover {
    opacity: 1;
    pointer-events: auto;
}

.cell-inserter-bar .divider {
    border-top: 1px dashed hsl(var(--b3));
}

.cell-inserter-bar .inserter-buttons {
    display: flex;
    gap: 8px;
    background-color: hsl(var(--b2));
    padding: 0 12px;
    flex-shrink: 0;
    border-radius: var(--rounded-box, 1rem);
}

/* END: Jupyter inter-cell inserter bar */


.prose p {
    margin-top: 1.25em;
    margin-bottom: 1.25em;
}

.prose a {
    color: hsl(var(--p));
    text-decoration: underline;
}

.prose a:hover {
    color: hsl(var(--pc));
}

.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
    margin-top: 1.6em;
    margin-bottom: 0.8em;
    font-weight: 600;
    line-height: 1.2;
}

.prose h1 {
    font-size: 2.0rem;
}

.prose h2 {
    font-size: 1.5rem;
}

.prose h3 {
    font-size: 1.25rem;
}

.prose h4 {
    font-size: 1.1rem;
}

.prose h5 {
    font-size: 1.0rem;
}

.prose h6 {
    font-size: 0.9rem;
    color: hsl(var(--bc) / 0.8);
}

.prose ul,
.prose ol {
    margin: 1.25em 0;
    padding-left: 1.75em;
}

.prose ul {
    list-style-type: disc;
}

.prose ol {
    list-style-type: decimal;
}

.prose li {
    margin-top: 0.5em;
}

.prose li>p {
    margin: 0;
}

.prose blockquote {
    margin: 1.6em 0;
    padding-left: 1em;
    border-left: 0.25rem solid hsl(var(--b3));
    color: hsl(var(--bc) / 0.8);
    font-style: italic;
}

.prose pre {
    background-color: hsl(var(--b2));
    color: hsl(var(--bc));
    padding: 1em;
    margin: 1.6em 0;
    border-radius: 0.5rem;
    overflow-x: auto;
    white-space: pre;
}

.prose code {
    background-color: hsl(var(--b2));
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 85%;
    border-radius: 0.25rem;
    color: hsl(var(--bc));
}

.prose pre code {
    background-color: transparent;
    padding: 0;
    margin: 0;
    font-size: inherit;
    border-radius: 0;
    color: inherit;
    white-space: inherit;
}

.prose table {
    width: 100%;
    margin: 1.6em 0;
    border-collapse: collapse;
}

.prose td,
.prose th {
    padding: 0.6rem 0.8rem;
    border: 1px solid hsl(var(--b3));
    text-align: left;
    vertical-align: top;
}

.prose th {
    font-weight: 600;
    background-color: hsl(var(--b2));
}

.prose hr {
    border-top: 1px solid hsl(var(--b3));
    margin: 2em 0;
}


.chat-bubble {
    box-sizing: border-box;
    max-width: 100%;
    overflow-wrap: break-word;
    word-break: break-word;
}

.message-text-container {
    overflow-wrap: break-word;
    word-break: break-word;
}

.message-text-container code {
    white-space: pre-wrap !important;
    overflow-wrap: break-word !important;
    word-break: break-word !important;
}

.message-text-container pre {
    white-space: pre-wrap !important;
    word-break: break-all !important;
    overflow-x: auto !important;
    background-color: hsl(var(--b2)) !important;
    color: hsl(var(--bc)) !important;
    padding: 1rem !important;
    border-radius: 0.5rem;
}

/* START: Code Block Copy Button in Chat */
.message-text-container .code-block-wrapper {
    position: relative;
}

.message-text-container .copy-code-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 1;
    opacity: 0.3;
    transition: opacity 0.2s ease-in-out;
}

.message-text-container .code-block-wrapper:hover .copy-code-btn {
    opacity: 1;
}

/* END: Code Block Copy Button in Chat */

#messageInput {
    resize: none;
    overflow-y: auto;
    transition: height 0.1s ease-out;
    max-height: 200px;
}

#fileList .file-actions {
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
}

#fileList li:hover .file-actions {
    opacity: 1;
}

#fileList .menu-title {
    pointer-events: none;
}

@keyframes flash-border-animation {
    0% {
        border-color: hsl(var(--p) / 0.8);
        box-shadow: 0 0 8px hsl(var(--p) / 0.4);
    }

    100% {
        border-color: transparent;
        box-shadow: none;
    }
}

.new-message-flash .chat-bubble {
    border: 1px solid transparent;
    animation: flash-border-animation 1.5s ease-out;
}

.chat-image .fa-solid {
    position: relative;
    top: 1px;
}

/* START: MODIFIED - Styles for Data Viewer Table */
#dataFrameTableContainer {
    display: block;
    border: 1px solid hsl(var(--b3));
    border-radius: var(--rounded-btn, 0.5rem);
    /* flex-grow and overflow are handled by parent/self classes */
}

#dataFrameTableContainer .table {
    table-layout: auto;
    width: 100%;
}

#dataFrameTableContainer .table th,
#dataFrameTableContainer .table td {
    white-space: nowrap;
    padding: 0.5rem 0.75rem;
}

#dataFrameTableContainer .table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: hsl(var(--b3));
    border-bottom: 2px solid hsl(var(--p));
    background-image: none;
    cursor: pointer;
}

#dataFrameTableContainer .table thead th:hover {
    background-color: hsl(var(--b2));
}

#dataFrameTableContainer .table tbody th {
    position: sticky;
    left: 0;
    z-index: 5;
    background-color: hsl(var(--b2));
    border-right: 1px solid hsl(var(--b3));
    background-image: none;
}

#dataFrameTableContainer .table thead th:first-child {
    left: 0;
    z-index: 15;
}

/* END: MODIFIED */

#variableListView .table td,
#variableListView .table th {
    max-width: 200px;
}

#variableListView .table td:first-child,
#variableListView .table th:first-child {
    max-width: 150px;
    font-weight: 600;
}

#variableListView .table td:last-child,
#variableListView .table th:last-child {
    width: 80px;
    max-width: 80px;
    text-align: right;
}

/* START: Added for Text Editor */
.text-editor-container,
.text-editor-container .CodeMirror {
    height: 100%;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

/* START: Added for Spreadsheet Viewer */
.spreadsheet-app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.spreadsheet-container {
    flex-grow: 1;
    overflow: auto;
    background-color: hsl(var(--b1));
    cursor: cell;
    isolation: isolate; /* FIX: Create a stacking context to contain header z-indexes */
}

.spreadsheet-container:focus {
    outline: none;
}

.spreadsheet-container table {
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.8rem;
    table-layout: fixed;
}

.spreadsheet-container th,
.spreadsheet-container td {
    border-right: 1px solid hsl(var(--b3));
    border-bottom: 1px solid hsl(var(--b3));
    padding: 4px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background-color 0.1s ease-in-out;
}

.spreadsheet-container th {
    background-color: hsl(var(--b2));
    font-weight: bold;
    position: sticky;
    top: 0;
    z-index: 4;
    /* Higher z-index for column headers */
    user-select: none;
    border-top: 1px solid hsl(var(--b3));
    border-left: 1px solid hsl(var(--b3));
}

.spreadsheet-container .row-header {
    position: sticky;
    left: 0;
    background-color: hsl(var(--b2));
    z-index: 3;
    min-width: 50px;
    text-align: center;
}

/* Style for the top-left corner cell */
.spreadsheet-container th.a1-corner {
    z-index: 5;
    /* Highest z-index */
    left: 0;
    top: 0;
}

.spreadsheet-container td {
    background-color: hsl(var(--b1));
    border-left: 1px solid hsl(var(--b3));
}

/* Increased specificity to override DaisyUI .table styles */
html .spreadsheet-container td.selection-range {
    background-color: darkslategrey !important;
}

/* Increased specificity for active cell */
html .spreadsheet-container td.active-cell {
    background-color: darkslategrey !important;
    outline: 2px solid hsl(var(--s));
    outline-offset: -2px;
    box-shadow: none;
    position: relative;
    z-index: 6;
    /* Active cell on top */
}

/* Frozen pane styling */
.spreadsheet-container td.frozen,
.spreadsheet-container th.frozen {
    background-color: hsl(var(--b3));
}

.sheet-tabs-container {
    flex-wrap: wrap;
    padding: 0 4px;
    border-bottom: 1px solid hsl(var(--b3));
    background-color: hsl(var(--b2));
}

.sheet-tabs-container .tab {
    border-radius: 4px 4px 0 0;
    border-bottom-width: 0 !important;
}

.spreadsheet-controls .fa-function {
    transform: translateY(-50%) scale(0.8);
}

/* Resizer handles */
.col-resizer {
    position: absolute;
    top: 0;
    right: -3px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 10;
}

.row-resizer {
    position: absolute;
    left: 0;
    bottom: -3px;
    width: 100%;
    height: 6px;
    cursor: row-resize;
    z-index: 10;
}

.col-resizer:hover,
.row-resizer:hover {
    background-color: hsl(var(--p));
}

.find-replace-panel {
    align-items: center;
}

/* Header sort/filter controls */
.spreadsheet-container thead th .header-controls {
    opacity: 0.2;
    transition: opacity 0.2s ease;
}

.spreadsheet-container thead th:hover .header-controls {
    opacity: 1;
}

.spreadsheet-container thead th .sort-indicator {
    color: hsl(var(--bc));
    min-width: 1em;
    /* prevent layout shift */
}

.spreadsheet-container thead th .sort-indicator:not(.fa-sort) {
    color: hsl(var(--p));
}

.spreadsheet-container thead th .filter-btn {
    opacity: 0.6;
}

.spreadsheet-container thead th .filter-btn:hover {
    opacity: 1;
    color: hsl(var(--p));
}

.spreadsheet-container thead th .filter-btn.active {
    opacity: 1;
    color: hsl(var(--a));
    /* Use accent color for active filter */
}

/* START: Report Outline Sidebar */
.report-outline-sidebar {
    width: 250px;
    min-width: 150px;
    max-width: 400px;
    resize: horizontal;
    overflow: auto; /* Required for the resize handle to show */
}

/* DaisyUI .menu > li > a is the target */
.report-outline-list li > a {
    padding-top: 2px;
    padding-bottom: 2px;
    cursor: pointer;
}

.report-outline-list li > a > span {
    display: block; /* Make sure span takes full width for truncate */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none; /* Prevents text selection during drag */
}

.report-outline-list li.dragging {
    opacity: 0.4;
    background-color: hsl(var(--n));
}

.report-outline-list li.drag-over > a {
    background-color: hsl(var(--p));
    color: hsl(var(--pc));
}

.outline-toggle-icon, .outline-toggle-placeholder {
    width: 20px;
    flex-shrink: 0;
    text-align: center;
    cursor: pointer;
    margin-right: 4px;
}

.outline-toggle-icon .fa-chevron-down {
    transition: transform 0.2s ease-in-out;
    font-size: 0.7em;
}

.report-outline-list li:not(.expanded) .outline-toggle-icon .fa-chevron-down {
    transform: rotate(-90deg);
}