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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 40px 30px;
    text-align: center;
}

h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    font-weight: 700;
}

.subtitle {
    font-size: 1.2em;
    opacity: 0.95;
    margin-bottom: 5px;
}

.description {
    font-size: 0.95em;
    opacity: 0.85;
    max-width: 800px;
    margin: 10px auto 0;
}

.tabs {
    display: flex;
    background: #f7f9fc;
    border-bottom: 2px solid #e1e8ed;
    overflow-x: auto;
}

.tab {
    flex: 1;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    font-weight: 600;
    color: #64748b;
    transition: all 0.3s;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    min-width: 200px;
}

.tab:hover {
    background: #e8ecf1;
}

.tab.active {
    color: #667eea;
    border-bottom-color: #667eea;
    background: white;
}

.tab-content {
    display: none;
    padding: 30px;
    animation: fadeIn 0.3s;
}

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

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

.section {
    margin-bottom: 30px;
    padding: 25px;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid #e1e8ed;
}

.section h2 {
    color: #1e293b;
    margin-bottom: 20px;
    font-size: 1.5em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section h3 {
    color: #475569;
    margin-bottom: 15px;
    font-size: 1.2em;
}

.section h4 {
    color: #64748b;
    margin: 15px 0 10px;
    font-size: 1.1em;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

label {
    font-weight: 600;
    color: #475569;
    margin-bottom: 8px;
    font-size: 0.95em;
}

select, input[type="number"], input[type="file"] {
    padding: 12px;
    border: 2px solid #e1e8ed;
    border-radius: 8px;
    font-size: 1em;
    transition: all 0.3s;
    background: white;
    font-family: inherit;
}

select:focus, input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

input[type="file"] {
    cursor: pointer;
}

button, .btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 30px;
    border: none;
    border-radius: 8px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    width: 100%;
    margin-top: 20px;
}

button:hover, .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

button:active {
    transform: translateY(0);
}

button:disabled, .btn-primary:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.result-box {
    background: white;
    padding: 25px;
    border-radius: 12px;
    border: 2px solid #667eea;
    margin-top: 20px;
}

.metric {
    text-align: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px;
    margin: 10px 0;
}

.metric-label {
    font-size: 0.9em;
    opacity: 0.9;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.metric-value {
    font-size: 2em;
    font-weight: bold;
}

.warning {
    background: #fef3c7;
    border-left: 4px solid #f59e0b;
    padding: 15px;
    margin: 15px 0;
    border-radius: 8px;
    color: #92400e;
}

.error {
    background: #fee2e2;
    border-left: 4px solid #ef4444;
    padding: 15px;
    margin: 15px 0;
    border-radius: 8px;
    color: #991b1b;
}

.success {
    background: #d1fae5;
    border-left: 4px solid #10b981;
    padding: 15px;
    margin: 15px 0;
    border-radius: 8px;
    color: #065f46;
}

.info {
    background: #dbeafe;
    border-left: 4px solid #3b82f6;
    padding: 15px;
    margin: 15px 0;
    border-radius: 8px;
    color: #1e40af;
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 15px 0;
}

.toggle {
    position: relative;
    width: 50px;
    height: 26px;
    background: #cbd5e1;
    border-radius: 13px;
    cursor: pointer;
    transition: background 0.3s;
    flex-shrink: 0;
}

.toggle.active {
    background: #667eea;
}

.toggle-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle.active .toggle-slider {
    transform: translateX(24px);
}

.radio-group {
    display: flex;
    gap: 15px;
    margin: 10px 0;
    flex-wrap: wrap;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    transition: background 0.2s;
}

.radio-option:hover {
    background: rgba(102, 126, 234, 0.1);
}

.radio-option input[type="radio"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    margin: 0;
}

.radio-option span {
    font-weight: 500;
    color: #475569;
}

#plotDiv {
    width: 100%;
    height: 500px;
    margin-top: 20px;
    background: white;
    border-radius: 8px;
    padding: 10px;
}

.stat-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    background: white;
    border-radius: 8px;
    overflow: hidden;
}

.stat-table th, .stat-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e1e8ed;
}

.stat-table th {
    background: #f1f5f9;
    font-weight: 600;
    color: #475569;
}

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

.spinner {
    border: 4px solid #f3f4f6;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

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

.hidden {
    display: none !important;
}

.model-weight-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    margin-bottom: 10px;
    border: 2px solid #e1e8ed;
}

.model-weight-item input[type="checkbox"] {
    width: 24px;
    height: 24px;
    cursor: pointer;
}

.model-weight-item label {
    flex: 1;
    margin: 0;
    cursor: pointer;
}

.model-weight-item input[type="number"] {
    width: 100px;
    margin: 0;
}

.download-btn {
    background: #10b981;
    margin-top: 10px;
}

.download-btn:hover {
    background: #059669;
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

/* ── Feature 1: Optgroup & grouped MC model list ── */
optgroup {
    font-weight: 700;
    font-style: normal;
}

.mc-model-group-header {
    font-weight: 700;
    color: #475569;
    font-size: 0.82em;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 10px 15px 4px;
    margin-top: 8px;
    border-top: 1px solid #e1e8ed;
}

.mc-model-group-header:first-child {
    border-top: none;
    margin-top: 0;
}

/* ── Feature 2: Model Comparison ── */
.btn-secondary {
    background: white;
    color: #667eea;
    border: 2px solid #667eea;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: auto;
    margin: 0;
    box-shadow: none;
}

.btn-secondary:hover {
    background: #667eea;
    color: white;
    transform: none;
    box-shadow: none;
}

.cmp-model-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.cmp-model-group-header {
    font-weight: 700;
    color: #475569;
    font-size: 0.82em;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 10px 5px 4px;
    margin-top: 10px;
    border-top: 1px solid #e1e8ed;
}

.cmp-model-group-header:first-child {
    margin-top: 0;
    border-top: none;
}

.cmp-model-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 5px;
}

.cmp-model-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
    margin: 0;
}

.cmp-model-item label {
    margin: 0;
    cursor: pointer;
    font-weight: 400;
    color: #1e293b;
}

.cmp-toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.table-scroll-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.cmp-table th,
.cmp-table td {
    font-size: 0.88em;
    white-space: nowrap;
}

.cmp-range {
    font-family: monospace;
    font-size: 0.82em;
    max-width: 180px;
    white-space: normal;
    word-break: break-word;
}

.cmp-in-range {
    color: #059669;
    font-weight: 700;
}

.cmp-out-of-range {
    color: #d97706;
    font-weight: 700;
}

.cmp-chart {
    width: 100%;
    height: 420px;
    margin-top: 25px;
}

/* ── Feature 3: Chain Calculations ── */
.section-description {
    color: #64748b;
    margin-bottom: 20px;
    font-size: 0.95em;
    line-height: 1.5;
}

.chain-step {
    background: white;
    border: 2px solid #e1e8ed;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 15px;
}

.chain-step-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.chain-step-number {
    font-weight: 700;
    color: #667eea;
    font-size: 1.05em;
}

.chain-step-arrow {
    font-size: 1.4em;
    color: #94a3b8;
    flex: 1;
}

.btn-remove-step {
    background: #fee2e2;
    color: #ef4444;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 0.85em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    box-shadow: none;
    transition: background 0.2s;
    flex-shrink: 0;
}

.btn-remove-step:hover {
    background: #fca5a5;
    transform: none;
    box-shadow: none;
}

.chain-input-display {
    padding: 12px;
    border: 2px solid #e1e8ed;
    border-radius: 8px;
    background: #f1f5f9;
    color: #64748b;
    font-weight: 600;
    font-size: 1em;
}

.chain-add-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

/* Chain visual result display */
.chain-visual {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0;
    padding: 20px 0;
    overflow-x: auto;
}

.chain-node {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px;
    padding: 15px 20px;
    text-align: center;
    min-width: 120px;
    position: relative;
    flex-shrink: 0;
}

.chain-node-warning {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.chain-node-param {
    font-size: 0.78em;
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 5px;
}

.chain-node-value {
    font-size: 1.25em;
    font-weight: 700;
}

.chain-node-warn-icon {
    position: absolute;
    top: -8px;
    right: -8px;
    background: white;
    color: #d97706;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8em;
    border: 2px solid #f59e0b;
}

.chain-arrow-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 8px;
    flex-shrink: 0;
    max-width: 140px;
}

.chain-model-label {
    font-size: 0.68em;
    color: #64748b;
    text-align: center;
    word-break: break-word;
    margin-bottom: 2px;
    line-height: 1.2;
}

.chain-arrow {
    font-size: 1.8em;
    color: #94a3b8;
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    header {
        padding: 30px 20px;
    }
    
    h1 {
        font-size: 2em;
    }
    
    .tab {
        padding: 15px 10px;
        font-size: 0.9em;
        min-width: 150px;
    }
    
    .tab-content {
        padding: 20px;
    }
    
    .section {
        padding: 20px;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    #plotDiv {
        height: 400px;
    }
}
