-- Apply "Default" modern gray professional theme as the install default.
-- Safe to run multiple times.  Only overwrites values that are still at an
-- old default; custom values chosen by the admin are left untouched.
-- ─────────────────────────────────────────────────────────────────────────────
START TRANSACTION;

-- ── Core palette ─────────────────────────────────────────────────────────────
INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_primary', 2, '#4B5563', 'Admin primary color', 'string', 60, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_primary');

UPDATE `plugin_base_options` SET `value` = '#4B5563'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_primary'
  AND LOWER(`value`) IN ('#374151', '#0a5114', '#11511a', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_secondary', 2, '#94A3B8', 'Admin secondary color', 'string', 61, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_secondary');

UPDATE `plugin_base_options` SET `value` = '#94A3B8'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_secondary'
  AND LOWER(`value`) IN ('#9ca3af', '#6b7280', '#f9761b', '#2e6e4a', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_sidebar', 2, '#111827', 'Admin sidebar color', 'string', 62, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_sidebar');

UPDATE `plugin_base_options` SET `value` = '#111827'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_sidebar'
  AND LOWER(`value`) IN ('#4b5563', '#1d1d2d', '#07320e', '#08250c', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_success', 2, '#84B66A', 'Admin success color', 'string', 63, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_success');

UPDATE `plugin_base_options` SET `value` = '#84B66A'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_success'
  AND LOWER(`value`) IN ('#059669', '#22c55e', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_warning', 2, '#F4C152', 'Admin warning color', 'string', 64, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_warning');

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

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_info', 2, '#94A3B8', 'Admin info color', 'string', 65, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_info');

UPDATE `plugin_base_options` SET `value` = '#94A3B8'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_info'
  AND LOWER(`value`) IN ('#0284c7', '#3b82f6', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_danger', 2, '#EF6B6B', 'Admin danger color', 'string', 66, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_danger');

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

-- ── Sidebar sub-colors ───────────────────────────────────────────────────────
INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_sidebar_secondary', 2, '#1F2937', 'Sidebar secondary bg', 'string', 71, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_sidebar_secondary');

UPDATE `plugin_base_options` SET `value` = '#1F2937'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_sidebar_secondary'
  AND LOWER(`value`) IN ('#282938', '#353543', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_sidebar_active', 2, '#374151', 'Sidebar active bg', 'string', 72, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_sidebar_active');

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

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_sidebar_text', 2, '#F3F4F6', 'Sidebar text color', 'string', 73, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_sidebar_text');

UPDATE `plugin_base_options` SET `value` = '#F3F4F6'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_sidebar_text'
  AND LOWER(`value`) IN ('#ffffff', '#f9fafb', '#f8fafc', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_sidebar_muted', 2, '#9CA3AF', 'Sidebar muted text', 'string', 74, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_sidebar_muted');

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

-- ── Content area ─────────────────────────────────────────────────────────────
INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_main_bg', 2, '#F5F6F8', 'Main page background', 'string', 75, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_main_bg');

UPDATE `plugin_base_options` SET `value` = '#F5F6F8'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_main_bg'
  AND LOWER(`value`) IN ('#f7f7f6', '#f6f7f9', '#f8fafc', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_card_bg2', 2, '#FFFFFF', 'Card background', 'string', 76, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_card_bg2');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_table_border', 2, '#E5E7EB', 'Table border color', 'string', 77, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_table_border');

UPDATE `plugin_base_options` SET `value` = '#E5E7EB'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_table_border'
  AND LOWER(`value`) IN ('#d1d1d0', '#e2e8f0', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_input_border', 2, '#E5E7EB', 'Input border color', 'string', 78, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_input_border');

UPDATE `plugin_base_options` SET `value` = '#E5E7EB'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_input_border'
  AND LOWER(`value`) IN ('#e0e0df', '#d1d5db', '#cbd5e1', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_main_text', 2, '#111827', 'Main text color', 'string', 79, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_main_text');

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

-- ── Accent / links ───────────────────────────────────────────────────────────
INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_accent', 2, '#4B5563', 'Accent color', 'string', 80, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_accent');

UPDATE `plugin_base_options` SET `value` = '#4B5563'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_accent'
  AND LOWER(`value`) IN ('#f9761b', '#374151', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_link_color', 2, '#9CA3AF', 'Link color', 'string', 81, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_link_color');

UPDATE `plugin_base_options` SET `value` = '#9CA3AF'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_link_color'
  AND LOWER(`value`) IN ('#b9d5f3', '#374151', '');

-- ── Table colors ─────────────────────────────────────────────────────────────
INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_table_header_bg', 2, '#F3F4F6', 'Table header background', 'string', 82, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_table_header_bg');

UPDATE `plugin_base_options` SET `value` = '#F3F4F6'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_table_header_bg'
  AND LOWER(`value`) IN ('#374151', '#f1f5f9', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_table_row_bg', 2, '#FFFFFF', 'Table row background', 'string', 83, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_table_row_bg');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_table_row_alt', 2, '#F9FAFB', 'Table alt row background', 'string', 84, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_table_row_alt');

UPDATE `plugin_base_options` SET `value` = '#F9FAFB'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_table_row_alt'
  AND LOWER(`value`) IN ('#fafafa', '#f8fafc', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_table_row_hover', 2, '#F9FAFB', 'Table row hover background', 'string', 85, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_table_row_hover');

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

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_table_text', 2, '#374151', 'Table text color', 'string', 86, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_table_text');

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

-- ── Typography ───────────────────────────────────────────────────────────────
INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_heading_text', 2, '#111827', 'Heading text color', 'string', 87, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_heading_text');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_muted_text', 2, '#9CA3AF', 'Muted text color', 'string', 88, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_muted_text');

UPDATE `plugin_base_options` SET `value` = '#9CA3AF'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_muted_text'
  AND LOWER(`value`) IN ('#6b7280', '#64748b', '#78909c', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_link_text', 2, '#4B5563', 'Link text color', 'string', 89, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_link_text');

UPDATE `plugin_base_options` SET `value` = '#4B5563'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_link_text'
  AND LOWER(`value`) IN ('#2563eb', '#374151', '#0078d4', '');

-- ── Icons ────────────────────────────────────────────────────────────────────
INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_sidebar_icon', 2, '#F3F4F6', 'Sidebar icon color', 'string', 90, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_sidebar_icon');

UPDATE `plugin_base_options` SET `value` = '#F3F4F6'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_sidebar_icon'
  AND LOWER(`value`) IN ('#ffffff', '#f9fafb', '#f8fafc', '#e8eaf6', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_icon_color', 2, '#4B5563', 'Icon color', 'string', 91, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_icon_color');

UPDATE `plugin_base_options` SET `value` = '#4B5563'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_icon_color'
  AND LOWER(`value`) IN ('#6b7280', '#78909c', '#5c6bc0', '');

-- ── Topbar / inputs / card border ────────────────────────────────────────────
INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_topbar_bg', 2, '#FFFFFF', 'Topbar background', 'string', 92, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_topbar_bg');

UPDATE `plugin_base_options` SET `value` = '#FFFFFF'
WHERE `foreign_id` = 1 AND `key` = 'o_admin_topbar_bg'
  AND LOWER(`value`) IN ('#f8f9fa', '#eceff1', '#e8eaf6', '#fff8e1', '');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_input_bg', 2, '#FFFFFF', 'Input background', 'string', 93, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_input_bg');

INSERT INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`)
SELECT 1, 'o_admin_card_border', 2, '#E5E7EB', 'Card border color', 'string', 94, 0, NULL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_options` WHERE `foreign_id` = 1 AND `key` = 'o_admin_card_border');

COMMIT;
