<?php
/**
 * Manifest dinámico — detecta base URL automáticamente
 */
$scriptDir = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
$base = ($scriptDir !== '/' && $scriptDir !== '\\') ? rtrim($scriptDir, '/') : '';

header('Content-Type: application/manifest+json; charset=utf-8');
header('Cache-Control: public, max-age=86400');

echo json_encode([
    'name' => 'Plataforma Ganadera',
    'short_name' => 'Ganadera',
    'description' => 'Plataforma Ganadera — Administración integral de ranchos y criaderos',
    'id' => $base ?: '/',
    'start_url' => $base ?: '/',
    'scope' => ($base ?: '/') . '/',
    'display' => 'standalone',
    'orientation' => 'portrait-primary',
    'background_color' => '#F1F5F9',
    'theme_color' => '#047857',
    'lang' => 'es-MX',
    'categories' => ['business', 'productivity'],
    'icons' => [
        ['src' => "$base/assets/img/icons/icon-72x72.png", 'sizes' => '72x72', 'type' => 'image/png', 'purpose' => 'any'],
        ['src' => "$base/assets/img/icons/icon-96x96.png", 'sizes' => '96x96', 'type' => 'image/png', 'purpose' => 'any'],
        ['src' => "$base/assets/img/icons/icon-128x128.png", 'sizes' => '128x128', 'type' => 'image/png', 'purpose' => 'any'],
        ['src' => "$base/assets/img/icons/icon-144x144.png", 'sizes' => '144x144', 'type' => 'image/png', 'purpose' => 'any'],
        ['src' => "$base/assets/img/icons/icon-152x152.png", 'sizes' => '152x152', 'type' => 'image/png', 'purpose' => 'any'],
        ['src' => "$base/assets/img/icons/icon-192x192.png", 'sizes' => '192x192', 'type' => 'image/png', 'purpose' => 'any'],
        ['src' => "$base/assets/img/icons/icon-384x384.png", 'sizes' => '384x384', 'type' => 'image/png', 'purpose' => 'any'],
        ['src' => "$base/assets/img/icons/icon-512x512.png", 'sizes' => '512x512', 'type' => 'image/png', 'purpose' => 'any'],
        ['src' => "$base/assets/img/icons/icon-512x512.png", 'sizes' => '512x512', 'type' => 'image/png', 'purpose' => 'maskable'],
    ],
    'screenshots' => [],
    'shortcuts' => [
        ['name' => 'Dashboard', 'url' => "$base/", 'icons' => [['src' => "$base/assets/img/icons/icon-96x96.png", 'sizes' => '96x96']]],
        ['name' => 'Animales', 'url' => "$base/animales", 'icons' => [['src' => "$base/assets/img/icons/icon-96x96.png", 'sizes' => '96x96']]],
    ],
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);