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

:root {
    --primary-color: #6200ee;
    --primary-dark: #3700b3;
    --accent-color: #03dac6;
    --error-color: #e53935;
    --success-color: #4caf50;
    --bg-color: #f5f5f5;
    --card-bg: #ffffff;
    --text-primary: #212121;
    --text-secondary: #757575;
    --border-color: #e0e0e0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    padding: 40px 20px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    border-radius: 12px;
    margin-bottom: 30px;
    box-shadow: 0 4px 12px rgba(98, 0, 238, 0.2);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    background: var(--card-bg);
    padding: 10px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.tab-button {
    flex: 1;
    padding: 15px 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.tab-button:hover {
    background: var(--bg-color);
}

.tab-button.active {
    background: var(--primary-color);
    color: white;
}

/* Tab Content */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

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

/* Upload Section */
.upload-section {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.upload-section h2 {
    margin-bottom: 20px;
    color: var(--text-primary);
}

.upload-area {
    border: 3px dashed var(--border-color);
    border-radius: 12px;
    padding: 60px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 20px;
}

.upload-area:hover {
    border-color: var(--primary-color);
    background: rgba(98, 0, 238, 0.05);
}

.upload-area.drag-over {
    border-color: var(--primary-color);
    background: rgba(98, 0, 238, 0.1);
}

.upload-placeholder svg {
    color: var(--primary-color);
    margin-bottom: 20px;
}

.upload-placeholder p {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.file-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.file-selected {
    padding: 20px;
    background: var(--bg-color);
    border-radius: 8px;
}

.file-selected strong {
    color: var(--primary-color);
}

/* Buttons */
.btn {
    padding: 15px 30px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 12px rgba(98, 0, 238, 0.3);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(98, 0, 238, 0.4);
}

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

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

/* Progress */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-color);
    border-radius: 4px;
    overflow: hidden;
    margin: 20px 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    transition: width 0.3s ease;
    width: 0%;
}

#progressText {
    text-align: center;
    color: var(--text-secondary);
    margin-top: 10px;
}

/* Status Message */
.status-message {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    padding: 20px;
    background: var(--bg-color);
    border-radius: 8px;
    margin-top: 20px;
}

.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--bg-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Models Section */
.models-section {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.section-header h2 {
    color: var(--text-primary);
}

.models-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.model-card {
    background: var(--bg-color);
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.model-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.15);
    border-color: var(--primary-color);
}

.model-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.model-card-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.defect-badge {
    background: var(--error-color);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
}

.defect-badge.no-defects {
    background: var(--success-color);
}

.model-card-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.model-card-info div {
    display: flex;
    justify-content: space-between;
}

.loading {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px;
    font-size: 1.1rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    animation: fadeIn 0.3s ease;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 12px;
    max-width: 900px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

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

.model-detail-header {
    margin-bottom: 30px;
}

.model-detail-header h2 {
    color: var(--text-primary);
    margin-bottom: 10px;
}

.model-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    margin: 30px 0;
}

.stat-item {
    text-align: center;
    padding: 20px;
    background: var(--bg-color);
    border-radius: 8px;
}

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

.stat-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 5px;
}

.viewer-container {
    width: 100%;
    height: 500px;
    background: #1a1a1a;
    border-radius: 12px;
    margin: 20px 0;
    overflow: hidden;
}

.defects-list {
    margin-top: 30px;
}

.defects-list h3 {
    margin-bottom: 20px;
    color: var(--text-primary);
}

.defect-item {
    background: var(--bg-color);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 10px;
    border-left: 4px solid var(--error-color);
}

.defect-item h4 {
    color: var(--text-primary);
    margin-bottom: 8px;
}

.defect-item p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 4px 0;
}

/* Selection Toolbar */
.selection-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.selection-mode-btn {
    padding: 8px 16px;
    font-size: 0.9rem;
}

.selection-mode-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Analysis Results */
.analysis-results {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-left: 4px solid var(--accent-color);
}

.analysis-results h3 {
    margin-bottom: 15px;
    color: var(--text-primary);
}

.analysis-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.analysis-item {
    background: var(--bg-color);
    padding: 15px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.analysis-item.full-width {
    grid-column: 1 / -1;
}

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

.analysis-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.analysis-value {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary-color);
}

/* Range slider styling */
input[type="range"] {
    -webkit-appearance: none;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem;
    }

    .container {
        padding: 10px;
    }

    .upload-section, .models-section {
        padding: 20px;
    }

    .models-grid {
        grid-template-columns: 1fr;
    }

    .section-header {
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
    }

    .modal-content {
        padding: 20px;
        width: 95%;
    }

    .viewer-container {
        height: 300px;
    }
    
    .selection-toolbar {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .analysis-grid {
        grid-template-columns: 1fr;
    }
}

/* Analysis History */
.analysis-history {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.analysis-history h3 {
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.analysis-history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.analysis-history-item {
    background: var(--bg-color);
    border-radius: 8px;
    padding: 12px 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.analysis-history-item:hover {
    border-color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(98, 0, 238, 0.15);
}

.analysis-history-item.expanded {
    border-color: var(--primary-color);
    background: linear-gradient(135deg, #f3e5f5 0%, #e8eaf6 100%);
}

.analysis-history-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.analysis-number {
    font-weight: bold;
    color: var(--primary-color);
    font-size: 1.1rem;
}

.analysis-date {
    color: var(--text-secondary);
    font-size: 0.85rem;
    flex: 1;
}

.btn-delete-analysis {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    opacity: 0.5;
    transition: opacity 0.2s;
    padding: 4px 8px;
    border-radius: 4px;
}

.btn-delete-analysis:hover {
    opacity: 1;
    background: rgba(229, 57, 53, 0.1);
}

.analysis-history-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.stat-chip {
    background: white;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.analysis-history-details {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 10px;
    background: white;
    border-radius: 6px;
}

.detail-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.detail-value {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
}
