/* Material Design / Scientific Light Theme */
:root {
    --bg-app: #f5f5f5;
    --panel-bg: #ffffff;
    --accent: #2196F3;
    /* Material Blue */
    --accent-hover: #1976D2;
    --text-main: #333333;
    --text-muted: #666666;
    --border: #e0e0e0;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --radius-md: 8px;
    --radius-full: 24px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Avenir', 'Helvetica Neue', 'Arial', sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    /* Prevent body scroll */
    line-height: 1.5;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: var(--panel-bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #000;
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 1.5rem;
}

.upload-section {
    display: flex;
    align-items: center;
    gap: 16px;
}

input[type="file"] {
    display: none;
}

.upload-btn {
    background-color: var(--accent);
    color: #fff;
    border: none;
    padding: 8px 24px;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: background-color 0.2s, box-shadow 0.2s;
    box-shadow: var(--shadow-sm);
}

.upload-btn:hover {
    background-color: var(--accent-hover);
    box-shadow: var(--shadow-md);
}

#fileName {
    font-size: 0.875rem;
    color: var(--text-muted);
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

main {
    flex: 1;
    display: flex;
    overflow: hidden;
    /* Container for sidebar and content */
    background: radial-gradient(circle at center, #1a1d2e 0%, #0b0d17 100%);
}

.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    /* Main content scroll */
    position: relative;
    scroll-behavior: smooth;
}

.viewer-container {
    width: 100%;
    min-height: 600px;
    /* Ensure viewer has height */
    flex-shrink: 0;
    /* Don't shrink */
    position: relative;
    background: #000;
    /* Black background for 3D view */
}

/* Dashboard */
.dashboard {
    /* Remove fixed height, let it grow */
    min-height: 300px;
    background: var(--panel-bg);
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    /* 2 columns for better fit? or 4? 4 is fine if wide enough. */
    gap: 16px;
    padding: 24px;
    flex-shrink: 0;
}

@media (min-width: 1400px) {
    .dashboard {
        grid-template-columns: repeat(4, 1fr);
    }
}

.sidebar {
    width: 360px;
    background: var(--panel-bg);
    border-left: 1px solid var(--border);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
    /* Scrollable */
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.05);
    flex: 0 0 360px;
    /* Fixed width, don't grow/shrink */
    height: 100%;
    /* Fill vertical space */
}

.panel {
    background: #fff;
    border-radius: var(--radius-md);
    padding: 0;
    /* Clean look, no inner padding/border for panel container itself if we want flat */
    /* Or keep card style */
    border: 1px solid var(--border);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.panel h2 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

.control-group {
    margin-bottom: 20px;
}

.control-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-main);
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    height: 4px;
    background: #e0e0e0;
    border-radius: 2px;
    outline: none;
}

.range-inputs {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
}

input[type="number"] {
    width: 100%;
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
}

button#applyFilter {
    width: 100%;
    background-color: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 16px;
    border-radius: 4px;
    /* Material buttons usually have small radius, or full for FAB/Chips. Let's go with 4px for contained button */
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: background-color 0.2s, box-shadow 0.2s;
    box-shadow: var(--shadow-sm);
    margin-top: 8px;
}

button#applyFilter:hover {
    background-color: var(--accent-hover);
    box-shadow: var(--shadow-md);
}

#statsInfo p {
    font-size: 0.875rem;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

#statsInfo p:last-child {
    border-bottom: none;
}

#statsInfo span {
    font-weight: 600;
    color: var(--text-main);
}

/* Tabs */
.tab-bar {
    display: flex;
    background: var(--panel-bg);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    gap: 24px;
}

.tab-btn {
    background: none;
    border: none;
    padding: 16px 0;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    color: var(--accent);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--accent);
}

.tab-content {
    display: none;
    flex: 1;
    overflow: hidden;
    /* Handle internal scroll */
    position: relative;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* Specific overrides for tab content */
#tab-viewer {
    background: #000;
}

#tab-dashboard {
    overflow-y: auto;
    background: var(--bg-app);
}

/* Sidebar Collapsible */
details.panel {
    display: flex;
    flex-direction: column;
    padding: 0;
    /* Reset padding, move to content */
}

details.panel summary {
    padding: 24px;
    cursor: pointer;
    list-style: none;
    /* Hide default triangle */
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
    transition: background-color 0.2s;
}

details.panel summary:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

details.panel summary::-webkit-details-marker {
    display: none;
}

details.panel summary h2 {
    margin: 0;
    font-size: 1rem;
    display: inline-block;
}

details.panel summary::after {
    content: '›';
    font-size: 1.2rem;
    color: var(--text-muted);
    transition: transform 0.2s;
}

details.panel[open] summary::after {
    transform: rotate(90deg);
}

.control-content {
    padding: 0 24px 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    animation: slideDown 0.2s ease-out;
    /* Ensure no inner scroll constraints */
    max-height: none;
    overflow: visible;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Adjust Dashboard Grid for Tab View */
.dashboard {
    border-top: none;
    /* Remove border as it's full page now */
    min-height: auto;
    /* Let it flow */
    overflow-y: visible;
    /* Scroll handled by tab-content */
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* Strict 2 columns */
    gap: 16px;
    padding: 24px;
    width: 100%;
    box-sizing: border-box;
}

.dashboard>div {
    width: 100%;
    height: 300px;
    /* Constrain height */
    background: #fff;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 12px;
    overflow: hidden;
    /* Prevent spillover */
    display: flex;
    flex-direction: column;
}

.dashboard h3 {
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.dashboard>div>div {
    flex: 1;
    width: 100%;
    min-height: 0;
    /* Allow plotly to shrink */
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(2px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e0e0e0;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #bdbdbd;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #9e9e9e;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #fff;
    padding: 24px;
    border-radius: var(--radius-md);
    width: 500px;
    max-width: 90%;
    box-shadow: var(--shadow-md);
}

.modal-content h2 {
    margin-bottom: 16px;
    font-size: 1.25rem;
}

.schema-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group select {
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.9rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.btn-primary {
    background-color: var(--accent);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
}

.btn-secondary {
    background-color: #e0e0e0;
    color: var(--text-main);
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
}

/* Hierarchy Tree */
.hierarchy-tree {
    padding: 20px;
    background: #ffffff;
    color: #333;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9rem;
    height: 100%;
    overflow-y: auto;
    border-radius: 8px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05);
}

.tree-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tree-node {
    margin-left: 10px;
}

.tree-content {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 4px;
    transition: background 0.2s;
}

.tree-content:hover {
    background: #f0f0f0;
}

.tree-toggle {
    width: 16px;
    text-align: center;
    color: #666;
    font-weight: bold;
}

.tree-children {
    display: none;
    margin-left: 10px;
    border-left: 1px solid #ddd;
}

.tree-children.expanded {
    display: block;
}

.placeholder-text {
    color: #888;
    font-style: italic;
    text-align: center;
    padding: 20px;
}

.error-text {
    color: #ff6b6b;
    text-align: center;
    padding: 10px;
}