First commit
This commit is contained in:
@@ -0,0 +1,357 @@
|
||||
/* Finance UI: theme, nav drawer, inline edits, live numbers, charts. No framework needed. */
|
||||
"use strict";
|
||||
|
||||
// ------------------------------------------------------------------ helpers
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
const $$ = (sel, root = document) => Array.from(root.querySelectorAll(sel));
|
||||
const css = (name) => getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
||||
const nf = (d) => new Intl.NumberFormat("nl-NL", { minimumFractionDigits: d, maximumFractionDigits: d });
|
||||
const eur = (v, d = 0) => (v < 0 ? "-" : "") + "€ " + nf(d).format(Math.abs(v));
|
||||
const eurCompact = (v) => {
|
||||
const a = Math.abs(v);
|
||||
if (a >= 1e6) return (v < 0 ? "-" : "") + "€ " + nf(1).format(a / 1e6) + "M";
|
||||
if (a >= 1e4) return (v < 0 ? "-" : "") + "€ " + nf(a >= 1e5 ? 0 : 1).format(a / 1e3) + "k";
|
||||
return eur(v);
|
||||
};
|
||||
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
||||
const monthLabel = (ym, withYear) => { const [y, m] = ym.split("-"); return MONTHS[+m - 1] + (withYear ? " " + y : ""); };
|
||||
const dateLabel = (iso) => { const d = new Date(iso); return d.getDate() + " " + MONTHS[d.getMonth()] + " " + d.getFullYear(); };
|
||||
|
||||
// ------------------------------------------------------------------ theme
|
||||
function currentTheme() { try { return localStorage.getItem("theme") || "auto"; } catch (e) { return "auto"; } }
|
||||
function markTheme() { $$("[data-theme-set]").forEach((b) => b.classList.toggle("on", b.dataset.themeSet === currentTheme())); }
|
||||
document.addEventListener("click", (e) => {
|
||||
const b = e.target.closest("[data-theme-set]");
|
||||
if (!b) return;
|
||||
const t = b.dataset.themeSet;
|
||||
try { t === "auto" ? localStorage.removeItem("theme") : localStorage.setItem("theme", t); } catch (err) {}
|
||||
if (t === "auto") delete document.documentElement.dataset.theme; else document.documentElement.dataset.theme = t;
|
||||
markTheme();
|
||||
redrawCharts(); // pick up the new colours without a reload
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------------ mobile nav drawer
|
||||
document.addEventListener("click", (e) => {
|
||||
if (e.target.closest("[data-nav-toggle]")) document.body.classList.toggle("nav-open");
|
||||
else if (e.target.closest("[data-nav-close]")) document.body.classList.remove("nav-open");
|
||||
});
|
||||
document.addEventListener("keydown", (e) => e.key === "Escape" && document.body.classList.remove("nav-open"));
|
||||
|
||||
// ------------------------------------------------------------------ inline edits & small UX
|
||||
document.addEventListener("change", async (e) => {
|
||||
const el = e.target;
|
||||
if (el.matches("select[data-tx]")) {
|
||||
const body = new FormData();
|
||||
body.append("category_id", el.value);
|
||||
const r = await fetch(`/transactions/${el.dataset.tx}/category`, { method: "POST", body });
|
||||
el.style.boxShadow = `0 0 0 3px ${r.ok ? css("--good") : css("--bad")}55`;
|
||||
const dot = el.closest("td")?.querySelector(".dot");
|
||||
if (dot && el.selectedOptions[0]) dot.style.background = el.selectedOptions[0].dataset.color || "transparent";
|
||||
setTimeout(() => (el.style.boxShadow = ""), 900);
|
||||
setTimeout(pollLive, 300);
|
||||
}
|
||||
if (el.matches("input[data-notes]")) {
|
||||
const body = new FormData();
|
||||
body.append("notes", el.value);
|
||||
await fetch(`/transactions/${el.dataset.notes}/notes`, { method: "POST", body });
|
||||
}
|
||||
if (el.matches("[data-autosubmit]")) el.form.submit();
|
||||
});
|
||||
document.addEventListener("submit", (e) => {
|
||||
const msg = e.target.dataset.confirm;
|
||||
if (msg && !confirm(msg)) e.preventDefault();
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------------ live numbers
|
||||
// Elements with data-live="key" refresh from /api/live. data-fmt: eur | eur0 | eurs | eur0s | pct ; data-color = good/bad by sign.
|
||||
const LIVE_INTERVAL = 30000;
|
||||
function fmt(v, kind) {
|
||||
if (v === null || v === undefined || Number.isNaN(v)) return "–";
|
||||
if (kind === "pct") return (v < 0 ? "-" : "+") + nf(1).format(Math.abs(v)) + "%";
|
||||
const sign = v < 0 ? "-" : kind.endsWith("s") && v > 0 ? "+" : "";
|
||||
return `${sign}€ ${nf(kind.startsWith("eur0") ? 0 : 2).format(Math.abs(v))}`;
|
||||
}
|
||||
function animate(el, from, to, kind) {
|
||||
const t0 = performance.now(), dur = 700;
|
||||
const step = (now) => {
|
||||
const p = Math.min(1, (now - t0) / dur), k = 1 - Math.pow(1 - p, 3);
|
||||
el.textContent = fmt(from + (to - from) * k, kind);
|
||||
if (p < 1) requestAnimationFrame(step);
|
||||
};
|
||||
requestAnimationFrame(step);
|
||||
}
|
||||
function applyLive(values) {
|
||||
$$("[data-live]").forEach((el) => {
|
||||
const key = el.dataset.live;
|
||||
if (!(key in values)) return;
|
||||
const to = values[key], kind = el.dataset.fmt || "eur";
|
||||
const from = el.dataset.v !== undefined && el.dataset.v !== "" ? parseFloat(el.dataset.v) : null;
|
||||
el.dataset.v = to ?? "";
|
||||
if (el.hasAttribute("data-color") && to !== null) { el.classList.toggle("good", to >= 0); el.classList.toggle("bad", to < 0); }
|
||||
if (from === null) { el.textContent = fmt(to, kind); return; }
|
||||
if (to === null || Math.abs(to - from) < 0.005) return;
|
||||
animate(el, from, to, kind);
|
||||
el.classList.remove("flash-up", "flash-down");
|
||||
void el.offsetWidth;
|
||||
el.classList.add(to > from ? "flash-up" : "flash-down");
|
||||
});
|
||||
}
|
||||
let liveVersion = null;
|
||||
async function pollLive() {
|
||||
if (!$("[data-live]") || document.hidden) return;
|
||||
const qs = new URLSearchParams(location.search), params = new URLSearchParams();
|
||||
["account", "month"].forEach((k) => qs.get(k) && params.set(k, qs.get(k)));
|
||||
try {
|
||||
const r = await fetch("/api/live?" + params, { headers: { Accept: "application/json" } });
|
||||
if (!r.ok) return;
|
||||
const data = await r.json();
|
||||
applyLive(data.values);
|
||||
const changed = liveVersion && data.version.split(":")[0] !== liveVersion.split(":")[0];
|
||||
$$(".live-status").forEach((s) => (s.innerHTML = changed ? 'New data · <a href="">reload</a>' : "Live · " + data.at));
|
||||
liveVersion = data.version;
|
||||
} catch (e) { /* offline / session expired: keep last numbers */ }
|
||||
}
|
||||
|
||||
// Refresh prices in place
|
||||
document.addEventListener("submit", async (e) => {
|
||||
const form = e.target;
|
||||
if (!form.matches("[data-ajax-refresh]")) return;
|
||||
e.preventDefault();
|
||||
const btn = $("button", form), label = btn.innerHTML;
|
||||
btn.disabled = true;
|
||||
btn.lastChild.textContent = " Refreshing…";
|
||||
try {
|
||||
const r = await (await fetch("/api/prices/refresh", { method: "POST" })).json();
|
||||
await pollLive();
|
||||
btn.lastChild.textContent = r.ok ? " Updated" : " Some failed";
|
||||
if (!r.ok) btn.title = r.errors.join("\n");
|
||||
} catch (err) { btn.lastChild.textContent = " Failed"; }
|
||||
setTimeout(() => { btn.disabled = false; btn.innerHTML = label; }, 2200);
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------------ charts
|
||||
const PALETTE = ["#6366f1", "#22c55e", "#f59e0b", "#ec4899", "#06b6d4", "#8b5cf6", "#ef4444", "#84cc16", "#14b8a6", "#f97316"];
|
||||
const charts = [];
|
||||
|
||||
const solid = (ds, i) => {
|
||||
const c = Array.isArray(ds.backgroundColor) ? ds.backgroundColor[i] : ds.borderColor || ds.backgroundColor;
|
||||
return typeof c === "string" ? c : ds.borderColor;
|
||||
};
|
||||
function baseOptions() {
|
||||
return {
|
||||
responsive: true, maintainAspectRatio: false, animation: { duration: 500 },
|
||||
interaction: { mode: "index", intersect: false },
|
||||
plugins: {
|
||||
legend: { display: false },
|
||||
tooltip: {
|
||||
backgroundColor: css("--panel"), titleColor: css("--text"), bodyColor: css("--text"), footerColor: css("--muted"),
|
||||
borderColor: css("--line"), borderWidth: 1, padding: 12, cornerRadius: 10, boxPadding: 5, usePointStyle: true,
|
||||
titleFont: { weight: "600" }, footerFont: { weight: "500" },
|
||||
callbacks: {},
|
||||
},
|
||||
},
|
||||
scales: {
|
||||
x: { grid: { display: false }, border: { display: false }, ticks: { color: css("--muted"), maxRotation: 0, autoSkipPadding: 14 } },
|
||||
y: { grid: { color: css("--line"), drawTicks: false }, border: { display: false },
|
||||
ticks: { color: css("--muted"), padding: 8, maxTicksLimit: 6, callback: (v) => eurCompact(v) } },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Text in the middle of a doughnut; follows the hovered slice.
|
||||
const centerText = {
|
||||
id: "centerText",
|
||||
afterDraw(chart, _args, opts) {
|
||||
if (!opts || !opts.label) return;
|
||||
const { ctx, chartArea: a } = chart;
|
||||
const active = chart.getActiveElements()[0];
|
||||
const ds = chart.data.datasets[0];
|
||||
const total = ds.data.reduce((s, v, i) => s + (chart.getDataVisibility(i) ? v : 0), 0);
|
||||
let top = opts.label, big = eur(total), small = "";
|
||||
if (active) {
|
||||
const v = ds.data[active.index];
|
||||
top = chart.data.labels[active.index];
|
||||
big = eur(v);
|
||||
small = total ? nf(1).format((v / total) * 100) + "%" : "";
|
||||
}
|
||||
const x = (a.left + a.right) / 2, y = (a.top + a.bottom) / 2;
|
||||
ctx.save();
|
||||
ctx.textAlign = "center"; ctx.textBaseline = "middle";
|
||||
ctx.fillStyle = css("--muted"); ctx.font = `500 12px ${getComputedStyle(document.body).fontFamily}`;
|
||||
ctx.fillText(top.length > 18 ? top.slice(0, 17) + "…" : top, x, y - 18);
|
||||
ctx.fillStyle = css("--text"); ctx.font = `700 19px ${getComputedStyle(document.body).fontFamily}`;
|
||||
ctx.fillText(big, x, y + 3);
|
||||
if (small) { ctx.fillStyle = css("--muted"); ctx.font = `600 12px ${getComputedStyle(document.body).fontFamily}`; ctx.fillText(small, x, y + 23); }
|
||||
ctx.restore();
|
||||
},
|
||||
};
|
||||
|
||||
// Vertical hover line for line charts
|
||||
const crosshair = {
|
||||
id: "crosshair",
|
||||
afterDatasetsDraw(chart) {
|
||||
const act = chart.tooltip && chart.tooltip.getActiveElements();
|
||||
if (!act || !act.length || chart.config.type !== "line") return;
|
||||
const x = act[0].element.x, { top, bottom } = chart.chartArea, ctx = chart.ctx;
|
||||
ctx.save(); ctx.strokeStyle = css("--muted"); ctx.globalAlpha = 0.35; ctx.setLineDash([4, 4]);
|
||||
ctx.beginPath(); ctx.moveTo(x, top); ctx.lineTo(x, bottom); ctx.stroke(); ctx.restore();
|
||||
},
|
||||
};
|
||||
|
||||
function gradient(chart, color) {
|
||||
const { ctx, chartArea } = chart;
|
||||
if (!chartArea) return color + "33";
|
||||
const g = ctx.createLinearGradient(0, chartArea.top, 0, chartArea.bottom);
|
||||
g.addColorStop(0, color + "55"); g.addColorStop(1, color + "00");
|
||||
return g;
|
||||
}
|
||||
|
||||
const builders = {
|
||||
// Income/expense bars + net line; click a month to drill in.
|
||||
months(canvas, d) {
|
||||
const good = css("--good"), bad = css("--bad"), accent = css("--accent");
|
||||
const net = d.income.map((v, i) => v - d.expense[i]);
|
||||
const o = baseOptions();
|
||||
o.scales.x.ticks.callback = function (v) { const l = this.getLabelForValue(v); return monthLabel(l, l.endsWith("-01")); };
|
||||
o.plugins.tooltip.callbacks = {
|
||||
labelColor: (c) => ({ borderColor: solid(c.dataset, c.dataIndex), backgroundColor: solid(c.dataset, c.dataIndex), borderRadius: 3 }),
|
||||
title: (items) => monthLabel(items[0].label, true),
|
||||
label: (c) => ` ${c.dataset.label}: ${eur(c.parsed.y)}`,
|
||||
footer: (items) => { const i = items[0].dataIndex, r = d.income[i] ? (net[i] / d.income[i]) * 100 : null;
|
||||
return r === null ? "" : `Savings rate ${nf(0).format(r)}%`; },
|
||||
};
|
||||
o.plugins.legend = { display: true, position: "bottom", labels: { usePointStyle: true, pointStyle: "rectRounded", boxWidth: 10, boxHeight: 10, color: css("--muted"), padding: 16 } };
|
||||
o.onClick = (_e, els) => { if (els.length && canvas.dataset.link) location.href = canvas.dataset.link.replace("{label}", d.labels[els[0].index]); };
|
||||
o.onHover = (e, els) => (e.native.target.style.cursor = els.length ? "pointer" : "default");
|
||||
const dim = (c) => d.labels.map((l) => (l === d.current ? c : c + "99"));
|
||||
return {
|
||||
type: "bar",
|
||||
data: { labels: d.labels, datasets: [
|
||||
{ label: "Income", data: d.income, backgroundColor: dim(good), borderRadius: 6, maxBarThickness: 22, order: 2 },
|
||||
{ label: "Expenses", data: d.expense, backgroundColor: dim(bad), borderRadius: 6, maxBarThickness: 22, order: 2 },
|
||||
{ label: "Net", data: net, type: "line", borderColor: accent, backgroundColor: accent, borderWidth: 2, tension: 0.35,
|
||||
pointRadius: 3, pointHoverRadius: 5, pointBackgroundColor: css("--panel"), order: 1 },
|
||||
] },
|
||||
options: o,
|
||||
};
|
||||
},
|
||||
|
||||
// Doughnut with centre total, custom clickable legend, click-through links.
|
||||
donut(canvas, d) {
|
||||
const o = baseOptions();
|
||||
delete o.scales; o.interaction = { mode: "nearest", intersect: true };
|
||||
o.cutout = "72%"; o.layout = { padding: 6 };
|
||||
o.plugins.centerText = { label: canvas.dataset.center === "spent" ? "Total spent" : "Total" };
|
||||
o.plugins.tooltip.enabled = false; // the centre shows the hovered slice
|
||||
o.onClick = (_e, els) => { if (els.length && d.links && d.links[els[0].index]) location.href = d.links[els[0].index]; };
|
||||
o.onHover = (e, els) => (e.native.target.style.cursor = els.length && d.links ? "pointer" : "default");
|
||||
const colors = d.colors || d.labels.map((_, i) => PALETTE[i % PALETTE.length]);
|
||||
return {
|
||||
type: "doughnut",
|
||||
data: { labels: d.labels, datasets: [{ data: d.data, backgroundColor: colors, borderColor: css("--panel"), borderWidth: 3, hoverOffset: 8, borderRadius: 4 }] },
|
||||
options: o, plugins: [centerText],
|
||||
};
|
||||
},
|
||||
|
||||
// Value vs paid over time; gradient fill, range filter, P/L in tooltip.
|
||||
history(canvas, d) {
|
||||
const accent = css("--accent"), muted = css("--muted");
|
||||
const o = baseOptions();
|
||||
o.scales.x.ticks.maxTicksLimit = 7;
|
||||
o.scales.x.ticks.callback = function (v) { const l = this.getLabelForValue(v); const dt = new Date(l); return dt.getDate() + " " + MONTHS[dt.getMonth()]; };
|
||||
o.plugins.tooltip.callbacks = {
|
||||
labelColor: (c) => ({ borderColor: c.dataset.borderColor, backgroundColor: c.dataset.borderColor, borderRadius: 3 }),
|
||||
title: (items) => dateLabel(items[0].label),
|
||||
label: (c) => ` ${c.dataset.label}: ${eur(c.parsed.y)}`,
|
||||
footer: (items) => {
|
||||
const v = items.find((i) => i.datasetIndex === 0), c = items.find((i) => i.datasetIndex === 1);
|
||||
if (!v || !c) return "";
|
||||
const pl = v.parsed.y - c.parsed.y, pct = c.parsed.y ? (pl / c.parsed.y) * 100 : 0;
|
||||
return `P/L ${pl >= 0 ? "+" : ""}${eur(pl)} (${pct >= 0 ? "+" : ""}${nf(1).format(pct)}%)`;
|
||||
},
|
||||
};
|
||||
o.plugins.legend = { display: true, position: "bottom", labels: { usePointStyle: true, pointStyle: "line", color: muted, padding: 16 } };
|
||||
canvas._full = d;
|
||||
return {
|
||||
type: "line",
|
||||
data: { labels: d.labels, datasets: [
|
||||
{ label: "Value", data: d.value, borderColor: accent, borderWidth: 2.5, tension: 0.3, pointRadius: 0, pointHoverRadius: 5,
|
||||
pointHoverBackgroundColor: accent, pointHoverBorderColor: css("--panel"), pointHoverBorderWidth: 2,
|
||||
fill: true, backgroundColor: (ctx) => gradient(ctx.chart, accent) },
|
||||
{ label: "Paid", data: d.cost, borderColor: muted, borderWidth: 1.5, borderDash: [5, 5], pointRadius: 0, pointHoverRadius: 0, stepped: true, fill: false },
|
||||
] },
|
||||
options: o, plugins: [crosshair],
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
function buildLegend(chart, id) {
|
||||
const box = document.getElementById(id);
|
||||
if (!box) return;
|
||||
box.innerHTML = "";
|
||||
const ds = chart.data.datasets[0];
|
||||
const total = ds.data.reduce((a, b) => a + b, 0);
|
||||
chart.data.labels.forEach((label, i) => {
|
||||
const b = document.createElement("button");
|
||||
b.type = "button";
|
||||
b.innerHTML = `<span class="dot" style="background:${ds.backgroundColor[i]}"></span><span>${label}</span><span class="v">${eur(ds.data[i])} · ${nf(0).format((ds.data[i] / total) * 100)}%</span>`;
|
||||
b.title = "Click to hide/show";
|
||||
b.onclick = () => { chart.toggleDataVisibility(i); b.classList.toggle("off", !chart.getDataVisibility(i)); chart.update(); };
|
||||
b.onmouseenter = () => { chart.setActiveElements([{ datasetIndex: 0, index: i }]); chart.update("none"); };
|
||||
b.onmouseleave = () => { chart.setActiveElements([]); chart.update("none"); };
|
||||
box.appendChild(b);
|
||||
});
|
||||
}
|
||||
|
||||
function applyRange(canvas, days) {
|
||||
const chart = Chart.getChart(canvas), d = canvas._full;
|
||||
if (!chart || !d) return;
|
||||
let from = 0;
|
||||
if (days > 0 && d.labels.length) {
|
||||
const cutoff = new Date(d.labels[d.labels.length - 1]);
|
||||
cutoff.setDate(cutoff.getDate() - days);
|
||||
from = d.labels.findIndex((l) => new Date(l) >= cutoff);
|
||||
if (from < 0) from = 0;
|
||||
}
|
||||
chart.data.labels = d.labels.slice(from);
|
||||
chart.data.datasets[0].data = d.value.slice(from);
|
||||
chart.data.datasets[1].data = d.cost.slice(from);
|
||||
chart.update();
|
||||
}
|
||||
document.addEventListener("click", (e) => {
|
||||
const b = e.target.closest("[data-range-for] button");
|
||||
if (!b) return;
|
||||
const seg = b.parentElement;
|
||||
$$("button", seg).forEach((x) => x.classList.toggle("on", x === b));
|
||||
const canvas = document.getElementById(seg.dataset.rangeFor);
|
||||
if (canvas) { canvas._days = +b.dataset.days; applyRange(canvas, canvas._days); }
|
||||
});
|
||||
|
||||
function drawCharts() {
|
||||
if (!window.Chart) return;
|
||||
Chart.defaults.font.family = getComputedStyle(document.body).fontFamily;
|
||||
Chart.defaults.color = css("--muted");
|
||||
$$("canvas[data-chart]").forEach((canvas) => {
|
||||
const build = builders[canvas.dataset.chart];
|
||||
if (!build) return;
|
||||
const chart = new Chart(canvas, build(canvas, JSON.parse(canvas.dataset.json)));
|
||||
charts.push(chart);
|
||||
if (canvas.dataset.legend) buildLegend(chart, canvas.dataset.legend);
|
||||
if (canvas.dataset.chart === "history") {
|
||||
const seg = $(`[data-range-for="${canvas.id}"] .on`);
|
||||
applyRange(canvas, canvas._days ?? (seg ? +seg.dataset.days : 0));
|
||||
}
|
||||
});
|
||||
}
|
||||
function redrawCharts() { while (charts.length) charts.pop().destroy(); drawCharts(); }
|
||||
|
||||
// ------------------------------------------------------------------ boot
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
markTheme();
|
||||
drawCharts();
|
||||
pollLive();
|
||||
setInterval(pollLive, LIVE_INTERVAL);
|
||||
document.addEventListener("visibilitychange", () => !document.hidden && pollLive());
|
||||
// follow OS theme changes live when on "auto"
|
||||
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => currentTheme() === "auto" && redrawCharts());
|
||||
});
|
||||
@@ -0,0 +1,236 @@
|
||||
/* ============================================================ theme */
|
||||
:root {
|
||||
--bg: #f4f5f9; --panel: #ffffff; --panel-2: #f8f9fc; --text: #161b26; --muted: #6b7385; --line: #e6e8ef;
|
||||
--accent: #4f46e5; --accent-2: #6366f1; --accent-soft: #eef0ff; --on-accent: #fff;
|
||||
--good: #15803d; --good-soft: #e8f6ee; --bad: #c2312f; --bad-soft: #fdecec; --warn: #b45309; --warn-soft: #fdf3e3;
|
||||
--chip: #eef0f6; --radius: 14px; --radius-sm: 9px;
|
||||
--shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.04);
|
||||
--shadow-lg: 0 10px 40px rgba(16,24,40,.12);
|
||||
--nav-w: 248px;
|
||||
color-scheme: light;
|
||||
}
|
||||
:root[data-theme=dark] {
|
||||
--bg: #0c0f16; --panel: #141923; --panel-2: #10141c; --text: #e7e9f0; --muted: #8e97aa; --line: #232a37;
|
||||
--accent: #818cf8; --accent-2: #a5b4fc; --accent-soft: #1d2140; --on-accent: #0c0f16;
|
||||
--good: #4ade80; --good-soft: #10291c; --bad: #f87171; --bad-soft: #2f1517; --warn: #fbbf24; --warn-soft: #2d230c;
|
||||
--chip: #1b2130; --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
|
||||
color-scheme: dark;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root:not([data-theme=light]) {
|
||||
--bg: #0c0f16; --panel: #141923; --panel-2: #10141c; --text: #e7e9f0; --muted: #8e97aa; --line: #232a37;
|
||||
--accent: #818cf8; --accent-2: #a5b4fc; --accent-soft: #1d2140; --on-accent: #0c0f16;
|
||||
--good: #4ade80; --good-soft: #10291c; --bad: #f87171; --bad-soft: #2f1517; --warn: #fbbf24; --warn-soft: #2d230c;
|
||||
--chip: #1b2130; --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
|
||||
color-scheme: dark;
|
||||
}
|
||||
}
|
||||
|
||||
/* ============================================================ base */
|
||||
* { box-sizing: border-box; }
|
||||
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
|
||||
body { margin: 0; font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg);
|
||||
color: var(--text); min-height: 100vh; font-feature-settings: "cv11", "ss01"; }
|
||||
a { color: var(--accent); text-decoration: none; }
|
||||
a:hover { text-decoration: underline; }
|
||||
h1 { font-size: 1.55rem; margin: 0; letter-spacing: -.02em; }
|
||||
h2 { font-size: 1rem; margin: 0 0 .9rem; letter-spacing: -.01em; display: flex; align-items: center; gap: .5rem; }
|
||||
h2 .ico { color: var(--muted); }
|
||||
code { font-size: .85em; background: var(--chip); padding: .1rem .35rem; border-radius: 5px; }
|
||||
.ico { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
|
||||
.ico.sm { width: 15px; height: 15px; vertical-align: -2px; }
|
||||
.ico.lg { width: 22px; height: 22px; }
|
||||
|
||||
/* ============================================================ sidebar */
|
||||
.layout { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh;
|
||||
background: linear-gradient(to right, var(--panel) calc(var(--nav-w) - 1px), var(--line) 0 var(--nav-w), transparent 0); }
|
||||
@media (max-width: 860px) { .layout { background: none; } }
|
||||
nav.side { background: var(--panel); border-right: 1px solid var(--line); padding: 1.1rem .85rem; position: sticky; top: 0;
|
||||
height: 100vh; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; z-index: 40; }
|
||||
.brand { display: flex; align-items: center; gap: .65rem; padding: .2rem .55rem 1.1rem; font-weight: 700; font-size: 1.08rem; letter-spacing: -.02em; }
|
||||
.brand .logo { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff;
|
||||
background: linear-gradient(135deg, #6366f1, #22c55e); box-shadow: 0 4px 14px rgba(99,102,241,.35); }
|
||||
.nav-section { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
|
||||
padding: 1rem .7rem .4rem; }
|
||||
.nav-link { position: relative; display: flex; align-items: center; gap: .75rem; padding: .55rem .7rem; border-radius: var(--radius-sm);
|
||||
color: var(--text); font-weight: 500; transition: background .15s, color .15s; }
|
||||
.nav-link .ico { color: var(--muted); transition: color .15s, transform .15s; }
|
||||
.nav-link:hover { background: var(--chip); text-decoration: none; }
|
||||
.nav-link:hover .ico { color: var(--text); transform: translateX(1px); }
|
||||
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
|
||||
.nav-link.active .ico { color: var(--accent); }
|
||||
.nav-link.active::before { content: ""; position: absolute; left: -.85rem; top: 22%; bottom: 22%; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
|
||||
.nav-count { margin-left: auto; min-width: 1.35rem; height: 1.35rem; padding: 0 .4rem; border-radius: 99px; font-size: .72rem; font-weight: 700;
|
||||
display: grid; place-items: center; background: var(--bad); color: #fff; }
|
||||
.nav-foot { margin-top: auto; padding-top: 1rem; display: flex; flex-direction: column; gap: .6rem; }
|
||||
.user-chip { display: flex; align-items: center; gap: .6rem; padding: .55rem .6rem; border-radius: var(--radius-sm); background: var(--panel-2); border: 1px solid var(--line); }
|
||||
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .85rem;
|
||||
background: var(--accent-soft); color: var(--accent); flex: none; }
|
||||
.user-chip .who { font-size: .85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.user-chip a { margin-left: auto; color: var(--muted); display: grid; place-items: center; padding: .25rem; border-radius: 6px; }
|
||||
.user-chip a:hover { background: var(--chip); color: var(--text); }
|
||||
|
||||
.theme-toggle { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 3px; }
|
||||
.theme-toggle button { background: none; border: 0; color: var(--muted); padding: .35rem; border-radius: 7px; cursor: pointer; display: grid; place-items: center; }
|
||||
.theme-toggle button:hover { color: var(--text); }
|
||||
.theme-toggle button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
|
||||
|
||||
/* mobile: top bar + bottom tabs + drawer */
|
||||
.topbar, .tabbar, .scrim { display: none; }
|
||||
@media (max-width: 860px) {
|
||||
.layout { grid-template-columns: 1fr; }
|
||||
nav.side { position: fixed; left: 0; top: 0; bottom: 0; width: 280px; transform: translateX(-102%); transition: transform .25s ease; box-shadow: var(--shadow-lg); }
|
||||
body.nav-open nav.side { transform: none; }
|
||||
.scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30; }
|
||||
body.nav-open .scrim { opacity: 1; pointer-events: auto; }
|
||||
.topbar { display: flex; align-items: center; gap: .6rem; position: sticky; top: 0; z-index: 20; padding: .6rem .9rem;
|
||||
background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
|
||||
.topbar .brand { padding: 0; font-size: 1rem; }
|
||||
.topbar .brand .logo { width: 28px; height: 28px; border-radius: 8px; }
|
||||
.icon-btn { background: none; border: 0; color: var(--text); padding: .4rem; border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
|
||||
.icon-btn:hover { background: var(--chip); }
|
||||
.tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
|
||||
background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
|
||||
padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom)); }
|
||||
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: .68rem; color: var(--muted); padding: .3rem 0; border-radius: 8px; position: relative; }
|
||||
.tabbar a:hover { text-decoration: none; }
|
||||
.tabbar a.active { color: var(--accent); font-weight: 600; }
|
||||
.tabbar a .dot-count { position: absolute; top: 0; right: calc(50% - 18px); width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
|
||||
main { padding-bottom: 5.5rem !important; }
|
||||
}
|
||||
|
||||
/* ============================================================ page */
|
||||
main { padding: 1.6rem 2.2rem 3rem; max-width: 1440px; width: 100%; min-width: 0; }
|
||||
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.3rem; }
|
||||
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: .25rem; }
|
||||
.page-head .actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
|
||||
@media (max-width: 860px) { main { padding: 1rem .8rem; } h1 { font-size: 1.3rem; } }
|
||||
|
||||
.grid { display: grid; gap: 1rem; }
|
||||
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
||||
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
||||
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
.span-2 { grid-column: span 2; }
|
||||
@media (max-width: 1150px) { .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cols-3 { grid-template-columns: 1fr 1fr; } }
|
||||
@media (max-width: 860px) { .cols-3, .cols-2 { grid-template-columns: 1fr; } .span-2 { grid-column: auto; } }
|
||||
@media (max-width: 480px) { .cols-4 { grid-template-columns: 1fr 1fr; gap: .6rem; } }
|
||||
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); min-width: 0; }
|
||||
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .9rem; flex-wrap: wrap; }
|
||||
.card-head h2 { margin: 0; }
|
||||
.mb { margin-bottom: 1rem; }
|
||||
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
|
||||
.spread { justify-content: space-between; }
|
||||
.muted { color: var(--muted); }
|
||||
.small { font-size: .85rem; }
|
||||
.right { text-align: right; }
|
||||
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
|
||||
|
||||
/* KPI tiles */
|
||||
.kpi { position: relative; overflow: hidden; }
|
||||
.kpi .label { color: var(--muted); font-size: .82rem; font-weight: 500; display: flex; align-items: center; gap: .5rem; }
|
||||
.kpi .value { font-size: 1.65rem; font-weight: 700; margin: .35rem 0 .2rem; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
|
||||
.kpi .sub { font-size: .82rem; color: var(--muted); line-height: 1.45; }
|
||||
.kpi .kpi-ico { position: absolute; top: 1rem; right: 1rem; width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; }
|
||||
.tint-accent { background: var(--accent-soft); color: var(--accent); }
|
||||
.tint-good { background: var(--good-soft); color: var(--good); }
|
||||
.tint-bad { background: var(--bad-soft); color: var(--bad); }
|
||||
.tint-warn { background: var(--warn-soft); color: var(--warn); }
|
||||
.delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; padding: .05rem .4rem; border-radius: 6px; font-size: .78rem; }
|
||||
.delta.good { background: var(--good-soft); } .delta.bad { background: var(--bad-soft); }
|
||||
@media (max-width: 480px) { .kpi .value { font-size: 1.2rem; } .kpi .kpi-ico { width: 30px; height: 30px; top: .8rem; right: .8rem; } .kpi .kpi-ico .ico { width: 15px; height: 15px; } }
|
||||
|
||||
/* tables */
|
||||
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -1.2rem; padding: 0 1.2rem; }
|
||||
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
|
||||
th, td { padding: .6rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
|
||||
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; white-space: nowrap; background: var(--panel-2); }
|
||||
thead th:first-child { border-top-left-radius: 8px; } thead th:last-child { border-top-right-radius: 8px; }
|
||||
th { border-bottom: 1px solid var(--line); }
|
||||
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||
tbody tr { transition: background .12s; }
|
||||
tbody tr:hover td { background: var(--panel-2); }
|
||||
tbody tr:last-child td { border-bottom: 0; }
|
||||
td .desc { color: var(--muted); font-size: .78rem; max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
|
||||
.tx-ico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none; }
|
||||
.cell-main { display: flex; align-items: center; gap: .7rem; min-width: 0; }
|
||||
.cell-main > div { min-width: 0; }
|
||||
|
||||
/* forms + buttons */
|
||||
input, select, textarea, button { font: inherit; color: inherit; }
|
||||
input, select, textarea { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .5rem .65rem; min-width: 0;
|
||||
transition: border-color .15s, box-shadow .15s; }
|
||||
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
|
||||
input[type=color] { padding: 2px; width: 2.4rem; height: 2.2rem; }
|
||||
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; background: var(--accent); color: var(--on-accent);
|
||||
border: 1px solid transparent; border-radius: var(--radius-sm); padding: .5rem .95rem; cursor: pointer; font-weight: 600; font-size: .9rem;
|
||||
transition: filter .15s, background .15s, transform .05s; white-space: nowrap; text-decoration: none !important; }
|
||||
button:hover, .btn:hover { filter: brightness(1.08); }
|
||||
button:active, .btn:active { transform: translateY(1px); }
|
||||
button:disabled { opacity: .6; cursor: progress; }
|
||||
button.secondary, .btn.secondary { background: var(--panel); color: var(--text); border-color: var(--line); box-shadow: var(--shadow); }
|
||||
button.secondary:hover, .btn.secondary:hover { background: var(--panel-2); filter: none; }
|
||||
button.danger, .btn.danger { background: transparent; color: var(--bad); border-color: var(--line); }
|
||||
button.danger:hover { background: var(--bad-soft); filter: none; }
|
||||
button.ghost, .btn.ghost { background: transparent; color: var(--muted); border-color: transparent; }
|
||||
button.ghost:hover, .btn.ghost:hover { background: var(--chip); color: var(--text); filter: none; }
|
||||
button.sm, .btn.sm { padding: .3rem .6rem; font-size: .8rem; border-radius: 7px; }
|
||||
button.icon, .btn.icon { padding: .4rem; }
|
||||
form.inline { display: inline; }
|
||||
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .7rem; align-items: end; }
|
||||
.form-grid label, label.f { display: flex; flex-direction: column; gap: .3rem; font-size: .8rem; color: var(--muted); font-weight: 500; }
|
||||
details > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: .5rem; }
|
||||
details > summary::-webkit-details-marker { display: none; }
|
||||
details[open] > summary { margin-bottom: .9rem; }
|
||||
td select { padding: .3rem .4rem; font-size: .82rem; max-width: 175px; }
|
||||
|
||||
/* segmented control (range buttons, filters) */
|
||||
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
|
||||
.seg button, .seg a { background: none; border: 0; color: var(--muted); padding: .28rem .65rem; border-radius: 7px; font-size: .8rem; font-weight: 600; box-shadow: none; }
|
||||
.seg button:hover, .seg a:hover { color: var(--text); filter: none; text-decoration: none; }
|
||||
.seg .on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
|
||||
|
||||
/* bits */
|
||||
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .14rem .55rem; border-radius: 99px; font-size: .72rem; font-weight: 600; background: var(--chip); color: var(--muted); white-space: nowrap; }
|
||||
.badge.bad { background: var(--bad-soft); color: var(--bad); }
|
||||
.badge.good { background: var(--good-soft); color: var(--good); }
|
||||
.badge.warn { background: var(--warn-soft); color: var(--warn); }
|
||||
.badge.accent { background: var(--accent-soft); color: var(--accent); }
|
||||
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 3px; margin-right: .45rem; vertical-align: middle; flex: none; }
|
||||
.flash { display: flex; align-items: center; gap: .6rem; background: var(--accent-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
|
||||
padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
|
||||
.flash .ico { color: var(--accent); }
|
||||
.alert { border: 1px solid color-mix(in srgb, var(--bad) 35%, var(--line)); background: linear-gradient(90deg, var(--bad-soft), var(--panel) 60%); }
|
||||
.alert h2 { color: var(--bad); }
|
||||
.progress { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; }
|
||||
.progress > div { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--good), color-mix(in srgb, var(--good) 70%, #22d3ee)); transition: width .6s ease; }
|
||||
.list { list-style: none; margin: 0; padding: 0; }
|
||||
.list li { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
|
||||
.list li:last-child { border-bottom: 0; }
|
||||
.list li .num, .list li > span:last-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
|
||||
.list a.cat { color: var(--text); display: flex; align-items: center; min-width: 0; }
|
||||
.list .bar { height: 4px; border-radius: 4px; background: var(--chip); margin-top: 5px; overflow: hidden; }
|
||||
.list .bar > div { height: 100%; border-radius: 4px; }
|
||||
.pager { display: flex; gap: .5rem; align-items: center; justify-content: center; margin-top: 1rem; }
|
||||
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
|
||||
.empty .ico { width: 34px; height: 34px; opacity: .5; margin-bottom: .4rem; }
|
||||
|
||||
/* charts */
|
||||
.chart-box { position: relative; height: 290px; }
|
||||
.chart-box.sm { height: 230px; }
|
||||
.chart-box.tall { height: 330px; }
|
||||
.donut-wrap { display: grid; grid-template-columns: minmax(0, 1fr); gap: .8rem; }
|
||||
.legend { display: flex; flex-direction: column; gap: .25rem; max-height: 210px; overflow-y: auto; }
|
||||
.legend button { display: flex; align-items: center; gap: .5rem; background: none; border: 0; padding: .3rem .4rem; border-radius: 7px; color: var(--text); font-weight: 500; font-size: .84rem; text-align: left; box-shadow: none; justify-content: flex-start; }
|
||||
.legend button:hover { background: var(--chip); filter: none; }
|
||||
.legend button.off { opacity: .4; text-decoration: line-through; }
|
||||
.legend button .v { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
|
||||
|
||||
/* live numbers */
|
||||
@keyframes flashUp { from { background: color-mix(in srgb, var(--good) 30%, transparent); } to { background: transparent; } }
|
||||
@keyframes flashDown { from { background: color-mix(in srgb, var(--bad) 30%, transparent); } to { background: transparent; } }
|
||||
.flash-up { animation: flashUp 1.6s ease-out; border-radius: 4px; }
|
||||
.flash-down { animation: flashDown 1.6s ease-out; border-radius: 4px; }
|
||||
.live-status { display: inline-flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--muted); white-space: nowrap; }
|
||||
.live-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); animation: pulse 2s infinite; }
|
||||
@keyframes pulse { 50% { box-shadow: 0 0 0 6px transparent; } }
|
||||
.live-status:empty { display: none; }
|
||||
Reference in New Issue
Block a user