# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## What this is

A single self-contained HTML file — `Evidenta_rapoarte_si_emitere_raport_daune_V7_toni__Ciprian_Momenta final pentru Ireene.html` (~27,500 lines) — that is the whole app. There is no build step, no dependency manager, no server code here: open the file in a browser and it runs. All third-party libraries (docx.js, JSZip, PDFLib) are vendored inline as minified/bundled `<script>` blocks in the middle of the file, so line numbers in the "business logic" sections jump by tens of thousands around them.

This is a standalone prototype tool, separate from the `admin.dtaclaims.ro` / `public_html` PHP app that lives one directory up (`../CLAUDE.md` documents that system) — it is the kind of throwaway tool the parent repo's `shared/calc_helpers.php` was ported *from* ("Calculatie Bunuri" started life exactly like this: a standalone single-file prototype later integrated into the PHP app). Treat this file as independent unless told otherwise.

## Architecture (all in one file)

- **`<style>` block** (top of file) — all CSS, custom-property based theme (`--bg`, `--accent`, etc.), tab/page navigation styling.
- **Vendored libraries** (~line 6000–24380) — bundled copies of docx.js, JSZip, PDFLib, exposed as `window.docx`, `window.JSZip`, `window.PDFLib`. Don't hand-edit these; if a library needs updating, replace the whole bundled block.
- **App logic** (~line 24880 onward) — everything after the vendored libraries. Key pieces:
  - `SUPA_URL` / `SUPA_KEY` (~line 24891) — Supabase project used as the backing store. `SUPA_KEY` is the public/anon `sb_publishable_...` key (safe to be client-side).
  - `api(path, options)` (~line 25154) — thin wrapper over `fetch(SUPA_URL + '/rest/v1/' + path, ...)` using PostgREST syntax (e.g. `dosare?select=*&order=adaugat_la.desc`). All persistence goes through this. The main table is `dosare`; case-type metadata lives in a `tipuri_dosar` table that the app tolerates being absent (falls back to a hardcoded default list — see comments around line 24949).
  - `showPage(id)` — simple tab/page switcher (`.page.active` / `.tab.active`), not a router; page ids referenced via `data-page` attributes and `#page-{id}` elements.
  - CRUD flow for records: `adauga()` (create), `deschideEdit()` / `salveazaEdit()` (edit), `sterge()` (delete), `renderEvidenta()` (re-render the table), `updateStats()`.
  - PV (proces verbal) import + AI extraction: `importaPdfPV()` parses an uploaded PDF via `PDFLib`, `analizeazaPVcuAI()` calls `apelAnthropicAPI()` (~line 25922) which hits `https://api.anthropic.com/v1/messages` directly from the browser using an API key the user is prompted for at runtime (`cereCheieAPI()`) and never stored in the file itself.
  - Report generation: `genereazaRaport()` builds the on-screen report from form + Supabase data; `descarcaWord()` (~line 26929) exports it as a `.docx` via the vendored `docx.js`; photo/annex handling (`adaugaFoto`, `getAnexeHTML`, `toggleAnexa`) attaches images as report annexes.
  - CSV export: `exportCSV()` / `exportLunaCSV()`.

## Working in this file

- There's no test suite, linter, or build command — the only way to verify a change is to open the HTML file directly in a browser and exercise the UI.
- Because it's one file with a giant embedded-library section in the middle, avoid reading large line ranges blindly — grep/search for the function or identifier you need first, then read a narrow range around it. A few lines (embedded base64 assets) are extremely long and can blow out a read on their own.
- Keep edits scoped to the app-logic section (after the vendored libraries) unless the task explicitly involves the bundled libraries themselves.
