<?php
declare(strict_types=1);
$toolName     = 'discrepancy';
$toolTitle    = 'Discrepancy Finder';
$toolKind     = 'Document comparison';
$toolBadge    = 'Cross-document AI';
$extraScripts = ['assets/js/discrepancy.js'];
require_once __DIR__ . '/includes/layout.php';
?>
                <form id="dcForm" class="tool-form deep-research" enctype="multipart/form-data">

                    <div class="lang-switcher" id="dcLangSwitcher" role="group" aria-label="UI language">
                        <button type="button" class="lang-btn is-active" data-lang="en">&#127468;&#127463; EN</button>
                        <button type="button" class="lang-btn" data-lang="no">&#127475;&#127476; NO</button>
                        <button type="button" class="lang-btn" data-lang="uk">&#127482;&#127462; UK</button>
                        <button type="button" class="lang-btn" data-lang="pl">&#127477;&#127473; PL</button>
                    </div>

                    <p class="upload-hint" style="margin-bottom:1.2rem">Upload two versions of the same Barnevernet document &mdash; or any two related documents &mdash; and the agent will find contradictions, deleted facts, new allegations, and party changes between them. Results include corpus-backed legal significance for each discrepancy.</p>

                    <!-- Two upload zones side by side -->
                    <div class="dc-upload-pair">

                        <div class="dc-upload-slot">
                            <p class="control-label">Document A <span class="dc-slot-hint">&mdash; Earlier / Original</span></p>
                            <div class="upload-zone dc-zone" id="dcZoneA" role="region" aria-label="Document A upload">
                                <input type="file" id="dcInputA" accept=".pdf,.docx,.txt" aria-label="Choose Document A">
                                <div id="dcPromptA" class="upload-prompt">
                                    <span class="upload-icon" aria-hidden="true">&#8679;</span>
                                    <p>Drop here or <label for="dcInputA" class="upload-browse">browse</label></p>
                                    <p class="upload-hint"><strong>PDF</strong>, <strong>DOCX</strong>, <strong>TXT</strong> &mdash; max 8 MB</p>
                                </div>
                                <div id="dcFileInfoA" class="upload-file is-hidden">
                                    <span id="dcFileNameA" class="upload-filename"></span>
                                    <button type="button" id="dcClearA" class="upload-clear">&times;</button>
                                </div>
                            </div>
                        </div>

                        <div class="dc-upload-slot">
                            <p class="control-label">Document B <span class="dc-slot-hint">&mdash; Later / Comparison</span></p>
                            <div class="upload-zone dc-zone" id="dcZoneB" role="region" aria-label="Document B upload">
                                <input type="file" id="dcInputB" accept=".pdf,.docx,.txt" aria-label="Choose Document B">
                                <div id="dcPromptB" class="upload-prompt">
                                    <span class="upload-icon" aria-hidden="true">&#8679;</span>
                                    <p>Drop here or <label for="dcInputB" class="upload-browse">browse</label></p>
                                    <p class="upload-hint"><strong>PDF</strong>, <strong>DOCX</strong>, <strong>TXT</strong> &mdash; max 8 MB</p>
                                </div>
                                <div id="dcFileInfoB" class="upload-file is-hidden">
                                    <span id="dcFileNameB" class="upload-filename"></span>
                                    <button type="button" id="dcClearB" class="upload-clear">&times;</button>
                                </div>
                            </div>
                        </div>

                    </div>

                    <div class="control-row" id="dcEngineControl">
                        <span class="control-label">Engine</span>
                        <label><input type="radio" name="dcEngine" value="azure_mini" checked> Azure gpt-4o-mini &#9733; <small class="control-hint">(~60-90s)</small></label>
                        <label><input type="radio" name="dcEngine" value="azure_full"> Azure gpt-4o <small class="control-hint">(best · ~2-3 min)</small></label>
                        <label><input type="radio" name="dcEngine" value="gpu"> GPU qwen2.5:14b <small class="control-hint">(local · ~90s)</small></label>
                        <label><input type="radio" name="dcEngine" value="dbn_legal_v3"> &#x1F1F3;&#x1F1F4; Norwegian specialist v3 &#9733; <small class="control-hint">(dbn-legal-agent-v3 · ~30-60s)</small></label>
                    </div>
                    <p class="upload-hint">Engine applies to the final synthesis only. Norwegian specialist v3 excels at identifying legally significant discrepancies in Barnevernet documents — procedural violations, threshold errors, and missing statutory justifications. Classification, party extraction, timelines, and cross-referencing always use azure-mini.</p>

                    <details class="advanced-panel" id="dcSlicePanel">
                        <summary class="advanced-toggle">Corpus slices <span class="control-hint">(used for legal significance context)</span></summary>
                        <p class="upload-hint" style="margin:8px 0">The corpus provides legal significance context for each discrepancy found. All four default slices cover the core Barnevernet framework.</p>
                        <div class="dr-slice-grid">
                            <button type="button" class="adv-slice is-on" data-slice="child_welfare" aria-pressed="true">
                                <div class="dr-slice__head">
                                    <span class="dr-slice__title">Child Welfare</span>
                                    <span class="dr-slice__badge">on</span>
                                </div>
                                <p class="dr-slice__tagline">Barnevern, omsorgsovertakelse, foster care</p>
                            </button>
                            <button type="button" class="adv-slice is-on" data-slice="echr" aria-pressed="true">
                                <div class="dr-slice__head">
                                    <span class="dr-slice__title">ECHR</span>
                                    <span class="dr-slice__badge">on</span>
                                </div>
                                <p class="dr-slice__tagline">Art.&nbsp;8 family life, procedural fairness, HUDOC vs Norway</p>
                            </button>
                            <button type="button" class="adv-slice is-on" data-slice="family_core" aria-pressed="true">
                                <div class="dr-slice__head">
                                    <span class="dr-slice__title">Family Law Core</span>
                                    <span class="dr-slice__badge">on</span>
                                </div>
                                <p class="dr-slice__tagline">Barneloven, custody, samvær, mediation</p>
                            </button>
                            <button type="button" class="adv-slice is-on" data-slice="bufdir_guidance" aria-pressed="true">
                                <div class="dr-slice__head">
                                    <span class="dr-slice__title">Bufdir Guidance</span>
                                    <span class="dr-slice__badge">on</span>
                                </div>
                                <p class="dr-slice__tagline">Bufdir, Barneombudet, Statsforvalteren standards</p>
                            </button>
                            <button type="button" class="adv-slice" data-slice="norwegian_courts" aria-pressed="false">
                                <div class="dr-slice__head">
                                    <span class="dr-slice__title">Norwegian Courts</span>
                                    <span class="dr-slice__badge">off</span>
                                </div>
                                <p class="dr-slice__tagline">Høyesterett + Lagmannsrett family decisions</p>
                            </button>
                            <button type="button" class="adv-slice" data-slice="broader_legal" aria-pressed="false">
                                <div class="dr-slice__head">
                                    <span class="dr-slice__title">Broader Legal</span>
                                    <span class="dr-slice__badge">off</span>
                                </div>
                                <p class="dr-slice__tagline">NOUer, statutes, government background</p>
                            </button>
                        </div>
                    </details>

                    <div class="form-footer">
                        <p id="dcStatus" class="form-status" role="status" aria-live="polite"></p>
                        <button id="dcRunButton" type="submit">Find discrepancies</button>
                    </div>
                </form>

                <section id="dcResults" class="results deep-research-results" aria-live="polite">
                    <div class="empty-state">
                        <h3>Ready</h3>
                        <p>Upload two Barnevernet documents, then run. The agent will classify each document, extract parties and timelines, cross-reference them for discrepancies, and produce a corpus-backed legal significance report.</p>
                        <p class="upload-hint" style="margin-top:8px">Typical use: compare the original Bekymringsmelding against the later Vedtak, or compare two versions of a Barnevernet investigation report.</p>
                    </div>
                </section>

                <!-- Source modal -->
                <div id="dcSourceModal" class="dr-source-modal is-hidden" role="dialog" aria-modal="true" aria-labelledby="dcSourceModalTitle">
                    <div class="dr-source-modal__dialog">
                        <header class="dr-source-modal__head">
                            <div>
                                <p class="eyebrow" id="dcSourceModalEyebrow">Source</p>
                                <h3 id="dcSourceModalTitle"></h3>
                            </div>
                            <button type="button" id="dcSourceModalClose" class="upload-clear" aria-label="Close">&times;</button>
                        </header>
                        <div class="dr-source-modal__body">
                            <aside class="dr-source-modal__meta" id="dcSourceModalMeta"></aside>
                            <div class="dr-source-modal__text" id="dcSourceModalText"></div>
                        </div>
                    </div>
                </div>

                <!-- Hidden stubs so tools.js element refs don't crash on this page -->
                <div class="is-hidden" id="languageControl" aria-hidden="true">
                    <input type="radio" name="language" value="en" checked>
                    <input type="radio" name="language" value="no">
                    <input type="radio" name="language" value="uk">
                    <input type="radio" name="language" value="pl">
                </div>
                <div class="is-hidden" id="redactionControl" aria-hidden="true"></div>
                <div class="is-hidden" id="audioZone" aria-hidden="true">
                    <input type="file" id="audioInput" style="display:none">
                    <div id="audioPrompt"></div>
                    <div id="audioFileInfo"><ol id="audioQueueList"></ol><button type="button" id="audioClear"></button></div>
                </div>
                <div class="is-hidden" id="diarizeControl" aria-hidden="true">
                    <input type="checkbox" id="diarizeCheck">
                    <input type="number" id="numSpeakersInput">
                </div>
                <div class="is-hidden" id="transcribeLangControl" aria-hidden="true"><input type="radio" name="transcribeLang" value="no" checked></div>
                <div class="is-hidden" id="vocabControl" aria-hidden="true">
                    <div id="vocabPresets"></div>
                    <textarea id="initPromptInput"></textarea>
                </div>
                <div class="is-hidden" id="aliasSection" aria-hidden="true">
                    <button type="button" id="addAliasRow"></button>
                    <div id="aliasRows"></div>
                </div>
                <div class="is-hidden" id="exemptSection" aria-hidden="true">
                    <button type="button" id="addExemptRow"></button>
                    <div id="exemptRows"></div>
                </div>
<?php require_once __DIR__ . '/includes/layout_footer.php'; ?>
