feat: comprehensive design system overhaul

Applied impeccable design critique, audit, harden, layout, distill, and polish across all pages.

DESIGN SYSTEM:
- Created PRODUCT.md (5 design principles, WCAG 2.1 AA target)
- Created DESIGN.md (34 color tokens, 6 radius scale, full component spec)
- Created .impeccable/design.json (sidecar with tonal ramps, shadows, motion)

ACCESSIBILITY:
- 33 aria-labels across 7 pages (was ~13)
- 63 <label> elements (was ~30)
- 6 <main> landmarks + role=navigation on all sidebars
- Esc to close modals on 4 pages
- Keyboard shortcuts (Ctrl+J/K, Ctrl+F) on chat

THEMING:
- 216 hardcoded colors replaced with var() references
- 449 !important removed from dark-mode.css
- Dark mode script unified (was duplicated 9x inline)
- All modals converted to .modal-overlay + .modal design system classes

CHAT:
- Error states for messages (.msg.erro, .msg.enviando)
- Connection status indicator
- Confirmation modal before finalizar
- Input bar reorganized (3 visible actions, + menu)
- Right panel accordions
- Send button disabled when empty
- Touch targets 44px on mobile

CLIENT DETAIL:
- Tabs/badges/sub-tabs use CSS classes instead of inline styles
- 'Iniciar Conversa' button now primary action
- alert() replaced with inline feedback
- Modal converted to design system classes

CLIENT LIST:
- Modal moved inside <body> (was HTML-invalid)
- alert() replaced with inline feedback
- Modal uses .show pattern

SETTINGS:
- 4 modals converted to design system classes
- 14 alert() calls replaced with inline feedback
- fecharModal() uses classList instead of style.display

ROUTES:
- border-radius normalized, hardcoded colors fixed

Score progression:
  Chat:        23 → 32/40
  Client List: 32 → 35/40
  Client Detail: 26 → 30/40
  Settings:     29 → 35/40
  Routes:       37 → 38/40
  Audit (project): 14/20 → 17/20
This commit is contained in:
2026-06-23 16:58:12 +00:00
parent cf720c37a1
commit 12d419de7c
113 changed files with 52423 additions and 951 deletions
@@ -0,0 +1,152 @@
/**
* Shared helpers for the pending-manual-edits buffer on disk.
*
* Location: .impeccable/live/pending-manual-edits.json (project-local).
* Schema: { version: 1, entries: [{ id, pageUrl, element, ops, stagedAt }] }
*
* Each entry corresponds to one Save action from the browser. Ops merge by
* (pageUrl, ref): if the user re-edits the same element before committing, the
* existing entry's `newText` is replaced and `originalText` is kept (it holds
* the real source state).
*/
import fs from 'node:fs';
import path from 'node:path';
import { getLiveDir } from '../lib/impeccable-paths.mjs';
const BUFFER_VERSION = 1;
const BUFFER_FILENAME = 'pending-manual-edits.json';
export function getBufferPath(cwd = process.cwd()) {
return path.join(getLiveDir(cwd), BUFFER_FILENAME);
}
export function readBuffer(cwd = process.cwd()) {
return readBufferInternal(cwd, { strict: false });
}
export function readBufferStrict(cwd = process.cwd()) {
return readBufferInternal(cwd, { strict: true });
}
function readBufferInternal(cwd, { strict }) {
const filePath = getBufferPath(cwd);
try {
const raw = fs.readFileSync(filePath, 'utf-8');
const parsed = JSON.parse(raw);
if (!parsed || typeof parsed !== 'object' || !Array.isArray(parsed.entries)) {
if (strict) throw new Error('manual_edit_buffer_invalid_schema');
return { version: BUFFER_VERSION, entries: [] };
}
return { version: BUFFER_VERSION, entries: parsed.entries };
} catch (err) {
if (strict && err?.code !== 'ENOENT') {
throw new Error('manual_edit_buffer_unreadable: ' + (err.message || String(err)));
}
return { version: BUFFER_VERSION, entries: [] };
}
}
export function writeBuffer(cwd, buffer) {
const filePath = getBufferPath(cwd);
fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, JSON.stringify({ version: BUFFER_VERSION, entries: buffer.entries }, null, 2));
}
/**
* Merge a new entry into the buffer. For each op in the new entry, if there's
* already a buffered op for the same (pageUrl, ref), update that op's newText
* and keep its original originalText (the true source state). Otherwise add
* the op (creating an entry if needed).
*
* Multiple ops in one Save are allowed; each is keyed by (pageUrl, ref).
*/
export function stageEntry(cwd, newEntry) {
const buf = readBufferStrict(cwd);
const pageUrl = newEntry.pageUrl;
for (const newOp of newEntry.ops) {
let mergedIntoExisting = false;
for (const existing of buf.entries) {
if (existing.pageUrl !== pageUrl) continue;
const existingOpIdx = existing.ops.findIndex((op) => op.ref === newOp.ref);
if (existingOpIdx >= 0) {
// Keep the original source text but refresh the latest DOM/source evidence.
existing.ops[existingOpIdx] = {
...newOp,
originalText: existing.ops[existingOpIdx].originalText,
newText: newOp.newText,
deleted: newOp.deleted || false,
};
if (newEntry.element) existing.element = newEntry.element;
existing.stagedAt = new Date().toISOString();
mergedIntoExisting = true;
break;
}
}
if (mergedIntoExisting) continue;
// No existing op for this (pageUrl, ref). Find or create an entry to hold it.
let entry = buf.entries.find((e) => e.pageUrl === pageUrl && e.id === newEntry.id);
if (!entry) {
entry = {
id: newEntry.id,
pageUrl,
element: newEntry.element,
ops: [],
stagedAt: new Date().toISOString(),
};
buf.entries.push(entry);
}
entry.ops.push(newOp);
entry.stagedAt = new Date().toISOString();
}
writeBuffer(cwd, buf);
return buf;
}
/**
* Remove entries matching a predicate. Returns count of removed *ops* (not
* entries) so callers report a unit consistent with truncateBuffer and the
* pill's per-page op count. Empty entries (no ops left) are also pruned.
*/
export function removeEntries(cwd, predicate) {
const buf = readBuffer(cwd);
let removedOps = 0;
const kept = [];
for (const entry of buf.entries) {
if (predicate(entry)) {
removedOps += entry.ops?.length || 0;
} else if (entry.ops && entry.ops.length > 0) {
kept.push(entry);
}
}
buf.entries = kept;
writeBuffer(cwd, buf);
return removedOps;
}
/**
* Count by page for the counter UI. Returns { totalCount, perPage: {[pageUrl]: count} }.
*/
export function countByPage(cwd = process.cwd()) {
const buf = readBuffer(cwd);
const perPage = {};
let totalCount = 0;
for (const entry of buf.entries) {
const n = entry.ops.length;
perPage[entry.pageUrl] = (perPage[entry.pageUrl] || 0) + n;
totalCount += n;
}
return { totalCount, perPage };
}
/**
* Truncate the buffer to empty (used by discard-all). Returns the count of
* removed ops.
*/
export function truncateBuffer(cwd) {
const buf = readBuffer(cwd);
let removed = 0;
for (const entry of buf.entries) removed += entry.ops.length;
writeBuffer(cwd, { version: BUFFER_VERSION, entries: [] });
return removed;
}