-- =============================================================================
-- Normalize the admin install default to the light orange Default palette.
-- This migration only overwrites known previous bundled defaults, including the
-- temporary Midnight palette, and leaves truly custom admin colors untouched.
-- =============================================================================
START TRANSACTION;

UPDATE `plugin_base_options` SET `value` = '#F97316'
WHERE `foreign_id` = 1 AND `key` IN ('o_admin_primary', 'o_admin_accent', 'o_admin_link_color', 'o_admin_link_text')
  AND LOWER(`value`) IN ('#334155', '#4b5563', '#374151', '#f9761b', '#9ca3af', '#2563eb', '#0078d4', '');

UPDATE `plugin_base_options` SET `value` = '#64748B'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_secondary'
  AND LOWER(`value`) IN ('#475569', '#94a3b8', '#4b5563', '#9ca3af', '#8b5cf6', '');

UPDATE `plugin_base_options` SET `value` = '#FFFFFF'
WHERE `foreign_id` = 1 AND `key` IN ('o_admin_sidebar', 'o_admin_card_bg2', 'o_admin_topbar_bg', 'o_admin_input_bg')
  AND LOWER(`value`) IN ('#0f172a', '#111827', '#1d1d2d', '#4b5563', '#fefefe', '#f8f9fa', '');

UPDATE `plugin_base_options` SET `value` = '#10B981'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_success'
  AND LOWER(`value`) IN ('#10b981', '#84b66a', '#059669', '');

UPDATE `plugin_base_options` SET `value` = '#F59E0B'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_warning'
  AND LOWER(`value`) IN ('#f59e0b', '#f4c152', '#d97706', '');

UPDATE `plugin_base_options` SET `value` = '#3B82F6'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_info'
  AND LOWER(`value`) IN ('#38bdf8', '#94a3b8', '#0284c7', '#8b5cf6', '');

UPDATE `plugin_base_options` SET `value` = '#EF4444'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_danger'
  AND LOWER(`value`) IN ('#ef4444', '#ef6b6b', '#b91c1c', '');

UPDATE `plugin_base_options` SET `value` = '#F8FAFC'
WHERE `foreign_id` = 1 AND `key` IN ('o_admin_sidebar_secondary', 'o_admin_main_bg', 'o_admin_table_header_bg', 'o_admin_table_row_alt')
  AND LOWER(`value`) IN ('#1e293b', '#1f2937', '#282938', '#f5f6f8', '#f7f7f6', '#f1f5f9', '#f3f4f6', '#f9fafb', '#fafafa', '');

UPDATE `plugin_base_options` SET `value` = '#FFF1E6'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_sidebar_active'
  AND LOWER(`value`) IN ('#334155', '#374151', '#353543', '');

UPDATE `plugin_base_options` SET `value` = '#64748B'
WHERE `foreign_id` = 1 AND `key` IN ('o_admin_sidebar_text', 'o_admin_muted_text', 'o_admin_sidebar_icon', 'o_admin_icon_color')
  AND LOWER(`value`) IN ('#f8fafc', '#f3f4f6', '#ffffff', '#94a3b8', '#9ca3af', '#868994', '#4b5563', '#6b7280', '');

UPDATE `plugin_base_options` SET `value` = '#94A3B8'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_sidebar_muted'
  AND LOWER(`value`) IN ('#94a3b8', '#9ca3af', '#868994', '');

UPDATE `plugin_base_options` SET `value` = '#E2E8F0'
WHERE `foreign_id` = 1 AND `key` IN ('o_admin_table_border', 'o_admin_input_border', 'o_admin_card_border')
  AND LOWER(`value`) IN ('#cbd5e1', '#e5e7eb', '#e0e0df', '#d1d1d0', '');

UPDATE `plugin_base_options` SET `value` = '#0F172A'
WHERE `foreign_id` = 1 AND `key` IN ('o_admin_main_text', 'o_admin_heading_text')
  AND LOWER(`value`) IN ('#0f172a', '#111827', '#2f2f2f', '');

UPDATE `plugin_base_options` SET `value` = '#FFFFFF'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_table_row_bg'
  AND LOWER(`value`) IN ('#ffffff', '');

UPDATE `plugin_base_options` SET `value` = '#FFF7ED'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_table_row_hover'
  AND LOWER(`value`) IN ('#f1f5f9', '#f9fafb', '#f3f4f6', '');

UPDATE `plugin_base_options` SET `value` = '#334155'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_table_text'
  AND LOWER(`value`) IN ('#334155', '#374151', '#2f2f2f', '');

COMMIT;
