
:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: rgba(59, 130, 246, 0.1);

    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-input: #ffffff;

    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-inverse: #ffffff;

    --border: #e2e8f0;
    --border-hover: #cbd5e1;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius: 12px;

    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-body: #0f172a;
        --bg-card: #1e293b;
        --bg-input: #334155;

        --text-main: #f8fafc;
        --text-muted: #94a3b8;

        --border: #334155;
        --border-hover: #475569;

        --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
        --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3);
    }
}

/* 强制覆盖深色模式的类 (JS toggle) */
html.dark-mode {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --border-hover: #475569;
}
html.light-mode {
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-hover: #cbd5e1;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    margin: 0;
    padding: 20px;
    transition: background-color 0.3s, color 0.3s;
}

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

/* Header */
header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

h1 { font-size: 1.8rem; font-weight: 700; margin: 0; letter-spacing: -0.025em; }
h2 { font-size: 1.4rem; font-weight: 600; margin: 1.5rem 0 1rem; }
h3 { font-size: 1.1rem; font-weight: 600; margin: 0 0 1rem; }

a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}
a:hover { color: var(--primary-hover); }

/* Components */
.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-sm);
    transition: transform 0.2s, box-shadow 0.2s, background-color 0.3s, border-color 0.3s;
}

.card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

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

.subgrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

/* Non-home pages: full-width blocks stacked vertically */
body.page-student .grid,
body.page-custom .grid {
    grid-template-columns: 1fr;
}
body.page-student .subgrid,
body.page-custom .subgrid {
    grid-template-columns: 1fr;
}

/* Form Elements */
label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

input[type="text"], input[type="number"], select, textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Range Slider */
input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
    margin: 10px 0;
}
input[type=range]:focus { outline: none; }

/* Webkit Slider */
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: var(--border);
    border-radius: 99px;
    transition: background 0.2s;
}
input[type=range]::-webkit-slider-thumb {
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    border: 2px solid var(--bg-card);
    transition: transform 0.1s;
}
input[type=range]:focus::-webkit-slider-thumb {
    transform: scale(1.1);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Firefox Slider */
input[type=range]::-moz-range-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: var(--border);
    border-radius: 99px;
}
input[type=range]::-moz-range-thumb {
    height: 18px;
    width: 18px;
    border: 2px solid var(--bg-card);
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* Buttons */
.actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    text-decoration: none;
}

button[type="submit"], .btn-primary {
    background-color: var(--primary);
    color: white;
}
button[type="submit"]:hover, .btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 12px var(--primary-light);
}

.btn-secondary {
    background-color: var(--bg-card);
    color: var(--text-main);
    border-color: var(--border);
}
.btn-secondary:hover {
    background-color: var(--bg-body);
    border-color: var(--border-hover);
}

/* Tables */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    white-space: nowrap;
}
th {
    background-color: var(--bg-body);
    font-weight: 600;
    text-align: left;
    padding: 12px 16px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}
td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-main);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background-color: var(--primary-light); }

/* Visuals */
.chart-container {
    background: white; /* 保持图表底色为白，确保Matplotlib渲染清晰 */
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
}
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Utils */
.muted { color: var(--text-muted); font-size: 0.85rem; }
.help { margin-top: 6px; color: var(--text-muted); font-size: 0.85rem; }
.viz-img { width: 100%; height: 360px; object-fit: contain; }
.viz-img-lg { width: 100%; height: 320px; object-fit: contain; }
.multiselect { min-height: 210px; }
.row { display: flex; align-items: center; gap: 10px; }
.row output { font-family: 'JetBrains Mono', monospace; font-weight: 600; color: var(--primary); width: 45px; text-align: right; }
.pill {
    display: inline-block;
    padding: 2px 8px;
    font-size: 0.75rem;
    border-radius: 99px;
    background: var(--bg-body);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
}
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
}
.theme-toggle:hover {
    background-color: var(--bg-body);
    color: var(--primary);
}

details {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.8rem;
    background: var(--bg-body);
}
details summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-main);
    user-select: none;
}
details[open] { background: var(--bg-card); }

/* Home: dashboard */
.toolbar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    align-items: end;
}
.toolbar .left {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 1rem;
}
.toolbar .right {
    display: flex;
    gap: 0.6rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}
.toolbar-simple {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}
.toolbar-simple .topline {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.toolbar-simple .filters {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.8rem;
}
.fig-summary {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 2px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-body);
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}
.chip.primary { border-color: rgba(59,130,246,0.35); background: rgba(59,130,246,0.12); color: var(--primary-hover); }
.chip.success { border-color: rgba(34,197,94,0.35); background: rgba(34,197,94,0.12); color: var(--success); }
.chip.warn { border-color: rgba(245,158,11,0.35); background: rgba(245,158,11,0.12); color: var(--warning); }
.chip.danger { border-color: rgba(239,68,68,0.35); background: rgba(239,68,68,0.12); color: var(--danger); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }
.card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}
.card-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.btn-sm { padding: 0.45rem 0.75rem; font-size: 0.85rem; border-radius: 10px; }
.img-frame {
    background: #fff;
    border-radius: 10px;
    border: 1px solid var(--border);
    padding: 10px;
    margin: 10px 0;
}
.fig-card h3 { margin: 0.35rem 0 0.5rem; }
.fig-meta { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1.8rem;
}
.section-header h2 { margin: 0; }
.section-desc { margin: 0.35rem 0 0; color: var(--text-muted); font-size: 0.92rem; }
.sticky { position: sticky; top: 12px; z-index: 20; }
.hidden { display: none !important; }

/* Modal (home: click image -> large view + explanation) */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    z-index: 999;
}
.modal {
    width: min(1180px, 100%);
    max-height: min(92vh, 980px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 6px 0 2px; }
.modal-close {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    font-size: 20px;
    line-height: 1;
}
.modal-close:hover { color: var(--text-main); border-color: var(--border-hover); }
.modal-body {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 0;
    min-height: 0;
}
.modal-left {
    background: #fff;
    border-right: 1px solid var(--border);
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}
.modal-left img {
    width: 100%;
    height: 100%;
    max-height: 78vh;
    object-fit: contain;
}
.modal-right {
    padding: 14px 16px;
    overflow: auto;
}
.modal-right h4 { margin: 0 0 8px; font-size: 1rem; }
.modal-ul { margin: 8px 0 0; padding-left: 18px; color: var(--text-muted); font-size: 0.9rem; }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.img-button {
    width: 100%;
    padding: 0;
    background: transparent;
    border: none;
    cursor: zoom-in;
}
@media (max-width: 920px) {
    .modal-body { grid-template-columns: 1fr; }
    .modal-left { border-right: none; border-bottom: 1px solid var(--border); }
}
