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

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

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: 2rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    margin-bottom: 3rem;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-title-container {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex: 1;
}

.logo-box {
    background: white;
    padding: 0.75rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo {
    height: 60px;
    width: auto;
    display: block;
}

.logo-title-container > div {
    text-align: left;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
}

.btn-admin {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-admin:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: #f0f7ff;
}

.btn-admin svg {
    flex-shrink: 0;
}

.header-buttons {
    display: flex;
    gap: 0.75rem;
}

main {
    flex: 1;
}

.upload-section {
    margin-bottom: 2rem;
}

.upload-box {
    background: var(--card-bg);
    border: 2px dashed var(--border-color);
    border-radius: 1rem;
    padding: 3rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.upload-box:hover {
    border-color: var(--primary-color);
    background: #f1f5f9;
}

.upload-box.drag-over {
    border-color: var(--primary-color);
    background: #eff6ff;
}

.upload-icon {
    width: 64px;
    height: 64px;
    color: var(--primary-color);
    margin: 0 auto 1rem;
}

.upload-text {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

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

.preview-section {
    background: var(--card-bg);
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: var(--shadow);
    text-align: center;
}

.preview-section img {
    max-width: 100%;
    max-height: 400px;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-lg);
}

.config-section {
    background: var(--card-bg);
    border-radius: 1rem;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.config-section label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.pipeline-select {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    background: white;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

.pipeline-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn-primary, .btn-secondary {
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    width: 100%;
}

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

.btn-primary:disabled {
    background: var(--secondary-color);
    cursor: not-allowed;
    opacity: 0.6;
}

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

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

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.results-section {
    background: var(--card-bg);
    border-radius: 1rem;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

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

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

.stat-card {
    background: var(--bg-color);
    padding: 1.5rem;
    border-radius: 0.5rem;
    text-align: center;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

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

.barcode-card {
    background: var(--bg-color);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin-bottom: 1rem;
    border-left: 4px solid var(--success-color);
}

.barcode-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.barcode-type {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--success-color);
    background: rgba(16, 185, 129, 0.1);
    padding: 0.25rem 0.75rem;
    border-radius: 0.25rem;
}

.barcode-confidence {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.barcode-data {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'Monaco', 'Courier New', monospace;
    background: white;
    padding: 1rem;
    border-radius: 0.5rem;
    word-break: break-all;
}

.barcode-roi {
    margin-top: 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    display: inline-block;
}

.barcode-bbox {
    margin-top: 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.error-section {
    background: var(--card-bg);
    border-radius: 1rem;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.error-box {
    text-align: center;
    padding: 2rem;
}

.error-icon {
    width: 64px;
    height: 64px;
    color: var(--error-color);
    margin: 0 auto 1rem;
}

.error-box h3 {
    color: var(--error-color);
    margin-bottom: 0.5rem;
}

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

footer {
    text-align: center;
    padding: 2rem 0;
    margin-top: 3rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
}

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

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

/* Pipeline Steps Visualization */
.pipeline-steps-section {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 2px solid var(--border-color);
}

.steps-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    margin-top: 1rem;
}

.step-card {
    background: var(--bg-color);
    border-radius: 0.75rem;
    padding: 1.5rem;
    border-left: 4px solid var(--primary-color);
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.step-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.step-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.step-number {
    background: var(--primary-color);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.step-name {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.step-time {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--success-color);
    background: rgba(16, 185, 129, 0.1);
    padding: 0.25rem 0.75rem;
    border-radius: 0.25rem;
}

.step-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    line-height: 1.5;
}

.step-image-container {
    background: white;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
}

.step-image {
    max-width: 100%;
    height: auto;
    border-radius: 0.25rem;
    display: block;
    box-shadow: var(--shadow);
}

.step-metadata {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.meta-item {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: white;
    padding: 0.25rem 0.75rem;
    border-radius: 0.25rem;
    border: 1px solid var(--border-color);
}

.step-details-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding: 0.75rem;
    background: rgba(37, 99, 235, 0.05);
    border-radius: 0.5rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.step-details-toggle:hover {
    background: rgba(37, 99, 235, 0.1);
}

.toggle-icon {
    font-size: 0.875rem;
    color: var(--primary-color);
    transition: transform 0.2s;
}

.toggle-text {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--primary-color);
}

.step-details-content {
    margin-top: 1rem;
    padding: 1rem;
    background: white;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}

.details-section {
    margin-bottom: 1.5rem;
}

.details-section:last-child {
    margin-bottom: 0;
}

.details-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.details-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.details-item {
    display: flex;
    font-size: 0.875rem;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 0.25rem;
}

.detail-key {
    font-weight: 600;
    color: var(--text-primary);
    min-width: 150px;
    flex-shrink: 0;
}

.detail-value {
    color: var(--text-secondary);
    font-family: 'Monaco', 'Courier New', monospace;
    word-break: break-word;
    white-space: pre-wrap;
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header h1 {
        font-size: 2rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .upload-box {
        padding: 2rem 1rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
