html, body {
    min-height: 100%;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; /* Modern font stack */
}

body {
    padding-top: 60px; /* Keep existing padding-top */
    margin: 0;
    overflow-y: hidden; /* Prevent body scroll; panes will scroll ON WIDE SCREENS */
    background-color: #f4f7f9; /* Light gray background */
}

/* Adjust userInfo positioning in the top right */
.navbar-text.navbar-right {
    margin-right: 15px;
    padding-left: 10px;
}

.fill {
    height: calc(100vh - 60px); /* CORRECTED: Match the navbar height for full viewport usage */
}


/* === REDESIGNED VIEWER LAYOUT STYLES (FIXED) === */
.viewer-layout-container {
    display: flex;
    flex-direction: column; /* CHANGED: Main layout is now vertical */
    height: 100%;
    width: 100%;
    position: relative; /* Needed for absolute positioning of the toggle button */
}

#viewer-main-area {
    flex-grow: 1;
    display: flex;
    min-height: 0; /* Important for flex-shrink to work in a column layout */
    min-width: 0; /* Important for flex-shrink to work */
}

.viewer-pane-wrapper {
    display: flex; /* Make wrapper a flex container */
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    transition: max-width 0.35s ease, flex-grow 0.35s ease;
    min-width: 45px;
    flex-grow: 1; /* ADDED: Allows visible panes to expand */
}
.viewer-pane-wrapper.pane-is-collapsed {
    max-width: 45px;
    flex-grow: 0 !important;
    background-color: #f8f9fa; /* Set the gray background on the wrapper */
    border-right: 1px solid #dee2e6; /* A border to separate collapsed panes */
}
.viewer-pane-wrapper.pane-is-collapsed .viewer-pane-content,
.viewer-pane-wrapper.pane-is-collapsed .viewer-pane-header h5 > span {
    display: none;
}

/* New styles for the collapsed pane look */
.viewer-pane-wrapper.pane-is-collapsed .viewer-pane {
    background-color: transparent; /* Make the pane transparent to show wrapper background */
    border: none;
    box-shadow: none;
}

.viewer-pane-wrapper.pane-is-collapsed .viewer-pane-header {
    height: 100%;
    flex-direction: column; /* Stack icon and button vertically */
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: none;
}

.viewer-pane-wrapper.pane-is-collapsed .viewer-pane-header h5 {
    margin: 0;
    font-size: 18px; /* Adjust icon size */
}
.pane-toggle-btn {
    background: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 2px 6px;
    line-height: 1.5;
    font-size: 12px;
    color: #555;
    cursor: pointer;
}
.pane-toggle-btn .fa-angle-double-right { display: none; }
.viewer-pane-wrapper.pane-is-collapsed .pane-toggle-btn .fa-angle-double-right { display: inline-block; }
.viewer-pane-wrapper.pane-is-collapsed .pane-toggle-btn .fa-angle-double-left { display: none; }
.gutter.is-hidden { display: none !important; }

.viewer-layout-container.no-split-transition .viewer-pane-wrapper {
    transition: none !important;
}

.viewer-pane {
    background-color: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
    display: flex;
    flex-direction: column;
    height: 100%;
    flex: 1;
}

.viewer-pane-header {
    padding: 8px 15px;
    border-bottom: 1px solid #dee2e6;
    background-color: #f8f9fa;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.viewer-pane-header h5 {
    margin: 0;
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.viewer-pane-content {
    flex-grow: 1;
    position: relative; /* Crucial for APS viewer */
    overflow: hidden; /* Default overflow, overridden for specific panes */
}

#xlsxTreeView,
#xlsxTableView {
    overflow: auto; /* Allow scrolling */
    padding: 10px;
    box-sizing: border-box;
}


.viewer-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #999;
    text-align: center;
}
.viewer-placeholder i {
    font-size: 48px;
    margin-bottom: 15px;
    color: #ccc;
}


/* --- Inspector Panel (REFACTORED WITH ANIMATION) --- */
#inspector-panel {
    flex-shrink: 0;
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.inspector-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    border-top: 1px solid #dee2e6;
    background-color: #f8f9fa;
    flex-shrink: 0;
    cursor: pointer;
    z-index: 10; /* Ensure header is on top */
}

.inspector-header h6 {
    margin: 0;
    font-weight: 600;
    font-size: 14px;
}

.inspector-header h6 i {
    margin-right: 8px;
}

.inspector-body {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    box-sizing: border-box;
    padding: 15px;
    overflow-x: auto;
    overflow-y: hidden;
    flex-grow: 1;
}

.control-group {
    padding-right: 15px;
    min-width: 220px;
    flex: 0 1 320px;
    display: flex;
    flex-direction: column;
}
.control-group:last-child {
    padding-right: 0;
}

/* --- Collapsed State via parent class --- */
.viewer-layout-container.inspector-is-collapsed .inspector-body {
    display: none;
}
.viewer-layout-container.inspector-is-collapsed .gutter.gutter-vertical {
    display: none;
}
.viewer-layout-container.inspector-is-collapsed #inspector-panel {
    height: 45px !important; /* keep header visible */
}
.viewer-layout-container.inspector-is-collapsed #viewer-main-area {
    height: calc(100% - 45px) !important;
}

#inspector-toggle-btn {
    padding: 2px 6px;
    line-height: 1.5;
    font-size: 12px;
}

#inspector-toggle-btn .fa-angle-double-up { display: none; }
.viewer-layout-container.inspector-is-collapsed #inspector-toggle-btn .fa-angle-double-up { display: inline-block; }
.viewer-layout-container.inspector-is-collapsed #inspector-toggle-btn .fa-angle-double-down { display: none; }

.control-group h6 {
    font-weight: bold;
    margin-top: 0;
    margin-bottom: 12px;
    color: #333;
    flex-shrink: 0;
}
.control-group .form-group {
    margin-bottom: 10px;
}
.control-group label {
    font-size: 13px;
    font-weight: normal;
    color: #555;
    margin-bottom: 4px;
}
.control-group .file-info {
    font-size: 13px;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.control-group .file-info i {
    margin-right: 8px;
}
.control-group:not(:last-child) {
    border-right: 1px solid #e9ecef;
}
.inspector-body hr {
    display: none;
}

/* --- Section-specific Styles --- */
#sheet-view-group,
#tree-view-group {
    flex: 1 1 250px; /* Give Data View a compact flexible size, allow growing */
}

.selected-headers-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.header-bubble {
    display: inline-flex;
    align-items: center;
    background-color: #e9ecef;
    border: 1px solid #dee2e6;
    border-radius: 12px;
    padding: 3px 8px;
    font-size: 13px;
    cursor: default;
    transition: background-color 0.2s ease;
}

.header-bubble .remove-bubble {
    margin-left: 8px;
    cursor: pointer;
    font-weight: bold;
    color: #6c757d;
    line-height: 1;
}

.header-bubble .remove-bubble:hover {
    color: #343a40;
}

#sorting-grouping-group .sorting-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
#sorting-grouping-group .sorting-row select {
    flex-grow: 1;
}


#isolate-group {
    flex: 1 1 450px; /* Allow this group to be larger */
}
.isolate-group-content {
    display: flex;
    flex-direction: row;
    align-items: flex-start; /* Anchor content to the top */
    gap: 15px;
    flex-grow: 1;
}
.isolate-forms {
    flex-grow: 1;
    display: flex;
    flex-direction: column; /* CHANGED: Stack form groups vertically */
    gap: 10px;
}
.isolate-forms .form-group {
    margin-bottom: 0;
}
.isolate-actions {
    display: flex;
    flex-shrink: 0;
    gap: 5px;
}
.isolate-actions .btn {
    width: 38px;
    height: 38px;
    font-size: 16px;
    padding: 0;
    line-height: 38px;
    text-align: center;
}

#filter-path-group {
    flex: 1 1 300px;
    min-width: 250px;
}
#filterPathDisplay.current-filter-path {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 8px;
    font-size: 12px;
    font-family: monospace;
    flex-grow: 1;
    overflow: auto;
    word-break: break-all;
    margin-top: 0;
}


/* gutters from Split.js */
.gutter {
    background-color: #f4f7f9;
    background-repeat: no-repeat;
    background-position: 50%;
    z-index: 50; /* Ensure gutter is above viewer content but below toggle button */
}
.gutter.gutter-horizontal {
    cursor: col-resize;
}
.gutter.gutter-vertical {
    cursor: row-resize;
}


/* viewer containers */
#modelViewer {
    width: 100%;
    height: 100%;
    overflow: hidden; /* This is correct for the 3D viewer canvas */
    position: relative;
    background: #ffffff;
}

/* trees (only in key management now) */
#keyManagerHubs {
    width: 100%;
    height: 100%;
    overflow: auto;
}

/* layout for key manager */
#keyManagerContent {
    height: 100%;
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

#keyManagerContent > h2,
#keyManagerContent > .lead {
    flex-shrink: 0;
}

.KeyManagerCard {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.04);
    border: 1px solid #e9ecef;
    transition: box-shadow 0.2s ease-in-out;
    margin-bottom: 0;
}
.KeyManagerCard:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.keyManagerCardsContainer {
    flex-grow: 1;
    min-height: 0;
    display: flex;
    gap: 20px;
}

.createKeyCard {
    flex: 1 1 380px;
    display: flex;
    flex-direction: column;
}

.listKeysCard {
    flex: 2 1 500px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.keysTableWrapper {
    flex-grow: 1;
    overflow-y: auto;
    margin-top: 15px;
}

@media (max-width: 992px) {
    body {
        overflow-y: auto;
    }
    .keyManagerCardsContainer {
        flex-direction: column;
        min-height: initial;
    }
    .KeyManagerCard {
        margin-bottom: 20px;
    }
}

.createKeyCard h3 {
    margin-top: 0;
    margin-bottom: 20px;
}
.createKeyCard .form-group {
    margin-bottom: 15px;
}
.createKeyCard .form-control {
    width: 100%;
    box-sizing: border-box;
}
.file-selection-group {
    margin-bottom: 20px;
}
.file-selection-group > label {
    font-weight: bold;
    margin-bottom: 10px;
    display: block;
}
.file-selectors-layout {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.file-selector-card {
    border: 2px dashed #ccc;
    border-radius: 8px;
    padding: 20px;
    min-height: 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background-color: #f8f9fa;
    transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out;
    flex: 1;
}
.file-selector-card:hover {
    background-color: #e9ecef;
    border-color: #999;
}
.file-selector-card.placeholder .file-name {
    color: #999;
}
.file-selector-card.selected {
    background-color: #eaf6ff;
    border-style: solid;
    border-color: #337ab7;
}
.file-selector-card.selected .glyphicon {
    color: #337ab7;
}
.file-selector-card .glyphicon {
    font-size: 40px;
    color: #555;
    margin-bottom: 10px;
}
.file-selector-card .file-description {
    font-weight: bold;
    color: #333;
    text-align: center;
    margin-bottom: 5px;
}
.file-selector-card .file-name {
    font-size: 14px;
    color: #222;
    text-align: center;
    word-break: break-word;
}
.pairing-key-icon {
    font-size: 48px;
    color: #337ab7;
    padding: 0 10px;
}
#createKeyButton {
    width: 100%;
    margin-top: 25px;
    padding: 12px 15px;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}
#createKeyButton .glyphicon {
    margin-right: 8px;
    font-size: 16px;
}
.sort-arrow {
    cursor: pointer;
}
#keysTableBody tr {
    transition: background-color 0.2s ease;
}
#keysTableBody tr:hover {
    background-color: #f5f5f5;
}

/* --- XLSX Viewer Styles --- */
.xlsx-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
    white-space: nowrap;
}
.xlsx-table th,
.xlsx-table td {
    border: 1px solid #e9ecef;
    padding: 8px;
    text-align: left;
    cursor: pointer;
}
.xlsx-table tbody tr:hover td,
.xlsx-table tbody tr:hover th {
    background-color: #f5f5f5;
}
.xlsx-table thead th {
    position: -webkit-sticky; /* For Safari */
    position: sticky;
    top: -10px; /* Adjust for container padding */
    z-index: 2;
    background-color: #f2f2f2;
    font-weight: bold;
}
.xlsx-table tbody td:first-child {
    background-color: #f8f9fa;
}
.xlsx-table tbody td:nth-child(2) {
    background-color: #f8f9fa;
}
.xlsx-table thead tr th:first-child {
    z-index: 3;
}
.xlsx-primary-row td, .xlsx-primary-row th {
    background-color: #aad4ff !important;
}
.xlsx-secondary-row td, .xlsx-secondary-row th {
    background-color: #d4eaff !important;
}

/* Hides table rows that are not highlighted */
#xlsxTableView.hide-non-highlighted .xlsx-table > tbody > tr {
    display: none;
}

#xlsxTableView.hide-non-highlighted .xlsx-table > tbody > tr.xlsx-primary-row,
#xlsxTableView.hide-non-highlighted .xlsx-table > tbody > tr.xlsx-secondary-row {
    display: table-row;
}


/* Notification Styles */
#notification-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    pointer-events: none;
}

.notification {
    background-color: #333;
    color: #fff;
    padding: 10px 15px;
    border-radius: 4px;
    min-width: 200px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: auto;
}

.notification.show {
    opacity: 1;
    transform: translateY(0);
}

/* Tree view custom grid styles */
.tree-grid-header {
    display: flex;
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    padding: 4px 8px;
    font-weight: bold;
}

.tree-col-header {
    flex: 0 0 100px;
    text-align: right;
    margin-left: 8px;
}

.tree-col-name {
    flex: 1 1 auto;
    text-align: left;
    margin-left: 0;
}

.jstree-anchor {
    display: inline-flex;
    align-items: center;
}

.tree-col-value {
    flex: 0 0 100px;
    text-align: right;
    margin-left: 8px;
}
/* Login Gate states */
body.logged-out nav,
body.logged-out #main-app-container {
    display: none;
}

body.logged-in #login-gate-container {
    display: none;
}