<?php
if (!isset($_SESSION['user_id'])) {
    header("Location: ../login.php");
    exit();
}
require_once(__DIR__ . '/functions.php');
$currentUser = getUserById($_SESSION['user_id']);
$userEndorsements = getEmployeeEndorsements($_SESSION['user_id']);
$endorsementDisplay = formatEndorsements($userEndorsements);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes, viewport-fit=cover">
    <title>RxAero Portal – Employee Portal</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            -webkit-tap-highlight-color: transparent;
        }

        body {
            font-family: 'Georgia', 'Times New Roman', 'Segoe UI', serif;
            background: #f3ede8;
            color: #3e2c1f;
            line-height: 1.5;
            position: relative;
            overflow-x: hidden;
        }

        /* Vintage Airline Colors */
        :root {
            --vintage-burgundy: #6b1d2f;
            --vintage-gold: #c9a87c;
            --vintage-cream: #faf3e8;
            --vintage-dark: #2c1e12;
            --vintage-brass: #b58b3c;
        }

        /* ===== AVIATION ANIMATIONS ===== */

        /* 1. Moving paper plane in navbar */
        .plane-animation {
            position: absolute;
            left: -30px;
            top: 50%;
            transform: translateY(-50%);
            font-size: 1.4rem;
            animation: fly 12s linear infinite;
            pointer-events: none;
            opacity: 0.7;
            z-index: 10;
        }
        @keyframes fly {
            0% { left: -30px; }
            100% { left: 100%; }
        }

        /* 2. Floating clouds in background */
        .cloud {
            position: fixed;
            font-size: 5rem;
            opacity: 0.08;
            pointer-events: none;
            z-index: 0;
        }
        .cloud1 {
            top: 20%;
            left: -10%;
            animation: floatCloud 30s linear infinite;
        }
        .cloud2 {
            bottom: 10%;
            right: -10%;
            animation: floatCloud 40s linear infinite reverse;
        }
        @keyframes floatCloud {
            0% { transform: translateX(0); }
            100% { transform: translateX(20vw); }
        }

        /* 3. Propeller loading spinner */
        .propeller-loader {
            display: inline-block;
            width: 20px;
            height: 20px;
            background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%236b1d2f"><path d="M12 2L15 8H9L12 2zM12 22L9 16H15L12 22zM22 12L16 9V15L22 12zM2 12L8 9V15L2 12z"/></svg>') no-repeat center;
            background-size: contain;
            animation: spin 1s linear infinite;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* 4. Button hover lift effect */
        .btn {
            transition: transform 0.2s ease, box-shadow 0.2s, background 0.2s;
        }
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 12px rgba(0,0,0,0.1);
        }

        /* 5. Radar sweep effect for cards */
        .radar-sweep {
            position: relative;
            overflow: hidden;
        }
        .radar-sweep::after {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(201,168,124,0.2), transparent);
            animation: sweep 4s ease-in-out infinite;
            pointer-events: none;
        }
        @keyframes sweep {
            0% { left: -100%; }
            50% { left: 100%; }
            100% { left: 100%; }
        }

        /* Respect reduced motion preferences */
        @media (prefers-reduced-motion: reduce) {
            .plane-animation, .cloud, .radar-sweep::after, .btn {
                animation: none !important;
                transition: none !important;
            }
            .plane-animation {
                display: none;
            }
        }

        /* ===== REST OF THE EXISTING STYLES (unchanged) ===== */
        .navbar {
            background: linear-gradient(135deg, #5a1525 0%, #7a2035 100%);
            color: #f9e4c2;
            padding: 12px 16px;
            position: sticky;
            top: 0;
            z-index: 1000;
            border-bottom: 3px solid var(--vintage-gold);
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        }
        .navbar-container {
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 12px;
            position: relative;
        }
        .navbar-brand {
            font-size: 1.3rem;
            font-weight: 700;
            letter-spacing: 1px;
            font-family: 'Georgia', serif;
        }
        .navbar-brand a {
            color: #f9e4c2;
            text-decoration: none;
        }
        .navbar-brand span {
            color: var(--vintage-gold);
            font-style: italic;
        }
        .user-info-block {
            text-align: right;
            background: rgba(0,0,0,0.3);
            padding: 8px 14px;
            border-radius: 60px;
            backdrop-filter: blur(2px);
            min-width: 200px;
        }
        .user-name {
            font-size: 0.9rem;
            font-weight: bold;
            color: #f9e4c2;
            font-family: 'Georgia', serif;
        }
        .user-email {
            font-size: 0.7rem;
            color: #e2cfb3;
        }
        .user-phone {
            font-size: 1rem;
            font-weight: bold;
            color: #facc15;
            margin: 4px 0;
        }
        .user-endorsements {
            font-size: 0.7rem;
            color: var(--vintage-gold);
        }
        .logout-btn {
            display: inline-block;
            background: #a03e4b;
            color: white;
            padding: 10px 20px;
            border-radius: 50px;
            text-decoration: none;
            font-weight: bold;
            font-size: 0.9rem;
            margin-top: 6px;
            transition: background 0.2s;
            border: none;
            cursor: pointer;
            min-width: 90px;
            text-align: center;
        }
        .logout-btn:hover {
            background: #c0392b;
        }
        .container {
            max-width: 1280px;
            margin: 0 auto;
            padding: 16px;
        }
        .sidebar {
            background: var(--vintage-cream);
            border-radius: 20px;
            padding: 16px;
            margin-bottom: 20px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.05);
            border: 1px solid #e2cfb3;
        }
        .sidebar h3 {
            font-size: 1rem;
            margin-bottom: 12px;
            color: var(--vintage-burgundy);
            padding-bottom: 8px;
            border-bottom: 2px solid var(--vintage-gold);
            font-family: 'Georgia', serif;
        }
        .sidebar .btn {
            display: block;
            width: 100%;
            text-align: center;
            margin: 8px 0;
            padding: 12px;
            font-size: 0.9rem;
            border-radius: 40px;
            background: #ede3d4;
            color: var(--vintage-dark);
            text-decoration: none;
            border: 1px solid #d4bc9a;
        }
        .sidebar .btn:hover {
            background: #d4bc9a;
            color: #2c1e12;
            border-color: var(--vintage-brass);
        }
        .sidebar .btn.active {
            background: var(--vintage-burgundy);
            color: #f9e4c2;
            border-color: var(--vintage-gold);
        }
        .content {
            background: var(--vintage-cream);
            border-radius: 20px;
            padding: 20px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.05);
            border: 1px solid #e2cfb3;
            overflow-x: auto;
        }
        .card {
            background: white;
            border-radius: 16px;
            margin-bottom: 16px;
            padding: 16px;
            border: 1px solid #f0e2d0;
            box-shadow: 0 2px 6px rgba(0,0,0,0.03);
        }
        .btn-primary {
            background: var(--vintage-burgundy);
            color: #f9e4c2;
        }
        .btn-primary:hover {
            background: #8b2635;
        }
        .btn-success {
            background: #8b6b42;
            color: #faf3e8;
        }
        .btn-warning {
            background: var(--vintage-brass);
            color: #2c1e12;
        }
        .btn-danger {
            background: #a03e4b;
            color: white;
        }
        .btn-sm {
            padding: 6px 12px;
            font-size: 0.75rem;
        }
        input, select, textarea {
            width: 100%;
            padding: 12px 14px;
            font-size: 1rem;
            border: 1px solid #d4bc9a;
            border-radius: 12px;
            margin: 8px 0;
            background: white;
            font-family: inherit;
            transition: 0.2s;
        }
        input:focus, select:focus, textarea:focus {
            outline: none;
            border-color: var(--vintage-brass);
            box-shadow: 0 0 0 3px rgba(185, 139, 60, 0.2);
        }
        label {
            font-weight: 600;
            display: block;
            margin-top: 8px;
            font-size: 0.85rem;
            color: var(--vintage-dark);
        }
        .table-responsive {
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            min-width: 500px;
        }
        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #e2cfb3;
        }
        th {
            background: #f8efe5;
            font-weight: 600;
            color: var(--vintage-burgundy);
        }
        .alert {
            padding: 12px 16px;
            border-radius: 12px;
            margin-bottom: 16px;
            font-size: 0.85rem;
        }
        .alert-success {
            background: #e3d9cd;
            border-left: 4px solid #8b6b42;
            color: #2c1e12;
        }
        .alert-warning {
            background: #fae9d6;
            border-left: 4px solid var(--vintage-brass);
            color: #5c3e1a;
        }
        .alert-danger {
            background: #f2dbdb;
            border-left: 4px solid #a03e4b;
            color: #6b1d2f;
        }
        .badge {
            display: inline-block;
            padding: 4px 10px;
            border-radius: 50px;
            font-size: 0.7rem;
            font-weight: 600;
        }
        .badge-success {
            background: #8b6b42;
            color: #faf3e8;
        }
        .badge-warning {
            background: var(--vintage-brass);
            color: #2c1e12;
        }
        .badge-danger {
            background: #a03e4b;
            color: white;
        }
        .grid-2 {
            display: grid;
            grid-template-columns: 1fr;
            gap: 16px;
        }
        @media (min-width: 768px) {
            .grid-2 {
                grid-template-columns: 1fr 1fr;
            }
            .sidebar {
                width: 260px;
                float: left;
                margin-right: 20px;
                margin-bottom: 0;
            }
            .content {
                width: calc(100% - 280px);
                float: right;
            }
            .container {
                padding: 20px;
            }
        }
        @media (max-width: 640px) {
            .navbar-container {
                flex-direction: column;
                align-items: stretch;
                text-align: center;
            }
            .user-info-block {
                text-align: center;
            }
            .logout-btn {
                width: 100%;
                margin-top: 10px;
            }
        }
        .text-center { text-align: center; }
        .mt-2 { margin-top: 8px; }
        .mt-3 { margin-top: 16px; }
        .mb-2 { margin-bottom: 8px; }
        .mb-3 { margin-bottom: 16px; }
        .flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
    </style>
</head>
<body>

<!-- Floating clouds -->
<div class="cloud cloud1">☁️</div>
<div class="cloud cloud2">☁️</div>

<div class="navbar">
    <div class="navbar-container">
        <!-- Moving paper plane -->
        <div class="plane-animation">✈️</div>

        <div class="navbar-brand">
            <a href="<?php echo $_SESSION['role'] == 'admin' ? '../admin/dashboard.php' : '../employee/dashboard.php'; ?>">
                ✈️ <span>RxAero</span> Portal
            </a>
        </div>
        <div class="user-info-block">
            <div class="user-name"><?php echo htmlspecialchars($currentUser['full_name']); ?></div>
            <div class="user-email">📧 <?php echo htmlspecialchars($currentUser['email']); ?></div>
            <div class="user-phone">📱 <?php echo htmlspecialchars($currentUser['phone']); ?></div>
            <?php if(!empty($endorsementDisplay)): ?>
                <div class="user-endorsements">✈️ <?php echo $endorsementDisplay; ?></div>
            <?php endif; ?>
            <a href="../logout.php" class="logout-btn">🚪 Logout</a>
        </div>
    </div>
</div>
<div class="container">