<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals
// phpcs:disable WordPress.Security.NonceVerification
// phpcs:disable WordPress.Security.ValidatedSanitizedInput
// phpcs:disable WordPress.WP.EnqueuedResourceParameters
// phpcs:disable WordPress.DB.PreparedSQL
// phpcs:disable WordPress.DB.PreparedSQLPlaceholders
// phpcs:disable WordPress.DB.DirectDatabaseQuery
// phpcs:disable WordPress.DB.SlowDBQuery
// phpcs:disable PluginCheck.Security.DirectDB
// phpcs:disable PluginCheck.CodeAnalysis
// phpcs:disable WordPressVIPMinimum

/**
 * GT BOGO Engine — Enterprise UI Wrapper Start
 * Full design system. NO <!DOCTYPE html> — WP owns the document.
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$_gt_tab     = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'dashboard';
$_gt_page    = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : 'gt-bogo-engine';
$_gt_url     = defined( 'GT_BOGO_ENGINE_URL' ) ? GT_BOGO_ENGINE_URL : plugin_dir_url( dirname( __DIR__ ) );
$_gt_ver     = defined( 'GT_BOGO_VERSION' ) ? GT_BOGO_VERSION : GT_BOGO_VERSION;
$_gt_is_pro  = get_option( 'gtbogo_license_status' ) === 'active';
$_gt_expires = get_option( 'gtbogo_license_expires', '' );
$_gt_days    = 0;
if ( $_gt_is_pro && $_gt_expires ) {
	$_gt_days = (int) ceil( ( strtotime( $_gt_expires ) - time() ) / 86400 );
}

function _gt_nav( $tab, $label, $icon, $badge = '' ) {
	global $_gt_tab, $_gt_is_pro;
	$active   = $_gt_tab === $tab ? 'gt-nav-active' : '';
	$is_gated = ! empty( $badge ) && ! $_gt_is_pro;
	$url      = $is_gated
		? admin_url( 'admin.php?page=gt-bogo-engine&tab=license' )
		: admin_url( 'admin.php?page=gt-bogo-engine&tab=' . $tab );
	$b        = $badge ? '<span class="gt-nav-badge">' . esc_html( $badge ) . '</span>' : '';
	$style    = $is_gated ? ' style="opacity:0.55;cursor:pointer"' : '';
	echo '<li><a href="' . esc_url( $url ) . '" class="gt-nav-link ' . esc_attr( $active ) . '"' . esc_attr( $style ) . '>'
		. '<span class="gt-nav-icon">' . wp_kses_post( $icon ) . '</span>'
		. '<span class="gt-nav-label">' . esc_html( $label ) . '</span>'
		. wp_kses_post( $b ) . '</a></li>';
}
?>
<?php wp_enqueue_style( 'gt-bogo-fonts', GT_BOGO_ENGINE_URL . 'assets/fonts/gt-bogo-fonts.css', array(), GT_BOGO_VERSION ); ?>
<style>
/* ═══════════════════════════════════════════════════
	GT BOGO ENGINE — OBSIDIAN COMMAND CENTER
	Design System v4.0
═══════════════════════════════════════════════════ */
/* ── Kill WordPress white flash immediately ── */
html, body, #wpbody, #wpbody-content,
#wpwrap, #wpcontent, #wpfooter {
	background:#020617 !important;
}
:root {
	--gt-bg:         #020617;
	--gt-nav:        #060d1f;
	--gt-card:       #0a1628;
	--gt-card-hover: #0d1c32;
	--gt-border:     rgba(255,255,255,0.06);
	--gt-border-md:  rgba(255,255,255,0.10);
	--gt-red:        #e10000;
	--gt-red-glow:   rgba(225,0,0,0.35);
	--gt-red-soft:   rgba(225,0,0,0.12);
	--gt-green:      #22c55e;
	--gt-yellow:     #f59e0b;
	--gt-blue:       #3b82f6;
	--gt-white:      #ffffff;
	--gt-soft:       #ffffff;
	--gt-subtle:     #64748b;
	--gt-r:          12px;
	--gt-r-lg:       16px;
	--gt-sidebar-w:  252px;
}

/* ── WP isolation ── */
#wpadminbar,#wpfooter,.update-nag,.notice:not(.gt-keep),.wp-header-end{display:none!important}
#wpbody-content,#wpcontent{padding:0!important;background:var(--gt-bg)!important}
body.wp-admin{background:var(--gt-bg)!important;font-family:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif!important}
#wpbody-content>.wrap{margin:0;padding:0}

/* ── Layout shell ── */
.gt-shell{display:flex;min-height:100vh;background:var(--gt-bg);font-family:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif;color:var(--gt-white);position:relative}

/* ── Animated background grid ── */
.gt-shell::before{
	content:'';position:fixed;inset:0;pointer-events:none;
	background-image:
	linear-gradient(rgba(255,255,255,0.018) 1px,transparent 1px),
	linear-gradient(90deg,rgba(255,255,255,0.018) 1px,transparent 1px);
	background-size:48px 48px;z-index:0;
}

/* ── Sidebar ── */
.gt-sidebar{
	width:var(--gt-sidebar-w);min-width:var(--gt-sidebar-w);
	background:var(--gt-nav);
	border-right:1px solid var(--gt-border);
	display:flex;flex-direction:column;
	position:fixed;top:32px;left:160px;height:calc(100vh - 32px);overflow-y:auto;z-index:9999;
	scrollbar-width:none;
}
.gt-sidebar::-webkit-scrollbar{display:none}

.gt-brand{
	display:flex;align-items:center;gap:12px;
	padding:20px 16px;
	border-bottom:1px solid var(--gt-border);
	text-decoration:none;
	background:linear-gradient(180deg,rgba(225,0,0,0.06) 0%,transparent 100%);
}
.gt-brand:hover{background:linear-gradient(180deg,rgba(225,0,0,0.1) 0%,transparent 100%)}
.gt-brand-icon{
	width:52px;height:52px;border-radius:10px;
	display:flex;align-items:center;justify-content:center;
	flex-shrink:0;
	box-shadow:0 0 24px var(--gt-red-glow),0 4px 12px rgba(0,0,0,0.4);
}
.gt-brand-text{display:flex;flex-direction:column;gap:3px}
.gt-brand-name{font-size:15px;font-weight:900;letter-spacing:2px;color:var(--gt-white);line-height:1;text-transform:uppercase}
.gt-brand-sub{font-size:11px;color:var(--gt-red);margin-top:1px;letter-spacing:1.5px;font-weight:800;text-transform:uppercase}

/* License pill */
.gt-lic-pill{
	display:flex;align-items:center;gap:8px;
	margin:12px 14px 4px;
	padding:8px 12px;border-radius:50px;
	font-size:11px;font-weight:700;letter-spacing:0.5px;
	border:1px solid;
}
.gt-lic-pill.pro{background:rgba(34,197,94,0.08);border-color:rgba(34,197,94,0.05);color:#86efac}
.gt-lic-pill.free{background:rgba(100,116,139,0.08);border-color:rgba(100,116,139,0.2);color:var(--gt-soft)}
.gt-pulse{
	width:7px;height:7px;border-radius:50%;flex-shrink:0;
	background:var(--gt-green);
	box-shadow:0 0 8px var(--gt-green);
	animation:gtp-pulse 2s ease-in-out infinite;
}
.gt-pulse.gray{background:var(--gt-subtle);box-shadow:none;animation:none}
@keyframes gtp-pulse{0%,100%{opacity:1;transform:scale(1)}50%{opacity:0.5;transform:scale(0.85)}}

/* Nav */
.gt-nav-section{padding:12px 0 4px;flex:1}
.gt-nav-sep{padding:14px 18px 6px;font-size:11px;font-weight:800;letter-spacing:1.5px;text-transform:uppercase;color:var(--gt-subtle)}
.gt-nav-list{list-style:none;margin:0;padding:0 10px}
.gt-nav-link{display:flex;align-items:center;padding:9px 12px;border-radius:8px;text-decoration:none;color:var(--gt-soft);font-size:13.5px;font-weight:600;transition:all .15s;gap:0;white-space:nowrap;overflow:hidden}
.gt-nav-link:hover{color:var(--gt-white);background:rgba(255,255,255,0.04)}
.gt-nav-active{
	color:var(--gt-white)!important;
	background:rgba(225,0,0,0.1)!important;
	font-weight:600!important;
}
.gt-nav-active::before{
	content:'';position:absolute;left:-8px;top:50%;transform:translateY(-50%);
	width:3px;height:18px;border-radius:3px;
	background:var(--gt-red);box-shadow:0 0 10px var(--gt-red-glow);
}
.gt-nav-icon{font-size:17px;width:24px;text-align:center;flex-shrink:0;margin-right:10px;line-height:1}
.gt-nav-label{flex:1;font-size:13.5px}
.gt-nav-badge{
	font-size:9px;font-weight:800;letter-spacing:0.8px;
	padding:2px 7px;border-radius:50px;
	background:var(--gt-red);color:#fff;
	box-shadow:0 0 8px var(--gt-red-glow);
}

/* Sidebar footer */
.gt-sidebar-foot{
	padding:14px 18px;
	border-top:1px solid var(--gt-border);
}
.gt-sidebar-ver{font-size:11px;color:var(--gt-subtle);font-family:'DM Mono','Courier New',monospace}

/* Upgrade box */
.gt-upgrade-box{
	margin:12px;padding:14px;border-radius:10px;
	background:linear-gradient(135deg,rgba(225,0,0,0.12),rgba(225,0,0,0.04));
	border:1px solid rgba(225,0,0,0.2);
}
.gt-upgrade-box h4{font-size:12px;font-weight:700;color:var(--gt-white);margin:0 0 4px}
.gt-upgrade-box p{font-size:11px;color:var(--gt-soft);margin:0 0 10px;line-height:1.4}
.gt-upgrade-btn{
	display:block;text-align:center;
	padding:7px;border-radius:50px;
	background:var(--gt-red);color:#fff;
	font-size:11px;font-weight:700;text-decoration:none;
	box-shadow:0 0 12px var(--gt-red-glow);
	transition:all 0.2s;
}
.gt-upgrade-btn:hover{background:#c50000;box-shadow:0 0 20px var(--gt-red-glow);color:#fff}

/* ── Main ── */
.gt-main{
	flex:1;padding:32px 36px;overflow-x:hidden;
	background:var(--gt-bg);z-index:1;position:relative;
	min-width:0;margin-left:var(--gt-sidebar-w);
}

/* ── Page header ── */
.gt-page-head{
	display:flex;align-items:flex-start;justify-content:space-between;
	margin-bottom:28px;gap:16px;flex-wrap:wrap;
}
.gt-page-title{
	font-size:28px;font-weight:800;color:var(--gt-white);
	margin:0 0 5px;letter-spacing:-0.5px;
}
.gt-page-sub{font-size:14px;color:var(--gt-soft);margin:0}
.gt-page-actions{display:flex;gap:10px;align-items:center;flex-wrap:wrap}

/* ── Cards ── */
.gt-card{
	background:var(--gt-card);
	border:1px solid var(--gt-border);
	border-radius:var(--gt-r-lg);
	padding:24px;margin-bottom:20px;
	transition:border-color 0.2s,background 0.2s;
}
.gt-card:hover{border-color:var(--gt-border-md)}
.gt-card-head{
	display:flex;align-items:center;justify-content:space-between;
	margin-bottom:20px;padding-bottom:16px;
	border-bottom:1px solid var(--gt-border);
}
.gt-card-title{font-size:15px;font-weight:700;color:var(--gt-white);margin:0}
.gt-card-label{
	font-size:10px;font-weight:700;letter-spacing:1.2px;
	text-transform:uppercase;color:var(--gt-subtle);margin-bottom:8px;
}

/* Gradient border card */
.gt-card-premium{
	position:relative;background:var(--gt-card);border-radius:var(--gt-r-lg);
	padding:24px;margin-bottom:20px;
}
.gt-card-premium::before{
	content:'';position:absolute;inset:0;border-radius:var(--gt-r-lg);
	padding:1px;
	background:linear-gradient(135deg,rgba(225,0,0,0.4),rgba(255,255,255,0.04),rgba(59,130,246,0.2));
	-webkit-mask:linear-gradient(#fff 0 0) content-box,linear-gradient(#fff 0 0);
	-webkit-mask-composite:xor;mask-composite:exclude;
	pointer-events:none;
}

/* ── Metric Grid ── */
.gt-metrics{
	display:grid;grid-template-columns:repeat(4,1fr);gap:16px;margin-bottom:20px;
}
.gt-metric{
	background:var(--gt-card);border:1px solid var(--gt-border);
	border-radius:var(--gt-r-lg);padding:20px;
	border-top:2px solid var(--gt-metric-c,var(--gt-red));
	position:relative;overflow:hidden;transition:all 0.2s;
}
.gt-metric::after{
	content:'';position:absolute;top:-20px;right:-20px;
	width:80px;height:80px;border-radius:50%;
	background:var(--gt-metric-c,var(--gt-red));opacity:0.05;
	filter:blur(20px);
}
.gt-metric:hover{transform:translateY(-2px);border-color:var(--gt-metric-c,var(--gt-red))}
.gt-metric-icon{font-size:22px;margin-bottom:14px;display:block;line-height:1}
.gt-metric-label{font-size:10px;font-weight:700;letter-spacing:1px;text-transform:uppercase;color:var(--gt-soft);margin-bottom:6px}
.gt-metric-value{font-size:28px;font-weight:800;color:var(--gt-white);font-family:'DM Mono','Courier New',monospace;letter-spacing:-1px;margin-bottom:4px}
.gt-metric-trend{font-size:11px;color:var(--gt-subtle)}

/* ── Grid layouts ── */
.gt-grid-3{display:grid;grid-template-columns:repeat(3,1fr);gap:16px}
.gt-grid-2{display:grid;grid-template-columns:repeat(2,1fr);gap:16px}
.gt-grid-4{display:grid;grid-template-columns:repeat(4,1fr);gap:16px}

/* ── Buttons ── */
.gt-btn{
	display:inline-flex;align-items:center;gap:7px;
	padding:10px 22px;border-radius:50px;
	font-size:13px;font-weight:700;font-family:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif;
	cursor:pointer;text-decoration:none;border:none;
	transition:all 0.2s;white-space:nowrap;letter-spacing:0.3px;
}
.gt-btn-primary{
	background:var(--gt-red);color:#fff;
	box-shadow:0 0 20px var(--gt-red-glow);
}
.gt-btn-primary:hover{background:#c50000;box-shadow:0 0 32px var(--gt-red-glow);transform:translateY(-1px);color:#fff}
.gt-btn-ghost{
	background:rgba(255,255,255,0.06);color:var(--gt-white);
	border:1px solid var(--gt-border-md);
}
.gt-btn-ghost:hover{background:rgba(255,255,255,0.1);color:#fff}
.gt-btn-sm{padding:7px 16px;font-size:12px}
.gt-btn-xs{padding:5px 12px;font-size:11px}

/* ── Status badges ── */
.gt-badge{
	display:inline-flex;align-items:center;gap:5px;
	padding:4px 10px;border-radius:50px;
	font-size:11px;font-weight:700;
}
.gt-badge-active{background:rgba(34,197,94,0.1);border:1px solid rgba(34,197,94,0.05);color:#86efac}
.gt-badge-expiring{background:rgba(245,158,11,0.1);border:1px solid rgba(245,158,11,0.25);color:#fcd34d}
.gt-badge-expired{background:rgba(225,0,0,0.1);border:1px solid rgba(225,0,0,0.25);color:#fca5a5}
.gt-badge-free{background:rgba(100,116,139,0.1);border:1px solid rgba(100,116,139,0.2);color:var(--gt-soft)}
.gt-badge-pro{background:rgba(225,0,0,0.12);border:1px solid rgba(225,0,0,0.3);color:#ff6666}
.gt-badge-owned{background:rgba(34,197,94,0.1);border:1px solid rgba(34,197,94,0.3);color:#86efac}

/* ── Dot status ── */
.gt-dot{width:8px;height:8px;border-radius:50%;flex-shrink:0;display:inline-block}
.gt-dot-green{background:var(--gt-green);box-shadow:0 0 8px var(--gt-green);animation:gtp-pulse 2s infinite}
.gt-dot-yellow{background:var(--gt-yellow);box-shadow:0 0 8px var(--gt-yellow)}
.gt-dot-red{background:var(--gt-red);box-shadow:0 0 8px var(--gt-red)}
.gt-dot-gray{background:var(--gt-subtle)}

/* ── Forms ── */
.gt-form-group{margin-bottom:20px}
.gt-form-label{display:block;font-size:13px;font-weight:600;color:var(--gt-white);margin-bottom:8px}
.gt-form-hint{font-size:13px;color:var(--gt-soft);margin-top:5px}
.gt-input{
	width:100%;padding:11px 14px;
	background:rgba(255,255,255,0.04);
	border:1px solid var(--gt-border-md);
	border-radius:8px;color:var(--gt-white);
	font-size:14px;font-family:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif;
	transition:border-color 0.2s,box-shadow 0.2s;
	box-sizing:border-box;
}
.gt-input:focus{outline:none;border-color:var(--gt-red);box-shadow:0 0 0 3px var(--gt-red-soft)}
.gt-select{
	appearance:none;width:100%;padding:11px 36px 11px 14px;
	background:#0a1628 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center;
	border:1px solid var(--gt-border-md);border-radius:8px;
	color:var(--gt-white);font-size:14px;font-family:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif;
	cursor:pointer;color-scheme:dark;
}
.gt-select:focus{outline:none;border-color:var(--gt-red)}
/* Compact select — matches toggle height exactly. Use for inline control rows */
.gt-select-sm{
	-webkit-appearance:none!important;-moz-appearance:none!important;appearance:none!important;
	height:24px!important;min-height:0!important;max-height:24px!important;
	padding:0 22px 0 8px!important;line-height:22px!important;
	background:#0a1628 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 6px center!important;
	border:1px solid var(--gt-border-md)!important;border-radius:6px!important;
	color:var(--gt-white)!important;font-size:12px!important;cursor:pointer;color-scheme:dark;
	box-sizing:border-box!important;display:inline-block!important;vertical-align:middle!important;
}
.gt-select-sm:focus{outline:none!important;border-color:#22c55e!important;}
select:not(.gt-select){background-image:none!important}
.gt-toggle{
	position:relative;display:inline-block;width:44px;height:24px;
}
.gt-toggle input{opacity:0;width:0;height:0;}
.gt-toggle-track{
	width:44px;height:24px;background:rgba(255,255,255,0.1);border:1px solid var(--gt-border);
	border-radius:12px;transition:all .3s;position:relative;display:block;flex-shrink:0;
	overflow:hidden;cursor:pointer;
}
.gt-toggle-thumb{
	position:absolute;width:18px;height:18px;left:2px;top:2px;
	background:rgba(255,255,255,0.5);border-radius:50%;transition:all .3s;display:block;
}
.gt-toggle input:checked + .gt-toggle-track{background:#16a34a;border-color:#22c55e;box-shadow:0 0 10px rgba(34,197,94,0.05)}
.gt-toggle input:checked + .gt-toggle-track .gt-toggle-thumb{transform:translateX(20px);background:#fff}
/* All toggles use green — gt-toggle-green kept for backwards compat */
/* Disabled/off state — explicit grey */
.gt-toggle input:not(:checked) + .gt-toggle-track .gt-toggle-thumb{background:rgba(255,255,255,0.4)}
.gt-toggle-slider{
	position:absolute;cursor:pointer;inset:0;border-radius:24px;
	background:rgba(255,255,255,0.1);border:1px solid var(--gt-border-md);
	transition:0.3s;
}
.gt-toggle-slider::before{
	content:'';position:absolute;height:16px;width:16px;
	left:3px;bottom:3px;background:var(--gt-soft);
	border-radius:50%;transition:0.3s;
}
.gt-toggle input:checked + .gt-toggle-slider{background:#16a34a;border-color:#22c55e;box-shadow:0 0 10px rgba(34,197,94,0.05)}
.gt-toggle input:checked + .gt-toggle-slider::before{transform:translateX(20px);background:#fff}

/* ── Notices ── */
.gt-notice{
	padding:14px 18px;border-radius:10px;margin-bottom:20px;
	font-size:13px;font-weight:500;display:flex;align-items:center;gap:10px;
}
.gt-notice-success{background:rgba(34,197,94,0.08);border:1px solid rgba(34,197,94,0.3);color:#86efac}
.gt-notice-error{background:rgba(225,0,0,0.08);border:1px solid rgba(225,0,0,0.2);color:#fca5a5}
.gt-notice-warn{background:rgba(245,158,11,0.08);border:1px solid rgba(245,158,11,0.2);color:#fcd34d}
.gt-notice-info{background:rgba(59,130,246,0.08);border:1px solid rgba(59,130,246,0.2);color:#93c5fd}

/* ── License banner ── */
.gt-lic-banner{
	display:flex;align-items:center;justify-content:space-between;gap:16px;
	padding:16px 20px;border-radius:10px;margin-bottom:20px;
}
.gt-lic-banner.expired{background:rgba(225,0,0,0.06);border:1px solid rgba(225,0,0,0.2)}
.gt-lic-banner.expiring{background:rgba(245,158,11,0.06);border:1px solid rgba(245,158,11,0.2)}
.gt-lic-banner h3{font-size:14px;font-weight:700;color:var(--gt-white);margin:0 0 3px}
.gt-lic-banner p{font-size:13px;color:var(--gt-soft);margin:0}

/* ── Divider ── */
.gt-hr{border:none;border-top:1px solid var(--gt-border);margin:24px 0}

/* ── Tables ── */
.gt-table{width:100%;border-collapse:collapse;font-size:13px}
.gt-table th{
	padding:10px 14px;text-align:left;
	font-size:10px;font-weight:700;letter-spacing:1px;text-transform:uppercase;
	color:var(--gt-subtle);border-bottom:1px solid var(--gt-border);
}
.gt-table td{padding:12px 14px;border-bottom:1px solid rgba(255,255,255,0.03);color:var(--gt-white)}
.gt-table tr:last-child td{border-bottom:none}
.gt-table tr:hover td{background:rgba(255,255,255,0.02)}

/* ── Animations ── */
.gt-fade{opacity:0;transform:translateY(12px);animation:gt-fadein 0.4s ease forwards}
.gt-fade:nth-child(1){animation-delay:0.05s}
.gt-fade:nth-child(2){animation-delay:0.10s}
.gt-fade:nth-child(3){animation-delay:0.15s}
.gt-fade:nth-child(4){animation-delay:0.20s}
.gt-fade:nth-child(5){animation-delay:0.25s}
.gt-fade:nth-child(6){animation-delay:0.30s}
.gt-fade:nth-child(7){animation-delay:0.35s}
.gt-fade:nth-child(8){animation-delay:0.40s}
@keyframes gt-fadein{to{opacity:1;transform:translateY(0)}}

/* ── Misc utils ── */
.gt-flex{display:flex;align-items:center}
.gt-flex-between{display:flex;align-items:center;justify-content:space-between}
.gt-gap-sm{gap:8px}
.gt-gap{gap:14px}
.gt-gap-lg{gap:20px}
.gt-text-sm{font-size:15px}
.gt-text-xs{font-size:11px}
.gt-soft{color:var(--gt-soft)}
.gt-white{color:var(--gt-white)}
.gt-mono{font-family:'DM Mono','Courier New',monospace}
.gt-mt{margin-top:16px}
.gt-mt-lg{margin-top:24px}
.gt-mb{margin-bottom:16px}
.gt-mb-lg{margin-bottom:24px}
.gt-fw-800{font-weight:800}
.gt-truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

/* ── Counter animation ── */
.gt-counter{display:inline-block}

/* ── PRO Pack vault ── */
.gt-vault-grid{
	display:grid;grid-template-columns:repeat(3,1fr);gap:18px;
}
.gt-pack-card{
	background:var(--gt-card);border:1px solid var(--gt-border);
	border-radius:var(--gt-r-lg);overflow:hidden;
	transition:all 0.25s;position:relative;
}
.gt-pack-card:hover{
	border-color:rgba(225,0,0,0.3);
	transform:translateY(-3px);
	box-shadow:0 12px 40px rgba(0,0,0,0.4);
}
.gt-pack-card.owned{border-color:rgba(34,197,94,0.3)}
.gt-pack-head{
	padding:18px 18px 14px;
	border-bottom:1px solid var(--gt-border);
	background:linear-gradient(135deg,rgba(255,255,255,0.02),transparent);
}
.gt-pack-icon{font-size:28px;margin-bottom:8px;display:block}
.gt-pack-name{font-size:14px;font-weight:700;color:var(--gt-white);margin:0 0 4px}
.gt-pack-desc{font-size:13px;color:var(--gt-soft);line-height:1.4;margin:0}
.gt-pack-foot{
	padding:14px 18px;
	display:flex;align-items:center;justify-content:space-between;
}
.gt-pack-price{font-size:16px;font-weight:800;color:var(--gt-white);font-family:'DM Mono','Courier New',monospace}
.gt-pack-owned-check{color:var(--gt-green);font-size:13px;font-weight:700;display:flex;align-items:center;gap:5px}

/* ── PayPal modal ── */
.gt-modal-overlay{
	display:none;position:fixed;inset:0;z-index:99999;
	background:rgba(2,6,23,0.88);backdrop-filter:blur(8px);
	align-items:center;justify-content:center;
}
.gt-modal-overlay.open{display:flex}
.gt-modal{
	background:var(--gt-card);border:1px solid var(--gt-border-md);
	border-radius:20px;padding:32px;width:460px;max-width:90vw;
	position:relative;
	box-shadow:0 32px 80px rgba(0,0,0,0.7);
	animation:gt-modal-in 0.3s ease;
}
@keyframes gt-modal-in{from{opacity:0;transform:scale(0.9) translateY(20px)}to{opacity:1;transform:scale(1) translateY(0)}}
.gt-modal-close{
	position:absolute;top:16px;right:16px;
	background:rgba(255,255,255,0.06);border:none;
	width:30px;height:30px;border-radius:50%;
	color:var(--gt-soft);font-size:16px;cursor:pointer;
	display:flex;align-items:center;justify-content:center;
	transition:all 0.2s;
}
.gt-modal-close:hover{background:rgba(255,255,255,0.12);color:var(--gt-white)}
.gt-modal h3{font-size:20px;font-weight:800;color:var(--gt-white);margin:0 0 6px}
.gt-modal p{font-size:14px;color:var(--gt-soft);margin:0 0 20px}
.gt-paypal-wrap{min-height:48px;display:flex;align-items:center;justify-content:center}

/* ── Bundle cards ── */
.gt-bundle-card{
	background:linear-gradient(135deg,var(--gt-card) 0%,rgba(225,0,0,0.04) 100%);
	border:1px solid rgba(225,0,0,0.15);
	border-radius:var(--gt-r-lg);padding:24px;
	transition:all 0.25s;
}
.gt-bundle-card:hover{border-color:rgba(225,0,0,0.35);transform:translateY(-2px);box-shadow:0 12px 40px rgba(225,0,0,0.1)}
.gt-bundle-price{font-size:32px;font-weight:900;color:var(--gt-white);font-family:'DM Mono','Courier New',monospace;letter-spacing:-1px}
.gt-bundle-name{font-size:16px;font-weight:700;color:var(--gt-white);margin-bottom:4px}
.gt-bundle-packs{font-size:13px;color:var(--gt-soft);margin-bottom:16px}
.gt-bundle-features{list-style:none;padding:0;margin:0 0 20px;display:flex;flex-direction:column;gap:6px}
.gt-bundle-features li{font-size:13px;color:var(--gt-soft);display:flex;align-items:center;gap:6px}
.gt-bundle-features li::before{content:'✓';color:var(--gt-green);font-weight:700;font-size:11px}

/* ── Pro gate ── */
.gt-pro-gate{
	text-align:center;padding:60px 40px;
	background:var(--gt-card);border:1px solid var(--gt-border);
	border-radius:var(--gt-r-lg);margin-bottom:20px;
}
.gt-pro-gate-icon{font-size:48px;display:block;margin-bottom:16px}
.gt-pro-gate h2{font-size:22px;font-weight:800;color:var(--gt-white);margin:0 0 10px}
.gt-pro-gate p{font-size:14px;color:var(--gt-soft);margin:0 0 24px;max-width:480px;display:inline-block}
.gt-pro-gate .gt-flex{gap:12px}

/* ── Button secondary ── */
.gt-btn-secondary{
	background:rgba(255,255,255,0.08);color:var(--gt-white)!important;
	border:1px solid var(--gt-border-md);
}
.gt-btn-secondary:hover{background:rgba(255,255,255,0.14);color:var(--gt-white)!important}

/* ── Page header ── */
.gt-page-header{display:flex;align-items:flex-start;justify-content:space-between;margin-bottom:28px;gap:16px;flex-wrap:wrap}
.gt-page-title{font-size:28px;font-weight:800;color:var(--gt-white);margin:0 0 5px;letter-spacing:-0.5px}
.gt-page-subtitle,.gt-page-sub{font-size:14px;color:var(--gt-soft);margin:0}
.gt-page-actions{display:flex;gap:10px;align-items:center;flex-wrap:wrap}

/* ── Card header ── */
.gt-card-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:20px;padding-bottom:16px;border-bottom:1px solid var(--gt-border)}

/* ── Animate in ── */
.gt-animate-in{animation:gt-fadein 0.35s ease forwards}

/* ── Text utils ── */
.gt-text-center{text-align:center}
.gt-text-white{color:var(--gt-white)!important}
.gt-text-soft{color:var(--gt-soft)!important}
.gt-text-sm{font-size:15px}
.gt-space-sm{gap:8px}

/* ── Form utils ── */
.gt-feature-grid{display:grid;gap:16px}
.gt-feature-grid--2col{grid-template-columns:repeat(2,1fr)}
@media(max-width:700px){.gt-feature-grid--2col{grid-template-columns:1fr}}

/* ── Pro gate ── */
.gt-pro-gate{
	text-align:center;padding:60px 40px;
	background:var(--gt-card);border:1px solid var(--gt-border);
	border-radius:var(--gt-r-lg);margin-bottom:20px;
}
.gt-pro-gate-icon{font-size:48px;display:block;margin-bottom:16px}
.gt-pro-gate h2{font-size:22px;font-weight:800;color:var(--gt-white);margin:0 0 10px}
.gt-pro-gate p{font-size:14px;color:var(--gt-soft);margin:0 0 24px;max-width:480px;display:inline-block}
.gt-pro-gate .gt-flex{gap:12px}

/* ── Button secondary ── */
.gt-btn-secondary{
	background:rgba(255,255,255,0.08);color:var(--gt-white)!important;
	border:1px solid var(--gt-border-md);
}
.gt-btn-secondary:hover{background:rgba(255,255,255,0.14);color:var(--gt-white)!important}

/* ── Page header ── */
.gt-page-header{display:flex;align-items:flex-start;justify-content:space-between;margin-bottom:28px;gap:16px;flex-wrap:wrap}
.gt-page-title{font-size:28px;font-weight:800;color:var(--gt-white);margin:0 0 5px;letter-spacing:-0.5px}
.gt-page-subtitle,.gt-page-sub{font-size:14px;color:var(--gt-soft);margin:0}
.gt-page-actions{display:flex;gap:10px;align-items:center;flex-wrap:wrap}

/* ── Card header ── */
.gt-card-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:20px;padding-bottom:16px;border-bottom:1px solid var(--gt-border)}

/* ── Animate in ── */
.gt-animate-in{animation:gt-fadein 0.35s ease forwards}

/* ── Text utils ── */
.gt-text-center{text-align:center}
.gt-text-white{color:var(--gt-white)!important}
.gt-text-soft{color:var(--gt-soft)!important}
.gt-text-sm{font-size:15px}

/* ── Form utils ── */
.gt-feature-grid{display:grid;gap:16px}
.gt-feature-grid--2col{grid-template-columns:repeat(2,1fr)}
@media(max-width:700px){.gt-feature-grid--2col{grid-template-columns:1fr}}

/* ── Pro gate ── */
.gt-pro-gate{text-align:center;padding:60px 40px;background:var(--gt-card);border:1px solid var(--gt-border);border-radius:var(--gt-r-lg);margin-bottom:20px}
.gt-pro-gate-icon{font-size:48px;display:block;margin-bottom:16px}
.gt-pro-gate h2{font-size:22px;font-weight:800;color:var(--gt-white);margin:0 0 10px}
.gt-pro-gate p{font-size:14px;color:var(--gt-soft);margin:0 0 24px;max-width:480px;display:inline-block}
.gt-pro-gate .gt-flex{gap:12px}

/* ── Button secondary ── */
.gt-btn-secondary{background:rgba(255,255,255,0.08);color:var(--gt-white)!important;border:1px solid var(--gt-border-md)}
.gt-btn-secondary:hover{background:rgba(255,255,255,0.14);color:var(--gt-white)!important}

/* ── Page header ── */
.gt-page-header{display:flex;align-items:flex-start;justify-content:space-between;margin-bottom:28px;gap:16px;flex-wrap:wrap}
.gt-page-title{font-size:28px;font-weight:800;color:var(--gt-white);margin:0 0 5px;letter-spacing:-0.5px}
.gt-page-subtitle,.gt-page-sub{font-size:14px;color:var(--gt-soft);margin:0}
.gt-page-actions{display:flex;gap:10px;align-items:center;flex-wrap:wrap}

/* ── Card header ── */
.gt-card-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:20px;padding-bottom:16px;border-bottom:1px solid var(--gt-border)}

/* ── Animate in ── */
.gt-animate-in{animation:gt-fadein 0.35s ease forwards}

/* ── Text utils ── */
.gt-text-center{text-align:center}
.gt-text-white{color:var(--gt-white)!important}
.gt-text-soft{color:var(--gt-soft)!important}
.gt-text-sm{font-size:15px}
.gt-text-xs{font-size:11px}

/* ── Form utils ── */
.gt-form-group{margin-bottom:20px}
.gt-form-label{display:block;font-size:13px;font-weight:600;color:var(--gt-white);margin-bottom:8px}
.gt-form-hint{font-size:13px;color:var(--gt-soft);margin-top:5px}
.gt-feature-grid{display:grid;gap:16px}
.gt-feature-grid--2col{grid-template-columns:repeat(2,1fr)}
@media(max-width:700px){.gt-feature-grid--2col{grid-template-columns:1fr}}

/* ── Space vars ── */
:root{
	--gt-space-xs:4px;--gt-space-sm:8px;--gt-space-md:16px;
	--gt-space-lg:24px;--gt-space-xl:32px;--gt-space-2xl:48px;
}

/* ── Section labels ── */
.gt-section-label{font-size:10px;font-weight:700;letter-spacing:1.5px;text-transform:uppercase;color:var(--gt-subtle);margin-bottom:8px}

/* ── Settings rows ── */
.gt-setting-row{display:flex;align-items:center;justify-content:space-between;padding:16px 0;border-bottom:1px solid var(--gt-border);gap:16px}
.gt-setting-row:last-child{border-bottom:none}
.gt-setting-label{font-size:14px;font-weight:600;color:var(--gt-white)}
.gt-setting-desc{font-size:13px;color:var(--gt-soft);margin-top:3px}

/* ── Code blocks ── */
code{background:rgba(255,255,255,0.06);border:1px solid var(--gt-border);color:#e2e8f0;padding:2px 6px;border-radius:4px;font-family:'DM Mono','Courier New',monospace;font-size:12px}

/* ── Import/Export ── */
.gt-import-zone{border:2px dashed var(--gt-border-md);border-radius:var(--gt-r-lg);padding:40px;text-align:center;transition:border-color 0.2s}
.gt-import-zone:hover{border-color:var(--gt-red)}
.gt-import-zone h3{color:var(--gt-white);margin:12px 0 6px}
.gt-import-zone p{color:var(--gt-soft);font-size:13px;margin:0}

/* ── Documentation ── */
.gt-doc-section{margin-bottom:32px}
.gt-doc-section h2{font-size:18px;font-weight:700;color:var(--gt-white);margin:0 0 12px;padding-bottom:10px;border-bottom:1px solid var(--gt-border)}
.gt-doc-section h3{font-size:15px;font-weight:600;color:var(--gt-white);margin:20px 0 8px}
.gt-doc-section p,.gt-doc-section li{font-size:14px;color:var(--gt-soft);line-height:1.7}
.gt-doc-section ul,.gt-doc-section ol{padding-left:20px;color:var(--gt-soft)}
.gt-doc-section strong{color:var(--gt-white)}
.gt-doc-section a{color:var(--gt-red);text-decoration:none}
.gt-doc-section a:hover{text-decoration:underline}

/* ── Welcome page ── */
.gt-welcome-hero{text-align:center;padding:48px 24px}
.gt-welcome-hero h1{font-size:36px;font-weight:900;color:var(--gt-white);margin:0 0 12px}
.gt-welcome-hero p{font-size:16px;color:var(--gt-soft);max-width:560px;margin:0 auto 32px}
.gt-step-card{background:var(--gt-card);border:1px solid var(--gt-border);border-radius:var(--gt-r-lg);padding:24px;text-align:center}
.gt-step-card h3{font-size:15px;font-weight:700;color:var(--gt-white);margin:12px 0 6px}
.gt-step-card p{font-size:13px;color:var(--gt-soft);margin:0}
.gt-step-num{width:32px;height:32px;border-radius:50%;background:var(--gt-red);color:#fff;font-weight:800;font-size:14px;display:flex;align-items:center;justify-content:center;margin:0 auto}

/* ── License page ── */
.gt-license-input-wrap{position:relative}
.gt-license-input-wrap .gt-input{padding-right:120px;font-family:'DM Mono','Courier New',monospace;letter-spacing:1px}
.gt-license-status-card{padding:20px;border-radius:var(--gt-r-lg);margin-bottom:20px}
.gt-license-status-card h3{font-size:16px;font-weight:700;color:var(--gt-white);margin:0 0 6px}
.gt-license-status-card p{font-size:13px;color:var(--gt-soft);margin:0}

/* ── Dashboard stat cards ── */
.gt-stat-label{font-size:10px;font-weight:700;letter-spacing:1px;text-transform:uppercase;color:var(--gt-soft);margin-bottom:6px}
.gt-stat-value{font-size:28px;font-weight:800;color:var(--gt-white);font-family:'DM Mono','Courier New',monospace;letter-spacing:-1px}
.gt-stat-trend{font-size:11px;color:var(--gt-subtle);margin-top:4px}

/* ── Activity feed ── */
.gt-feed-item{display:flex;align-items:center;gap:12px;padding:12px 0;border-bottom:1px solid rgba(255,255,255,0.03)}
.gt-feed-item:last-child{border-bottom:none}
.gt-feed-icon{width:32px;height:32px;border-radius:8px;background:rgba(255,255,255,0.04);display:flex;align-items:center;justify-content:center;font-size:14px;flex-shrink:0}
.gt-feed-text{flex:1;font-size:13px;color:var(--gt-white)}
.gt-feed-sub{font-size:11px;color:var(--gt-subtle);margin-top:2px}
.gt-feed-time{font-size:11px;color:var(--gt-subtle);white-space:nowrap}

/* ── PRO packs vault ── */
.gt-vault-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:20px;overflow:hidden}
.gt-pack-card{background:rgba(255,255,255,0.02);border:1px solid rgba(255,255,255,0.06);border-radius:12px;padding:20px;transition:all 0.2s;display:flex;flex-direction:column;overflow:hidden;word-break:break-word;min-width:0}
.gt-pack-card:hover{background:rgba(255,255,255,0.04);border-color:rgba(225,0,0,0.2);transform:translateY(-2px)}
.gt-pack-card-top{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}
.gt-pack-icon{font-size:24px}
.gt-pack-name{color:var(--gt-white);font-size:15px;font-weight:600;margin:0 0 8px}
.gt-pack-desc{color:var(--gt-soft);font-size:13px;line-height:1.5;margin:0;flex:1}
.gt-pack-actions{margin-top:16px}

/* ── Modal ── */
.gt-modal h3{color:var(--gt-white)!important}
.gt-modal p{color:var(--gt-soft)!important}
.gt-modal label{color:var(--gt-white)!important}

/* ── Tables ── */
.gt-table th{color:var(--gt-subtle)!important}
.gt-table td{color:var(--gt-white)!important}
.gt-table td a{color:var(--gt-white)!important}
.gt-table td strong{color:var(--gt-white)!important}

/* ── All headings white ── */
.gt-card h1,.gt-card h2,.gt-card h3,.gt-card h4{color:var(--gt-white)!important}
.gt-card p{color:var(--gt-soft)}
.gt-card label{color:var(--gt-white)}
.gt-card strong{color:var(--gt-white)}
select.gt-select option{background:var(--gt-card);color:var(--gt-white)}

/* ── Brand strip ── */
.gt-brand-strip{
	display:flex;align-items:center;justify-content:space-between;
	padding:10px 16px;margin:-32px -36px 28px;
	background:linear-gradient(90deg,rgba(225,0,0,0.08) 0%,rgba(7,12,28,0.6) 50%,rgba(225,0,0,0.04) 100%);
	border-bottom:1px solid rgba(225,0,0,0.15);
	flex-wrap:wrap;gap:8px;
}
.gt-brand-strip-left{display:flex;align-items:center;gap:10px}
.gt-brand-strip-name{font-size:12px;font-weight:800;letter-spacing:1.5px;color:var(--gt-white);text-transform:uppercase}
.gt-brand-strip-edition{font-size:10px;font-weight:700;letter-spacing:1px;color:var(--gt-red);text-transform:uppercase;padding:2px 8px;border-radius:50px;border:1px solid rgba(225,0,0,0.3);background:rgba(225,0,0,0.08)}
.gt-brand-strip-right{display:flex;align-items:center;gap:10px}
.gt-brand-strip-badge{font-size:10px;font-weight:700;letter-spacing:0.8px;padding:3px 10px;border-radius:50px;text-transform:uppercase}
.gt-brand-strip-badge.pro{background:rgba(34,197,94,0.1);border:1px solid rgba(34,197,94,0.05);color:#86efac}
.gt-brand-strip-badge.warn{background:rgba(245,158,11,0.1);border:1px solid rgba(245,158,11,0.25);color:#fcd34d}
.gt-brand-strip-badge.upgrade{background:rgba(225,0,0,0.1);border:1px solid rgba(225,0,0,0.3);color:#fca5a5;text-decoration:none}
.gt-brand-strip-badge.upgrade:hover{background:rgba(225,0,0,0.2);color:#fff}
.gt-brand-strip-ver{font-size:10px;color:var(--gt-subtle);font-family:'DM Mono','Courier New',monospace}

/* ── Responsive ── */
@media (max-width:1024px){
	.gt-metrics{grid-template-columns:repeat(2,1fr)}
	.gt-vault-grid{grid-template-columns:repeat(2,1fr)}
	.gt-grid-3{grid-template-columns:repeat(2,1fr)}
}
@media (max-width:768px){
	.gt-sidebar{display:none}
	.gt-main{padding:16px}
	.gt-metrics{grid-template-columns:1fr 1fr}
	.gt-vault-grid{grid-template-columns:1fr}
}

/* ── ROI chart container ── */
.gt-chart-wrap{position:relative;height:220px}

/* ── GLOBAL TEXT OVERRIDE — all body text white, min 15px ── */
.gt-main p, .gt-main span, .gt-main label, .gt-main div,
.gt-main li, .gt-main td, .gt-main th {
	color: #ffffff;
}
.gt-main p[style*="color:var(--gt-subtle)"],
.gt-main p[style*="color:var(--gt-soft)"],
.gt-main span[style*="color:var(--gt-subtle)"],
.gt-main span[style*="color:var(--gt-soft)"] {
	color: #ffffff !important;
}
.gt-main p { font-size: 15px !important; line-height: 1.7; }
.gt-main .gt-setting-desc { font-size: 14px !important; color: #ffffff !important; }
.gt-main .gt-form-hint { font-size: 13px !important; color: #e2e8f0 !important; }
.gt-soft { color: #ffffff !important; }
.gt-subtle { color: #e2e8f0 !important; }
.gt-text-soft { color: #e2e8f0 !important; }
</style>
<script>
// GT BOGO — kill admin bar flash
document.addEventListener('DOMContentLoaded', function() {
	document.body.classList.add('gt-bogo-ready');
});

// GT BOGO — cross-page settings sync via localStorage
(function() {
	// Broadcast a superpower state change to all open plugin tabs
	window.gtBogoSPBroadcast = function(sp_id, enabled) {
		try {
			localStorage.setItem('gtbogo_sp_change', JSON.stringify({
				sp: sp_id, enabled: enabled, ts: Date.now()
			}));
		} catch(e) {}
	};

	// Listen for changes from other tabs/pages
	window.addEventListener('storage', function(e) {
		if (e.key !== 'gtbogo_sp_change') return;
		try {
			var d = JSON.parse(e.newValue);
			if (!d || !d.sp) return;
			// Update any matching toggles on this page
			document.querySelectorAll('[data-sp="' + d.sp + '"]').forEach(function(el) {
				if (el.type === 'checkbox' && el.checked !== d.enabled) {
					el.checked = d.enabled;
					var row = el.closest('[style*="justify-content:space-between"]');
					if (row) row.style.opacity = d.enabled ? '1' : '0.6';
				}
			});
		} catch(e) {}
	});

	// Prevent toggle scroll-jump: blur hidden checkbox immediately after change
	document.addEventListener('change', function(e) {
		if (e.target && e.target.closest && e.target.closest('.gt-toggle')) {
			setTimeout(function() { if (document.activeElement) document.activeElement.blur(); }, 0);
		}
	}, true);

	// ── Toggle save confirmation pill ─────────────────────────────────────────
	// Injects a branded pill anchored to the toggle, animates in/out, zero layout impact
	(function() {
		// Inject keyframe animation once
		var styleId = 'gt-toggle-tick-style';
		if (!document.getElementById(styleId)) {
			var s = document.createElement('style');
			s.id = styleId;
			s.textContent = [
				'@keyframes gtTickIn{',
				'  0%  {opacity:0;transform:translateX(-6px) scale(.7)}',
				'  60% {opacity:1;transform:translateX(2px) scale(1.05)}',
				'  100%{opacity:1;transform:translateX(0) scale(1)}',
				'}',
				'@keyframes gtTickOut{',
				'  0%  {opacity:1;transform:translateX(0) scale(1)}',
				'  100%{opacity:0;transform:translateX(4px) scale(.8)}',
				'}',
				'.gt-save-pill{',
				'  position:fixed;z-index:99999;pointer-events:none;',
				'  display:inline-flex;align-items:center;gap:4px;',
				'  background:linear-gradient(135deg,#14532d,#166534);',
				'  border:1px solid #22c55e;border-radius:999px;',
				'  padding:3px 8px 3px 6px;',
				'  font-size:11px;font-weight:700;color:#bbf7d0;',
				'  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;',
				'  box-shadow:0 2px 12px rgba(34,197,94,.25),0 0 0 1px rgba(34,197,94,.1);',
				'  white-space:nowrap;',
				'  animation:gtTickIn .22s cubic-bezier(.34,1.56,.64,1) forwards;',
				'}',
				'.gt-save-pill.gt-out{animation:gtTickOut .18s ease-in forwards;}',
				'.gt-save-pill svg{flex-shrink:0}'
			].join('');
			document.head.appendChild(s);
		}

		document.addEventListener('change', function(e) {
			var input = e.target;
			if (!input || !input.closest) return;
			var label = input.closest('.gt-toggle');
			if (!label) return;

			var rect = label.getBoundingClientRect();
			var pill = document.createElement('span');
			pill.className = 'gt-save-pill';
			pill.innerHTML = '<svg width="10" height="10" viewBox="0 0 10 10" fill="none">'
				+ '<path d="M1.5 5.5L4 8L8.5 2.5" stroke="#4ade80" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/>'
				+ '</svg>Saved';

			// Anchor: vertically centred on toggle, 8px gap to its right
			pill.style.left = (rect.right + 8) + 'px';
			pill.style.top  = (rect.top + rect.height / 2 - 12) + 'px';

			document.body.appendChild(pill);

			// Animate out then remove
			setTimeout(function() {
				pill.classList.add('gt-out');
				setTimeout(function() {
					if (pill.parentNode) pill.parentNode.removeChild(pill);
				}, 200);
			}, 900);
		});
	})();
})();
</script>


<div class="gt-shell">
	<!-- ═══ SIDEBAR ═══ -->
	<aside class="gt-sidebar">

	<a href="<?php echo esc_url( admin_url( 'admin.php?page=gt-bogo-engine' ) ); ?>" class="gt-brand">
		<div class="gt-brand-icon" style="background:none;box-shadow:none;padding:0;overflow:hidden;border-radius:10px;flex-shrink:0"><img src="<?php echo esc_url( $_gt_url ); ?>assets/images/icon-256x256.png" width="52" height="52" style="display:block;border-radius:10px;" alt="GT BOGO"></div>
		<div class="gt-brand-text">
		<span class="gt-brand-name" style="font-size:15px;letter-spacing:2px;font-weight:900">GT BOGO ENGINE</span>
		<span class="gt-brand-sub" style="font-size:10px;color:#E10000;letter-spacing:1.5px;font-weight:800">PRO EDITION</span>
		</div>
	</a>

	<div class="gt-lic-pill <?php echo esc_html( $_gt_is_pro ) ? 'pro' : 'free'; ?>">
		<span class="gt-pulse <?php echo esc_html( $_gt_is_pro ) ? '' : 'gray'; ?>"></span>
		<?php if ( $_gt_is_pro ) : ?>
		<span>PRO Active</span>
			<?php if ( $_gt_days > 0 && $_gt_days <= 30 ) : ?>
			<span style="margin-left:auto;font-size:10px;color:var(--gt-yellow)"><?php echo (int) $_gt_days; ?>d left</span>
		<?php endif; ?>
		<?php else : ?>
		<span style="color:#ffffff;font-weight:600;">Free Plan</span>
		<a href="<?php echo esc_url( admin_url( 'admin.php?page=gt-bogo-engine&tab=license' ) ); ?>" style="margin-left:auto;color:var(--gt-red);font-size:10px;font-weight:800;text-decoration:none">UPGRADE</a>
		<?php endif; ?>
	</div>

	<nav class="gt-nav-section">
		<p class="gt-nav-sep">MAIN</p>
		<ul class="gt-nav-list">
		<?php
		_gt_nav( 'dashboard', 'Dashboard', '📊' );
		_gt_nav( 'free-rule', 'Free Core Rule', '🎁' );
		_gt_nav( 'pack-config', 'Rule Editor', '✏️', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'superpowers', 'Superpowers', '⚡', $_gt_is_pro ? '' : 'PRO' );

		?>
		</ul>

		<p class="gt-nav-sep">PACKS</p>
		<ul class="gt-nav-list">
		<?php
		_gt_nav( 'pro-rules', 'PRO Pack Store', '&#128722;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'my-packs', 'My Packs', '&#128230;', $_gt_is_pro ? '' : 'PRO' );
		?>
		</ul>

		<p class="gt-nav-sep">CAMPAIGNS</p>
		<ul class="gt-nav-list">
		<?php
		_gt_nav( 'scheduler', 'Campaign Scheduler', '&#128197;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'segments', 'Customer Segments', '&#127919;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'ab-testing', 'A/B Testing', '&#129514;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'geo-targeting', 'Geo Targeting', '&#127757;', $_gt_is_pro ? '' : 'PRO' );
		?>
		</ul>

		<p class="gt-nav-sep">INTELLIGENCE</p>
		<ul class="gt-nav-list">
		<?php
		_gt_nav( 'ai-settings', 'AI Intelligence', '&#129302;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'analytics', 'Analytics', '&#128201;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'customer-intelligence', 'Customer Intel', '&#129504;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'customer-journey', 'Journey Map', '&#128392;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'roi-projector', 'ROI Projector', '&#128200;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'audit-log', 'Audit Log', '&#128269;', $_gt_is_pro ? '' : 'PRO' );
		?>
		</ul>

		<p class="gt-nav-sep">PRECISION</p>
		<ul class="gt-nav-list">
		<?php
		_gt_nav( 'conditions', 'Rule Conditions', '&#127771;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'conflicts', 'Conflict Resolver', '&#9876;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'deal-lockout', 'Deal Lockout', '&#128274;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'variant-rules', 'Variant Rules', '&#127912;', $_gt_is_pro ? '' : 'PRO' );
		?>
		</ul>

		<p class="gt-nav-sep">GROWTH</p>
		<ul class="gt-nav-list">
		<?php
		_gt_nav( 'deal-page', 'Deal Page', '&#128717;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'multi-currency', 'Multi-Currency', '&#128178;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'rest-api', 'REST API', '&#128279;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'pdf-export', 'PDF Export', '&#128196;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'integrations', 'Integrations', '&#128268;', $_gt_is_pro ? '' : 'PRO' );
		_gt_nav( 'white-label', 'White Label', '&#127991;', $_gt_is_pro ? '' : 'PRO' );
		?>
		</ul>

		<p class="gt-nav-sep">TOOLS</p>
		<ul class="gt-nav-list">
		<?php
		_gt_nav( 'settings', 'Settings', '&#9881;' );
		_gt_nav( 'import-export', 'Import / Export', '&#128260;' );
		_gt_nav( 'license', 'License', $_gt_is_pro ? '&#9989;' : '&#128273;' );
		_gt_nav( 'store-health', 'Health Monitor', '&#127973;' );
		_gt_nav( 'store-status', 'Store Status', '&#128640;' );
		_gt_nav( 'system-status', 'System Status', '&#128421;' );
		_gt_nav( 'documentation', 'Documentation', '&#128218;' );
		_gt_nav( 'welcome', 'Welcome', '&#128075;' );
		?>
		</ul>
	</nav>
	<?php if ( ! $_gt_is_pro ) : ?>
	<div class="gt-upgrade-box">
		<h4>Unlock PRO Features</h4>
		<p>PRO Packs, stackable rules &amp; advanced analytics.</p>
		<a href="<?php echo esc_url( admin_url( 'admin.php?page=gt-bogo-engine&tab=license' ) ); ?>" class="gt-upgrade-btn">Activate PRO &mdash; $499/yr</a>
	</div>
	<?php endif; ?>

	<div class="gt-sidebar-foot">
		<div class="gt-sidebar-ver">v<?php echo esc_html( $_gt_ver ); ?> · <a href="https://graphictshirts.shop" target="_blank" rel="noopener" style="color:var(--gt-white);text-decoration:none;font-weight:800;letter-spacing:1px;font-size:11px;font-family:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif">GRAPHIC T-SHIRTS</a></div>
	</div>

	</aside>

	<!-- ═══ MAIN CONTENT ═══ -->
	<main class="gt-main">
	<!-- ── GT Brand Strip — consistent on every page ── -->
	<div class="gt-brand-strip">
		<div class="gt-brand-strip-left">
			<img src="<?php echo esc_url( $_gt_url ); ?>assets/images/icon-128x128.png" width="28" height="28" style="border-radius:6px;display:block" alt="">
			<div style="display:flex;flex-direction:column;gap:1px;line-height:1">
				<span class="gt-brand-strip-name" style="font-size:13px;font-weight:900;letter-spacing:2px;color:#ffffff">GT BOGO ENGINE</span>
				<span class="gt-brand-strip-edition" style="font-size:9px;letter-spacing:1.5px;color:#E10000;font-weight:800">PRO EDITION</span>
			</div>
		</div>
		<div class="gt-brand-strip-right">
			<?php if ( $_gt_is_pro ) : ?>
			<span class="gt-brand-strip-badge pro">⚡ PRO ACTIVE</span>
				<?php if ( $_gt_days > 0 && $_gt_days <= 30 ) : ?>
			<span class="gt-brand-strip-badge warn">⚠ Expires in <?php echo esc_html( $_gt_days ); ?> days</span>
			<?php endif; ?>
			<?php else : ?>
			<a href="https://graphictshirts.shop/bogo/" target="_blank" rel="noopener" class="gt-brand-strip-badge upgrade">🔒 Upgrade to PRO</a>
			<?php endif; ?>
			<span class="gt-brand-strip-ver">v<?php echo esc_html( $_gt_ver ); ?></span>
		</div>
	</div>

<!-- ── GT BOGO Enterprise Product/Category Picker Modal ──────────────────── -->
<div id="gtbogo-product-picker" style="display:none;position:fixed;inset:0;z-index:999999;background:rgba(0,0,0,0.8);align-items:center;justify-content:center">
	<div style="background:#0f172a;border:1px solid rgba(255,255,255,0.08);border-radius:16px;width:min(900px,96vw);max-height:90vh;display:flex;flex-direction:column;box-shadow:0 25px 80px rgba(0,0,0,0.7)">
	<div style="display:flex;align-items:center;justify-content:space-between;padding:20px 24px;border-bottom:1px solid rgba(255,255,255,0.06)">
		<div>
		<div style="font-size:16px;font-weight:800;color:#fff" id="gtpicker-title">Select Products</div>
		<div style="font-size:12px;color:#64748b;margin-top:2px" id="gtpicker-subtitle">Search and select products to include in this rule</div>
		</div>
		<button onclick="gtPickerClose()" style="background:rgba(255,255,255,0.06);border:none;color:#94a3b8;width:32px;height:32px;border-radius:8px;cursor:pointer;font-size:18px;line-height:1">&times;</button>
	</div>
	<div style="display:flex;align-items:center;gap:10px;padding:14px 24px;border-bottom:1px solid rgba(255,255,255,0.06);flex-wrap:wrap">
		<div style="flex:1;min-width:200px;position:relative">
		<input type="text" id="gtpicker-search" placeholder="Search by name or SKU..."
			style="width:100%;padding:8px 12px 8px 36px;background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.1);border-radius:8px;color:#fff;font-size:13px;box-sizing:border-box;outline:none"
			oninput="gtPickerSearch(this.value)">
		<span style="position:absolute;left:11px;top:50%;transform:translateY(-50%);color:#64748b">🔍</span>
		</div>
		<select id="gtpicker-category" onchange="gtPickerFilterCat(this.value)"
		style="padding:8px 12px;background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.1);border-radius:8px;color:#fff;font-size:13px;min-width:160px">
		<option value="">All Categories</option>
		</select>
		<select id="gtpicker-perpage" onchange="gtPickerSetPerPage(this.value)"
		style="padding:8px 12px;background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.1);border-radius:8px;color:#fff;font-size:13px">
		<option value="20">20 per page</option>
		<option value="50">50 per page</option>
		</select>
		<button onclick="gtPickerSelectPage()"
		style="padding:8px 14px;background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.1);border-radius:8px;color:#94a3b8;font-size:12px;cursor:pointer;white-space:nowrap">Select Page</button>
		<button onclick="gtPickerClearAll()"
		style="padding:8px 14px;background:rgba(239,68,68,0.08);border:1px solid rgba(239,68,68,0.15);border-radius:8px;color:#fca5a5;font-size:12px;cursor:pointer">Clear All</button>
	</div>
	<div style="display:flex;flex:1;overflow:hidden;min-height:0">
		<div style="flex:1;overflow-y:auto;padding:16px 24px" id="gtpicker-grid">
		<div style="color:#64748b;text-align:center;padding:40px">Loading...</div>
		</div>
		<div style="width:220px;border-left:1px solid rgba(255,255,255,0.06);display:flex;flex-direction:column;flex-shrink:0">
		<div style="padding:12px 16px;border-bottom:1px solid rgba(255,255,255,0.06);font-size:12px;font-weight:700;color:#64748b;text-transform:uppercase;letter-spacing:.8px">
			Selected <span id="gtpicker-count" style="color:#E10000">0</span>
		</div>
		<div id="gtpicker-selected-list" style="flex:1;overflow-y:auto;padding:8px">
			<div style="color:#475569;font-size:12px;padding:12px;text-align:center">Nothing selected</div>
		</div>
		</div>
	</div>
	<div style="display:flex;align-items:center;justify-content:space-between;padding:14px 24px;border-top:1px solid rgba(255,255,255,0.06)">
		<div style="display:flex;align-items:center;gap:8px">
		<button onclick="gtPickerPage(-1)" id="gtpicker-prev"
			style="padding:6px 14px;background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.1);border-radius:6px;color:#94a3b8;cursor:pointer;font-size:13px">Prev</button>
		<span id="gtpicker-pageinfo" style="font-size:12px;color:#64748b">—</span>
		<button onclick="gtPickerPage(1)" id="gtpicker-next"
			style="padding:6px 14px;background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.1);border-radius:6px;color:#94a3b8;cursor:pointer;font-size:13px">Next</button>
		</div>
		<div style="display:flex;gap:10px">
		<button onclick="gtPickerClose()"
			style="padding:8px 20px;background:transparent;border:1px solid rgba(255,255,255,0.1);border-radius:8px;color:#64748b;cursor:pointer;font-size:13px">Cancel</button>
		<button onclick="gtPickerConfirm()"
			style="padding:8px 24px;background:#E10000;border:none;border-radius:8px;color:#fff;font-weight:700;cursor:pointer;font-size:13px">Apply Selection</button>
		</div>
	</div>
	</div>
</div>

<script>
var gtPicker={nonce:'',ajaxUrl:'',mode:'products',selected:{},page:1,pages:1,perPage:20,search:'',catFilter:'',searchTimer:null,callback:null};

function gtPickerOpen(opts){
	gtPicker.nonce=opts.nonce||'';gtPicker.ajaxUrl=opts.ajaxUrl||'';
	gtPicker.mode=opts.mode||'products';gtPicker.callback=opts.callback||null;
	gtPicker.selected={};gtPicker.page=1;gtPicker.search='';gtPicker.catFilter='';
	if(opts.existingIds)opts.existingIds.forEach(function(i){gtPicker.selected[i.id]=i;});
	var m=document.getElementById('gtbogo-product-picker');m.style.display='flex';
	document.getElementById('gtpicker-title').textContent=opts.mode==='categories'?'Select Categories':'Select Products';
	document.getElementById('gtpicker-subtitle').textContent=opts.mode==='categories'?'Select product categories for this rule':'Search and select products — bulk selection supported';
	document.getElementById('gtpicker-search').value='';
	var catSel=document.getElementById('gtpicker-category');
	if(opts.mode==='categories'){catSel.style.display='none';gtPickerLoadCategories();}
	else{catSel.style.display='';gtPickerLoadCategoryFilter();gtPickerLoad();}
	gtPickerRenderSelected();
}

function gtPickerClose(){document.getElementById('gtbogo-product-picker').style.display='none';}

function gtPickerLoad(){
	var grid=document.getElementById('gtpicker-grid');
	grid.innerHTML='<div style="color:#64748b;text-align:center;padding:40px">Loading...</div>';
	var fd=new FormData();
	fd.append('action','gtbogo_search_products');fd.append('nonce',gtPicker.nonce);
	fd.append('search',gtPicker.search);fd.append('page',gtPicker.page);
	fd.append('per_page',gtPicker.perPage);fd.append('category_id',gtPicker.catFilter);
	fetch(gtPicker.ajaxUrl,{method:'POST',body:fd,credentials:'same-origin'})
	.then(function(r){return r.json();})
	.then(function(res){
	if(!res.success){grid.innerHTML='<div style="color:#ef4444;padding:20px">Error loading products.</div>';return;}
	var d=res.data;gtPicker.pages=d.pages||1;
	gtPickerRenderGrid(d.products||[]);
	document.getElementById('gtpicker-pageinfo').textContent='Page '+gtPicker.page+' of '+gtPicker.pages+' ('+parseInt(d.total||0).toLocaleString()+' total)';
	document.getElementById('gtpicker-prev').disabled=gtPicker.page<=1;
	document.getElementById('gtpicker-next').disabled=gtPicker.page>=gtPicker.pages;
	});
}

function gtPickerLoadCategories(){
	var grid=document.getElementById('gtpicker-grid');
	grid.innerHTML='<div style="color:#64748b;text-align:center;padding:40px">Loading categories...</div>';
	var fd=new FormData();fd.append('action','gtbogo_search_categories');fd.append('nonce',gtPicker.nonce);fd.append('search',gtPicker.search);
	fetch(gtPicker.ajaxUrl,{method:'POST',body:fd,credentials:'same-origin'})
	.then(function(r){return r.json();})
	.then(function(res){
	if(!res.success)return;
	var html='<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:8px">';
	(res.data.categories||[]).forEach(function(c){
		var sel=!!gtPicker.selected[c.id];
		html+='<div onclick="gtPickerToggle('+JSON.stringify(c)+')" id="gtpicker-item-'+c.id+'" style="display:flex;align-items:center;gap:10px;padding:10px 14px;border-radius:8px;cursor:pointer;background:'+(sel?'rgba(225,0,0,0.08)':'rgba(255,255,255,0.02)')+';border:1px solid '+(sel?'rgba(225,0,0,0.25)':'rgba(255,255,255,0.06)')+'">'
		+'<div style="width:18px;height:18px;border-radius:4px;border:1.5px solid '+(sel?'#E10000':'#475569')+';background:'+(sel?'#E10000':'transparent')+';display:flex;align-items:center;justify-content:center;flex-shrink:0">'+(sel?'<span style="color:#fff;font-size:10px;font-weight:700">✓</span>':'')+'</div>'
		+'<div style="min-width:0"><div style="font-size:13px;font-weight:600;color:#fff;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">'+c.name+'</div><div style="font-size:11px;color:#64748b">'+c.count+' products</div></div></div>';
	});
	html+='</div>';grid.innerHTML=html;
	});
}

function gtPickerLoadCategoryFilter(){
	var sel=document.getElementById('gtpicker-category');
	var fd=new FormData();fd.append('action','gtbogo_search_categories');fd.append('nonce',gtPicker.nonce);
	fetch(gtPicker.ajaxUrl,{method:'POST',body:fd,credentials:'same-origin'})
	.then(function(r){return r.json();})
	.then(function(res){
	if(!res.success)return;
	var opts='<option value="">All Categories</option>';
	(res.data.categories||[]).forEach(function(c){opts+='<option value="'+c.id+'">'+c.name+' ('+c.count+')</option>';});
	sel.innerHTML=opts;
	});
}

function gtPickerRenderGrid(products){
	var grid=document.getElementById('gtpicker-grid');
	if(!products.length){grid.innerHTML='<div style="color:#64748b;text-align:center;padding:40px">No products found.</div>';return;}
	var html='<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(155px,1fr));gap:8px">';
	products.forEach(function(p){
	var sel=!!gtPicker.selected[p.id];
	html+='<div onclick="gtPickerToggle('+JSON.stringify(p)+')" id="gtpicker-item-'+p.id+'" style="position:relative;border-radius:8px;cursor:pointer;background:'+(sel?'rgba(225,0,0,0.08)':'rgba(255,255,255,0.02)')+';border:1.5px solid '+(sel?'#E10000':'rgba(255,255,255,0.06)')+';padding:10px;transition:border-color .15s">'
		+'<div style="position:absolute;top:8px;right:8px;width:18px;height:18px;border-radius:4px;border:1.5px solid '+(sel?'#E10000':'#475569')+';background:'+(sel?'#E10000':'transparent')+';display:flex;align-items:center;justify-content:center">'+(sel?'<span style="color:#fff;font-size:10px;font-weight:700">✓</span>':'')+'</div>'
		+(p.image?'<img src="'+p.image+'" style="width:100%;aspect-ratio:1;object-fit:cover;border-radius:6px;margin-bottom:8px" loading="lazy">':'')
		+'<div style="font-size:12px;font-weight:600;color:#fff;line-height:1.3;margin-bottom:3px;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical">'+p.name+'</div>'
		+(p.sku?'<div style="font-size:10px;color:#64748b">'+p.sku+'</div>':'')
		+'<div style="font-size:12px;font-weight:700;color:#86efac;margin-top:4px">'+p.price+'</div>'
		+'<div style="font-size:10px;color:'+(p.stock==='instock'?'#86efac':'#fca5a5')+'">'+p.stock+'</div>'
		+'</div>';
	});
	html+='</div>';grid.innerHTML=html;
}

function gtPickerToggle(item){
	if(gtPicker.selected[item.id]){delete gtPicker.selected[item.id];}
	else{gtPicker.selected[item.id]=item;}
	var el=document.getElementById('gtpicker-item-'+item.id);
	if(el){
	var sel=!!gtPicker.selected[item.id];
	el.style.background=sel?'rgba(225,0,0,0.08)':'rgba(255,255,255,0.02)';
	el.style.borderColor=sel?'#E10000':'rgba(255,255,255,0.06)';
	var cb=el.querySelector('[style*="width:18px"]');
	if(cb){cb.style.background=sel?'#E10000':'transparent';cb.style.borderColor=sel?'#E10000':'#475569';cb.innerHTML=sel?'<span style="color:#fff;font-size:10px;font-weight:700">✓</span>':'';}
	}
	gtPickerRenderSelected();
}

function gtPickerRenderSelected(){
	var list=document.getElementById('gtpicker-selected-list');
	var count=Object.keys(gtPicker.selected).length;
	document.getElementById('gtpicker-count').textContent=count;
	if(!count){list.innerHTML='<div style="color:#475569;font-size:12px;padding:12px;text-align:center">Nothing selected</div>';return;}
	var html='';
	Object.values(gtPicker.selected).forEach(function(item){
	html+='<div style="display:flex;align-items:center;justify-content:space-between;padding:5px 8px;border-radius:5px;margin-bottom:2px;background:rgba(255,255,255,0.03)">'
		+'<span style="font-size:11px;color:#e2e8f0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:150px">'+item.name+'</span>'
		+'<button onclick="gtPickerToggle('+JSON.stringify(item)+')" style="background:none;border:none;color:#ef4444;cursor:pointer;font-size:14px;padding:0;margin-left:4px;flex-shrink:0">&times;</button>'
		+'</div>';
	});
	list.innerHTML=html;
}

function gtPickerSelectPage(){
	document.querySelectorAll('#gtpicker-grid [id^="gtpicker-item-"]').forEach(function(el){
	var id=parseInt(el.id.replace('gtpicker-item-',''));
	if(!gtPicker.selected[id]){
		var nameEl=el.querySelector('[style*="-webkit-line-clamp"]')||el.querySelector('[style*="font-weight:600"]');
		var name=nameEl?nameEl.textContent.trim():'Product '+id;
		gtPickerToggle({id:id,name:name});
	}
	});
}

function gtPickerClearAll(){
	gtPicker.selected={};
	document.querySelectorAll('#gtpicker-grid [id^="gtpicker-item-"]').forEach(function(el){
	el.style.background='rgba(255,255,255,0.02)';el.style.borderColor='rgba(255,255,255,0.06)';
	var cb=el.querySelector('[style*="width:18px"]');
	if(cb){cb.style.background='transparent';cb.style.borderColor='#475569';cb.innerHTML='';}
	});
	gtPickerRenderSelected();
}

function gtPickerSearch(val){
	clearTimeout(gtPicker.searchTimer);gtPicker.search=val;
	gtPicker.searchTimer=setTimeout(function(){gtPicker.page=1;gtPicker.mode==='categories'?gtPickerLoadCategories():gtPickerLoad();},350);
}
function gtPickerFilterCat(val){gtPicker.catFilter=val;gtPicker.page=1;gtPickerLoad();}
function gtPickerSetPerPage(val){gtPicker.perPage=parseInt(val);gtPicker.page=1;gtPickerLoad();}
function gtPickerPage(dir){gtPicker.page=Math.max(1,Math.min(gtPicker.pages,gtPicker.page+dir));gtPickerLoad();}
function gtPickerConfirm(){if(gtPicker.callback)gtPicker.callback(Object.values(gtPicker.selected));gtPickerClose();}

document.addEventListener('DOMContentLoaded',function(){
	var m=document.getElementById('gtbogo-product-picker');
	if(m)m.addEventListener('click',function(e){if(e.target===this)gtPickerClose();});
});
</script>
