from pathlib import Path
p = Path('/opt/struktur/projects-dashboard/app.py')
s = p.read_text(encoding='utf-8')
old = '<div class="card-header"><div class="card-icon">{{p.icon}}</div>\n<span class="badge pending" id="badge-{{p.id}}">...</span></div>'
icon = '''<div class="card-header"><div class="card-icon">\n{% if p.id in ['youtube', 'youtube-lm', 'content-extraction'] %}\n<svg class="yt-app-icon" viewBox="0 0 52 52" aria-hidden="true">\n <polygon class="yt-play" points="8,7 8,39 36,23"/>\n <circle class="yt-addon-bg" cx="38" cy="38" r="11"/>\n {% if p.id == 'youtube' %}\n <circle class="yt-addon-line" cx="35.5" cy="35.5" r="4.5"/><line class="yt-addon-line" x1="39" y1="39" x2="44" y2="44"/>\n {% elif p.id == 'youtube-lm' %}\n <line class="yt-addon-line" x1="32" y1="38" x2="32" y2="38"/><line class="yt-addon-line" x1="35" y1="34" x2="35" y2="42"/><line class="yt-addon-line" x1="38" y1="31" x2="38" y2="45"/><line class="yt-addon-line" x1="41" y1="34" x2="41" y2="42"/><line class="yt-addon-line" x1="44" y1="37" x2="44" y2="39"/>\n {% else %}\n <path class="yt-addon-line" d="M33 32h7l4 4v9H33z"/><path class="yt-addon-line" d="M40 32v4h4"/><line class="yt-addon-line" x1="35" y1="39" x2="41" y2="39"/><line class="yt-addon-line" x1="35" y1="42" x2="40" y2="42"/>\n {% endif %}\n</svg>\n{% else %}{{p.icon}}{% endif %}\n</div>\n<span class="badge pending" id="badge-{{p.id}}">...</span></div>'''
count = s.count(old)
if count != 3:
raise SystemExit(f'expected 3 icon render blocks, found {count}')
s = s.replace(old, icon)
css_anchor = '.card-icon { font-size: 2rem; }'
css_new = '''.card-icon { font-size: 2rem; min-height: 52px; display: flex; align-items: center; }\n.yt-app-icon { width: 52px; height: 52px; display: block; overflow: visible; }\n.yt-play { fill: #ff0033; }\n.yt-addon-bg { fill: #111827; stroke: #64748b; stroke-width: 1.5; }\n.yt-addon-line { fill: none; stroke: #f8fafc; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }'''
if css_anchor not in s:
raise SystemExit('css anchor not found')
s = s.replace(css_anchor, css_new, 1)
p.write_text(s, encoding='utf-8')
print('patched', count, 'icon blocks')