<?php 
include('header.php');
include('../config.php');  // Include database connection from parent directory

// Function to write debug logs
function writeDebugLog($message) {
    $logFile = __DIR__ . '/backup_debug.log';
    $timestamp = date('Y-m-d H:i:s');
    file_put_contents($logFile, "[$timestamp] $message\n", FILE_APPEND);
}

// Check if user is logged in
if (!isset($_SESSION['username']) || empty($_SESSION['username'])) {
    writeDebugLog("ERROR: No username found in session");
    echo '<div class="cyber-notification error">
            <i class="fas fa-exclamation-circle"></i>
            <span>You must be logged in to create a backup!</span>
          </div>';
    exit;
}

$username = $_SESSION['username'];
writeDebugLog("User logged in as: " . $username);

// Check database connection
if (!isset($condb) || !$condb) {
    writeDebugLog("ERROR: Database connection not established");
    echo '<div class="cyber-notification error">
            <i class="fas fa-exclamation-circle"></i>
            <span>Database connection error!</span>
          </div>';
    exit;
}

writeDebugLog("Database connection established");
writeDebugLog("Database server info: " . mysqli_get_server_info($condb));

// Check if backup button was clicked
if (isset($_POST['create_backup'])) {
    writeDebugLog("Backup button clicked, starting backup process");
    
    // Create a temporary file in memory
    $tempFile = tempnam(sys_get_temp_dir(), 'backup_');
    writeDebugLog("Created temporary file: " . $tempFile);
    
    $zip = new ZipArchive();
    writeDebugLog("Initialized ZipArchive");

    if ($zip->open($tempFile, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) {
        writeDebugLog("Successfully opened zip file");
        
        // Check both possible upload directory locations
        $possibleDirs = [
            str_replace('/', '\\', __DIR__ . '\\..\\upload\\'),  // Go up one level from Panel to webpanel/upload
            'C:\\xampp\\htdocs\\webpanel\\upload\\'  // Absolute path
        ];
        
        $foundDir = null;
        foreach ($possibleDirs as $dir) {
            writeDebugLog("Checking directory: " . $dir);
            if (is_dir($dir)) {
                writeDebugLog("Found valid directory: " . $dir);
                $foundDir = $dir;
                break;
            }
        }
        
        if ($foundDir) {
            writeDebugLog("Using upload directory: " . $foundDir);
            writeDebugLog("Directory is readable: " . (is_readable($foundDir) ? 'Yes' : 'No'));
            
            // Get all HWID directories
            $hwidDirs = glob($foundDir . '*', GLOB_ONLYDIR);
            writeDebugLog("Found " . count($hwidDirs) . " HWID directories");
            
            $userLogsFound = false;
            
            // Get all logs for this user from database
            writeDebugLog("Current username before query: " . $username);
            $query = "SELECT DISTINCT hwid FROM logs WHERE username = ?";
            writeDebugLog("Preparing query with username: " . $username);
            $stmt = mysqli_prepare($condb, $query);
            
            if (!$stmt) {
                writeDebugLog("Database query preparation failed: " . mysqli_error($condb));
                echo '<div class="cyber-notification error">
                        <i class="fas fa-exclamation-circle"></i>
                        <span>Database error: ' . mysqli_error($condb) . '</span>
                      </div>';
                exit;
            }
            
            writeDebugLog("Binding parameter with username: " . $username);
            mysqli_stmt_bind_param($stmt, "s", $username);
            if (!mysqli_stmt_execute($stmt)) {
                writeDebugLog("Database query execution failed: " . mysqli_stmt_error($stmt));
                echo '<div class="cyber-notification error">
                        <i class="fas fa-exclamation-circle"></i>
                        <span>Database error: ' . mysqli_stmt_error($stmt) . '</span>
                      </div>';
                exit;
            }
            
            $result = mysqli_stmt_get_result($stmt);
            if (!$result) {
                writeDebugLog("Failed to get query result: " . mysqli_error($condb));
                echo '<div class="cyber-notification error">
                        <i class="fas fa-exclamation-circle"></i>
                        <span>Database error: ' . mysqli_error($condb) . '</span>
                      </div>';
                exit;
            }
            
            $userHwids = [];
            $numRows = mysqli_num_rows($result);
            writeDebugLog("Database query returned " . $numRows . " rows");
            
            while ($row = mysqli_fetch_assoc($result)) {
                $userHwids[] = $row['hwid'];
                writeDebugLog("Found HWID for user " . $username . ": " . $row['hwid']);
            }
            writeDebugLog("Found " . count($userHwids) . " HWIDs for user: " . $username);
            
            // Log all HWID directories found
            writeDebugLog("HWID directories found:");
            foreach ($hwidDirs as $dir) {
                writeDebugLog("- " . basename($dir));
            }
            
            foreach ($hwidDirs as $hwidDir) {
                writeDebugLog("Processing HWID directory: " . $hwidDir);
                $hwid = basename($hwidDir);
                writeDebugLog("Checking HWID: " . $hwid);
                writeDebugLog("Is HWID in user's list? " . (in_array($hwid, $userHwids) ? 'Yes' : 'No'));
                
                // Check if this HWID belongs to the user
                if (in_array($hwid, $userHwids)) {
                    writeDebugLog("Found matching HWID for user: " . $username);
                    
                    // Verify this HWID is actually associated with this username
                    $verifyQuery = "SELECT COUNT(*) as count FROM logs WHERE hwid = ? AND username = ?";
                    $verifyStmt = mysqli_prepare($condb, $verifyQuery);
                    mysqli_stmt_bind_param($verifyStmt, "ss", $hwid, $username);
                    mysqli_stmt_execute($verifyStmt);
                    $verifyResult = mysqli_stmt_get_result($verifyStmt);
                    $verifyRow = mysqli_fetch_assoc($verifyResult);
                    
                    if ($verifyRow['count'] > 0) {
                        writeDebugLog("Verified HWID " . $hwid . " belongs to user " . $username);
                        
                        // Look for zip file in the HWID directory
                        $zipFile = $hwidDir . '\\' . $hwid . '.zip';
                        writeDebugLog("Looking for zip file: " . $zipFile);
                        
                        if (file_exists($zipFile)) {
                            writeDebugLog("Found zip file, size: " . filesize($zipFile) . " bytes");
                            if ($zip->addFile($zipFile, $hwid . '.zip')) {
                                writeDebugLog("Successfully added zip file to backup");
                                $userLogsFound = true;
                            } else {
                                writeDebugLog("Failed to add zip file to backup");
                            }
                        } else {
                            writeDebugLog("Zip file not found: " . $zipFile);
                        }
                    } else {
                        writeDebugLog("HWID " . $hwid . " not verified for user " . $username);
                    }
                } else {
                    writeDebugLog("Skipping directory - HWID not matching user: " . $username);
                }
            }
            
            $zip->close();
            writeDebugLog("Closed zip file");

            if ($userLogsFound) {
                // Save the backup file to the backups directory
                $backupDir = __DIR__ . '/backups/';
                if (!file_exists($backupDir)) {
                    mkdir($backupDir, 0777, true);
                }
                
                $backupFileName = 'backup_' . $username . '_' . date('Y-m-d_H-i-s') . '.zip';
                $backupFilePath = $backupDir . $backupFileName;
                
                if (copy($tempFile, $backupFilePath)) {
                    writeDebugLog("Successfully saved backup to: " . $backupFilePath);
                    
                    // Clean up temporary file
                    unlink($tempFile);
                    writeDebugLog("Cleaned up temporary file");
                    
                    // Show success message and refresh
                    echo '<div class="cyber-notification success" id="success-message">
                            <i class="fas fa-check-circle"></i>
                            <span>Backup created successfully!</span>
                          </div>';
                    
                    echo '<script>
                        setTimeout(function() {
                            window.location.href = window.location.pathname;
                        }, 1500);
                    </script>';
                } else {
                    writeDebugLog("Failed to save backup file");
                    echo '<div class="cyber-notification error">
                            <i class="fas fa-exclamation-circle"></i>
                            <span>Failed to save backup file!</span>
                          </div>';
                }
            } else {
                writeDebugLog("No logs found for user: " . $username);
                echo '<div class="cyber-notification error">
                        <i class="fas fa-exclamation-circle"></i>
                        <span>No logs found for your account!</span>
                      </div>';
            }
        } else {
            writeDebugLog("ERROR: Could not find upload directory in any of the checked locations");
            echo '<div class="cyber-notification error">
                    <i class="fas fa-exclamation-circle"></i>
                    <span>Could not find upload directory!</span>
                  </div>';
        }
    } else {
        writeDebugLog("ERROR: Failed to open zip file");
        echo '<div class="cyber-notification error">
                <i class="fas fa-exclamation-circle"></i>
                <span>Failed to create backup!</span>
              </div>';
    }
}
?>

<div class="container-fluid">
<div class="row">
    <div class="col-md-12">
            <div class="cyber-panel">
                <div class="cyber-panel-header">
                    <h3><i class="fas fa-database"></i> System Backup</h3>
                </div>
                <div class="cyber-panel-body">
                    <div class="cyber-alert">
                        <i class="fas fa-info-circle"></i>
                        <span>Create and manage system backups</span>
                    </div>

                    <!-- Backup Status -->
                            <div class="cyber-status-card">
                        <div class="cyber-status-header">
                            <i class="fas fa-server"></i>
                            <span>Backup Status</span>
                                </div>
                        <div class="cyber-status-content">
<?php
                            $backupDir = 'backups/';
                            if (!file_exists($backupDir)) {
                                mkdir($backupDir, 0777, true);
                            }
                            
                            $lastBackup = '';
                            $backupSize = '0 GB';
                            $backupStatus = 'No backups found';
                            $totalLogs = 0;
                            $totalBackups = 0;
                            $lastError = 'None';
                            
                            // Get all backup files for this user
                            $files = glob($backupDir . 'backup_' . $username . '_*.zip');
                                    if (!empty($files)) {
                                $lastBackupFile = end($files);
                                $lastBackup = date('Y-m-d H:i:s', filemtime($lastBackupFile));
                                $backupSize = round(filesize($lastBackupFile) / (1024 * 1024 * 1024), 2) . ' GB';
                                $backupStatus = 'Completed';
                                $totalBackups = count($files);
                                
                                // Count zip files in the backup
                                $zip = new ZipArchive();
                                if ($zip->open($lastBackupFile) === TRUE) {
                                    $totalLogs = $zip->numFiles;
                                    $zip->close();
                                    } else {
                                    $lastError = 'Failed to read last backup';
                                }
                            }
                            ?>
                            <div class="cyber-status-item">
                                <span class="cyber-status-label">Last Backup</span>
                                <span class="cyber-status-value"><?php echo $lastBackup; ?></span>
                            </div>
                            <div class="cyber-status-item">
                                <span class="cyber-status-label">Backup Size</span>
                                <span class="cyber-status-value"><?php echo $backupSize; ?></span>
                                </div>
                            <div class="cyber-status-item">
                                <span class="cyber-status-label">Logs</span>
                                <span class="cyber-status-value"><?php echo $totalLogs; ?></span>
                            </div>
                            <div class="cyber-status-item">
                                <span class="cyber-status-label">Status</span>
                                <span class="cyber-status-value success"><?php echo $backupStatus; ?></span>
                                </div>
                            <div class="cyber-status-item">
                                <span class="cyber-status-label">Total Backups</span>
                                <span class="cyber-status-value info"><?php echo $totalBackups; ?></span>
                                </div>
                            <div class="cyber-status-item">
                                <span class="cyber-status-label">Last Error</span>
                                <span class="cyber-status-value <?php echo $lastError === 'None' ? 'success' : 'error'; ?>"><?php echo $lastError; ?></span>
                            </div>
                        </div>
                    </div>

                    <!-- Backup Actions -->
                    <div class="cyber-actions">
                        <form method="post" style="display: inline;" onsubmit="showLoading()">
                            <button type="submit" name="create_backup" class="cyber-button primary">
                                <i class="fas fa-plus"></i>
                                <span>Download All Logs</span>
                            </button>
                        </form>
                    </div>

                    <!-- Loading Screen -->
                    <div id="loading-screen" class="cyber-loading-screen" style="display: none;">
                        <div class="cyber-loading-content">
                            <div class="cyber-loading-spinner"></div>
                            <div class="cyber-loading-text">Creating Backup...</div>
                        </div>
                    </div>

                    <?php
                    if(isset($_GET['download']) && isset($_SESSION['download_backup'])) {
                        $filename = $_SESSION['download_backup'];
                        $filepath = $backupDir . $filename;
                        
                        if(file_exists($filepath)) {
                            header('Content-Type: application/zip');
                            header('Content-Disposition: attachment; filename="'.$filename.'"');
                            header('Content-Length: ' . filesize($filepath));
                            readfile($filepath);
                            
                            // Clear the session variable
                            unset($_SESSION['download_backup']);
                            
                            // Redirect back to the page
                            header('Location: ' . $_SERVER['PHP_SELF']);
                            exit();
                        }
                    }

                    if(isset($_POST['delete_backup'])) {
                        $fileName = $_POST['delete_backup'];
                        $filePath = $backupDir . $fileName;
                        if(file_exists($filePath) && unlink($filePath)) {
                            echo '<div class="cyber-notification success">
                                    <i class="fas fa-check-circle"></i>
                                    <span>Backup deleted successfully!</span>
                                  </div>';
} else {
                            echo '<div class="cyber-notification error">
                                    <i class="fas fa-exclamation-circle"></i>
                                    <span>Failed to delete backup!</span>
                                  </div>';
                        }
                    }
                    ?>

                    <!-- Backup History -->
                                <div class="cyber-table-wrapper">
                                    <table class="cyber-table">
                                        <thead>
                                            <tr>
                                    <th width="10%"><i class="fas fa-hashtag"></i> ID</th>
                                    <th width="20%"><i class="fas fa-calendar"></i> Date</th>
                                    <th width="15%"><i class="fas fa-hdd"></i> Size</th>
                                    <th width="15%"><i class="fas fa-file-archive"></i> Logs</th>
                                    <th width="15%"><i class="fas fa-info-circle"></i> Status</th>
                                    <th width="25%"><i class="fas fa-cog"></i> Actions</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                // Only get backup files for the current user
                                $files = glob($backupDir . 'backup_' . $username . '_*.zip');
                                            rsort($files);
                                foreach($files as $index => $file) {
                                                $fileName = basename($file);
                                                $fileTime = date('Y-m-d H:i:s', filemtime($file));
                                    $fileSize = round(filesize($file) / (1024 * 1024 * 1024), 2) . ' GB';
                                    
                                    // Count zip files in the backup
                                    $totalLogs = 0;
                                    $zip = new ZipArchive();
                                    if ($zip->open($file) === TRUE) {
                                        $totalLogs = $zip->numFiles;
                                        $zip->close();
                                    }
                                    
                                    echo "<tr>
                                            <td>" . ($index + 1) . "</td>
                                            <td>{$fileTime}</td>
                                            <td>{$fileSize}</td>
                                            <td>{$totalLogs}</td>
                                            <td><span class='cyber-status-value success'>Completed</span></td>
                                            <td>
                                                <a href='{$backupDir}{$fileName}' class='cyber-button'>
                                                    <i class='fas fa-download'></i>
                                                            <span>Download</span>
                                                        </a>
                                                <form method='post' style='display: inline;' onsubmit='return confirm(\"Are you sure you want to delete this backup?\");'>
                                                    <input type='hidden' name='delete_backup' value='{$fileName}'>
                                                    <button type='submit' class='cyber-button danger'>
                                                        <i class='fas fa-trash'></i>
                                                        <span>Delete</span>
                                                    </button>
                                                </form>
                                            </td>
                                        </tr>";
                                            }
                                            ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
             </div>
    </div>
</div>

<style>
/* Import cyberpunk font */
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;600;700&display=swap');

/* Base styles */
html, body {
    background: #0a0a0f !important;
    color: #ffffff;
    margin: 0;
    padding: 0;
    height: 100%;
    min-height: 100vh;
}

/* Container positioning */
.container-fluid {
    background: linear-gradient(180deg, #0a0a0f 0%, #12151C 100%);
    min-height: 100vh;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.row {
    width: 100%;
    max-width: 1200px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    padding: 0;
}

.col-md-12 {
    width: 100%;
    padding: 0 15px;
}

/* Panel Styling */
.cyber-panel {
    background: linear-gradient(165deg, #12151C 0%, #0a0a0f 100%);
    border: 1px solid rgba(0, 157, 255, 0.3);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 157, 255, 0.15);
    overflow: hidden;
    position: relative;
    margin: 0 auto 2rem auto;
    width: 100%;
    backdrop-filter: blur(10px);
}

.cyber-panel-header {
    background: linear-gradient(90deg, #0d1117 0%, #161b22 100%);
    padding: 25px;
    border-bottom: 1px solid rgba(0, 157, 255, 0.3);
    position: relative;
}

.cyber-panel-header h3 {
    color: #00b3ff;
    font-family: 'Orbitron', sans-serif;
    font-size: 22px;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 15px;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 0 0 15px rgba(0, 157, 255, 0.5);
}

.cyber-panel-header h3 i {
    font-size: 24px;
    color: #00b3ff;
}

.cyber-panel-body {
    padding: 25px;
    background: transparent;
}

/* Alert Styling */
.cyber-alert {
    background: rgba(33, 150, 243, 0.05);
    border: 1px solid rgba(33, 150, 243, 0.3);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 30px;
    display: flex;
    align-items: center;
    gap: 15px;
    color: #2196F3;
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.05);
}

/* Status Card Styling */
.cyber-status-card {
    background: rgba(0, 157, 255, 0.03);
    border: 1px solid rgba(0, 157, 255, 0.2);
    border-radius: 12px;
    margin-bottom: 30px;
    overflow: hidden;
    width: 100%;
    box-shadow: 0 4px 24px rgba(0, 157, 255, 0.1);
}

.cyber-status-header {
    background: rgba(0, 157, 255, 0.08);
    padding: 20px 25px;
    border-bottom: 1px solid rgba(0, 157, 255, 0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    color: #00b3ff;
    font-family: 'Orbitron', sans-serif;
    font-size: 18px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.cyber-status-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 25px;
    padding: 25px;
    background: rgba(0, 157, 255, 0.02);
}

.cyber-status-item {
    background: rgba(0, 157, 255, 0.04);
    border: 1px solid rgba(0, 157, 255, 0.15);
    border-radius: 10px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all 0.3s ease;
}

.cyber-status-item:hover {
    background: rgba(0, 157, 255, 0.06);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 157, 255, 0.15);
}

.cyber-status-label {
    color: rgba(255, 255, 255, 0.7);
    font-family: 'Orbitron', sans-serif;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 500;
}

.cyber-status-value {
    color: #00b3ff;
    font-family: 'Orbitron', sans-serif;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.cyber-status-value.info {
    color: #00b3ff;
    text-shadow: 0 0 10px rgba(0, 157, 255, 0.5);
}

.cyber-status-value.success {
    color: #00ff9d;
    text-shadow: 0 0 10px rgba(0, 255, 157, 0.5);
}

.cyber-status-value.warning {
    color: #ffb300;
    text-shadow: 0 0 10px rgba(255, 179, 0, 0.5);
}

.cyber-status-value.error {
    color: #ff2d55;
    text-shadow: 0 0 10px rgba(255, 45, 85, 0.5);
}

/* Button Styling */
.cyber-button {
    background: transparent;
    border: 1.5px solid #00b3ff;
    border-radius: 8px;
    color: #00b3ff;
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    padding: 12px 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    white-space: nowrap;
    text-decoration: none;
    position: relative;
    overflow: hidden;
}

.cyber-button::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120%;
    height: 120%;
    background: rgba(0, 157, 255, 0.1);
    transform: translate(-50%, -50%) scale(0);
    border-radius: 50%;
    transition: transform 0.5s ease;
}

.cyber-button:hover::after {
    transform: translate(-50%, -50%) scale(1);
}

.cyber-button.primary {
    background: #00b3ff;
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(0, 157, 255, 0.3);
}

.cyber-button.danger {
    border-color: #ff2d55;
    color: #ff2d55;
}

.cyber-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 157, 255, 0.2);
}

.cyber-actions {
    display: flex;
    gap: 15px;
    margin: 30px 0;
    flex-wrap: wrap;
    justify-content: flex-start;
}

/* Table Styling */
.cyber-table-wrapper {
    overflow-x: auto;
    margin: 0 -25px;
    padding: 0 25px;
    width: calc(100% + 50px);
    background: rgba(0, 157, 255, 0.02);
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 157, 255, 0.05);
}

.cyber-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 800px;
    margin: 0;
}

.cyber-table th {
    background: rgba(0, 157, 255, 0.08);
    color: #00b3ff;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    white-space: nowrap;
    border-bottom: 2px solid rgba(0, 157, 255, 0.2);
}

.cyber-table th i {
    color: #00b3ff;
}

.cyber-table tbody tr:hover {
    background: rgba(0, 157, 255, 0.05);
    box-shadow: 0 4px 20px rgba(0, 157, 255, 0.1);
}

.cyber-table td {
    vertical-align: middle;
    color: #ffffff;
}

.cyber-table td .cyber-button {
    margin: 3px;
    padding: 10px 20px;
    font-size: 13px;
}

.cyber-table td form {
    display: inline-block;
    margin: 3px;
}

/* Loading Screen Styles */
.cyber-loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 15, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(10px);
}

.cyber-loading-content {
    text-align: center;
    padding: 30px;
    background: rgba(0, 157, 255, 0.05);
    border-radius: 15px;
    border: 1px solid rgba(0, 157, 255, 0.2);
    box-shadow: 0 8px 32px rgba(0, 157, 255, 0.1);
}

.cyber-loading-spinner {
    width: 70px;
    height: 70px;
    border: 4px solid rgba(0, 157, 255, 0.1);
    border-left-color: #00b3ff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 25px;
}

.cyber-loading-text {
    color: #00b3ff;
    font-family: 'Orbitron', sans-serif;
    font-size: 20px;
    text-transform: uppercase;
    letter-spacing: 2px;
    animation: pulse 1.5s ease-in-out infinite;
    text-shadow: 0 0 15px rgba(0, 157, 255, 0.5);
}

/* Notification Styling */
.cyber-notification {
    position: fixed;
    top: 25px;
    right: 25px;
    padding: 20px 30px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 15px;
    font-family: 'Orbitron', sans-serif;
    z-index: 1000;
    animation: slideIn 0.3s ease-out;
    background: rgba(0, 157, 255, 0.1);
    border: 1px solid rgba(0, 157, 255, 0.3);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 157, 255, 0.2);
}

.cyber-notification.success {
    background: rgba(0, 255, 157, 0.1);
    border: 1px solid rgba(0, 255, 157, 0.3);
    color: #00ff9d;
}

.cyber-notification.error {
    background: rgba(255, 45, 85, 0.1);
    border: 1px solid rgba(255, 45, 85, 0.3);
    color: #ff2d55;
}

/* Animations */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes pulse {
    0% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
    100% {
        opacity: 0.6;
    }
}

/* Responsive Styles */
@media (max-width: 768px) {
    .container-fluid {
        padding: 1rem;
    }
    
    .cyber-panel-header {
        padding: 20px;
    }
    
    .cyber-panel-header h3 {
        font-size: 18px;
    }
    
    .cyber-panel-body {
        padding: 20px;
    }
    
    .cyber-status-content {
        grid-template-columns: 1fr;
        padding: 20px;
        gap: 20px;
    }
    
    .cyber-status-item {
        padding: 15px;
    }
    
    .cyber-status-label {
        font-size: 12px;
    }
    
    .cyber-status-value {
        font-size: 16px;
    }
    
    .cyber-table th,
    .cyber-table td {
        padding: 15px;
        font-size: 13px;
    }
    
    .cyber-table td:last-child {
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 15px;
    }
    
    .cyber-table td:last-child .cyber-button,
    .cyber-table td:last-child form {
        width: 100%;
        margin: 0;
    }
    
    .cyber-table td:last-child .cyber-button {
        justify-content: center;
    }
    
    .cyber-loading-spinner {
        width: 50px;
        height: 50px;
    }
    
    .cyber-loading-text {
        font-size: 16px;
    }
}
</style>

<script>
function showLoading() {
    document.getElementById('loading-screen').style.display = 'flex';
    document.getElementById('loading-text').textContent = 'Creating Backup...';
}

// Add event listener for page load
window.addEventListener('load', function() {
    // Hide loading screen if it's visible
    document.getElementById('loading-screen').style.display = 'none';
});

// Add event listener for before unload
window.addEventListener('beforeunload', function() {
    if (document.getElementById('loading-screen').style.display === 'flex') {
        document.getElementById('loading-text').textContent = 'Refreshing...';
    }
});
</script>

<?php include('footer.php'); ?>
