import os
import re
import codecs

files = [
    r'D:\cnf\chatbot-canifa-feedback\backend\static\social-inbox\index.html',
    r'D:\cnf\chatbot-canifa-feedback\backend\static\content-composer\index.html',
    r'D:\cnf\chatbot-canifa-feedback\backend\static\content-approval\index.html',
    r'D:\cnf\chatbot-canifa-feedback\backend\static\content-calendar\index.html',
    r'D:\cnf\chatbot-canifa-feedback\backend\static\media-library\index.html'
]

for fpath in files:
    if not os.path.exists(fpath):
        continue
    with codecs.open(fpath, 'r', 'utf-8') as f:
        content = f.read()
    
    # 1. Update CSS
    content = re.sub(r'header \{[^}]+\}', '.topbar { padding: 14px 24px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 50; }', content)
    
    # 2. Update HTML
    content = re.sub(r'<header>', '<div class="topbar">', content)
    content = re.sub(r'</header>', '</div>', content)
    
    # 3. Restructure .logo to .topbar-left
    # It usually looks like:
    # <div class="logo">
    #   <div> / <h1 ...
    # We can just replace class="logo" with class="topbar-left"
    content = content.replace('class="logo"', 'class="topbar-left"')
    
    # We should also ensure h1 doesn't have huge font weights if it was defined, but we keep it
    
    with codecs.open(fpath, 'w', 'utf-8') as f:
        f.write(content)
    print(f"Updated header to topbar in {fpath}")
