/* ==========================================================================
   MLExplain -- Scientific / Academic Theme
   Clean blue, white, and gray palette
   ========================================================================== */

/* -- Reset & Base --------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #1a56db;
    --primary-dark: #1343b0;
    --primary-light: #e8effc;
    --secondary: #4b5563;
    --accent: #059669;
    --danger: #dc2626;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
    --radius: 8px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* -- Navbar --------------------------------------------------------------- */
.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}
.nav-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.nav-brand:hover { text-decoration: none; }
.brand-icon { font-size: 1.4rem; }
.nav-links {
    list-style: none;
    display: flex;
    gap: 0.25rem;
}
.nav-links a {
    display: block;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    color: var(--secondary);
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}
.nav-links a:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.nav-links a.active { background: var(--primary); color: #fff; }

/* -- Layout --------------------------------------------------------------- */
.main-content { flex: 1; padding: 2rem 1.5rem; }
.container { max-width: 1200px; margin: 0 auto; }

/* -- Hero / Page Headers -------------------------------------------------- */
.hero, .page-header {
    text-align: center;
    margin-bottom: 2rem;
    padding: 1.5rem 0;
}
.hero h1, .page-header h1 { font-size: 2rem; color: var(--primary-dark); margin-bottom: 0.5rem; }
.subtitle { color: var(--text-muted); font-size: 1.1rem; }

/* -- Cards ---------------------------------------------------------------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}
.card h2 { font-size: 1.25rem; margin-bottom: 1rem; color: var(--primary-dark); }

/* -- Stats Grid ----------------------------------------------------------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    box-shadow: var(--shadow);
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.25rem; }

/* -- Action Grid ---------------------------------------------------------- */
.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}
.action-card {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    transition: box-shadow 0.2s, border-color 0.2s;
    color: var(--text);
}
.action-card:hover { box-shadow: var(--shadow-lg); border-color: var(--primary); text-decoration: none; }
.action-icon { font-size: 2rem; margin-bottom: 0.75rem; }
.action-card h3 { margin-bottom: 0.5rem; color: var(--primary-dark); }

/* -- Sections ------------------------------------------------------------- */
.section { margin-bottom: 2rem; }
.section h2 { font-size: 1.25rem; margin-bottom: 1rem; color: var(--primary-dark); }

/* -- Tables --------------------------------------------------------------- */
.table-container { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.data-table tr:hover { background: #f1f5f9; }
.description-cell { max-width: 300px; }

/* -- Metrics Grid --------------------------------------------------------- */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.metric-card {
    background: var(--primary-light);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}
.metric-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.metric-value { font-size: 1.5rem; font-weight: 700; color: var(--primary-dark); margin-top: 0.25rem; }

/* -- Badges --------------------------------------------------------------- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-algo { background: var(--primary-light); color: var(--primary-dark); }

/* -- Buttons -------------------------------------------------------------- */
.btn {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    text-align: center;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow); }
.btn-secondary { background: #e2e8f0; color: var(--secondary); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.8rem; }
.btn-block { display: block; width: 100%; }

/* -- Forms ---------------------------------------------------------------- */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.35rem; font-weight: 600; font-size: 0.9rem; color: var(--secondary); }
.form-control {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: border-color 0.15s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,0.1); }
.form-row { display: flex; gap: 1rem; }
.form-group.half { flex: 1; }
.form-group.inline { display: inline-block; margin-right: 0.75rem; min-width: 120px; }
.checkbox-group { display: flex; flex-direction: column; gap: 0.5rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; cursor: pointer; }

/* -- Train / Compare Layout ----------------------------------------------- */
.train-layout, .compare-layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 1.5rem;
    align-items: start;
}
@media (max-width: 768px) {
    .train-layout, .compare-layout { grid-template-columns: 1fr; }
}

/* -- Charts --------------------------------------------------------------- */
.chart-section { margin-top: 1.5rem; }
.chart-section h3 { font-size: 1rem; margin-bottom: 0.75rem; color: var(--secondary); }

/* -- Confusion Matrix Table ----------------------------------------------- */
.cm-table-container { margin-top: 1rem; }
.cm-table td, .cm-table th { text-align: center; padding: 0.5rem; }
.cm-cell { font-weight: 600; }
.cm-diagonal { background: var(--primary-light); color: var(--primary-dark); }

/* -- Info Grid ------------------------------------------------------------ */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
}
.info-item { display: flex; gap: 0.5rem; }
.info-label { color: var(--text-muted); font-size: 0.85rem; }
.info-value { font-weight: 600; font-size: 0.85rem; }

/* -- Prediction ----------------------------------------------------------- */
.predict-features {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.prediction-result {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--primary-light);
    border-radius: var(--radius);
}
.prob-bars { margin-top: 0.75rem; }
.prob-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.prob-label { width: 100px; font-size: 0.85rem; text-align: right; }
.prob-bar-bg { flex: 1; height: 20px; background: var(--border); border-radius: 10px; overflow: hidden; }
.prob-bar { height: 100%; background: var(--primary); border-radius: 10px; transition: width 0.3s; }
.prob-value { width: 50px; font-size: 0.85rem; font-weight: 600; }

/* -- About Page ----------------------------------------------------------- */
.about-content .card { margin-bottom: 1.5rem; }
.algo-grid, .method-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; }
.algo-card, .method-card {
    padding: 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.algo-card h3, .method-card h3 { font-size: 1rem; color: var(--primary-dark); margin-bottom: 0.5rem; }
.algo-params { margin-top: 0.5rem; }
.param-tag {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: var(--mono);
    margin-right: 0.25rem;
}
.dataset-list { display: grid; gap: 0.75rem; }
.dataset-item { padding: 0.75rem; background: var(--bg); border-radius: var(--radius); border: 1px solid var(--border); }
.dataset-item h3 { font-size: 1rem; color: var(--primary-dark); margin-bottom: 0.25rem; }
.tech-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.5rem; }
.tech-item { font-size: 0.9rem; padding: 0.5rem; }

/* -- Loading Overlay ------------------------------------------------------ */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.spinner {
    width: 40px; height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -- Empty state / Muted -------------------------------------------------- */
.empty-state { text-align: center; padding: 2rem; color: var(--text-muted); }
.text-muted { color: var(--text-muted); }
.error { color: var(--danger); font-weight: 600; }

/* -- Flash messages ------------------------------------------------------- */
.flash-messages { margin-bottom: 1rem; }
.flash { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 0.5rem; font-size: 0.9rem; }
.flash-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash-info { background: var(--primary-light); color: var(--primary-dark); border: 1px solid #bfdbfe; }

/* -- Footer --------------------------------------------------------------- */
.footer {
    text-align: center;
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: auto;
}

/* -- Code ----------------------------------------------------------------- */
code {
    background: var(--bg);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 0.85em;
    color: var(--primary-dark);
}

/* -- Responsive ----------------------------------------------------------- */
@media (max-width: 640px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .metrics-grid { grid-template-columns: repeat(2, 1fr); }
    .nav-links { gap: 0; }
    .nav-links a { padding: 0.4rem 0.6rem; font-size: 0.85rem; }
}
