<?php
require_once '../../includes/auth.php';
require_once '../../includes/header.php';
require_once '../../includes/database.php';
requireRole('estudiante');

// Obtener datos del estudiante actual con sección, grado y nivel
$usuario_id = $_SESSION['user_id'];
$estudiante = $db->fetchOne("
    SELECT e.id, u.nombre, u.apellido, u.email,
           e.seccion, e.grado, e.nivel
    FROM estudiantes e
    JOIN usuarios u ON e.usuario_id = u.id
    WHERE e.usuario_id = ?
", [$usuario_id]);

// Obtener auxiliares y directores
$destinatarios = $db->fetchAll("
    SELECT id, nombre, apellido, email, tipo
    FROM usuarios
    WHERE tipo IN ('auxiliar', 'direccion')
");

// Obtener historial de correos enviados por este estudiante
$correos = $db->fetchAll("
    SELECT * 
    FROM correos_enviados 
    WHERE enviado_por = ?
    ORDER BY fecha_envio DESC 
    LIMIT 5
", [$usuario_id]);

$success = $_SESSION['success'] ?? null;
$error = $_SESSION['error'] ?? null;
unset($_SESSION['success'], $_SESSION['error']);

// Configuración para menú y header
$nombreColegio = APP_NAME;
$usuarioNombre = $_SESSION['user_name'] ?? 'Estudiante';
$usuarioRol = 'Estudiante';
?>

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contactar a Auxiliar/Director - <?= APP_NAME ?></title>
    <link href="<?= APP_URL ?>/assets/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            --primary: #3498db;
            --secondary: #2980b9;
            --accent: #3498db;
            --light: #ecf0f1;
            --dark: #2c3e50;
            --success: #2ecc71;
            --warning: #f39c12;
            --info: #1abc9c;
            --sidebar-width: 280px;
            --header-height: 70px;
        }

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

        body {
            background-color: #f5f7fa;
            color: #333;
            display: flex;
            min-height: 100vh;
            margin: 0;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            overflow-x: hidden;
            font-size: 16px;
            line-height: 1.5;
        }

        /* Sidebar para estudiantes */
        .sidebar {
            width: var(--sidebar-width);
            background: linear-gradient(to bottom, var(--primary), var(--secondary));
            color: white;
            height: 100vh;
            position: fixed;
            overflow-y: auto;
            transition: all 0.3s ease;
            box-shadow: 3px 0 15px rgba(0, 0, 0, 0.1);
            z-index: 1000;
        }

        .logo-container {
            padding: 20px 25px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            background-color: rgba(0, 0, 0, 0.1);
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .logo i {
            font-size: 28px;
            color: white;
        }

        .logo h1 {
            font-size: 22px;
            font-weight: 600;
        }

        .menu-section {
            padding: 25px 0;
        }

        .menu-title {
            padding: 0 25px 10px;
            font-size: 14px;
            text-transform: uppercase;
            letter-spacing: 1px;
            color: rgba(255, 255, 255, 0.7);
            font-weight: 500;
        }

        .menu-items {
            list-style: none;
            padding: 0;
        }

        .menu-item {
            padding: 12px 25px;
            display: flex;
            align-items: center;
            gap: 15px;
            cursor: pointer;
            transition: all 0.2s ease;
            border-left: 4px solid transparent;
            position: relative;
        }

        .menu-item:hover {
            background-color: rgba(255, 255, 255, 0.1);
            border-left-color: white;
        }

        .menu-item.active {
            background-color: rgba(255, 255, 255, 0.15);
            border-left-color: white;
        }

        .menu-item i {
            width: 24px;
            text-align: center;
            font-size: 18px;
        }

        .menu-item span {
            font-size: 16px;
            font-weight: 500;
        }

        /* Main Content */
        .main-content {
            flex: 1;
            margin-left: var(--sidebar-width);
            padding-bottom: 30px;
            transition: margin-left 0.3s ease;
            display: flex;
            flex-direction: column;
            min-height: 100vh;
        }

        /* Header */
        .header {
            height: var(--header-height);
            background-color: white;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 30px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            position: sticky;
            top: 0;
            z-index: 900;
            flex-shrink: 0;
        }

        .header-left {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .toggle-menu {
            display: none;
            font-size: 24px;
            cursor: pointer;
            color: var(--dark);
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: linear-gradient(135deg, var(--secondary), var(--primary));
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            font-size: 18px;
            flex-shrink: 0;
        }

        .user-details {
            display: flex;
            flex-direction: column;
        }

        .user-name {
            font-weight: 600;
            font-size: 15px;
        }

        .user-role {
            font-size: 13px;
            color: #7f8c8d;
        }
        
        /* Content container */
        .content {
            flex: 1;
            padding: 20px;
            display: flex;
            flex-direction: column;
        }
        
        .footer {
            padding: 20px 30px;
            text-align: center;
            color: #7f8c8d;
            font-size: 14px;
            border-top: 1px solid #eee;
            margin-top: auto;
            background: white;
            flex-shrink: 0;
        }
        
        /* ESTILOS MEJORADOS PARA EL FORMULARIO */
        .email-container {
            max-width: 100%;
            margin: 30px auto;
            background: white;
            border-radius: 12px;
            box-shadow: 0 5px 20px rgba(0,0,0,0.08);
            overflow: hidden;
            border: 1px solid #e0e6ef;
            flex: 1;
            display: flex;
            flex-direction: column;
        }
        
        .email-header {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            color: white;
            padding: 25px 30px;
            position: relative;
        }
        
        .email-header h1 {
            font-size: 24px;
            font-weight: 600;
            margin: 0;
            display: flex;
            align-items: center;
            gap: 15px;
        }
        
        .email-header p {
            opacity: 0.9;
            margin: 10px 0 0;
            font-size: 16px;
            max-width: 80%;
        }
        
        .email-content {
            padding: 30px;
            background: #fff;
            flex: 1;
            display: flex;
            flex-direction: column;
        }
        
        .form-label {
            font-weight: 600;
            color: var(--dark);
            margin-bottom: 8px;
            display: block;
        }
        
        .form-control, .form-select {
            border: 2px solid #e0e6ef;
            border-radius: 8px;
            padding: 12px 15px;
            transition: all 0.3s;
            background: #f8fafc;
            width: 100%;
            font-size: 16px;
        }
        
        .form-control:focus, .form-select:focus {
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
            background: #fff;
            outline: none;
        }
        
        .btn-send {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            border: none;
            padding: 12px 25px;
            font-weight: 600;
            font-size: 16px;
            border-radius: 8px;
            transition: all 0.3s;
            color: white;
            box-shadow: 0 4px 10px rgba(52, 152, 219, 0.3);
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }
        
        .btn-send:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 15px rgba(52, 152, 219, 0.4);
            color: white;
        }
        
        .recipient-card {
            background: #e8f4fe;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 25px;
            display: flex;
            align-items: center;
            gap: 15px;
            border-left: 4px solid var(--primary);
        }
        
        .recipient-icon {
            width: 60px;
            height: 60px;
            background: rgba(52, 152, 219, 0.1);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            color: var(--primary);
            flex-shrink: 0;
        }
        
        .recipient-info {
            flex: 1;
        }
        
        .recipient-info h3 {
            margin: 0;
            font-size: 18px;
            color: var(--dark);
        }
        
        .recipient-info p {
            margin: 5px 0 0;
            color: #6c757d;
        }
        
        .history-card {
            background: #f8fafc;
            border-radius: 10px;
            padding: 20px;
            margin-top: 30px;
            border: 1px solid #e9ecef;
            flex: 1;
            display: flex;
            flex-direction: column;
        }
        
        .history-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        
        .history-header h3 {
            margin: 0;
            color: var(--dark);
            font-size: 18px;
            display: flex;
            align-items: center;
            gap: 10px;
            color: var(--primary);
        }
        
        .history-table {
            width: 100%;
            border-collapse: collapse;
        }
        
        .history-table th {
            background-color: #e8f4fe;
            padding: 12px 15px;
            text-align: left;
            color: var(--dark);
            font-weight: 600;
            border-bottom: 2px solid #d0e8ff;
        }
        
        .history-table td {
            padding: 12px 15px;
            border-bottom: 1px solid #e9ecef;
        }
        
        .history-table tr:last-child td {
            border-bottom: none;
        }
        
        .badge {
            display: inline-block;
            padding: 5px 12px;
            border-radius: 50px;
            font-weight: 500;
            font-size: 14px;
        }
        
        .badge-success {
            background-color: rgba(46, 204, 113, 0.15);
            color: #27ae60;
        }
        
        .badge-danger {
            background-color: rgba(231, 76, 60, 0.15);
            color: #c0392b;
        }
        
        .no-history {
            text-align: center;
            padding: 30px;
            color: #6c757d;
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
        }
        
        .no-history i {
            font-size: 48px;
            color: #d0e8ff;
            margin-bottom: 15px;
        }
        
        .btn-back {
            background: rgba(255, 255, 255, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.3);
            color: white;
            padding: 8px 15px;
            border-radius: 6px;
            transition: all 0.3s;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            position: absolute;
            top: 20px;
            right: 20px;
        }
        
        .btn-back:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: translateY(-2px);
            color: white;
        }
        
        .alert {
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 20px;
            display: flex;
            align-items: flex-start;
            gap: 10px;
        }
        
        .alert-success {
            background-color: rgba(46, 204, 113, 0.15);
            border: 1px solid rgba(46, 204, 113, 0.3);
            color: #27ae60;
        }
        
        .alert-danger {
            background-color: rgba(231, 76, 60, 0.15);
            border: 1px solid rgba(231, 76, 60, 0.3);
            color: #c0392b;
        }
        
        .alert i {
            font-size: 20px;
            flex-shrink: 0;
        }
        
        .alert-content {
            flex: 1;
        }
        
        .form-group {
            margin-bottom: 25px;
        }
        
        .form-text {
            color: #6c757d;
            font-size: 14px;
            margin-top: 5px;
            display: flex;
            align-items: flex-start;
            gap: 8px;
        }
        
        .form-text i {
            color: var(--primary);
            flex-shrink: 0;
        }
        
        .form-actions {
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 15px;
            margin-top: 10px;
        }
        
        .form-info {
            color: #6c757d;
            font-size: 14px;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .form-info i {
            color: var(--primary);
        }
        
        /* RESPONSIVE */
        @media (max-width: 1200px) {
            .email-header h1 {
                font-size: 22px;
            }
            
            .email-header p {
                max-width: 100%;
            }
        }
        
        @media (max-width: 992px) {
            .sidebar {
                transform: translateX(-100%);
                z-index: 1100;
            }

            .sidebar.active {
                transform: translateX(0);
                box-shadow: 0 0 20px rgba(0,0,0,0.3);
            }

            .main-content {
                margin-left: 0;
            }

            .toggle-menu {
                display: block;
            }
            
            .email-container {
                margin: 20px;
            }
            
            .email-header h1 {
                font-size: 20px;
                flex-direction: column;
                align-items: flex-start;
                gap: 8px;
            }
            
            .email-header h1 i {
                font-size: 28px;
            }
            
            .email-header p {
                font-size: 15px;
            }
            
            .btn-back {
                top: 15px;
                right: 15px;
                padding: 6px 12px;
                font-size: 14px;
            }
        }
        
        @media (max-width: 768px) {
            .header {
                padding: 0 15px;
                height: 60px;
            }
            
            .email-container {
                margin: 15px;
            }
            
            .email-content {
                padding: 20px;
            }
            
            .recipient-card {
                flex-direction: column;
                text-align: center;
                padding: 15px;
            }
            
            .recipient-info h3 {
                font-size: 17px;
            }
            
            .form-actions {
                flex-direction: column;
                align-items: stretch;
            }
            
            .form-info {
                justify-content: center;
                text-align: center;
            }
            
            .history-table th, 
            .history-table td {
                padding: 10px;
                font-size: 14px;
            }
            
            .history-header h3 {
                font-size: 16px;
            }
            
            .history-card {
                padding: 15px;
            }
            
            .alert {
                padding: 12px;
            }
        }
        
        @media (max-width: 576px) {
            .sidebar {
                width: 100%;
                max-width: 300px;
            }
            
            .email-container {
                margin: 10px;
            }
            
            .email-header {
                padding: 20px 15px;
            }
            
            .email-content {
                padding: 15px;
            }
            
            .user-avatar {
                width: 36px;
                height: 36px;
                font-size: 16px;
            }
            
            .user-details {
                display: none;
            }
            
            .form-label {
                font-size: 15px;
            }
            
            .form-control, .form-select {
                padding: 10px;
                font-size: 15px;
            }
            
            .btn-send {
                width: 100%;
                padding: 12px;
            }
            
            .recipient-icon {
                width: 50px;
                height: 50px;
                font-size: 20px;
            }
            
            .history-table {
                display: block;
                overflow-x: auto;
            }
            
            .footer {
                padding: 15px;
                font-size: 13px;
            }
            
            .no-history {
                padding: 20px;
            }
            
            .no-history i {
                font-size: 40px;
            }
        }
        
        @media (max-width: 480px) {
            .logo h1 {
                font-size: 18px;
            }
            
            .menu-item {
                padding: 10px 15px;
            }
            
            .menu-item span {
                font-size: 14px;
            }
            
            .email-header h1 {
                font-size: 18px;
            }
            
            .email-header p {
                font-size: 14px;
            }
            
            .form-control, .form-select {
                font-size: 14px;
            }
            
            .history-card {
                padding: 12px;
            }
            
            .history-table th, 
            .history-table td {
                padding: 8px 10px;
                font-size: 13px;
            }
            
            .badge {
                font-size: 12px;
                padding: 4px 10px;
            }
            
            .alert {
                font-size: 14px;
            }
        }
        
        @media (max-width: 360px) {
            body {
                font-size: 14px;
            }
            
            .email-header {
                padding: 15px 12px;
            }
            
            .btn-back {
                top: 12px;
                right: 12px;
                font-size: 13px;
                padding: 5px 10px;
            }
            
            .email-header h1 {
                font-size: 16px;
            }
            
            .email-header h1 i {
                font-size: 24px;
            }
            
            .form-group {
                margin-bottom: 20px;
            }
            
            .form-text {
                font-size: 13px;
            }
            
            .form-info {
                font-size: 13px;
            }
        }
        
        /* Animations */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .fade-in {
            animation: fadeIn 0.5s ease forwards;
        }
        
        /* Overlay for mobile menu */
        .sidebar-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0,0,0,0.5);
            z-index: 1099;
            display: none;
        }
        
        .sidebar-overlay.active {
            display: block;
        }
        
        /* Smooth transitions */
        .sidebar, .main-content, .sidebar-overlay {
            transition: all 0.3s ease;
        }
    </style>
</head>
<body>
    <div class="sidebar">
        <div class="logo-container">
            <div class="logo">
                <i class="fas fa-graduation-cap"></i>
                <h1><?= $nombreColegio ?></h1>
            </div>
        </div>

        <div class="menu-section">
            <h3 class="menu-title">Principal</h3>
            <ul class="menu-items">
                <li class="menu-item">
                    <a href="<?= APP_URL ?>/modules/estudiante/dashboard.php" style="display: block; color: inherit; text-decoration: none;">
                        <i class="fas fa-home"></i>
                        <span>Menu</span>
                    </a>
                </li>
            </ul>
        </div>

        <div class="menu-section">
            <h3 class="menu-title">Académico</h3>
            <ul class="menu-items">
                <li class="menu-item">
                    <a href="<?= APP_URL ?>/modules/estudiante/ver_asistencia.php" style="display: block; color: inherit; text-decoration: none;">
                        <i class="fas fa-calendar-alt"></i>
                        <span>Ver Asistencia</span>
                    </a>
                </li>
                <li class="menu-item">
                    <a href="<?= APP_URL ?>/modules/estudiante/notificaciones.php" style="display: block; color: inherit; text-decoration: none;">
                        <i class="fas fa-inbox"></i>
                        <span>Ver Mensajería</span>
                    </a>
                </li>
                <li class="menu-item active">
                    <a href="<?= APP_URL ?>/modules/estudiante/enviar_correo.php" style="display: block; color: inherit; text-decoration: none;">
                        <i class="fas fa-envelope"></i>
                        <span>Enviar comunicado</span>
                    </a>
                </li>
                <li class="menu-item">
                    <a href="<?= APP_URL ?>/modules/estudiante/historial_de_correos_enviados.php" style="display: block; color: inherit; text-decoration: none;">
                        <i class="fas fa-history"></i>
                        <span>Historial de Comunicados</span>
                    </a>
                </li>
            </ul>
        </div>

        <div class="menu-section">
            <h3 class="menu-title">Cuenta</h3>
            <ul class="menu-items">
                <li class="menu-item">
                    <a href="<?= APP_URL ?>/modules/estudiante/cambiar_contrasena.php" style="display: block; color: inherit; text-decoration: none;">
                        <i class="fas fa-key"></i>
                        <span>Cambiar Contraseña</span>
                    </a>
                </li>
                <li class="menu-item">
                    <a href="<?= APP_URL ?>/auth/logout.php" style="display: block; color: inherit; text-decoration: none;">
                        <i class="fas fa-sign-out-alt"></i>
                        <span>Cerrar Sesión</span>
                    </a>
                </li>
            </ul>
        </div>
    </div>
    
    <!-- Overlay for mobile menu -->
    <div class="sidebar-overlay"></div>

    <!-- Main Content -->
    <div class="main-content">
        <!-- Header -->
        <header class="header">
            <div class="header-left">
                <div class="toggle-menu">
                    <i class="fas fa-bars"></i>
                </div>
            </div>

            <div class="header-right">
                <div class="user-profile">
                    <div class="user-info">
                        <div class="user-avatar"><?= substr($usuarioNombre, 0, 1) . (strpos($usuarioNombre, ' ') !== false ? substr($usuarioNombre, strpos($usuarioNombre, ' ') + 1, 1) : '') ?></div>
                        <div class="user-details">
                            <div class="user-name"><?= $usuarioNombre ?></div>
                            <div class="user-tipo"><?= $usuarioRol ?></div>
                        </div>
                    </div>
                </div>
            </div>
        </header>

        <!-- Contenido de contacto -->
        <div class="content">
            
                <div class="email-header">
                    <h1 class="fade-in"><i class="fas fa-headset"></i> Contactar a Auxiliar/Director</h1>
                    <p class="fade-in">Envía un mensaje al personal administrativo</p>
                    
                    <a href="dashboard.php" class="btn-back fade-in">
                        <i class="fas fa-arrow-left"></i> Volver
                    </a>
                </div>
                
                <div class="email-content">
                    <?php if ($success): ?>
                        <div class="alert alert-success fade-in">
                            <i class="fas fa-check-circle"></i>
                            <div class="alert-content"><?= $success ?></div>
                        </div>
                    <?php endif; ?>
                    
                    <?php if ($error): ?>
                        <div class="alert alert-danger fade-in">
                            <i class="fas fa-exclamation-circle"></i>
                            <div class="alert-content"><?= $error ?></div>
                        </div>
                    <?php endif; ?>
                    
                    <!-- Formulario de envío de correo -->
                    <form method="POST" action="send_email_estudiante_handler.php" id="emailForm" class="fade-in">
                        <input type="hidden" name="from" value="<?= htmlspecialchars($estudiante['email']) ?>">
                        <input type="hidden" name="estudiante_id" value="<?= $estudiante['id'] ?>">
                        
                        <div class="form-group">
                            <label for="recipient" class="form-label">Destinatario</label>
                            <select class="form-select" id="recipient" name="recipient" required>
                                <option value="">Seleccionar destinatario</option>
                                <?php foreach ($destinatarios as $dest): ?>
                                    <option value="<?= $dest['id'] ?>">
                                        <?= htmlspecialchars($dest['tipo']) ?>: 
                                        <?= htmlspecialchars($dest['nombre'] . ' ' . $dest['apellido']) ?>
                                    </option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        
                        <div class="form-group">
                            <label for="subject" class="form-label">Asunto</label>
                            <input type="text" class="form-control" id="subject" name="subject" required
                                   placeholder="Asunto del mensaje" value="Consulta de <?= htmlspecialchars($estudiante['nombre'] ?? '') ?>">

                        </div>
                        
                        <div class="form-group">
                            <label for="message" class="form-label">Mensaje</label>
                            <textarea class="form-control" id="message" name="message" rows="6" required
                                      placeholder="Escribe tu mensaje aquí...">Estimado(a),</textarea>
                            <div class="form-text">
                                <i class="fas fa-info-circle"></i> 
                                Tu nombre (<strong><?= htmlspecialchars($usuarioNombre) ?></strong>) 
                                se agregará automáticamente al final del mensaje
                            </div>
                        </div>
                        
                        <div class="form-actions">
                            <button type="submit" class="btn btn-send">
                                <i class="fas fa-paper-plane me-2"></i>Enviar Mensaje
                            </button>
                            <div class="form-info">
                                <i class="fas fa-info-circle"></i>Se enviará una copia a tu correo
                            </div>
                        </div>
                    </form>

                
            </div>
        </div>

        <!-- Footer -->
        <footer class="footer">
            <p>Sistema Escolar Integrado v3.0 © <?= date('Y') ?> - Todos los derechos reservados</p>
        </footer>
    </div>

    <!-- Bootstrap JS -->
    <script src="<?= APP_URL ?>/assets/js/bootstrap.bundle.min.js"></script>
    
    <script>
        // Toggle sidebar on mobile
        document.querySelector('.toggle-menu')?.addEventListener('click', function() {
            document.querySelector('.sidebar').classList.toggle('active');
            document.querySelector('.sidebar-overlay').classList.toggle('active');
            document.body.style.overflow = document.querySelector('.sidebar').classList.contains('active') ? 'hidden' : '';
        });
        
        // Close sidebar when clicking outside
        document.querySelector('.sidebar-overlay')?.addEventListener('click', function() {
            document.querySelector('.sidebar').classList.remove('active');
            this.classList.remove('active');
            document.body.style.overflow = '';
        });
        
        // Close sidebar when clicking on a menu item
        document.querySelectorAll('.menu-item a').forEach(item => {
            item.addEventListener('click', function() {
                document.querySelector('.sidebar').classList.remove('active');
                document.querySelector('.sidebar-overlay').classList.remove('active');
                document.body.style.overflow = '';
            });
        });
        
        // Form validation
        document.getElementById('emailForm')?.addEventListener('submit', function(e) {
            const recipient = document.getElementById('recipient').value;
            const subject = document.getElementById('subject').value.trim();
            const message = document.getElementById('message').value.trim();
            
            if (!recipient || !subject || !message) {
                e.preventDefault();
                alert('Por favor complete todos los campos requeridos');
            }
        });
        
        // Add animations to elements as they come into view
        const observer = new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    entry.target.classList.add('fade-in');
                }
            });
        }, { threshold: 0.1 });
        
        document.querySelectorAll('.fade-in').forEach(el => {
            observer.observe(el);
        });
    </script>
</body>
</html>