<?php
/**
 * Contentosapp Studio — New Production view.
 *
 * Rebuilt for Premium SaaS UI with Summary Rail.
 *
 * @package Contentosapp_Studio
 * @since   3.2.0
 */
defined( 'ABSPATH' ) || exit;
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals -- View template variables are scoped to this included admin file.

// $studio_plan_id is read (capability-gated, absint-sanitized) in the
// page_studio() menu callback before this template is included.
$plan_id = $studio_plan_id ?? 0;
$plan    = $plan_id ? Costudio_Planning::find( $plan_id ) : null;

// Get configured sites for the select
$sites_repo       = costudio_sites();
$configured_sites = $sites_repo ? $sites_repo->get_all() : [];
$active_sites     = array_filter(
	$configured_sites,
	function( $s, $key ) use ( $sites_repo ) {
		return $sites_repo ? $sites_repo->is_site_operable( (string) $key ) : ! empty( $s['active'] );
	},
	ARRAY_FILTER_USE_BOTH
);

$hub_url = function( $tab ) {
	return admin_url( 'admin.php?page=costudio-studio&tab=' . $tab );
};

$agents_def = [
	1 => [ 'label' => __( 'Discoverer', 'contentosapp-studio' ),   'icon' => '🔍' ],
	2 => [ 'label' => __( 'Strategist', 'contentosapp-studio' ),   'icon' => '🎯' ],
	3 => [ 'label' => __( 'Researcher', 'contentosapp-studio' ),   'icon' => '🔬' ],
	4 => [ 'label' => __( 'Writer', 'contentosapp-studio' ),       'icon' => '✍️' ],
	5 => [ 'label' => __( 'Visual Designer', 'contentosapp-studio' ), 'icon' => '🎨' ],
	6 => [ 'label' => __( 'Social Media', 'contentosapp-studio' ), 'icon' => '📢' ],
];

$content_languages        = Costudio_Admin::get_supported_content_languages();
$default_content_language = Costudio_Admin::get_default_content_language();
$content_language_flags   = [
	'pt_BR' => 'pt_BR.svg',
	'en_US' => 'en_US.svg',
	'es_ES' => 'es_ES.svg',
];
$content_language_flag_base = COSTUDIO_URL . 'assets/images/flags/';

// Determine the initial mode for the user.
$current_user_id = get_current_user_id();
$np_mode = get_user_meta( $current_user_id, 'costudio_np_mode', true );
if ( empty( $np_mode ) ) {
	// If the user has never set a preference, default to 'simple' for new users
	// (<= 3 productions) and 'advanced' for experienced users.
	$prod_count = Costudio_Production::count_total();
	$np_mode = $prod_count <= 3 ? 'simple' : 'advanced';
}
$is_simple = $np_mode === 'simple';

// $is_simple is already defined by the parent page-studio.php wrapper.
// If loaded directly, ensure it has a fallback.
if ( ! isset( $is_simple ) ) {
	$is_simple = false;
}
?>

<div id="fos-form-section" class="<?php echo esc_attr( $is_simple ? 'fos-np-mode-simple' : 'fos-np-mode-advanced' ); ?>">
	
	<form id="fos-production-form" class="fos-np-form" autocomplete="off">
		<input type="hidden" id="fos-plan-id-input" name="plan_id" value="<?php echo (int) $plan_id; ?>">
		<input type="hidden" id="fos-nicho"    name="nicho"    value="<?php echo esc_attr( $plan && isset( $configured_sites[ $plan->site_key ] ) ? costudio_site_display_name( $configured_sites[ $plan->site_key ], $plan->site_key ) : '' ); ?>">
		<input type="hidden" id="fos-extensao" name="extensao" value="2000-2600">

		<div class="fos-np-layout">
			
			<!-- Left Column: Config Flow -->
			<div class="fos-np-main-col">

				<!-- 1. Basics -->
				<div class="fos-np-section-card">
					<div class="fos-np-section-card__header">
						<div class="fos-np-section-card__num">1</div>
						<div class="fos-np-section-card__title-wrap">
							<h3 class="fos-np-section-card__title"><?php esc_html_e( 'Basics', 'contentosapp-studio' ); ?></h3>
							<p class="fos-np-section-card__subtitle"><?php esc_html_e( 'Where this article lives and what it\'s about', 'contentosapp-studio' ); ?></p>
						</div>
					</div>
					<div class="fos-np-section-card__body">
						<div class="fos-form-row fos-form-row--2">
							<div class="cts-field">
								<label class="cts-field__label" for="fos-site-key-select">
									<?php esc_html_e( 'Publishing site', 'contentosapp-studio' ); ?> <span class="fos-required">*</span>
								</label>
								<select id="fos-site-key-select" name="site_key" class="cts-input" required <?php disabled( empty( $configured_sites ) ); ?>>
									<option value=""><?php esc_html_e( '— Select site —', 'contentosapp-studio' ); ?></option>
									<?php 
									foreach ( $configured_sites as $key => $cfg ) :
										$is_disabled = empty( $cfg['active'] );
										$site_name   = costudio_site_display_name( $cfg, $key );
									?>
										<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $plan ? $plan->site_key : '', $key ); ?> <?php disabled( $is_disabled ); ?>>
											<?php echo esc_html( $site_name ); ?>
										</option>
									<?php endforeach; ?>
								</select>
							</div>

							<div class="cts-field">
								<label class="cts-field__label" for="fos-categoria-select">
									<?php esc_html_e( 'Category', 'contentosapp-studio' ); ?> <span class="fos-required">*</span>
								</label>
								<select id="fos-categoria-select" name="categoria" class="cts-input" required>
									<option value=""><?php esc_html_e( '— Select site first —', 'contentosapp-studio' ); ?></option>
									<?php if ( $plan && ! empty( $plan->category ) ) : ?>
										<option value="<?php echo esc_attr( $plan->category ); ?>" selected><?php echo esc_html( $plan->category ); ?></option>
									<?php endif; ?>
								</select>
							</div>
						</div>

						<div class="fos-form-row fos-form-row--2 fos-keyword-language-row">
							<div class="cts-field">
								<label class="cts-field__label" for="fos-keyword">
									<?php esc_html_e( 'Main keyword', 'contentosapp-studio' ); ?> <span class="fos-required">*</span>
								</label>
								<input type="text" id="fos-keyword" name="keyword" class="cts-input"
									placeholder="<?php esc_attr_e( 'Ex: how to protect WhatsApp', 'contentosapp-studio' ); ?>"
									required
									value="<?php echo esc_attr( $plan ? $plan->keyword : '' ); ?>">
								<p class="fos-field-hint"><?php esc_html_e( 'The SEO target. The Strategist uses this as the primary intent signal.', 'contentosapp-studio' ); ?></p>
							</div>

							<div class="cts-field">
								<label class="cts-field__label" for="fos-content-language">
									<?php esc_html_e( 'Content language', 'contentosapp-studio' ); ?> <span class="fos-required">*</span>
								</label>
								<div class="fos-content-language-select">
									<img id="fos-content-language-flag"
										src="<?php echo esc_url( $content_language_flag_base . $content_language_flags[ $default_content_language ] ); ?>"
										alt="" width="24" height="16" aria-hidden="true">
									<select id="fos-content-language" name="lang_code" class="cts-input" required>
										<?php foreach ( $content_languages as $code => $language_name ) : ?>
											<option value="<?php echo esc_attr( $code ); ?>"
												data-language-name="<?php echo esc_attr( $language_name ); ?>"
												<?php selected( $default_content_language, $code ); ?>><?php echo esc_html( $language_name ); ?></option>
										<?php endforeach; ?>
									</select>
								</div>
								<p class="fos-field-hint"><?php esc_html_e( 'Used only for this production. The default language in Settings will not be changed.', 'contentosapp-studio' ); ?></p>
							</div>
						</div>

						<div class="fos-form-row fos-form-row--2 fos-advanced-only">
							<div class="cts-field">
								<label class="cts-field__label" for="fos-angulo">
									<?php esc_html_e( 'Editorial angle', 'contentosapp-studio' ); ?> <span class="fos-required">*</span>
								</label>
								<div class="fos-ai-input-wrap fos-ai-input-wrap--adornment">
									<input type="text" id="fos-angulo" name="angulo" class="cts-input"
										placeholder="<?php esc_attr_e( 'Ex: How science explains why anxiety gets worse at night', 'contentosapp-studio' ); ?>"
										<?php echo esc_attr( $is_simple ? '' : 'required' ); ?>
										value="<?php echo esc_attr( $plan ? $plan->title : '' ); ?>">
									<button type="button" class="fos-ai-input-suggest fos-ai-input-suggest--adornment"
										data-field-type="angle" data-target="#fos-angulo"
										title="<?php esc_attr_e( 'Suggest angle', 'contentosapp-studio' ); ?>"
										aria-label="<?php esc_attr_e( 'Suggest angle', 'contentosapp-studio' ); ?>">
										<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="16" height="16" aria-hidden="true"><path d="M15.98 1.804a1 1 0 0 0-1.96 0l-.24 1.192a1 1 0 0 1-.784.785l-1.192.238a1 1 0 0 0 0 1.962l1.192.238a1 1 0 0 1 .785.785l.238 1.192a1 1 0 0 0 1.962 0l.238-1.192a1 1 0 0 1 .785-.785l1.192-.238a1 1 0 0 0 0-1.962l-1.192-.238a1 1 0 0 1-.785-.785l-.238-1.192ZM6.949 5.684a1 1 0 0 0-1.898 0l-.683 2.051a1 1 0 0 1-.633.633l-2.051.683a1 1 0 0 0 0 1.898l2.051.684a1 1 0 0 1 .633.632l.683 2.051a1 1 0 0 0 1.898 0l.683-2.051a1 1 0 0 1 .633-.633l2.051-.683a1 1 0 0 0 0-1.897l-2.051-.684a1 1 0 0 1-.633-.633L6.95 5.684ZM13.949 13.684a1 1 0 0 0-1.898 0l-.184.551a1 1 0 0 1-.632.633l-.551.183a1 1 0 0 0 0 1.898l.551.183a1 1 0 0 1 .633.633l.183.551a1 1 0 0 0 1.898 0l.184-.551a1 1 0 0 1 .632-.633l.551-.183a1 1 0 0 0 0-1.898l-.551-.184a1 1 0 0 1-.633-.632l-.183-.551Z"/></svg>
									</button>
								</div>
								<p class="fos-field-hint"><?php esc_html_e( 'Unique perspective that becomes the article H1.', 'contentosapp-studio' ); ?></p>
							</div>

							<div class="cts-field">
								<label class="cts-field__label" for="fos-perfil">
									<?php esc_html_e( 'Reader profile', 'contentosapp-studio' ); ?> <span class="fos-required">*</span>
								</label>
								<div class="fos-ai-input-wrap fos-ai-input-wrap--adornment">
									<input type="text" id="fos-perfil" name="perfil" class="cts-input"
										placeholder="<?php esc_attr_e( 'Ex: Women aged 25-40 with anxiety at work', 'contentosapp-studio' ); ?>"
										<?php echo esc_attr( $is_simple ? '' : 'required' ); ?>>
									<button type="button" class="fos-ai-input-suggest fos-ai-input-suggest--adornment"
										data-field-type="reader_profile" data-target="#fos-perfil"
										title="<?php esc_attr_e( 'Suggest profile', 'contentosapp-studio' ); ?>"
										aria-label="<?php esc_attr_e( 'Suggest profile', 'contentosapp-studio' ); ?>">
										<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" width="16" height="16" aria-hidden="true"><path d="M15.98 1.804a1 1 0 0 0-1.96 0l-.24 1.192a1 1 0 0 1-.784.785l-1.192.238a1 1 0 0 0 0 1.962l1.192.238a1 1 0 0 1 .785.785l.238 1.192a1 1 0 0 0 1.962 0l.238-1.192a1 1 0 0 1 .785-.785l1.192-.238a1 1 0 0 0 0-1.962l-1.192-.238a1 1 0 0 1-.785-.785l-.238-1.192ZM6.949 5.684a1 1 0 0 0-1.898 0l-.683 2.051a1 1 0 0 1-.633.633l-2.051.683a1 1 0 0 0 0 1.898l2.051.684a1 1 0 0 1 .633.632l.683 2.051a1 1 0 0 0 1.898 0l.683-2.051a1 1 0 0 1 .633-.633l2.051-.683a1 1 0 0 0 0-1.897l-2.051-.684a1 1 0 0 1-.633-.633L6.95 5.684ZM13.949 13.684a1 1 0 0 0-1.898 0l-.184.551a1 1 0 0 1-.632.633l-.551.183a1 1 0 0 0 0 1.898l.551.183a1 1 0 0 1 .633.633l.183.551a1 1 0 0 0 1.898 0l.184-.551a1 1 0 0 1 .632-.633l.551-.183a1 1 0 0 0 0-1.898l-.551-.184a1 1 0 0 1-.633-.632l-.183-.551Z"/></svg>
									</button>
								</div>
								<p class="fos-field-hint"><?php esc_html_e( 'The more specific, the better the article tone.', 'contentosapp-studio' ); ?></p>
							</div>
						</div>
					</div>
				</div>

				<!-- 2. Article Type -->
				<div class="fos-np-section-card">
					<div class="fos-np-section-card__header">
						<div class="fos-np-section-card__num">2</div>
						<div class="fos-np-section-card__title-wrap">
							<h3 class="fos-np-section-card__title"><?php esc_html_e( 'Article type', 'contentosapp-studio' ); ?></h3>
							<p class="fos-np-section-card__subtitle"><?php esc_html_e( 'Shapes the pipeline behavior and word count', 'contentosapp-studio' ); ?></p>
						</div>
					</div>
					<div class="fos-np-section-card__body">
						
						<div class="fos-np-type-chips">
							<label class="fos-np-type-chip">
								<input type="radio" name="article_type" value="pillar">
								<div class="fos-np-type-chip__box">
									<span class="fos-np-type-chip__icon">📚</span>
									<span class="fos-np-type-chip__label"><?php esc_html_e( 'Pilar', 'contentosapp-studio' ); ?></span>
									<span class="fos-np-type-chip__desc"><?php esc_html_e( 'Definitive guide', 'contentosapp-studio' ); ?></span>
								</div>
								<div class="fos-np-type-chip__check">✓</div>
							</label>

							<label class="fos-np-type-chip">
								<input type="radio" name="article_type" value="satellite" checked>
								<div class="fos-np-type-chip__box">
									<span class="fos-np-type-chip__icon">🛰️</span>
									<span class="fos-np-type-chip__label"><?php esc_html_e( 'Satellite', 'contentosapp-studio' ); ?></span>
									<span class="fos-np-type-chip__desc"><?php esc_html_e( 'Support article', 'contentosapp-studio' ); ?></span>
								</div>
								<div class="fos-np-type-chip__check">✓</div>
							</label>

							<label class="fos-np-type-chip">
								<input type="radio" name="article_type" value="comparison">
								<div class="fos-np-type-chip__box">
									<span class="fos-np-type-chip__icon">⚖️</span>
									<span class="fos-np-type-chip__label"><?php esc_html_e( 'Comparison', 'contentosapp-studio' ); ?></span>
									<span class="fos-np-type-chip__desc"><?php esc_html_e( 'Unbiased analysis', 'contentosapp-studio' ); ?></span>
								</div>
								<div class="fos-np-type-chip__check">✓</div>
							</label>

							<label class="fos-np-type-chip">
								<input type="radio" name="article_type" value="news">
								<div class="fos-np-type-chip__box">
									<span class="fos-np-type-chip__icon">📰</span>
									<span class="fos-np-type-chip__label"><?php esc_html_e( 'News', 'contentosapp-studio' ); ?></span>
									<span class="fos-np-type-chip__desc"><?php esc_html_e( 'Timely factual', 'contentosapp-studio' ); ?></span>
								</div>
								<div class="fos-np-type-chip__check">✓</div>
							</label>

							<label class="fos-np-type-chip">
								<input type="radio" name="article_type" value="update">
								<div class="fos-np-type-chip__box">
									<span class="fos-np-type-chip__icon">🔄</span>
									<span class="fos-np-type-chip__label"><?php esc_html_e( 'Update', 'contentosapp-studio' ); ?></span>
									<span class="fos-np-type-chip__desc"><?php esc_html_e( 'Refresh existing', 'contentosapp-studio' ); ?></span>
								</div>
								<div class="fos-np-type-chip__check">✓</div>
							</label>
						</div>

						<div id="fos-type-context" class="fos-type-context">
							<!-- pillar -->
							<div class="fos-type-panel" data-panel-type="pillar">
								<div class="fos-type-panel__header-new">
									<span class="fos-type-panel__header-icon">📚</span>
									<div class="fos-type-panel__header-title"><?php esc_html_e( 'Pillar', 'contentosapp-studio' ); ?> — <?php esc_html_e( 'Definitive guide', 'contentosapp-studio' ); ?></div>
									<div class="fos-type-panel__header-words">3.000–5.000 <?php esc_html_e( 'words', 'contentosapp-studio' ); ?></div>
								</div>
								<div class="fos-type-panel__blurb" style="margin-bottom: 0;">
									<?php esc_html_e( 'Full pipeline runs. Strategist builds a comprehensive structure with multiple sections, FAQs, and maximum depth.', 'contentosapp-studio' ); ?>
								</div>
							</div>

							<!-- satellite -->
							<div class="fos-type-panel fos-type-panel--active" data-panel-type="satellite">
								<div class="fos-type-panel__header-new">
									<span class="fos-type-panel__header-icon">🛰️</span>
									<div class="fos-type-panel__header-title"><?php esc_html_e( 'Satellite', 'contentosapp-studio' ); ?> — <?php esc_html_e( 'Support article', 'contentosapp-studio' ); ?></div>
									<div class="fos-type-panel__header-words">2.000–2.600 <?php esc_html_e( 'words', 'contentosapp-studio' ); ?></div>
								</div>
								<div class="fos-type-panel__blurb" style="margin-bottom: 0;">
									<?php esc_html_e( 'Standard production. Optionally linked to a Pillar article for automatic interlinking.', 'contentosapp-studio' ); ?>
								</div>
								<div class="cts-field" style="margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--fos-primary-border);">
									<label class="cts-field__label" for="fos-pilar-url-display">
										<?php esc_html_e( 'Related Pillar article', 'contentosapp-studio' ); ?> <span style="font-weight: normal; color: var(--fos-text-dim);">[<?php esc_html_e( 'optional', 'contentosapp-studio' ); ?>]</span>
									</label>
									<div class="fos-np-links-search-row">
										<input type="text" id="fos-pilar-url-display" class="cts-input fos-np-links-input" placeholder="<?php esc_attr_e( 'Pillar URL or title', 'contentosapp-studio' ); ?>">
										<div class="fos-np-links-actions">
											<button type="button" class="cts-btn cts-btn--ghost fos-btn-limpar-busca" id="fos-btn-limpar-pilar" style="display:none;" title="<?php esc_attr_e( 'Clear', 'contentosapp-studio' ); ?>">&times;</button>
											<button type="button" class="cts-btn cts-btn--secondary fos-np-btn-search-wp" id="fos-btn-buscar-pilar">
												<svg class="fos-search-btn-icon fos-search-btn-icon--search" width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
													<circle cx="6" cy="6" r="4.5" stroke="currentColor" stroke-width="1.5"/>
													<path d="M9.5 9.5L12.5 12.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
												</svg>
												<svg class="fos-search-btn-icon fos-search-btn-icon--spinner" width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
													<circle cx="7" cy="7" r="5.5" stroke="currentColor" stroke-width="1.5" stroke-dasharray="22" stroke-dashoffset="8" stroke-linecap="round"/>
												</svg>
												<span class="fos-search-btn-label"><?php esc_html_e( 'Search WP', 'contentosapp-studio' ); ?></span>
												<span class="fos-search-btn-label--loading" aria-live="polite"><?php esc_html_e( 'Searching…', 'contentosapp-studio' ); ?></span>
											</button>
										</div>
									</div>
									<div id="fos-pilar-search-results" style="display:none; margin-top:8px;"></div>
									<div style="font-size: 11px; color: var(--fos-text-dim); margin-top: 5px; line-height: 1.5;">
										<?php esc_html_e( 'The Satellite will link back to this Pillar article for SEO cluster strategy.', 'contentosapp-studio' ); ?>
									</div>
									<input type="hidden" name="pilar_url" id="fos-pilar-url">
									<input type="hidden" name="pilar_title" id="fos-pilar-title">
								</div>
							</div>

							<!-- comparison -->
							<div class="fos-type-panel" data-panel-type="comparison">
								<div class="fos-type-panel__header-new">
									<span class="fos-type-panel__header-icon">⚖️</span>
									<div class="fos-type-panel__header-title"><?php esc_html_e( 'Comparison', 'contentosapp-studio' ); ?> — <?php esc_html_e( 'Unbiased analysis', 'contentosapp-studio' ); ?></div>
									<div class="fos-type-panel__header-words">2.500–4.000 <?php esc_html_e( 'words', 'contentosapp-studio' ); ?></div>
								</div>
								<div class="fos-type-panel__blurb">
									<?php esc_html_e( 'Bottom-of-funnel product review. Researcher looks up real data per item. Output includes comparison table, pros/cons boxes, and affiliate CTA buttons.', 'contentosapp-studio' ); ?>
								</div>
								<div class="cts-field">
									<label class="cts-field__label"><?php esc_html_e( 'Items to compare', 'contentosapp-studio' ); ?> <span class="fos-required">*</span></label>
									<div class="fos-type-dynamic-list" id="fos-comp-list">
										<div class="fos-type-dynamic-item">
											<div class="fos-type-dynamic-item__num">1</div>
											<input type="text" class="cts-input fos-comp-input fos-comp-input-label" placeholder="<?php esc_attr_e( 'Product or service name', 'contentosapp-studio' ); ?>" style="flex:1; border:none; padding:6px 4px; height:auto; box-shadow:none; outline:none; background:transparent;">
											<div style="width:1px; background:var(--fos-border); margin:4px 0;"></div>
											<input type="url" class="cts-input fos-comp-input-url" placeholder="<?php esc_attr_e( 'https://... (optional)', 'contentosapp-studio' ); ?>" style="flex:1; border:none; padding:6px 4px; height:auto; box-shadow:none; outline:none; background:transparent; font-family:var(--fos-font-mono); font-size:12px; color:var(--fos-text-sub);">
											<button type="button" class="fos-type-remove-btn">&times;</button>
										</div>
										<div class="fos-type-dynamic-item">
											<div class="fos-type-dynamic-item__num">2</div>
											<input type="text" class="cts-input fos-comp-input fos-comp-input-label" placeholder="<?php esc_attr_e( 'Product or service name', 'contentosapp-studio' ); ?>" style="flex:1; border:none; padding:6px 4px; height:auto; box-shadow:none; outline:none; background:transparent;">
											<div style="width:1px; background:var(--fos-border); margin:4px 0;"></div>
											<input type="url" class="cts-input fos-comp-input-url" placeholder="<?php esc_attr_e( 'https://... (optional)', 'contentosapp-studio' ); ?>" style="flex:1; border:none; padding:6px 4px; height:auto; box-shadow:none; outline:none; background:transparent; font-family:var(--fos-font-mono); font-size:12px; color:var(--fos-text-sub);">
											<button type="button" class="fos-type-remove-btn">&times;</button>
										</div>
									</div>
									<button type="button" class="fos-type-add-btn" id="fos-add-comp-btn" style="margin-top:8px;">+ <?php esc_html_e( 'Add item (up to 8)', 'contentosapp-studio' ); ?></button>
									<input type="hidden" name="comparison_items" id="fos-comp-items-json">
								</div>
								<div class="cts-field" style="margin-top:12px;">
									<label class="cts-field__label" for="fos-comp-crit"><?php esc_html_e( 'Comparison criteria', 'contentosapp-studio' ); ?> <span style="font-weight: normal; color: var(--fos-text-dim);">[<?php esc_html_e( 'optional', 'contentosapp-studio' ); ?>]</span></label>
									<input type="text" id="fos-comp-crit" name="comparison_criteria" class="cts-input" placeholder="<?php esc_attr_e( 'Price, quality, steam performance...', 'contentosapp-studio' ); ?>">
								</div>
							</div>

							<!-- news -->
							<div class="fos-type-panel" data-panel-type="news">
								<div class="fos-type-panel__header-new">
									<span class="fos-type-panel__header-icon">📰</span>
									<div class="fos-type-panel__header-title"><?php esc_html_e( 'News', 'contentosapp-studio' ); ?> — <?php esc_html_e( 'Factual, synthesised from multiple sources', 'contentosapp-studio' ); ?></div>
									<div class="fos-type-panel__header-words">800–1.200 <?php esc_html_e( 'words', 'contentosapp-studio' ); ?></div>
								</div>
								<div class="fos-type-panel__blurb">
									<?php esc_html_e( 'The Researcher reads every source URL (any language) and identifies their editorial DNA. The Writer produces an ORIGINAL news piece that mirrors that DNA, adapted to the output language.', 'contentosapp-studio' ); ?>
								</div>
								<div class="cts-field">
									<label class="cts-field__label"><?php esc_html_e( 'Inspiration sources', 'contentosapp-studio' ); ?> <span class="fos-required">*</span></label>
									<div class="fos-type-dynamic-list" id="fos-news-list">
										<div class="fos-type-dynamic-item">
											<div class="fos-type-dynamic-item__dot"></div>
											<input type="url" class="cts-input fos-news-input" placeholder="https://..." style="flex:1; border:none; padding:0; height:auto; box-shadow:none; outline:none;">
											<button type="button" class="fos-type-remove-btn">&times;</button>
										</div>
									</div>
									<button type="button" class="fos-type-add-btn" id="fos-add-news-btn" style="margin-top:8px;">+ <?php esc_html_e( 'Add source', 'contentosapp-studio' ); ?></button>
									<div style="font-size: 11px; color: var(--fos-text-dim); margin-top: 6px; line-height: 1.5;">
										<?php esc_html_e( 'Sources are inspiration — the Writer will NOT copy them. Mixing languages is fine; the output stays in the site language.', 'contentosapp-studio' ); ?>
									</div>
								</div>
								<div class="cts-field" style="margin-top:12px;">
									<label class="cts-field__label" for="fos-news-author-id"><?php esc_html_e( 'Author', 'contentosapp-studio' ); ?> <span class="fos-required">*</span></label>
									<?php
									wp_dropdown_users(
										array(
											'name'             => 'news_author_id',
											'id'               => 'fos-news-author-id',
											'class'            => 'cts-input',
											'role__in'         => array( 'administrator', 'editor', 'author' ),
											'show_option_none' => esc_html__( '— Select author —', 'contentosapp-studio' ),
											'option_none_value' => 0,
											'selected'         => get_current_user_id(),
										)
									);
									?>
									<div style="font-size: 11px; color: var(--fos-text-dim); margin-top: 5px; line-height: 1.5;">
										<?php esc_html_e( 'Appears in the byline and the article schema as author (Person). Strengthens E-E-A-T signals.', 'contentosapp-studio' ); ?>
									</div>
								</div>
							</div>

							<!-- update -->
							<div class="fos-type-panel" data-panel-type="update">
								<div class="fos-type-panel__header-new">
									<span class="fos-type-panel__header-icon">🔄</span>
									<div class="fos-type-panel__header-title"><?php esc_html_e( 'Update', 'contentosapp-studio' ); ?> — <?php esc_html_e( 'Refresh existing', 'contentosapp-studio' ); ?></div>
								</div>
								<div class="fos-type-panel__blurb">
									<?php esc_html_e( 'Original post is fetched via REST API, passed to the Writer as context, then updated in WordPress.', 'contentosapp-studio' ); ?>
								</div>
								<div class="cts-field">
									<label class="cts-field__label"><?php esc_html_e( 'Search existing article', 'contentosapp-studio' ); ?> <span class="fos-required">*</span></label>
									<div class="fos-np-links-search-row">
										<input type="text" id="fos-update-url-display" class="cts-input fos-np-links-input" placeholder="<?php esc_attr_e( 'Title or URL', 'contentosapp-studio' ); ?>">
										<div class="fos-np-links-actions">
											<button type="button" class="cts-btn cts-btn--ghost fos-btn-limpar-busca" id="fos-btn-limpar-update" style="display:none;">&times;</button>
											<button type="button" class="cts-btn cts-btn--secondary fos-np-btn-search-wp" id="fos-btn-buscar-update">
												<svg class="fos-search-btn-icon fos-search-btn-icon--search" width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
													<circle cx="6" cy="6" r="4.5" stroke="currentColor" stroke-width="1.5"/>
													<path d="M9.5 9.5L12.5 12.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
												</svg>
												<svg class="fos-search-btn-icon fos-search-btn-icon--spinner" width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
													<circle cx="7" cy="7" r="5.5" stroke="currentColor" stroke-width="1.5" stroke-dasharray="22" stroke-dashoffset="8" stroke-linecap="round"/>
												</svg>
												<span class="fos-search-btn-label"><?php esc_html_e( 'Search WP', 'contentosapp-studio' ); ?></span>
												<span class="fos-search-btn-label--loading" aria-live="polite"><?php esc_html_e( 'Searching…', 'contentosapp-studio' ); ?></span>
											</button>
										</div>
									</div>
									<div id="fos-update-search-results" style="display:none; margin-top:8px;"></div>
									<div id="fos-update-selected-result" style="display:none; margin-top:8px;"></div>
									<input type="hidden" name="update_post_id" id="fos-update-id">
									<input type="hidden" name="update_post_url" id="fos-update-url">
									<input type="hidden" name="update_post_title" id="fos-update-title">
									<input type="hidden" name="update_post_content" id="fos-update-content">
								</div>
								<div class="cts-field" style="margin-top:12px;">
									<label class="cts-field__label" for="fos-update-inst"><?php esc_html_e( 'What to update', 'contentosapp-studio' ); ?> <span class="fos-required">*</span></label>
									<textarea id="fos-update-inst" name="update_instructions" rows="3" class="cts-input fos-np-textarea"></textarea>
								</div>
							</div>
						</div>

						<!-- Publish & Execution Mode -->
						<div class="fos-form-row fos-form-row--2 fos-advanced-only">
							<div class="cts-field">
								<label class="cts-field__label"><?php esc_html_e( 'Publish as', 'contentosapp-studio' ); ?></label>
								<div class="fos-np-segmented" id="fos-publish-mode-segmented" style="display: flex;">
									<button type="button" class="fos-np-segmented__btn is-active" data-mode="draft">📝 <?php esc_html_e( 'Draft', 'contentosapp-studio' ); ?></button>
									<button type="button" class="fos-np-segmented__btn" data-mode="scheduled">📅 <?php esc_html_e( 'Scheduled', 'contentosapp-studio' ); ?></button>
									<button type="button" class="fos-np-segmented__btn" data-mode="published">✅ <?php esc_html_e( 'Published', 'contentosapp-studio' ); ?></button>
								</div>
								<input type="hidden" id="fos-publish-mode" name="publish_mode" value="draft">
								<div id="fos-publish-hint" class="fos-field-hint" style="margin-top: 3px;">
									<?php esc_html_e( 'Article saved as draft — review and publish manually.', 'contentosapp-studio' ); ?>
								</div>
								<div id="fos-publish-date-wrap" style="display:none; margin-top: 8px;">
									<div class="fos-date-input-wrap">
										<span class="fos-date-input-wrap__icon">📅</span>
										<input type="text" id="fos-publish-date" name="publish_date" class="cts-input fos-np-date-input fos-np-date-input--with-icon" style="width: auto;" placeholder="<?php esc_attr_e( 'Select date and time...', 'contentosapp-studio' ); ?>">
									</div>
								</div>
							</div>

							<div class="cts-field">
								<label class="cts-field__label"><?php esc_html_e( 'Execution', 'contentosapp-studio' ); ?></label>
								<div class="fos-np-segmented" id="fos-exec-mode-segmented" style="display: flex;">
									<button type="button" class="fos-np-segmented__btn is-active" data-mode="auto">⚡ <?php esc_html_e( 'Automatic', 'contentosapp-studio' ); ?></button>
									<button type="button" class="fos-np-segmented__btn" data-mode="manual">✋ <?php esc_html_e( 'Manual review', 'contentosapp-studio' ); ?></button>
								</div>
								<input type="hidden" id="fos-exec-mode" name="execution_mode" value="auto">
								<div id="fos-exec-hint" class="fos-field-hint" style="margin-top: 3px;">
									<?php esc_html_e( 'The pipeline runs directly from Agent 1 to 7.', 'contentosapp-studio' ); ?>
								</div>
							</div>
						</div>
					</div>
				</div>

				<!-- 3. Article References -->
				<div class="fos-np-section-card fos-advanced-only" id="fos-refs-card">
					<div class="fos-np-section-card__header">
						<div class="fos-np-section-card__num">3</div>
						<div class="fos-np-section-card__title-wrap">
							<h3 class="fos-np-section-card__title">
								<?php esc_html_e( 'Article references', 'contentosapp-studio' ); ?>
								<span class="fos-np-badge-optional"><?php esc_html_e( 'Optional', 'contentosapp-studio' ); ?></span>
							</h3>
							<p class="fos-np-section-card__subtitle"><?php esc_html_e( 'Links for the Writer agent to use for interlinking and as sources', 'contentosapp-studio' ); ?></p>
						</div>
						<div class="fos-refs-tabs" role="tablist">
							<button type="button" class="fos-refs-tab fos-refs-tab--active" data-tab="internal">
								<?php esc_html_e( 'Internal links', 'contentosapp-studio' ); ?>
								<span class="fos-tab-count" data-tab="internal">0</span>
							</button>
							<button type="button" class="fos-refs-tab" data-tab="external">
								<?php esc_html_e( 'External links', 'contentosapp-studio' ); ?>
								<span class="fos-tab-count" data-tab="external">0</span>
							</button>
						</div>
					</div>

					<div id="fos-refs-panel-internal" class="fos-refs-panel fos-refs-panel--active" style="padding: 20px;">
						<?php if ( empty( $active_sites ) ) : ?>
							<p class="fos-field-hint"><?php esc_html_e( 'No active sites.', 'contentosapp-studio' ); ?></p>
						<?php else : ?>
							<div class="fos-refs-filter-row">
								<span class="fos-refs-filter-label"><?php esc_html_e( 'Search in', 'contentosapp-studio' ); ?></span>
								<?php if ( count( $active_sites ) <= 3 ) : ?>
									<div class="fos-refs-chips fos-refs-chips--legacy-sites" id="fos-links-site-checkboxes">
										<?php foreach ( $active_sites as $sk => $scfg ) : ?>
											<input type="checkbox" class="fos-links-site-cb fos-chip-cb" id="fos-site-cb-<?php echo esc_attr( $sk ); ?>" value="<?php echo esc_attr( $sk ); ?>" checked>
											<label class="fos-chip fos-chip--active" for="fos-site-cb-<?php echo esc_attr( $sk ); ?>"><span class="fos-chip__dot"></span><?php echo esc_html( $scfg['name'] ?? $sk ); ?></label>
										<?php endforeach; ?>
									</div>
								<?php else : ?>
								<div
									class="fos-refs-site-picker"
									id="fos-links-site-checkboxes"
									data-label-all="<?php esc_attr_e( 'All sites', 'contentosapp-studio' ); ?>"
									data-label-none="<?php esc_attr_e( 'No site selected', 'contentosapp-studio' ); ?>"
									<?php /* translators: %d: number of selected sites (singular) */ ?>
									data-label-one="<?php esc_attr_e( '%d site selected', 'contentosapp-studio' ); ?>"
									<?php /* translators: %d: number of selected sites (plural) */ ?>
									data-label-many="<?php esc_attr_e( '%d sites selected', 'contentosapp-studio' ); ?>"
								>
									<button type="button" class="fos-refs-site-picker__toggle" id="fos-links-sites-toggle" aria-haspopup="true" aria-expanded="false" aria-controls="fos-links-sites-menu">
										<span class="fos-refs-site-picker__badges" id="fos-links-sites-badges" aria-hidden="true">
											<?php
											$badge_index = 0;
											foreach ( $active_sites as $sk => $scfg ) :
												if ( $badge_index >= 4 ) {
													break;
												}
												$site_name    = (string) ( $scfg['name'] ?? $sk );
												$site_initial = function_exists( 'mb_substr' ) ? mb_substr( $site_name, 0, 1, 'UTF-8' ) : substr( $site_name, 0, 1 );
												$site_colors  = costudio_site_color_vars( $scfg );
												?>
												<span
													class="fos-refs-site-badge"
													data-site-key="<?php echo esc_attr( $sk ); ?>"
													data-site-accent="<?php echo esc_attr( $site_colors['accent'] ); ?>"
													data-site-soft="<?php echo esc_attr( $site_colors['soft'] ); ?>"
													data-site-border="<?php echo esc_attr( $site_colors['border'] ); ?>"
													style="<?php echo esc_attr( $site_colors['style'] ); ?>"
												><?php echo esc_html( strtoupper( $site_initial ) ); ?></span>
												<?php
												$badge_index++;
											endforeach;
											if ( count( $active_sites ) > 4 ) :
												?>
												<span class="fos-refs-site-badge fos-refs-site-badge--more">+<?php echo esc_html( count( $active_sites ) - 4 ); ?></span>
											<?php endif; ?>
										</span>
										<span class="fos-refs-site-picker__summary" aria-live="polite">
											<?php esc_html_e( 'All sites', 'contentosapp-studio' ); ?>
										</span>
										<span class="fos-refs-site-picker__chevron" aria-hidden="true">v</span>
									</button>
									<div class="fos-refs-site-picker__menu" id="fos-links-sites-menu" role="group" aria-label="<?php esc_attr_e( 'Search in', 'contentosapp-studio' ); ?>" hidden>
										<div class="fos-refs-site-picker__tools">
											<input type="search" class="fos-refs-site-picker__search" id="fos-links-sites-search" placeholder="<?php esc_attr_e( 'Search site...', 'contentosapp-studio' ); ?>" autocomplete="off">
											<div class="fos-refs-site-picker__actions">
												<button type="button" class="fos-refs-site-picker__action" data-site-action="all"><?php esc_html_e( 'All', 'contentosapp-studio' ); ?></button>
												<button type="button" class="fos-refs-site-picker__action" data-site-action="none"><?php esc_html_e( 'None', 'contentosapp-studio' ); ?></button>
												<span class="fos-refs-site-picker__count" id="fos-links-sites-count"></span>
											</div>
										</div>
										<div class="fos-refs-site-picker__options">
											<?php foreach ( $active_sites as $sk => $scfg ) : ?>
												<?php $site_name = (string) ( $scfg['name'] ?? $sk ); ?>
												<?php $site_initial = function_exists( 'mb_substr' ) ? mb_substr( $site_name, 0, 1, 'UTF-8' ) : substr( $site_name, 0, 1 ); ?>
												<?php $site_colors = costudio_site_color_vars( $scfg ); ?>
												<input type="checkbox" class="fos-links-site-cb fos-chip-cb" id="fos-site-cb-<?php echo esc_attr( $sk ); ?>" value="<?php echo esc_attr( $sk ); ?>" checked>
												<label
													class="fos-refs-site-option fos-refs-site-option--active"
													for="fos-site-cb-<?php echo esc_attr( $sk ); ?>"
													role="checkbox"
													aria-checked="true"
													tabindex="0"
													data-site-key="<?php echo esc_attr( $sk ); ?>"
													data-site-name="<?php echo esc_attr( strtolower( $site_name ) ); ?>"
													data-site-label="<?php echo esc_attr( $site_name ); ?>"
													data-site-initial="<?php echo esc_attr( strtoupper( $site_initial ) ); ?>"
													data-site-accent="<?php echo esc_attr( $site_colors['accent'] ); ?>"
													data-site-soft="<?php echo esc_attr( $site_colors['soft'] ); ?>"
													data-site-border="<?php echo esc_attr( $site_colors['border'] ); ?>"
													style="<?php echo esc_attr( $site_colors['style'] ); ?>"
												>
													<span class="fos-refs-site-option__check" aria-hidden="true"></span>
													<span class="fos-refs-site-option__badge" aria-hidden="true"><?php echo esc_html( strtoupper( $site_initial ) ); ?></span>
													<span class="fos-refs-site-option__name"><?php echo esc_html( $site_name ); ?></span>
												</label>
											<?php endforeach; ?>
											<div class="fos-refs-site-picker__empty" hidden><?php esc_html_e( 'No sites found.', 'contentosapp-studio' ); ?></div>
										</div>
									</div>
								</div>
								<?php endif; ?>
								
								<span class="fos-refs-filter-label fos-refs-type-label"><?php esc_html_e( 'Type', 'contentosapp-studio' ); ?></span>
								<div class="fos-refs-chips">
									<input type="checkbox" class="fos-links-type-cb fos-chip-cb" id="fos-type-cb-post" value="post" checked>
									<label class="fos-chip fos-chip--active" for="fos-type-cb-post"><span class="fos-chip__dot"></span><?php esc_html_e( 'Posts', 'contentosapp-studio' ); ?></label>
									
									<input type="checkbox" class="fos-links-type-cb fos-chip-cb" id="fos-type-cb-page" value="page">
									<label class="fos-chip" for="fos-type-cb-page">
										<span class="fos-chip__dot"></span><?php esc_html_e( 'Pages', 'contentosapp-studio' ); ?>
										<span class="fos-refs-tooltip-wrap">
											<span class="fos-refs-tooltip-icon" aria-hidden="true">?</span>
											<span class="fos-refs-tooltip-text" role="tooltip"><?php esc_html_e( 'Include static pages.', 'contentosapp-studio' ); ?></span>
										</span>
									</label>
								</div>
							</div>
							<div class="fos-np-links-search-row">
								<input type="text" id="fos-links-keywords" class="cts-input fos-np-links-input" placeholder="<?php esc_attr_e( 'Search keywords...', 'contentosapp-studio' ); ?>">
								<div class="fos-np-links-actions">
									<button type="button" id="fos-links-clear-btn" class="cts-btn cts-btn--ghost"><?php esc_html_e( 'Clear', 'contentosapp-studio' ); ?></button>
									<button type="button" id="fos-preview-links-btn" class="cts-btn fos-np-btn-search-wp">
										<svg class="fos-search-btn-icon fos-search-btn-icon--search" width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
											<circle cx="6" cy="6" r="4.5" stroke="currentColor" stroke-width="1.5"/>
											<path d="M9.5 9.5L12.5 12.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
										</svg>
										<svg class="fos-search-btn-icon fos-search-btn-icon--spinner" width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
											<circle cx="7" cy="7" r="5.5" stroke="currentColor" stroke-width="1.5" stroke-dasharray="22" stroke-dashoffset="8" stroke-linecap="round"/>
										</svg>
										<span class="fos-search-btn-label"><?php esc_html_e( 'Search WP', 'contentosapp-studio' ); ?></span>
										<span class="fos-search-btn-label--loading" aria-live="polite"><?php esc_html_e( 'Searching…', 'contentosapp-studio' ); ?></span>
									</button>
								</div>
							</div>
							
							<div id="fos-links-results-wrap" style="display:none">
								<div id="fos-links-result-list" class="fos-links-result-list"></div>
							</div>
							<p id="fos-links-empty-msg" class="fos-links-empty-msg"><?php esc_html_e( 'No search yet. Selected links will be sent to the Writer agent.', 'contentosapp-studio' ); ?></p>

							<div id="fos-links-selected-wrap" style="display:none; margin-top:10px;">
								<div style="font-size:10px; font-weight:700; color:var(--fos-text-dim); letter-spacing:0.6px; text-transform:uppercase; margin-bottom:6px;">
									<?php esc_html_e( 'Selected', 'contentosapp-studio' ); ?> (<span id="fos-links-selected-count">0</span>)
								</div>
								<div id="fos-links-selected-list" style="display:flex; flex-direction:column; gap:4px;"></div>
							</div>
						<?php endif; ?>
					</div>

					<div id="fos-refs-panel-external" class="fos-refs-panel" style="padding: 20px;" hidden>
						<div class="fos-refs-ext-fields">
							<div class="cts-field">
								<label class="fos-refs-field-label"><?php esc_html_e( 'URL', 'contentosapp-studio' ); ?></label>
								<input type="url" id="fos-ext-url" class="cts-input" placeholder="https://...">
							</div>
							<div class="cts-field">
								<label class="fos-refs-field-label"><?php esc_html_e( 'Description', 'contentosapp-studio' ); ?></label>
								<input type="text" id="fos-ext-desc" class="cts-input" placeholder="<?php esc_attr_e( 'Ex: statistics study', 'contentosapp-studio' ); ?>">
							</div>
							<div class="fos-refs-ext-add-col">
								<button type="button" id="fos-ext-add-btn" class="cts-btn fos-np-btn-search-wp">
									<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true" style="margin-right:4px;">
										<path d="M7 1v12M1 7h12" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
									</svg>
									<?php esc_html_e( 'Add link', 'contentosapp-studio' ); ?>
								</button>
							</div>
						</div>
						
						<div id="fos-ext-list" class="fos-ext-list" style="display:none"></div>
						<p id="fos-ext-empty-msg" class="fos-links-empty-msg"><?php esc_html_e( 'No external links added.', 'contentosapp-studio' ); ?></p>
						<div id="fos-ext-many-warn" class="fos-notice fos-notice--warn" style="display:none;margin-top:12px">
							<?php esc_html_e( 'Too many external links can dilute the article focus.', 'contentosapp-studio' ); ?>
						</div>
					</div>
					<input type="hidden" id="fos-links-internos-json" name="links_internos" value="">
				</div>

				<!-- 4. Notes -->
				<div class="fos-np-section-card fos-advanced-only">
					<div class="fos-np-section-card__header">
						<div class="fos-np-section-card__num">4</div>
						<div class="fos-np-section-card__title-wrap">
							<h3 class="fos-np-section-card__title">
								<?php esc_html_e( 'Notes for agents', 'contentosapp-studio' ); ?>
								<span class="fos-np-badge-optional"><?php esc_html_e( 'Optional', 'contentosapp-studio' ); ?></span>
							</h3>
							<p class="fos-np-section-card__subtitle"><?php esc_html_e( 'Direct instructions that will guide the AI tone, structure, or constraints', 'contentosapp-studio' ); ?></p>
						</div>
					</div>
					<div class="fos-np-section-card__body">
						<textarea id="fos-notes-geral" name="notas_adicionais" class="cts-input fos-np-textarea" rows="3" placeholder="<?php esc_attr_e( 'Ex: Use a persuasive tone, mention the 2026 legislation in section 3, add a CTA to download our e-book, do NOT mention competitors...', 'contentosapp-studio' ); ?>"></textarea>
					</div>
				</div>

				<!-- ── ERROR NOTICE (inline, above footer) ── -->
				<div id="fos-error-notice" style="display:none" class="fos-np-error-notice">
					<div class="fos-np-error-notice__icon">❌</div>
					<div class="fos-np-error-notice__content">
						<strong class="fos-np-error-notice__title"><?php esc_html_e( 'Production error', 'contentosapp-studio' ); ?></strong>
						<span class="fos-np-error-notice__msg" id="fos-error-message"><?php esc_html_e( 'An unexpected error occurred.', 'contentosapp-studio' ); ?></span>
					</div>
				</div>

				<!-- Submit Bar -->
				<div class="fos-np-footer-bar">
					<div class="fos-np-footer-status" id="fos-form-status-msg">
						<span>Complete fields to continue</span>
					</div>
					<div class="fos-np-footer-actions">
						<a href="<?php echo esc_url( $hub_url( 'central' ) ); ?>" class="cts-btn cts-btn--ghost"><?php esc_html_e( 'Cancel', 'contentosapp-studio' ); ?></a>
						<button type="submit" id="fos-start-btn" class="cts-btn cts-btn--primary cts-btn--lg">🚀 <?php esc_html_e( 'Start production', 'contentosapp-studio' ); ?></button>
					</div>
				</div>

			</div> <!-- /fos-np-main-col -->

			<!-- Right Column: Summary Rail -->
			<aside class="fos-summary-rail">
				
				<div class="fos-summary-card">
					<div class="fos-summary-card__header">
						<div class="fos-summary-card__eyebrow"><?php esc_html_e( 'Summary', 'contentosapp-studio' ); ?></div>
						<div class="fos-summary-card__title fos-summary-card__title--placeholder" id="fos-summary-angle-preview">
							<?php esc_html_e( 'Your editorial angle...', 'contentosapp-studio' ); ?>
						</div>
					</div>
					<div class="fos-summary-card__body">
						<div class="fos-summary-row">
							<span class="fos-summary-row__key"><?php esc_html_e( 'Type', 'contentosapp-studio' ); ?></span>
							<span class="fos-summary-row__val" id="fos-summary-type-val"><span class="fos-status-pill fos-status-pill--planned">🛰️ Satellite</span></span>
						</div>
						<div class="fos-summary-row">
							<span class="fos-summary-row__key"><?php esc_html_e( 'Keyword', 'contentosapp-studio' ); ?></span>
							<span class="fos-summary-row__val fos-summary-row__val--empty" id="fos-summary-kw-val">—</span>
						</div>
						<div class="fos-summary-row">
							<span class="fos-summary-row__key"><?php esc_html_e( 'Site', 'contentosapp-studio' ); ?></span>
							<span class="fos-summary-row__val fos-summary-row__val--empty" id="fos-summary-site-val">—</span>
						</div>
						<div class="fos-summary-row">
							<span class="fos-summary-row__key"><?php esc_html_e( 'Category', 'contentosapp-studio' ); ?></span>
							<span class="fos-summary-row__val fos-summary-row__val--empty" id="fos-summary-cat-val">—</span>
						</div>
						<div class="fos-summary-row">
							<span class="fos-summary-row__key"><?php esc_html_e( 'Language', 'contentosapp-studio' ); ?></span>
							<span class="fos-summary-row__val fos-summary-language" id="fos-summary-language-val">
								<img id="fos-summary-language-flag"
									src="<?php echo esc_url( $content_language_flag_base . $content_language_flags[ $default_content_language ] ); ?>"
									alt="" width="20" height="14" aria-hidden="true">
								<span id="fos-summary-language-name"><?php echo esc_html( $content_languages[ $default_content_language ] ); ?></span>
							</span>
						</div>
						<div class="fos-summary-row">
							<span class="fos-summary-row__key"><?php esc_html_e( 'Publish', 'contentosapp-studio' ); ?></span>
							<span class="fos-summary-row__val" id="fos-summary-publish-val"><?php esc_html_e( 'Draft', 'contentosapp-studio' ); ?></span>
						</div>
					</div>
					<div class="fos-summary-card__footer">
						<div class="fos-summary-progress">
							<span class="fos-summary-progress__label"><?php esc_html_e( 'Progress', 'contentosapp-studio' ); ?></span>
							<span class="fos-summary-progress__pct" id="fos-summary-pct">0%</span>
						</div>
						<div class="fos-summary-progress-bar">
							<div class="fos-summary-progress-fill" id="fos-summary-fill"></div>
						</div>
					</div>
				</div>

				<div class="fos-pipeline-preview">
					<div class="fos-pipeline-preview__header">
						<div class="fos-pipeline-preview__title"><?php esc_html_e( 'Pipeline sequence', 'contentosapp-studio' ); ?></div>
					</div>
					<div class="fos-pipeline-preview__body">
						<?php foreach ( $agents_def as $step => $a ) : ?>
							<div class="fos-pipeline-step" data-step="<?php echo (int) $step; ?>">
								<div class="fos-pipeline-step__icon"><?php echo wp_kses_post( $a['icon'] ); ?></div>
								<div class="fos-pipeline-step__name"><?php echo esc_html( $a['label'] ); ?></div>
								<div class="fos-pipeline-step__num"><?php
								/* translators: %d: pipeline step number (1 to 7) */
								printf(
									/* translators: %d: setup wizard step number. */
									esc_html__( 'Step %d', 'contentosapp-studio' ),
									(int) $step
								); ?></div>
							</div>
						<?php endforeach; ?>
					</div>
				</div>

			</aside>

		</div> <!-- /fos-np-layout -->

	</form>
</div>

<?php
// ── BYOK first-production warning modal ─────────────────────────────────────
// One-time advisory shown when a BYOK user starts their first production.
// Costs run on their own provider account, so we make that explicit before
// the first run. The decision is persisted in the `costudio_byok_warning_dismissed`
// option — never shown again afterwards.
$cts            = function_exists( 'costudio_settings' ) ? costudio_settings() : null;
$ai_mode        = $cts ? (string) $cts->get( 'ai_mode', '' ) : '';
$is_byok_mode   = ( $ai_mode === 'byok' );
$byok_dismissed = (bool) get_option( 'costudio_byok_warning_dismissed', false );
$show_byok_warning = $is_byok_mode && ! $byok_dismissed;
$byok_nonce     = wp_create_nonce( Costudio_Admin::NONCE );
?>
<div id="fos-byok-warning-modal"
	data-show="<?php echo esc_attr( $show_byok_warning ? '1' : '0' ); ?>"
	data-nonce="<?php echo esc_attr( $byok_nonce ); ?>"
	style="display:none;position:fixed;inset:0;z-index:100000;background:rgba(0,0,0,0.5);align-items:center;justify-content:center;">
	<div class="fos-modal-card">
		<div class="fos-modal-card__header">
			<div class="fos-modal-card__title-wrap">
				<span class="fos-modal-card__hicon">💳</span>
				<span class="fos-modal-card__title"><?php esc_html_e( 'You are using your own API key', 'contentosapp-studio' ); ?></span>
			</div>
			<button type="button" class="fos-modal-card__close" id="fos-byok-warning-x" aria-label="<?php esc_attr_e( 'Close', 'contentosapp-studio' ); ?>">&times;</button>
		</div>
		<div class="fos-modal-card__body">
			<p style="margin:0 0 14px;font-size:13px;color:#374151;line-height:1.6;">
				<?php esc_html_e( 'Generation costs will be charged directly on your provider account (Google Gemini, OpenAI or Anthropic).', 'contentosapp-studio' ); ?>
			</p>
			<p style="margin:0 0 14px;font-size:13px;color:#374151;line-height:1.6;">
				<strong><?php esc_html_e( 'The cost of each article varies depending on the AI model selected and the length of the content.', 'contentosapp-studio' ); ?></strong>
			</p>
			<p style="margin:0;font-size:13px;color:#4b5563;line-height:1.6;">
				<?php esc_html_e( 'Track your spending in the provider console. To configure spend alerts, set up budget alerts directly there.', 'contentosapp-studio' ); ?>
			</p>
		</div>
		<div class="fos-modal-card__footer" style="gap:8px;">
			<button type="button" class="fos-modal-card__btn--ghost" id="fos-byok-warning-cancel">
				<?php esc_html_e( 'Cancel', 'contentosapp-studio' ); ?>
			</button>
			<button type="button" class="fos-modal-card__btn--primary" id="fos-byok-warning-confirm">
				<?php esc_html_e( 'Got it, start production', 'contentosapp-studio' ); ?>
			</button>
		</div>
	</div>
</div>
