-- Emergency fix for First Economy Mail and other mail activities
-- Run this directly in PostgreSQL

-- Fix ALL mail-related activities
UPDATE activity_records
SET category = 'browser', subcategory = 'email'
WHERE category = 'productive'
AND (
    LOWER(window_title) LIKE '%mail%'
    OR LOWER(window_title) LIKE '%gmail%'
    OR LOWER(window_title) LIKE '%outlook%'
    OR LOWER(window_title) LIKE '%inbox%'
    OR LOWER(window_title) LIKE '%email%'
);

-- Verify the fix
SELECT 
    'Mail activities in browser' as status,
    COUNT(*) as count
FROM activity_records
WHERE category = 'browser'
AND LOWER(window_title) LIKE '%mail%';

-- Check if any mail is still in productive
SELECT 
    'Mail still in productive' as status,
    COUNT(*) as count,
    STRING_AGG(DISTINCT window_title, ', ') as examples
FROM activity_records
WHERE category = 'productive'
AND LOWER(window_title) LIKE '%mail%';