/* Root Variables */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: rgba(0, 0, 0, 0.1);
}

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

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

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

/* Header */
header {
    text-align: center;
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 2px solid var(--border);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

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

/* Main Content */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Upload Section */
.upload-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 8px var(--shadow);
}

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

.upload-area:hover {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
}

.upload-area.dragover {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
}

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

.upload-text {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.upload-subtext {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

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

.file-info {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid var(--success-color);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-remove {
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Sensor Section */
.sensor-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 8px var(--shadow);
    border: 2px solid var(--primary-color);
}

.sensor-section h2 {
    margin-bottom: 0.5rem;
}

.sensor-auto-detect {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.sensor-status {
    font-size: 0.9rem;
    color: var(--success-color);
    font-weight: 500;
}

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

.sensor-field {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sensor-field label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.sensor-field input,
.sensor-field select {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    background: var(--surface);
    color: var(--text-primary);
    transition: border-color 0.3s;
}

.sensor-field input:focus,
.sensor-field select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.sensor-field input::placeholder {
    color: var(--text-secondary);
}

/* BLC Section */
.blc-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 8px var(--shadow);
    border: 2px solid #f59e0b;
}

.blc-section h2 {
    margin-bottom: 0.5rem;
}

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

.blc-field {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.blc-field label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.blc-field input {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    background: var(--surface);
    color: var(--text-primary);
    transition: border-color 0.3s;
}

.blc-field input:focus {
    outline: none;
    border-color: #f59e0b;
}

.blc-field input::placeholder {
    color: var(--text-secondary);
}

.field-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-style: italic;
}

.blc-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* White Balance Section */
.wb-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 8px var(--shadow);
    border: 2px solid #10b981;
}

.wb-section h2 {
    margin-bottom: 0.5rem;
}

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

.wb-field {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.wb-field label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.wb-field input {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    background: var(--surface);
    color: var(--text-primary);
    transition: border-color 0.3s;
}

.wb-field input:focus:not(:disabled) {
    outline: none;
    border-color: #10b981;
}

.wb-field input::placeholder {
    color: var(--text-secondary);
}

.wb-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* CCM Section */
.ccm-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 8px var(--shadow);
    border: 2px solid #8b5cf6;
}

.ccm-section h2 {
    margin-bottom: 0.5rem;
}

.ccm-matrix {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}

.matrix-label {
    text-align: center;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.matrix-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
}

.matrix-row {
    display: grid;
    grid-template-columns: 30px 1fr 1fr 1fr;
    gap: 0.75rem;
    align-items: center;
}

.row-label {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 1rem;
    text-align: right;
}

.matrix-row input {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    background: var(--surface);
    color: var(--text-primary);
    text-align: center;
    font-family: 'Courier New', monospace;
    transition: border-color 0.3s;
}

.matrix-row input:focus {
    outline: none;
    border-color: #8b5cf6;
}

.matrix-input-labels {
    display: grid;
    grid-template-columns: 30px 1fr 1fr 1fr;
    gap: 0.75rem;
    margin-top: 0.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.matrix-input-labels span {
    text-align: center;
}

.matrix-input-labels span:first-child {
    visibility: hidden;
}

.matrix-input-label-text {
    text-align: center;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.ccm-info {
    background: rgba(139, 92, 246, 0.1);
    border-left: 3px solid #8b5cf6;
    padding: 0.75rem 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

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

.ccm-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* Config Section */
.config-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 8px var(--shadow);
}

.config-section h2 {
    margin-bottom: 0.5rem;
}

.config-note {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.module-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--background);
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.module-item.module-mandatory {
    background: rgba(37, 99, 235, 0.05);
    border: 1px solid rgba(37, 99, 235, 0.2);
}

.module-label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.module-name {
    font-weight: 500;
}

.mandatory-badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    width: fit-content;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--secondary-color);
    transition: 0.3s;
    border-radius: 28px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: var(--primary-color);
}

input:checked + .toggle-slider:before {
    transform: translateX(24px);
}

/* Locked toggle (for mandatory modules) */
input:disabled + .toggle-slider {
    opacity: 0.6;
    cursor: not-allowed;
}

input:disabled:checked + .toggle-slider {
    background-color: var(--primary-color);
}

.toggle-slider.locked {
    cursor: not-allowed;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-download {
    padding: 0.75rem 2rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    width: 100%;
    justify-content: center;
    font-size: 1.1rem;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

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

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

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

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

.btn-download:hover {
    background: #16a34a;
}

/* Action Section */
.action-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 8px var(--shadow);
}

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

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.progress-info {
    margin-top: 1rem;
    text-align: center;
    color: var(--text-secondary);
}

.progress-detail {
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

/* Results Section */
.results-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 8px var(--shadow);
}

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

.result-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.result-image {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.image-label {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    margin: 0;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border);
}

.result-image img {
    width: 100%;
    height: auto;
    border-radius: 8px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px var(--shadow);
    transition: transform 0.3s ease;
}

.result-image img:hover {
    transform: scale(1.02);
}

/* Error Section */
.error-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 8px var(--shadow);
}

.error-message {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error-color);
    border-radius: 8px;
    color: var(--error-color);
}

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

/* Footer */
footer {
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--text-secondary);
}

.footer-note {
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

/* BNR Section */
.bnr-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 8px var(--shadow);
    border: 2px solid #ef4444;
}

.bnr-section h2 {
    margin-bottom: 0.5rem;
}

/* 2DNR Section */
.dnr2d-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 8px var(--shadow);
    border: 2px solid #06b6d4;
}

.dnr2d-section h2 {
    margin-bottom: 0.5rem;
}

/* Sharpen Section */
.sharpen-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 8px var(--shadow);
    border: 2px solid #ec4899;
}

.sharpen-section h2 {
    margin-bottom: 0.5rem;
}

/* Parameters Grid (for BNR, 2DNR, Sharpen) */
.params-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.param-field {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.param-field label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.param-field input {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.2s;
}

.param-field input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.param-field input[type="number"] {
    font-family: 'Courier New', monospace;
}

.param-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

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

    header h1 {
        font-size: 2rem;
    }

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

    .result-container {
        grid-template-columns: 1fr;
    }

    .quick-actions {
        flex-direction: column;
    }

    .quick-actions button {
        width: 100%;
    }

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

    .param-actions {
        flex-direction: column;
    }

    .param-actions button {
        width: 100%;
    }
}
