body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100vh;
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: row;
    overflow: hidden;
}

#mainControlsPanel {
    width: 350px; /* Initial/default width, JS will manage and persist this */
    min-width: 320px; /* Fallback CSS minimum, JS will enforce its own minimum */
    height: 100%;
    padding: 10px;
    background-color: #f0f0f0;
    border-right: 1px solid #ccc;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    box-sizing: border-box;
    flex-shrink: 0; /* Prevent shrinking beyond its basis when body shrinks */
}

#panelResizer {
    width: 6px;
    background-color: #bdbdbd;
    cursor: col-resize;
    height: 100%;
    flex-shrink: 0;
    border-left: 1px solid #ccc;
    border-right: 1px solid #ccc;
    box-sizing: border-box;
}

#panelResizer:hover {
    background-color: #aaa;
}


#appTitle {
    color: #007bff;
    text-align: center;
    margin-top: 5px;
    margin-bottom: 10px;
    font-size: 1.8em;
    font-weight: bold;
}


#plotSectionWrapper {
    flex-grow: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0; /* Important for flex items that might shrink */
}

#plotSectionTopRow {
    flex-grow: 1;
    display: flex;
    flex-direction: column; /* Changed to column for main plot and diff plot */
    overflow: hidden;
    min-height: 0;
}

#plotCanvas {
    flex-grow: 1; /* Main plot canvas will take available space */
    height: auto; /* Allow it to grow, or set a min-height if preferred */
    min-height: 100px; /* Example minimum height for the main plot */
    display: block;
    background-color: #fff;
    width: 100%; /* Ensure it takes full width */
    cursor: grab;
}


#diffPlotContainer {
    width: 100%;
    height: 200px; /* Fixed height for the difference plot (includes separator and canvas) */
    min-height: 100px; /* Minimum height if resizable in future */
    /* border-top: 1px solid #ccc; REMOVED - Separator handles this */
    background-color: #fdfdfd; /* Background for the whole diff plot area */
    display: none; /* Hidden by default, JS changes to 'flex' when visible */
    flex-direction: column; /* For separator and canvas */
    flex-shrink: 0; /* Prevent shrinking */
    box-sizing: border-box;
}

#diffPlotSeparator {
    height: 24px; /* Total height of the bar */
    background-color: #e0e0e0; /* A noticeable gray */
    display: flex;
    align-items: center;
    justify-content: center; /* Center the label */
    flex-shrink: 0;
    border-top: 1px solid #c0c0c0; /* Top border for definition */
    border-bottom: 1px solid #c0c0c0; /* Bottom border for definition */
    box-sizing: border-box;
    width: 100%;
}

#diffPlotSeparator span {
    font-size: 0.9em;
    color: #333;
    font-weight: normal;
}

#diffPlotCanvas {
    width: 100%;
    flex-grow: 1; /* Takes remaining space in diffPlotContainer */
    min-height: 0; /* Important for flex children */
    display: block;
    background-color: #fff; /* Match main canvas or make distinct */
}


:root {
    --axis-control-pane-size: 45px; /* Adjusted as there are fewer elements */
    --axis-button-padding: 5px;
    --default-icon-size: 1.2em;
    --home-icon-size: 1.5em;
}

#xAxisControlsPanel {
    flex-grow: 1;
    height: var(--axis-control-pane-size);
    min-height: var(--axis-control-pane-size);
    padding: 3px 8px; 
    border-top: 1px solid #ccc;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px; 
    overflow: hidden;
    box-sizing: border-box;
    min-width: 0;
    background-color: #e9e9e9;
}

.x-axis-main-controls {
    display: flex;
    align-items: center;
    gap: 10px; 
}

#homeButton {
    font-size: var(--home-icon-size);
    width: calc(var(--axis-control-pane-size) - 2 * 3px - 2 * 1px);
    height: calc(var(--axis-control-pane-size) - 2 * 3px - 2 * 1px);
    padding: var(--axis-button-padding);
    box-sizing: border-box;
    line-height: 1;
    margin: 0;
}

#homeButton i {
    color: #006400;
    font-size: inherit;
}
#homeButton:hover i {
    color: #004d00;
}

.control-group-inline {
    display: flex;
    align-items: center;
    gap: 4px;
}
.control-group-inline label {
    font-size: 0.85em;
    color: #333;
    margin-right: 2px;
}
.control-group-inline input[type="number"] {
    width: 45px; /* Adjust width as needed */
    padding: 3px 5px;
    font-size: 0.85em;
    text-align: center;
    border: 1px solid #ccc;
    border-radius: 3px;
    height: calc(var(--axis-control-pane-size) - 16px); /* Approximate height match */
    box-sizing: border-box;
}
/* Hide number input spinners */
.control-group-inline input[type=number]::-webkit-inner-spin-button,
.control-group-inline input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.control-group-inline input[type=number] {
    -moz-appearance: textfield;
}

.control-group-inline .ratio-btn {
    padding: 0;
    width: 24px; /* Square buttons */
    height: calc(var(--axis-control-pane-size) - 16px); /* Match input height approx */
    font-size: 0.9em; /* Adjust for button content */
    line-height: 1; /* Center text/icon */
}


.status-and-actions-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto; /* Push this group to the right */
}

.canvas-action-buttons {
    display: flex;
    gap: 3px; 
}

#xAxisControlsPanel .action-btn {
    padding: 6px 8px; 
    height: auto; 
}
#xAxisControlsPanel .action-btn i {
     font-size: var(--default-icon-size); 
}


#canvasActionFeedback {
    padding: 4px 8px;
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
    border-radius: 4px;
    font-size: 0.85em;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
    white-space: nowrap;
}

#canvasActionFeedback.show {
    opacity: 1;
    visibility: visible;
}

#canvasActionFeedback.error {
    background-color: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}


#plotSectionBottomRow {
    height: var(--axis-control-pane-size);
    min-height: var(--axis-control-pane-size);
    display: flex;
    flex-direction: row;
    background-color: #e9e9e9; 
}


.control-group {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background-color: #fff;
    width: 100%;
    box-sizing: border-box;
}

.control-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    cursor: pointer; 
}

.control-group-header h4 {
    margin: 0;
    font-size: 0.95em;
    color: #333;
}

.control-group-header .header-icons {
    display: flex;
    align-items: center;
    gap: 8px; 
}

.tooltip-icon {
    font-size: 0.9em;
    color: #666;
    cursor: help;
}

.group-toggle-icon {
    font-size: 0.9em;
    color: #666;
    cursor: pointer;
    padding: 2px 4px; 
}
.group-toggle-icon:hover {
    color: #333;
}

.control-group-content {
    transition: max-height 0.2s ease-out, opacity 0.2s ease-out;
    overflow: hidden;
    max-height: 2000px; 
    opacity: 1;
}

.control-group.collapsed .control-group-content {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0; 
    padding-top: 0; 
    padding-bottom: 0;
    border-top: none; 
}


#functionsGroup .add-buttons-container {
    display: flex;
    gap: 5px;
    margin-top: 5px;
}

#functionsGroup .add-buttons-container button {
    flex-grow: 1;
}


.data-entry {
    display: flex;
    flex-direction: column;
    margin-bottom: 10px;
    gap: 5px; 
}

.data-entry-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px; 
    cursor: default; 
}

.data-entry-name-input {
    flex-grow: 1; 
    padding: 5px 7px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 0.85em;
    line-height: 1.2;
    min-width: 50px; 
}

.data-entry-action-buttons {
    display: flex;
    align-items: center;
    gap: 4px; 
    flex-shrink: 0; 
}

.data-input-area {
    width: 100%;
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 0.9em;
    font-family: inherit;
    resize: none;
    line-height: 1.4;
    box-sizing: border-box;
}

.function-entry .data-input-area {
    min-height: 20px;
    overflow-y: hidden;
    transition: height 0.1s ease-out;
}

.csv-entry .data-input-area {
    min-height: calc(1.4em * 1 + 10px);
    max-height: calc(1.4em * 3 + 10px);
    overflow-y: auto;
}

.data-input-area.invalid-function,
.data-input-area.invalid-csv {
    background-color: #ffe0e0;
    border-color: #ff9090;
}

.data-entry-action-buttons .action-btn,
.data-entry-action-buttons input[type="color"] {
    padding: 4px 6px;
    font-size: 0.85em;
    min-width: 28px;
    height: 28px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
}
.data-entry-action-buttons .action-btn i {
    font-size: 0.9em;
}
.data-entry-action-buttons input[type="color"] {
    width: 28px;
    height: 28px;
    padding: 1px;
    border: 1px solid #ccc;
    border-radius: 3px;
    cursor: pointer;
}

/* --- More Actions Submenu Styles --- */
.more-actions-container {
    position: relative; /* For submenu positioning */
    display: flex;
    align-items: center;
}

.more-actions-btn i {
    font-size: 0.9em; /* Ensure icon size matches other action buttons */
}

.actions-submenu {
    display: none; /* Hidden by default */
    position: absolute;
    top: 100%; /* Position below the button */
    right: 0;
    background-color: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
    z-index: 10;
    min-width: 120px; /* Adjust as needed */
    padding: 4px 0;
}

.actions-submenu.submenu-visible {
    display: block;
}

.actions-submenu .action-btn,
.actions-submenu .remove-btn {
    display: block;
    width: 100%;
    text-align: left;
    padding: 6px 10px; /* Consistent padding */
    font-size: 0.85em;
    border: none;
    border-radius: 0;
    background-color: transparent;
    color: #333;
}
.actions-submenu .action-btn i {
    margin-right: 6px;
    font-size: 0.9em;
}

.actions-submenu .action-btn:hover,
.actions-submenu .remove-btn:hover {
    background-color: #f0f0f0;
}
.actions-submenu .remove-btn {
    color: #721c24; /* Original remove button text color */
}
.actions-submenu .remove-btn:hover {
    background-color: #f8d7da; /* Original remove button hover bg */
}
/* --- End Submenu Styles --- */


#parameterScaleGroup {
    margin-bottom: 8px;
}

#parameterScaleButtons {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    justify-content: flex-start;
    overflow-y: hidden;
    max-height: 50px;
}

.scale-btn {
    padding: 2px 5px;
    font-size: 0.75em;
    min-width: auto;
    flex-shrink: 0;
}

.scale-btn.active-scale {
    background-color: #007bff;
    color: white;
    border-color: #0056b3;
}

#parametersContainer .parameter-entry {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    gap: 4px;
}

#parametersContainer .parameter-entry label {
    min-width: 25px;
    font-weight: bold;
    font-size: 0.9em;
}

#parametersContainer .parameter-entry input[type="number"] {
    width: 70px;
    text-align: center;
}

#cursorInfoContent {
    font-size: 0.9em;
    padding: 5px 0;
}

#cursorXValue {
    margin-bottom: 5px;
    font-weight: bold;
    color: #333;
}

#cursorYValuesContainer .cursor-y-value-entry {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em; 
    margin-bottom: 4px;
    padding-left: 2px;
}

#cursorYValuesContainer .cursor-y-color-indicator {
    width: 10px;
    height: 10px;
    border: 1px solid #ccc;
    display: inline-block;
    flex-shrink: 0;
    border-radius: 2px;
}

#cursorYValuesContainer .cursor-y-name {
    color: #444;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px; 
    margin-right: 2px; /* Space before the '=' sign if it's in the value */
}

#cursorYValuesContainer .cursor-y-value {
    color: #222;
    font-weight: 500;
}


.action-btn {
    font-weight: normal;
    background-color: #e0e0e0;
    color: #333;
    border: 1px solid #bbb;
    border-radius: 3px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

#mainControlsPanel .action-btn,
#functionsGroup .add-buttons-container button {
    padding: 5px 7px; 
    font-size: 0.9em;
    line-height: 1;
    width: auto;
    height: auto;
}


#functionsGroup .add-buttons-container button {
    font-size: 0.85em;
}


.action-btn:hover {
    background-color: #d0d0d0;
}

.action-btn:active {
    background-color: #c0c0c0;
}

.action-btn:disabled {
    background-color: #f0f0f0;
    color: #aaa;
    cursor: not-allowed;
    border-color: #ddd;
}
.action-btn:disabled i {
    color: #bbb;
}


.function-toggle-btn.hidden-function {
    opacity: 0.6;
    background-color: #f0f0f0;
}

button#addFunctionBtn, button#addCsvBtn {
    padding: 6px 10px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85em;
}

button#addFunctionBtn:hover, button#addCsvBtn:hover {
    background-color: #0056b3;
}

.remove-btn { /* Style for remove button when it's directly visible, if ever */
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}
.remove-btn:hover {
    background-color: #f1b0b7;
}


#plotCanvas.crosshair-active {
    cursor: crosshair;
}

#plotCanvas.grabbing {
    cursor: grabbing; /* Overrides crosshair/grab when panning */
}

#errorMessages {
    display: none;
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
}

.modal-hidden {
    display: none;
}

.modal-visible {
    display: flex;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 600px;
    border-radius: 8px;
    position: relative;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h3 {
    margin-top: 0;
    color: #007bff;
}

.modal-content h4 {
    margin-top: 15px;
    margin-bottom: 5px;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

.modal-content ul {
    list-style-type: disc;
    padding-left: 25px;
    margin-bottom: 10px;
}

.modal-content li {
    margin-bottom: 4px;
}

.modal-content code {
    background-color: #e8e8e8;
    padding: 1px 4px;
    border-radius: 3px;
    font-family: monospace;
}

.modal-content p {
    margin-bottom: 10px;
    line-height: 1.5;
}

.modal-close-btn {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    top: 5px;
    right: 15px;
}

.modal-close-btn:hover, .modal-close-btn:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

/* Curve Fit Group Styles */
#curveFitGroup .control-group-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.curve-fit-control {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.curve-fit-control label {
    font-size: 0.85em;
    color: #333;
    margin-bottom: 2px;
}

/* General checkbox label style */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px; /* Space between checkbox and its text */
    font-size: 0.9em;
    cursor: pointer;
    user-select: none; /* Prevent text selection when clicking label */
}

.checkbox-label input[type="checkbox"] {
    margin: 0; /* Remove default browser margins for the checkbox */
    vertical-align: middle; /* Good for baseline alignment if not strictly flex */
}

/* Specific margin for checkbox labels that are direct children of .curve-fit-control */
.curve-fit-control > label.checkbox-label {
    margin-top: 4px; /* Space above checkbox in this specific context */
}


.curve-fit-select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 0.9em;
    box-sizing: border-box;
    background-color: white;
}

.curve-fit-metrics {
    font-size: 0.8em;
    color: #555;
    margin-top: 8px; /* Spacing from element above */
    margin-bottom: 5px; /* Spacing to element below (actions) */
    padding: 4px;
    background-color: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 3px;
    text-align: center;
    min-height: 1.5em; /* To prevent layout jumps with dynamic text */
    line-height: 1.4;
    word-wrap: break-word;
}

.curve-fit-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 5px;
}

#curveFitStartStopBtn {
    padding: 6px 12px;
    font-size: 0.85em;
    background-color: #28a745; /* Green */
    color: white;
    border: none;
}
#curveFitStartStopBtn:hover {
    background-color: #218838;
}
/* Style for when it's a "Stop" button */
#curveFitStartStopBtn.fitting-active {
    background-color: #dc3545; /* Red */
}
#curveFitStartStopBtn.fitting-active:hover {
    background-color: #c82333;
}


#curveFitStatusLabel {
    font-size: 0.85em;
    color: #555;
    flex-grow: 1;
    text-align: left;
}