<?php
$db_file = __DIR__ . '/db_planos.db';
$plano = null;

try {
    if (file_exists($db_file)) {
        $pdo = new PDO("sqlite:" . $db_file);
        $id = isset($_GET['id']) ? (int)$_GET['id'] : 1;
        $stmt = $pdo->prepare("SELECT * FROM planos WHERE id = ?");
        $stmt->execute([$id]);
        $plano = $stmt->fetch(PDO::FETCH_ASSOC);
    }
} catch(Exception $e) { }

if (!$plano) exit();
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        html, body { 
            width: 100%; 
            height: 100%; 
            background: transparent !important; 
            overflow: hidden; 
            font-family: sans-serif; 
        }
        
        .container { 
            width: 100vw; 
            height: 100vh; 
            display: flex; 
            flex-direction: column; 
            justify-content: space-between; 
            align-items: center; 
            /* Padding leve para afastar os textos das bordas físicas */
            padding: 6px 4px; 
            text-align: center;
        }

        .titulo { 
            font-size: 9.5vw; 
            font-weight: 900; 
            color: <?= $plano['cor_titulo'] ?>; 
            text-transform: uppercase; 
            line-height: 1; 
            /* Removi o margin negativo para ele descer um pouco */
            margin-top: 2px; 
        }

        .qr-box { 
            flex: 1; 
            display: flex; 
            align-items: center; 
            justify-content: center; 
            width: 100%; 
        }

        .qrcode { 
            max-width: 90%; 
            max-height: 90%; 
            height: auto; 
            border-radius: 8px; 
            border: 4px solid #fff; 
            box-shadow: 0 4px 10px rgba(0,0,0,0.3);
        }

        .valor { 
            font-size: 11.5vw; 
            font-weight: 900; 
            color: <?= $plano['cor_texto'] ?>; 
            text-transform: uppercase; 
            line-height: 1; 
            /* Removi o margin negativo para ele subir um pouco */
            margin-bottom: 2px; 
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="titulo"><?= htmlspecialchars($plano['titulo'] ?: ' ') ?></div>
        
        <div class="qr-box">
            <?php if(!empty($plano['qrcode_url'])): ?>
                <img src="<?= htmlspecialchars($plano['qrcode_url']) ?>" class="qrcode">
            <?php endif; ?>
        </div>

        <div class="valor"><?= htmlspecialchars($plano['valor']) ?></div>
    </div>
</body>
</html>
