<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spanish Inheritance Tax Forecaster | ABAD Abogados</title>
    <!-- Load Tailwind CSS -->
    <script src="https://cdn.tailwindcss.com"></script>
    <style>
        /* Custom styles to refine the slider and input appearance */
        body { font-family: 'Inter', sans-serif; background-color: #f7f7f7; }
        .card { box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 0 10px rgba(0, 0, 0, 0.04); }
        input[type="range"] {
            -webkit-appearance: none;
            appearance: none;
            width: 100%;
            height: 8px;
            background: #e0e0e0;
            outline: none;
            opacity: 0.9;
            transition: opacity .2s;
            border-radius: 4px;
        }
        input[type="range"]::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 20px;
            height: 20px;
            background: #0D47A1; /* ABAD Primary Blue */
            cursor: pointer;
            border-radius: 50%;
            border: 3px solid #f7f7f7;
        }
    </style>
</head>
<body class="p-4 sm:p-8 flex items-center justify-center min-h-screen bg-gray-50">

    <div id="forecaster-app" class="card w-full max-w-4xl bg-white rounded-xl overflow-hidden shadow-2xl">
        
        <!-- Header Section -->
        <div class="p-6 sm:p-8 bg-blue-700 text-white">
            <h1 class="text-3xl sm:text-4xl font-extrabold mb-1">🇪🇸 Regional Tax Forecaster</h1>
            <h2 class="text-xl font-light">See your estimated Inheritance Tax liability in Murcia & Valencia.</h2>
        </div>

        <!-- Calculator Section -->
        <div class="p-6 sm:p-8 md:flex md:space-x-8">
            <!-- Input Column (Left) -->
            <div id="input-column" class="md:w-1/2 space-y-6">
                
                <h3 class="text-2xl font-semibold text-gray-800 border-b pb-2 mb-4">1. Your Spanish Estate Details</h3>

                <!-- Asset Value Slider -->
                <div class="space-y-2">
                    <label for="assetValue" class="block text-sm font-medium text-gray-700">Total Spanish Asset Value (€)</label>
                    <input type="range" id="assetValue" min="100000" max="1000000" step="50000" value="300000" oninput="updateCalculation()">
                    <div class="flex justify-between text-sm text-gray-600">
                        <span>€100k</span>
                        <span id="valueDisplay" class="font-bold text-lg text-blue-700">€300,000</span>
                        <span>€1M+</span>
                    </div>
                </div>

                <!-- Asset Location Dropdown -->
                <div>
                    <label for="assetLocation" class="block text-sm font-medium text-gray-700">Property Location (The Tax Decider)</label>
                    <select id="assetLocation" onchange="updateCalculation()" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md shadow-sm">
                        <option value="Murcia">Murcia Region (99% Relief)</option>
                        <option value="Valencia/Alicante">Valencia/Alicante (99% Relief + €100k Allowance)</option>
                        <option value="Other">Other Region (High Tax Estimate)</option>
                    </select>
                </div>

                <!-- Beneficiary Relationship Dropdown -->
                <div>
                    <label for="relationship" class="block text-sm font-medium text-gray-700">Relationship to Deceased</label>
                    <select id="relationship" onchange="updateCalculation()" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md shadow-sm">
                        <option value="Spouse">Spouse or Registered Partner (Group II)</option>
                        <option value="Child">Child or Descendant (Group I/II)</option>
                        <option value="Step-Child">Step-Child or Sibling (Group III - High Risk)</option>
                        <option value="Unrelated">Unrelated Person (Group IV - Highest Tax)</option>
                    </select>
                </div>
                
                <!-- Heir Residency Status Dropdown -->
                <div>
                    <label for="residency" class="block text-sm font-medium text-gray-700">Heir's Current Residency Status</label>
                    <select id="residency" onchange="updateCalculation()" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md shadow-sm">
                        <option value="Spain">Resident in Spain</option>
                        <option value="UK/EU">Resident in UK/EU</option>
                        <option value="Non-EU">Non-Resident outside EU/UK (NIE Required)</option>
                    </select>
                </div>

            </div>
            
            <!-- Result and Gated Form Column (Right) -->
            <div id="result-column" class="md:w-1/2 mt-8 md:mt-0 space-y-6">
                
                <h3 class="text-2xl font-semibold text-gray-800 border-b pb-2 mb-4">2. Your Estimated Tax & Risk</h3>

                <!-- Estimated Tax Display -->
                <div class="bg-blue-50 border-4 border-blue-200 p-4 sm:p-6 rounded-lg text-center shadow-inner">
                    <p class="text-sm font-medium text-gray-600 mb-1">Estimated Inheritance Tax Bill</p>
                    <p id="taxResult" class="text-5xl font-extrabold text-blue-800">€X,XXX</p>
                    <p id="riskMessage" class="text-sm mt-3 font-semibold"></p>
                </div>

                <!-- Gated Lead Capture Form -->
                <div id="gatedForm" class="bg-red-50 border border-red-300 p-4 sm:p-6 rounded-lg space-y-4">
                    <h4 class="text-xl font-bold text-red-700 text-center">Unlock Your Full Customised Report Now</h4>
                    <p class="text-sm text-gray-700 text-center">Submit your details to receive the **"2025 Inheritance Action Plan"** PDF, showing how to secure this estimated saving and bypass forced heirship.</p>
                    
                    <!-- Simulating a GHL Form for the lead capture -->
                    <form id="leadCaptureForm" action="javascript:void(0)" class="space-y-3">
                        <input type="email" placeholder="Email (Required for Report)" required class="w-full p-2 border border-gray-300 rounded-md">
                        <input type="text" placeholder="First Name" required class="w-full p-2 border border-gray-300 rounded-md">
                        <input type="tel" placeholder="Phone Number" class="w-full p-2 border border-gray-300 rounded-md">
                        
                        <!-- Hidden fields to capture calculation results -->
                        <input type="hidden" id="hiddenAssetValue" name="AssetValue">
                        <input type="hidden" id="hiddenTaxResult" name="TaxResult">
                        <input type="hidden" id="hiddenRisk" name="RiskMessage">
                        
                        <button type="submit" class="w-full bg-red-600 hover:bg-red-700 text-white font-bold py-3 rounded-lg shadow-lg transition duration-150">
                            YES, SEND MY FREE ACTION PLAN
                        </button>
                        <p class="text-xs text-center text-gray-500">We specialize in Murcia, Alicante, and Valencia. Your data is confidential.</p>
                    </form>
                </div>
            </div>
        </div>

        <!-- Footer / Authority Section -->
        <div class="p-4 sm:p-6 bg-gray-100 border-t text-center text-sm text-gray-600">
            <p class="font-semibold text-blue-800">Expert Guidance from ABAD Abogados</p>
            <p>Authored by specialists serving British expats in Murcia, Alicante, and Valencia since 1996.</p>
        </div>

    </div>

    <script>
        // --- CORE TAX CALCULATION LOGIC ---

        // This function simulates the tax calculation based on the known regional rules (99% bonification).
        // It uses simple math for demonstration but relies on the user input for the regional advantage logic.
        function calculateEstimatedTax() {
            const assetValue = parseInt(document.getElementById('assetValue').value);
            const location = document.getElementById('assetLocation').value;
            const relationship = document.getElementById('relationship').value;
            const residency = document.getElementById('residency').value;
            
            // --- CONSTANTS ---
            // Simplified Base Tax: Uses a fixed rate (e.g., 18%) for a large estate to show the *gross* liability before discounts.
            const BASE_RATE = 0.18; 
            const STATE_TAX_GROSS = assetValue * BASE_RATE; 

            let bonification = 0;
            let resultMessage = "This estimate is based on the region's current rules.";
            let taxCategory = '';

            // --- STEP 1: Determine Tax Group and Apply Base Bonification (99% for Close Family) ---
            if (relationship === 'Spouse' || relationship === 'Child') {
                taxCategory = 'Group I/II (Close Family)';
                
                if (location === 'Murcia' || location === 'Valencia/Alicante') {
                    // Murcia/Valencia/Alicante: 99% reduction for Group I/II is the key saving.
                    bonification = 0.99; 
                    resultMessage = "Great News! Your family should qualify for the **99% Regional Tax Reduction** in this area.";
                } else {
                    // 'Other' High Tax Region: Assume 50% bonification for 'Other' to show a medium-high bill.
                    bonification = 0.50; 
                    resultMessage = "Warning: In non-preferred regions, tax could be significantly higher (estimate based on 50% discount).";
                }
            } else if (relationship === 'Step-Child') {
                taxCategory = 'Group III (High Risk)';
                // Step-children are Group III (Siblings/Nieces/Nephews) unless adopted or registered as Pareja de Hecho.
                bonification = 0;
                resultMessage = "Immediate Warning: Step-children/siblings are high-risk (Group III) and usually pay **full State Tax** with minimal relief. Immediate planning is vital.";
            } else {
                taxCategory = 'Group IV (Highest Tax)';
                // Unrelated persons are Group IV, facing high rates and high coefficients.
                bonification = 0;
                resultMessage = "Extreme Warning: Unrelated heirs (Group IV) face the highest tax coefficients (up to 2.4x the base rate). This is a crisis situation.";
            }
            
            // --- STEP 2: Calculate Final Tax ---
            let taxDue = 0;

            if (taxCategory === 'Group I/II (Close Family)') {
                 // Tax is the remaining 1% of the gross liability (due to 99% bonification)
                taxDue = STATE_TAX_GROSS * (1 - bonification);
                
                // Add a small extra fee to show it's not exactly zero (e.g., 500 Euro fixed fee for minimal paperwork)
                taxDue = taxDue > 1000 ? taxDue : 500; 

            } else if (taxCategory === 'Group III (High Risk)') {
                // If no bonification, they pay much closer to the full state rate.
                taxDue = STATE_TAX_GROSS * 1.5; // Multiply by 1.5 to reflect the higher Group III multiplier
                resultMessage += " The estimated bill is inflated by high multiplier coefficients.";
            } else if (taxCategory === 'Group IV (Highest Tax)') {
                taxDue = STATE_TAX_GROSS * 2.0; // Multiply by 2.0 to reflect the highest Group IV multiplier
                resultMessage += " The estimated bill is inflated by high multiplier coefficients.";
            } else {
                taxDue = 0; // Fallback
            }

            // --- STEP 3: Check for Non-Resident/Deadline Risk (NIE Bottleneck) ---
            if ((residency === 'UK/EU' || residency === 'Non-EU') && (relationship === 'Child' || relationship === 'Step-Child' || relationship === 'Unrelated')) {
                resultMessage += " **CRITICAL RISK:** As a non-resident heir, obtaining the NIE number within the 6-month tax deadline is the biggest challenge. **Action required now.**";
            }
            
            // --- STEP 4: Format and Output ---
            const formattedTax = `€${Math.round(taxDue).toLocaleString()}`;
            
            // Update display elements
            document.getElementById('valueDisplay').textContent = `€${assetValue.toLocaleString()}`;
            document.getElementById('taxResult').textContent = formattedTax;
            document.getElementById('riskMessage').innerHTML = resultMessage;

            // Update hidden fields for GHL data capture (if the form was a GHL component)
            document.getElementById('hiddenAssetValue').value = assetValue;
            document.getElementById('hiddenTaxResult').value = formattedTax;
            document.getElementById('hiddenRisk').value = resultMessage.replace(/<[^>]*>?/gm, ''); // Remove HTML tags for GHL
        }

        // Initialize calculation on load
        window.onload = function() {
            updateCalculation();
            
            // Handle form submission (Simulate GHL webhook/submission)
            document.getElementById('leadCaptureForm').onsubmit = function(event) {
                event.preventDefault();
                const form = event.target;
                const email = form.querySelector('input[type="email"]').value;
                
                // Final confirmation message (simulating the GHL Thank You page logic)
                document.getElementById('forecaster-app').innerHTML = `
                    <div class="p-12 text-center bg-white rounded-xl">
                        <svg class="mx-auto h-16 w-16 text-green-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
                        </svg>
                        <h3 class="mt-4 text-2xl font-semibold text-gray-900">Success! Your Report is on the Way.</h3>
                        <p class="mt-2 text-lg text-gray-600">The <strong>"2025 Inheritance Action Plan"</strong> PDF has been sent to <strong>${email}</strong>.</p>
                        <p class="mt-4 text-xl font-bold text-red-700">Immediate Next Step:</p>
                        <p class="text-gray-700">Don't wait for the crisis. Schedule your free 30-minute review with Professor Abad's team now to secure your estimated savings and bypass forced heirship.</p>
                        <a href="#" class="mt-6 inline-flex items-center px-6 py-3 border border-transparent text-base font-medium rounded-md shadow-sm text-white bg-blue-700 hover:bg-blue-800 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
                            Book Your Free Strategy Call
                        </a>
                    </div>
                `;
            };
        };

        // Bind the calculation function to input changes
        const inputs = document.querySelectorAll('#input-column input, #input-column select');
        inputs.forEach(input => {
            input.addEventListener('input', updateCalculation);
            input.addEventListener('change', updateCalculation);
        });

    </script>
</body>
</html>