#!/usr/bin/env python3
"""
Check what's inside the inner page (csm-certification-training.php)
that causes CSS distortion.
Look for:
1. Duplicate JS/CSS loads
2. Inline styles causing overflow:hidden
3. Missing closing tags
"""
import re

page = '/Applications/XAMPP/xamppfiles/htdocs/aaa/agile-management/csm-certification-training.php'
with open(page, 'r', encoding='utf-8', errors='ignore') as f:
    content = f.read()

print(f"Page size: {len(content)} bytes")

# Check for duplicate script loads
scripts = re.findall(r'<script[^>]*src=["\'][^"\']+["\'][^>]*>', content)
print(f"\nScript tags: {len(scripts)}")

# Check for inline style with overflow
overflow_styles = re.findall(r'style="[^"]*overflow[^"]*"', content[:50000])
print(f"\noverflow inline styles (first 50k): {len(overflow_styles)}")
for s in overflow_styles[:5]:
    print(" ", s[:100])

# Check for the body-level issues
# Does the page contain duplicate head/header imports?
head_count = content.count('<head>')
body_count = content.count('<body')
html_count = content.count('<html')
print(f"\n<head> count: {head_count}")
print(f"<body> count: {body_count}")
print(f"<html> count: {html_count}")

# Check footer.php
footer_path = '/Applications/XAMPP/xamppfiles/htdocs/aaa/footer.php'
with open(footer_path, 'r', encoding='utf-8', errors='ignore') as f:
    footer = f.read()

print(f"\nfooter.php size: {len(footer)}")
print("footer first 300 chars:", footer[:300])
print("footer last 200 chars:", footer[-200:])

# Check if inner page has any inline overflow:hidden
body_styles = re.findall(r'document\.body\.style', content)
print(f"\nbody.style JS calls: {len(body_styles)}")
