/* CSS Variables */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --bg-white: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 6px rgba(0,0,0,0.1);
    --radius: 8px;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

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

/* Header */
header {
    text-align: center;
    padding: 30px 0;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border-radius: var(--radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow-lg);
}

header h1 {
    font-size: 2rem;
    margin-bottom: 8px;
}

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

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-white);
    padding: 8px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.tab-btn {
    flex: 1;
    padding: 12px 20px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-light);
    border-radius: 6px;
    transition: all 0.3s ease;
}

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

.tab-btn.active {
    background: var(--primary);
    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); }
}

/* Panels */
.panel {
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.panel h3 {
    color: var(--primary);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--bg);
}

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

.panel-grid .panel {
    margin-bottom: 0;
}

/* Forms */
.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-light);
    margin-bottom: 4px;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

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

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

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

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

.btn-secondary:hover {
    background: #475569;
}

.btn-success {
    background: var(--success);
    color: white;
}

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

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-light);
    font-size: 0.875rem;
}

td input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.9rem;
}

td input:focus {
    outline: none;
    border-color: var(--primary);
}

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

/* Result boxes */
.result-box {
    margin-top: 20px;
    padding: 16px;
    background: var(--bg);
    border-radius: 6px;
}

.result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
}

.result-item .label {
    color: var(--text-light);
    min-width: 150px;
}

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

.result-item .unit {
    color: var(--text-light);
    font-size: 0.9rem;
}

/* Status box */
.status-box {
    text-align: center;
    padding: 30px;
    background: var(--bg);
    border-radius: 6px;
}

.status-indicator {
    display: inline-block;
    padding: 12px 30px;
    border-radius: 30px;
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.status-indicator.pending {
    background: #e2e8f0;
    color: var(--text-light);
}

.status-indicator.miscible {
    background: #dcfce7;
    color: #166534;
}

.status-indicator.near-miscible {
    background: #fef3c7;
    color: #92400e;
}

.status-indicator.immiscible {
    background: #fee2e2;
    color: #991b1b;
}

.status-desc {
    color: var(--text-light);
    margin-top: 10px;
}

.status-legend {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.875rem;
    color: var(--text-light);
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.dot.miscible { background: #22c55e; }
.dot.near-miscible { background: #f59e0b; }
.dot.immiscible { background: #ef4444; }

/* Data Input Area */
.data-input-area {
    margin-bottom: 15px;
}

.data-input-area textarea {
    width: 100%;
    height: 200px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: monospace;
    font-size: 0.9rem;
    resize: vertical;
}

.data-input-area textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* Progress */
.calc-progress {
    margin-top: 15px;
    background: var(--bg);
    border-radius: 6px;
    padding: 12px;
}

.progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-bar::after {
    content: '';
    display: block;
    height: 100%;
    width: 0%;
    background: var(--primary);
    transition: width 0.3s ease;
}

.calc-progress.running .progress-bar::after {
    animation: progressPulse 1.5s ease infinite;
}

.calc-progress.complete .progress-bar::after {
    width: 100%;
    background: var(--success);
}

@keyframes progressPulse {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 100%; }
}

.progress-text {
    font-size: 0.875rem;
    color: var(--text-light);
}

/* Fit Metrics */
.fit-metrics {
    display: flex;
    gap: 30px;
    justify-content: center;
    flex-wrap: wrap;
}

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

.metric-label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-light);
    margin-bottom: 5px;
}

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

/* Charts */
canvas {
    width: 100% !important;
    height: auto !important;
    max-height: 400px;
}

.chart-legend {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-top: 15px;
    font-size: 0.9rem;
    color: var(--text-light);
}

.legend-line {
    display: inline-block;
    width: 30px;
    height: 3px;
    margin-right: 8px;
    vertical-align: middle;
}

.legend-line.observed {
    background: #ef4444;
}

.legend-line.calculated {
    background: #2563eb;
}

/* Actions */
.panel.actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    color: var(--text-light);
    font-size: 0.875rem;
}

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

    header h1 {
        font-size: 1.5rem;
    }

    .tabs {
        flex-wrap: wrap;
    }

    .tab-btn {
        flex: 1 1 45%;
    }

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

    .fit-metrics {
        gap: 15px;
    }

    .metric {
        padding: 15px 25px;
    }
}

/* Error highlight for tables */
.error-high {
    background-color: #fee2e2 !important;
}

.error-medium {
    background-color: #fef3c7 !important;
}

.error-low {
    background-color: #dcfce7 !important;
}
