<?php
$base = defined('APP_BASE') ? APP_BASE : '';
if ($base !== '') {
    ob_start(function (string $html) use ($base): string {
        $html = preg_replace('/(href|action|src)="\/(?!\/)/', '$1="' . $base . '/', $html);
        return $html;
    });
}
$appName = Helper::getSetting('app_name', 'Plenvo');
$_privacyUrl = Helper::getSetting('privacy_url', '');
$_imprintUrl = Helper::getSetting('imprint_url', '');
?>
<!DOCTYPE html>
<html lang="de" data-theme="light">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= Helper::e($appName) ?> – <?= isset($pageTitle) ? Helper::e($pageTitle) : 'Hilfe' ?></title>
    <link rel="stylesheet" href="/assets/css/app.css">
    <link rel="icon" href="/assets/img/favicon.svg" type="image/svg+xml">
</head>
<body style="background:var(--bg-base);min-height:100vh;display:flex;flex-direction:column">

<header style="background:var(--bg-card);border-bottom:1px solid var(--border-color);padding:0 32px;height:56px;display:flex;align-items:center;justify-content:space-between;flex-shrink:0">
    <a href="/" style="display:flex;align-items:center;gap:10px;text-decoration:none">
        <svg viewBox="0 0 40 40" fill="none" width="28" height="28"><rect width="40" height="40" rx="10" fill="#4f46e5"/><path d="M10 14h20M10 20h14M10 26h18" stroke="white" stroke-width="2.5" stroke-linecap="round"/></svg>
        <span style="font-weight:700;font-size:1rem;color:var(--text-primary)"><?= Helper::e($appName) ?></span>
    </a>
    <div style="display:flex;align-items:center;gap:16px">
        <a href="/help" style="font-size:.875rem;color:var(--text-secondary);text-decoration:none"><?= t('manual') ?></a>
        <a href="/login" class="btn btn-primary btn-sm"><?= t('login_btn') ?></a>
    </div>
</header>

<main style="flex:1;padding:32px;max-width:1100px;width:100%;margin:0 auto;box-sizing:border-box">
    <?= $content ?>
</main>

<footer style="background:var(--bg-card);border-top:1px solid var(--border-color);padding:16px 32px;display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:8px">
    <span style="font-size:.8rem;color:var(--text-muted)">v<?= APP_VERSION ?> · <?= Helper::e($appName) ?></span>
    <div style="display:flex;gap:16px">
        <?php if ($_privacyUrl): ?>
        <a href="<?= Helper::e($_privacyUrl) ?>" target="_blank" rel="noopener" style="font-size:.8rem;color:var(--text-muted);text-decoration:none">Datenschutz</a>
        <?php endif; ?>
        <?php if ($_imprintUrl): ?>
        <a href="<?= Helper::e($_imprintUrl) ?>" target="_blank" rel="noopener" style="font-size:.8rem;color:var(--text-muted);text-decoration:none">Impressum</a>
        <?php endif; ?>
    </div>
</footer>

<script nonce="<?= csp_nonce() ?>" src="/assets/js/app.js"></script>
</body>
</html>
