: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);
}

/* Top bar */
.top-bar {
    background-color: #fff;
    border-bottom: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.logo a {
    text-decoration: none;
    color: var(--primary);
    font-weight: 600;
    margin-right: 15px;
}
.logo span {
    font-weight: 700;
    font-size: 18px;
    color: #0f172a;
}
.top-actions {
    display: flex;
    gap: 10px;
}

/* Layout */
.container {
    display: flex;
    height: calc(100vh - 55px);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: #fff;
    border-right: 4px double #475569;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    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;
}
.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;
    height: 100%;
}
.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;
}
