<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>{{ $clinicIdentity->name ?? 'Portal de Salud' }} - @yield('title')</title>
    
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
    
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <script src='/js/app.js'></script>

    
    <!-- Estilos personalizados -->
    <style>
        :root {
            --primary-color: #2A4E6D;
            --secondary-color: #3B6EA5;
            --accent-color: #4A90E2;
            --light-accent: #E3F2FD;
            --gradient: linear-gradient(135deg, #4A90E2 0%, #2A4E6D 100%);
            --text-color: #333;
            --light-gray: #f8f9fa;
            --white: #ffffff;
        }
        
        body {
            font-family: 'Poppins', sans-serif;
            color: var(--text-color);
            line-height: 1.6;
            overflow-x: hidden;
        }
        
        /* Header */
        .portal-navbar {
            background-color: var(--white);
            box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
            padding: 0.8rem 0;
        }
        
        .portal-navbar .navbar-brand img {
            height: 50px;
        }
        
        .portal-navbar .nav-link {
            color: var(--primary-color);
            font-weight: 500;
            padding: 0.5rem 1rem;
            margin: 0 0.25rem;
            transition: all 0.3s ease;
        }
        
        .portal-navbar .nav-link:hover,
        .portal-navbar .nav-link.active {
            color: var(--accent-color);
        }
        
        .portal-navbar .btn-primary {
            background: var(--gradient);
            border: none;
            padding: 0.6rem 1.5rem;
            border-radius: 50px;
            font-weight: 500;
            transition: all 0.3s ease;
        }
        
        .portal-navbar .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3);
        }
        
        /* Hero Section */
        .hero-section {
            position: relative;
            min-height: 600px;
            display: flex;
            align-items: center;
            background: var(--gradient);
            color: var(--white);
            overflow: hidden;
        }
        
        .hero-section::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 100px;
            background: var(--white);
            clip-path: polygon(0 50%, 100% 0, 100% 100%, 0% 100%);
            z-index: 1;
        }
        
        .hero-content {
            position: relative;
            z-index: 2;
            max-width: 650px;
        }
        
        .hero-content h1 {
            font-size: 3rem;
            font-weight: 700;
            margin-bottom: 1.5rem;
        }
        
        .hero-content p {
            font-size: 1.2rem;
            margin-bottom: 2rem;
            opacity: 0.9;
        }
        
        .btn-light-outline {
            background: transparent;
            border: 2px solid var(--white);
            color: var(--white);
            border-radius: 50px;
            padding: 0.6rem 1.5rem;
            font-weight: 500;
            transition: all 0.3s ease;
        }
        
        .btn-light-outline:hover {
            background: var(--white);
            color: var(--primary-color);
        }
        
        /* Secciones */
        section {
            padding: 5rem 0;
        }
        
        .section-title {
            text-align: center;
            margin-bottom: 3rem;
        }
        
        .section-title h2 {
            color: var(--primary-color);
            font-weight: 700;
            margin-bottom: 1rem;
            position: relative;
            display: inline-block;
        }
        
        .section-title h2::after {
            content: '';
            position: absolute;
            bottom: -10px;
            left: 50%;
            transform: translateX(-50%);
            width: 50px;
            height: 3px;
            background: var(--accent-color);
        }
        
        /* Cards */
        .card {
            border: none;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            transition: all 0.3s ease;
            height: 100%;
        }
        
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        
        .card-img-top {
            border-top-left-radius: 15px;
            border-top-right-radius: 15px;
            height: 200px;
            object-fit: cover;
        }
        
        .card-title {
            color: var(--primary-color);
            font-weight: 600;
        }
        
        /* Features */
        .feature-box {
            padding: 2rem;
            border-radius: 15px;
            background: var(--white);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            margin-bottom: 2rem;
            transition: all 0.3s ease;
        }
        
        .feature-box:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        
        .feature-icon {
            font-size: 2.5rem;
            color: var(--accent-color);
            margin-bottom: 1.5rem;
        }
        
        /* Call to Action */
        .cta-section {
            background: var(--gradient);
            color: var(--white);
            padding: 5rem 0;
            position: relative;
            overflow: hidden;
        }
        
        .cta-section::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100px;
            background: var(--white);
            clip-path: polygon(0 0, 100% 0, 100% 50%, 0 100%);
        }
        
        .cta-content {
            position: relative;
            z-index: 2;
            text-align: center;
            max-width: 700px;
            margin: 0 auto;
        }
        
        .cta-content h2 {
            font-size: 2.5rem;
            font-weight: 700;
            margin-bottom: 1.5rem;
        }
        
        /* Footer */
        footer {
            background-color: var(--primary-color);
            color: var(--white);
            padding: 4rem 0 1rem;
        }
        
        .footer-logo {
            max-width: 180px;
            margin-bottom: 1.5rem;
        }
        
        .footer-links h5 {
            font-weight: 600;
            margin-bottom: 1.5rem;
            color: var(--white);
        }
        
        .footer-links ul {
            list-style: none;
            padding: 0;
        }
        
        .footer-links ul li {
            margin-bottom: 0.8rem;
        }
        
        .footer-links ul li a {
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            transition: all 0.3s ease;
        }
        
        .footer-links ul li a:hover {
            color: var(--white);
            text-decoration: underline;
        }
        
        .social-links a {
            display: inline-block;
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.1);
            color: var(--white);
            text-align: center;
            line-height: 36px;
            margin-right: 0.5rem;
            transition: all 0.3s ease;
        }
        
        .social-links a:hover {
            background: var(--accent-color);
            transform: translateY(-3px);
        }
        
        .copyright {
            text-align: center;
            padding-top: 2rem;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            margin-top: 3rem;
            color: rgba(255, 255, 255, 0.7);
        }
        
        /* Forms */
        .form-control {
            border-radius: 8px;
            padding: 0.8rem 1rem;
            border: 1px solid #e1e1e1;
        }
        
        .form-control:focus {
            border-color: var(--accent-color);
            box-shadow: 0 0 0 0.25rem rgba(74, 144, 226, 0.25);
        }
        
        .form-label {
            font-weight: 500;
            color: var(--text-color);
        }
        
        /* Responsive */
        @media (max-width: 768px) {
            .hero-content h1 {
                font-size: 2.5rem;
            }
            
            .hero-content p {
                font-size: 1rem;
            }
            
            section {
                padding: 3rem 0;
            }
        }
    </style>
    
    @yield('styles')
</head>
<body>
    <!-- Header -->
    <nav class="navbar navbar-expand-lg navbar-light portal-navbar">
        <div class="container">
            <a class="navbar-brand" href="{{ route('portal.index') }}">
                @if(isset($clinicIdentity) && !empty($clinicIdentity->logo_path))
                    <img src="{{ asset('storage/' . $clinicIdentity->logo_path) }}" alt="{{ $clinicIdentity->name ?? 'Portal de Salud' }}">
                @else
                    <img src="{{ asset('images/default-logo.png') }}" alt="Portal de Salud">
                @endif
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ms-auto">
                    <li class="nav-item">
                        <a class="nav-link {{ Route::currentRouteName() == 'portal.index' ? 'active' : '' }}" href="{{ route('portal.index') }}">Inicio</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {{ Route::currentRouteName() == 'portal.services' ? 'active' : '' }}" href="{{ route('portal.services') }}">Servicios</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {{ Route::currentRouteName() == 'portal.contact' ? 'active' : '' }}" href="{{ route('portal.contact') }}">Contacto</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {{ Route::currentRouteName() == 'portal.register' ? 'active' : '' }}" href="{{ route('portal.register') }}">Registro</a>
                    </li>
                </ul>
                <a href="{{ route('portal.appointments') }}" class="btn btn-primary ms-3">Agendar Cita</a>
            </div>
        </div>
    </nav>

    <!-- Contenido principal -->
    <main>
        @yield('content')
    </main>

    <!-- Footer -->
    <footer>
        <div class="container">
            <div class="row">
                <div class="col-lg-4 mb-4">
                    <div class="footer-info">
                        @if(isset($clinicIdentity) && !empty($clinicIdentity->logo_path))
                            <img src="{{ asset('storage/' . $clinicIdentity->logo_path) }}" alt="{{ $clinicIdentity->name ?? 'Portal de Salud' }}" class="footer-logo">
                        @else
                            <img src="{{ asset('images/default-logo-white.png') }}" alt="Portal de Salud" class="footer-logo">
                        @endif
                        <p>{{ $clinicIdentity->description ?? 'Nuestra misión es brindar la mejor atención médica a todos nuestros pacientes, con profesionalismo, calidez y tecnología de vanguardia.' }}</p>
                        <div class="social-links mt-3">
                            <a href="#"><i class="fab fa-facebook-f"></i></a>
                            <a href="#"><i class="fab fa-twitter"></i></a>
                            <a href="#"><i class="fab fa-instagram"></i></a>
                            <a href="#"><i class="fab fa-linkedin-in"></i></a>
                        </div>
                    </div>
                </div>
                <div class="col-lg-2 col-md-6 mb-4">
                    <div class="footer-links">
                        <h5>Enlaces rápidos</h5>
                        <ul>
                            <li><a href="{{ route('portal.index') }}">Inicio</a></li>
                            <li><a href="{{ route('portal.services') }}">Servicios</a></li>
                            <li><a href="{{ route('portal.contact') }}">Contacto</a></li>
                            <li><a href="{{ route('portal.register') }}">Registro</a></li>
                        </ul>
                    </div>
                </div>
                <div class="col-lg-3 col-md-6 mb-4">
                    <div class="footer-links">
                        <h5>Servicios</h5>
                        <ul>
                            <li><a href="{{ route('portal.services') }}">Consultas Médicas</a></li>
                            <li><a href="{{ route('portal.services') }}">Especialidades</a></li>
                            <li><a href="{{ route('portal.services') }}">Exámenes</a></li>
                            <li><a href="{{ route('portal.services') }}">Tratamientos</a></li>
                        </ul>
                    </div>
                </div>
                <div class="col-lg-3 col-md-6 mb-4">
                    <div class="footer-links">
                        <h5>Contáctenos</h5>
                        <p>
                            <i class="fas fa-map-marker-alt me-2"></i> {{ $clinicIdentity->address ?? 'Calle Principal 123, Ciudad' }}<br>
                            <i class="fas fa-phone me-2"></i> {{ $clinicIdentity->phone ?? '+1 234 567 890' }}<br>
                            <i class="fas fa-envelope me-2"></i> {{ $clinicIdentity->email ?? 'info@clinica.com' }}
                        </p>
                        <p><strong>Horario:</strong><br>{{ $clinicIdentity->working_hours ?? 'Lunes a Viernes: 8:00 AM - 8:00 PM' }}</p>
                    </div>
                </div>
            </div>
            <div class="copyright">
                <p>&copy; {{ date('Y') }} {{ $clinicIdentity->name ?? 'Portal de Salud' }}. Todos los derechos reservados.</p>
            </div>
        </div>
    </footer>

    <!-- Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
    

    
    @yield('scripts')
    <script src="{{ asset('js/portal.js') }}"></script>
    @stack('scripts')
    
    <!-- Modal de Alerta de Conexión -->
    <div class="modal fade" id="connectionAlertModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="connectionAlertModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-header bg-danger text-white">
                    <h5 class="modal-title" id="connectionAlertModalLabel">
                        <i class="fas fa-wifi-slash me-2"></i>Sin conexión a Internet
                    </h5>
                </div>
                <div class="modal-body">
                    <div class="text-center mb-4">
                        <i class="fas fa-globe-americas fs-1 text-secondary mb-3"></i>
                        <p class="lead">Se ha perdido la conexión a Internet.</p>
                        <p>El portal requiere una conexión activa para funcionar correctamente. Por favor verifique su conexión a Internet e intente nuevamente.</p>
                    </div>
                    <div class="d-flex justify-content-center">
                        <div class="spinner-border text-primary me-2" role="status">
                            <span class="visually-hidden">Verificando...</span>
                        </div>
                        <span>Verificando conexión...</span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Script para detectar la conexión a Internet -->
    <script>
        // Variables para el manejo del modal y temporizadores
        let connectionModal;
        let connectionTimeout;
        let pingInterval;
        
        // Inicializar modal cuando el DOM esté listo
        document.addEventListener('DOMContentLoaded', function() {
            connectionModal = new bootstrap.Modal(document.getElementById('connectionAlertModal'), {
                backdrop: 'static',
                keyboard: false
            });
        });
        
        // Función para verificar la conexión haciendo una petición mínima
        function checkConnection() {
            return fetch('/favicon.ico', { 
                method: 'HEAD',
                cache: 'no-store',
                mode: 'no-cors',
                timeout: 5000 
            })
            .then(() => true)
            .catch(() => false);
        }
        
        // Manejador cuando se detecta pérdida de conexión
        async function handleOffline() {
            // Limpiar temporizadores existentes
            clearTimeout(connectionTimeout);
            clearInterval(pingInterval);
            
            // Mostrar modal
            if (connectionModal) connectionModal.show();
            
            // Iniciar verificación periódica de conexión
            pingInterval = setInterval(async () => {
                const isConnected = await checkConnection();
                if (isConnected) {
                    handleOnline();
                }
            }, 5000); // Verificar cada 5 segundos
        }
        
        // Manejador cuando se restaura la conexión
        function handleOnline() {
            // Limpiar verificación periódica
            clearInterval(pingInterval);
            
            // Cerrar modal
            if (connectionModal) connectionModal.hide();
            
            // Mostrar notificación de reconexión
            const toast = document.createElement('div');
            toast.className = 'position-fixed bottom-0 end-0 p-3';
            toast.style.zIndex = '9999';
            toast.innerHTML = `
                <div class="toast show" role="alert" aria-live="assertive" aria-atomic="true">
                    <div class="toast-header bg-success text-white">
                        <i class="fas fa-wifi me-2"></i>
                        <strong class="me-auto">Conexión restaurada</strong>
                        <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
                    </div>
                    <div class="toast-body">
                        La conexión a Internet ha sido restablecida.
                    </div>
                </div>
            `;
            document.body.appendChild(toast);
            
            // Eliminar toast después de 3 segundos
            setTimeout(() => {
                toast.remove();
            }, 3000);
        }
        
        // Verificación proactiva al cargar la página
        window.addEventListener('load', async () => {
            const isConnected = await checkConnection();
            if (!isConnected) {
                handleOffline();
            }
        });
        
        // Escuchar eventos nativos de conexión/desconexión
        window.addEventListener('offline', () => {
            // Esperar un momento para confirmar que realmente se perdió la conexión
            connectionTimeout = setTimeout(async () => {
                const isConnected = await checkConnection();
                if (!isConnected) {
                    handleOffline();
                }
            }, 1500);
        });
        
        window.addEventListener('online', async () => {
            clearTimeout(connectionTimeout);
            // Verificar que realmente hay conexión
            const isConnected = await checkConnection();
            if (isConnected) {
                handleOnline();
            }
        });
        
        // Verificación periódica adicional (cada 30 segundos)
        setInterval(async () => {
            const isConnected = await checkConnection();
            if (!isConnected) {
                handleOffline();
            }
        }, 30000);
    </script>
</body>
</html> 