:root {
    --bg-color: #f8fafc;
    --text-main: #334155;
    --border-color: #e2e8f0;
    --primary: #2563eb;
    --success: #16a34a;
    --danger: #ef4444;
    --sidebar-width: 340px;
}

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden;
}

/* Optimus Layout Menu Bar */
.optimus-menu-bar {
    background-color: #f0f0f0;
    border-bottom: 1px solid #ccc;
    padding: 2px 10px;
    display: flex;
    font-size: 13px;
    color: #333;
}
.optimus-menu-item {
    padding: 4px 10px;
    cursor: pointer;
}
.optimus-menu-item:hover {
    background-color: #e5e5e5;
    border-radius: 2px;
}
.optimus-menu-item {
    position: relative;
}
.dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background-color: #fff;
    min-width: 150px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1000;
    border: 1px solid #ccc;
    border-radius: 2px;
}
.optimus-menu-item:hover .dropdown {
    display: block;
}
.dropdown-item {
    padding: 8px 12px;
    cursor: pointer;
    color: #333;
}
.dropdown-item:hover {
    background-color: #f1f5f9;
}
.dropdown-separator {
    height: 1px;
    background-color: #e2e8f0;
    margin: 4px 0;
}

/* Optimus Layout Toolbar */
.optimus-toolbar {
    background-color: #f8f8f8;
    border-bottom: 1px solid #ccc;
    padding: 4px 10px;
    display: flex;
    align-items: center;
    gap: 15px;
}
.toolbar-group {
    display: flex;
    align-items: center;
    gap: 5px;
}
.toolbar-btn {
    background: none;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 16px;
    color: #444;
    padding: 4px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.toolbar-btn:hover {
    background: #e1e1e1;
    border: 1px solid #ccc;
}
.toolbar-text-btn {
    font-size: 12px;
    color: #333;
    background: none;
    border: 1px solid transparent;
    padding: 4px 8px;
    cursor: pointer;
}
.toolbar-text-btn:hover {
    background: #e1e1e1;
    border: 1px solid #ccc;
}
.toolbar-separator {
    width: 1px;
    height: 20px;
    background-color: #ccc;
    margin: 0 5px;
}

/* Layout */
.container {
    display: flex;
    height: calc(100vh - 65px); /* Adjusted for menu+toolbar */
    overflow: hidden;
}

/* Right Tabbed Panel */
.right-tabbed-panel {
    width: var(--sidebar-width);
    background-color: #f5f5f5;
    border-left: 2px solid #ccc;
    display: flex;
    flex-direction: column;
}
.right-panel-content {
    flex: 1;
    overflow-y: auto;
    background: #fff;
}
.right-panel-tabs {
    display: flex;
    background: #e0e0e0;
    border-top: 1px solid #ccc;
}
.panel-tab {
    padding: 5px 10px;
    font-size: 12px;
    cursor: pointer;
    border-right: 1px solid #ccc;
    border-top: 2px solid transparent;
    background: #f0f0f0;
    color: #555;
    white-space: nowrap;
}
.panel-tab.active {
    background: #fff;
    border-top: 2px solid var(--primary);
    font-weight: 600;
    color: #000;
}
.tab-content {
    display: none;
    height: 100%;
}
.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* Data Manager Tree View */
.tree-view {
    padding: 10px;
    font-size: 13px;
    flex: 1;
    overflow-y: auto;
    border-bottom: 1px solid #ccc;
}
.tree-node {
    margin-left: 15px;
    padding: 2px 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
}
.tree-node i { color: #666; font-size: 12px; }
.tree-node:hover { background-color: #f0f4f8; }
.tree-node.selected { background-color: #e2e8f0; font-weight: 600; }

.brief-info {
    height: 150px;
    background: #ffffe0; /* Pale yellow like Optimus */
    border-top: 1px solid #ccc;
    padding: 10px;
    font-size: 12px;
    overflow-y: auto;
}
.brief-info-header {
    border-bottom: 1px solid #ccc;
    margin-bottom: 5px;
    font-weight: 600;
}
.brief-info-row {
    display: flex;
    margin-bottom: 2px;
}
.brief-info-row span:first-child {
    width: 130px;
    color: #444;
}

/* Removing old sidebar */
.sidebar { display: none !important; }
    transition: width 0.3s ease, padding 0.3s ease;
    flex-shrink: 0;
}
.sidebar.collapsed {
    width: 0;
    padding: 15px 0;
    border-right: none;
    overflow: hidden;
}

/* Upload zone */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 20px 10px;
    text-align: center;
    background-color: #f1f5f9;
    cursor: pointer;
    transition: 0.2s ease;
}
.upload-zone.dragover {
    border-color: var(--primary);
    background-color: #e0f2fe;
}
.upload-icon {
    font-size: 30px;
    margin-bottom: 10px;
    color: var(--primary);
}

/* Panel Sections */
.panel-section {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    background: #f8fafc;
}
.panel-section h3 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: #0f172a;
}
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.section-header h3 { margin: 0; }

.depth-controls {
    display: flex;
    gap: 10px;
}

.form-group {
    margin-bottom: 10px;
}
.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 12px;
}
.form-control {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 13px;
}

/* Tracks */
.d3-data-track {
    flex: 1;
    min-width: 150px;
    position: relative;
    background: #fff;
    border-right: 4px double #475569;
}
#tracksContainer {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.track-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}
.track-header {
    background: #e2e8f0;
    padding: 8px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
}
.track-actions {
    display: flex;
    gap: 5px;
}
.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #64748b;
    padding: 2px 5px;
    transition: 0.2s;
}
.icon-btn:hover { color: var(--primary); }
.btn-delete-track:hover { color: var(--danger); }

.track-curves {
    padding: 5px;
}
.curve-chip {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f1f5f9;
    padding: 4px 8px;
    border-radius: 4px;
    margin-bottom: 4px;
    font-size: 12px;
    border-left: 4px solid var(--primary);
    cursor: context-menu;
    transition: background 0.2s;
}
.curve-chip:hover {
    background: #e2e8f0;
}
.curve-chip-name {
    font-weight: 600;
    flex: 1;
}
.curve-chip-scale {
    font-size: 10px;
    color: #64748b;
    margin-right: 8px;
}

/* Main Content */
.main-content {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
    background-color: #fff;
    display: flex;
    flex-direction: column;
}
.loading {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.8);
    color: #fff;
    padding: 20px 40px;
    border-radius: 8px;
    font-weight: bold;
    z-index: 100;
    text-align: center;
}

/* PDF Area */
#exportArea {
    background: #fff;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.pdf-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 2px solid #000;
    background: #fff;
}
.pdf-logo {
    max-width: 200px;
    max-height: 80px;
}
.pdf-logo img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
.pdf-info {
    text-align: right;
}
.pdf-info h2 {
    margin: 0 0 10px 0;
}
.pdf-info p {
    margin: 0 0 5px 0;
    font-size: 14px;
}

/* Buttons */
.btn {
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: 0.2s;
    font-size: 13px;
}
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-primary { background-color: var(--primary); color: #fff; }
.btn-primary:hover { background-color: #1d4ed8; }
.btn-success { background-color: var(--success); color: #fff; }
.btn-success:hover { background-color: #15803d; }
.btn-outline { background-color: transparent; border: 1px solid var(--border-color); color: var(--text-main); }
.btn-outline:hover { background-color: #e2e8f0; }

/* Modal */
.modal {
    display: none; 
    position: fixed; 
    z-index: 1000; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    background-color: rgba(0,0,0,0.5); 
}
.modal-content {
    background-color: #fefefe;
    margin: 8% auto; 
    padding: 20px;
    border: 1px solid #888;
    width: 400px;
    border-radius: 8px;
}
.close {
    color: #aaa;
    float: right;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}
.close:hover { color: black; }

/* Drag and Drop states */
.track-card {
    transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s;
}
.track-card.drag-enter {
    border: 2px dashed var(--primary);
    background-color: #f1f5f9;
    box-shadow: 0 0 10px rgba(37, 99, 235, 0.2);
    transform: scale(1.02);
}

.global-curve-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-color);
    background: #f8fafc;
    margin-bottom: 2px;
    border-radius: 4px;
    cursor: grab;
    transition: background 0.2s;
}
.global-curve-item:hover {
    background: #e2e8f0;
}
.global-curve-item:active {
    cursor: grabbing;
}
.global-curve-item .curve-name {
    font-weight: 600;
    font-size: 13px;
    flex: 1;
    margin-left: 8px;
}
.global-curve-item .drag-handle {
    color: #94a3b8;
    cursor: grab;
    margin-right: 8px;
}

.curve-chip {
    cursor: grab;
}
.curve-chip:active {
    cursor: grabbing;
}

/* D3.js Specific Styles */
#d3TracksContainer {
    display: flex;
    flex-direction: row;
    height: 100%;
    width: 100%;
}

.d3-depth-track {
    width: 60px;
    flex-shrink: 0;
    border-right: 4px double #475569;
    background-color: #f8fafc;
    position: relative;
}

.d3-data-track {
    flex: 1;
    border-right: 4px double #475569;
    position: relative;
    overflow: hidden;
    background-color: #ffffff;
}

.d3-data-track:last-child {
    border-right: none;
}

.d3-data-track.drag-enter {
    background-color: rgba(37, 99, 235, 0.05);
    border: 2px dashed var(--primary);
}

.d3-axis text {
    font-family: 'Inter', sans-serif;
    font-size: 10px;
    fill: #475569;
}

.d3-axis path,
.d3-axis line {
    stroke: #cbd5e1;
}

.d3-grid-major line {
    stroke: #94a3b8;
    stroke-width: 1.5px;
}

.d3-grid-minor line {
    stroke: #e2e8f0;
    stroke-width: 1px;
}

.d3-crosshair-line {
    stroke: #ef4444;
    stroke-width: 1px;
    stroke-dasharray: 4,4;
    pointer-events: none;
}

.d3-crosshair-text {
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    fill: #ef4444;
    background: white;
    font-weight: 600;
    pointer-events: none;
}

.d3-tooltip-box {
    position: absolute;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 5px 8px;
    font-size: 11px;
    pointer-events: none;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    z-index: 10;
    white-space: nowrap;
}

/* Custom Context Menu */
.custom-context-menu {
    position: absolute;
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 5px 0;
    min-width: 180px;
    z-index: 9999;
    display: none;
    font-family: 'Inter', sans-serif;
    font-size: 13px;
}
.custom-context-menu.active {
    display: block;
}
.context-menu-item {
    padding: 8px 15px;
    cursor: pointer;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.2s;
}
.context-menu-item:hover {
    background-color: #f1f5f9;
    color: var(--primary);
}
.context-menu-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 4px 0;
}

/* Sidebar Auto-hide */
.sidebar.auto-hide {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    background: #f8fafc;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
}

/* ===== Properties Panel (Right Sidebar) ===== */
.properties-panel {
    width: 320px;
    min-width: 320px;
    height: 100%;
    background: #ffffff;
    color: #334155;
    display: flex;
    flex-direction: column;
    font-size: 13px;
    border-left: 1px solid #e2e8f0;
    z-index: 100;
}

.properties-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}
.properties-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #334155;
    display: flex;
    gap: 8px;
}
.properties-header h3 i {
    color: #2563eb;
}

.properties-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.properties-content::-webkit-scrollbar {
    width: 5px;
}

.properties-content::-webkit-scrollbar-track {
    background: #f8fafc;
}

.properties-content::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* Prop Group (Accordion) */
.prop-group {
    border-bottom: 1px solid #e2e8f0;
}

.prop-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    user-select: none;
    background: #f1f5f9;
    color: #334155;
    transition: background 0.2s;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.prop-group-header:hover {
    background: #e2e8f0;
}

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

.prop-group-header span i {
    color: #60a5fa;
    font-size: 11px;
}

.prop-group-header .toggle-icon {
    transition: transform 0.3s;
    font-size: 10px;
    color: #64748b;
}

.prop-group.collapsed .prop-group-header .toggle-icon {
    transform: rotate(-90deg);
}

.prop-group-content {
    overflow: hidden;
    max-height: 500px;
    transition: max-height 0.3s ease;
}

.prop-group.collapsed .prop-group-content {
    max-height: 0;
}

/* Property Rows */
.prop-row {
    display: flex;
    align-items: center;
    padding: 6px 16px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.5);
    transition: background 0.15s;
}

.prop-row:hover {
    background: rgba(241, 245, 249, 0.5);
}

.prop-row:last-child {
    border-bottom: none;
}

.prop-label {
    flex: 1;
    color: #475569;
    padding-right: 10px;
    font-weight: 500;
}

.prop-value {
    flex: 1.5;
}

.prop-input {
    width: 100%;
    padding: 6px 8px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #334155;
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.prop-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37,99,235,0.2);
}

.prop-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: #f1f5f9;
}

select.prop-input {
    cursor: pointer;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2394a3b8'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 4px center;
    background-size: 16px;
    padding-right: 22px;
}

.prop-color-input {
    width: 100%;
    height: 28px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 2px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.prop-color-input:hover {
    border-color: #3b82f6;
}

.prop-check {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 12px;
    color: #475569;
}

.prop-check input[type="checkbox"] {
    accent-color: #3b82f6;
    width: 15px;
    height: 15px;
    cursor: pointer;
}
