<?php
/**
 * Admin Settings Page Template
 */
if (!defined('ABSPATH')) {
	exit;
}

function podcastmaker_render_settings_page()
{
	// Get current tab
	// phpcs:ignore WordPress.Security.NonceVerification.Recommended
	$active_tab = isset($_GET['tab']) ? sanitize_key(wp_unslash($_GET['tab'])) : 'general';
?>

<div class="wrap">
	<h1><?php echo esc_html__('QuikVox AI Settings', 'quikvox-ai'); ?></h1>
	<?php settings_errors(); ?>

	<h2 class="nav-tab-wrapper">
		<a href="?page=Podcastmaker&tab=general" class="nav-tab <?php echo $active_tab == 'general' ? 'nav-tab-active' : ''; ?>"><?php echo esc_html__('General', 'quikvox-ai'); ?></a>
		<a href="?page=Podcastmaker&tab=gemini" class="nav-tab <?php echo $active_tab == 'gemini' ? 'nav-tab-active' : ''; ?>"><?php echo esc_html__('Google AI Studio', 'quikvox-ai'); ?></a>
		<?php if (Podcastmaker_License::is_business()): ?>
			<a href="?page=Podcastmaker&tab=vertex" class="nav-tab <?php echo $active_tab == 'vertex' ? 'nav-tab-active' : ''; ?>"><?php echo esc_html__('Vertex AI', 'quikvox-ai'); ?></a>
		<?php
	else: ?>
			<a href="#" class="nav-tab" style="color: #a7aaad; cursor: not-allowed; pointer-events: none;" title="<?php echo esc_attr__('Business Plan required', 'quikvox-ai'); ?>"><?php echo esc_html__('Vertex AI', 'quikvox-ai'); ?></a>
		<?php
	endif; ?>
		<a href="?page=Podcastmaker&tab=prompts" class="nav-tab <?php echo $active_tab == 'prompts' ? 'nav-tab-active' : ''; ?>"><?php echo esc_html__('Prompt Sets', 'quikvox-ai'); ?></a>
		<a href="#" class="nav-tab" style="color: #a7aaad; cursor: not-allowed; pointer-events: none;" title="<?php echo esc_attr__('Coming Soon', 'quikvox-ai'); ?>"><?php echo esc_html__('Usage', 'quikvox-ai'); ?> <span style="font-size: 10px; font-style: italic;"><?php echo esc_html__('(Coming Soon)', 'quikvox-ai'); ?></span></a>
		<?php if (Podcastmaker_License::is_pro()): ?>
			<a href="?page=Podcastmaker&tab=smart_tone" class="nav-tab <?php echo $active_tab == 'smart_tone' ? 'nav-tab-active' : ''; ?>"><?php echo esc_html__('Smart Tone', 'quikvox-ai'); ?></a>
		<?php endif; ?>
	</h2>

	<?php if ($active_tab !== 'prompts' && $active_tab !== 'smart_tone'): ?>
		<?php
		$vertex_region_groups = array(
			'global' => array(
				'label' => esc_html__('global', 'quikvox-ai'),
				'locations' => array('global'),
			),
			'us' => array(
				'label' => esc_html__('US', 'quikvox-ai'),
				'locations' => array('us-central1', 'us-east1', 'us-east4', 'us-east5', 'us-south1', 'us-west1', 'us-west4'),
			),
			'europe' => array(
				'label' => esc_html__('Europe', 'quikvox-ai'),
				'locations' => array('europe-central2', 'europe-north1', 'europe-southwest1', 'europe-west1', 'europe-west4'),
			),
			'asia' => array(
				'label' => esc_html__('Asia Pacific', 'quikvox-ai'),
				'locations' => array('asia-northeast1'),
			),
		);

		$vertex_location_allowlist = array(
			'text' => array(
				'gemini-3.1-pro-preview' => array('global'),
				'gemini-2.5-pro' => array('global', 'us-central1', 'us-east1', 'us-east4', 'us-east5', 'us-south1', 'us-west1', 'us-west4', 'europe-central2', 'europe-north1', 'europe-southwest1', 'europe-west1', 'europe-west4'),
				'gemini-2.5-flash' => array('global', 'us-central1', 'us-east1', 'us-east4', 'us-east5', 'us-south1', 'us-west1', 'us-west4', 'europe-central2', 'europe-north1', 'europe-southwest1', 'europe-west1', 'europe-west4'),
				'gemini-2.5-flash-lite' => array('global', 'us-central1', 'us-east1', 'us-east4', 'us-east5', 'us-south1', 'us-west1', 'us-west4', 'europe-central2', 'europe-north1', 'europe-southwest1', 'europe-west1', 'europe-west4'),
			),
			'tts' => array(
				'gemini-3.1-flash-tts-preview' => array('global'),
				'gemini-2.5-flash-tts' => array('global', 'us-central1', 'us-east1', 'us-east4', 'us-east5', 'us-south1', 'us-west1', 'us-west4', 'europe-central2', 'europe-north1', 'europe-southwest1', 'europe-west1', 'europe-west4', 'northamerica-northeast1'),
				'gemini-2.5-pro-tts' => array('global', 'us-central1', 'us-east1', 'us-east4', 'us-east5', 'us-south1', 'us-west1', 'us-west4', 'europe-central2', 'europe-north1', 'europe-southwest1', 'europe-west1', 'europe-west4'),
				'gemini-2.5-flash-lite-preview-tts' => array('global', 'us-central1', 'us-east1', 'us-east4', 'us-east5', 'us-south1', 'us-west1', 'us-west4', 'europe-central2', 'europe-north1', 'europe-southwest1', 'europe-west1', 'europe-west4', 'northamerica-northeast1'),
			),
		);

		$vertex_location_is_allowed = static function ($kind, $model_id, $location) use ($vertex_location_allowlist) {
			return isset($vertex_location_allowlist[$kind][$model_id]) && in_array($location, $vertex_location_allowlist[$kind][$model_id], true);
		};

		// Gemini API Models (2026 Current)
		$gemini_models = array(
			'gemini-3.1-pro-preview' => esc_html__('gemini-3.1-pro-preview', 'quikvox-ai'),
			'gemini-3.1-flash-lite-preview' => esc_html__('gemini-3.1-flash-lite-preview', 'quikvox-ai'),
			'gemini-2.5-pro' => esc_html__('gemini-2.5-pro', 'quikvox-ai'),
			'gemini-2.5-flash' => esc_html__('gemini-2.5-flash', 'quikvox-ai'),
		);

		// Vertex AI LLM Models (2026 Current)
		$vertex_llm_models = array(
			'gemini-3.1-pro-preview' => esc_html__('gemini-3.1-pro-preview', 'quikvox-ai'),
			'gemini-2.5-pro' => esc_html__('gemini-2.5-pro', 'quikvox-ai'),
			'gemini-2.5-flash' => esc_html__('gemini-2.5-flash', 'quikvox-ai'),
			'gemini-2.5-flash-lite' => esc_html__('gemini-2.5-flash-lite', 'quikvox-ai'),
		);
		if (!isset($vertex_llm_models[$vertex_text_model])) {
			$vertex_text_model = 'gemini-2.5-flash';
		}

		// Vertex AI Audio (TTS) Models
		$vertex_tts_models = array(
			'gemini-3.1-flash-tts-preview' => esc_html__('gemini-3.1-flash-tts-preview', 'quikvox-ai'),
			'gemini-2.5-flash-tts' => esc_html__('gemini-2.5-flash-tts', 'quikvox-ai'),
			'gemini-2.5-pro-tts' => esc_html__('gemini-2.5-pro-tts', 'quikvox-ai'),
			'gemini-2.5-flash-lite-preview-tts' => esc_html__('gemini-2.5-flash-lite-preview-tts', 'quikvox-ai'),
		);
		?>
	<form method="post" action="options.php">
		<?php
		$option_group = 'Podcastmaker_settings_group'; // Default
		if ($active_tab === 'gemini') {
			$option_group = 'Podcastmaker_gemini_settings';
		}
		elseif ($active_tab === 'vertex') {
			$option_group = 'Podcastmaker_vertex_settings';
		}

		settings_fields($option_group);
		// do_settings_sections( $option_group );
?>
	<?php
	endif; ?>

		<div class="Podcastmaker-tab-content">
			<?php if ($active_tab == 'general'): ?>
				<!-- Dashboard / General -->
				
				<?php
		$current_plan = Podcastmaker_License::get_plan();
		$license_key = get_option('podcastmaker_license_key', '');
		$license_status = Podcastmaker_License::get_license_status();
		$license_info = Podcastmaker_License::get_license_info();
		$license_state = Podcastmaker_License::get_license_state();
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$license_recheck_result = isset($_GET['license_recheck_result']) ? sanitize_key(wp_unslash($_GET['license_recheck_result'])) : '';
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$license_recheck_message = isset($_GET['license_recheck_message']) ? sanitize_text_field(wp_unslash($_GET['license_recheck_message'])) : '';
?>

				<?php if ($license_recheck_result === 'success' && $license_recheck_message !== ''): ?>
					<div class="notice notice-success inline" style="margin-left: 0; margin-bottom: 15px;">
						<p><?php echo esc_html($license_recheck_message); ?></p>
					</div>
				<?php elseif ($license_recheck_result === 'error' && $license_recheck_message !== ''): ?>
					<div class="notice notice-error inline" style="margin-left: 0; margin-bottom: 15px;">
						<p><?php echo esc_html($license_recheck_message); ?></p>
					</div>
				<?php endif; ?>

				<!-- License Registration -->
				<div class="card" style="margin-bottom: 20px; border-left: 4px solid #2271b1; width: max-content; max-width: 100%; padding-right: 40px;">
					<h3 style="margin-top: 0;"><?php echo esc_html__('QuikVox AI License', 'quikvox-ai'); ?></h3>
					<p><?php echo esc_html__('Enter your license key to activate Pro or Business features. Online verification only runs when you save, manually recheck, or open this page after the next scheduled verification time.', 'quikvox-ai'); ?></p>
					<?php if ($license_status['state'] === 'invalid'): ?>
						<div class="notice notice-error inline" style="margin-left: 0; margin-bottom: 15px;">
							<p><strong><span class="dashicons dashicons-warning"></span> <?php echo esc_html__('License Verification Failed.', 'quikvox-ai'); ?></strong> <?php echo esc_html($license_status['message']); ?></p>
						</div>
					<?php endif; ?>
					<?php if ($license_state['status'] === 'expired'): ?>
						<div class="notice notice-error inline" style="margin-left: 0; margin-bottom: 15px;">
							<p><strong><span class="dashicons dashicons-warning"></span> <?php echo esc_html__('License Expired!', 'quikvox-ai'); ?></strong> <?php echo esc_html__('Your license expired on', 'quikvox-ai'); ?> <?php echo esc_html($license_state['expires_at']); ?>. <?php echo esc_html__('You have been downgraded to the Basic plan. Please renew your license.', 'quikvox-ai'); ?></p>
						</div>
					<?php
		endif; ?>
					<table class="form-table" style="margin-top: 0;">
						<tr>
							<th scope="row" style="padding: 10px 10px 10px 0;"><label for="podcastmaker_license_key"><?php echo esc_html__('License Key', 'quikvox-ai'); ?></label></th>
							<td style="padding: 10px 0;">
								<?php wp_nonce_field('podcastmaker_recheck_license', 'podcastmaker_recheck_nonce'); ?>
								<div style="display: flex; align-items: center; gap: 6px;">
									<input type="password" name="podcastmaker_license_key" id="podcastmaker_license_key" value="<?php echo esc_attr($license_key); ?>" class="large-text code" placeholder="<?php echo esc_attr__('QVX-PRO-XXXXX', 'quikvox-ai'); ?>" style="width: 85ch; max-width: 100%; font-family: monospace; font-size: 15px; padding: 6px;">
									<button type="button" id="toggle_license_key" class="button pm-toggle-button" data-podcastmaker-password-toggle="#podcastmaker_license_key" aria-pressed="false" title="<?php echo esc_attr__('Show/Hide License Key', 'quikvox-ai'); ?>"><span class="dashicons dashicons-visibility"></span></button>
								</div>
								<div style="margin-top: 10px;">
									<button type="submit" class="button button-primary"><?php echo esc_html__('Verify & Save', 'quikvox-ai'); ?></button>
									<?php if (!empty($license_key)): ?>
									<button type="submit" class="button pm-confirm-button" data-podcastmaker-confirm="<?php echo esc_attr__('Are you sure you want to clear your license and downgrade to the Free plan?', 'quikvox-ai'); ?>" style="margin-left: 10px;"><?php echo esc_html__('Clear License (Free)', 'quikvox-ai'); ?></button>
									<?php
		endif; ?>
									<button type="submit" name="action" value="podcastmaker_recheck_license" formaction="<?php echo esc_url(admin_url('admin-post.php')); ?>" formmethod="post" formnovalidate class="button" style="margin-left: 10px;"><?php echo esc_html__('License Recheck', 'quikvox-ai'); ?></button>
								</div>
								<p class="description"><?php echo wp_kses_post(sprintf(
									/* translators: %s: official website link. */
									esc_html__("If you don't have a license, you can purchase one from our", 'quikvox-ai') . ' %s',
									'<a href="https://quikvox-ai.com/" target="_blank" rel="noreferrer noopener">' . esc_html__('official website', 'quikvox-ai') . '</a>'
								)); ?></p>
								<p class="description" style="margin-top: 12px;">
									<?php echo esc_html__('Current status:', 'quikvox-ai'); ?> <?php echo esc_html($license_state['status']); ?><br>
									<?php echo esc_html__('Plan:', 'quikvox-ai'); ?> <?php echo esc_html($license_state['plan']); ?><br>
									<?php echo esc_html__('Last checked:', 'quikvox-ai'); ?> <?php echo esc_html($license_state['checked_at'] !== '' ? $license_state['checked_at'] : __('Not checked yet', 'quikvox-ai')); ?><br>
									<?php echo esc_html__('Next check:', 'quikvox-ai'); ?> <?php echo esc_html($license_state['next_check_at'] !== '' ? $license_state['next_check_at'] : __('Not scheduled', 'quikvox-ai')); ?><br>
									<?php echo esc_html__('Grace until:', 'quikvox-ai'); ?> <?php echo esc_html($license_state['grace_until'] !== '' ? $license_state['grace_until'] : __('Not set', 'quikvox-ai')); ?><br>
									<?php echo esc_html__('Failed checks:', 'quikvox-ai'); ?> <?php echo esc_html((string) absint($license_state['failed_check_count'])); ?>
								</p>
							</td>
						</tr>
					</table>
				</div>
                
				<div class="card" style="margin-top: 20px; width: max-content; max-width: 100%; padding-right: 40px;">
					<h2><?php echo esc_html__('API Provider', 'quikvox-ai'); ?></h2>
					<?php $api_provider = get_option('podcastmaker_api_provider', 'google_ai_studio'); ?>
					<table class="form-table">
						<tr>
							<th scope="row"><?php echo esc_html__('Select Provider', 'quikvox-ai'); ?></th>
							<td>
								<fieldset>
									<label style="display: block; margin-bottom: 10px;">
										<input type="radio" name="podcastmaker_api_provider" value="google_ai_studio" <?php checked($api_provider, 'google_ai_studio'); ?>>
										<strong><?php echo esc_html__('Google AI Studio', 'quikvox-ai'); ?></strong> <span style="color: #646970;"><?php echo esc_html__('(Gemini API)', 'quikvox-ai'); ?></span>
									</label>
									<label style="display: block; margin-bottom: 10px; <?php echo !Podcastmaker_License::is_business() ? 'opacity: 0.6;' : ''; ?>">
										<input type="radio" name="podcastmaker_api_provider" value="vertex_ai" <?php echo !Podcastmaker_License::is_business() ? 'disabled' : ''; ?> <?php checked($api_provider, 'vertex_ai'); ?>>
										<strong><?php echo esc_html__('Vertex AI', 'quikvox-ai'); ?></strong> <span style="color: #646970;"><?php echo esc_html__('(Google Cloud)', 'quikvox-ai'); ?></span>
										<?php if (!Podcastmaker_License::is_business()): ?>
											<span style="color: #d63638; font-size: 13px; margin-left: 5px;"><?php echo esc_html__('- Business Plan required', 'quikvox-ai'); ?></span>
										<?php
		endif; ?>
									</label>
								</fieldset>
								<p class="description"><?php echo esc_html__('Select which API to use for content generation. Access your chosen provider\'s tab above to configure it.', 'quikvox-ai'); ?></p>
							</td>
						</tr>
					</table>
					<?php submit_button(__('Save Provider Settings', 'quikvox-ai')); ?>
				</div>
				
				<style>
					.Podcastmaker-plan-cards { display: flex; flex-wrap: wrap; gap: 20px; margin-top: 20px; }
					.Podcastmaker-plan-card { flex: 1; min-width: 300px; padding: 20px; border: 1px solid #ccd0d4; border-radius: 4px; background: #fff; position: relative; }
					.Podcastmaker-plan-card.active { border: 2px solid #2271b1; box-shadow: 0 4px 12px rgba(34,113,177,0.15); }
					.Podcastmaker-plan-card.disabled { background: #f6f7f7; opacity: 0.8; }
					.Podcastmaker-plan-card .active-badge { font-size: 11px; font-weight: bold; background: #00a32a; color: #fff; padding: 3px 8px; border-radius: 10px; margin-left: 10px; }
					.Podcastmaker-plan-card .pro-badge { font-size: 11px; font-weight: bold; background: #eba000; color: #fff; padding: 3px 8px; border-radius: 10px; margin-left: 10px; }
					.Podcastmaker-plan-card .business-badge { font-size: 11px; font-weight: bold; background: #722ed1; color: #fff; padding: 3px 8px; border-radius: 10px; margin-left: 10px; }
					.Podcastmaker-gemini-card { margin-top: 20px; }
	
	/* Voice Preview Styles */
	.podcastmaker-preview-controls { display: flex; gap: 4px; }
	.pm-preview-btn { 
		display: inline-flex !important; 
		align-items: center; 
		justify-content: center;
		min-width: 48px !important;
	}
	.pm-preview-btn .dashicons { font-size: 14px; width: 14px; height: 14px; margin-right: 2px; }
	.pm-preview-btn.is-playing {
		background: #00a32a !important;
		border-color: #00a32a !important;
		color: #fff !important;
		animation: pm-pulse 1.2s infinite;
	}
	@keyframes pm-pulse {
		0%, 100% { box-shadow: 0 0 0 0 rgba(0,163,42,0.5); }
		50% { box-shadow: 0 0 0 4px rgba(0,163,42,0); }
	}
	.Podcastmaker-voice-preview-table tr.is-playing-row {
		background-color: #f0f6fb !important;
	}
					.Podcastmaker-plan-card ul { margin-top: 15px; }
					.Podcastmaker-plan-card li { margin-bottom: 8px; font-size: 14px; }
				</style>

				<div class="card Podcastmaker-plan-section">
					<h2><?php echo esc_html__('QuikVox AI Plan', 'quikvox-ai'); ?></h2>
					<p><?php echo esc_html__('You are currently using the', 'quikvox-ai'); ?> <strong><?php echo esc_html(ucfirst(strtolower($current_plan))); ?></strong> <?php echo esc_html__('version of QuikVox AI.', 'quikvox-ai'); ?></p>
					<?php if ($license_info && !$license_info['is_expired']): ?>
						<p style="color: #00a32a; font-weight: bold;"><span class="dashicons dashicons-yes"></span> <?php echo esc_html__('License Verified. Valid until:', 'quikvox-ai'); ?> <?php echo esc_html($license_info['expires']); ?></p>
						<p style="color: #646970; font-size: 13px; margin-top: -10px; margin-bottom: 20px;"><?php echo esc_html__('Issued on:', 'quikvox-ai'); ?> <?php echo esc_html($license_info['issued']); ?></p>
					<?php
		endif; ?>
					
					<div class="Podcastmaker-plan-cards" style="display: flex; flex-wrap: wrap; gap: 20px; margin-top: 20px;">
						<!-- BASIC Card -->
						<div class="Podcastmaker-plan-card <?php echo strtolower($current_plan) === 'basic' ? 'active' : 'disabled'; ?>" style="flex: 1; min-width: 300px; padding: 20px; border: <?php echo strtolower($current_plan) === 'basic' ? '2px solid #2271b1' : '1px solid #ccd0d4'; ?>; border-radius: 4px; background: <?php echo strtolower($current_plan) === 'basic' ? '#fff' : '#f6f7f7'; ?>; opacity: <?php echo strtolower($current_plan) === 'basic' ? '1' : '0.8'; ?>;">
							<h3 style="margin-top: 0; display: flex; align-items: center;">
								<span class="dashicons dashicons-yes-alt" style="color:#00a32a; font-size:24px; width:24px; height:24px; margin-right:8px;"></span>
								<?php echo esc_html__('QuikVox AI BASIC (Free)', 'quikvox-ai'); ?>
								<?php if (strtolower($current_plan) === 'basic'): ?><span class="active-badge"><?php echo esc_html__('Active', 'quikvox-ai'); ?></span><?php
		endif; ?>
							</h3>
							<ul>
								<li><span class="dashicons dashicons-yes" style="color:#00a32a;"></span> <?php echo esc_html__('15 Natural AI Voices', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-yes" style="color:#00a32a;"></span> <?php echo esc_html__('Male & Female Voice Options', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-yes" style="color:#00a32a;"></span> <?php echo esc_html__('Standard Prompt Set', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-yes" style="color:#00a32a;"></span> <?php echo esc_html__('WAV Format Support', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-no" style="color:#d63638;"></span> <?php echo esc_html__('Multi Speaker Support', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-no" style="color:#d63638;"></span> <?php echo esc_html__('Speech Rate Control', 'quikvox-ai'); ?></li>
							</ul>
						</div>

						<!-- Pro Card -->
						<div class="Podcastmaker-plan-card <?php echo strtolower($current_plan) === 'pro' ? 'active' : 'disabled'; ?>" style="flex: 1; min-width: 300px; padding: 20px; border: <?php echo strtolower($current_plan) === 'pro' ? '2px solid #2271b1' : '1px solid #ccd0d4'; ?>; border-radius: 4px; background: <?php echo strtolower($current_plan) === 'pro' ? '#fff' : '#f6f7f7'; ?>; opacity: <?php echo strtolower($current_plan) === 'pro' ? '1' : '0.8'; ?>;">
							<h3 style="margin-top: 0; display: flex; align-items: center;">
								<span class="dashicons dashicons-awards" style="color:#eba000; font-size:24px; width:24px; height:24px; margin-right:8px;"></span>
								<?php echo esc_html__('Pro (Paid plan)', 'quikvox-ai'); ?>
								<span class="pro-badge">PRO</span>
								<?php if (strtolower($current_plan) === 'pro'): ?><span class="active-badge"><?php echo esc_html__('Active', 'quikvox-ai'); ?></span><?php
		endif; ?>
							</h3>
							<ul>
								<li style="font-weight: bold; color: #2271b1;"><span class="dashicons dashicons-saved"></span> <?php echo esc_html__('Includes all BASIC features', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-yes" style="color:#00a32a;"></span> <?php echo esc_html__('30 Natural AI Voices', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-yes" style="color:#00a32a;"></span> <?php echo esc_html__('SMART TONE', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-yes" style="color:#00a32a;"></span> <?php echo esc_html__('Multi Speaker Support', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-yes" style="color:#00a32a;"></span> <?php echo esc_html__('Usage Meter (Coming Soon)', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-no" style="color:#d63638;"></span> <?php echo esc_html__('Vertex AI Integration', 'quikvox-ai'); ?></li>
							</ul>
							<?php if ($current_plan === 'basic'): ?>
								<a href="https://quikvox-ai.com/" target="_blank" class="button"><?php echo esc_html__('Upgrade', 'quikvox-ai'); ?></a>
							<?php
		endif; ?>
						</div>

						<!-- Business Card -->
						<div class="Podcastmaker-plan-card <?php echo strtolower($current_plan) === 'business' ? 'active' : 'disabled'; ?>" style="flex: 1; min-width: 300px; padding: 20px; border: <?php echo strtolower($current_plan) === 'business' ? '2px solid #2271b1' : '1px solid #ccd0d4'; ?>; border-radius: 4px; background: <?php echo strtolower($current_plan) === 'business' ? '#fff' : '#f6f7f7'; ?>; opacity: <?php echo strtolower($current_plan) === 'business' ? '1' : '0.8'; ?>;">
							<h3 style="margin-top: 0; display: flex; align-items: center;">
								<span class="dashicons dashicons-businessman" style="color:#722ed1; font-size:24px; width:24px; height:24px; margin-right:8px;"></span>
								<?php echo esc_html__('Business', 'quikvox-ai'); ?>
								<span class="business-badge">BUSINESS</span>
								<?php if (strtolower($current_plan) === 'business'): ?><span class="active-badge"><?php echo esc_html__('Active', 'quikvox-ai'); ?></span><?php
		endif; ?>
							</h3>
							<ul>
								<li style="font-weight: bold; color: #722ed1;"><span class="dashicons dashicons-saved"></span> <?php echo esc_html__('Includes all Pro features', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-yes" style="color:#00a32a;"></span> <strong><?php echo esc_html__('Vertex AI', 'quikvox-ai'); ?></strong> <?php echo esc_html__('Integration', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-yes" style="color:#00a32a;"></span> <?php echo esc_html__('Data Sovereignty & Local Regions', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-yes" style="color:#00a32a;"></span> <?php echo esc_html__('30 Natural AI Voices', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-yes" style="color:#00a32a;"></span> <?php echo esc_html__('Full Automation (Coming Soon)', 'quikvox-ai'); ?></li>
								<li><span class="dashicons dashicons-yes" style="color:#00a32a;"></span> <?php echo esc_html__('BGM & Auto Mastering (Coming Soon)', 'quikvox-ai'); ?></li>
							</ul>
							<?php if ($current_plan !== 'business'): ?>
								<a href="https://quikvox-ai.com/" target="_blank" class="button"><?php echo esc_html__('Contact Us', 'quikvox-ai'); ?></a>
							<?php
		endif; ?>
						</div>
					</div>
				</div>


				<div class="card" style="margin-top: 20px;">
					<h2><?php echo esc_html__('Quick Start', 'quikvox-ai'); ?></h2>
					<p><?php echo esc_html__('1. Configure your API credentials in', 'quikvox-ai'); ?> <a href="?page=Podcastmaker&tab=gemini"><?php echo esc_html__('Google AI Studio', 'quikvox-ai'); ?></a> <?php echo esc_html__('or', 'quikvox-ai'); ?> <a href="?page=Podcastmaker&tab=vertex"><?php echo esc_html__('Vertex AI', 'quikvox-ai'); ?></a>.</p>
					<p><?php echo esc_html__('2. Set up your', 'quikvox-ai'); ?> <a href="?page=Podcastmaker&tab=prompts"><?php echo esc_html__('Prompt Sets', 'quikvox-ai'); ?></a> <?php echo esc_html__('for different topics or languages.', 'quikvox-ai'); ?></p>
					<p><?php echo esc_html__('3. Go to any', 'quikvox-ai'); ?> <a href="edit.php"><?php echo esc_html__('Post', 'quikvox-ai'); ?></a> <?php echo esc_html__('and click "Create Audio" in the sidebar.', 'quikvox-ai'); ?></p>
				</div>

			<?php
	elseif ($active_tab == 'gemini'):
		$api_provider = get_option('podcastmaker_api_provider', 'google_ai_studio');
?>
				<!-- Google AI Studio Settings -->
				<div class="card Podcastmaker-gemini-card" <?php echo $api_provider !== 'google_ai_studio' ? 'style="opacity: 0.6;"' : ''; ?>>
					<h2>
						<span class="dashicons dashicons-rest-api" style="font-size: 24px; width: 24px; height: 24px;"></span> <?php echo esc_html__('Google AI Studio Settings', 'quikvox-ai'); ?>
						<?php if ($api_provider === 'google_ai_studio'): ?>
							<span style="color: #00a32a; font-size: 12px; font-weight: bold; background: #e5f6ed; padding: 3px 8px; border-radius: 10px; margin-left: 10px; vertical-align: middle;"><span class="dashicons dashicons-yes-alt" style="font-size: 14px; width: 14px; height: 14px; line-height: 1;"></span> <?php echo esc_html__('Active', 'quikvox-ai'); ?></span>
						<?php
		else: ?>
							<span style="color: #646970; font-size: 12px; font-weight: bold; background: #f0f0f1; padding: 3px 8px; border-radius: 10px; margin-left: 10px; vertical-align: middle;"><span class="dashicons dashicons-dismiss" style="font-size: 14px; width: 14px; height: 14px; line-height: 1;"></span> <?php echo esc_html__('Inactive', 'quikvox-ai'); ?></span>
						<?php
		endif; ?>
					</h2>
					<p><?php echo esc_html__('Configure your Google AI Studio API connections for both Text/Script Generation and Voice Generation (TTS).', 'quikvox-ai'); ?></p>
					<?php
		// API Keys
		$gemini_script_api_key = get_option('Podcastmaker_gemini_api_key');
		$gemini_tts_api_key = get_option('Podcastmaker_gemini_tts_api_key');

		// Script Model Config
		$current_default_model = get_option('Podcastmaker_gemini_model', 'gemini-2.5-flash');
		$available_models_saved = get_option('Podcastmaker_gemini_available_models', array('gemini-2.5-flash'));
		if (!is_array($available_models_saved)) {
			$available_models_saved = array();
		}

		// System Fallback Models (used until the user refreshes the cache)
		$fallback_models = array(
			'gemini-3.1-pro-preview',
			'gemini-3.1-flash-lite-preview',
			'gemini-2.5-pro',
			'gemini-2.5-flash',
			'gemini-2.5-flash-lite',
		);

		$gemini_model_cache = get_option('Podcastmaker_gemini_model_list_cache', array());
		$cached_models = array();
		$cache_updated_at = 0;
		if (is_array($gemini_model_cache)) {
			if (isset($gemini_model_cache['models']) && is_array($gemini_model_cache['models'])) {
				$cached_models = $gemini_model_cache['models'];
			}
			elseif (!empty($gemini_model_cache)) {
				$cached_models = $gemini_model_cache;
			}

			if (isset($gemini_model_cache['updated_at'])) {
				$cache_updated_at = absint($gemini_model_cache['updated_at']);
			}
		}

		$gemini_model_exclusion_list = class_exists('Podcastmaker_Admin')
			? Podcastmaker_Admin::get_gemini_model_exclusion_list()
			: array();

		$display_source_models = !empty($cached_models) ? $cached_models : $fallback_models;
		$display_models = array();
		foreach ($display_source_models as $m) {
			$clean_name = str_replace('models/', '', (string) $m);
			if ($clean_name === '' || in_array($clean_name, $gemini_model_exclusion_list, true) || strpos($clean_name, 'tts') !== false) {
				continue;
			}

			$display_models[$clean_name] = $clean_name;
		}

		if (empty($display_models)) {
			foreach ($fallback_models as $m) {
				$display_models[$m] = $m . ' (' . esc_html__('System Default', 'quikvox-ai') . ')';
			}
		}

		$cache_status_text = $cache_updated_at > 0
			? sprintf(
				/* translators: %s: localized date/time */
				esc_html__('Last update: %s', 'quikvox-ai'),
				esc_html(wp_date(get_option('date_format') . ' ' . get_option('time_format'), $cache_updated_at))
			)
			: esc_html__('Last update: not yet updated', 'quikvox-ai');
		$default_model_missing = !isset($display_models[$current_default_model]);

		// Fetch voices only when the TTS API key exists
		$tts_status = '';
		$voices_list = array();
		if (!empty($gemini_tts_api_key)) {
			if (class_exists('Podcastmaker_API_Gemini')) {
				// Use TTS Key for this instance
				$gemini_tts = new Podcastmaker_API_Gemini($gemini_tts_api_key);
				$voices_result = $gemini_tts->get_voices();
				if (is_array($voices_result)) {
					$voices_list = $voices_result;
					$tts_status = '<div class="notice notice-success inline"><p>' . esc_html__('Voice API ready.', 'quikvox-ai') . '</p></div>';
				}
			}
		}
?>
					
					<?php echo wp_kses_post($tts_status); ?>

					<table class="form-table">
						<!-- API Keys Section -->
						<tr style="border-bottom: 1px solid #ddd;">
							<th scope="row"><strong><?php echo esc_html__('API Keys Setup', 'quikvox-ai'); ?></strong></th>
							<td></td>
						</tr>
						<tr>
							<th scope="row"><label for="Podcastmaker_gemini_api_key"><?php echo esc_html__('Script Generation API Key', 'quikvox-ai'); ?></label></th>
							<td>
								<div style="display: flex; align-items: center; gap: 6px;">
									<input name="Podcastmaker_gemini_api_key" type="password" id="Podcastmaker_gemini_api_key" value="<?php echo esc_attr($gemini_script_api_key); ?>" class="regular-text">
									<button type="button" id="toggle_gemini_api_key" class="button pm-toggle-button" data-podcastmaker-password-toggle="#Podcastmaker_gemini_api_key" aria-pressed="false" title="<?php echo esc_attr__('Show/Hide API Key', 'quikvox-ai'); ?>"><span class="dashicons dashicons-visibility"></span></button>
								</div>
								<p class="description"><?php echo esc_html__('Used for generating podcast scripts from articles (LLM). Model list is updated only when you press the Update button below.', 'quikvox-ai'); ?></p>
							</td>
						</tr>
						<tr>
							<th scope="row"><label for="Podcastmaker_gemini_tts_api_key"><?php echo esc_html__('Voice Generation API Key', 'quikvox-ai'); ?></label></th>
							<td>
								<div style="display: flex; align-items: center; gap: 6px;">
									<input name="Podcastmaker_gemini_tts_api_key" type="password" id="Podcastmaker_gemini_tts_api_key" value="<?php echo esc_attr($gemini_tts_api_key); ?>" class="regular-text">
									<button type="button" id="toggle_gemini_tts_api_key" class="button pm-toggle-button" data-podcastmaker-password-toggle="#Podcastmaker_gemini_tts_api_key" aria-pressed="false" title="<?php echo esc_attr__('Show/Hide API Key', 'quikvox-ai'); ?>"><span class="dashicons dashicons-visibility"></span></button>
								</div>
								<p class="description"><?php echo esc_html__('Used for generating audio (TTS).', 'quikvox-ai'); ?> <br><strong><?php echo esc_html__('Use the key you provided: AIzaSy...', 'quikvox-ai'); ?></strong></p>
							</td>
						</tr>
						<tr>
							<td colspan="2" style="padding: 0 0 16px 0;">
								<?php submit_button(esc_html__('Save Changes', 'quikvox-ai')); ?>
							</td>
						</tr>

						<!-- Script Settings -->
						<tr style="border-bottom: 1px solid #ddd; background-color: #f9f9f9;">
							<th scope="row" colspan="2"><strong><?php echo esc_html__('Script Generation Settings', 'quikvox-ai'); ?></strong></th>
						</tr>
						<tr class="Podcastmaker-wide-row">
							<th scope="row"><?php echo esc_html__('Model Selection', 'quikvox-ai'); ?></th>
							<td>
								<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
									<button type="button" class="button button-secondary" id="podcastmaker_refresh_gemini_models"><?php echo esc_html__('Update Available Models', 'quikvox-ai'); ?></button>
									<span id="podcastmaker_gemini_models_status" class="pm-admin-status"><?php echo esc_html($cache_status_text); ?></span>
								</div>
								<?php if ($default_model_missing): ?>
									<div class="notice notice-warning inline" style="margin: 0 0 12px 0;">
										<p><?php echo esc_html__('The current default model is no longer in the list. Please update the model list and select a model again.', 'quikvox-ai'); ?></p>
									</div>
								<?php endif; ?>
								<fieldset>
									<legend class="screen-reader-text"><span><?php echo esc_html__('Model Configuration', 'quikvox-ai'); ?></span></legend>
									<p class="description" style="margin-bottom: 15px;">
										<?php echo esc_html__('Select enabled models from the list. The list is cached and refreshed only when you press the Update button.', 'quikvox-ai'); ?>
									</p>
									<p class="description" style="margin-bottom: 15px;">
										<?php echo esc_html__('Text models only. TTS models are hidden here.', 'quikvox-ai'); ?>
									</p>
									<div style="margin: 0 0 12px 0; display: flex; align-items: center; gap: 10px;">
										<button type="button" class="button button-secondary Podcastmaker-vertex-availability-check" data-vertex-kind="text" data-availability-target="podcastmaker_gemini_availability_status_text" id="podcastmaker_check_gemini_text"><?php echo esc_html__('Check Availability', 'quikvox-ai'); ?></button>
										<span id="podcastmaker_gemini_availability_status_text" class="pm-admin-status"><?php echo esc_html__('Not checked', 'quikvox-ai'); ?></span>
									</div>
									
									<div class="Podcastmaker-model-container">
										<?php
		$sorted_models = $display_models;
		ksort($sorted_models, SORT_NATURAL | SORT_FLAG_CASE);
?>
										<table class="Podcastmaker-model-table widefat striped" style="max-width: 100%;">
											<thead>
												<tr>
													<th class="col-enable"><?php echo esc_html__('Enable', 'quikvox-ai'); ?></th>
													<th class="col-default"><?php echo esc_html__('Default', 'quikvox-ai'); ?></th>
													<th class="col-name"><?php echo esc_html__('Model Name', 'quikvox-ai'); ?></th>
												</tr>
											</thead>
											<tbody>
												<?php foreach ($sorted_models as $model_id => $model_label): ?>
													<tr>
														<td class="col-enable">
															<input type="checkbox"
																class="Podcastmaker-check-available"
																name="Podcastmaker_gemini_available_models[]"
																value="<?php echo esc_attr($model_id); ?>"
																id="available_<?php echo esc_attr($model_id); ?>"
																<?php checked(in_array($model_id, $available_models_saved, true)); ?>>
														</td>
														<td class="col-default">
															<input type="radio"
																name="Podcastmaker_gemini_model"
																class="Podcastmaker-radio-default"
																value="<?php echo esc_attr($model_id); ?>"
																id="default_<?php echo esc_attr($model_id); ?>"
																<?php checked($current_default_model, $model_id); ?>>
														</td>
														<td class="col-name">
															<label for="available_<?php echo esc_attr($model_id); ?>" title="<?php echo esc_attr($model_id); ?>">
																<strong><?php echo esc_html($model_id); ?></strong>
															</label>
														</td>
													</tr>
												<?php endforeach; ?>
											</tbody>
										</table>
									</div>
						</fieldset>

						</td>
					</tr>
					<tr>
						<td colspan="2" style="padding: 0 0 16px 0;">
							<?php submit_button(esc_html__('Save Changes', 'quikvox-ai')); ?>
						</td>
					</tr>

					<!-- Voice Settings -->
						<tr style="border-bottom: 1px solid #ddd; background-color: #f9f9f9;">
							<th scope="row" colspan="2"><strong><?php echo esc_html__('Voice Generation Settings (Gemini TTS)', 'quikvox-ai'); ?></strong></th>
						</tr>
						<tr class="Podcastmaker-wide-row">
							<th scope="row" colspan="2"><label for="Podcastmaker_gemini_tts_model"><?php echo esc_html__('TTS Model Default Setting', 'quikvox-ai'); ?></label></th>
						</tr>
						<tr class="Podcastmaker-wide-row">
							<td colspan="2">
								<p class="description" style="margin-bottom: 15px;">
									<?php echo esc_html__('TTS models only. Text models are hidden here.', 'quikvox-ai'); ?>
								</p>
								<?php
		$current_tts_model = get_option('Podcastmaker_gemini_tts_model', 'gemini-2.5-flash-preview-tts');
		$available_tts_saved = get_option('Podcastmaker_gemini_available_tts_models', array('gemini-3.1-flash-tts-preview', 'gemini-2.5-flash-preview-tts', 'gemini-2.5-pro-preview-tts'));
		$gemini_tts_legacy_map = array(
			'gemini-3.1-flash-tts-preview' => 'gemini-3.1-flash-tts-preview',
			'gemini-2.5-flash' => 'gemini-2.5-flash-preview-tts',
			'gemini-2.5-flash-tts' => 'gemini-2.5-flash-preview-tts',
			'gemini-2.5-pro' => 'gemini-2.5-pro-preview-tts',
			'gemini-2.5-pro-tts' => 'gemini-2.5-pro-preview-tts',
			'gemini-3.1-flash-lite-preview' => 'gemini-2.5-flash-preview-tts',
		);
		$current_tts_model = isset($gemini_tts_legacy_map[$current_tts_model]) ? $gemini_tts_legacy_map[$current_tts_model] : $current_tts_model;
		if (is_array($available_tts_saved)) {
			$available_tts_saved = array_values(array_unique(array_map(function ($model) use ($gemini_tts_legacy_map) {
				return isset($gemini_tts_legacy_map[$model]) ? $gemini_tts_legacy_map[$model] : $model;
			}, $available_tts_saved)));
		}
		else {
			$available_tts_saved = array('gemini-3.1-flash-tts-preview', 'gemini-2.5-flash-preview-tts', 'gemini-2.5-pro-preview-tts');
		}
		$tts_models = array(
			'gemini-3.1-flash-tts-preview' => esc_html__('gemini-3.1-flash-tts-preview', 'quikvox-ai'),
			'gemini-2.5-flash-preview-tts' => esc_html__('gemini-2.5-flash-preview-tts', 'quikvox-ai'),
			'gemini-2.5-pro-preview-tts' => esc_html__('gemini-2.5-pro-preview-tts', 'quikvox-ai'),
		);
		if (!isset($tts_models[$current_tts_model])) {
			$current_tts_model = 'gemini-2.5-flash-preview-tts';
		}
		$available_tts_saved = array_values(array_intersect($available_tts_saved, array_keys($tts_models)));
		if (empty($available_tts_saved)) {
			$available_tts_saved = array('gemini-3.1-flash-tts-preview', 'gemini-2.5-flash-preview-tts');
		}
?>
								<table class="widefat striped" style="max-width: 600px;">
									<thead>
										<tr>
											<th style="width: 50px; text-align: center;"><?php echo esc_html__('Enable', 'quikvox-ai'); ?></th>
											<th style="width: 50px; text-align: center;"><?php echo esc_html__('Default', 'quikvox-ai'); ?></th>
											<th><?php echo esc_html__('Model Name', 'quikvox-ai'); ?></th>
										</tr>
									</thead>
									<tbody>
										<?php foreach ($tts_models as $val => $label): ?>
											<tr>
												<td style="text-align: center;">
													<input type="checkbox" name="Podcastmaker_gemini_available_tts_models[]" value="<?php echo esc_attr($val); ?>" <?php checked(in_array($val, $available_tts_saved)); ?>>
												</td>
												<td style="text-align: center;">
													<input type="radio" name="Podcastmaker_gemini_tts_model" value="<?php echo esc_attr($val); ?>" <?php checked($current_tts_model, $val); ?>>
												</td>
												<td><?php echo esc_html($label); ?></td>
											</tr>
										<?php
		endforeach; ?>
									</tbody>
								</table>
								<p class="description"><?php echo esc_html__('Select which TTS models are available in the editor and which one is the default.', 'quikvox-ai'); ?></p>
							</td>
						</tr>
						<tr>
							<td colspan="2" style="padding: 0 0 16px 0;">
								<?php submit_button(esc_html__('Save Changes', 'quikvox-ai')); ?>
							</td>
						</tr>
						<tr class="Podcastmaker-wide-row">
							<th scope="row"><?php echo esc_html__('Available Voices', 'quikvox-ai'); ?></th>
							<td>
								<?php if (empty($voices_list)): ?>
									<p class="description"><?php echo esc_html__('No voices found. Please check your Voice Generation API Key.', 'quikvox-ai'); ?></p>
								<?php
		else: ?>
									<table class="widefat striped" style="max-width: 100%;">
										<thead>
											<tr>
												<th style="width: 40px;"><?php echo esc_html__('ID', 'quikvox-ai'); ?></th>
												<th><?php echo esc_html__('Voice Name', 'quikvox-ai'); ?></th>
												<th><?php echo esc_html__('Gender', 'quikvox-ai'); ?></th>
												<th><?php echo esc_html__('Characteristics', 'quikvox-ai'); ?></th>
											</tr>
										</thead>
										<tbody>
											<?php
			$voice_index = 1;
			foreach ($voices_list as $voice):
?>
												<tr>
													<td style="text-align: center; color: #646970; font-weight: bold;"><?php echo esc_html($voice_index++); ?></td>
													<td><strong><?php echo esc_html($voice['voice_id']); ?></strong></td>
													<td>
														<?php if ($voice['gender'] === 'Male'): ?>
															<span style="color: #2271b1;"> <span class="dashicons dashicons-businessman"></span> <?php echo esc_html__('Male', 'quikvox-ai'); ?></span>
														<?php
				else: ?>
															<span style="color: #d63638;"> <span class="dashicons dashicons-businesswoman"></span> <?php echo esc_html__('Female', 'quikvox-ai'); ?></span>
														<?php
				endif; ?>
													</td>
													<td style="color: #646970; font-style: italic;">
														<?php echo esc_html(isset($voice['characteristics']) ? $voice['characteristics'] : ''); ?>
													</td>
												</tr>
											<?php
			endforeach; ?>
										</tbody>
									</table>
								<?php
		endif; ?>
							</td>
						</tr>
					</table>
				</div>

			<?php
	elseif ($active_tab == 'vertex'):
		$api_provider = get_option('podcastmaker_api_provider', 'google_ai_studio');
?>
				<!-- Vertex AI Settings (Business Only) -->
				<div class="card Podcastmaker-gemini-card" <?php echo $api_provider !== 'vertex_ai' ? 'style="opacity: 0.6;"' : ''; ?>>
					<h2>
						<span class="dashicons dashicons-cloud" style="font-size: 24px; width: 24px; height: 24px;"></span> <?php echo esc_html__('Vertex AI Settings', 'quikvox-ai'); ?>
						<?php if ($api_provider === 'vertex_ai'): ?>
							<span style="color: #00a32a; font-size: 12px; font-weight: bold; background: #e5f6ed; padding: 3px 8px; border-radius: 10px; margin-left: 10px; vertical-align: middle;"><span class="dashicons dashicons-yes-alt" style="font-size: 14px; width: 14px; height: 14px; line-height: 1;"></span> <?php echo esc_html__('Active', 'quikvox-ai'); ?></span>
						<?php
		else: ?>
							<span style="color: #646970; font-size: 12px; font-weight: bold; background: #f0f0f1; padding: 3px 8px; border-radius: 10px; margin-left: 10px; vertical-align: middle;"><span class="dashicons dashicons-dismiss" style="font-size: 14px; width: 14px; height: 14px; line-height: 1;"></span> <?php echo esc_html__('Inactive', 'quikvox-ai'); ?></span>
						<?php
		endif; ?>
					</h2>
					<div class="notice notice-info inline">
						<p><strong><?php echo esc_html__('Business Plan Feature:', 'quikvox-ai'); ?></strong> <?php echo esc_html__('Access Google\'s enterprise-grade Vertex AI models. Requires a Google Cloud Platform project.', 'quikvox-ai'); ?></p>
					</div>

					<?php
		$vertex_location = get_option('podcastmaker_vertex_location', 'global');
		$vertex_tts_location = get_option('podcastmaker_vertex_tts_location', 'global');
		$vertex_json = get_option('podcastmaker_vertex_auth_json', '');
		$vertex_tts_locations = array('global', 'us-central1', 'us-east1', 'us-east4', 'us-east5', 'us-south1', 'us-west1', 'us-west4', 'northamerica-northeast1', 'europe-central2', 'europe-north1', 'europe-southwest1', 'europe-west1', 'europe-west4');
		if (!in_array($vertex_tts_location, $vertex_tts_locations, true)) {
			$vertex_tts_location = 'global';
		}
		$vertex_model_regions = get_option('podcastmaker_vertex_model_regions', array(
			'gemini-3.1-pro-preview' => 'global',
			'gemini-2.5-pro' => 'global',
			'gemini-2.5-flash' => 'global',
			'gemini-2.5-flash-lite' => 'global',
		));
		if (!is_array($vertex_model_regions)) {
			$vertex_model_regions = array();
		}
		$vertex_tts_model_regions = get_option('podcastmaker_vertex_tts_model_regions', array(
			'gemini-3.1-flash-tts-preview' => 'global',
			'gemini-2.5-flash-tts' => 'global',
			'gemini-2.5-pro-tts' => 'global',
			'gemini-2.5-flash-lite-preview-tts' => 'global',
		));
		if (!is_array($vertex_tts_model_regions)) {
			$vertex_tts_model_regions = array();
		}
		$allowed_vertex_locations = array();
		foreach ($vertex_region_groups as $group_data) {
			$allowed_vertex_locations = array_merge($allowed_vertex_locations, $group_data['locations']);
		}
		$allowed_vertex_locations = array_values(array_unique($allowed_vertex_locations));

		$normalize_vertex_region_selection = static function ($selection) use ($allowed_vertex_locations) {
			if (is_array($selection)) {
				$selection = reset($selection);
			}

			$clean_selection = sanitize_key((string) $selection);
			return in_array($clean_selection, $allowed_vertex_locations, true) ? $clean_selection : '';
		};

		$vertex_model_regions = array_map($normalize_vertex_region_selection, $vertex_model_regions);
		$vertex_tts_model_regions = array_map($normalize_vertex_region_selection, $vertex_tts_model_regions);

		// ---- Vertex Text/Script LLM models ----
		$vertex_text_model = get_option('podcastmaker_vertex_model', 'gemini-2.5-flash');
		$vertex_available_models = get_option('podcastmaker_vertex_available_models', array('gemini-2.5-flash', 'gemini-3.1-pro-preview', 'gemini-2.5-pro', 'gemini-2.5-flash-lite'));
		if (!is_array($vertex_available_models))
			$vertex_available_models = array();
		if (empty($vertex_available_models)) {
			$vertex_available_models = array('gemini-2.5-flash', 'gemini-3.1-pro-preview', 'gemini-2.5-pro', 'gemini-2.5-flash-lite');
		}

		$vertex_llm_models = array(
			'gemini-3.1-pro-preview' => esc_html__('gemini-3.1-pro-preview', 'quikvox-ai'),
			'gemini-2.5-pro' => esc_html__('gemini-2.5-pro', 'quikvox-ai'),
			'gemini-2.5-flash' => esc_html__('gemini-2.5-flash', 'quikvox-ai'),
			'gemini-2.5-flash-lite' => esc_html__('gemini-2.5-flash-lite', 'quikvox-ai'),
		);

		// ---- Vertex TTS models (Vertex AI GA — no -preview- suffix) ----
		// Source: https://cloud.google.com/text-to-speech/docs/gemini-tts
		$vertex_tts_model = get_option('podcastmaker_vertex_tts_model', 'gemini-2.5-flash-tts');
		$vertex_available_tts = get_option('podcastmaker_vertex_available_tts_models', array('gemini-3.1-flash-tts-preview', 'gemini-2.5-flash-tts', 'gemini-2.5-pro-tts', 'gemini-2.5-flash-lite-preview-tts'));
		if (!is_array($vertex_available_tts))
			$vertex_available_tts = array();
		$vertex_tts_legacy_map = array(
			'gemini-3.1-flash-tts-preview' => 'gemini-3.1-flash-tts-preview',
			'gemini-2.5-flash' => 'gemini-2.5-flash-tts',
			'gemini-2.5-flash-preview-tts' => 'gemini-2.5-flash-tts',
			'gemini-2.5-flash-lite' => 'gemini-2.5-flash-lite-preview-tts',
			'gemini-2.5-flash-lite-tts' => 'gemini-2.5-flash-lite-preview-tts',
			'gemini-2.5-pro' => 'gemini-2.5-pro-tts',
			'gemini-2.5-pro-preview-tts' => 'gemini-2.5-pro-tts',
		);
		$vertex_tts_model = isset($vertex_tts_legacy_map[$vertex_tts_model]) ? $vertex_tts_legacy_map[$vertex_tts_model] : $vertex_tts_model;
		$vertex_available_tts = array_values(array_unique(array_map(function ($model) use ($vertex_tts_legacy_map) {
			return isset($vertex_tts_legacy_map[$model]) ? $vertex_tts_legacy_map[$model] : $model;
		}, $vertex_available_tts)));

		$vertex_tts_models = array(
			'gemini-3.1-flash-tts-preview' => esc_html__('gemini-3.1-flash-tts-preview', 'quikvox-ai'),
			'gemini-2.5-flash-tts'              => esc_html__('gemini-2.5-flash-tts', 'quikvox-ai'),
			'gemini-2.5-pro-tts'                => esc_html__('gemini-2.5-pro-tts', 'quikvox-ai'),
			'gemini-2.5-flash-lite-preview-tts' => esc_html__('gemini-2.5-flash-lite-preview-tts', 'quikvox-ai'),
		);
		foreach ($vertex_llm_models as $model_id => $_label) {
			if (empty($vertex_model_regions[$model_id])) {
				$vertex_model_regions[$model_id] = 'global';
			}
		}
		foreach ($vertex_tts_models as $model_id => $_label) {
			if (empty($vertex_tts_model_regions[$model_id])) {
				$vertex_tts_model_regions[$model_id] = 'global';
			}
		}
		if (!isset($vertex_tts_models[$vertex_tts_model])) {
			$vertex_tts_model = 'gemini-2.5-flash-tts';
		}
		$vertex_available_tts = array_values(array_intersect($vertex_available_tts, array_keys($vertex_tts_models)));
		if (empty($vertex_available_tts)) {
			$vertex_available_tts = array('gemini-3.1-flash-tts-preview', 'gemini-2.5-flash-tts');
		}
		if (empty($vertex_model_regions['gemini-3.1-pro-preview'])) {
			$vertex_model_regions['gemini-3.1-pro-preview'] = 'global';
		}
		if (empty($vertex_tts_model_regions['gemini-2.5-flash-tts'])) {
			$vertex_tts_model_regions['gemini-2.5-flash-tts'] = 'global';
		}
		if (empty($vertex_model_regions[$vertex_text_model])) {
			$vertex_model_regions[$vertex_text_model] = 'global';
		}
		if (empty($vertex_tts_model_regions[$vertex_tts_model])) {
			$vertex_tts_model_regions[$vertex_tts_model] = 'global';
		}

		// ---- Vertex AI Voices — Male first, then Female ----
		$vertex_voices = array(
			// Male voices
				array('voice_id' => 'Puck', 'gender' => 'Male', 'characteristics' => 'Upbeat'),
				array('voice_id' => 'Charon', 'gender' => 'Male', 'characteristics' => 'Informative'),
				array('voice_id' => 'Fenrir', 'gender' => 'Male', 'characteristics' => 'Excitable'),
				array('voice_id' => 'Orus', 'gender' => 'Male', 'characteristics' => 'Firm'),
				array('voice_id' => 'Enceladus', 'gender' => 'Male', 'characteristics' => 'Breathy'),
				array('voice_id' => 'Iapetus', 'gender' => 'Male', 'characteristics' => 'Clear'),
				array('voice_id' => 'Umbriel', 'gender' => 'Male', 'characteristics' => 'Easy-going'),
				array('voice_id' => 'Algieba', 'gender' => 'Male', 'characteristics' => 'Smooth'),
				array('voice_id' => 'Algenib', 'gender' => 'Male', 'characteristics' => 'Gravelly'),
				array('voice_id' => 'Rasalgethi', 'gender' => 'Male', 'characteristics' => 'Informative'),
				array('voice_id' => 'Alnilam', 'gender' => 'Male', 'characteristics' => 'Firm'),
				array('voice_id' => 'Schedar', 'gender' => 'Male', 'characteristics' => 'Even'),
				array('voice_id' => 'Achird', 'gender' => 'Male', 'characteristics' => 'Friendly'),
				array('voice_id' => 'Zubenelgenubi', 'gender' => 'Male', 'characteristics' => 'Casual'),
				array('voice_id' => 'Sadachbia', 'gender' => 'Male', 'characteristics' => 'Lively'),
				array('voice_id' => 'Sadaltager', 'gender' => 'Male', 'characteristics' => 'Knowledgeable'),
			// Female voices
				array('voice_id' => 'Zephyr', 'gender' => 'Female', 'characteristics' => 'Bright'),
				array('voice_id' => 'Kore', 'gender' => 'Female', 'characteristics' => 'Firm'),
				array('voice_id' => 'Aoede', 'gender' => 'Female', 'characteristics' => 'Breezy'),
				array('voice_id' => 'Leda', 'gender' => 'Female', 'characteristics' => 'Youthful'),
				array('voice_id' => 'Callirrhoe', 'gender' => 'Female', 'characteristics' => 'Easy-going'),
				array('voice_id' => 'Autonoe', 'gender' => 'Female', 'characteristics' => 'Bright'),
				array('voice_id' => 'Despina', 'gender' => 'Female', 'characteristics' => 'Smooth'),
				array('voice_id' => 'Erinome', 'gender' => 'Female', 'characteristics' => 'Clear'),
				array('voice_id' => 'Laomedeia', 'gender' => 'Female', 'characteristics' => 'Upbeat'),
				array('voice_id' => 'Achernar', 'gender' => 'Female', 'characteristics' => 'Soft'),
				array('voice_id' => 'Gacrux', 'gender' => 'Female', 'characteristics' => 'Mature'),
				array('voice_id' => 'Pulcherrima', 'gender' => 'Female', 'characteristics' => 'Forward'),
				array('voice_id' => 'Vindemiatrix', 'gender' => 'Female', 'characteristics' => 'Gentle'),
				array('voice_id' => 'Sulafat', 'gender' => 'Female', 'characteristics' => 'Warm'),
		);
?>
					<table class="form-table">
						<tr style="border-bottom: 1px solid #ddd;">
							<th scope="row"><strong><?php echo esc_html__('Authentication', 'quikvox-ai'); ?></strong></th>
							<td></td>
						</tr>
						<tr>
							<th scope="row"><label for="podcastmaker_vertex_auth_json"><?php echo esc_html__('Service Account JSON', 'quikvox-ai'); ?></label></th>
							<td>
								<div style="display: flex; align-items: flex-start; gap: 6px;">
									<textarea name="podcastmaker_vertex_auth_json" id="podcastmaker_vertex_auth_json" rows="10" cols="50" class="large-text code" placeholder='{
  "type": "service_account",
  "project_id": "...",
  "private_key_id": "...",
  ...
}' style="<?php echo !empty($vertex_json) ? 'filter: blur(4px); user-select: none;' : ''; ?>"><?php echo esc_textarea($vertex_json); ?></textarea>
									<?php if (!empty($vertex_json)): ?>
									<button type="button" id="toggle_vertex_json" class="button pm-toggle-button" data-podcastmaker-secret-toggle="#podcastmaker_vertex_auth_json" aria-pressed="false" title="<?php echo esc_attr__('Show/Hide Service Account JSON', 'quikvox-ai'); ?>"><span class="dashicons dashicons-visibility"></span></button>
									<?php endif; ?>
								</div>
								<p class="description"><?php echo esc_html__('Paste the content of your Service Account JSON key. This is used for server-to-server authentication.', 'quikvox-ai'); ?></p>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo esc_html__('Authentication Status', 'quikvox-ai'); ?></th>
							<td>
								<button type="button" class="button button-secondary" id="podcastmaker_test_vertex"><?php echo esc_html__('Authentication Test', 'quikvox-ai'); ?></button>
								<span id="podcastmaker_vertex_status" class="pm-admin-status" style="margin-left: 10px;"><?php echo esc_html__('Not tested', 'quikvox-ai'); ?></span>
							</td>
						</tr>
						<!-- Script LLM Model Selection -->
						<tr style="border-bottom: 1px solid #ddd; background-color: #f9f9f9;">
							<th scope="row" colspan="2"><strong><?php echo esc_html__('Script Generation Settings (Text LLM)', 'quikvox-ai'); ?></strong></th>
						</tr>
						<tr>
							<th scope="row"><?php echo esc_html__('Model Selection', 'quikvox-ai'); ?></th>
							<td>
								<p class="description Podcastmaker-matrix-note"><?php echo esc_html__('Region groups are collapsed by default. Open a group to choose the specific location.', 'quikvox-ai'); ?></p>
								<p class="description Podcastmaker-matrix-note"><?php echo esc_html__('Choose one location per model.', 'quikvox-ai'); ?></p>
								<div style="margin: 0 0 12px 0; display: flex; align-items: center; gap: 10px;">
									<button type="button" class="button button-secondary Podcastmaker-vertex-availability-check" data-vertex-kind="text" data-availability-target="podcastmaker_vertex_availability_status_text" id="podcastmaker_check_vertex_text"><?php echo esc_html__('Check Availability', 'quikvox-ai'); ?></button>
									<span id="podcastmaker_vertex_availability_status_text" class="pm-admin-status"><?php echo esc_html__('Not checked', 'quikvox-ai'); ?></span>
								</div>
								<div class="Podcastmaker-matrix-section">
									<table class="Podcastmaker-model-matrix widefat striped" style="max-width: 100%;">
										<thead>
											<tr>
												<th class="col-enable"><?php echo esc_html__('Enable', 'quikvox-ai'); ?></th>
												<th class="col-default"><?php echo esc_html__('Default', 'quikvox-ai'); ?></th>
												<th class="col-name"><?php echo esc_html__('Model Name', 'quikvox-ai'); ?></th>
												<th><?php echo esc_html__('Region', 'quikvox-ai'); ?></th>
											</tr>
										</thead>
										<tbody>
											<?php foreach ($vertex_llm_models as $val => $label): ?>
												<tr>
													<?php
													$current_vertex_location = isset($vertex_model_regions[$val]) ? $vertex_model_regions[$val] : '';
													?>
													<td class="col-enable">
														<input type="checkbox"
															class="Podcastmaker-check-available Podcastmaker-vertex-check-available"
															name="podcastmaker_vertex_available_models[]"
															value="<?php echo esc_attr($val); ?>"
															id="available_<?php echo esc_attr($val); ?>"
															<?php checked(in_array($val, $vertex_available_models, true)); ?>>
													</td>
													<td class="col-default">
														<input type="radio"
															name="podcastmaker_vertex_model"
															class="Podcastmaker-radio-default Podcastmaker-vertex-radio-default"
															value="<?php echo esc_attr($val); ?>"
															id="default_<?php echo esc_attr($val); ?>"
															<?php checked($vertex_text_model, $val); ?>>
													</td>
													<td class="col-name">
														<label for="available_<?php echo esc_attr($val); ?>" title="<?php echo esc_attr($val); ?>">
															<strong><?php echo esc_html($val); ?></strong>
														</label>
													</td>
													<td>
														<div class="Podcastmaker-region-grid">
															<?php foreach ($vertex_region_groups as $group_key => $group_data): ?>
																<?php
																$is_group_selected = $current_vertex_location !== '' && in_array($current_vertex_location, $group_data['locations'], true);
																?>
																<details class="Podcastmaker-region-card">
																	<summary>
																		<strong><?php echo esc_html($group_data['label']); ?></strong>
																		<span class="Podcastmaker-region-status<?php echo $is_group_selected ? ' is-selected' : ' is-hidden'; ?>">
																			<span class="Podcastmaker-region-status-value"><?php echo esc_html($is_group_selected ? $current_vertex_location : ''); ?></span>
																		</span>
																	</summary>
																	<div class="Podcastmaker-region-card-body">
																		<div class="Podcastmaker-region-pill-list">
																			<?php foreach ($group_data['locations'] as $location): ?>
																				<?php
																				$is_selected_location = isset($vertex_model_regions[$val]) && $vertex_model_regions[$val] === $location;
																				$is_disabled_location = !$vertex_location_is_allowed('text', $val, $location);
																				?>
																				<label class="Podcastmaker-region-pill<?php echo $is_selected_location ? ' is-active' : ''; ?><?php echo $is_disabled_location ? ' is-disabled' : ''; ?>">
																					<input type="radio"
																						name="podcastmaker_vertex_model_regions[<?php echo esc_attr($val); ?>]"
																						value="<?php echo esc_attr($location); ?>"
																						<?php disabled($is_disabled_location); ?>
																						<?php checked($is_selected_location); ?>>
																					<span><?php echo esc_html($location); ?></span>
																				</label>
																			<?php endforeach; ?>
																		</div>
																	</div>
																</details>
															<?php endforeach; ?>
														</div>
													</td>
												</tr>
											<?php endforeach; ?>
										</tbody>
									</table>
								</div>
								<p class="description"><?php echo esc_html__('Select which Vertex AI LLM models are available and which one is the default.', 'quikvox-ai'); ?></p>
								<div style="margin-top: 16px;">
									<?php submit_button(esc_html__('Save Changes', 'quikvox-ai')); ?>
								</div>
							</td>
						</tr>
						<!-- TTS Model Selection -->
						<tr style="border-bottom: 1px solid #ddd; background-color: #f9f9f9;">
							<th scope="row" colspan="2"><strong><?php echo esc_html__('Voice Generation Settings (Vertex AI TTS)', 'quikvox-ai'); ?></strong></th>
						</tr>
						<tr>
							<th scope="row"><?php echo esc_html__('TTS Model', 'quikvox-ai'); ?></th>
							<td>
								<p class="description Podcastmaker-matrix-note"><?php echo esc_html__('Choose one location per model.', 'quikvox-ai'); ?></p>
								<div style="margin: 0 0 12px 0; display: flex; align-items: center; gap: 10px;">
									<button type="button" class="button button-secondary Podcastmaker-vertex-availability-check" data-vertex-kind="tts" data-availability-target="podcastmaker_vertex_availability_status_tts" id="podcastmaker_check_vertex_tts"><?php echo esc_html__('Check Availability', 'quikvox-ai'); ?></button>
									<span id="podcastmaker_vertex_availability_status_tts" class="pm-admin-status"><?php echo esc_html__('Not checked', 'quikvox-ai'); ?></span>
								</div>
								<div class="Podcastmaker-matrix-section">
									<table class="Podcastmaker-model-matrix widefat striped" style="max-width: 100%;">
										<thead>
											<tr>
												<th class="col-enable"><?php echo esc_html__('Enable', 'quikvox-ai'); ?></th>
												<th class="col-default"><?php echo esc_html__('Default', 'quikvox-ai'); ?></th>
												<th class="col-name"><?php echo esc_html__('Model Name', 'quikvox-ai'); ?></th>
												<th><?php echo esc_html__('Region', 'quikvox-ai'); ?></th>
											</tr>
										</thead>
										<tbody>
											<?php foreach ($vertex_tts_models as $val => $label): ?>
												<tr>
													<?php
													$current_vertex_tts_location = isset($vertex_tts_model_regions[$val]) ? $vertex_tts_model_regions[$val] : '';
													?>
													<td class="col-enable">
														<input type="checkbox" class="Podcastmaker-vertex-check-available-tts" name="podcastmaker_vertex_available_tts_models[]" value="<?php echo esc_attr($val); ?>" id="available_tts_<?php echo esc_attr($val); ?>" <?php checked(in_array($val, $vertex_available_tts, true)); ?>>
													</td>
													<td class="col-default">
														<input type="radio" name="podcastmaker_vertex_tts_model" class="Podcastmaker-vertex-radio-default-tts" value="<?php echo esc_attr($val); ?>" id="default_tts_<?php echo esc_attr($val); ?>" <?php checked($vertex_tts_model, $val); ?>>
													</td>
													<td class="col-name">
														<label for="available_tts_<?php echo esc_attr($val); ?>" title="<?php echo esc_attr($val); ?>">
															<strong><?php echo esc_html($val); ?></strong>
														</label>
													</td>
													<td>
														<div class="Podcastmaker-region-grid">
															<?php foreach ($vertex_region_groups as $group_key => $group_data): ?>
																<?php
																$is_tts_group_selected = $current_vertex_tts_location !== '' && in_array($current_vertex_tts_location, $group_data['locations'], true);
																?>
																<details class="Podcastmaker-region-card">
																	<summary>
																		<strong><?php echo esc_html($group_data['label']); ?></strong>
																		<span class="Podcastmaker-region-status<?php echo $is_tts_group_selected ? ' is-selected' : ' is-hidden'; ?>">
																			<span class="Podcastmaker-region-status-value"><?php echo esc_html($is_tts_group_selected ? $current_vertex_tts_location : ''); ?></span>
																		</span>
																	</summary>
																	<div class="Podcastmaker-region-card-body">
																		<div class="Podcastmaker-region-pill-list">
																			<?php foreach ($group_data['locations'] as $location): ?>
																				<?php
																				$is_selected_tts_location = isset($vertex_tts_model_regions[$val]) && $vertex_tts_model_regions[$val] === $location;
																				$is_disabled_tts_location = !$vertex_location_is_allowed('tts', $val, $location);
																				?>
																				<label class="Podcastmaker-region-pill<?php echo $is_selected_tts_location ? ' is-active' : ''; ?><?php echo $is_disabled_tts_location ? ' is-disabled' : ''; ?>">
																					<input type="radio"
																						name="podcastmaker_vertex_tts_model_regions[<?php echo esc_attr($val); ?>]"
																						value="<?php echo esc_attr($location); ?>"
																						<?php disabled($is_disabled_tts_location); ?>
																						<?php checked($is_selected_tts_location); ?>>
																					<span><?php echo esc_html($location); ?></span>
																				</label>
																			<?php endforeach; ?>
																		</div>
																	</div>
																</details>
															<?php endforeach; ?>
														</div>
													</td>
												</tr>
											<?php endforeach; ?>
										</tbody>
								</table>
							</div>
							<p class="description"><?php echo esc_html__('Output format: WAV', 'quikvox-ai'); ?></p>
							<div style="margin-top: 16px;">
								<?php submit_button(esc_html__('Save Changes', 'quikvox-ai')); ?>
							</div>
							</td>
						</tr>
						<!-- Voices -->
						<tr>
							<th scope="row"><?php echo esc_html__('Available Voices', 'quikvox-ai'); ?></th>
							<td>
								<?php
		$assets_url = plugins_url('assets/audio/previews/', dirname(__FILE__));
?>
								<table class="widefat striped Podcastmaker-voice-preview-table" style="max-width:100%;" data-podcastmaker-assets-url="<?php echo esc_attr($assets_url); ?>">
									<thead>
										<tr>
											<th style="width:40px;"><?php echo esc_html__('ID', 'quikvox-ai'); ?></th>
											<th><?php echo esc_html__('Voice Name', 'quikvox-ai'); ?></th>
											<th><?php echo esc_html__('Gender', 'quikvox-ai'); ?></th>
											<th><?php echo esc_html__('Characteristics', 'quikvox-ai'); ?></th>
											<th><?php echo esc_html__('Preview', 'quikvox-ai'); ?></th>
										</tr>
									</thead>
									<tbody>
									<?php
		$vi = 1;
		foreach ($vertex_voices as $voice):
			$v_id = $voice['voice_id'];
?>
									<tr id="voice-row-<?php echo esc_attr($v_id); ?>">
										<td style="text-align:center;color:#646970;font-weight:bold;"><?php echo esc_html($vi++); ?></td>
										<td><strong><?php echo esc_html($v_id); ?></strong></td>
										<td><?php if ($voice['gender'] === 'Male'): ?><span style="color:#2271b1;"><span class="dashicons dashicons-businessman"></span> <?php echo esc_html__('Male', 'quikvox-ai'); ?></span><?php
			else: ?><span style="color:#d63638;"><span class="dashicons dashicons-businesswoman"></span> <?php echo esc_html__('Female', 'quikvox-ai'); ?></span><?php
			endif; ?></td>
										<td style="color:#646970;font-style:italic;"><?php echo esc_html($voice['characteristics']); ?></td>
										<td>
											<div class="podcastmaker-preview-controls">
												<button type="button" class="button button-small pm-preview-btn" data-voice="<?php echo esc_attr($v_id); ?>" data-lang="ja" title="<?php echo esc_attr__('Preview Japanese', 'quikvox-ai'); ?>">
													<span class="dashicons dashicons-controls-play"></span> JP
												</button>
												<button type="button" class="button button-small pm-preview-btn" data-voice="<?php echo esc_attr($v_id); ?>" data-lang="en" title="<?php echo esc_attr__('Preview English', 'quikvox-ai'); ?>">
													<span class="dashicons dashicons-controls-play"></span> EN
												</button>
											</div>
										</td>
									</tr>
									<?php
		endforeach; ?>
									</tbody>
								</table>
								<p class="description"><?php echo esc_html__('30 voices available with Vertex AI Gemini-TTS. Voice is selected at generation time in the editor.', 'quikvox-ai'); ?></p>
							</td>
						</tr>
				</div>

			<?php
	elseif ($active_tab == 'usage'): ?>
				<!-- Usage Dashboard -->
				
				<?php
		// Mock Data & Threshold Logic
		$usage_chars = 1200000; // 1.2M
		$usage_audio = 252; // 4h 12m in minutes

		// Get thresholds (mocking defaults for demo)
		$threshold_chars = get_option('podcastmaker_threshold_chars', 1000000); // Default 1M
		$threshold_audio = get_option('podcastmaker_threshold_audio', 300); // Default 5h (300m)

		$is_char_alert = $usage_chars > $threshold_chars;
		$is_audio_alert = $usage_audio > $threshold_audio;
?>

				<!-- Summary Cards -->
				<div class="Podcastmaker-plan-cards" style="margin-bottom: 20px;">
					<!-- Cost Card -->
					<div class="Podcastmaker-plan-card" style="min-width: 200px; padding: 20px;">
						<h3 style="font-size: 14px; margin: 0 0 10px; color: #646970;"><?php echo esc_html__('Total Cost (Est.)', 'quikvox-ai'); ?></h3>
						<p style="font-size: 28px; margin: 0; font-weight: bold;">$12.45</p>
						<p style="font-size: 12px; color: #00a32a; margin: 5px 0 0;"><?php echo esc_html__('This Month', 'quikvox-ai'); ?></p>
					</div>

					<!-- Characters Card -->
					<div class="Podcastmaker-plan-card <?php echo $is_char_alert ? 'alert-triggered' : ''; ?>" 
						 style="min-width: 200px; padding: 20px; <?php echo $is_char_alert ? 'border-color: #d63638; background: #fff8f8;' : ''; ?>">
						<h3 style="font-size: 14px; margin: 0 0 10px; color: #646970;">
							Total Characters
							<?php if ($is_char_alert): ?>
								<span class="dashicons dashicons-warning" style="color: #d63638; font-size: 18px; vertical-align: middle;"></span>
							<?php
		endif; ?>
						</h3>
						<p style="font-size: 28px; margin: 0; font-weight: bold; <?php echo $is_char_alert ? 'color: #d63638;' : ''; ?>">
							1.2M
						</p>
						<p style="font-size: 12px; color: #646970; margin: 5px 0 15px;"><?php echo esc_html__('Script Generation', 'quikvox-ai'); ?></p>
						
						<!-- Threshold Input -->
						<div style="border-top: 1px solid <?php echo $is_char_alert ? '#ffc4c4' : '#eee'; ?>; padding-top: 10px;">
							<label for="podcastmaker_threshold_chars" style="font-size: 11px; color: #646970; display: block; margin-bottom: 4px;"><?php echo esc_html__('Alert Threshold (Chars)', 'quikvox-ai'); ?></label>
							<div style="display: flex; align-items: center; gap: 5px;">
								<input type="number" name="podcastmaker_threshold_chars" id="podcastmaker_threshold_chars" 
									   value="<?php echo esc_attr($threshold_chars); ?>" 
									   step="10000" style="width: 100px; padding: 2px 6px; font-size: 12px;">
							</div>
							<?php if ($is_char_alert): ?>
								<p style="color: #d63638; font-size: 11px; margin: 4px 0 0;"><?php echo esc_html__('Exceeded limit!', 'quikvox-ai'); ?></p>
							<?php
		endif; ?>
						</div>
					</div>

					<!-- Audio Duration Card -->
					<div class="Podcastmaker-plan-card <?php echo $is_audio_alert ? 'alert-triggered' : ''; ?>" 
						 style="min-width: 200px; padding: 20px; border-color: <?php echo $is_audio_alert ? '#d63638' : '#2271b1'; ?>; <?php echo $is_audio_alert ? 'background: #fff8f8;' : ''; ?>">
						<h3 style="font-size: 14px; margin: 0 0 10px; color: <?php echo $is_audio_alert ? '#d63638' : '#2271b1'; ?>;">
							Audio Duration
							<?php if ($is_audio_alert): ?>
								<span class="dashicons dashicons-warning" style="color: #d63638;"></span>
							<?php
		endif; ?>
						</h3>
						<p style="font-size: 28px; margin: 0; font-weight: bold;">4h 12m</p>
						<p style="font-size: 12px; color: <?php echo $is_audio_alert ? '#d63638' : '#2271b1'; ?>; margin: 5px 0 15px;"><?php echo esc_html__('TTS Generation', 'quikvox-ai'); ?></p>

						<!-- Threshold Input -->
						<div style="border-top: 1px solid <?php echo $is_audio_alert ? '#ffc4c4' : '#eee'; ?>; padding-top: 10px;">
							<label for="podcastmaker_threshold_audio" style="font-size: 11px; color: #646970; display: block; margin-bottom: 4px;"><?php echo esc_html__('Alert Threshold (Mins)', 'quikvox-ai'); ?></label>
							<div style="display: flex; align-items: center; gap: 5px;">
								<input type="number" name="podcastmaker_threshold_audio" id="podcastmaker_threshold_audio" 
									   value="<?php echo esc_attr($threshold_audio); ?>" 
									   step="10" style="width: 80px; padding: 2px 6px; font-size: 12px;">
								<span style="font-size: 11px; color: #646970;"><?php echo esc_html__('mins (5h)', 'quikvox-ai'); ?></span>
							</div>
						</div>
					</div>
				</div>

				<div class="card Podcastmaker-gemini-card" style="max-width: 100% !important;">
					<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;">
						<h2 style="margin: 0;"><?php echo esc_html__('Usage Logs', 'quikvox-ai'); ?></h2>
						<div>
							<select style="margin-right: 10px;">
								<option><?php echo esc_html__('This Month', 'quikvox-ai'); ?></option>
								<option><?php echo esc_html__('Last Month', 'quikvox-ai'); ?></option>
								<option><?php echo esc_html__('All Time', 'quikvox-ai'); ?></option>
							</select>
							<button class="button"><span class="dashicons dashicons-download" style="line-height: 28px;"></span> <?php echo esc_html__('Export CSV', 'quikvox-ai'); ?></button>
						</div>
					</div>
					
					<table class="wp-list-table widefat fixed striped">
						<thead>
							<tr>
								<th scope="col" class="manage-column column-date" style="width: 150px;"><?php echo esc_html__('Date', 'quikvox-ai'); ?></th>
								<th scope="col" class="manage-column column-user" style="width: 120px;"><?php echo esc_html__('User', 'quikvox-ai'); ?></th>
								<th scope="col" class="manage-column column-type" style="width: 100px;"><?php echo esc_html__('Type', 'quikvox-ai'); ?></th>
								<th scope="col" class="manage-column column-model"><?php echo esc_html__('Model Used', 'quikvox-ai'); ?></th>
								<th scope="col" class="manage-column column-amount" style="width: 100px;"><?php echo esc_html__('Amount', 'quikvox-ai'); ?></th>
								<th scope="col" class="manage-column column-cost" style="width: 80px;"><?php echo esc_html__('Cost (Est)', 'quikvox-ai'); ?></th>
							</tr>
						</thead>
						<tbody>
							<!-- Mock Data -->
							<tr>
								<td>2026-02-05 14:20</td>
								<td><strong>admin</strong></td>
								<td><span class="badge" style="background:#e5f8ff; color:#005c8a; padding:2px 6px; border-radius:4px; font-size:11px;"><?php echo esc_html__('Script', 'quikvox-ai'); ?></span></td>
								<td>gemini-2.5-pro</td>
								<td>4,500 chars</td>
								<td>$0.012</td>
							</tr>
							<tr>
								<td>2026-02-05 14:22</td>
								<td><strong>admin</strong></td>
								<td><span class="badge" style="background:#f0f6fa; color:#2271b1; padding:2px 6px; border-radius:4px; font-size:11px;"><?php echo esc_html__('TTS', 'quikvox-ai'); ?></span></td>
								<td>gemini-2.5-flash-preview-tts</td>
								<td>2m 15s</td>
								<td>$0.045</td>
							</tr>
							<tr>
								<td>2026-02-04 09:15</td>
								<td>editor_suszan</td>
								<td><span class="badge" style="background:#e5f8ff; color:#005c8a; padding:2px 6px; border-radius:4px; font-size:11px;">Script</span></td>
								<td>gemini-2.5-flash</td>
								<td>8,200 chars</td>
								<td>$0.004</td>
							</tr>
							<tr>
								<td>2026-02-03 18:40</td>
								<td>author_ken</td>
								<td><span class="badge" style="background:#f0f6fa; color:#2271b1; padding:2px 6px; border-radius:4px; font-size:11px;">TTS</span></td>
								<td>gemini-2.5-pro-preview-tts</td>
								<td>5m 00s</td>
								<td>$0.200</td>
							</tr>
						</tbody>
					</table>
					<div class="tablenav bottom">
						<div class="tablenav-pages">
							<span class="displaying-num"><?php echo esc_html__('4 items', 'quikvox-ai'); ?></span>
						</div>
					</div>
				</div>

			<?php
	elseif ($active_tab == 'smart_tone'):
		require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-podcastmaker-smart-tone.php';
		$smart_tone_mgr = new Podcastmaker_Smart_Tone();
		$config = $smart_tone_mgr->get_config();
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$smart_tone_action = isset($_GET['action']) ? sanitize_text_field(wp_unslash($_GET['action'])) : 'list';
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$smart_tone_edit_id = isset($_GET['id']) ? sanitize_text_field(wp_unslash($_GET['id'])) : '';
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$smart_tone_speaker_filter = isset($_GET['speaker_filter']) ? sanitize_text_field(wp_unslash($_GET['speaker_filter'])) : 'single';
		$smart_tone_speaker_filter = $smart_tone_speaker_filter === 'multi' ? 'multi' : 'single';
		$smart_tone_styles = Podcastmaker_Smart_Tone::get_styles();
		$default_single_smart_tone_style_id = Podcastmaker_Smart_Tone::get_default_style_id('single');
		$default_multi_smart_tone_style_id = Podcastmaker_Smart_Tone::get_default_style_id('multi');
		$default_single_smart_tone_style = Podcastmaker_Smart_Tone::find_style($default_single_smart_tone_style_id);
		$default_multi_smart_tone_style = Podcastmaker_Smart_Tone::find_style($default_multi_smart_tone_style_id);
?>
				<div class="card Podcastmaker-prompts-card">
					<h2><?php echo esc_html__('Smart Tone Styles Management', 'quikvox-ai'); ?></h2>
					<p class="description"><?php echo esc_html__('Manage reusable Smart Tone templates for single and multi speaker scripts. The structure mirrors Prompt Sets so users can edit styles without changing their mental model.', 'quikvox-ai'); ?></p>

					<?php // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
					<?php if (isset($_GET['saved'])): ?>
						<div class="notice notice-success is-dismissible inline"><p><?php echo esc_html__('Base system instruction saved successfully.', 'quikvox-ai'); ?></p></div>
					<?php endif; ?>
					<?php // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
					<?php if (isset($_GET['saved_style'])): ?>
						<div class="notice notice-success is-dismissible inline"><p><?php echo esc_html__('Smart Tone Style saved successfully.', 'quikvox-ai'); ?></p></div>
					<?php endif; ?>
					<?php // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
					<?php if (isset($_GET['duplicated_style'])): ?>
						<div class="notice notice-success is-dismissible inline"><p><?php echo esc_html__('Smart Tone Style duplicated successfully.', 'quikvox-ai'); ?></p></div>
					<?php endif; ?>
					<?php // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
					<?php if (isset($_GET['deleted_style'])): ?>
						<div class="notice notice-warning is-dismissible inline"><p><?php echo esc_html__('Smart Tone Style deleted.', 'quikvox-ai'); ?></p></div>
					<?php endif; ?>
					<?php // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
					<?php if (isset($_GET['default_updated'])): ?>
						<div class="notice notice-success is-dismissible inline"><p><?php echo esc_html__('Default Smart Tone Style updated.', 'quikvox-ai'); ?></p></div>
					<?php endif; ?>
					<?php if ($smart_tone_action == 'edit' || $smart_tone_action == 'view' || $smart_tone_action == 'add'): ?>
						<?php
						$current_style = array(
							'id' => '',
							'name' => '',
							'speaker_type' => $smart_tone_speaker_filter,
							'description' => '',
							'directive' => '',
							'voice_direction_template' => '',
						);

						if (($smart_tone_action == 'edit' || $smart_tone_action == 'view') && !empty($smart_tone_edit_id)) {
							$loaded_style = Podcastmaker_Smart_Tone::get_style($smart_tone_edit_id);
							if ($loaded_style) {
								$current_style = array_merge($current_style, $loaded_style);
							}
						}
						$is_builtin_smart_tone = isset($current_style['is_system']) && $current_style['is_system'];
						$is_view_only_mode = $smart_tone_action === 'view' || $is_builtin_smart_tone;
						?>
						<form method="post" id="Podcastmaker-smart-tone-style-form" data-view-only="<?php echo esc_attr($is_view_only_mode ? '1' : '0'); ?>">
							<?php wp_nonce_field('podcastmaker_save_smart_tone_style_nonce'); ?>
							<input type="hidden" name="style_id" value="<?php echo esc_attr($current_style['id']); ?>">
							<input type="hidden" name="speaker_filter" value="<?php echo esc_attr($smart_tone_speaker_filter); ?>">
							<table class="form-table">
								<tr>
									<th><label for="style_name"><?php echo esc_html__('1. Title', 'quikvox-ai'); ?></label></th>
									<td><input type="text" name="style_name" id="style_name" value="<?php echo esc_attr($current_style['name']); ?>" class="regular-text" required<?php echo $is_view_only_mode ? ' readonly' : ''; ?> <?php disabled($is_view_only_mode); ?>></td>
								</tr>
								<tr>
									<th><?php echo esc_html__('Speaker Type', 'quikvox-ai'); ?></th>
									<td>
										<div class="speaker-select-container">
											<label class="speaker-select-option <?php echo $current_style['speaker_type'] === 'single' ? 'selected' : ''; ?>">
												<input type="radio" name="speaker_type" value="single" <?php checked($current_style['speaker_type'], 'single'); ?> style="display:none;">
												<span class="speaker-type-icon single"><span class="dashicons dashicons-admin-users"></span></span>
												<strong><?php echo esc_html__('Single Speaker', 'quikvox-ai'); ?></strong>
											</label>

											<label class="speaker-select-option <?php echo $current_style['speaker_type'] === 'multi' ? 'selected' : ''; ?>">
												<input type="radio" name="speaker_type" value="multi" <?php checked($current_style['speaker_type'], 'multi'); ?> style="display:none;">
												<span class="speaker-type-icon multi"><span class="dashicons dashicons-groups"></span></span>
												<strong><?php echo esc_html__('Multi Speaker', 'quikvox-ai'); ?></strong>
											</label>
										</div>
									</td>
								</tr>
								<tr>
									<th><label for="voice_direction_template"><?php echo esc_html__('2. Voice Direction Template', 'quikvox-ai'); ?></label></th>
									<td>
										<textarea name="voice_direction_template" id="voice_direction_template" rows="14" class="large-text code"<?php echo $is_view_only_mode ? ' readonly' : ''; ?> <?php disabled($is_view_only_mode); ?>><?php echo esc_textarea($current_style['voice_direction_template']); ?></textarea>
										<p class="description"><?php echo esc_html__('Template copied into the post-specific Voice Direction area when the user chooses to apply this style template.', 'quikvox-ai'); ?></p>
									</td>
								</tr>
								<tr>
									<th><label for="style_directive"><?php echo esc_html__('3. Smart Tone Directive', 'quikvox-ai'); ?></label></th>
									<td>
										<textarea name="style_directive" id="style_directive" rows="8" class="large-text code" required<?php echo $is_view_only_mode ? ' readonly' : ''; ?> <?php disabled($is_view_only_mode); ?>><?php echo esc_textarea($current_style['directive']); ?></textarea>
										<p class="description"><?php echo esc_html__('This directive is appended to the base system instruction and sent to the LLM when this style is selected.', 'quikvox-ai'); ?></p>
									</td>
								</tr>
							</table>
							<p class="submit">
								<?php if ($is_view_only_mode): ?>
									<?php if (!$is_builtin_smart_tone): ?>
										<a href="<?php echo esc_url(add_query_arg(array('page' => 'Podcastmaker', 'tab' => 'smart_tone', 'action' => 'edit', 'id' => $current_style['id'], 'speaker_filter' => $smart_tone_speaker_filter), admin_url('admin.php'))); ?>" class="button button-primary"><?php echo esc_html__('Edit', 'quikvox-ai'); ?></a>
									<?php endif; ?>
									<a href="<?php echo esc_url(add_query_arg(array('page' => 'Podcastmaker', 'tab' => 'smart_tone', 'speaker_filter' => $smart_tone_speaker_filter), admin_url('admin.php'))); ?>" class="button"><?php echo esc_html__('Return to List', 'quikvox-ai'); ?></a>
								<?php else: ?>
									<input type="submit" name="save_smart_tone_style" class="button button-primary" value="Save Smart Tone Style">
									<a href="<?php echo esc_url(add_query_arg(array('page' => 'Podcastmaker', 'tab' => 'smart_tone', 'speaker_filter' => $smart_tone_speaker_filter), admin_url('admin.php'))); ?>" class="button"><?php echo esc_html__('Cancel', 'quikvox-ai'); ?></a>
								<?php endif; ?>
							</p>
						</form>
					<?php else: ?>
						<?php
						$single_filter_url = add_query_arg(
							array(
								'page' => 'Podcastmaker',
								'tab' => 'smart_tone',
								'speaker_filter' => 'single',
							),
							admin_url('admin.php')
						);
						$multi_filter_url = add_query_arg(
							array(
								'page' => 'Podcastmaker',
								'tab' => 'smart_tone',
								'speaker_filter' => 'multi',
							),
							admin_url('admin.php')
						);
						$add_style_url = add_query_arg(
							array(
								'page' => 'Podcastmaker',
								'tab' => 'smart_tone',
								'action' => 'add',
								'speaker_filter' => $smart_tone_speaker_filter,
							),
							admin_url('admin.php')
						);
						$filtered_styles = array_filter($smart_tone_styles, function ($style) use ($smart_tone_speaker_filter) {
							$speaker_type = isset($style['speaker_type']) && $style['speaker_type'] === 'multi' ? 'multi' : 'single';
							return $speaker_type === $smart_tone_speaker_filter;
						});
						?>
						<form method="post" style="margin-bottom: 20px;">
							<?php wp_nonce_field('Podcastmaker_smart_tone_nonce'); ?>
							<input type="hidden" name="smart_tone_config[default_single_smart_tone_style_id]" value="<?php echo esc_attr($default_single_smart_tone_style_id); ?>">
							<input type="hidden" name="smart_tone_config[default_multi_smart_tone_style_id]" value="<?php echo esc_attr($default_multi_smart_tone_style_id); ?>">
							<div class="pm-tone-editor-section" style="margin-bottom: 18px;">
								<h3><?php echo esc_html__('Base System Instruction', 'quikvox-ai'); ?></h3>
								<p class="description" style="margin-bottom: 12px;"><?php echo esc_html__('This global instruction is shared by all Smart Tone styles and defines the common formatting rules the model should follow.', 'quikvox-ai'); ?></p>
								<textarea name="smart_tone_config[base_instruction]" class="large-text code" rows="12" style="font-size: 13px; line-height: 1.5;"><?php echo esc_textarea($config['base_instruction']); ?></textarea>
							</div>
							<p class="submit" style="margin-top: 0;">
								<input type="submit" name="save_smart_tone_settings" class="button button-primary" value="Save Base Instruction">
							</p>
						</form>

						<div class="Podcastmaker-prompt-toolbar">
							<div class="Podcastmaker-prompt-filter-group" role="tablist" aria-label="Smart tone speaker filter">
								<a href="<?php echo esc_url($single_filter_url); ?>" class="Podcastmaker-prompt-filter <?php echo $smart_tone_speaker_filter === 'single' ? 'is-active' : ''; ?>"><?php echo esc_html__('Single', 'quikvox-ai'); ?></a>
								<a href="<?php echo esc_url($multi_filter_url); ?>" class="Podcastmaker-prompt-filter <?php echo $smart_tone_speaker_filter === 'multi' ? 'is-active' : ''; ?>"><?php echo esc_html__('Multi', 'quikvox-ai'); ?></a>
							</div>
							<a href="<?php echo esc_url($add_style_url); ?>" class="button button-secondary"><?php echo esc_html__('+ Add New Smart Tone Style', 'quikvox-ai'); ?></a>
						</div>

						<table class="wp-list-table widefat striped">
							<thead>
									<tr>
										<th style="width: 50px;"><?php echo esc_html__('ID', 'quikvox-ai'); ?></th>
										<th style="width: 12%;"><?php echo esc_html__('Default', 'quikvox-ai'); ?></th>
										<th style="width: 50px; text-align: center;"><?php echo esc_html__('Type', 'quikvox-ai'); ?></th>
										<th style="width: 24%;"><?php echo esc_html__('Title', 'quikvox-ai'); ?></th>
									<th><?php echo esc_html__('Directive Preview', 'quikvox-ai'); ?></th>
									<th style="width: 20%;"><?php echo esc_html__('Last Update', 'quikvox-ai'); ?></th>
									<th style="width: 180px; text-align: right;"><?php echo esc_html__('Actions', 'quikvox-ai'); ?></th>
								</tr>
							</thead>
							<tbody>
								<?php if (empty($filtered_styles)) : ?>
									<tr><td colspan="7"><?php echo esc_html__('No Smart Tone Styles found for this speaker type.', 'quikvox-ai'); ?></td></tr>
								<?php else : ?>
									<?php foreach ($filtered_styles as $style) :
										$style_id = isset($style['id']) ? sanitize_key($style['id']) : '';
										$row_speaker_type = isset($style['speaker_type']) && $style['speaker_type'] === 'multi' ? 'multi' : 'single';
										$is_builtin_smart_tone = !empty($style['is_system']);
										$is_default_single = $row_speaker_type === 'single' && $style_id === $default_single_smart_tone_style_id;
										$is_default_multi = $row_speaker_type === 'multi' && $style_id === $default_multi_smart_tone_style_id;
										$edit_url = add_query_arg(
											array(
												'page' => 'Podcastmaker',
												'tab' => 'smart_tone',
												'action' => 'edit',
												'id' => $style_id,
												'speaker_filter' => $smart_tone_speaker_filter,
											),
											admin_url('admin.php')
										);
										$view_url = add_query_arg(
											array(
												'page' => 'Podcastmaker',
												'tab' => 'smart_tone',
												'action' => 'view',
												'id' => $style_id,
												'speaker_filter' => $smart_tone_speaker_filter,
											),
											admin_url('admin.php')
										);
									?>
										<tr>
											<td style="font-weight: 600; color: #a0aec0; vertical-align: middle;"><?php echo isset($style['index_id']) ? esc_html($style['index_id']) : '-'; ?></td>
											<td style="text-align: center; vertical-align: middle;">
												<?php if ($is_default_single || $is_default_multi): ?>
													<span class="Podcastmaker-default-star is-active" title="<?php echo esc_attr__('Current default', 'quikvox-ai'); ?>" aria-label="<?php echo esc_attr__('Current default', 'quikvox-ai'); ?>">
														<span class="dashicons dashicons-star-filled"></span>
													</span>
												<?php else: ?>
													<form method="post" style="display:inline;">
														<?php wp_nonce_field('podcastmaker_set_default_smart_tone_' . $style_id); ?>
														<input type="hidden" name="id" value="<?php echo esc_attr($style_id); ?>">
														<input type="hidden" name="speaker_filter" value="<?php echo esc_attr($smart_tone_speaker_filter); ?>">
														<input type="hidden" name="default_speaker_type" value="<?php echo esc_attr($row_speaker_type); ?>">
														<button type="submit" name="set_default_smart_tone_style" class="Podcastmaker-default-star-toggle" title="<?php echo esc_attr__('Set as default', 'quikvox-ai'); ?>" aria-label="<?php echo esc_attr__('Set as default', 'quikvox-ai'); ?>">
															<span class="dashicons dashicons-star-empty"></span>
														</button>
													</form>
												<?php endif; ?>
											</td>
											<td>
												<?php if ($row_speaker_type === 'multi'): ?>
													<span class="speaker-type-icon multi" title="<?php echo esc_attr__('Multi Speaker', 'quikvox-ai'); ?>"><span class="dashicons dashicons-groups"></span></span>
												<?php else: ?>
													<span class="speaker-type-icon single" title="<?php echo esc_attr__('Single Speaker', 'quikvox-ai'); ?>"><span class="dashicons dashicons-admin-users"></span></span>
												<?php endif; ?>
											</td>
											<td>
												<strong><a href="<?php echo esc_url($is_builtin_smart_tone ? $view_url : $edit_url); ?>" style="text-decoration: none;"><?php echo esc_html(!empty($style['name']) ? $style['name'] : '(No Title)'); ?></a></strong>
											</td>
											<td>
												<code style="font-size: 11px; color: #666;"><?php echo esc_html(mb_strimwidth($style['directive'], 0, 120, '...')); ?></code>
											</td>
											<td style="font-size: 11px; color: #666; white-space: nowrap;"><?php echo !empty($style['last_updated']) ? esc_html(date_i18n('Y/m/d H:i', strtotime($style['last_updated']))) : 'System default'; ?></td>
											<td class="Podcastmaker-prompt-list-actions" style="text-align:right; vertical-align: middle;">
												<div class="row-actions Podcastmaker-prompt-set-actions" style="visibility: visible; position: static; text-align: right;">
													<span class="duplicate">
														<form method="post" style="display:inline;">
															<?php wp_nonce_field('podcastmaker_duplicate_smart_tone_' . $style_id); ?>
															<input type="hidden" name="id" value="<?php echo esc_attr($style_id); ?>">
															<input type="hidden" name="speaker_filter" value="<?php echo esc_attr($smart_tone_speaker_filter); ?>">
															<button type="submit" name="duplicate_smart_tone_style" class="button-link" style="font-weight: 600; color: #00a32a; padding: 0; border: none; background: none; cursor: pointer; text-decoration: underline;"><?php echo esc_html__('Duplicate', 'quikvox-ai'); ?></button>
														</form>
													</span>
													<?php if ($is_builtin_smart_tone): ?>
														<span class="edit"> | <a href="<?php echo esc_url($view_url); ?>"><?php echo esc_html__('View', 'quikvox-ai'); ?></a></span>
													<?php else: ?>
														<span class="edit"> | <a href="<?php echo esc_url($edit_url); ?>"><?php echo esc_html__('Edit', 'quikvox-ai'); ?></a> | </span>
														<span class="trash">
															<form method="post" style="display:inline;">
																<?php wp_nonce_field('podcastmaker_delete_smart_tone_' . $style_id); ?>
																<input type="hidden" name="id" value="<?php echo esc_attr($style_id); ?>">
																<input type="hidden" name="speaker_filter" value="<?php echo esc_attr($smart_tone_speaker_filter); ?>">
																<button type="submit" name="delete_smart_tone_style" class="button-link submitdelete pm-confirm-button" data-podcastmaker-confirm="<?php echo esc_attr__('Are you sure?', 'quikvox-ai'); ?>" style="color: #a00; padding: 0; border: none; background: none; cursor: pointer; text-decoration: underline;"><?php echo esc_attr__('Delete', 'quikvox-ai'); ?></button>
															</form>
														</span>
													<?php endif; ?>
												</div>
											</td>
										</tr>
									<?php endforeach; ?>
								<?php endif; ?>
							</tbody>
						</table>
					<?php endif; ?>
				</div>

			<?php
	elseif ($active_tab == 'prompts'): ?>
				<!-- Prompt Sets -->
				<?php
		// Include the class if not already included (though admin class should handle it, good for safety here in view)
		if (!class_exists('Podcastmaker_Prompt_Sets')) {
			require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-podcastmaker-prompt-sets.php';
		}
		$prompt_manager = new Podcastmaker_Prompt_Sets();
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$action = isset($_GET['action']) ? sanitize_text_field(wp_unslash($_GET['action'])) : 'list';
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$edit_id = isset($_GET['id']) ? sanitize_text_field(wp_unslash($_GET['id'])) : '';
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$prompt_speaker_filter = isset($_GET['speaker_filter']) ? sanitize_text_field(wp_unslash($_GET['speaker_filter'])) : 'single';
		$prompt_speaker_filter = $prompt_speaker_filter === 'multi' ? 'multi' : 'single';
		$can_edit_multi_prompts = Podcastmaker_License::is_pro();
		$default_single_prompt_set_id = $prompt_manager->get_default_prompt_set_id('single');
		$default_multi_prompt_set_id = $prompt_manager->get_default_prompt_set_id('multi');
		$default_single_prompt_set = $prompt_manager->get($default_single_prompt_set_id);
		$default_multi_prompt_set = $prompt_manager->get($default_multi_prompt_set_id);
		$base_prompt_language_options = array(
			'ja' => 'Japanese',
			'en' => 'English',
			'zh-cn' => 'Chinese (Simplified)',
			'zh-tw' => 'Chinese (Traditional)',
			'ko' => 'Korean',
		);
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$base_prompt_language = isset($_GET['base_language']) ? sanitize_text_field(wp_unslash($_GET['base_language'])) : '';
		if (!isset($base_prompt_language_options[$base_prompt_language])) {
			$site_locale = get_locale();
			if (strpos($site_locale, 'ja') === 0) {
				$base_prompt_language = 'ja';
			}
			elseif (strpos($site_locale, 'zh_CN') === 0) {
				$base_prompt_language = 'zh-cn';
			}
			elseif (strpos($site_locale, 'zh_TW') === 0) {
				$base_prompt_language = 'zh-tw';
			}
			elseif (strpos($site_locale, 'ko') === 0) {
				$base_prompt_language = 'ko';
			}
			else {
				$base_prompt_language = 'en';
			}
		}
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$base_prompt_speaker_type = isset($_GET['base_speaker_type']) ? sanitize_text_field(wp_unslash($_GET['base_speaker_type'])) : $prompt_speaker_filter;
		$base_prompt_speaker_type = $base_prompt_speaker_type === 'multi' ? 'multi' : 'single';
		$selected_prompt_language = $base_prompt_language;
		$selected_prompt_speaker_type = $base_prompt_speaker_type;
		$base_prompt_speaker_options = array(
			'single' => 'Single',
			'multi' => 'Multi',
		);
		$base_prompt_record = $prompt_manager->get_base_prompt_record($base_prompt_language, $base_prompt_speaker_type);

		$all_sets = $prompt_manager->get_all();

?>
				<div class="card Podcastmaker-prompts-card Podcastmaker-base-prompt-card">
					<?php // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
					<?php if (isset($_GET['base_prompt_saved'])): ?>
						<div class="notice notice-success is-dismissible inline"><p><?php echo esc_html__('Base Prompt saved successfully.', 'quikvox-ai'); ?></p></div>
					<?php endif; ?>

					<div class="Podcastmaker-prompt-toolbar Podcastmaker-base-prompt-toolbar">
						<div class="Podcastmaker-prompt-filter-group" role="tablist" aria-label="Base prompt language filter">
							<?php foreach ($base_prompt_language_options as $language_code => $language_label): ?>
								<?php
								$language_filter_url = add_query_arg(
									array(
										'page' => 'Podcastmaker',
										'tab' => 'prompts',
										'speaker_filter' => $selected_prompt_speaker_type,
										'base_language' => $language_code,
										'base_speaker_type' => $base_prompt_speaker_type,
									),
									admin_url('admin.php')
								);
								?>
								<a href="<?php echo esc_url($language_filter_url); ?>" class="Podcastmaker-prompt-filter <?php echo $base_prompt_language === $language_code ? 'is-active' : ''; ?>"><?php echo esc_html($language_label); ?></a>
							<?php endforeach; ?>
						</div>

						<div class="Podcastmaker-prompt-filter-group" role="tablist" aria-label="Base prompt speaker filter">
							<?php foreach ($base_prompt_speaker_options as $speaker_code => $speaker_label): ?>
								<?php
								$speaker_filter_url = add_query_arg(
									array(
										'page' => 'Podcastmaker',
										'tab' => 'prompts',
										'speaker_filter' => $selected_prompt_speaker_type,
										'base_language' => $base_prompt_language,
										'base_speaker_type' => $speaker_code,
									),
									admin_url('admin.php')
								);
								?>
								<a href="<?php echo esc_url($speaker_filter_url); ?>" class="Podcastmaker-prompt-filter <?php echo $base_prompt_speaker_type === $speaker_code ? 'is-active' : ''; ?>"><?php echo esc_html($speaker_label); ?></a>
							<?php endforeach; ?>
						</div>
					</div>

					<form method="post" class="Podcastmaker-base-prompt-form">
						<?php wp_nonce_field('Podcastmaker_save_base_prompt_nonce'); ?>
						<input type="hidden" name="base_prompt_language" value="<?php echo esc_attr($base_prompt_language); ?>">
						<input type="hidden" name="base_prompt_speaker_type" value="<?php echo esc_attr($base_prompt_speaker_type); ?>">
						<input type="hidden" name="speaker_filter" value="<?php echo esc_attr($selected_prompt_speaker_type); ?>">
						<h3 class="Podcastmaker-base-prompt-field-title"><?php echo esc_html__('Base Prompt', 'quikvox-ai'); ?></h3>
						<table class="form-table">
							<tr class="Podcastmaker-wide-row">
								<th><label for="base_prompt_content" class="screen-reader-text"><?php echo esc_html__('Base Prompt', 'quikvox-ai'); ?></label></th>
								<td>
									<textarea name="base_prompt_content" id="base_prompt_content" rows="8" class="large-text code" readonly data-original-value="<?php echo esc_attr(isset($base_prompt_record['prompt']) ? $base_prompt_record['prompt'] : ''); ?>"><?php echo esc_textarea(isset($base_prompt_record['prompt']) ? $base_prompt_record['prompt'] : ''); ?></textarea>
								</td>
							</tr>
						</table>
						<div class="Podcastmaker-base-prompt-actions">
							<button type="button" class="button" id="Podcastmaker-base-prompt-edit-btn"><?php echo esc_html__('Edit', 'quikvox-ai'); ?></button>
							<button type="button" class="button" id="Podcastmaker-base-prompt-cancel-btn" disabled><?php echo esc_html__('Cancel', 'quikvox-ai'); ?></button>
							<input type="submit" name="save_base_prompt" class="button button-primary" id="Podcastmaker-base-prompt-save-btn" value="<?php echo esc_attr__('Save Base Prompt', 'quikvox-ai'); ?>" disabled>
						</div>
					</form>
				</div>

				<div class="card Podcastmaker-prompts-card">
					<?php // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
					<?php if (isset($_GET['default_updated'])): ?>
						<div class="notice notice-success is-dismissible inline"><p><?php echo esc_html__('Default Prompt Set updated.', 'quikvox-ai'); ?></p></div>
					<?php endif; ?>

					<?php if ($action == 'edit' || $action == 'add' || $action == 'view'): ?>
						<?php
			$current_data = array(
				'name' => '',
				'prompt' => '',
				'language' => $selected_prompt_language,
				'speaker_type' => $selected_prompt_speaker_type,
			);
			if (($action == 'edit' || $action == 'view') && !empty($edit_id)) {
				$current_data = $prompt_manager->get($edit_id);
			}

			if (!isset($current_data['speaker_type'])) {
				$current_data['speaker_type'] = $selected_prompt_speaker_type;
			}
			$is_builtin_prompt_set = isset($current_data['source_type']) && $current_data['source_type'] === 'builtin';
			$is_view_only_mode = $is_builtin_prompt_set || $action === 'view';

			if ($action === 'add' && empty($current_data['prompt'])) {
				$current_data['prompt'] = "[baseprompt]\n";
			}

			// Keep the selected top-level context as the edit target.
			if (empty($current_data['language'])) {
				$current_data['language'] = $selected_prompt_language;
			}

?>
						<form method="post" id="Podcastmaker-prompt-form" data-view-only="<?php echo esc_attr($is_view_only_mode ? '1' : '0'); ?>">
								<?php wp_nonce_field('Podcastmaker_save_prompt_nonce'); ?>
								<input type="hidden" name="prompt_id" value="<?php echo esc_attr($edit_id); ?>">
								<input type="hidden" name="prompt_lang" value="<?php echo esc_attr($selected_prompt_language); ?>">
								<input type="hidden" name="speaker_type" value="<?php echo esc_attr($selected_prompt_speaker_type); ?>">
								<input type="hidden" name="base_language" value="<?php echo esc_attr($selected_prompt_language); ?>">
								<input type="hidden" name="base_speaker_type" value="<?php echo esc_attr($selected_prompt_speaker_type); ?>">
								<input type="hidden" name="speaker_filter" value="<?php echo esc_attr($selected_prompt_speaker_type); ?>">
								<?php
								$back_to_list_url = add_query_arg(
									array(
										'page' => 'Podcastmaker',
										'tab' => 'prompts',
										'action' => 'list',
										'base_language' => $selected_prompt_language,
										'base_speaker_type' => $selected_prompt_speaker_type,
										'speaker_filter' => $selected_prompt_speaker_type,
									),
									admin_url('admin.php')
								);
								?>
								<div class="Podcastmaker-prompt-editor-topbar">
									<a href="<?php echo esc_url($back_to_list_url); ?>" class="button"><?php echo esc_html__('Return to List', 'quikvox-ai'); ?></a>
								</div>
								<h3 class="Podcastmaker-prompt-set-field-title"><?php echo esc_html__('Prompt Set', 'quikvox-ai'); ?></h3>
								<table class="form-table">
									<tr>
										<th><label for="prompt_name"><?php echo esc_html__('Title', 'quikvox-ai'); ?></label></th>
										<td><input type="text" name="prompt_name" id="prompt_name" value="<?php echo esc_attr($current_data['name']); ?>" class="regular-text" required<?php echo $is_view_only_mode ? ' readonly' : ''; ?> <?php disabled($is_view_only_mode); ?> data-original-value="<?php echo esc_attr($current_data['name']); ?>"></td>
									</tr>
									<tr>
										<th><label for="prompt_content"><?php echo esc_html__('Prompt', 'quikvox-ai'); ?></label></th>
										<td>
											<textarea name="prompt_content" id="prompt_content" rows="10" cols="50" class="large-text code"<?php echo $is_view_only_mode ? ' readonly' : ''; ?> <?php disabled($is_view_only_mode); ?> data-original-value="<?php echo esc_attr($current_data['prompt']); ?>"><?php echo esc_textarea($current_data['prompt']); ?></textarea>
										</td>
									</tr>
								</table>
								<p class="submit Podcastmaker-prompt-editor-actions">
									<button type="button" class="button" id="Podcastmaker-prompt-edit-btn" <?php disabled($is_view_only_mode); ?>><?php echo esc_html__('Edit', 'quikvox-ai'); ?></button>
									<button type="button" class="button" id="Podcastmaker-prompt-cancel-btn" disabled><?php echo esc_html__('Cancel', 'quikvox-ai'); ?></button>
									<input type="submit" name="save_prompt_set" class="button button-primary" id="Podcastmaker-prompt-save-btn" value="<?php echo esc_attr__('Save Prompt Set', 'quikvox-ai'); ?>" disabled>
								</p>
							</form>

					<!-- AI Translation AJAX handled by admin.js via PodcastmakerAdminData -->

					<?php
		else: ?>
						<!-- List Mode -->
						<?php
			$add_prompt_url = add_query_arg(
				array(
					'page' => 'Podcastmaker',
					'tab' => 'prompts',
					'action' => 'add',
					'base_language' => $selected_prompt_language,
					'base_speaker_type' => $selected_prompt_speaker_type,
					'speaker_filter' => $selected_prompt_speaker_type,
				),
				admin_url('admin.php')
			);
			$filtered_sets = array_filter($all_sets, function ($data) use ($selected_prompt_language, $selected_prompt_speaker_type) {
				$record_language = isset($data['language']) ? $data['language'] : '';
				$speaker_type = isset($data['speaker_type']) ? $data['speaker_type'] : 'single';
				return $record_language === $selected_prompt_language && $speaker_type === $selected_prompt_speaker_type;
			});
?>
						<div class="Podcastmaker-prompt-toolbar">
							<h3 class="Podcastmaker-prompt-list-title"><?php echo esc_html__('Prompt List', 'quikvox-ai'); ?></h3>
							<a href="<?php echo esc_url($add_prompt_url); ?>" class="button button-primary"><?php echo esc_html__('+ Add New Prompt', 'quikvox-ai'); ?></a>
						</div>

						<table class="wp-list-table widefat striped">
							<thead>
								<tr>
									<th style="width: 50px;"><?php echo esc_html__('ID', 'quikvox-ai'); ?></th>
									<th style="width: 54px; text-align: center;"><?php echo esc_html__('Default', 'quikvox-ai'); ?></th>
									<th style="width: 72px; text-align: center;"><?php echo esc_html__('Type', 'quikvox-ai'); ?></th>
									<th style="width: 25%;"><?php echo esc_html__('Title', 'quikvox-ai'); ?></th>
									<th><?php echo esc_html__('Preview', 'quikvox-ai'); ?></th>
									<th><?php echo esc_html__('Last Update', 'quikvox-ai'); ?></th>
									<th style="width: 220px;"><?php echo esc_html__('Actions', 'quikvox-ai'); ?></th>
								</tr>
							</thead>
							<tbody>
								<?php
			if (empty($filtered_sets)) {
				echo '<tr><td colspan="7">' . esc_html__('No prompt sets found for the selected language and speaker type.', 'quikvox-ai') . '</td></tr>';
			}
					else {
						foreach ($filtered_sets as $id => $data) {
					$edit_url = add_query_arg(
						array(
							'page' => 'Podcastmaker',
							'tab' => 'prompts',
							'action' => 'edit',
							'id' => $id,
							'base_language' => $selected_prompt_language,
							'base_speaker_type' => $selected_prompt_speaker_type,
							'speaker_filter' => $selected_prompt_speaker_type,
						),
						admin_url('admin.php')
					);
					$view_url = add_query_arg(
						array(
							'page' => 'Podcastmaker',
							'tab' => 'prompts',
							'action' => 'view',
							'id' => $id,
							'base_language' => $selected_prompt_language,
							'base_speaker_type' => $selected_prompt_speaker_type,
							'speaker_filter' => $selected_prompt_speaker_type,
						),
						admin_url('admin.php')
					);

					$row_speaker_type = isset($data['speaker_type']) && $data['speaker_type'] === 'multi' ? 'multi' : 'single';
					$is_builtin_prompt_set = isset($data['source_type']) && $data['source_type'] === 'builtin';
					$is_default_single = $row_speaker_type === 'single' && $id === $default_single_prompt_set_id;
					$is_default_multi = $row_speaker_type === 'multi' && $id === $default_multi_prompt_set_id;
					$is_current_default = $is_default_single || $is_default_multi;
					$type_icon_class = $row_speaker_type === 'multi' ? 'dashicons-groups' : 'dashicons-admin-users';
?>
										<tr>
											<td style="font-weight: 600; color: #a0aec0; vertical-align: middle;"><?php echo isset($data['index_id']) ? esc_html($data['index_id']) : '-'; ?></td>
											<td style="text-align: center; vertical-align: middle;">
												<?php if ($is_current_default): ?>
													<span class="Podcastmaker-default-star is-active" title="<?php echo esc_attr__('Current default', 'quikvox-ai'); ?>" aria-label="<?php echo esc_attr__('Current default', 'quikvox-ai'); ?>">
														<span class="dashicons dashicons-star-filled"></span>
													</span>
												<?php else: ?>
													<form method="post" style="display:inline;">
														<?php wp_nonce_field('podcastmaker_set_default_prompt_' . $id); ?>
														<input type="hidden" name="id" value="<?php echo esc_attr($id); ?>">
														<input type="hidden" name="speaker_filter" value="<?php echo esc_attr($selected_prompt_speaker_type); ?>">
														<input type="hidden" name="base_language" value="<?php echo esc_attr($selected_prompt_language); ?>">
														<input type="hidden" name="base_speaker_type" value="<?php echo esc_attr($selected_prompt_speaker_type); ?>">
														<input type="hidden" name="default_speaker_type" value="<?php echo esc_attr($row_speaker_type); ?>">
														<button type="submit" name="set_default_prompt_set" class="Podcastmaker-default-star-toggle" title="<?php echo esc_attr__('Set as default', 'quikvox-ai'); ?>" aria-label="<?php echo esc_attr__('Set as default', 'quikvox-ai'); ?>">
															<span class="dashicons dashicons-star-empty"></span>
														</button>
														</form>
													<?php endif; ?>
											</td>
											<td class="Podcastmaker-prompt-list-type" style="text-align: center; vertical-align: middle;">
												<span class="speaker-type-icon <?php echo esc_attr($row_speaker_type); ?>" title="<?php echo esc_attr(ucfirst($row_speaker_type)); ?> Speaker" aria-label="<?php echo esc_attr(ucfirst($row_speaker_type)); ?> Speaker">
													<span class="dashicons <?php echo esc_attr($type_icon_class); ?>"></span>
												</span>
											</td>
											<td>
												<?php if ($is_builtin_prompt_set): ?>
													<strong><a href="<?php echo esc_url($view_url); ?>" style="text-decoration: none;"><?php echo !empty($data['name']) ? esc_html($data['name']) : esc_html__('(No Title)', 'quikvox-ai'); ?></a></strong>
													<span class="Podcastmaker-prompt-badge is-builtin"><?php echo esc_html__('Built-in', 'quikvox-ai'); ?></span>
												<?php else: ?>
													<strong><a href="<?php echo esc_url($edit_url); ?>" style="text-decoration: none;"><?php echo !empty($data['name']) ? esc_html($data['name']) : esc_html__('(No Title)', 'quikvox-ai'); ?></a></strong>
												<?php endif; ?>
											</td>
											<td><code style="font-size: 11px; color: #666;"><?php echo esc_html(mb_strimwidth($data['prompt'], 0, 80, '...')); ?></code></td>
											<td style="font-size: 11px; color: #666; white-space: nowrap;"><?php echo isset($data['last_updated']) ? esc_html(date_i18n('Y/m/d H:i', strtotime($data['last_updated']))) : '-'; ?></td>
											<td class="Podcastmaker-prompt-list-actions">
												<div class="row-actions Podcastmaker-prompt-set-actions" style="visibility: visible; position: static;">
													<span class="duplicate">
														<form method="post" style="display:inline;">
															<?php wp_nonce_field('podcastmaker_duplicate_prompt_' . $id); ?>
															<input type="hidden" name="action" value="duplicate">
															<input type="hidden" name="id" value="<?php echo esc_attr($id); ?>">
															<input type="hidden" name="speaker_filter" value="<?php echo esc_attr($selected_prompt_speaker_type); ?>">
															<input type="hidden" name="base_language" value="<?php echo esc_attr($selected_prompt_language); ?>">
															<input type="hidden" name="base_speaker_type" value="<?php echo esc_attr($selected_prompt_speaker_type); ?>">
															<button type="submit" name="duplicate_prompt_set" class="button-link" style="font-weight: 600; color: #00a32a; padding: 0; border: none; background: none; cursor: pointer; text-decoration: underline;"><?php echo esc_html__('Duplicate', 'quikvox-ai'); ?></button>
														</form>
													</span>
													<?php if ($is_builtin_prompt_set): ?>
														<span class="edit"> | <a href="<?php echo esc_url($view_url); ?>"><?php echo esc_html__('View', 'quikvox-ai'); ?></a></span>
													<?php else: ?>
														<span class="edit"> | <a href="<?php echo esc_url($edit_url); ?>"><?php echo esc_html__('Edit', 'quikvox-ai'); ?></a> | </span>
														<span class="trash">
															<form method="post" style="display:inline;">
																<?php wp_nonce_field('podcastmaker_delete_prompt_' . $id); ?>
																<input type="hidden" name="action" value="delete">
																<input type="hidden" name="id" value="<?php echo esc_attr($id); ?>">
																<input type="hidden" name="speaker_filter" value="<?php echo esc_attr($selected_prompt_speaker_type); ?>">
																<input type="hidden" name="base_language" value="<?php echo esc_attr($selected_prompt_language); ?>">
																<input type="hidden" name="base_speaker_type" value="<?php echo esc_attr($selected_prompt_speaker_type); ?>">
																<button type="submit" name="delete_prompt_set" class="button-link submitdelete pm-confirm-button" data-podcastmaker-confirm="<?php echo esc_attr__('Are you sure?', 'quikvox-ai'); ?>" style="color: #a00; padding: 0; border: none; background: none; cursor: pointer; text-decoration: underline;"><?php echo esc_attr__('Delete', 'quikvox-ai'); ?></button>
															</form>
														</span>
													<?php endif; ?>
												</div>
											</td>
										</tr>
										<?php
				}
			}
?>
							</tbody>
						</table>
					<?php
		endif; ?>
				</div>
			<?php
	endif; ?>
		</div>
	<?php if ($active_tab !== 'prompts' && $active_tab !== 'smart_tone'): ?>
	</form>
	<?php
	endif; ?>
</div>


<?php
}?>

