<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Teacher Dashboard - RUSO LMS</title>
    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <!-- Tailwind CSS CDN -->
    <script src="https://cdn.tailwindcss.com"></script>
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    fontFamily: { sans: ['Inter', 'sans-serif'] },
                    colors: { primary: '#1a56db', secondary: '#10b981' }
                }
            }
        }
    </script>
</head>
<body class="bg-gray-50 text-gray-900 font-sans antialiased flex">

    <?php $first_name = $profile ? explode(' ', trim($profile->full_name))[0] : 'Teacher'; ?>

    <!-- ================= DESKTOP SIDEBAR ================= -->
    <aside class="hidden md:flex flex-col w-64 bg-gray-900 text-white min-h-screen fixed left-0 top-0 z-50">
        <div class="p-6 border-b border-gray-800">
            <img src="<?= base_url('assets/images/logo.png') ?>" alt="CSO Logo" class="h-12 w-auto bg-white rounded p-1">
            <div class="text-xs text-gray-400 mt-1 uppercase tracking-wider font-semibold">Teacher Portal</div>
        </div>
        
        <nav class="flex-1 px-4 py-6 space-y-2">
            <a href="<?= site_url('teacher/dashboard') ?>" class="flex items-center gap-3 px-4 py-3 bg-gray-800 text-white rounded-lg border-l-4 border-blue-500 transition-colors">
                <svg class="w-5 h-5 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><rect x="3" y="3" width="7" height="7"></rect><rect x="14" y="3" width="7" height="7"></rect><rect x="14" y="14" width="7" height="7"></rect><rect x="3" y="14" width="7" height="7"></rect></svg>
                <span class="font-medium">Dashboard</span>
            </a>
            
            <a href="#" class="flex items-center gap-3 px-4 py-3 text-gray-400 hover:bg-gray-800 hover:text-white rounded-lg transition-colors">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"></path></svg>
                <span class="font-medium">My Classes</span>
            </a>
            
            <a href="#" class="flex items-center gap-3 px-4 py-3 text-gray-400 hover:bg-gray-800 hover:text-white rounded-lg transition-colors">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>
                <span class="font-medium">Materials</span>
            </a>

            <a href="#" class="flex items-center gap-3 px-4 py-3 text-gray-400 hover:bg-gray-800 hover:text-white rounded-lg transition-colors">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"></path></svg>
                <span class="font-medium">Assignments & Quizzes</span>
            </a>
        </nav>
        
        <div class="p-4 border-t border-gray-800">
            <a href="<?= site_url('auth/logout') ?>" class="flex items-center gap-3 px-4 py-3 text-red-400 hover:bg-red-500 hover:bg-opacity-10 rounded-lg transition-colors">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"></path></svg>
                <span class="font-medium">Sign Out</span>
            </a>
        </div>
    </aside>

    <!-- ================= MOBILE BOTTOM BAR ================= -->
    <nav class="md:hidden fixed bottom-0 w-full bg-white border-t border-gray-200 z-50 shadow-[0_-4px_10px_rgba(0,0,0,0.05)] pb-safe">
        <div class="flex justify-around items-center h-16 px-2">
            <a href="<?= site_url('teacher/dashboard') ?>" class="flex flex-col items-center justify-center w-full text-blue-600 transition-colors">
                <svg class="w-6 h-6 mb-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><rect x="3" y="3" width="7" height="7"></rect><rect x="14" y="3" width="7" height="7"></rect><rect x="14" y="14" width="7" height="7"></rect><rect x="3" y="14" width="7" height="7"></rect></svg>
                <span class="text-[10px] font-medium">Home</span>
            </a>
            
            <a href="#" class="flex flex-col items-center justify-center w-full text-gray-500 hover:text-gray-900 transition-colors">
                <svg class="w-6 h-6 mb-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"></path></svg>
                <span class="text-[10px] font-medium">Classes</span>
            </a>

            <a href="#" class="flex flex-col items-center justify-center w-full text-gray-500 hover:text-gray-900 transition-colors">
                <svg class="w-6 h-6 mb-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>
                <span class="text-[10px] font-medium">Files</span>
            </a>
        </div>
    </nav>

    <!-- ================= MAIN CONTENT ================= -->
    <main class="flex-1 ml-0 md:ml-64 pb-20 md:pb-0 min-h-screen">
        
        <!-- Topbar -->
        <header class="bg-white h-16 flex items-center justify-between md:justify-end px-6 shadow-sm sticky top-0 z-40">
            <div class="md:hidden flex items-center">
                <img src="<?= base_url('assets/images/logo.png') ?>" alt="CSO Logo" class="h-8 w-auto">
            </div>
            
            <div class="flex items-center gap-3">
                <div class="text-right hidden sm:block">
                    <div class="text-sm font-bold text-gray-900"><?= $profile ? htmlspecialchars($profile->full_name) : 'Teacher' ?></div>
                    <div class="text-xs text-gray-500 font-medium">Instructor</div>
                </div>
                <div class="w-10 h-10 rounded-full bg-indigo-600 flex items-center justify-center text-white font-bold text-lg shadow-md ring-2 ring-white">
                    <?= $profile ? strtoupper(substr($profile->full_name, 0, 1)) : 'T' ?>
                </div>
            </div>
        </header>

        <div class="p-4 sm:p-6 lg:p-8 max-w-7xl mx-auto space-y-8">
            
            <!-- Welcome Banner -->
            <div class="bg-gradient-to-br from-indigo-700 to-blue-600 rounded-2xl p-6 sm:p-8 text-white shadow-lg relative overflow-hidden">
                <div class="absolute right-0 top-0 h-full w-1/2 opacity-10" style="background: url('data:image/svg+xml;utf8,<svg width=\'60\' height=\'60\' viewBox=\'0 0 60 60\' xmlns=\'http://www.w3.org/2000/svg\'><g fill=\'none\' fill-rule=\'evenodd\'><g fill=\'%23ffffff\' fill-opacity=\'1\'><path d=\'M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z\'/></g></g></svg>');"></div>
                
                <div class="relative z-10">
                    <h1 class="text-3xl sm:text-4xl font-bold mb-2">Welcome back, <?= htmlspecialchars($first_name) ?>!</h1>
                    <p class="text-indigo-100 text-lg max-w-xl">Manage your classes, upload teaching materials, and grade assignments from your portal.</p>
                </div>
            </div>

            <!-- Assigned Classes Section -->
            <section>
                <div class="flex justify-between items-end mb-4">
                    <h2 class="text-xl font-bold text-gray-900">My Assigned Classes</h2>
                </div>
                
                <?php if (!empty($assignments)): ?>
                    <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6">
                        <?php foreach ($assignments as $assignment): ?>
                            <div class="bg-white rounded-xl p-5 border border-gray-200 shadow-sm hover:shadow-md hover:border-indigo-200 transition-all group">
                                <div class="flex justify-between items-start mb-4">
                                    <div class="w-12 h-12 bg-indigo-50 text-indigo-600 rounded-lg flex items-center justify-center group-hover:bg-indigo-600 group-hover:text-white transition-colors">
                                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"></path></svg>
                                    </div>
                                    <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold bg-gray-100 text-gray-800 border border-gray-200">
                                        <?= htmlspecialchars($assignment->class_name) ?>
                                    </span>
                                </div>
                                <h3 class="font-bold text-lg text-gray-900 mb-1 leading-tight line-clamp-1"><?= htmlspecialchars($assignment->subject_name) ?></h3>
                                <p class="text-sm text-gray-500 mb-4">Subject Code: <?= htmlspecialchars($assignment->code) ?></p>
                                
                                <div class="pt-4 border-t border-gray-100 grid grid-cols-1 gap-2">
                                    <a href="<?= site_url('teacher/class_details/' . $assignment->assignment_id) ?>" class="text-center bg-gray-50 hover:bg-indigo-50 text-gray-700 hover:text-indigo-700 text-sm font-medium py-2 rounded-lg transition-colors border border-gray-200 hover:border-indigo-200">
                                        Open Course Hub
                                    </a>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                <?php else: ?>
                    <div class="bg-white rounded-2xl border-2 border-dashed border-gray-200 p-8 text-center sm:p-12">
                        <div class="w-16 h-16 bg-gray-50 rounded-full flex items-center justify-center mx-auto mb-4">
                            <svg class="h-8 w-8 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253" />
                            </svg>
                        </div>
                        <h3 class="text-lg font-bold text-gray-900 mb-1">No classes assigned</h3>
                        <p class="text-sm text-gray-500 max-w-sm mx-auto">The administrator has not assigned you to teach any classes yet. Please check back later.</p>
                    </div>
                <?php endif; ?>
            </section>
            
        </div>
    </main>

</body>
</html>
