:root {
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent-color: #0ea5e9;
    --accent-glow: rgba(14, 165, 233, 0.1);
    --success-color: #10b981;
    --danger-color: #ef4444;
    --border-color: #e2e8f0;
    --input-bg: #f1f5f9;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at 10% 20%, rgba(14, 165, 233, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(99, 102, 241, 0.05) 0%, transparent 40%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    padding: 2rem 1rem;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

.banner-container {
    width: 100%;
    border-radius: 24px;
    overflow: hidden;
    margin-bottom: 2rem;
    box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    position: relative;
    background-color: #1e293b; /* Deep slate fallback background */
}


.app-banner {
    width: 100%;
    height: 350px;
    object-fit: cover;
    display: block;
    transition: transform 0.5s ease;
}

.banner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 3rem;
    pointer-events: none;
}

.banner-text-right {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 2.5rem;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    text-align: right;
    max-width: 500px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

.banner-text-right h1.banner-title {
    font-size: 4.5rem;
    font-weight: 800;
    margin: 0;
    padding: 0;
    line-height: 1;
    color: white;
    text-shadow: 0 4px 15px rgba(0,0,0,0.4);
    display: block; /* Explicitly visible */
}

.banner-desc {
    color: rgba(255, 255, 255, 0.95);
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 0.5rem;
    line-height: 1.2;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.author-attribution {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.8rem;
    margin-top: 0.5rem;
    font-style: italic;
}

.version-tag {
    position: absolute;
    bottom: 0.8rem;
    right: 1.5rem;
    background: rgba(14, 165, 233, 0.2);
    backdrop-filter: blur(4px);
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    border: 1px solid rgba(255, 255, 255, 0.2);
    letter-spacing: 0.05rem;
    z-index: 10;
}

header > div > h1, 
header > div > p {
    display: none; /* Hide original header text only */
}

header h1 span {
    color: var(--accent-color);
}

header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 300;
}

.module-switcher {
    display: flex;
    gap: 0.5rem;
    background: #f1f5f9;
    padding: 0.4rem;
    border-radius: 12px;
}

.module-btn {
    background: transparent;
    border: none;
    color: #64748b;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.module-btn.active {
    color: white;
    background: var(--accent-color);
    box-shadow: 0 4px 6px -1px rgba(14, 165, 233, 0.3);
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #1e293b;
}

/* Button Styles */
.btn {
    padding: 0.8rem 1.5rem;
    border-radius: 12px;
    border: none;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn.primary {
    background: linear-gradient(135deg, #0ea5e9, #6366f1);
    color: white;
}

.btn.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 15px -3px rgba(14, 165, 233, 0.3);
}

.btn.secondary {
    background: #ffffff;
    color: #475569;
    border: 1px solid var(--border-color);
}

.btn.secondary:hover {
    background: #f8fafc;
}

.btn.small {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.btn.x-large {
    padding: 1.5rem 3rem;
    font-size: 1.25rem;
    width: 100%;
}

.btn.success {
    background: var(--success-color);
    color: white;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* Upload Section */
.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 16px;
    padding: 3rem;
    text-align: center;
    transition: all 0.3s ease;
    background: #f8fafc;
}

.drop-zone.drag-over {
    border-color: var(--accent-color);
    background: #f0f9ff;
}

.drop-zone p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

/* Table Styles */
.table-container {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 500px;
    /* Limit height to show ~20 rows */
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th,
td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

th {
    position: sticky;
    top: 0;
    background: #f1f5f9;
    color: #475569;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    z-index: 5;
}

tr:hover {
    background-color: #f8fafc;
}

.col-header-type {
    margin-top: 0.5rem;
}

.type-toggle {
    display: flex;
    background: #e2e8f0;
    border-radius: 8px;
    padding: 2px;
    font-size: 0.7rem;
    width: 60px;
}

.type-toggle span {
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 6px;
    flex: 1;
    text-align: center;
    color: #64748b;
}

.type-toggle span.active {
    background: var(--accent-color);
    color: white;
}

/* Tabs */
.setup-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    background: #f1f5f9;
    padding: 0.4rem;
    border-radius: 12px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: #64748b;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    flex: 1;
    transition: all 0.2s ease;
}

.tab-btn.active {
    color: #0f172a;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.tab-content.hidden {
    display: none;
}

/* Form Elements */
input[type="text"],
input[type="number"],
select {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-family: inherit;
    outline: none;
    width: 100%;
}

input:focus,
select:focus {
    border-color: var(--accent-color);
    background: white;
}

/* Tweak Grid */
.tweak-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.tweak-item.full-width {
    grid-column: 1 / -1;
}

.tweak-item label {
    display: block;
    margin-bottom: 0.6rem;
    color: #475569;
    font-size: 0.9rem;
    font-weight: 500;
}

/* Switch */
.switch-group {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider.round {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: .4s;
    border-radius: 34px;
}

.slider.round:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent-color);
}

input:checked+.slider:before {
    transform: translateX(26px);
}

/* Slider */
.slider-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

input[type="range"] {
    flex: 1;
    accent-color: var(--accent-color);
}

/* Footer Section */
.run-container {
    margin: 3rem 0;
}

.action-footer {
    margin-top: 2rem;
    text-align: center;
    padding: 2rem;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 16px;
}

.action-footer p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* Utils */
.hidden {
    display: none !important;
}

#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f1f5f9;
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.editable-cell {
    background: #f0fdf4;
    border: 1px dashed var(--success-color);
    border-radius: 4px;
    min-width: 80px;
}

.editable-cell:empty::before {
    content: "Enter value";
    color: rgba(34, 197, 94, 0.3);
    font-size: 0.8rem;
}

/* SA Results Styling */
.badge {
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge.good { background: #dcfce7; color: #166534; }
.badge.overfitting { background: #fee2e2; color: #991b1b; }
.badge.underfitting { background: #fef9c3; color: #854d0e; }

#sa-reliability-info ul {
    list-style: none;
    padding: 0;
}

#sa-reliability-info li {
    padding: 1rem;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Tooltip / Balloon */
.tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: help;
    margin-left: 8px;
    color: var(--accent-color);
    background: #f0f9ff;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 0.75rem;
    flex-shrink: 0;
    border: 1px solid var(--accent-color);
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 280px;
    background-color: #1e293b;
    color: #ffffff;
    text-align: left;
    border-radius: 12px;
    padding: 1.25rem;
    position: absolute;
    z-index: 100;
    bottom: 150%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    font-size: 0.85rem;
    font-weight: 400;
    text-transform: none;
    line-height: 1.6;
    pointer-events: none;
}

.tooltip .tooltiptext::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -8px;
    border-width: 8px;
    border-style: solid;
    border-color: #1e293b transparent transparent transparent;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}

.tooltiptext b {
    color: #38bdf8;
    display: block;
    margin-bottom: 0.5rem;
}

/* Info Cards and Interpretation Guide */
.info-card {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-left: 5px solid var(--accent-color);
    margin-bottom: 2rem;
}

.info-card h2 {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--accent-color);
    margin-bottom: 1.5rem;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}

.info-item h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.info-item p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.accent-text {
    color: var(--accent-color);
}

.pareto-text {
    color: #f59e0b; /* Amber/Gold for Pareto */
}

/* DoE Quality Dashboard */
.quality-dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.quality-card {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.25rem;
    text-align: center;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.quality-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.metric-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.quality-flag {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    text-transform: uppercase;
}

.flag-good { background: #dcfce7; color: #15803d; }
.flag-limited { background: #fef9c3; color: #a16207; }
.flag-poor { background: #fee2e2; color: #b91c1c; }

/* ----------------------------------------- */
/* MOBILE RESPONSIVE LAYOUT (<= 768px Width) */
/* ----------------------------------------- */

@media (max-width: 768px) {
    /* Base Typography Reduction */
    body {
        padding: 0.5rem 0.25rem;
        font-size: 13px; /* Reduced by roughly 20-30% from 16px */
    }
    h2 { font-size: 1.4rem; }
    h3 { font-size: 1.1rem; }
    
    .container {
        width: 100%;
        padding: 0 0.5rem;
    }

    /* Banner Adjustments */
    .app-banner {
        height: 180px;
    }
    .banner-overlay {
        padding: 1rem;
        justify-content: center;
        text-align: center;
    }
    .banner-text-right {
        text-align: center;
        padding: 1rem;
        background: rgba(0, 0, 0, 0.4);
    }
    .banner-text-right h1.banner-title {
        font-size: 2rem;
    }
    .banner-desc {
        font-size: 0.8rem;
    }

    /* Grid Layouts to Stacks */
    .app-grid, .upload-grid, .btn-group {
        grid-template-columns: 1fr;
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    /* Feature Configuration Row Adjustments */
    .feature-row {
        flex-direction: column;
        align-items: stretch;
        background: var(--bg-color);
        padding: 0.75rem;
        border-radius: 12px;
        margin-bottom: 0.5rem;
    }
    .feature-row > * {
        margin-bottom: 0.5rem;
        width: 100%;
    }
    .feature-row button {
        align-self: flex-end;
        width: auto;
    }

    /* Target inputs for Optimization */
    .target-inputs {
        flex-direction: column;
        gap: 10px;
    }

    /* Table Wrapping & Setup Tabs (Horizontal Scroll for wide content) */
    .table-container, .tab-content {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        border: 1px solid var(--border-color);
        border-radius: 8px;
        margin: 1rem 0;
        padding-bottom: 8px; /* Leave space for scrollbar */
    }
    
    /* Explicit Scrollbar Hints for Mobile */
    .table-container::-webkit-scrollbar, .tab-content::-webkit-scrollbar, .plot-container::-webkit-scrollbar {
        height: 8px; /* Force a visible thick scrollbar tracking */
        background-color: #f1f5f9;
        border-radius: 4px;
    }
    .table-container::-webkit-scrollbar-thumb, .tab-content::-webkit-scrollbar-thumb, .plot-container::-webkit-scrollbar-thumb {
        background-color: #94a3b8;
        border-radius: 4px;
    }
    
    table {
        min-width: 500px; /* Ensure table keeps its readable width inside the scrollable box */
    }

    /* Plotly Chart Adjustments */
    .plot-container {
        min-width: 600px;
        min-height: 450px;
        padding-bottom: 10px;
    }

    /* Touch-friendly buttons */
    .btn {
        min-height: 40px; 
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        width: 100%; /* Full width buttons on mobile */
        justify-content: center;
    }
    
    /* Touch-friendly inputs */
    input[type="text"], 
    input[type="number"], 
    select {
        min-height: 40px;
        font-size: 14px; 
    }

    /* Card Panels & Plot Scrollers */
    .card {
        padding: 1rem;
        margin-bottom: 1rem;
        width: 100%;
        overflow-x: auto; /* Let charts slide without breaking layout */
        -webkit-overflow-scrolling: touch;
    }

    /* Parameter Controls */
    .parameter-controls {
        flex-direction: column;
    }
    .parameter-item {
        margin-bottom: 1rem;
    }

    /* Action Grid inside SA module */
    .action-grid {
        grid-template-columns: 1fr;
    }
}