<?php
/**
 * Costudio_Admin_Assets — CSS/JS enqueueing for the admin UI.
 *
 * Owns the entire admin_enqueue_scripts flow: shared stylesheet, page-specific
 * CSS/JS bundles (dashboard, detail, studio hub/production/settings, license,
 * setup wizard), third-party libs (marked, DOMPurify, flatpickr), and the
 * localized CostudioData payload (URLs, nonces, site map, i18n strings).
 *
 * Extracted from Costudio_Admin as part of Task 2 (PR 3 — Assets split).
 *
 * @package Contentosapp_Studio
 * @since   3.2.0
 */

defined( 'ABSPATH' ) || exit;

class Costudio_Admin_Assets {

	/** @var self|null */
	private static ?self $instance = null;

	private function __construct() {}

	public static function get_instance(): self {
		if ( null === self::$instance ) {
			self::$instance = new self();
		}
		return self::$instance;
	}

	/**
	 * Wire the asset-loading hook.
	 */
	public function register_hooks(): void {
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
	}

	/**
	 * Enqueue styles, scripts and localized data for Contentosapp Studio admin pages.
	 */
	public function enqueue_assets( string $hook = '' ): void {
		// Hide internal submenu links everywhere in wp-admin (they must remain registered for user_can_access_admin_page).
		if ( current_user_can( 'manage_options' ) ) {
			wp_register_style( 'costudio-submenu-internal-hide', false, array(), COSTUDIO_VERSION );
			wp_enqueue_style( 'costudio-submenu-internal-hide' );
			wp_add_inline_style(
				'costudio-submenu-internal-hide',
				'#toplevel_page_costudio .wp-submenu > li > a[href*="page=costudio-setup"],'
				. '#toplevel_page_costudio .wp-submenu > li > a[href*="page=costudio-detalhe"] { display: none !important; }'
				. '#toplevel_page_costudio .fos-has-flyout { position: relative; overflow: visible !important; }'
				. '#toplevel_page_costudio .fos-has-flyout > a { position: relative; padding-right: 24px; }'
				. '#toplevel_page_costudio .fos-has-flyout > a::after { content: "\f139"; font-family: dashicons; position: absolute; right: 5px; top: 50%; transform: translateY(-50%); opacity: 0.8; font-size: 14px; width: 14px; height: 14px; }'
				. '#toplevel_page_costudio .fos-flyout-menu { display: none; position: absolute; left: 100%; top: -5px; width: 150px; background: #2c3338; z-index: 999999; padding: 5px 0; }'
				. '#toplevel_page_costudio .fos-has-flyout:hover .fos-flyout-menu { display: block; }'
				. '#toplevel_page_costudio .fos-flyout-menu a { display: block; padding: 5px 12px !important; margin: 0 !important; color: rgba(255,255,255,0.8) !important; text-decoration: none !important; font-size: 13px !important; line-height: 1.5 !important; transition: all .15s; font-weight: 400 !important; }'
			);

			wp_register_script( 'costudio-submenu-flyout', false, array( 'jquery' ), COSTUDIO_VERSION, true );
			wp_enqueue_script( 'costudio-submenu-flyout' );
			wp_add_inline_script(
				'costudio-submenu-flyout',
				'jQuery(document).ready(function($) {
					var $studio = $("#toplevel_page_costudio .wp-submenu a[href*=\'page=costudio-studio\']").parent("li");
					if ($studio.length) {
						$studio.addClass("fos-has-flyout");
						var $flyout = $(\'<div class="fos-flyout-menu">\' +
							\'<a href="admin.php?page=costudio-studio&tab=hub&paged=1">\' + ' . wp_json_encode( __( 'Content Hub', 'contentosapp-studio' ) ) . ' + \'</a>\' +
							\'<a href="admin.php?page=costudio-studio&tab=producao&paged=1">\' + ' . wp_json_encode( __( 'New Production', 'contentosapp-studio' ) ) . ' + \'</a>\' +
						\'</div>\');
						$studio.append($flyout);
					}
				});'
			);
		}

		// Called via 'contentos_module_assets_costudio' action.
		// Guard: only enqueue main Contentosapp Studio assets on Contentosapp Studio admin pages.
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only admin routing parameter.
		$page = sanitize_key( wp_unslash( $_GET['page'] ?? '' ) );
		if ( 0 !== strpos( $page, 'costudio' ) ) {
			return;
		}

		// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only admin navigation parameter.
		$studio_tab = sanitize_key( wp_unslash( $_GET['tab'] ?? 'hub' ) );

		// Ensure contentos-tokens is registered before declaring it as a dependency.
		// ContentOS Core only enqueues it on its own pages (contentos-*), not on costudio-* pages.
		if ( ! wp_style_is( 'contentos-tokens', 'registered' ) ) {
			if ( defined( 'CONTENTOS_PLUGIN_DIR' ) && defined( 'CONTENTOS_PLUGIN_URL' ) ) {
				$tokens_file = CONTENTOS_PLUGIN_DIR . 'assets/css/admin-tokens.css';
				if ( is_readable( $tokens_file ) ) {
					wp_enqueue_style(
						'contentos-tokens',
						CONTENTOS_PLUGIN_URL . 'assets/css/admin-tokens.css',
						array(),
						filemtime( $tokens_file )
					);
				}
			}
		}

		$costudio_css_deps = wp_style_is( 'contentos-tokens', 'registered' ) ? array( 'contentos-tokens' ) : array();
		wp_enqueue_style(
			'costudio-admin',
			COSTUDIO_URL . 'admin/costudio-admin.css',
			$costudio_css_deps,
			COSTUDIO_VERSION
		);

		// Detail page: isolated stylesheet loaded only on the detail screen.
		if ( 'costudio-detalhe' === $page ) {
			$detail_css = COSTUDIO_DIR . 'admin/css/costudio-admin-detail.css';
			if ( is_readable( $detail_css ) ) {
				wp_enqueue_style(
					'costudio-admin-detail',
					COSTUDIO_URL . 'admin/css/costudio-admin-detail.css',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION
				);
			}

			$inspector_css = COSTUDIO_DIR . 'admin/css/costudio-output-inspector.css';
			if ( is_readable( $inspector_css ) ) {
				wp_enqueue_style(
					'costudio-output-inspector',
					COSTUDIO_URL . 'admin/css/costudio-output-inspector.css',
					array( 'costudio-admin-detail' ),
					COSTUDIO_VERSION
				);
			}
		}

		// Dashboard page: isolated stylesheet.
		if ( 'costudio' === $page ) {
			$dashboard_css = COSTUDIO_DIR . 'admin/css/costudio-admin-dashboard.css';
			if ( is_readable( $dashboard_css ) ) {
				wp_enqueue_style(
					'costudio-admin-dashboard',
					COSTUDIO_URL . 'admin/css/costudio-admin-dashboard.css',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION
				);
			}
		}

		// Studio page: skeleton loaders shared across hub/production/settings tabs.
		if ( 'costudio-studio' === $page ) {
			$skeleton_css = COSTUDIO_DIR . 'admin/css/costudio-admin-skeleton.css';
			if ( is_readable( $skeleton_css ) ) {
				wp_enqueue_style(
					'costudio-admin-skeleton',
					COSTUDIO_URL . 'admin/css/costudio-admin-skeleton.css',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION
				);
			}
		}

		// License page: isolated stylesheet.
		if ( 'costudio-license' === $page ) {
			$license_css = COSTUDIO_DIR . 'admin/css/costudio-admin-license.css';
			if ( is_readable( $license_css ) ) {
				wp_enqueue_style(
					'costudio-admin-license',
					COSTUDIO_URL . 'admin/css/costudio-admin-license.css',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION
				);
			}
		}

		// Sprint B.3 + B.4 — Buy Extra Quotas modal + Confirm Extra modal CSS:
		// load on the three pages that host their triggers:
		//   - License page  → "Buy more credits" button (B.3)
		//   - Dashboard     → "+ Buy" pill (B.3)
		//   - Studio        → quota-blocked Caso B (B.4) + confirm-extra Caso A (B.4)
		// Both modals share this single stylesheet (.fos-modal__box--addon and
		// --confirm variants live in the same file).
		if ( in_array( $page, array( 'costudio', 'costudio-license', 'costudio-studio', 'costudio-detalhe' ), true ) ) {
			$addon_css = COSTUDIO_DIR . 'admin/css/costudio-addon.css';
			if ( is_readable( $addon_css ) ) {
				wp_enqueue_style(
					'costudio-addon',
					COSTUDIO_URL . 'admin/css/costudio-addon.css',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION
				);
			}
		}

		// Load page-specific third-party libraries only where they are used.
		$needs_flatpickr = ( 'costudio-studio' === $page );
		$needs_markdown  = ( 'costudio-detalhe' === $page );

		$script_deps = array( 'jquery' );
		if ( $needs_flatpickr ) {
			wp_enqueue_style(
				'flatpickr-css',
				COSTUDIO_URL . 'admin/lib/flatpickr.min.css',
				array(),
				'4.6.13'
			);
			wp_enqueue_script(
				'flatpickr-js',
				COSTUDIO_URL . 'admin/lib/flatpickr.min.js',
				array(),
				'4.6.13',
				true
			);
			$script_deps[] = 'flatpickr-js';
		}

		if ( $needs_markdown ) {
			wp_enqueue_script(
				'marked-js',
				COSTUDIO_URL . 'admin/lib/marked.min.js',
				array(),
				'15.0.12',
				true
			);
			wp_enqueue_script(
				'dompurify-js',
				COSTUDIO_URL . 'admin/lib/dompurify.min.js',
				array(),
				'3.2.4',
				true
			);
			$script_deps[] = 'marked-js';
			$script_deps[] = 'dompurify-js';
		}

		wp_enqueue_script(
			'costudio-admin',
			COSTUDIO_URL . 'admin/costudio-admin.js',
			$script_deps,
			COSTUDIO_VERSION,
			true
		);

		// Setup wizard page: enqueue sites + integrations scripts (AI test + site modal).
		if ( 'costudio-setup' === $page ) {
			$wizard_deps = array( 'costudio-admin' );

			$sites_js = COSTUDIO_DIR . 'admin/js/costudio-admin-sites.js';
			if ( is_readable( $sites_js ) ) {
				wp_enqueue_script(
					'costudio-admin-sites',
					COSTUDIO_URL . 'admin/js/costudio-admin-sites.js',
					$wizard_deps,
					COSTUDIO_VERSION,
					true
				);
				$wizard_deps[] = 'costudio-admin-sites';
			}

			$integrations_js = COSTUDIO_DIR . 'admin/js/costudio-admin-settings-integrations.js';
			if ( is_readable( $integrations_js ) ) {
				wp_enqueue_script(
					'costudio-admin-settings-integrations',
					COSTUDIO_URL . 'admin/js/costudio-admin-settings-integrations.js',
					$wizard_deps,
					COSTUDIO_VERSION,
					true
				);
			}
		}

		// Detail page: load isolated behaviors after the shared admin bundle.
		if ( 'costudio-detalhe' === $page ) {
			$inspector_js = COSTUDIO_DIR . 'admin/js/costudio-output-inspector.js';
			if ( is_readable( $inspector_js ) ) {
				wp_enqueue_script(
					'costudio-output-inspector',
					COSTUDIO_URL . 'admin/js/costudio-output-inspector.js',
					array( 'costudio-admin', 'marked-js', 'dompurify-js' ),
					COSTUDIO_VERSION,
					true
				);
			}

			$detail_js = COSTUDIO_DIR . 'admin/js/costudio-admin-detail.js';
			if ( is_readable( $detail_js ) ) {
				wp_enqueue_script(
					'costudio-admin-detail',
					COSTUDIO_URL . 'admin/js/costudio-admin-detail.js',
					array( 'costudio-admin', 'costudio-output-inspector' ),
					COSTUDIO_VERSION,
					true
				);
			}
		}

		// License page: isolated interactions.
		if ( 'costudio-license' === $page ) {
			$license_js = COSTUDIO_DIR . 'admin/js/costudio-admin-license.js';
			if ( is_readable( $license_js ) ) {
				wp_enqueue_script(
					'costudio-admin-license',
					COSTUDIO_URL . 'admin/js/costudio-admin-license.js',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION,
					true
				);
			}
		}

		// Sprint B.3 + B.4 — Buy Extra Quotas modal controller: now also
		// enqueued on Studio page so the production form (Nova Produção)
		// can open the buy modal in production_blocked context when the
		// user hits the quota wall.
		if ( in_array( $page, array( 'costudio', 'costudio-license', 'costudio-studio', 'costudio-detalhe' ), true ) ) {
			$addon_js = COSTUDIO_DIR . 'admin/js/costudio-addon-checkout.js';
			if ( is_readable( $addon_js ) ) {
				wp_enqueue_script(
					'costudio-addon-checkout',
					COSTUDIO_URL . 'admin/js/costudio-addon-checkout.js',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION,
					true
				);
			}
		}

		// Sprint B.4.2 — Confirm Extra Credit Use modal controller (Caso A).
		// Studio page only — it's only triggered from the production submit
		// flow when the user has extras balance but monthly is exhausted.
		if ( 'costudio-studio' === $page ) {
			$confirm_js = COSTUDIO_DIR . 'admin/js/costudio-confirm-extra.js';
			if ( is_readable( $confirm_js ) ) {
				wp_enqueue_script(
					'costudio-confirm-extra',
					COSTUDIO_URL . 'admin/js/costudio-confirm-extra.js',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION,
					true
				);
			}
		}

		// Dashboard page: quick-add queue interactions.
		if ( 'costudio' === $page ) {
			$dashboard_js = COSTUDIO_DIR . 'admin/js/costudio-admin-dashboard.js';
			if ( is_readable( $dashboard_js ) ) {
				wp_enqueue_script(
					'costudio-admin-dashboard',
					COSTUDIO_URL . 'admin/js/costudio-admin-dashboard.js',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION,
					true
				);
			}
		}

		// Studio page: Load Hub AND Production assets simultaneously for SPA-like navigation.
		if ( 'costudio-studio' === $page ) {
			$hub_css = COSTUDIO_DIR . 'admin/css/costudio-admin-hub.css';
			if ( is_readable( $hub_css ) ) {
				wp_enqueue_style(
					'costudio-admin-hub',
					COSTUDIO_URL . 'admin/css/costudio-admin-hub.css',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION
				);
			}

			$hub_js = COSTUDIO_DIR . 'admin/js/costudio-admin-hub.js';
			if ( is_readable( $hub_js ) ) {
				wp_enqueue_script(
					'costudio-admin-hub',
					COSTUDIO_URL . 'admin/js/costudio-admin-hub.js',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION,
					true
				);
			}

			$production_css = COSTUDIO_DIR . 'admin/css/costudio-admin-production.css';
			if ( is_readable( $production_css ) ) {
				wp_enqueue_style(
					'costudio-admin-production',
					COSTUDIO_URL . 'admin/css/costudio-admin-production.css',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION
				);
			}

			$production_js = COSTUDIO_DIR . 'admin/js/costudio-admin-production.js';
			if ( is_readable( $production_js ) ) {
				wp_enqueue_script(
					'costudio-admin-production',
					COSTUDIO_URL . 'admin/js/costudio-admin-production.js',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION,
					true
				);
			}
		}

		// Settings (standalone page OR studio tab): language flag preview interactions.
		if ( 'costudio-settings' === $page || ( 'costudio-studio' === $page && 'settings' === $studio_tab ) ) {
			$settings_css = COSTUDIO_DIR . 'admin/css/costudio-admin-settings.css';
			if ( is_readable( $settings_css ) ) {
				wp_enqueue_style(
					'costudio-admin-settings',
					COSTUDIO_URL . 'admin/css/costudio-admin-settings.css',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION
				);
			}

			$settings_lang_css = COSTUDIO_DIR . 'admin/css/costudio-admin-settings-language.css';
			if ( is_readable( $settings_lang_css ) ) {
				wp_enqueue_style(
					'costudio-admin-settings-language',
					COSTUDIO_URL . 'admin/css/costudio-admin-settings-language.css',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION
				);
			}

			$sites_js = COSTUDIO_DIR . 'admin/js/costudio-admin-sites.js';
			if ( is_readable( $sites_js ) ) {
				wp_enqueue_script(
					'costudio-admin-sites',
					COSTUDIO_URL . 'admin/js/costudio-admin-sites.js',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION,
					true
				);
			}

			$settings_integrations_js = COSTUDIO_DIR . 'admin/js/costudio-admin-settings-integrations.js';
			if ( is_readable( $settings_integrations_js ) ) {
				wp_enqueue_script(
					'costudio-admin-settings-integrations',
					COSTUDIO_URL . 'admin/js/costudio-admin-settings-integrations.js',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION,
					true
				);
			}

			$settings_lang_js = COSTUDIO_DIR . 'admin/js/costudio-admin-settings-language.js';
			if ( is_readable( $settings_lang_js ) ) {
				wp_enqueue_script(
					'costudio-admin-settings-language',
					COSTUDIO_URL . 'admin/js/costudio-admin-settings-language.js',
					array( 'costudio-admin-settings-integrations' ),
					COSTUDIO_VERSION,
					true
				);
			}

			$agents_js = COSTUDIO_DIR . 'admin/js/costudio-admin-agents.js';
			if ( is_readable( $agents_js ) ) {
				wp_enqueue_script(
					'costudio-admin-agents',
					COSTUDIO_URL . 'admin/js/costudio-admin-agents.js',
					array( 'costudio-admin' ),
					COSTUDIO_VERSION,
					true
				);
			}

			// 🎙️ Brand Voice Assets
			if ( class_exists( 'Costudio_Brand_Voice' ) ) {
				$bv_css = COSTUDIO_DIR . 'admin/css/costudio-brand-voice.css';
				if ( is_readable( $bv_css ) ) {
					wp_enqueue_style(
						'costudio-brand-voice',
						COSTUDIO_URL . 'admin/css/costudio-brand-voice.css',
						array( 'costudio-admin-settings' ),
						COSTUDIO_VERSION
					);
				}

				$bv_js = COSTUDIO_DIR . 'admin/js/costudio-brand-voice.js';
				if ( is_readable( $bv_js ) ) {
					wp_enqueue_script(
						'costudio-brand-voice',
						COSTUDIO_URL . 'admin/js/costudio-brand-voice.js',
						array( 'costudio-admin' ),
						COSTUDIO_VERSION,
						true
					);
				}
			}
		}

		$sites_repo = costudio_sites();
		$sites      = $sites_repo ? $sites_repo->get_all() : array();
		$site_map   = array();
		$site_data  = array();
		foreach ( $sites as $key => $cfg ) {
			$site_map[ $key ]  = costudio_site_display_name( $cfg, $key );
			// Expose safe fields only — never expose the password.
			$site_data[ $key ] = array(
				'name'       => costudio_site_display_name( $cfg, $key ),
				'url'        => $cfg['url']        ?? '',
				'user'       => $cfg['user']       ?? '',
				'color'      => $cfg['color']      ?? '#3b82f6',
				'categories' => $cfg['categories'] ?? array(),
			);
		}

		// Sprint B.3.6.1 — Snapshot of usage + addon balance for the modal's
		// context line ("You have X extras + Y service quota credits left this month").
		// Reads cached transients only (no remote sync here) — Path A from
		// the polish plan: we already have this data server-side, just expose
		// it. The modal opens with accurate-enough context; if a webhook just
		// credited the balance, the next page nav picks up the fresh value.
		$_lic_for_ctx       = Costudio_Standalone_License::get_instance();
		$_addon_for_ctx     = Costudio_Standalone_License::get_addon_balance();
		$_monthly_count_ctx = Costudio_Standalone_License::get_monthly_count();
		$_service_limit_ctx = (int) $_lic_for_ctx->get_api_production_limit();
		$_addon_context     = array(
			'addon_enabled'     => ! empty( $_addon_for_ctx['enabled'] ),
			'addon_balance'     => (int) ( $_addon_for_ctx['balance'] ?? 0 ),
			'monthly_remaining' => max( 0, $_service_limit_ctx - (int) $_monthly_count_ctx ),
		);

		wp_localize_script(
			'costudio-admin',
			'CostudioData',
			array(
				'ajax_url'           => admin_url( 'admin-ajax.php' ),
				'nonce'              => wp_create_nonce( Costudio_Admin::NONCE ),
				'hub_url'            => admin_url( 'admin.php?page=costudio-studio&tab=hub' ),
				'settings_url'       => admin_url( 'admin.php?page=costudio-settings' ),
				'license_url'        => admin_url( 'admin.php?page=costudio-license' ),
				'upgrade_url'        => defined( 'COSTUDIO_FOS_PRO_URL' ) ? COSTUDIO_FOS_PRO_URL : admin_url( 'admin.php?page=costudio-license' ),
				'addon_context'      => $_addon_context,
				'site_map'           => $site_map,
				'site_data'          => $site_data,
				'site_cats'          => $this->get_site_categories(),
				'models_cache'       => class_exists( 'Costudio_Admin_Model_Discovery' )
					? Costudio_Admin_Model_Discovery::normalize_model_cache( (array) get_option( 'costudio_models_cache', array() ) )
					: get_option( 'costudio_models_cache', array() ),
				'image_models_cache' => class_exists( 'Costudio_Admin_Model_Discovery' )
					? Costudio_Admin_Model_Discovery::normalize_model_cache( (array) get_option( 'costudio_image_models_cache', array() ) )
					: get_option( 'costudio_image_models_cache', array() ),
				'flag_url_base'      => COSTUDIO_URL . 'assets/images/flags/',
				'flag_map'           => array(
					'pt_BR' => 'pt_BR.svg',
					'en_US' => 'en_US.svg',
					'es_ES' => 'es_ES.svg',
				),
				'i18n'               => array(
					'confirm_publish'            => __( 'Publish this article to WordPress?', 'contentosapp-studio' ),
					'confirm_delete'             => __( 'Are you sure you want to delete this item?', 'contentosapp-studio' ),
					'confirm_delete_site'        => __( 'Delete this site?', 'contentosapp-studio' ),
					'confirm_deactivate_license' => __( 'Are you sure you want to deactivate the license? This will free up an activation slot.', 'contentosapp-studio' ),
					'confirm_reset_sites'        => __( 'Delete ALL configured sites? This cannot be undone.', 'contentosapp-studio' ),
					'saved'                      => __( 'Saved!', 'contentosapp-studio' ),
					'saved_check'                => __( '✓ Saved!', 'contentosapp-studio' ),
					'selected_model'             => __( 'Selected model', 'contentosapp-studio' ),
					'error'                      => __( 'Error', 'contentosapp-studio' ),
					'error_generic'              => __( 'Error.', 'contentosapp-studio' ),
					'testing'                    => __( 'Testing…', 'contentosapp-studio' ),
					'connected'                  => __( 'Connected', 'contentosapp-studio' ),
					'connected_check'            => __( '✓ Connected!', 'contentosapp-studio' ),
					'no_site_connected'          => __( 'No site connected — articles will be saved as drafts only.', 'contentosapp-studio' ),
					'add_site_settings'          => __( 'Adicionar um site nas Configurações →', 'contentosapp-studio' ),
					'agent_badge_adjusted'         => __( 'Adjusted', 'contentosapp-studio' ),
					'agent_badge_default'          => __( 'Default', 'contentosapp-studio' ),
					'agent_saved'                  => __( 'Agent saved.', 'contentosapp-studio' ),
					'agent_save_error'             => __( 'Error saving agent.', 'contentosapp-studio' ),
					'agent_history_load_error'     => __( 'Could not load history.', 'contentosapp-studio' ),
					'agent_history_empty'          => __( 'No history yet. A snapshot is saved each time you save this agent.', 'contentosapp-studio' ),
					'agent_history_temp'           => __( 'Temp: {value}', 'contentosapp-studio' ),
					'agent_history_niche'          => __( 'Niche: {value}', 'contentosapp-studio' ),
					'agent_history_extra_chars'    => __( 'Extra: {count} chars', 'contentosapp-studio' ),
					'agent_history_no_adjustments' => __( 'No adjustments', 'contentosapp-studio' ),
					'restore'                      => __( 'Restore', 'contentosapp-studio' ),
					'reset_all_confirm'            => __( 'Reset all adjustments (niche, extra instructions, temperature) for all 7 agents? This cannot be undone.', 'contentosapp-studio' ),
					'all_adjustments_reset'        => __( 'All adjustments reset.', 'contentosapp-studio' ),
					'reset_all_error'              => __( 'Error resetting adjustments.', 'contentosapp-studio' ),
					'version_restored'             => __( 'Version restored.', 'contentosapp-studio' ),
					'version_restore_error'        => __( 'Error restoring version.', 'contentosapp-studio' ),
					'telemetry_save_error'       => __( 'Could not save your preference. Please try again.', 'contentosapp-studio' ),
					'diagnose_api_btn'           => __( 'Diagnose API connectivity', 'contentosapp-studio' ),
					'diagnose_api_loading'       => __( 'Running connectivity tests (PHP, DNS, TCP, HTTPS, REST API)… may take up to 60s.', 'contentosapp-studio' ),
					'diagnose_api_title'         => __( 'Connectivity report', 'contentosapp-studio' ),
					'diagnose_api_ok'            => __( 'All checks passed', 'contentosapp-studio' ),
					'diagnose_api_warn'          => __( 'Some checks need attention', 'contentosapp-studio' ),
					'diagnose_api_unexpected'    => __( 'Unexpected response from the server.', 'contentosapp-studio' ),
					'network_error'              => __( 'Network error', 'contentosapp-studio' ),
					'hide_report'                => __( 'Hide', 'contentosapp-studio' ),
					'show_report'                => __( 'Show report', 'contentosapp-studio' ),
					'loading'                    => __( 'Loading…', 'contentosapp-studio' ),
					'loading_ellipsis'           => __( '…loading…', 'contentosapp-studio' ),
					'close'                      => __( 'Close', 'contentosapp-studio' ),
					'remove'                     => __( 'Remove', 'contentosapp-studio' ),
					'edit'                       => __( 'Edit', 'contentosapp-studio' ),
					'models_loaded'              => __( 'models available. Click 🔄 to refresh.', 'contentosapp-studio' ),
					'click_to_load'              => __( '— Click 🔄 to load —', 'contentosapp-studio' ),
					'models_hint'                => __( 'Click 🔄 to load available models from API.', 'contentosapp-studio' ),
					'api_key_saved'              => __( 'API key saved', 'contentosapp-studio' ),
					'api_key_pending'            => __( 'API key pending', 'contentosapp-studio' ),
					'api_key_missing'            => __( 'API key missing', 'contentosapp-studio' ),
					'using_plan_quota'           => __( 'Using ContentOS Auto quota', 'contentosapp-studio' ),
					'contentos_auto_pro_studio'  => __( 'Unavailable on this plan', 'contentosapp-studio' ),
					'no_images_mode'             => __( 'No images', 'contentosapp-studio' ),
					'placeholder_mode'           => __( 'Suggesting placements', 'contentosapp-studio' ),
					'select_provider_status'     => __( 'Provider not selected', 'contentosapp-studio' ),
					'not_configured'             => __( 'Not configured', 'contentosapp-studio' ),
					'request_failed'             => __( 'Request failed.', 'contentosapp-studio' ),
					'request_failed_connection'  => __( 'Request failed. Check your connection.', 'contentosapp-studio' ),
					'models_fetch_error'         => __( 'Error fetching models.', 'contentosapp-studio' ),
					'models_fetch_failed'        => __( 'Failed to fetch models.', 'contentosapp-studio' ),
					'select_provider_first'      => __( 'Select a provider first.', 'contentosapp-studio' ),
					'select_provider_first_option' => __( '— Select a provider first —', 'contentosapp-studio' ),
					'grounding_active'           => __( 'Grounding active', 'contentosapp-studio' ),
					'search_disabled'            => __( 'Search disabled', 'contentosapp-studio' ),
					'fields_required'            => __( 'Please fill all fields.', 'contentosapp-studio' ),
					'tip_select_provider'        => __( 'Select a provider to see details and usage recommendations.', 'contentosapp-studio' ),
					'tip_gemini'                 => __( 'Google Gemini offers a free tier for initial testing. Create your key at aistudio.google.com.', 'contentosapp-studio' ),
					'tip_openai'                 => __( 'Pay as you go. GPT-4o has strong performance for structured writing and English content.', 'contentosapp-studio' ),
					'tip_claude'                 => __( 'Pay as you go. Claude is excellent for maintaining tone consistency in long-form articles.', 'contentosapp-studio' ),
					'provider_unavailable'       => __( 'Provider unavailable.', 'contentosapp-studio' ),
					'upgrade_now'                => __( 'Manage service plan', 'contentosapp-studio' ),

					'add_site'                   => __( 'Add New Site', 'contentosapp-studio' ),
					'edit_site'                  => __( 'Edit Site', 'contentosapp-studio' ),
					'load_from_site'             => __( 'Load from site', 'contentosapp-studio' ),
					'site_password_keep_current' => __( '(leave blank to keep current)', 'contentosapp-studio' ),
					'site_url_required'          => __( 'Please enter the site URL first.', 'contentosapp-studio' ),
					'categories_prompt'          => __( 'Click "Load from site" to fetch available categories.', 'contentosapp-studio' ),
					'categories_empty'           => __( 'No categories found.', 'contentosapp-studio' ),
					'categories_loading'         => __( 'Loading categories…', 'contentosapp-studio' ),
					'categories_fetch_error'     => __( 'Could not load categories.', 'contentosapp-studio' ),
					'no_sites_configured'        => __( 'No sites configured.', 'contentosapp-studio' ),
					'connection_success'         => __( 'Connection successful!', 'contentosapp-studio' ),
					'connection_error'           => __( 'Connection error', 'contentosapp-studio' ),

					'select_category'            => __( 'Select category', 'contentosapp-studio' ),
					'select_site_first'          => __( 'Select a site first.', 'contentosapp-studio' ),
					'field_suggest_ai_short'     => __( 'AI', 'contentosapp-studio' ),
					'field_suggest_ai'           => __( 'Suggest with AI', 'contentosapp-studio' ),
					'field_suggest_angle'        => __( 'Suggest angle', 'contentosapp-studio' ),
					'field_suggest_reader_profile' => __( 'Suggest profile', 'contentosapp-studio' ),
					'field_generating_ai'        => __( 'Generating...', 'contentosapp-studio' ),
					'field_ai_failed_soft'       => __( 'Could not generate a suggestion right now.', 'contentosapp-studio' ),
					'enter_keywords'             => __( 'Enter keywords to search.', 'contentosapp-studio' ),
					'searching'                  => __( 'Searching…', 'contentosapp-studio' ),
					'no_links_found'             => __( 'No links found.', 'contentosapp-studio' ),
					'starting'                   => __( 'Starting…', 'contentosapp-studio' ),
					'error_starting_production'  => __( 'Error starting production.', 'contentosapp-studio' ),
					'agents_completed'           => __( 'agents completed', 'contentosapp-studio' ),
					'all_agents_complete'        => __( 'All agents complete!', 'contentosapp-studio' ),
					'producing_article'          => __( 'Producing article…', 'contentosapp-studio' ),
					'unexpected_error'           => __( 'An unexpected error occurred.', 'contentosapp-studio' ),
					'error_retrying'             => __( 'Error retrying.', 'contentosapp-studio' ),
					'save_failed'                => __( 'Save failed.', 'contentosapp-studio' ),
					'image_placeholder'          => __( 'Image placeholder', 'contentosapp-studio' ),
					'pipeline_waiting'           => __( 'Waiting for server…', 'contentosapp-studio' ),
					'resuming_pipeline'          => __( 'Scheduling…', 'contentosapp-studio' ),
					'select_type_first'          => __( 'Select at least one content type.', 'contentosapp-studio' ),
					'url_required'               => __( 'Enter the URL before adding.', 'contentosapp-studio' ),
					'url_invalid'                => __( 'Invalid URL. Use format https://example.com/article', 'contentosapp-studio' ),
					'no_results_found'           => __( 'No results found.', 'contentosapp-studio' ),
					'error_searching_post'       => __( 'Error searching post.', 'contentosapp-studio' ),
					'extracting_content'         => __( 'Extracting content...', 'contentosapp-studio' ),
					'published_on'               => __( 'Published on', 'contentosapp-studio' ),
					'edited_months'              => __( 'edited', 'contentosapp-studio' ),
					'edited_recently'            => __( 'edited recently', 'contentosapp-studio' ),
					'error_extracting_post_content' => __( 'Error extracting post content.', 'contentosapp-studio' ),
					'error_connection_extracting_post_content' => __( 'Connection error while extracting post content.', 'contentosapp-studio' ),
					'error_comparative_min_items' => __( 'Comparative type requires at least 2 items.', 'contentosapp-studio' ),
					'error_news_min_sources'     => __( 'News type requires at least 1 source URL.', 'contentosapp-studio' ),
					'error_update_requires_existing' => __( 'Update type requires selecting an existing article.', 'contentosapp-studio' ),
					'error_update_requires_instructions' => __( 'Update type requires instructions describing what to change.', 'contentosapp-studio' ),
					'error_invalid_schedule_date' => __( 'Please choose a valid future date for scheduling.', 'contentosapp-studio' ),
					'publish_hint_scheduled'     => __( 'Scheduled article - set publication date and time below.', 'contentosapp-studio' ),
					'publish_hint_draft'         => __( 'Article saved as draft - review and publish manually.', 'contentosapp-studio' ),
					'publish_hint_published'     => __( 'Article published immediately after the pipeline finishes.', 'contentosapp-studio' ),
					'publish_hint_scheduled_req' => __( 'Invalid date - fill in the scheduling field.', 'contentosapp-studio' ),
					'publish_hint_scheduled_past' => __( 'Past date - choose a future date.', 'contentosapp-studio' ),
					'publish_hint_scheduled_in'  => __( 'Will be published in', 'contentosapp-studio' ),
					'exec_manual_warning'        => __( 'In manual mode, the pipeline pauses after each agent and waits for your approval to continue.', 'contentosapp-studio' ),
					'exec_hint_auto'             => __( 'Pipeline runs straight from Agent 1 to 7.', 'contentosapp-studio' ),
					'start_review_mode'          => __( 'Start with review', 'contentosapp-studio' ),
					'start_production'           => __( 'Start production', 'contentosapp-studio' ),
					'waiting_approval'           => __( 'Waiting for your review...', 'contentosapp-studio' ),
					'approve_and_continue'       => __( 'Approve and continue', 'contentosapp-studio' ),
					'approving'                  => __( 'Approving…', 'contentosapp-studio' ),
					'error_approving'            => __( 'Error approving step.', 'contentosapp-studio' ),
					'day'                        => __( 'day', 'contentosapp-studio' ),
					'days'                       => __( 'days', 'contentosapp-studio' ),
					'months'                     => __( 'months', 'contentosapp-studio' ),
					'of'                         => __( 'of', 'contentosapp-studio' ),
					'links_selected'             => __( 'selected links', 'contentosapp-studio' ),
					'deselect_all'               => __( 'Deselect all', 'contentosapp-studio' ),
					'page_label'                 => __( 'Page', 'contentosapp-studio' ),
					'post_label'                 => __( 'Post', 'contentosapp-studio' ),
					'placeholder_comp'           => __( 'Product name - https://url (optional)', 'contentosapp-studio' ),

					'edit_plan'                  => __( 'Edit Idea', 'contentosapp-studio' ),
					'add_plan'                   => __( 'New Idea', 'contentosapp-studio' ),
					'title_ai_suggestions_label' => __( 'AI suggestions', 'contentosapp-studio' ),
					'title_suggest_with_ai'      => __( 'Suggest with AI', 'contentosapp-studio' ),
					'title_generating_ai'        => __( 'Generating...', 'contentosapp-studio' ),
					'title_ai_failed_soft'       => __( 'Could not generate AI suggestions right now.', 'contentosapp-studio' ),
					'any_category'               => __( 'Any Category', 'contentosapp-studio' ),
					'syncing'                    => __( 'Syncing…', 'contentosapp-studio' ),
					'sync_imported'              => __( 'Imported:', 'contentosapp-studio' ),
					'sync_errors'                => __( 'Errors:', 'contentosapp-studio' ),
					'sync_failed'                => __( 'Sync failed.', 'contentosapp-studio' ),
					'adding'                     => __( 'Adding…', 'contentosapp-studio' ),
					'add_idea_arrow'             => __( 'Add idea →', 'contentosapp-studio' ),
					'dash_live_label'            => __( 'LIVE - PRODUCTION RUNNING', 'contentosapp-studio' ),
					'dash_produce_now'           => __( 'Produce now', 'contentosapp-studio' ),
					'dash_vs_last_month'         => __( 'vs last month', 'contentosapp-studio' ),
					'dash_articles'              => __( 'articles', 'contentosapp-studio' ),
					'dash_unlimited'             => __( 'Unlimited', 'contentosapp-studio' ),
					'dash_pro_plan'              => __( 'PRO service plan', 'contentosapp-studio' ),
					'dash_free_plan'             => __( 'Free service plan', 'contentosapp-studio' ),
					'dash_auto_quota'            => __( 'Auto (Plan)', 'contentosapp-studio' ),
					'dash_byok_quota'            => __( 'BYOK (Own Key)', 'contentosapp-studio' ),
					// Sprint B.2 v2 — short labels used in the headline+breakdown layout.
					// Semantic: each value is "available right now" (not "used").
					'dash_auto_short'            => __( 'plan', 'contentosapp-studio' ),
					'dash_extras_short'          => __( 'extras', 'contentosapp-studio' ),
					'dash_byok_short'            => __( 'BYOK', 'contentosapp-studio' ),
					'dash_addon_buy'             => __( 'Buy', 'contentosapp-studio' ),
					'dash_addon_buy_title'       => __( 'Buy more credits', 'contentosapp-studio' ),

					// Sprint B.3 — Buy Extra Quotas modal (costudio-addon-checkout.js).
					// Card labels.
					'addon_buy_now'              => __( 'Buy Now', 'contentosapp-studio' ),
					'addon_qty_label'            => __( 'extra credits', 'contentosapp-studio' ),
					'addon_badge_popular'        => __( 'Popular', 'contentosapp-studio' ),
					'addon_badge_best_value'     => __( 'Best value', 'contentosapp-studio' ),
					// State controls + status copy.
					'addon_retry'                => __( 'Try again', 'contentosapp-studio' ),
					'addon_redirecting'          => __( 'Redirecting to secure checkout…', 'contentosapp-studio' ),
					'addon_buy_coming_soon'      => __( 'The purchase modal is not available on this page.', 'contentosapp-studio' ),
					'addon_toast_dismiss'        => __( 'Dismiss this notice', 'contentosapp-studio' ),
					// Return-from-Stripe toast copy.
					'addon_purchase_success'     => __( '✨ Credits added! Refreshing in a moment…', 'contentosapp-studio' ),
					'addon_purchase_cancelled'   => __( 'Purchase cancelled. No charge was made.', 'contentosapp-studio' ),
					// Error code → user-facing message map. Keys mirror the
					// server's WP_Error codes so the JS can pick the right
					// copy without a separate translation step.
					'addon_err_disabled'         => __( 'Extra credits are not available right now.', 'contentosapp-studio' ),
					'addon_err_unconfigured'     => __( 'There is a server configuration issue. Please contact support.', 'contentosapp-studio' ),
					'addon_err_plan'             => __( 'Your current managed-service plan does not support extra credits.', 'contentosapp-studio' ),
					'addon_err_ratelimit'        => __( 'Too many attempts. Please wait a few minutes and try again.', 'contentosapp-studio' ),
					'addon_err_invalid_pkg'      => __( 'Selected package is not available. Please refresh and try again.', 'contentosapp-studio' ),
					'addon_err_url'              => __( 'Invalid return URL. Please refresh the page and try again.', 'contentosapp-studio' ),
					'addon_err_no_license'       => __( 'No active ContentOS Auto service license. Activate a service license before purchasing extra credits.', 'contentosapp-studio' ),
					'addon_err_network'          => __( 'Could not reach the server. Check your connection and try again.', 'contentosapp-studio' ),
					'addon_err_empty'            => __( 'No packages are available right now.', 'contentosapp-studio' ),
					'addon_err_generic'          => __( 'Something went wrong. Please try again.', 'contentosapp-studio' ),

					// Sprint B.3.6.1 — polish: per-card savings + modal context line.
					/* translators: shown on each pack card as a savings indicator vs the cheapest pack. {percent} is replaced with an integer like "20". */
					'addon_savings'              => __( 'Save {percent}%', 'contentosapp-studio' ),
					/* translators: context line above the package grid. {extras_count} and {plan_count} are integers replaced client-side. */
					'addon_context_dual'         => __( 'You have {extras_count} extras + {plan_count} service quota credits left this month.', 'contentosapp-studio' ),
					/* translators: context line shown when both extras balance AND remaining service quota credits are zero. */
					'addon_context_exhausted'    => __( 'Your ContentOS Auto service credits are exhausted. Choose a pack below to continue with the managed service.', 'contentosapp-studio' ),

					// Sprint B.4 — Quota-blocked production flow (Caso A confirm + Caso B buy + auto-retry).
					/* translators: shown in the confirm-extra modal body. {count} is replaced client-side with the post-deduction extras count. */
					'confirm_extra_remaining'    => __( 'You\'ll have {count} extras remaining after this.', 'contentosapp-studio' ),
					/* translators: appended after the server's quota-exhausted message when opening the buy modal from a blocked production. */
					'addon_buy_to_continue'      => __( 'Choose a pack below to continue with the managed service.', 'contentosapp-studio' ),
					/* translators: contextual headline shown above the package grid when the buy modal opens in production_blocked context. */
					'addon_context_blocked'      => __( 'Your ContentOS Auto monthly quota is full. Choose a pack below to keep producing with the managed service.', 'contentosapp-studio' ),
					/* translators: banner shown briefly while the production form is being restored and re-submitted after a Stripe purchase. */
					'production_retry_banner'    => __( 'Continuing your production…', 'contentosapp-studio' ),
					'dash_configure_api'         => __( 'Configure API', 'contentosapp-studio' ),
					'dash_site_active'           => __( 'site active', 'contentosapp-studio' ),
					'dash_sites_active'          => __( 'sites active', 'contentosapp-studio' ),
					'dash_connect_site'          => __( 'Connect a site', 'contentosapp-studio' ),
					'dash_pro_active'            => __( 'Service plan active', 'contentosapp-studio' ),
					'dash_free_basic'            => __( 'Free plan', 'contentosapp-studio' ),
					'dash_unlimited_access'      => __( 'BYOK remains unlimited', 'contentosapp-studio' ),
					'dash_upgrade_pro'           => __( 'Manage service plan', 'contentosapp-studio' ),
					'dash_no_ideas_yet'          => __( 'No ideas in the queue yet.', 'contentosapp-studio' ),
					'dash_no_articles_yet'       => __( 'No articles generated yet.', 'contentosapp-studio' ),
					'dash_free_upgrade'          => __( 'Choose a service plan', 'contentosapp-studio' ),
					'dash_load_failed'           => __( 'Could not load dashboard data right now. Please refresh and check the logs if it persists.', 'contentosapp-studio' ),
					'dash_try_refresh'           => __( 'Refresh the page or try again shortly.', 'contentosapp-studio' ),
					'dash_production_queue'      => __( 'Production queue', 'contentosapp-studio' ),
					'dash_queue_waiting'         => __( 'waiting', 'contentosapp-studio' ),
					'dash_queue_slot_busy'       => __( 'Slot busy', 'contentosapp-studio' ),
					'dash_queue_slot_free'       => __( 'Slot free', 'contentosapp-studio' ),
					'dash_queue_none_waiting_busy' => __( 'No productions waiting. The local slot is currently busy.', 'contentosapp-studio' ),
					'dash_queue_none_waiting_free' => __( 'No productions waiting. The local slot is free.', 'contentosapp-studio' ),
					'queue_position_sentence'    => __( 'Waiting for the local slot. Position {position} of {total} in the queue.', 'contentosapp-studio' ),
					'queue_label'                => __( 'Queue', 'contentosapp-studio' ),

					'agent_label'                => __( 'Agent', 'contentosapp-studio' ),
					'is_running'                 => __( 'is running', 'contentosapp-studio' ),
					'minutes_short'              => __( 'min', 'contentosapp-studio' ),
					'finishing'                  => __( 'finishing…', 'contentosapp-studio' ),
					'done'                       => __( 'Done', 'contentosapp-studio' ),
					'running'                    => __( 'Running', 'contentosapp-studio' ),
					'paused'                     => __( 'Paused', 'contentosapp-studio' ),
					'completed'                  => __( 'Completed', 'contentosapp-studio' ),
					'queued'                     => __( 'Queued', 'contentosapp-studio' ),
					'awaiting_approval'          => __( 'Awaiting Approval', 'contentosapp-studio' ),
					'failed'                     => __( 'Failed', 'contentosapp-studio' ),
					'waiting'                    => __( 'Waiting', 'contentosapp-studio' ),
					'words'                      => __( 'words', 'contentosapp-studio' ),
					'view'                       => __( 'View', 'contentosapp-studio' ),
					'edit'                       => __( 'Edit', 'contentosapp-studio' ),
					'view_full_output'           => __( 'View full output', 'contentosapp-studio' ),
					'output_preview'             => __( 'Output preview', 'contentosapp-studio' ),
					'preview_html'               => __( 'Preview HTML', 'contentosapp-studio' ),
					'raw_markdown'               => __( 'Raw Markdown', 'contentosapp-studio' ),
					'copy'                       => __( 'Copy', 'contentosapp-studio' ),
					'copied'                     => __( '✓ Copied!', 'contentosapp-studio' ),
					'save_changes'               => __( 'Save Changes', 'contentosapp-studio' ),
					'saving'                     => __( 'Saving…', 'contentosapp-studio' ),
					'empty'                      => __( '(empty)', 'contentosapp-studio' ),
					'error_loading_output'       => __( 'Error loading output.', 'contentosapp-studio' ),
					'network_error'              => __( 'Network error.', 'contentosapp-studio' ),
					'yes'                        => __( 'Yes', 'contentosapp-studio' ),
					'no'                         => __( 'No', 'contentosapp-studio' ),
					'waiting_for_runtime_events' => __( 'Waiting for runtime events…', 'contentosapp-studio' ),
					'pending_background_token'   => __( 'pending background token', 'contentosapp-studio' ),
					'heartbeat_stale'            => __( 'stale heartbeat', 'contentosapp-studio' ),
					'pipeline_stall_warning'     => __( 'The pipeline looks stalled before Agent 01 could save output:', 'contentosapp-studio' ),
					'pipeline_running_warning'   => __( 'A background runner is still processing Agent 01:', 'contentosapp-studio' ),
					'live_heartbeat'             => __( 'live heartbeat', 'contentosapp-studio' ),
					'session_duration'           => __( 'session duration', 'contentosapp-studio' ),
					'confirm_reprocess_from'     => __( 'Confirm — reprocess from Agent', 'contentosapp-studio' ),
					'reprocess_from_here'        => __( 'Reprocess from here', 'contentosapp-studio' ),
					'starting_reprocess'         => __( 'Starting reprocess…', 'contentosapp-studio' ),
					'error_starting_reprocess'   => __( 'Error starting reprocess.', 'contentosapp-studio' ),
					'confirm_click_again_cancel' => __( 'Sure? Click again to confirm', 'contentosapp-studio' ),
					'confirm_cancel_action'      => __( 'Confirm cancel?', 'contentosapp-studio' ),
					'confirm_reprocess'          => __( 'Confirm reprocess?', 'contentosapp-studio' ),
					'cancel'                     => __( 'Cancel', 'contentosapp-studio' ),
					'cancel_production'          => __( 'Cancel production', 'contentosapp-studio' ),
					'finalizing'                 => __( 'Finalizando…', 'contentosapp-studio' ),
					'finalizing_publication'     => __( 'Finalizando publicação', 'contentosapp-studio' ),
					'finalizing_notice_title'    => __( 'Todos os agentes terminaram. Publicação em andamento.', 'contentosapp-studio' ),
					'finalizing_notice_text'     => __( 'O Contentosapp Studio está preparando referências, imagens, schema, metadados e o rascunho final no WordPress.', 'contentosapp-studio' ),
					'current_stage'              => __( 'Etapa Atual', 'contentosapp-studio' ),
					'current_agent'              => __( 'Agente Atual', 'contentosapp-studio' ),
					'next_agent'                 => __( 'Próximo Agente', 'contentosapp-studio' ),
					'creating_wp_draft'          => __( 'criando o rascunho no WordPress…', 'contentosapp-studio' ),
					'processing_stage'           => __( 'processando etapa…', 'contentosapp-studio' ),
					'publishing'                 => __( 'Publishing…', 'contentosapp-studio' ),
					'publish_to_wp'              => __( 'Publish to WordPress', 'contentosapp-studio' ),
					'published_check'            => __( '✓ Published', 'contentosapp-studio' ),
					'error_publishing_article'   => __( 'Error publishing article.', 'contentosapp-studio' ),
					'network_error_publishing'   => __( 'Network error while publishing.', 'contentosapp-studio' ),
					'this_site'                  => __( 'This site', 'contentosapp-studio' ),
					'auto_connected'             => __( 'Auto-connected · no credentials needed', 'contentosapp-studio' ),
					'plug_and_play'              => __( 'Plug & Play', 'contentosapp-studio' ),
					'no_credentials'             => __( 'No credentials needed — publishes directly to this WordPress installation.', 'contentosapp-studio' ),
					'connect_this_site'          => __( 'Connect this site', 'contentosapp-studio' ),
					'auto_connect_arrow'         => __( 'Auto-connect →', 'contentosapp-studio' ),

					// Dashboard / studio tables
					'col_article'                => __( 'Article', 'contentosapp-studio' ),
					'col_date'                   => __( 'Date', 'contentosapp-studio' ),
					'col_priority'               => __( 'Priority', 'contentosapp-studio' ),
					'col_site'                   => __( 'Site', 'contentosapp-studio' ),
					'col_status'                 => __( 'Status', 'contentosapp-studio' ),
					'filter_all'                 => __( 'All', 'contentosapp-studio' ),
					'status_completed_short'     => __( 'Done', 'contentosapp-studio' ),
					'status_running'             => __( 'Running', 'contentosapp-studio' ),
					'status_pending'             => __( 'Pending', 'contentosapp-studio' ),
					'status_paused'              => __( 'Paused', 'contentosapp-studio' ),
					'status_error'               => __( 'Error', 'contentosapp-studio' ),
					'status_upgrade_required'    => __( 'Managed service quota needs attention', 'contentosapp-studio' ),
					'status_planned'             => __( 'Planned', 'contentosapp-studio' ),
					'dash_all_time'              => __( 'All time', 'contentosapp-studio' ),
					'priority_high'              => __( 'High', 'contentosapp-studio' ),
					'priority_medium'            => __( 'Medium', 'contentosapp-studio' ),
					'priority_low'               => __( 'Low', 'contentosapp-studio' ),
					'status_draft'               => __( 'Draft', 'contentosapp-studio' ),
					'status_published'           => __( 'Published', 'contentosapp-studio' ),
					'select_all'                 => __( 'Select all', 'contentosapp-studio' ),

					// Nova Produção — form hints & placeholders
					'complete_required'          => __( 'Complete the required fields to continue', 'contentosapp-studio' ),
					'ready_to_produce'           => __( 'Ready to start production', 'contentosapp-studio' ),
					'summary_angle_placeholder'  => __( 'Your editorial angle appears here...', 'contentosapp-studio' ),
					'summary_ai_optimized'       => __( '✨ Optimized by AI', 'contentosapp-studio' ),
					'summary_ai_optimized_short' => __( 'Auto', 'contentosapp-studio' ),
					'placeholder_comp_label'     => __( 'Product or service name', 'contentosapp-studio' ),
					'placeholder_comp_url'       => __( 'https://... (optional)', 'contentosapp-studio' ),
					'hint_draft'                 => __( 'Article saved as draft — review and publish manually.', 'contentosapp-studio' ),
					'hint_scheduled'             => __( 'Article scheduled for a future date.', 'contentosapp-studio' ),
					'hint_published'             => __( 'Auto-publishes to the site immediately.', 'contentosapp-studio' ),
					'hint_exec_manual'           => __( 'Pipeline pauses after each agent so you can review and approve.', 'contentosapp-studio' ),
					'hint_exec_auto'             => __( 'The pipeline runs directly from Agent 1 to 7.', 'contentosapp-studio' ),
					'as_draft'                   => __( 'As Draft', 'contentosapp-studio' ),
					'auto_publish'               => __( 'Auto-publish', 'contentosapp-studio' ),
					'auto_detected'              => __( 'Auto-detected', 'contentosapp-studio' ),
					'scheduled'                  => __( 'Scheduled', 'contentosapp-studio' ),
					'skipped'                    => __( 'Skipped', 'contentosapp-studio' ),
					'step_n'                     => __( 'Step', 'contentosapp-studio' ),

					// Detail / preview
					'article_preview'            => __( 'Article Preview', 'contentosapp-studio' ),
					'preview_article'            => __( 'Preview Article', 'contentosapp-studio' ),
					'preview_error'              => __( 'Could not load preview.', 'contentosapp-studio' ),

					// Article types
					'type_pilar'                 => __( 'Pillar', 'contentosapp-studio' ),
					'type_satellite'             => __( 'Satellite', 'contentosapp-studio' ),
					'type_comparative'           => __( 'Comparison', 'contentosapp-studio' ),
					'type_news'                  => __( 'News', 'contentosapp-studio' ),
					'type_update'                => __( 'Update', 'contentosapp-studio' ),

					// Brand Voice
					'generating'                 => __( 'Generating...', 'contentosapp-studio' ),
					'generate_preview'           => __( 'Generate Preview', 'contentosapp-studio' ),
					'brand_voice_preview_loading'=> __( 'AI is crafting your preview...', 'contentosapp-studio' ),
					'brand_voice_preview_empty'  => __( 'Adjust your settings and click the button below to test your brand voice.', 'contentosapp-studio' ),
					'brand_voice_name_required'  => __( 'Voice name is required.', 'contentosapp-studio' ),
					'brand_voice_continue'       => __( 'Continue', 'contentosapp-studio' ),
					'brand_voice_continue_tone'  => __( 'Continue to Tone', 'contentosapp-studio' ),
					'brand_voice_continue_vocab' => __( 'Continue to Vocabulary', 'contentosapp-studio' ),
					'brand_voice_continue_review'=> __( 'Continue to Review', 'contentosapp-studio' ),
					'brand_voice_resolve_vocab_conflicts' => __( 'Resolve vocabulary conflicts before continuing: {terms}.', 'contentosapp-studio' ),
					'brand_voice_preview_optional' => __( 'The preview is optional. Generate a sample to validate the tone before saving.', 'contentosapp-studio' ),
					'brand_voice_no_replacements' => __( 'No substitutions configured.', 'contentosapp-studio' ),
					'brand_voice_remove_replacement' => __( 'Remove substitution', 'contentosapp-studio' ),
					'brand_voice_remove_item'    => __( 'Remove {item}', 'contentosapp-studio' ),
					'brand_voice_term_singular'  => __( 'term', 'contentosapp-studio' ),
					'brand_voice_term_plural'    => __( 'terms', 'contentosapp-studio' ),
					'brand_voice_example_singular' => __( 'example', 'contentosapp-studio' ),
					'brand_voice_example_plural' => __( 'examples', 'contentosapp-studio' ),
					'brand_voice_prefer_short'   => __( 'prefer', 'contentosapp-studio' ),
					'brand_voice_avoid_short'    => __( 'avoid', 'contentosapp-studio' ),
					'brand_voice_subst_short'    => __( 'subst.', 'contentosapp-studio' ),
					'brand_voice_signature_singular' => __( 'signature', 'contentosapp-studio' ),
					'brand_voice_signature_plural' => __( 'signatures', 'contentosapp-studio' ),
					'brand_voice_prompt_vocabulary' => __( 'VOCABULARY', 'contentosapp-studio' ),
					'brand_voice_prompt_prioritize' => __( 'prioritize', 'contentosapp-studio' ),
					'brand_voice_prompt_prohibit' => __( 'prohibit', 'contentosapp-studio' ),
					'brand_voice_prompt_replace' => __( 'replace', 'contentosapp-studio' ),
					'brand_voice_prompt_signature' => __( 'signature', 'contentosapp-studio' ),
					'brand_voice_conflict'       => __( 'Conflict: {terms}.', 'contentosapp-studio' ),
					'brand_voice_no_conflicts'   => __( 'No conflicts detected.', 'contentosapp-studio' ),
					'brand_voice_radar_label'    => __( 'Voice DNA', 'contentosapp-studio' ),
					'brand_voice_radar_formality'=> __( 'Formality', 'contentosapp-studio' ),
					'brand_voice_radar_technical'=> __( 'Technical', 'contentosapp-studio' ),
					'brand_voice_radar_authority'=> __( 'Authority', 'contentosapp-studio' ),
					'brand_voice_radar_opinion'  => __( 'Opinion', 'contentosapp-studio' ),
					'brand_voice_radar_warmth'   => __( 'Warmth', 'contentosapp-studio' ),
					'brand_voice_tone_formality_1' => __( 'Very casual', 'contentosapp-studio' ),
					'brand_voice_tone_formality_2' => __( 'Friendly chat', 'contentosapp-studio' ),
					'brand_voice_tone_formality_3' => __( 'Neutral', 'contentosapp-studio' ),
					'brand_voice_tone_formality_4' => __( 'Professional', 'contentosapp-studio' ),
					'brand_voice_tone_formality_5' => __( 'Formal', 'contentosapp-studio' ),
					'brand_voice_tone_technicality_1' => __( 'For beginners', 'contentosapp-studio' ),
					'brand_voice_tone_technicality_2' => __( 'Accessible', 'contentosapp-studio' ),
					'brand_voice_tone_technicality_3' => __( 'Balanced', 'contentosapp-studio' ),
					'brand_voice_tone_technicality_4' => __( 'Technical', 'contentosapp-studio' ),
					'brand_voice_tone_technicality_5' => __( 'Expert', 'contentosapp-studio' ),
					'brand_voice_tone_authority_1' => __( 'Careful', 'contentosapp-studio' ),
					'brand_voice_tone_authority_2' => __( 'Guiding', 'contentosapp-studio' ),
					'brand_voice_tone_authority_3' => __( 'Confident', 'contentosapp-studio' ),
					'brand_voice_tone_authority_4' => __( 'Assertive', 'contentosapp-studio' ),
					'brand_voice_tone_authority_5' => __( 'Categorical', 'contentosapp-studio' ),
					'brand_voice_tone_opinion_1' => __( 'Factual', 'contentosapp-studio' ),
					'brand_voice_tone_opinion_2' => __( 'Analytical', 'contentosapp-studio' ),
					'brand_voice_tone_opinion_3' => __( 'Balanced', 'contentosapp-studio' ),
					'brand_voice_tone_opinion_4' => __( 'Critical', 'contentosapp-studio' ),
					'brand_voice_tone_opinion_5' => __( 'Opinionated', 'contentosapp-studio' ),
					'brand_voice_tone_warmth_1'  => __( 'Distant', 'contentosapp-studio' ),
					'brand_voice_tone_warmth_2'  => __( 'Reserved', 'contentosapp-studio' ),
					'brand_voice_tone_warmth_3'  => __( 'Natural', 'contentosapp-studio' ),
					'brand_voice_tone_warmth_4'  => __( 'Close', 'contentosapp-studio' ),
					'brand_voice_tone_warmth_5'  => __( 'Welcoming', 'contentosapp-studio' ),
					'brand_voice_signature_academic' => __( 'Academic', 'contentosapp-studio' ),
					'brand_voice_signature_professional' => __( 'Professional', 'contentosapp-studio' ),
					'brand_voice_signature_conversational' => __( 'Conversational+', 'contentosapp-studio' ),
					'brand_voice_signature_critical' => __( 'Critical', 'contentosapp-studio' ),
					'brand_voice_signature_balanced' => __( 'Balanced', 'contentosapp-studio' ),
					'brand_voice_quote_academic' => __( '“The analysis shows a consistent pattern: clear processes reduce rework and increase operational predictability.”', 'contentosapp-studio' ),
					'brand_voice_quote_professional' => __( '“The company can scale production with a clear process, the right metrics, and consistent review.”', 'contentosapp-studio' ),
					'brand_voice_quote_conversational' => __( '“You can simplify it: choose the next step, measure what matters, and adjust without complicating the process.”', 'contentosapp-studio' ),
					'brand_voice_quote_critical' => __( '“The problem is not producing more. It is producing without method and calling volume strategy.”', 'contentosapp-studio' ),
					'brand_voice_quote_balanced' => __( '“The path becomes clearer when strategy, process, and measurement move together.”', 'contentosapp-studio' ),
					'brand_voice_pov_first_plural' => __( '1st person plural (We)', 'contentosapp-studio' ),
					'brand_voice_pov_second'     => __( '2nd person (You)', 'contentosapp-studio' ),
					'brand_voice_pov_third'      => __( '3rd person (Impersonal)', 'contentosapp-studio' ),
					'brand_voice_para_short'     => __( 'Short · 2-3 sentences', 'contentosapp-studio' ),
					'brand_voice_para_medium'    => __( 'Medium · 4-5 sentences', 'contentosapp-studio' ),
					'brand_voice_para_long'      => __( 'Long · 6+ sentences', 'contentosapp-studio' ),
					'brand_voice_pack_marketing_preferred_1' => __( 'funnel conversion', 'contentosapp-studio' ),
					'brand_voice_pack_marketing_preferred_2' => __( 'marketing team', 'contentosapp-studio' ),
					'brand_voice_pack_marketing_preferred_3' => __( 'scale production', 'contentosapp-studio' ),
					'brand_voice_pack_marketing_preferred_4' => __( 'playbook', 'contentosapp-studio' ),
					'brand_voice_pack_marketing_preferred_5' => __( 'consistency', 'contentosapp-studio' ),
					'brand_voice_pack_marketing_avoid_1' => __( 'revolutionary', 'contentosapp-studio' ),
					'brand_voice_pack_marketing_avoid_2' => __( 'transform', 'contentosapp-studio' ),
					'brand_voice_pack_marketing_avoid_3' => __( 'game changer', 'contentosapp-studio' ),
					'brand_voice_pack_marketing_signature' => __( 'Marketing that measures what matters.', 'contentosapp-studio' ),
					'brand_voice_pack_marketing_from' => __( 'user', 'contentosapp-studio' ),
					'brand_voice_pack_marketing_to' => __( 'customer', 'contentosapp-studio' ),
					'brand_voice_pack_marketing_do' => __( 'use business metrics', 'contentosapp-studio' ),
					'brand_voice_pack_marketing_dont' => __( 'promise guaranteed results', 'contentosapp-studio' ),
					'brand_voice_pack_editorial_preferred_1' => __( 'context', 'contentosapp-studio' ),
					'brand_voice_pack_editorial_preferred_2' => __( 'evidence', 'contentosapp-studio' ),
					'brand_voice_pack_editorial_preferred_3' => __( 'clarity', 'contentosapp-studio' ),
					'brand_voice_pack_editorial_preferred_4' => __( 'analysis', 'contentosapp-studio' ),
					'brand_voice_pack_editorial_avoid_1' => __( 'shocking', 'contentosapp-studio' ),
					'brand_voice_pack_editorial_avoid_2' => __( 'must-see', 'contentosapp-studio' ),
					'brand_voice_pack_editorial_avoid_3' => __( 'revealed secret', 'contentosapp-studio' ),
					'brand_voice_pack_editorial_signature' => __( 'No exaggeration: only what holds up.', 'contentosapp-studio' ),
					'brand_voice_pack_editorial_from' => __( 'opinion', 'contentosapp-studio' ),
					'brand_voice_pack_editorial_to' => __( 'analysis', 'contentosapp-studio' ),
					'brand_voice_pack_editorial_do' => __( 'explain cause and consequence', 'contentosapp-studio' ),
					'brand_voice_pack_editorial_dont' => __( 'use sensationalist tone', 'contentosapp-studio' ),

					// License / add-on history
					'license_key_required'       => __( 'License key is required.', 'contentosapp-studio' ),
					'purchase_email_required'    => __( 'Enter the purchase email used for this license.', 'contentosapp-studio' ),
					'addon_history_empty'        => __( 'No purchases yet.', 'contentosapp-studio' ),
					'addon_status_refunded'      => __( 'Refunded', 'contentosapp-studio' ),
					'addon_status_manual'        => __( 'Manual', 'contentosapp-studio' ),
					'addon_status_completed'     => __( 'Paid', 'contentosapp-studio' ),
					'addon_credits_label'        => __( 'credits', 'contentosapp-studio' ),
					'addon_th_date'              => __( 'Date', 'contentosapp-studio' ),
					'addon_th_qty'               => __( 'Quantity', 'contentosapp-studio' ),
					'addon_th_amount'            => __( 'Amount', 'contentosapp-studio' ),
					'addon_th_status'            => __( 'Status', 'contentosapp-studio' ),
				),
				'home_url'           => home_url(),
			)
		);
	}

	/**
	 * Build the site → categories map consumed by admin JS.
	 */
	private function get_site_categories(): array {
		$sites_repo = costudio_sites();
		$sites      = $sites_repo ? $sites_repo->get_all() : array();
		$result     = array();
		foreach ( $sites as $key => $cfg ) {
			$result[ $key ] = $cfg['categories'] ?? array();
		}
		return $result;
	}
}
