/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary-color), #3b82f6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Upload Section */
.upload-section {
    background: var(--card-bg);
    border: 2px dashed var(--border-color);
    border-radius: 1rem;
    padding: 3rem;
    text-align: center;
    transition: all 0.3s ease;
    margin-bottom: 2rem;
}

.upload-section:hover,
.upload-section.drag-over {
    border-color: var(--primary-color);
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
}

.upload-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.upload-content p {
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.upload-hint {
    font-size: 0.875rem !important;
    color: var(--text-secondary) !important;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-small {
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-size: 1rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    margin-top: 1rem;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-color);
    border-color: var(--primary-color);
}

.btn-small {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    background: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-small:hover {
    background: var(--border-color);
}

/* Loading */
.loading {
    text-align: center;
    padding: 2rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

/* Results Section */
.results {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.results-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.results-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: var(--primary-color);
    color: white;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge.mpd {
    background: var(--success-color);
}

.badge.ldr {
    background: var(--warning-color);
}

.badge.dat {
    background: var(--secondary-color);
}

/* 3D Viewer Styles */
.viewer-panel {
    margin-bottom: 1.5rem;
}

.viewer-container {
    width: 100%;
    height: 400px;
    background: #2a2a2a;
    border-radius: 0.5rem;
    overflow: hidden;
    position: relative;
}

.viewer-container canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

.viewer-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.viewer-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.viewer-controls .checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.viewer-controls input[type="checkbox"] {
    cursor: pointer;
}

/* View Buttons */
.view-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
}

.btn-view {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    min-width: 36px;
}

.btn-view:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.btn-view.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.25rem;
    border-radius: 0.75rem;
    text-align: center;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Two Column Layout */
.two-column {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 900px) {
    .two-column {
        grid-template-columns: 1fr;
    }
}

.column {
    min-width: 0;
}

/* Info Panel */
.info-panel {
    background: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.info-panel h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.info-table {
    width: 100%;
    border-collapse: collapse;
}

.info-table td {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.info-table td:first-child {
    width: 100px;
    color: var(--text-secondary);
    font-weight: 500;
}

.info-table tr:last-child td {
    border-bottom: none;
}

/* Geometry Chart */
.geometry-chart {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chart-bar-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chart-label {
    width: 100px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.chart-bar-wrapper {
    flex: 1;
    height: 20px;
    background: var(--bg-color);
    border-radius: 4px;
    overflow: hidden;
}

.chart-bar {
    height: 100%;
    background: var(--primary-color);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.chart-bar.bar-triangle {
    background: #3b82f6;
}

.chart-bar.bar-quad {
    background: #10b981;
}

.chart-bar.bar-line {
    background: #f59e0b;
}

.chart-bar.bar-optional {
    background: #8b5cf6;
}

.chart-bar.bar-meta {
    background: var(--secondary-color);
}

.chart-value {
    width: 40px;
    text-align: right;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Tree View (MPD Submodels) */
.tree-view {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}

.tree-item {
    padding: 0.5rem;
    border-radius: 4px;
    margin-bottom: 0.25rem;
}

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

.tree-item.main {
    background: #eff6ff;
    border-left: 3px solid var(--primary-color);
}

.tree-item.sub {
    padding-left: 1.5rem;
    border-left: 2px solid var(--border-color);
    margin-left: 0.5rem;
}

.tree-item-name {
    font-weight: 600;
    color: var(--text-primary);
}

.tree-item-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: 0.5rem;
}

/* BFC Info */
.bfc-info {
    font-size: 0.9rem;
}

.bfc-status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
}

.bfc-status.certified {
    background: #d1fae5;
    color: #065f46;
}

.bfc-status.uncertified {
    background: #fee2e2;
    color: #991b1b;
}

.bfc-status.none {
    background: var(--bg-color);
    color: var(--text-secondary);
}

.bfc-commands {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-color);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
}

.bfc-command {
    padding: 0.25rem 0;
    color: var(--text-secondary);
}

.bfc-command::before {
    content: "•";
    margin-right: 0.5rem;
    color: var(--primary-color);
}

/* Part List */
.part-list {
    max-height: 250px;
    overflow-y: auto;
}

.part-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s;
}

.part-item:hover {
    background: var(--bg-color);
}

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

.part-name {
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    word-break: break-all;
}

.part-color {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    border: 1px solid var(--border-color);
    margin-left: 0.5rem;
    flex-shrink: 0;
}

.part-count {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-right: 0.5rem;
}

/* Raw Content */
.raw-content {
    max-height: 400px;
    overflow: auto;
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 0.5rem;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
}

.toggle-btn {
    font-size: 0.8rem;
    color: var(--primary-color);
    cursor: pointer;
    font-weight: 500;
    margin-left: auto;
}

.toggle-btn:hover {
    text-decoration: underline;
}

/* Actions */
.actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Error */
.error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 0.75rem;
    padding: 1.5rem;
    text-align: center;
    color: var(--error-color);
}

.error-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* Footer */
footer {
    margin-top: auto;
    padding-top: 2rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Utility */
.hidden {
    display: none !important;
}

.text-secondary {
    color: var(--text-secondary);
}

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

::-webkit-scrollbar-track {
    background: var(--bg-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    header h1 {
        font-size: 1.875rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .upload-section {
        padding: 2rem 1rem;
    }
    
    .chart-label {
        width: 80px;
        font-size: 0.75rem;
    }
    
    .viewer-container {
        height: 300px;
    }
    
    .viewer-controls {
        flex-wrap: wrap;
    }
}

/* Library Styles */
.library-stats {
    display: flex;
    gap: 2rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--bg-color);
    border-radius: 0.5rem;
}

.library-stats span {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.library-stats strong {
    color: var(--primary-color);
    font-size: 1.125rem;
}

.library-actions {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.library-actions button {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--card-bg);
    border-radius: 1rem;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.2s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1rem 1.5rem;
    overflow-y: auto;
    max-height: 50vh;
}

.modal-footer {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

.modal-footer button {
    padding: 0.5rem 1.25rem;
    font-size: 0.9rem;
}

/* Missing Parts List */
.missing-parts-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.missing-parts-empty {
    text-align: center;
    padding: 2rem;
    color: var(--success-color);
    font-size: 1rem;
}

.missing-part-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-color);
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
}

.missing-part-item:hover {
    border-color: var(--primary-color);
    background: #eff6ff;
}

.missing-part-name {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    color: var(--text-primary);
    word-break: break-all;
}

.btn-copy-part {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    font-size: 1rem;
    opacity: 0.7;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.btn-copy-part:hover {
    opacity: 1;
}

/* Clickable stat value */
#stat-missing {
    transition: all 0.2s;
}

#stat-missing:hover {
    color: var(--error-color);
    transform: scale(1.05);
}

/* Box Selection Marquee */
.box-selection-marquee {
    position: fixed;
    pointer-events: none;
    z-index: 10000;
    border: 2px solid #3b82f6;
    background: rgba(59, 130, 246, 0.1);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3) inset;
    border-radius: 2px;
}

/* Alternative styles for different modes (can be toggled via JS) */
.box-selection-marquee.append-mode {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.1);
}

.box-selection-marquee.subtract-mode {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* Animation for marquee appearance */
@keyframes marquee-appear {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.box-selection-marquee {
    animation: marquee-appear 0.1s ease-out;
}
