@extends('layouts.app')

@section('content')
<div class="container py-4">
    
    <div class="card border-0 bg-dark text-white p-4 p-md-5 rounded-3 mb-4 shadow-sm position-relative overflow-hidden">
        <div class="position-absolute top-0 end-0 p-3 opacity-10 d-none d-md-block" style="font-size: 8rem; transform: translate(20px, -20px);">
            <i class="bi bi-mortarboard-fill"></i>
        </div>
        <div class="row align-items-center position-relative" style="z-index: 2;">
            <div class="col-md-8">
                <span class="badge bg-primary text-uppercase px-3 py-2 rounded-pill mb-2 fw-bold small">Panel del Estudiante</span>
                <h1 class="display-6 fw-bold mb-2">¡Hola, {{ Auth::user()->name }}! 👋</h1>
                <p class="lead text-white-50 mb-0">Qué bueno verte de regreso. Continúa expandiendo tus conocimientos y especialización profesional hoy.</p>
            </div>
            <div class="col-md-4 text-md-end mt-3 mt-md-0">
                <div class="bg-white bg-opacity-10 rounded-3 p-3 d-inline-block border border-white border-opacity-10 text-start">
                    <small class="text-white-50 d-block fw-semibold text-uppercase" style="font-size: 0.7rem; tracking: 1px;">Mis Programas</small>
                    <span class="fs-3 fw-bold">{{ $courses->count() }}</span>
                    <span class="text-white-50 small">Matriculados</span>
                </div>
            </div>
        </div>
    </div>

    <div class="mb-5">
        <div class="d-flex align-items-center mb-3">
            <div class="p-2 bg-primary-subtle text-primary rounded-3 me-2 fs-5 d-flex align-items-center justify-content-center" style="width: 38px; height: 38px;">
                <i class="bi bi-book-half"></i>
            </div>
            <h4 class="fw-bold text-dark mb-0">Mis Cursos Activos</h4>
        </div>

        <div class="row g-4">
            @forelse($courses as $course)
                <div class="col-md-6 col-lg-4">
                    <div class="card h-100 border-0 shadow-sm rounded-3 overflow-hidden bg-white transition-hover">
                        
                        <div class="position-relative">
                            @if($course->image_path)
                                <img src="{{ asset('storage/' . $course->image_path) }}" class="card-img-top" alt="{{ $course->title }}" style="height: 180px; object-fit: cover;">
                            @else
                                <div class="bg-light border-bottom d-flex align-items-center justify-content-center text-muted card-img-top" style="height: 180px;">
                                    <i class="bi bi-image" style="font-size: 3rem;"></i>
                                </div>
                            @endif
                            <span class="position-absolute top-0 start-0 m-3 badge bg-dark bg-opacity-70 backdrop-blur rounded-pill text-capitalize small">
                                {{ $course->type->name ?? 'Especialidad' }}
                            </span>
                        </div>

                        <div class="card-body p-4 d-flex flex-column justify-content-between">
                            <div>
                                <h5 class="card-title fw-bold text-dark text-truncate-2 mb-2" style="font-size: 1.1rem; line-height: 1.4;">
                                    {{ $course->title }}
                                </h5>
                                <p class="card-text text-muted small text-truncate-3 mb-4">
                                    {{ $course->summary }}
                                </p>
                            </div>

                            <div class="mb-4">
                                <div class="d-flex justify-content-between align-items-center mb-1">
                                    <span class="text-secondary fw-semibold" style="font-size: 0.75rem;">Progreso del estudio</span>
                                    <span class="text-primary fw-bold" style="font-size: 0.75rem;">35%</span>
                                </div>
                                <div class="progress rounded-pill" style="height: 6px;">
                                    <div class="progress-bar progress-bar-striped progress-bar-animated rounded-pill" role="progressbar" style="width: 35%" aria-valuenow="35" aria-valuemin="0" aria-valuemax="100"></div>
                                </div>
                            </div>

                            <div class="d-grid">
                                <a href="{{ route('classroom.show', $course->id) }}" class="btn btn-primary fw-bold rounded-pill shadow-sm d-flex align-items-center justify-content-center py-2">
                                    <span>Ingresar al Aula Virtual</span>
                                    <i class="bi bi-arrow-right-short fs-5 ms-1"></i>
                                </a>
                            </div>
                        </div>

                    </div>
                </div>
            @empty
                <div class="col-12 text-center py-5">
                    <div class="card border-0 shadow-sm p-5 bg-white rounded-3 max-w-md mx-auto">
                        <i class="bi bi-journal-x display-3 text-muted mb-3"></i>
                        <h5 class="fw-bold text-dark">Aún no estás inscrito en ningún curso</h5>
                        <p class="text-secondary small mb-4">Explora nuestra vitrina académica y encuentra el programa perfecto para potenciar tu carrera profesional.</p>
                        <a href="{{ url('/') }}" class="btn btn-outline-primary fw-bold rounded-pill px-4">
                            <i class="bi bi-search me-1"></i> Ver Catálogo de Cursos
                        </a>
                    </div>
                </div>
            @endforelse
        </div>
    </div>

</div>

<style>
    /* Efecto de elevación suave para las tarjetas al pasar el cursor */
    .transition-hover {
        transition: transform 0.3s ease, box-shadow 0.3s ease;
    }
    .transition-hover:hover {
        transform: translateY(-5px);
        box-shadow: 0 1rem 3rem rgba(0,0,0,.12) !important;
    }
    /* Filtro blur para el badge flotante en las portadas */
    .backdrop-blur {
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }
    /* Limitador de líneas para párrafos extensos */
    .text-truncate-2 {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;  
        overflow: hidden;
    }
    .text-truncate-3 {
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;  
        overflow: hidden;
    }
    .max-w-md { max-width: 450px; }
</style>
@endsection