* {
    box-sizing: border-box;
}

html {
    font-size: 10pt;
    font-family: var(--font-family-ui);
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    padding: 0;
    font-size: 11pt;
    background-color: var(--bg-dark);
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100vh;
    min-width: 800px;
    overflow: hidden;
}

/* ==================== HEADER (fixed top) ==================== */
.app-header {
    flex-shrink: 0;
    width: 100%;
    background: var(--bg);
    overflow: visible;
    position: relative;
    z-index: 100;
}

.app-title-bar {
    padding: var(--title-bar-padding);
    background-color: var(--title-bar-bg);
    color: var(--title-bar-color);
    font-weight: var(--title-bar-font-weight);
    font-size: var(--title-bar-font-size);
    user-select: none;
}

.app-menu-bar {
    display: flex;
    flex-wrap: nowrap;
    background-color: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 0;
    user-select: none;
    overflow: visible;
}

.menu-item {
    position: relative;
    overflow: visible;
}

.menu-item > button {
    background: none;
    border: 1px solid transparent;
    padding: 3px 10px;
    font-size: var(--font-size-small);
    cursor: pointer;
}

.menu-item > button:hover,
.menu-item > button.active {
    background-color: var(--bg-toolbar-hover);
    border: 1px solid var(--border-toolbar);
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background-color: var(--bg);
    border: 1px solid var(--border-dark);
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
    min-width: 180px;
    padding: 2px;
    z-index: 1000;
}

.dropdown-menu.visible {
    display: block;
}

.dropdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 12px;
    font-size: var(--font-size-small);
    cursor: pointer;
}

.dropdown-item.has-submenu {
    position: relative;
}

.dropdown-item.has-submenu::after {
    content: '▸';
    margin-left: 8px;
    font-size: 0.9em;
}

.dropdown-submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: 0;
    margin-left: -2px;
    background-color: var(--bg);
    border: 1px solid var(--border-dark);
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
    min-width: 180px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 2px;
    z-index: 1001;
}

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

.dropdown-submenu .dropdown-item {
    color: var(--text);
}

.dropdown-item:hover {
    background-color: var(--title-bg);
    color: white;
}

.dropdown-item.disabled {
    color: var(--color-menu-disabled);
    cursor: default;
}

.dropdown-item .shortcut {
    margin-left: 24px;
    color: var(--color-text-shortcut);
}

.dropdown-item:hover .shortcut {
    color: rgba(255, 255, 255, 0.9);
}

.separator {
    height: 1px;
    background-color: var(--border);
    margin: 4px 2px;
}

.app-toolbar {
    display: flex;
    gap: 2px;
    padding: 2px 4px;
    border-bottom: 1px solid var(--border);
    background-color: var(--bg);
}

.toolbar-btn {
    background: none;
    border: 1px solid transparent;
    padding: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toolbar-btn:hover {
    background-color: var(--bg-toolbar-hover);
    border: 1px solid var(--border-toolbar);
}

.toolbar-btn:active {
    background-color: var(--bg-toolbar-active);
    border: 1px solid var(--border-toolbar-active);
}

.toolbar-btn {
    color: var(--color-text-disabled);
}
.toolbar-btn svg,
.toolbar-btn img {
    width: 20px;
    height: 20px;
}
.toolbar-btn img {
    opacity: 0.65;
}
.toolbar-btn:hover img,
.toolbar-btn:active img,
.toolbar-btn.active img {
    opacity: 1;
    filter: var(--color-icon-filter);
}

.toolbar-btn.active {
    background-color: var(--bg-toolbar-active);
    border: 1px solid var(--border-toolbar-active);
}

.toolbar-sep {
    width: 1px;
    background-color: var(--border);
    margin: 2px 4px;
}


button.tab-btn img ,button.accordion-header img{
    width: 20px;
    height: 20px;
    margin-right: 4px;
    vertical-align: middle;
    filter: var(--color-icon-filter);
}

/* ==================== MAIN CONTAINER ==================== */
.app-container {
    flex: 1 1 0;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

/* Panel dividers (resizable) */
.panel-divider {
    width: 6px;
    flex-shrink: 0;
    background: var(--border);
    cursor: col-resize;
    position: relative;
}

.panel-divider:hover {
    background: var(--title-bg);
}

.panel-divider:active {
    background: var(--title-bg);
}

.panel-divider.hidden {
    width: 0 !important;
    min-width: 0;
    cursor: default;
    pointer-events: none;
}

/* Left panel (252px) - on the left side */
.panel-left {
    width: 252px;
    min-width: 150px;
    flex-shrink: 0;
    background: var(--bg);
    border-right: 1px solid var(--border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    transition: width 0.2s, margin 0.2s, min-width 0.2s;
}

.panel-left.hidden {
    width: 0 !important;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    border-right: none;
}

/* Center panel with Data/Results tabs */
.panel-center {
    flex: 1 1 0;
    background: var(--bg-surface);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.panel-center .tab-container {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
}

.panel-center .tab-list {
    display: flex;
    background-color: var(--bg-dark);
    padding: 0 4px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-center .tab-btn {
    padding: 6px 12px;
    font-size: var(--font-size-small);
    cursor: pointer;
    border: 1px solid transparent;
    border-bottom: none;
    background: none;
    margin-bottom: -1px;
}

.panel-center .tab-btn.active {
    background-color: var(--bg-surface);
    border-color: var(--border);
    border-bottom-color: var(--bg-surface);
    position: relative;
    z-index: 1;
}

.panel-center .tab-content {
    flex: 1 1 0;
    min-height: 0;
    background-color: var(--bg-surface);
    padding: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-center .tab-panel {
    display: none;
}

.panel-center .tab-panel.active {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
}

#tab-data.active .spreadsheet-with-headers {
    flex: 1;
    overflow: hidden;
    padding: 2px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#tab-results.active .results-content,
#tab-results.active .panel-placeholder,
#tab-info.active .panel-placeholder,
#tab-context-help.active .panel-placeholder {
    flex: 1;
    overflow: auto;
    padding: 2px;
    min-height: 0;
}

.dataset-label,
.tab-label-bar {
    padding: 4px 8px;
    background-color: var(--bg-highlight);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    font-size: var(--font-size-small);
    color: var(--text);
}

.project-info-bar {
    padding: 4px 8px;
    background-color: var(--bg-highlight);
    border: 1px solid var(--border);
    font-size: var(--font-size-small);
    color: var(--text);
}

.dataset-label {
    border-bottom: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.dataset-status-icon {
    flex-shrink: 0;
}

.dataset-status-icon.dataset-saved {
    color: var(--color-saved);
}

.dataset-status-icon.dataset-changed {
    color: var(--color-changed);
}

.dataset-label-text {
    flex: 1;
    min-width: 0;
}

.project-info-bar {
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.spreadsheet-with-headers {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.column-headers-bar {
    flex-shrink: 0;
    margin-bottom: 2px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.column-headers-bar::-webkit-scrollbar {
    display: none;
}

.column-headers-table {
    table-layout: fixed;
    border-collapse: collapse;
    border-spacing: 0;
}

.column-headers-table td {
    padding: 0;
    vertical-align: top;
    border: 1px solid var(--border);
}

.column-headers-index {
    position: sticky;
    left: 0;
    z-index: 1;
    background: linear-gradient(to right, var(--bg-inset) calc(100% - 1px), var(--border) calc(100% - 1px));
    min-width: 51px;
}

.column-headers-bar .column-header-input {
    width: 100%;
    min-width: 0;
    padding: 2px 4px;
    font-size: var(--font-size-small);
    border: none;
    margin: 0;
    box-sizing: border-box;
    background-color: var(--bg-inset);
}

.column-headers-bar .column-header-input:focus {
    outline: none;
    border-color: var(--title-bg);
}

.spreadsheet-wrapper {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#tab-data.active .spreadsheet-wrapper #spreadsheet {
    flex: 1;
    overflow: auto !important;
    min-height: 0;
    margin-bottom: 0 !important;
}

.spreadsheet-corner-overlay {
    position: absolute;
    top: 1px;
    left: 1px;
    z-index: 3;
    pointer-events: none;
    background-color: var(--bg-inset);
    width: 50px;
    height: 28px;
    border-top: 1px solid var(--border-default);
    border-left: 1px solid var(--border-default);
    border-right: 1px solid transparent;
    border-bottom: 1px solid transparent;
}

/* Right panel (250px) - on the right side */
.panel-right {
    width: 300px;
    min-width: 150px;
    flex-shrink: 0;
    background: var(--bg);
    border-left: 1px solid var(--border);
    padding: 8px;
    overflow-y: auto;
    transition: width 0.2s, margin 0.2s, min-width 0.2s;
}

.panel-right.hidden {
    width: 0 !important;
    min-width: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border-left: none;
}

/* Right panel content */
.panel-right .right-panel-logo {
    height: 40px;
    width: auto;
    float: left;
    margin-right: 8px;
}

.panel-right h2 {
    font-size: 16px;
    margin-top: 0;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

/* Accordion */
.accordion-container {
    border: 1px solid var(--border);
}

.accordion-item {
    border-bottom: 1px solid var(--border);
}

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

.accordion-header {
    width: 100%;
    background-color: var(--bg);
    border: none;
    padding: 8px 10px;
    text-align: left;
    font-size: var(--font-size-small);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.accordion-header:hover {
    background-color: var(--bg-dark);
}

.accordion-header .accordion-indicator::before {
    content: '+';
    font-size: 1.1em;
    font-weight: bold;
    margin-right: 5px;
}

.accordion-header.active .accordion-indicator::before {
    content: '−';
}

.accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s ease-out;
    background-color: var(--bg-surface);
}

.accordion-content-inner {
    padding: 12px 15px;
    font-size: var(--font-size-small);
    line-height: 1.5;
}

.function-usage-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.function-usage-label {
    font-weight: 600;
    color: var(--color-text);
}

.function-usage-select {
    width: 100%;
    max-width: 100%;
}

.function-usage-generate-btn {
    width: 100%;
    max-width: 100%;
}

.function-usage-controls {
    margin-top: var(--space-xs);
}

/* Left panel tabs */
.panel-left .tab-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.panel-left .tab-list {
    display: flex;
    background-color: var(--bg-dark);
    padding: 0 4px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-left .tab-btn {
    padding: 6px 12px;
    font-size: var(--font-size-small);
    cursor: pointer;
    border: 1px solid transparent;
    border-bottom: none;
    background: none;
    margin-bottom: -1px;
}

.panel-left .tab-btn.active {
    background-color: var(--bg);
    border-color: var(--border);
    border-bottom-color: var(--bg);
    position: relative;
    z-index: 1;
}

.panel-left .tab-content {
    flex-grow: 1;
    min-height: 0;
    background-color: var(--bg);
    padding: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-left .tab-panel {
    display: none;
}

.panel-left .tab-panel.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Tree view (Tab1) */
.tree-view {
    font-size: var(--font-size-small);
    color: var(--text);
    background-color: var(--bg-surface);
    padding: 4px 0;
    margin: 0;
    border: 1px solid var(--border);
    list-style: none;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.tree-view ul {
    list-style: none;
    padding-left: 16px;
    margin: 0;
    border-left: 1px solid var(--border-light);
    margin-left: 8px;
}

.tree-view li {
    padding: 1px 0;
    position: relative;
}

.tree-view .tree-row {
    display: flex;
    align-items: center;
    padding: 2px 4px;
    border-radius: 2px;
    cursor: default;
    position: relative;
}

.tree-view .tree-row:hover {
    background-color: var(--bg-tree-hover);
}

.tree-view .tree-spacer {
    width: 16px;
    height: 16px;
    margin: 0 6px 0 0;
    flex-shrink: 0;
    background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236c757d' stroke-width='2'%3e%3cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'%3e%3c/path%3e%3cpolyline points='14 2 14 8 20 8'%3e%3c/polyline%3e%3c/svg%3e") no-repeat center;
    background-size: 14px;
}

.tree-view .tree-label {
    flex: 1;
    cursor: pointer;
    user-select: none;
}

.tree-view li.tree-folder > .tree-row .tree-label {
    cursor: pointer;
}

/* Functions tab — category groups (ANOVA, Regression, DOE, …) */
#function-tree li.tree-folder > .tree-row .tree-label {
    font-weight: 700;
    color: var(--color-primary);
}

#function-tree li.tree-folder > .tree-row .tree-label:hover {
    color: var(--color-primary-hover);
}

.tree-view li.tree-item > .tree-row .tree-label {
    cursor: pointer;
}

.tree-view li.tree-item > .tree-row .tree-label:hover {
    text-decoration: underline;
}

.tree-view li.tree-folder > ul {
    display: block;
}

.tree-view li.tree-folder.collapsed > ul {
    display: none;
}

.tree-view li.tree-folder > .tree-row .tree-check-wrap {
    width: 16px;
    height: 16px;
    margin: 0 6px 0 0;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    color: var(--color-text-muted);
}

.tree-view li.tree-folder > .tree-row .tree-check-wrap::before {
    content: '▸';
}

.tree-view li.tree-folder.expanded > .tree-row .tree-check-wrap::before {
    content: '▾';
}

.tree-view li.tree-folder > .tree-row .tree-icon {
    width: 16px;
    height: 16px;
    margin-right: 4px;
    flex-shrink: 0;
    background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%230078d7' stroke-width='2'%3e%3cpath d='M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z'%3e%3c/path%3e%3c/svg%3e") no-repeat center;
    background-size: 14px;
}

.tree-view li.tree-folder.expanded > .tree-row .tree-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%230078d7' stroke-width='2'%3e%3cpath d='m6 14 1.45-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2v1'%3e%3c/path%3e%3c/svg%3e");
}

.tree-view li.tree-folder > .tree-row input.tree-check {
    position: absolute;
    opacity: 0;
    width: 16px;
    height: 16px;
    margin: 0;
    cursor: pointer;
    z-index: 1;
}

.panel-placeholder {
    padding: 20px;
    text-align: center;
    color: var(--color-text-placeholder);
    font-size: var(--font-size-small);
}

/* jspreadsheet */
#spreadsheet {
    margin-bottom: 20px;
}

#spreadsheet .jss {
    width: auto !important;
}

/* Freeze first column (row index) - CSS sticky when horizontal scroll */
#spreadsheet table td:first-child,
#spreadsheet table th:first-child {
    position: sticky !important;
    left: 0 !important;
    z-index: 2 !important;
    background-color: var(--bg-inset);
    box-shadow: 1px 0 0 0 var(--border);
}

/* Row header selected state - match jspreadsheet column header selection */
#spreadsheet table tbody tr.selected td:first-child {
    background-color: var(--bg-row-selected) !important;
}

/* Project tree - file icon and DataInfo button */
.project-tree .tree-file-icon {
    width: 16px;
    height: 16px;
    margin: 0 6px 0 0;
    flex-shrink: 0;
}

.project-tree .tree-row-with-actions {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 4px;
}

.project-tree .tree-label {
    flex: 1;
    min-width: 0;
}

/* Project tree — folder categories (JSON_input, XML_output, …) */
.project-tree li.tree-folder > .tree-row .tree-label {
    font-weight: 700;
    color: var(--color-primary);
}

.project-tree li.tree-folder > .tree-row .tree-label:hover {
    color: var(--color-primary-hover);
}

.project-tree .tree-datainfo-btn,
.project-tree .tree-file-menu-btn {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    color: var(--color-text-muted);
    border-radius: 2px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.project-tree .tree-datainfo-btn:hover,
.project-tree .tree-file-menu-btn:hover {
    background-color: var(--title-bg);
    color: white;
}

.project-tree .tree-file-menu-btn img {
    display: block;
    width: 14px;
    height: 14px;
    opacity: 0.75;
}

.project-tree .tree-file-menu-btn:hover img {
    opacity: 1;
    filter: brightness(0) invert(1);
}

.project-tree-tooltip {
    position: fixed;
    z-index: 10050;
    max-width: 280px;
    padding: 8px 10px;
    background: #1e293b;
    color: #f8fafc;
    border-radius: 6px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
    font-size: 12px;
    line-height: 1.45;
    pointer-events: none;
}

.project-tree-tooltip b {
    display: block;
    font-weight: 600;
    font-size: 12px;
    margin-bottom: 4px;
}

.project-tree-tooltip p {
    margin: 0;
    font-weight: 400;
    opacity: 0.92;
}

.project-tree-context-menu {
    position: fixed;
    z-index: 10050;
    min-width: 160px;
    padding: 4px 0;
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border-light, #ddd);
    border-radius: 4px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}

.project-tree-context-menu-item {
    display: block;
    width: 100%;
    padding: 7px 14px;
    border: none;
    background: transparent;
    text-align: left;
    font-size: 13px;
    cursor: pointer;
    color: var(--color-text-body, #333);
}

.project-tree-context-menu-item:hover {
    background: var(--bg-app, #f0f0f0);
}

.project-tree-context-menu-item.is-danger {
    color: #c0392b;
}

.project-tree .tree-action {
    cursor: pointer;
    color: var(--title-bg);
}

.project-tree .tree-action:hover {
    text-decoration: underline;
}

.project-tree .tree-no-project-list {
    list-style: none;
    padding-left: 20px;
    margin: 0 0 0 8px;
    border-left: 1px solid var(--border-light);
}

.project-tree li.tree-item.selected .tree-row {
    background-color: var(--bg-highlight);
}

/* ==================== FOOTER (statusbar) ==================== */
.app-footer {
    flex-shrink: 0;
    width: 100%;
}

.statusbar {
    display: flex;
    background-color: var(--bg);
    border-top: 1px solid var(--border);
    padding: 3px 4px;
    font-size: var(--font-size-small);
    gap: 4px;
}

.status-panel {
    padding: 2px 8px;
    border: 1px solid var(--border-dark);
    border-right-color: var(--inset-light);
    border-bottom-color: var(--inset-light);
    min-width: 80px;
}

#status-project,
#status-dataset {
    min-width: 120px;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background-color: var(--bg-highlight);
}

#status-project strong,
#status-dataset strong {
    font-weight: 700;
}

.center-toolbar {
    flex-shrink: 0;
}

.tab-toolbar {
    display: flex;
    gap: 2px;
    padding: 2px 4px;
    border-bottom: 1px solid var(--border);
    background-color: var(--bg);
    flex-shrink: 0;
}

#tab-results-toolbar.tab-toolbar-with-badge {
    position: relative;
    padding-right: 148px;
}

.results-verified-badge {
    position: absolute;
    top: 3px;
    right: 6px;
    padding: 1px;
    background: #1a52c4;
    border-radius: 6px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 2;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.results-verified-badge-inner {
    display: block;
    padding: 2px 9px;
    font-size: 10px;
    font-weight: 600;
    font-family: var(--font-family-ui, Arial, sans-serif);
    color: #fff;
    background: #1a52c4;
    border: 2px solid #fff;
    border-radius: 4px;
    line-height: 1.35;
}

.results-verified-badge[hidden] {
    display: none;
}

.tab-label-bar {
    flex-shrink: 0;
}

.status-stretch {
    flex-grow: 1;
}

