Files
Personal-Finance-Management/app/templates/base.html
T
2026-06-05 15:23:23 -04:00

588 lines
27 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="csrf-token" content="{{ csrf_token() }}" />
<title>{% block title %}PFM{% endblock %} — Personal Finance</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet"
/>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=DM+Sans:ital,wght@0,300;0,400;0,500;0,600;1,400&family=DM+Mono:wght@400;500&display=swap"
rel="stylesheet"
/>
<style>
:root {
--sidebar-width: 240px;
--sidebar-col-width: 64px;
--sidebar-bg: #0f172a;
--sidebar-text: #94a3b8;
--sidebar-text-active: #f1f5f9;
--sidebar-hover: #1e293b;
--sidebar-active: #1e3a5f;
--accent: #3b82f6;
--topbar-h: 56px;
--body-bg: #f1f5f9;
--card-bg: #ffffff;
--text: #0f172a;
--muted: #64748b;
--border: #e2e8f0;
--income: #10b981;
--expense: #ef4444;
--invest: #3b82f6;
--trans: all 0.2s cubic-bezier(.4,0,.2,1);
}
*, *::before, *::after { box-sizing: border-box; }
body { font-family: 'DM Sans', sans-serif; background: var(--body-bg); color: var(--text); margin: 0; overflow-x: hidden; font-size: 14px; }
/* SIDEBAR */
#sidebar {
position: fixed; top: 0; left: 0; height: 100vh;
width: var(--sidebar-width); background: var(--sidebar-bg);
display: flex; flex-direction: column; z-index: 1040;
transition: var(--trans); overflow: hidden;
}
#sidebar.collapsed { width: var(--sidebar-col-width); }
.sb-brand {
display: flex; align-items: center; gap: 10px;
padding: 0 16px; height: var(--topbar-h);
border-bottom: 1px solid #1e293b; flex-shrink: 0; overflow: hidden;
}
.sb-brand .b-icon {
width: 32px; height: 32px; background: var(--accent);
border-radius: 8px; display: flex; align-items: center;
justify-content: center; flex-shrink: 0; color: #fff; font-size: 16px;
}
.sb-brand .b-text { font-size: 15px; font-weight: 600; color: var(--sidebar-text-active); white-space: nowrap; transition: var(--trans); }
#sidebar.collapsed .b-text { opacity: 0; width: 0; }
.sb-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 6px 0; scrollbar-width: none; }
.sb-nav::-webkit-scrollbar { display: none; }
.sb-section {
font-size: 10px; font-weight: 600; letter-spacing: .1em;
text-transform: uppercase; color: #475569;
padding: 14px 20px 4px; white-space: nowrap; transition: var(--trans);
}
#sidebar.collapsed .sb-section { opacity: 0; }
.sb-link {
display: flex; align-items: center; gap: 12px;
padding: 9px 16px; color: var(--sidebar-text);
text-decoration: none; font-size: 13.5px;
border-radius: 6px; margin: 1px 8px;
white-space: nowrap; overflow: hidden; transition: var(--trans); position: relative;
}
.sb-link:hover { background: var(--sidebar-hover); color: var(--sidebar-text-active); }
.sb-link.active { background: var(--sidebar-active); color: var(--sidebar-text-active); font-weight: 500; }
.sb-link.active::before {
content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
width: 3px; height: 60%; background: var(--accent); border-radius: 0 2px 2px 0;
}
.sb-link i { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.sb-link .lt { transition: var(--trans); }
#sidebar.collapsed .sb-link .lt { opacity: 0; width: 0; overflow: hidden; }
.sb-footer { padding: 8px; border-top: 1px solid #1e293b; flex-shrink: 0; }
/* TOPBAR */
#topbar {
position: fixed; top: 0; right: 0;
left: var(--sidebar-width); height: var(--topbar-h);
background: var(--card-bg); border-bottom: 1px solid var(--border);
display: flex; align-items: center; padding: 0 20px;
z-index: 1030; gap: 12px; transition: var(--trans);
}
#sidebar.collapsed ~ #topbar { left: var(--sidebar-col-width); }
.tb-toggle {
background: none; border: none; color: var(--muted);
font-size: 18px; cursor: pointer; padding: 4px 6px;
border-radius: 6px; line-height: 1; transition: var(--trans);
}
.tb-toggle:hover { background: var(--border); color: var(--text); }
.tb-title { font-size: 15px; font-weight: 600; flex: 1; }
.tb-right { display: flex; align-items: center; gap: 8px; }
/* MAIN */
#main {
margin-left: var(--sidebar-width);
margin-top: var(--topbar-h);
padding: 24px;
min-height: calc(100vh - var(--topbar-h));
transition: var(--trans);
}
#sidebar.collapsed ~ #main { margin-left: var(--sidebar-col-width); }
/* CARDS */
.pcard { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.pcard-sm { padding: 16px; }
.pcard-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 6px; }
/* STAT CARDS */
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.stat-card .stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.stat-card .stat-value { font-size: 24px; font-weight: 600; line-height: 1.2; margin-top: 4px; font-family: 'DM Mono', monospace; }
.stat-card .stat-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; }
/* FLASH */
.flash-wrap {
position: fixed; top: calc(var(--topbar-h) + 12px); right: 16px;
z-index: 2000; display: flex; flex-direction: column; gap: 8px; max-width: 360px;
}
/* BADGES */
.badge-income { background: #d1fae5; color: #065f46; }
.badge-expense { background: #fee2e2; color: #991b1b; }
.badge-transfer { background: #dbeafe; color: #1e40af; }
/* UTILITIES */
.text-income { color: var(--income) !important; }
.text-expense { color: var(--expense) !important; }
.text-invest { color: var(--invest) !important; }
.mono { font-family: 'DM Mono', monospace; }
/* TABLE */
.pfm-table { width: 100%; border-collapse: collapse; }
.pfm-table th { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.pfm-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.pfm-table tbody tr:hover { background: #f8fafc; }
.pfm-table tbody tr:last-child td { border-bottom: none; }
/* RESPONSIVE */
@media (max-width: 768px) {
#sidebar { transform: translateX(-100%); width: var(--sidebar-width) !important; }
#sidebar.mob-open { transform: translateX(0); }
#topbar, #sidebar.collapsed ~ #topbar { left: 0 !important; }
#main, #sidebar.collapsed ~ #main { margin-left: 0 !important; padding: 14px; }
.pcard { padding: 14px; }
.stat-card { padding: 14px 16px; }
.stat-card .stat-value { font-size: 18px; }
/* Tables: scroll horizontally on small screens */
.table-wrap, .pcard.p-0 { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Remove h-100 height constraint on table wrappers so overflow-x works */
.pcard.p-0.h-100 { height: auto !important; }
/* Default min-width — hides .d-mob-none columns first, then scroll */
.pfm-table { min-width: 420px; }
/* Wider tables (investments, etc.) can opt in to more space */
.pfm-table.wide { min-width: 700px; }
/* Hide low-priority columns */
.d-mob-none { display: none !important; }
/* Topbar title: truncate so action buttons always fit */
.tb-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
/* Flash: stretch full width */
.flash-wrap { left: 8px; right: 8px; max-width: none; }
/* Teller/Schwab action rows: stack on very small cards */
.pcard .d-flex.gap-2 { flex-wrap: wrap; }
}
/* Extra-small screens: hide button label text, keep icons */
@media (max-width: 575px) {
#main { padding: 10px; }
.pcard { padding: 12px; }
.btn-label { display: none; }
.tb-right .btn { padding-left: 8px; padding-right: 8px; }
.stat-card .stat-value { font-size: 16px; }
}
/* Keyboard shortcut cheatsheet modal */
#kbd-modal .kbd-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
#kbd-modal .kbd-row:last-child { border: none; }
#kbd-modal kbd { background: #f1f5f9; border: 1px solid #cbd5e1; border-radius: 4px; padding: 2px 7px; font-size: 12px; font-family: 'DM Mono', monospace; }
.sb-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1039; }
.sb-overlay.on { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }
/* ── Dark mode ─────────────────────────────────────────────────────── */
body.dark-mode {
--body-bg: #0f172a; --card-bg: #1e293b; --text: #e2e8f0;
--muted: #94a3b8; --border: #334155;
color-scheme: dark;
}
body.dark-mode #topbar { background: #1e293b; border-color: #334155; }
body.dark-mode .pfm-table tbody tr:hover { background: #263548; }
body.dark-mode .pfm-table th, body.dark-mode .pfm-table td { border-color: #334155; }
body.dark-mode .form-control, body.dark-mode .form-select {
background: #0f172a; border-color: #334155; color: #e2e8f0;
}
body.dark-mode .form-control:focus, body.dark-mode .form-select:focus {
background: #0f172a; border-color: #3b82f6; color: #e2e8f0;
box-shadow: 0 0 0 .2rem rgba(59,130,246,.25);
}
body.dark-mode .form-control::placeholder { color: #475569; }
body.dark-mode .form-check-input { background-color: #334155; border-color: #475569; }
body.dark-mode .form-check-input:checked { background-color: #3b82f6; border-color: #3b82f6; }
body.dark-mode .btn-outline-secondary { color: #94a3b8; border-color: #334155; }
body.dark-mode .btn-outline-secondary:hover,
body.dark-mode .btn-outline-secondary:focus { background: #334155; color: #e2e8f0; border-color: #334155; }
body.dark-mode .btn-outline-primary { color: #93c5fd; border-color: #1e40af; }
body.dark-mode .btn-outline-primary:hover { background: #1e40af; color: #fff; }
body.dark-mode .btn-outline-warning { color: #fcd34d; border-color: #92400e; }
body.dark-mode .btn-outline-warning:hover { background: #92400e; color: #fff; }
body.dark-mode .btn-outline-danger { color: #fca5a5; border-color: #991b1b; }
body.dark-mode .btn-outline-danger:hover { background: #991b1b; color: #fff; }
body.dark-mode .dropdown-menu { background: #1e293b; border-color: #334155; }
body.dark-mode .dropdown-item { color: #e2e8f0; }
body.dark-mode .dropdown-item:hover, body.dark-mode .dropdown-item:focus { background: #334155; color: #f1f5f9; }
body.dark-mode .dropdown-divider { border-color: #334155; }
body.dark-mode .modal-content { background: #1e293b; border-color: #334155; color: #e2e8f0; }
body.dark-mode .modal-header, body.dark-mode .modal-footer { border-color: #334155; }
body.dark-mode .modal-header .btn-close { filter: invert(1) grayscale(1); }
body.dark-mode .alert-warning { background: #451a03; border-color: #92400e; color: #fcd34d; }
body.dark-mode .alert-danger { background: #450a0a; border-color: #991b1b; color: #fca5a5; }
body.dark-mode .alert-success { background: #052e16; border-color: #166534; color: #86efac; }
body.dark-mode .alert-info { background: #0c1a2e; border-color: #1e40af; color: #93c5fd; }
body.dark-mode .progress { background: #334155; }
body.dark-mode .table { color: #e2e8f0; }
body.dark-mode .input-group-text { background: #334155; border-color: #334155; color: #94a3b8; }
body.dark-mode .badge-income { background: #064e3b; color: #6ee7b7; }
body.dark-mode .badge-expense { background: #450a0a; color: #fca5a5; }
body.dark-mode .badge-transfer { background: #1e3a5f; color: #93c5fd; }
body.dark-mode #kbd-modal kbd { background: #334155; border-color: #475569; color: #e2e8f0; }
body.dark-mode .report-tab { background: #1e293b; border-color: #334155; color: #94a3b8; }
body.dark-mode .report-tab:hover { background: #334155; color: #e2e8f0; }
body.dark-mode .report-tab.active { background: #e2e8f0; color: #0f172a; border-color: #e2e8f0; }
/* Override common hardcoded light backgrounds in component inline styles */
body.dark-mode [style*="background:#f8fafc"], body.dark-mode [style*="background: #f8fafc"],
body.dark-mode [style*="background:#f1f5f9"], body.dark-mode [style*="background: #f1f5f9"]
{ background: #263548 !important; }
body.dark-mode [style*="background:#eff6ff"], body.dark-mode [style*="background: #eff6ff"]
{ background: #1e3a5f !important; }
body.dark-mode [style*="background:#fef2f2"], body.dark-mode [style*="background: #fef2f2"]
{ background: #450a0a !important; }
body.dark-mode [style*="background:#f0fdf4"], body.dark-mode [style*="background: #f0fdf4"]
{ background: #052e16 !important; }
body.dark-mode [style*="background:#fff5e6"], body.dark-mode [style*="background:#fffbeb"]
{ background: #451a03 !important; }
/* Text color overrides for hardcoded darks */
body.dark-mode [style*="color:#0f172a"] { color: #e2e8f0 !important; }
body.dark-mode [style*="color:#1e293b"] { color: #94a3b8 !important; }
body.dark-mode [style*="color:#374151"] { color: #94a3b8 !important; }
/* Border overrides */
body.dark-mode [style*="border-bottom:1px solid #e2e8f0"],
body.dark-mode [style*="border-bottom: 1px solid #e2e8f0"] { border-color: #334155 !important; }
body.dark-mode [style*="border:1px solid #e2e8f0"],
body.dark-mode [style*="border: 1px solid #e2e8f0"] { border-color: #334155 !important; }
{% block extra_css %}{% endblock %}
</style>
<script>
/* Apply dark mode class to body before first paint to avoid flash */
(function(){ if(localStorage.getItem('pfm_dark')==='1') document.documentElement.setAttribute('data-pfm-dark','1'); })();
</script>
<style>
/* Instant pre-body dark (avoids FOUC) — matches body.dark-mode vars */
html[data-pfm-dark] body { --body-bg:#0f172a; --card-bg:#1e293b; --text:#e2e8f0; --muted:#94a3b8; --border:#334155; }
</style>
</head>
<body>
<div class="sb-overlay" id="sbOverlay"></div>
<!-- SIDEBAR -->
<nav id="sidebar">
<div class="sb-brand">
<div class="b-icon"><i class="bi bi-currency-exchange"></i></div>
<span class="b-text">PFM</span>
</div>
<div class="sb-nav">
<a
href="{{ url_for('dashboard.index') }}"
class="sb-link {% if request.endpoint == 'dashboard.index' %}active{% endif %}"
>
<i class="bi bi-grid-1x2"></i><span class="lt">Dashboard</span>
</a>
<div class="sb-section">Money</div>
<a
href="{{ url_for('transactions.index') }}"
class="sb-link {% if request.blueprint == 'transactions' %}active{% endif %}"
>
<i class="bi bi-arrow-left-right"></i
><span class="lt">Transactions</span>
</a>
<a
href="{{ url_for('transactions.new', type='income') }}"
class="sb-link"
>
<i class="bi bi-arrow-down-circle"></i
><span class="lt">Add Income</span>
</a>
<a
href="{{ url_for('transactions.new', type='expense') }}"
class="sb-link"
>
<i class="bi bi-arrow-up-circle"></i
><span class="lt">Add Expense</span>
</a>
<a
href="{{ url_for('accounts.index') }}"
class="sb-link {% if request.blueprint == 'accounts' %}active{% endif %}"
>
<i class="bi bi-wallet2"></i><span class="lt">Accounts</span>
</a>
<a
href="{{ url_for('bank_import.index') }}"
class="sb-link {% if request.blueprint == 'bank_import' %}active{% endif %}"
>
<i class="bi bi-upload"></i><span class="lt">Import Statement</span>
</a>
<div class="sb-section">Planning</div>
<a
href="{{ url_for('budgets.index') }}"
class="sb-link {% if request.blueprint == 'budgets' %}active{% endif %}"
>
<i class="bi bi-pie-chart"></i><span class="lt">Budgets</span>
</a>
<a
href="{{ url_for('goals.index') }}"
class="sb-link {% if request.blueprint == 'goals' %}active{% endif %}"
>
<i class="bi bi-bullseye"></i><span class="lt">Goals</span>
</a>
<div class="sb-section">Growth</div>
<a
href="{{ url_for('investments.index') }}"
class="sb-link {% if request.blueprint == 'investments' %}active{% endif %}"
>
<i class="bi bi-graph-up-arrow"></i
><span class="lt">Investments</span>
</a>
<a
href="{{ url_for('reports.index') }}"
class="sb-link {% if request.blueprint == 'reports' %}active{% endif %}"
>
<i class="bi bi-file-earmark-bar-graph"></i
><span class="lt">Reports</span>
</a>
<div class="sb-section">AI</div>
<a
href="{{ url_for('ai.index') }}"
class="sb-link {% if request.blueprint == 'ai' %}active{% endif %}"
>
<i class="bi bi-stars"></i><span class="lt">AI Assistant</span>
</a>
</div>
<div class="sb-footer">
<a
href="{{ url_for('categories.index') }}"
class="sb-link {% if request.blueprint == 'categories' %}active{% endif %}"
>
<i class="bi bi-tags"></i><span class="lt">Categories</span>
</a>
<a
href="{{ url_for('settings.index') }}"
class="sb-link {% if request.blueprint in ('settings', 'logs', 'plaid', 'teller', 'schwab') %}active{% endif %}"
>
<i class="bi bi-gear"></i><span class="lt">Settings</span>
</a>
<a href="{{ url_for('auth.logout') }}" class="sb-link">
<i class="bi bi-box-arrow-right"></i><span class="lt">Logout</span>
</a>
</div>
</nav>
<!-- TOPBAR -->
<header id="topbar">
<button class="tb-toggle" id="sbToggle">
<i class="bi bi-list"></i>
</button>
<span class="tb-title">{% block page_title %}{% endblock %}</span>
<div class="tb-right">
{% block topbar_actions %}{% endblock %}
<button id="dark-toggle" type="button" title="Toggle dark mode"
style="background:none;border:none;color:var(--muted);font-size:15px;padding:3px 6px;border-radius:6px;cursor:pointer;line-height:1;"
class="d-inline-flex align-items-center">
<i class="bi bi-moon-stars"></i>
</button>
<button type="button" data-bs-toggle="modal" data-bs-target="#kbd-modal"
title="Keyboard shortcuts (?)"
style="background:none;border:none;color:var(--muted);font-size:13px;padding:3px 6px;border-radius:6px;cursor:pointer;line-height:1;"
class="d-none d-md-inline-flex align-items-center">
<i class="bi bi-keyboard"></i>
</button>
<span class="d-none d-sm-inline small text-muted mono"
>{{ current_user.display_name or current_user.username }}</span
>
</div>
</header>
<!-- FLASH -->
<div class="flash-wrap">
{% with messages = get_flashed_messages(with_categories=true) %} {% for
cat, msg in messages %}
<div
class="alert alert-{{ 'danger' if cat == 'error' else cat }} alert-dismissible fade show shadow-sm mb-0 py-2 px-3"
style="font-size: 13px; border-radius: 8px"
role="alert"
>
{{ msg }}<button
type="button"
class="btn-close"
style="padding: 0.4rem"
data-bs-dismiss="alert"
></button>
</div>
{% endfor %} {% endwith %}
</div>
<!-- MAIN -->
<main id="main">{% block content %}{% endblock %}</main>
<!-- Keyboard shortcuts cheatsheet modal -->
<div class="modal fade" id="kbd-modal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header py-2 px-3">
<h6 class="modal-title mb-0"><i class="bi bi-keyboard me-2"></i>Keyboard Shortcuts</h6>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body px-3 py-2">
<div class="kbd-row"><span>New expense</span><kbd>n</kbd></div>
<div class="kbd-row"><span>New income</span><kbd>i</kbd></div>
<div class="kbd-row"><span>Focus search</span><kbd>/</kbd></div>
<div class="kbd-row"><span>Go to dashboard</span><kbd>g</kbd> then <kbd>h</kbd></div>
<div class="kbd-row"><span>Go to transactions</span><kbd>g</kbd> then <kbd>t</kbd></div>
<div class="kbd-row"><span>Go to accounts</span><kbd>g</kbd> then <kbd>a</kbd></div>
<div class="kbd-row"><span>Show this help</span><kbd>?</kbd></div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
(function () {
const sb = document.getElementById("sidebar");
const overlay = document.getElementById("sbOverlay");
const KEY = "pfm_sb";
const mob = () => window.innerWidth < 769;
if (!mob() && localStorage.getItem(KEY) === "1")
sb.classList.add("collapsed");
document
.getElementById("sbToggle")
.addEventListener("click", function () {
if (mob()) {
sb.classList.toggle("mob-open");
overlay.classList.toggle("on");
} else {
sb.classList.toggle("collapsed");
localStorage.setItem(
KEY,
sb.classList.contains("collapsed") ? "1" : "0",
);
}
});
overlay.addEventListener("click", function () {
sb.classList.remove("mob-open");
overlay.classList.remove("on");
});
document.querySelectorAll(".flash-wrap .alert").forEach(function (el) {
setTimeout(function () {
bootstrap.Alert.getOrCreateInstance(el).close();
}, 4500);
});
})();
// ── Keyboard shortcuts ────────────────────────────────────────────────
(function () {
var gPending = false, gTimer = null;
function inInput() {
var t = document.activeElement;
return t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' ||
t.tagName === 'SELECT' || t.isContentEditable);
}
document.addEventListener('keydown', function (e) {
if (inInput()) return;
if (e.ctrlKey || e.metaKey || e.altKey) return;
var key = e.key;
// ? → show shortcut modal
if (key === '?') {
e.preventDefault();
bootstrap.Modal.getOrCreateInstance(
document.getElementById('kbd-modal')
).show();
return;
}
// g-chord for navigation
if (gPending) {
clearTimeout(gTimer);
gPending = false;
if (key === 'h') { window.location.href = '/'; return; }
if (key === 't') { window.location.href = '{{ url_for("transactions.index") }}'; return; }
if (key === 'a') { window.location.href = '{{ url_for("accounts.index") }}'; return; }
return;
}
if (key === 'g') {
gPending = true;
gTimer = setTimeout(function () { gPending = false; }, 1000);
return;
}
// n → new expense
if (key === 'n') {
e.preventDefault();
window.location.href = '{{ url_for("transactions.new", type="expense") }}';
return;
}
// i → new income
if (key === 'i') {
e.preventDefault();
window.location.href = '{{ url_for("transactions.new", type="income") }}';
return;
}
// / → focus search input
if (key === '/') {
var s = document.querySelector('input[name="q"], input[type="search"], .search-input');
if (s) {
e.preventDefault();
s.focus();
s.select();
}
}
});
})();
// ── Dark mode toggle ─────────────────────────────────────────────────
(function () {
var DKEY = 'pfm_dark';
var body = document.body;
var btn = document.getElementById('dark-toggle');
function applyDark(on) {
body.classList.toggle('dark-mode', on);
document.documentElement.setAttribute('data-pfm-dark', on ? '1' : '0');
if (btn) btn.querySelector('i').className = on ? 'bi bi-sun' : 'bi bi-moon-stars';
}
// Initialise from storage
var saved = localStorage.getItem(DKEY) === '1';
applyDark(saved);
if (btn) btn.addEventListener('click', function () {
var next = !body.classList.contains('dark-mode');
localStorage.setItem(DKEY, next ? '1' : '0');
applyDark(next);
});
})();
</script>
{% block extra_js %}{% endblock %}
</body>
</html>