<!DOCTYPE html>
<html lang="pt-BR">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Alemão Conveniência - Promoções & Sorteio</title>
    <meta name="description"
        content="Confira as melhores promoções da Alemão Conveniência e participe do nosso sorteio!">
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/bootstrap-icons.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css"/>
    <style>
        :root {
            --primary: #f59e0b;
            --primary-dark: #d97706;
            --primary-light: #fbbf24;
            --secondary: #10b981; /* Was #06b6d4 (Cyan) -> Now #10b981 (Emerald) */
            --bg-dark: #0f172a;
            --bg-card: #1e293b;
            --bg-section: #131c2e;
            --text-light: #f1f5f9;
            --text-muted: #94a3b8;
            --glass-border: rgba(255, 255, 255, 0.08);
            --success: #06b6d4; /* Was #10b981 (Emerald) -> Now #06b6d4 (Cyan) */
            --danger: #ef4444;
            --gradient-primary: linear-gradient(135deg, #f59e0b, #d97706);
            --gradient-secondary: linear-gradient(135deg, #10b981, #059669);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        html {
            scroll-behavior: smooth;
        }

        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            background: var(--bg-dark);
            color: var(--text-light);
            overflow-x: hidden;
        }

        /* Navbar */
        .navbar-custom {
            background: rgba(15, 23, 42, 0.9);
            backdrop-filter: blur(20px);
            border-bottom: 1px solid var(--glass-border);
            padding: 16px 0;
            position: fixed;
            top: 0;
            width: 100%;
            z-index: 100;
            transition: all 0.3s;
        }

        .navbar-brand {
            font-weight: 800;
            font-size: 1.3rem;
            color: var(--text-light) !important;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .navbar-brand .brand-icon {
            width: 36px;
            height: 36px;
            background: var(--gradient-primary);
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 18px;
        }

        .nav-link {
            color: var(--text-muted) !important;
            font-weight: 500;
            font-size: 0.9rem;
            transition: color 0.3s;
        }

        .nav-link:hover {
            color: var(--primary) !important;
        }

        .nav-link.active {
            color: var(--primary) !important;
        }

        /* Hero */
        .hero {
            padding: 140px 0 80px;
            position: relative;
            overflow: hidden;
        }

        .hero::before {
            content: '';
            position: absolute;
            top: -200px;
            right: -200px;
            width: 600px;
            height: 600px;
            background: radial-gradient(circle, rgba(245, 158, 11, 0.08), transparent);
            border-radius: 50%;
        }

        .hero-badge {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            background: rgba(245, 158, 11, 0.1);
            border: 1px solid rgba(245, 158, 11, 0.2);
            border-radius: 100px;
            padding: 8px 16px;
            color: var(--primary);
            font-size: 0.8rem;
            font-weight: 600;
            margin-bottom: 20px;
            animation: fadeIn 0.6s ease;
        }

        .hero h1 {
            font-size: 3rem;
            font-weight: 900;
            line-height: 1.1;
            letter-spacing: -0.03em;
            margin-bottom: 16px;
            animation: slideUp 0.6s ease;
        }

        .hero h1 span {
            color: var(--primary);
        }

        .hero p {
            font-size: 1.1rem;
            color: var(--text-muted);
            max-width: 500px;
            line-height: 1.6;
            margin-bottom: 32px;
            animation: slideUp 0.6s ease 0.1s both;
        }

        .hero-buttons {
            display: flex;
            gap: 12px;
            flex-wrap: wrap;
            animation: slideUp 0.6s ease 0.2s both;
        }

        .btn-primary-custom {
            background: var(--gradient-primary);
            border: none;
            border-radius: 12px;
            padding: 14px 28px;
            color: white;
            font-weight: 700;
            font-size: 0.95rem;
            text-decoration: none;
            transition: all 0.3s;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }

        .btn-primary-custom:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 30px rgba(245, 158, 11, 0.3);
            color: white;
        }

        .btn-secondary-custom {
            background: rgba(255, 255, 255, 0.05);
            border: 1px solid var(--glass-border);
            border-radius: 12px;
            padding: 14px 28px;
            color: var(--text-light);
            font-weight: 600;
            font-size: 0.95rem;
            text-decoration: none;
            transition: all 0.3s;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }

        .btn-secondary-custom:hover {
            background: rgba(255, 255, 255, 0.1);
            color: white;
        }

        @keyframes slideUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
            }

            to {
                opacity: 1;
            }
        }

        /* Section Headers */
        .section-header {
            text-align: center;
            margin-bottom: 48px;
        }

        .section-badge {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            padding: 6px 14px;
            border-radius: 100px;
            font-size: 0.75rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            margin-bottom: 12px;
        }

        .section-header h2 {
            font-size: 2rem;
            font-weight: 800;
            letter-spacing: -0.02em;
            margin-bottom: 8px;
        }

        .section-header p {
            color: var(--text-muted);
            font-size: 1rem;
        }

        /* Promotions */
        .promotions-section {
            padding: 80px 0;
            background: var(--bg-section);
            position: relative;
        }

        .promo-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 24px;
        }

        .promo-card {
            background: var(--bg-card);
            border: 1px solid var(--glass-border);
            border-radius: 20px;
            overflow: hidden;
            transition: all 0.3s;
            position: relative;
        }

        .promo-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
        }

        .promo-card .promo-image {
            height: 240px;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            overflow: hidden;
            background: #000;
        }

        .promo-card .promo-image::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            height: 50%;
            background: linear-gradient(to top, rgba(15, 23, 42, 0.6), transparent);
            pointer-events: none;
        }

        .promo-discount {
            position: absolute;
            top: 16px;
            right: 16px;
            background: var(--danger);
            color: white;
            padding: 6px 12px;
            border-radius: 10px;
            font-size: 0.8rem;
            font-weight: 800;
            z-index: 5;
            box-shadow: 0 4px 10px rgba(239, 68, 68, 0.4);
        }

        .promo-body {
            padding: 24px;
            background: var(--bg-card);
        }

        .promo-body h3 {
            font-size: 1.15rem;
            font-weight: 800;
            margin-bottom: 10px;
            color: white;
            letter-spacing: -0.01em;
        }

        .promo-body .promo-desc {
            font-size: 0.85rem;
            color: var(--text-muted);
            margin-bottom: 20px;
            line-height: 1.5;
        }

        .promo-prices {
            display: flex;
            align-items: baseline;
            gap: 10px;
        }

        .promo-price-old {
            color: var(--text-muted);
            text-decoration: line-through;
            font-size: 0.85rem;
        }

        .promo-price-new {
            font-size: 1.4rem;
            font-weight: 800;
            color: var(--success);
        }

        /* Product images */
        .product-img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
        }

        .promo-card:hover .product-img {
            transform: scale(1.08);
        }

        /* Raffle Section */
        .raffle-section {
            padding: 80px 0;
        }

        .raffle-header-card {
            background: var(--bg-card);
            border: 1px solid var(--glass-border);
            border-radius: 20px;
            padding: 32px;
            margin-bottom: 32px;
            text-align: center;
        }

        .raffle-header-card h3 {
            font-size: 1.5rem;
            font-weight: 800;
            margin-bottom: 8px;
        }

        .raffle-header-card .price-tag {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            background: rgba(245, 158, 11, 0.1);
            border: 1px solid rgba(245, 158, 11, 0.2);
            border-radius: 100px;
            padding: 8px 20px;
            color: var(--primary);
            font-size: 1.1rem;
            font-weight: 700;
            margin: 12px 0;
        }

        .raffle-stats {
            display: flex;
            justify-content: center;
            gap: 32px;
            margin-top: 16px;
            flex-wrap: wrap;
        }

        .raffle-stat {
            text-align: center;
        }

        .raffle-stat .value {
            font-size: 1.5rem;
            font-weight: 800;
        }

        .raffle-stat .label {
            font-size: 0.75rem;
            color: var(--text-muted);
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }

        .numbers-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
            gap: 6px;
            max-height: 400px;
            overflow-y: auto;
            padding: 16px;
            background: var(--bg-card);
            border: 1px solid var(--glass-border);
            border-radius: 16px;
        }

        .numbers-grid::-webkit-scrollbar {
            width: 6px;
        }

        .numbers-grid::-webkit-scrollbar-track {
            background: transparent;
        }

        .numbers-grid::-webkit-scrollbar-thumb {
            background: var(--glass-border);
            border-radius: 3px;
        }

        .number-cell {
            width: 100%;
            aspect-ratio: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 8px;
            font-size: 0.75rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s;
            border: 1px solid var(--glass-border);
            background: rgba(255, 255, 255, 0.03);
            color: var(--text-light);
        }

        .number-cell:hover:not(.sold) {
            background: rgba(245, 158, 11, 0.15);
            border-color: var(--primary);
            transform: scale(1.05);
        }

        .number-cell.sold {
            background: rgba(239, 68, 68, 0.15);
            border-color: rgba(239, 68, 68, 0.3);
            color: var(--danger);
            cursor: not-allowed;
            opacity: 0.6;
        }

        .number-cell.selected {
            background: var(--gradient-primary);
            border-color: var(--primary);
            color: white;
            transform: scale(1.1);
            box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
        }

        /* Buy Modal */
        .modal-content {
            background: var(--bg-card);
            border: 1px solid var(--glass-border);
            border-radius: 20px;
            color: var(--text-light);
        }

        .modal-header {
            border-bottom: 1px solid var(--glass-border);
            padding: 20px 24px;
        }

        .modal-header .modal-title {
            font-weight: 700;
        }

        .modal-header .btn-close {
            filter: invert(1);
        }

        .modal-body {
            padding: 24px;
        }

        .modal-footer {
            border-top: 1px solid var(--glass-border);
            padding: 16px 24px;
        }

        .modal .form-control {
            background: rgba(255, 255, 255, 0.05);
            border: 1px solid var(--glass-border);
            border-radius: 10px;
            color: var(--text-light);
            padding: 12px 16px;
        }

        .modal .form-control:focus {
            background: rgba(255, 255, 255, 0.08);
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
            color: var(--text-light);
        }

        .modal .form-label {
            color: var(--text-muted);
            font-size: 0.85rem;
            font-weight: 600;
        }

        .btn-buy {
            background: var(--gradient-primary);
            border: none;
            border-radius: 12px;
            padding: 12px 28px;
            color: white;
            font-weight: 700;
            transition: all 0.3s;
        }

        .btn-buy:hover {
            transform: translateY(-1px);
            box-shadow: 0 5px 15px rgba(245, 158, 11, 0.3);
            color: white;
        }

        /* Legends */
        .number-legend {
            display: flex;
            gap: 20px;
            justify-content: center;
            margin: 16px 0;
            flex-wrap: wrap;
        }

        .legend-item {
            display: flex;
            align-items: center;
            gap: 6px;
            font-size: 0.8rem;
            color: var(--text-muted);
        }

        .legend-dot {
            width: 12px;
            height: 12px;
            border-radius: 4px;
        }

        .legend-dot.available {
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid var(--glass-border);
        }

        .legend-dot.sold {
            background: rgba(239, 68, 68, 0.3);
            border: 1px solid rgba(239, 68, 68, 0.3);
        }

        .legend-dot.selected {
            background: var(--primary);
        }

        /* Footer */
        .footer {
            padding: 40px 0 24px;
            background: var(--bg-section);
            border-top: 1px solid var(--glass-border);
            text-align: center;
            color: var(--text-muted);
            font-size: 0.85rem;
        }

        /* Toast */
        .toast-container {
            position: fixed;
            top: 80px;
            right: 20px;
            z-index: 200;
        }

        .toast {
            border-radius: 12px;
        }

        @media (max-width: 768px) {
            .hero h1 {
                font-size: 2rem;
            }

            .hero {
                padding: 120px 0 60px;
            }

            .numbers-grid {
                grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
            }
        }
        /* Swiper Hero Customizations */
        .hero-swiper {
            width: 100%;
            padding-bottom: 40px;
        }

        .swiper-pagination-bullet {
            background: rgba(255, 255, 255, 0.5) !important;
            width: 12px;
            height: 12px;
            opacity: 1;
        }

        .swiper-pagination-bullet-active {
            background: var(--primary) !important;
            width: 30px;
            border-radius: 6px;
        }

        .healthcare-slide-content {
            background: linear-gradient(135deg, rgba(15, 23, 42, 0.9) 0%, rgba(15, 23, 42, 0.4) 100%), url('/images/saude-bucal-blue-bg.png');
            background-size: cover;
            background-position: center;
            border-radius: 24px;
            padding: 80px 40px;
            border: 1px solid var(--glass-border);
            position: relative;
            overflow: hidden;
        }

        .healthcare-slide-content::after {
            content: '';
            position: absolute;
            inset: 0;
            background: radial-gradient(circle at 20% 50%, rgba(6, 182, 212, 0.15), transparent 50%);
            pointer-events: none;
        }

        .btn-healthcare {
            background: var(--gradient-secondary);
            border: none;
            border-radius: 12px;
            padding: 14px 28px;
            color: white;
            font-weight: 700;
            font-size: 0.95rem;
            text-decoration: none;
            transition: all 0.3s;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }

        .btn-healthcare:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 30px rgba(6, 182, 212, 0.3);
            color: white;
        }

        @media (max-width: 768px) {
            .hero-swiper {
                padding-bottom: 30px;
            }
            .healthcare-slide-content {
                padding: 40px 20px;
            }
        }

        /* Raffle Swiper Styles */
        .raffle-swiper {
            padding-bottom: 60px !important;
            margin-top: 20px;
        }

        .raffle-pagination {
            bottom: 10px !important;
            display: flex;
            justify-content: center;
            gap: 10px;
            flex-wrap: wrap;
        }

        .raffle-pagination .swiper-pagination-bullet {
            width: auto !important;
            height: 36px !important;
            padding: 0 16px !important;
            border-radius: 12px !important;
            background: rgba(255, 255, 255, 0.05) !important;
            border: 1px solid var(--glass-border) !important;
            color: var(--text-muted) !important;
            display: inline-flex !important;
            align-items: center !important;
            justify-content: center !important;
            font-size: 0.85rem !important;
            font-weight: 700 !important;
            transition: all 0.3s !important;
            opacity: 1 !important;
            margin: 0 !important;
        }

        .raffle-pagination .swiper-pagination-bullet-active {
            background: var(--gradient-primary) !important;
            border-color: var(--primary) !important;
            color: white !important;
            box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3) !important;
        }

        .swiper-button-next, .swiper-button-prev {
            color: var(--primary);
        }

        .swiper-button-next:after, .swiper-button-prev:after {
            font-size: 24px;
        }

        /* Fidelity Section Style */
        .fidelity-section {
            padding: 80px 0;
            background: var(--bg-dark);
            position: relative;
        }

        .fidelity-card {
            background: var(--bg-card);
            border: 1px solid var(--glass-border);
            border-radius: 24px;
            padding: 40px;
            text-align: center;
            transition: all 0.3s;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            position: relative;
            overflow: hidden;
        }

        .fidelity-card.featured {
            border-color: var(--secondary);
            background: linear-gradient(135deg, var(--bg-card) 0%, rgba(6, 182, 212, 0.05) 100%);
        }

        .fidelity-card:hover {
            transform: translateY(-8px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
            border-color: var(--primary);
        }

        .fidelity-card .card-icon {
            font-size: 40px;
            color: var(--secondary);
            margin-bottom: 20px;
        }

        .fidelity-card h3 {
            font-size: 1.5rem;
            font-weight: 800;
            margin-bottom: 16px;
        }

        .fidelity-card .card-price {
            font-size: 2.5rem;
            font-weight: 900;
            color: white;
            margin-bottom: 24px;
        }

        .fidelity-card .card-price span {
            font-size: 0.9rem;
            color: var(--text-muted);
            font-weight: 400;
        }

        .fidelity-card .card-features {
            list-style: none;
            padding: 0;
            margin-bottom: 32px;
            text-align: left;
        }

        .fidelity-card .card-features li {
            margin-bottom: 12px;
            font-size: 0.9rem;
            color: var(--text-muted);
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .fidelity-card .card-features li i {
            color: var(--success);
        }

        .btn-fidelity {
            background: rgba(255, 255, 255, 0.05);
            border: 1px solid var(--glass-border);
            border-radius: 12px;
            padding: 12px;
            color: white;
            text-decoration: none;
            font-weight: 700;
            transition: all 0.3s;
        }

        .btn-fidelity.featured {
            background: var(--gradient-secondary);
            border: none;
        }

        .btn-fidelity:hover {
            background: var(--primary);
            border-color: var(--primary);
            color: white;
        }
    </style>
</head>

<body>
    <!-- Navbar -->
    <nav class="navbar-custom">
        <div class="container">
            <div class="d-flex justify-content-between align-items-center">
                <a class="navbar-brand" href="/">
                    <div class="brand-icon">🏪</div>
                    Alemão Conveniência
                </a>
                <div class="d-none d-md-flex gap-4">
                    <a href="#promos" class="nav-link">Promoções</a>
                    <a href="#sorteio" class="nav-link">Sorteio</a>
                    <a href="/login" class="nav-link"><i class="bi bi-person-circle me-1"></i> Minha Área</a>
                </div>
                <button class="d-md-none" id="mobileMenuBtn" onclick="toggleMobileMenu()"
                    style="background:none;border:1px solid rgba(255,255,255,0.15);border-radius:8px;padding:6px 10px;color:var(--text-light);cursor:pointer;">
                    <i class="bi bi-list" style="font-size:1.2rem"></i>
                </button>
            </div>
            <!-- Mobile drawer -->
            <div id="mobileMenu" style="display:none;padding:12px 0 4px;border-top:1px solid rgba(255,255,255,0.06);margin-top:12px;">
                <a href="#promos" class="nav-link d-block py-2" onclick="toggleMobileMenu()">Promoções</a>
                <a href="#sorteio" class="nav-link d-block py-2" onclick="toggleMobileMenu()">Sorteio</a>
                <a href="/login" class="nav-link d-block py-2" onclick="toggleMobileMenu()"><i class="bi bi-person-circle me-1"></i> Minha Área</a>
            </div>
        </div>
    </nav>

    <!-- Hero Slider -->
    <div class="container mt-4">
        <div class="swiper hero-swiper">
            <div class="swiper-wrapper">
                <!-- Slide 1: Promoções -->
                <div class="swiper-slide">
                    <section class="hero w-100 p-0" style="padding: 60px 0 !important;">
                        <div class="row align-items-center">
                            <div class="col-lg-7">
                                <div class="hero-badge">
                                    <i class="bi bi-stars"></i> Ofertas Exclusivas
                                </div>
                                <h1>As Melhores <span>Promoções</span> da Conveniência</h1>
                                <p>Confira nossas ofertas especiais e participe do nosso grande sorteio. Números a partir de R$5,00!</p>
                                <div class="hero-buttons">
                                    <a href="#promos" class="btn-primary-custom">
                                        <i class="bi bi-tag"></i> Ver Promoções
                                    </a>
                                    <a href="#sorteio" class="btn-secondary-custom">
                                        <i class="bi bi-ticket-perforated"></i> Participar Sorteio
                                    </a>
                                </div>
                            </div>
                        </div>
                    </section>
                </div>

                <!-- Slide 2: Saúde Bucal -->
                <div class="swiper-slide">
                    <div class="healthcare-slide-content w-100">
                        <div class="row align-items-center">
                            <div class="col-lg-7">
                                <div class="hero-badge" style="background: rgba(6, 182, 212, 0.1); border-color: rgba(6, 182, 212, 0.2); color: var(--secondary);">
                                    <i class="bi bi-shield-plus"></i> Saúde Bucal
                                </div>
                                <h1 style="color: white;">Seu <span>Sorriso</span> em Dia</h1>
                                <p>Descontos exclusivos em tratamentos odontológicos, limpezas e prevenção com o nosso programa de fidelidade direto e sem burocracia.</p>
                                <div class="hero-buttons">
                                    <a href="#fidelidade" class="btn-healthcare">
                                        <i class="bi bi-info-circle"></i> Ver Detalhes
                                    </a>
                                    <a href="#parceiros" class="btn-secondary-custom">
                                        <i class="bi bi-geo-alt"></i> Ver Parceiros
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Pagination -->
            <div class="swiper-pagination"></div>
        </div>
    </div>

    <!-- Fidelity Section -->
    <section class="fidelity-section" id="fidelidade">
        <div class="container">
            <div class="section-header">
                <div class="section-badge" style="background:rgba(6,182,212,0.1);color:var(--success);border:1px solid rgba(6,182,212,0.2)">
                    <i class="bi bi-shield-check"></i> Saúde Bucal
                </div>
                <h2>Planos Odontológicos Diretos</h2>
                <p>Cuidado e prevenção para o seu sorriso com as melhores condições da região.</p>
            </div>

            <div class="row justify-content-center g-4">
                <!-- Individual Plan -->
                <div class="col-md-5 col-lg-4">
                    <div class="fidelity-card">
                        <div class="card-icon"><i class="bi bi-person"></i></div>
                        <h3>Plano Individual</h3>
                        <div class="card-price">R$ 25<span>/mês</span></div>
                        <ul class="card-features">
                            <li><i class="bi bi-check2"></i> Limpezas e Prevenção</li>
                            <li><i class="bi bi-check2"></i> Descontos em Tratamentos</li>
                            <li><i class="bi bi-check2"></i> Extrações e Obturações</li>
                            <li><i class="bi bi-check2"></i> Sem Carência</li>
                        </ul>
                        <a href="#" class="btn-fidelity">Assinar Agora</a>
                    </div>
                </div>

                <!-- Family Plan -->
                <div class="col-md-5 col-lg-4">
                    <div class="fidelity-card featured">
                        <div class="card-icon"><i class="bi bi-people"></i></div>
                        <h3>Plano Família</h3>
                        <div class="card-price">R$ 80<span>/mês</span></div>
                        <ul class="card-features">
                            <li><i class="bi bi-check2"></i> Até 4 Dependentes</li>
                            <li><i class="bi bi-check2"></i> Limpezas e Prevenção</li>
                            <li><i class="bi bi-check2"></i> Descontos em Tratamentos</li>
                            <li><i class="bi bi-check2"></i> Urgência e Emergência</li>
                        </ul>
                        <a href="#" class="btn-fidelity featured">Assinar Agora</a>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Promotions -->
    <section class="promotions-section" id="promos">
        <div class="container">
            <div class="section-header">
                <div class="section-badge"
                    style="background:rgba(245,158,11,0.1);color:var(--primary);border:1px solid rgba(245,158,11,0.2)">
                    <i class="bi bi-fire"></i> Promoções
                </div>
                <h2>Ofertas Imperdíveis</h2>
                <p>Aproveite os melhores preços em produtos selecionados</p>
            </div>
            <div class="promo-grid" id="promoGrid">
                <div class="text-center py-5" style="grid-column: 1/-1; color:var(--text-muted)">
                    <div class="spinner-border text-warning mb-3" role="status"></div>
                    <p>Carregando promoções...</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Raffle -->
    <section class="raffle-section" id="sorteio">
        <div class="container">
            <div class="section-header">
                <div class="section-badge"
                    style="background:rgba(16,185,129,0.1);color:var(--secondary);border:1px solid rgba(16,185,129,0.2)">
                    <i class="bi bi-trophy"></i> Sorteio
                </div>
                <h2>Grande Sorteio</h2>
                <p>Escolha seu número da sorte e concorra a prêmios incríveis</p>
            </div>

            <div id="raffleContent">
                <div class="text-center py-5" style="color:var(--text-muted)">
                    <div class="spinner-border text-info mb-3" role="status"></div>
                    <p>Carregando sorteio...</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="footer">
        <div class="container">
            <p><strong>Alemão Conveniência 6.0</strong></p>
            <p class="mt-1" style="font-size:0.75rem">© 2024 - Todos os direitos reservados</p>
        </div>
    </footer>

    <!-- Buy Modal -->
    <div class="modal fade" id="buyModal" tabindex="-1">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title"><i class="bi bi-ticket-perforated me-2"></i>Comprar Número</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <div class="text-center mb-3">
                        <span style="font-size:2.5rem;font-weight:900;color:var(--primary)"
                            id="selectedNumberDisplay">-</span>
                        <p style="color:var(--text-muted);font-size:0.85rem">Número selecionado</p>
                    </div>
                    <form id="buyForm">
                        <input type="hidden" id="buyRaffleId">
                        <input type="hidden" id="buyNumero">
                        <div class="mb-3">
                            <label class="form-label" for="buyNome">Nome Completo *</label>
                            <input type="text" class="form-control" id="buyNome" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label" for="buyCpf">CPF *</label>
                            <input type="text" class="form-control" id="buyCpf" maxlength="14" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label" for="buyTelefone">WhatsApp *</label>
                            <input type="tel" class="form-control" id="buyTelefone" maxlength="15" required>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"
                        style="border-radius:10px">Cancelar</button>
                    <button type="button" class="btn btn-buy" id="btnBuy" onclick="confirmBuy()">
                        <i class="bi bi-cart-check me-1"></i> Confirmar Compra
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Pix Payment Modal -->
    <div class="modal fade" id="pixModal" data-bs-backdrop="static" tabindex="-1">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-header text-center">
                    <h5 class="modal-title w-100"><i class="bi bi-qr-code me-2"></i>Pagamento PIX</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body text-center p-4">
                    <div class="mb-3">
                        <h4 style="color:var(--success);font-weight:800;" id="pixAmountDisplay">R$ 0,00</h4>
                        <p class="text-muted" style="font-size:0.85rem">Escaneie o QR Code ou copie o código PIX</p>
                    </div>
                    <div class="bg-white p-2 border-radius-10 mb-4" style="border-radius:12px; display:inline-block; width:220px; height:220px; text-align:center;">
                        <img id="pixQrImage" src="" alt="QR Code Pix" style="width:100%; height:100%;">
                    </div>
                    <div class="input-group mb-3 text-start">
                        <input type="text" class="form-control" id="pixCodeInput" readonly style="font-size:0.8rem; background:rgba(255,255,255,0.05); color:white; border:1px solid rgba(255,255,255,0.1);">
                        <button class="btn btn-primary" type="button" onclick="copyPixCode()"><i class="bi bi-files"></i> Copiar</button>
                    </div>
                    
                    <div class="mt-4" id="pixStatusContainer">
                        <div class="spinner-border spinner-border-sm text-warning mb-2" role="status"></div>
                        <p class="text-warning mb-0" style="font-weight:600; font-size:0.9rem">Aguardando pagamento...</p>
                        <p class="text-muted" style="font-size:0.75rem">Sua reserva expira em 5 minutos.</p>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- Success Modal (WiFi Only) -->
    <div class="modal fade" id="wifiSuccessModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content" style="border: 2px solid var(--primary); background: var(--bg-card); border-radius: 24px;">
                <div class="modal-body text-center p-5">
                    <div class="mb-4">
                        <div style="width: 80px; height: 80px; background: rgba(16, 185, 129, 0.1); border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto;">
                            <i class="bi bi-check-lg" style="font-size: 3rem; color: var(--success);"></i>
                        </div>
                    </div>
                    <h3 class="fw-bold mb-3" style="color: var(--text-light);">Cadastro Concluído!</h3>
                    <p class="text-muted mb-4">Para sua melhor experiência e para que a conexão não caia, clique no botão abaixo para abrir nosso site no seu navegador principal.</p>
                    
                    <button type="button" class="btn-primary-custom w-100 py-3 mb-3" id="btnFinalize" onclick="finalizeAndOpenChrome(this)" style="justify-content: center;">
                        <i class="bi bi-browser-chrome"></i> ABRIR NO GOOGLE CHROME
                    </button>
                    
                    <div class="d-flex flex-column align-items-center justify-content-center gap-2 text-muted" style="font-size: 0.75rem;">
                        <div class="d-flex align-items-center gap-1">
                            <i class="bi bi-shield-lock"></i>
                            <span>Sua internet será liberada agora</span>
                        </div>
                        <a href="#" id="manualChromeLink" class="text-primary text-decoration-none mt-2 d-none" style="font-weight: 600;">
                            Clique aqui se o Chrome não abrir sozinho
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Toast -->
    <div class="toast-container">
        <div id="toast" class="toast" role="alert">
            <div class="toast-body" id="toastBody"></div>
        </div>
    </div>

    <script src="/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>
    <script>
        // Hero Slider Initialization (Safe Check)
        let heroSwiper = null;
        if (typeof Swiper !== 'undefined') {
            heroSwiper = new Swiper('.hero-swiper', {
                loop: true,
                autoplay: {
                    delay: 9000,
                    disableOnInteraction: false,
                    pauseOnMouseEnter: true,
                },
                pagination: {
                    el: '.swiper-pagination',
                    clickable: true,
                },
                effect: 'fade',
                fadeEffect: {
                    crossFade: true
                },
                speed: 800,
            });
        } else {
            console.warn('⚠️ Swiper não carregado (provavelmente sem internet). Prosseguindo...');
        }

        let currentRaffle = null;
        let selectedNumber = null;

        function showToast(msg, type = 'success') {
            const t = document.getElementById('toast');
            const tb = document.getElementById('toastBody');
            tb.textContent = msg;
            t.className = 'toast show ' + (type === 'success' ? 'bg-success' : 'bg-danger');
            t.style.color = 'white';
            setTimeout(() => t.className = 'toast', 4000);
        }

        // Product emoji icons
        function getProductIcon(nome) {
            const n = nome.toLowerCase();
            if (n.includes('coca') || n.includes('refrigerante') || n.includes('pepsi')) return '🥤';
            if (n.includes('cerveja') || n.includes('heineken') || n.includes('brahma') || n.includes('skol')) return '🍺';
            if (n.includes('doritos') || n.includes('salgadinho') || n.includes('cheetos')) return '🌮';
            if (n.includes('energético') || n.includes('red bull') || n.includes('monster')) return '⚡';
            if (n.includes('água')) return '💧';
            if (n.includes('chocolate') || n.includes('bis') || n.includes('kit kat')) return '🍫';
            if (n.includes('café') || n.includes('cappuccino')) return '☕';
            if (n.includes('sorvete') || n.includes('picolé')) return '🍦';
            if (n.includes('pão') || n.includes('pao')) return '🍞';
            if (n.includes('cigarro') || n.includes('tabaco')) return '🚬';
            return '🛒';
        }

        function getProductBg(nome) {
            const n = nome.toLowerCase();
            if (n.includes('coca') || n.includes('refrigerante')) return 'linear-gradient(135deg, #1a0000, #3d0000)';
            if (n.includes('cerveja') || n.includes('heineken')) return 'linear-gradient(135deg, #001a0d, #003d1a)';
            if (n.includes('doritos') || n.includes('salgadinho')) return 'linear-gradient(135deg, #1a1000, #3d2600)';
            if (n.includes('energético') || n.includes('red bull')) return 'linear-gradient(135deg, #0d001a, #1a003d)';
            if (n.includes('água')) return 'linear-gradient(135deg, #001a2e, #003d6b)';
            if (n.includes('chocolate') || n.includes('bis')) return 'linear-gradient(135deg, #1a0d00, #3d1f00)';
            return 'linear-gradient(135deg, #0d1a2e, #1a2d47)';
        }

        function getProductImage(nome) {
            const n = nome.toLowerCase();
            if (n.includes('coca')) return '/images/products/coca-cola.png';
            if (n.includes('heineken') || n.includes('cerveja')) return '/images/products/heineken.png';
            if (n.includes('doritos')) return '/images/products/doritos.png';
            if (n.includes('red bull') || n.includes('energético')) return '/images/products/red-bull.png';
            if (n.includes('água')) return '/images/products/agua.png';
            if (n.includes('bis') || n.includes('chocolate')) return '/images/products/bis.png';
            return null;
        }

        function calcDiscount(original, promo) {
            if (!original || original <= promo) return 0;
            return Math.round(((original - promo) / original) * 100);
        }

        // Load promotions
        async function loadPromotions() {
            try {
                const res = await fetch('/api/promotions');
                const promos = await res.json();
                const grid = document.getElementById('promoGrid');

                if (promos.length === 0) {
                    grid.innerHTML = '<div class="text-center py-5" style="grid-column:1/-1;color:var(--text-muted)"><i class="bi bi-bag-x" style="font-size:3rem"></i><p class="mt-2">Nenhuma promoção no momento</p></div>';
                    return;
                }

                grid.innerHTML = promos.map(p => {
                    const discount = calcDiscount(p.preco_original, p.preco_promocional);
                    const imgSrc = getProductImage(p.nome);
                    return `
            <div class="promo-card">
              <div class="promo-image">
                ${imgSrc ? `<img src="${imgSrc}" alt="${p.nome}" class="product-img">` : `<div style="background:${getProductBg(p.nome)}; width:100%; height:100%; display:flex; align-items:center; justify-content:center; font-size:64px;">${getProductIcon(p.nome)}</div>`}
                ${discount > 0 ? `<div class="promo-discount">-${discount}%</div>` : ''}
              </div>
              <div class="promo-body">
                <h3>${p.nome}</h3>
                <p class="promo-desc">${p.descricao || ''}</p>
                <div class="promo-prices">
                  <span class="promo-price-new">R$ ${parseFloat(p.preco_promocional).toFixed(2)}</span>
                  ${p.preco_original ? `<span class="promo-price-old">R$ ${parseFloat(p.preco_original).toFixed(2)}</span>` : ''}
                </div>
              </div>
            </div>
          `;
                }).join('');
            } catch (err) {
                console.error('Erro:', err);
                document.getElementById('promoGrid').innerHTML = '<div class="text-center py-5" style="grid-column:1/-1;color:var(--text-muted)">Erro ao carregar promoções</div>';
            }
        }

        // Load raffle
        async function loadRaffle() {
            try {
                const res = await fetch('/api/raffle');
                const raffles = await res.json();

                if (raffles.length === 0) {
                    document.getElementById('raffleContent').innerHTML = '<div class="text-center py-5" style="color:var(--text-muted)">Nenhum sorteio ativo</div>';
                    return;
                }

                const raffle = raffles[0];
                const detailRes = await fetch(`/api/raffle/${raffle.id}`);
                currentRaffle = await detailRes.json();

                renderRaffle();
            } catch (err) {
                console.error('Erro:', err);
                document.getElementById('raffleContent').innerHTML = '<div class="text-center py-5" style="color:var(--text-muted)">Erro ao carregar sorteio</div>';
            }
        }

        function renderRaffle() {
            if (!currentRaffle) return;
            const r = currentRaffle;

            const html = `
        <div class="raffle-header-card">
          <h3>🏆 ${r.titulo}</h3>
          <p style="color:var(--text-muted)">${r.descricao || ''}</p>
          <div class="price-tag"><i class="bi bi-ticket-perforated"></i> R$ ${parseFloat(r.preco_numero).toFixed(2)} / número</div>
          <div class="raffle-stats">
            <div class="raffle-stat">
              <div class="value" style="color:var(--success)">${r.totalDisponivel}</div>
              <div class="label">Disponíveis</div>
            </div>
            <div class="raffle-stat">
              <div class="value" style="color:var(--danger)">${r.totalSold}</div>
              <div class="label">Vendidos</div>
            </div>
            <div class="raffle-stat">
              <div class="value">${r.total_numeros}</div>
              <div class="label">Total</div>
            </div>
          </div>
        </div>

        <div class="number-legend">
          <div class="legend-item"><div class="legend-dot available"></div> Disponível</div>
          <div class="legend-item"><div class="legend-dot sold"></div> Vendido</div>
          <div class="legend-item"><div class="legend-dot selected"></div> Selecionado</div>
        </div>

        <div class="swiper raffle-swiper">
          <div class="swiper-wrapper" id="raffleSwiperWrapper"></div>
          <div class="swiper-pagination raffle-pagination"></div>
          <div class="swiper-button-next d-none d-md-flex"></div>
          <div class="swiper-button-prev d-none d-md-flex"></div>
        </div>
      `;

            document.getElementById('raffleContent').innerHTML = html;

            const swiperWrapper = document.getElementById('raffleSwiperWrapper');
            const soldSet = new Set(r.soldNumbers || []);
            
            // Create slides (100 numbers each)
            let currentSlideHtml = '';
            for (let i = 1; i <= r.total_numeros; i++) {
                const isSold = soldSet.has(i);
                
                if ((i - 1) % 100 === 0) {
                    currentSlideHtml = '<div class="swiper-slide"><div class="numbers-grid">';
                }
                
                currentSlideHtml += `<div class="number-cell ${isSold ? 'sold' : ''}" data-number="${i}" ${!isSold ? `onclick="selectNumber(${i})"` : ''}>${String(i).padStart(3, '0')}</div>`;
                
                if (i % 100 === 0 || i === r.total_numeros) {
                    currentSlideHtml += '</div></div>';
                    swiperWrapper.insertAdjacentHTML('beforeend', currentSlideHtml);
                }
            }

            // Init Raffle Swiper (Safe Check)
            if (typeof Swiper !== 'undefined') {
                new Swiper('.raffle-swiper', {
                    loop: false,
                    pagination: {
                        el: '.raffle-pagination',
                        clickable: true,
                        renderBullet: function (index, className) {
                            return '<span class="' + className + '">' + (index + 1) + '/' + ((index + 1) * 100) + '</span>';
                        },
                    },
                    navigation: {
                        nextEl: '.swiper-button-next',
                        prevEl: '.swiper-button-prev',
                    },
                    speed: 600,
                });
            }
        }

        function selectNumber(num) {
            if (selectedNumber === num) {
                selectedNumber = null;
                document.querySelectorAll('.number-cell').forEach(c => c.classList.remove('selected'));
                return;
            }

            selectedNumber = num;
            document.querySelectorAll('.number-cell').forEach(c => c.classList.remove('selected'));
            document.querySelector(`.number-cell[data-number="${num}"]`).classList.add('selected');

            // Open modal
            document.getElementById('selectedNumberDisplay').textContent = String(num).padStart(3, '0');
            document.getElementById('buyRaffleId').value = currentRaffle.id;
            document.getElementById('buyNumero').value = num;

            const modal = new bootstrap.Modal(document.getElementById('buyModal'));
            modal.show();
        }

        let pixStatusInterval = null;

        async function confirmBuy() {
            const nome = document.getElementById('buyNome').value.trim();
            const cpf = document.getElementById('buyCpf').value.trim();
            const telefone = document.getElementById('buyTelefone').value.trim();
            const raffleId = document.getElementById('buyRaffleId').value;
            const numero = document.getElementById('buyNumero').value;

            if (!nome || !cpf || !telefone) {
                showToast('Preencha os campos obrigatórios (Nome, CPF e WhatsApp)', 'error');
                return;
            }

            const btn = document.getElementById('btnBuy');
            btn.disabled = true;
            btn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Gerando PIX...';

            try {
                const res = await fetch('/api/raffle/ticket', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({
                        raffle_id: parseInt(raffleId),
                        numero: parseInt(numero),
                        usuario_nome: nome,
                        usuario_telefone: telefone.replace(/\D/g, ''),
                        usuario_cpf: cpf.replace(/\D/g, '')
                    })
                });

                const data = await res.json();

                if (data.success) {
                    sessionStorage.setItem('wifi_user_nome', nome);
                    sessionStorage.setItem('wifi_user_cpf', cpf.replace(/\D/g, ''));
                    sessionStorage.setItem('wifi_user_telefone', telefone.replace(/\D/g, ''));

                    bootstrap.Modal.getInstance(document.getElementById('buyModal')).hide();
                    
                    // Show Pix Modal
                    document.getElementById('pixAmountDisplay').textContent = 'R$ ' + parseFloat(data.amount).toFixed(2).replace('.', ',');
                    document.getElementById('pixQrImage').src = 'data:image/jpeg;base64,' + data.qrCodeUrl;
                    document.getElementById('pixCodeInput').value = data.pixCopyPaste;
                    
                    document.getElementById('pixStatusContainer').innerHTML = `
                        <div class="spinner-border spinner-border-sm text-warning mb-2" role="status"></div>
                        <p class="text-warning mb-0" style="font-weight:600; font-size:0.9rem">Aguardando pagamento...</p>
                        <p class="text-muted" style="font-size:0.75rem">Sua reserva expira em 5 minutos.</p>
                    `;

                    const pixModal = new bootstrap.Modal(document.getElementById('pixModal'));
                    pixModal.show();

                    // Start Polling
                    startPixPolling(data.orderId, raffleId);
                    
                } else {
                    showToast(data.error || 'Erro ao comprar', 'error');
                }
            } catch (err) {
                showToast('Erro de conexão', 'error');
            } finally {
                btn.disabled = false;
                btn.innerHTML = '<i class="bi bi-cart-check me-1"></i> Confirmar Compra';
            }
        }

        function copyPixCode() {
            const input = document.getElementById('pixCodeInput');
            input.select();
            input.setSelectionRange(0, 99999);
            navigator.clipboard.writeText(input.value);
            showToast('Código PIX copiado!');
        }

        function startPixPolling(orderId, raffleId) {
            if (pixStatusInterval) clearInterval(pixStatusInterval);
            let attempts = 0;
            
            pixStatusInterval = setInterval(async () => {
                attempts++;
                if (attempts > 300) { // 5 minutes max
                    clearInterval(pixStatusInterval);
                    document.getElementById('pixStatusContainer').innerHTML = '<p class="text-danger" style="font-weight:bold;">Tempo expirado</p>';
                    return;
                }
                
                try {
                    const res = await fetch(`/api/raffle/order/${orderId}/status`);
                    const orderState = await res.json();
                    
                    if (orderState.status === 'paid') {
                        clearInterval(pixStatusInterval);
                        
                        document.getElementById('pixStatusContainer').innerHTML = `
                            <i class="bi bi-check-circle-fill text-success" style="font-size:2rem"></i>
                            <p class="text-success mb-0 mt-2" style="font-weight:700; font-size:1.1rem">Pagamento Confirmado!</p>
                            <p class="text-muted mt-1">Seus bilhetes foram garantidos.</p>
                        `;
                        
                        // Close modal after 3s and refresh
                        setTimeout(async () => {
                            bootstrap.Modal.getInstance(document.getElementById('pixModal')).hide();
                            selectedNumber = null;
                            const detailRes = await fetch(`/api/raffle/${raffleId}`);
                            currentRaffle = await detailRes.json();
                            renderRaffle();
                        }, 3000);
                    } else if (orderState.status === 'expired' || orderState.status === 'canceled') {
                        clearInterval(pixStatusInterval);
                        document.getElementById('pixStatusContainer').innerHTML = '<p class="text-danger" style="font-weight:bold;">Reserva expirada/cancelada</p>';
                    }
                } catch (e) { console.error('Erro no polling do PIX', e); }
            }, 5000);
        }

        // CPF Mask
        document.getElementById('buyCpf').addEventListener('input', function (e) {
            let v = e.target.value.replace(/\D/g, '');
            if (v.length > 11) v = v.slice(0, 11);
            if (v.length > 9) v = v.replace(/(\d{3})(\d{3})(\d{3})(\d{1,2})/, '$1.$2.$3-$4');
            else if (v.length > 6) v = v.replace(/(\d{3})(\d{3})(\d{1,3})/, '$1.$2.$3');
            else if (v.length > 3) v = v.replace(/(\d{3})(\d{1,3})/, '$1.$2');
            e.target.value = v;
        });

        // Phone Mask
        document.getElementById('buyTelefone').addEventListener('input', function (e) {
            let v = e.target.value.replace(/\D/g, '');
            if (v.length > 11) v = v.slice(0, 11);
            if (v.length > 6) v = v.replace(/(\d{2})(\d{5})(\d{1,4})/, '($1) $2-$3');
            else if (v.length > 2) v = v.replace(/(\d{2})(\d{1,5})/, '($1) $2');
            e.target.value = v;
        });

        // --- Captive Portal Session Confirmation (Automatic) ---
        function autoConfirmWifi() {
            const params  = new URLSearchParams(window.location.search);
            const session = params.get('session');

            if (!session) return;

            const ua         = navigator.userAgent;
            const isAndroid  = /Android/i.test(ua);
            const isIOS      = /iPhone|iPad/i.test(ua);
            const isWebSheet = isAndroid && (!window.chrome || /Version\/\d/.test(ua));

            // Android WebSheet: dispara intent URL automaticamente após 1.2s
            // O usuário não precisa tocar em nada — Chrome abre sozinho.
            if (isWebSheet) {
                console.log('📡 WebSheet detectado. Abrindo Chrome em 1.2s...');
                setTimeout(() => {
                    const cleanUrl = window.location.origin + '/';
                    const intent   = 'intent://alemaoconveniencias.local:4001/' +
                        '#Intent;scheme=http;package=com.android.chrome;' +
                        'S.browser_fallback_url=' + encodeURIComponent(cleanUrl) + ';end';
                    window.location.href = intent;
                }, 1200);
                return;
            }

            // iOS CNA: window.open com _blank sai do CNA e abre no Safari
            if (isIOS) {
                console.log('📡 iOS CNA detectado. Abrindo Safari em 1.2s...');
                setTimeout(() => {
                    window.open(window.location.origin + '/', '_blank');
                }, 1200);
                return;
            }

            // Já está no Chrome/Safari (breakout feito pelo success.html):
            // só limpa os query params da URL.
            window.history.replaceState({}, document.title, '/');
        }

        function toggleMobileMenu() {
            const menu = document.getElementById('mobileMenu');
            const btn = document.getElementById('mobileMenuBtn');
            const isOpen = menu.style.display !== 'none';
            menu.style.display = isOpen ? 'none' : 'block';
            btn.innerHTML = isOpen ? '<i class="bi bi-list" style="font-size:1.2rem"></i>' : '<i class="bi bi-x-lg" style="font-size:1.2rem"></i>';
        }

        // ── Breakout para navegador real ─────────────────────────────────────────
        // Chamada pelo botão "ABRIR NO GOOGLE CHROME" dentro do modal wifiSuccessModal.
        // Cenário A: usuário está no Android WebSheet (mini-browser do captive portal)
        //   → dispara Intent URL para abrir o Chrome com a URL limpa do site
        // Cenário B: usuário já está no Chrome (breakout feito pelo success.html)
        //   → fecha o modal e limpa os query params da URL (remove session/gateway)
        function finalizeAndOpenChrome(btn) {
            const cleanUrl = window.location.origin + '/';
            const ua       = navigator.userAgent;

            // Android WebSheet: User-Agent contém "Version/x.x" sem ser Samsung Browser,
            // e window.chrome é undefined (WebView nativo não injeta o objeto chrome).
            const isAndroid    = /Android/i.test(ua);
            const isWebSheet   = isAndroid && (!window.chrome || /Version\/\d/.test(ua));

            if (isWebSheet) {
                // Tenta Chrome primeiro; fallback abre no browser padrão
                const intent = 'intent://alemaoconveniencias.local:4001/' +
                    '#Intent;scheme=http;package=com.android.chrome;' +
                    'S.browser_fallback_url=' + encodeURIComponent(cleanUrl) + ';end';
                window.location.href = intent;
                return;
            }

            if (/iPhone|iPad/i.test(ua)) {
                // iOS: window.open com _blank sai do CNA e abre no Safari
                window.open(cleanUrl, '_blank');
                return;
            }

            // Já está no Chrome/Firefox/Safari — só fecha o modal e limpa a URL
            try {
                bootstrap.Modal.getOrCreateInstance(
                    document.getElementById('wifiSuccessModal')
                ).hide();
            } catch (_) {}
            window.history.replaceState({}, document.title, '/');
        }

        // Init
        loadPromotions();
        loadRaffle();
        autoConfirmWifi();
    </script>
</body>

</html>