<?php
$title = 'ICT Asset Details';
$active = 'ict';
require_once __DIR__ . '/../layouts/header.php';
require_once __DIR__ . '/../layouts/sidebar.php';

// Initialize $today variable
$today = time();
?>

<div class="container-fluid">
    <!-- Page Header -->
    <div class="page-header">
        <div class="header-content">
            <h1>
                <i class="fas fa-eye"></i>
                ICT Asset Details
            </h1>
            <p><?php echo Security::escape($asset['asset_description'] ?? 'N/A'); ?> - <?php echo Security::escape($asset['asset_code'] ?? 'N/A'); ?></p>
        </div>
        <div class="header-actions">
            <a href="<?php echo BASE_URL; ?>/ict" class="btn btn-secondary">
                <i class="fas fa-arrow-left"></i> Back to ICT Assets
            </a>
            <?php if (Auth::can('ict.edit')): ?>
            <a href="<?php echo BASE_URL; ?>/ict/edit/<?php echo $asset['id']; ?>" class="btn btn-success">
                <i class="fas fa-edit"></i> Edit Asset
            </a>
            <?php endif; ?>
            <button class="btn btn-outline" onclick="window.print()">
                <i class="fas fa-print"></i> Print
            </button>
        </div>
    </div>
    
    <!-- Success Message Display -->
<?php
$successMessage = Session::get('success', '');
if (!empty($successMessage)):
?>
<div class="alert alert-success alert-dismissible fade show" role="alert" id="successAlert">
    <i class="fas fa-check-circle"></i>
    <?php echo Security::escape($successMessage); ?>
    <button type="button" class="btn-close" onclick="this.parentElement.style.display='none'">&times;</button>
</div>
<?php 
    Session::remove('success');
endif; 
?>

<?php
$errorMessage = Session::get('error', '');
if (!empty($errorMessage)):
?>
<div class="alert alert-danger alert-dismissible fade show" role="alert" id="errorAlert">
    <i class="fas fa-exclamation-circle"></i>
    <?php echo Security::escape($errorMessage); ?>
    <button type="button" class="btn-close" onclick="this.parentElement.style.display='none'">&times;</button>
</div>
<?php 
    Session::remove('error');
endif; 
?>

    <!-- Status Alerts -->
    <?php
    if (!empty($asset['warranty_expiry'])) {
        $warrantyExpiry = strtotime($asset['warranty_expiry']);
        $daysToExpiry = round(($warrantyExpiry - $today) / (60 * 60 * 24));
        
        if ($daysToExpiry <= 30 && $daysToExpiry >= 0):
    ?>
    <div class="status-banner status-warning">
        <div class="status-icon">
            <i class="fas fa-shield-alt"></i>
        </div>
        <div class="status-content">
            <h3>Warranty Expiring Soon</h3>
            <p>Warranty expires in <?php echo $daysToExpiry; ?> days (<?php echo date('d/m/Y', strtotime($asset['warranty_expiry'])); ?>)</p>
        </div>
    </div>
    <?php 
        elseif ($daysToExpiry < 0):
    ?>
    <div class="status-banner status-danger">
        <div class="status-icon">
            <i class="fas fa-exclamation-circle"></i>
        </div>
        <div class="status-content">
            <h3>Warranty Expired</h3>
            <p>Warranty expired on <?php echo date('d/m/Y', strtotime($asset['warranty_expiry'])); ?></p>
        </div>
    </div>
    <?php 
        endif;
    }
    
    if (!empty($asset['license_expiry'])):
        $licenseExpiry = strtotime($asset['license_expiry']);
        $daysToLicense = round(($licenseExpiry - $today) / (60 * 60 * 24));
        
        if ($daysToLicense <= 30 && $daysToLicense >= 0):
    ?>
    <div class="status-banner status-warning">
        <div class="status-icon">
            <i class="fas fa-key"></i>
        </div>
        <div class="status-content">
            <h3>License Expiring Soon</h3>
            <p>Software license expires in <?php echo $daysToLicense; ?> days (<?php echo date('d/m/Y', strtotime($asset['license_expiry'])); ?>)</p>
        </div>
    </div>
    <?php 
        elseif ($daysToLicense < 0):
    ?>
    <div class="status-banner status-danger">
        <div class="status-icon">
            <i class="fas fa-exclamation-circle"></i>
        </div>
        <div class="status-content">
            <h3>License Expired</h3>
            <p>Software license expired on <?php echo date('d/m/Y', strtotime($asset['license_expiry'])); ?></p>
        </div>
    </div>
    <?php 
        endif;
    endif;
    
    if (!empty($asset['next_service_date'])):
        $serviceDate = strtotime($asset['next_service_date']);
        $daysToService = round(($serviceDate - $today) / (60 * 60 * 24));
        
        if ($daysToService <= 7 && $daysToService >= 0):
    ?>
    <div class="status-banner status-warning">
        <div class="status-icon">
            <i class="fas fa-tools"></i>
        </div>
        <div class="status-content">
            <h3>Maintenance Due Soon</h3>
            <p>Maintenance is due in <?php echo $daysToService; ?> days (<?php echo date('d/m/Y', strtotime($asset['next_service_date'])); ?>)</p>
        </div>
    </div>
    <?php 
        elseif ($daysToService < 0):
    ?>
    <div class="status-banner status-danger">
        <div class="status-icon">
            <i class="fas fa-exclamation-circle"></i>
        </div>
        <div class="status-content">
            <h3>Maintenance Overdue</h3>
            <p>Maintenance was due on <?php echo date('d/m/Y', strtotime($asset['next_service_date'])); ?></p>
        </div>
    </div>
    <?php 
        endif;
    endif;
    ?>

    <!-- Asset Information Grid -->
    <div class="asset-details-grid">
        <!-- Basic Information Card -->
        <div class="detail-card">
            <div class="card-header">
                <h3><i class="fas fa-info-circle"></i> Basic Information</h3>
            </div>
            <div class="card-body">
                <div class="detail-row">
                    <div class="detail-label">Asset Code:</div>
                    <div class="detail-value">
                        <span class="asset-code"><?php echo Security::escape($asset['asset_code'] ?? 'N/A'); ?></span>
                    </div>
                </div>
                <div class="detail-row">
                    <div class="detail-label">Description:</div>
                    <div class="detail-value"><?php echo Security::escape($asset['asset_description'] ?? 'N/A'); ?></div>
                </div>
                <div class="detail-row">
                    <div class="detail-label">Category:</div>
                    <div class="detail-value">
                        <?php 
                        $categoryClass = '';
                        $category = $asset['asset_category'] ?? '';
                        if ($category == 'Hardware') $categoryClass = 'badge-hardware';
                        elseif ($category == 'Software') $categoryClass = 'badge-software';
                        elseif ($category == 'Network') $categoryClass = 'badge-network';
                        elseif ($category == 'Server') $categoryClass = 'badge-server';
                        else $categoryClass = 'badge-peripheral';
                        ?>
                        <span class="badge <?php echo $categoryClass; ?>">
                            <?php echo Security::escape($category ?: 'N/A'); ?>
                        </span>
                    </div>
                </div>
                <div class="detail-row">
                    <div class="detail-label">Manufacturer:</div>
                    <div class="detail-value"><?php echo Security::escape($asset['manufacturer'] ?? 'N/A'); ?></div>
                </div>
                <div class="detail-row">
                    <div class="detail-label">Model/Version:</div>
                    <div class="detail-value"><?php echo Security::escape($asset['model_version'] ?? 'N/A'); ?></div>
                </div>
                <div class="detail-row">
                    <div class="detail-label">Serial Number:</div>
                    <div class="detail-value">
                        <?php if (!empty($asset['serial_number'])): ?>
                            <span class="serial-number"><?php echo Security::escape($asset['serial_number']); ?></span>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>

        <!-- Technical Details Card -->
        <div class="detail-card">
            <div class="card-header">
                <h3><i class="fas fa-microchip"></i> Technical Details</h3>
            </div>
            <div class="card-body">
                <?php if (!empty($asset['ip_address'])): ?>
                <div class="detail-row">
                    <div class="detail-label">IP Address:</div>
                    <div class="detail-value">
                        <code><?php echo Security::escape($asset['ip_address']); ?></code>
                    </div>
                </div>
                <?php endif; ?>
                
                <?php if (!empty($asset['mac_address'])): ?>
                <div class="detail-row">
                    <div class="detail-label">MAC Address:</div>
                    <div class="detail-value">
                        <code><?php echo Security::escape($asset['mac_address']); ?></code>
                    </div>
                </div>
                <?php endif; ?>
                
                <?php if (!empty($asset['operating_system'])): ?>
                <div class="detail-row">
                    <div class="detail-label">OS:</div>
                    <div class="detail-value"><?php echo Security::escape($asset['operating_system']); ?></div>
                </div>
                <?php endif; ?>
                
                <?php if (!empty($asset['software_license'])): ?>
                <div class="detail-row">
                    <div class="detail-label">License:</div>
                    <div class="detail-value">
                        <code><?php echo Security::escape($asset['software_license']); ?></code>
                    </div>
                </div>
                <?php endif; ?>
                
                <?php if (!empty($asset['license_expiry'])): ?>
                <div class="detail-row">
                    <div class="detail-label">License Expiry:</div>
                    <div class="detail-value">
                        <?php echo date('d/m/Y', strtotime($asset['license_expiry'])); ?>
                        <?php
                        $licenseExpiry = strtotime($asset['license_expiry']);
                        $daysToLicense = round(($licenseExpiry - $today) / (60 * 60 * 24));
                        if ($daysToLicense <= 30 && $daysToLicense >= 0) {
                            echo '<span class="days-remaining warning">(' . $daysToLicense . ' days)</span>';
                        } elseif ($daysToLicense < 0) {
                            echo '<span class="days-remaining expired">(Expired)</span>';
                        }
                        ?>
                    </div>
                </div>
                <?php endif; ?>
            </div>
        </div>

        <!-- Location Card -->
        <div class="detail-card">
            <div class="card-header">
                <h3><i class="fas fa-map-marker-alt"></i> Location</h3>
            </div>
            <div class="card-body">
                <div class="detail-row">
                    <div class="detail-label">State:</div>
                    <div class="detail-value"><?php echo Security::escape($asset['state_name'] ?? 'N/A'); ?></div>
                </div>
                <div class="detail-row">
                    <div class="detail-label">LGA:</div>
                    <div class="detail-value"><?php echo Security::escape($asset['lga_name'] ?? 'N/A'); ?></div>
                </div>
                <div class="detail-row">
                    <div class="detail-label">Zone:</div>
                    <div class="detail-value"><?php echo Security::escape($asset['zone_name'] ?? 'N/A'); ?></div>
                </div>
                <div class="detail-row">
                    <div class="detail-label">Command:</div>
                    <div class="detail-value"><?php echo Security::escape($asset['command_name'] ?? 'N/A'); ?></div>
                </div>
                <?php if (!empty($asset['location'])): ?>
                <div class="detail-row">
                    <div class="detail-label">Specific Location:</div>
                    <div class="detail-value"><?php echo Security::escape($asset['location']); ?></div>
                </div>
                <?php endif; ?>
                <?php if (!empty($asset['responsible_officer'])): ?>
                <div class="detail-row">
                    <div class="detail-label">Responsible Officer:</div>
                    <div class="detail-value"><?php echo Security::escape($asset['responsible_officer']); ?></div>
                </div>
                <?php endif; ?>
            </div>
        </div>

        <!-- Acquisition Card -->
        <div class="detail-card">
            <div class="card-header">
                <h3><i class="fas fa-file-invoice-dollar"></i> Acquisition Details</h3>
            </div>
            <div class="card-body">
                <div class="detail-row">
                    <div class="detail-label">Purchase Date:</div>
                    <div class="detail-value"><?php echo !empty($asset['purchase_date']) ? date('d/m/Y', strtotime($asset['purchase_date'])) : 'N/A'; ?></div>
                </div>
                <div class="detail-row">
                    <div class="detail-label">Purchase Value:</div>
                    <div class="detail-value highlight">₦<?php echo number_format($asset['purchase_value'] ?? 0, 2); ?></div>
                </div>
                <?php if (!empty($asset['current_value'])): ?>
                <div class="detail-row">
                    <div class="detail-label">Current Value:</div>
                    <div class="detail-value">₦<?php echo number_format($asset['current_value'], 2); ?></div>
                </div>
                <?php endif; ?>
                <div class="detail-row">
                    <div class="detail-label">Ownership:</div>
                    <div class="detail-value"><?php echo Security::escape($asset['ownership_type'] ?? 'FGN'); ?></div>
                </div>
            </div>
        </div>

        <!-- Warranty Card -->
        <div class="detail-card">
            <div class="card-header">
                <h3><i class="fas fa-shield-alt"></i> Warranty & Maintenance</h3>
            </div>
            <div class="card-body">
                <?php if (!empty($asset['warranty_period'])): ?>
                <div class="detail-row">
                    <div class="detail-label">Warranty Period:</div>
                    <div class="detail-value"><?php echo Security::escape($asset['warranty_period']); ?></div>
                </div>
                <?php endif; ?>
                
                <?php if (!empty($asset['warranty_expiry'])): ?>
                <div class="detail-row">
                    <div class="detail-label">Warranty Expiry:</div>
                    <div class="detail-value">
                        <?php echo date('d/m/Y', strtotime($asset['warranty_expiry'])); ?>
                        <?php
                        $warrantyExpiry = strtotime($asset['warranty_expiry']);
                        $daysToWarranty = round(($warrantyExpiry - $today) / (60 * 60 * 24));
                        if ($daysToWarranty <= 30 && $daysToWarranty >= 0) {
                            echo '<span class="days-remaining warning">(' . $daysToWarranty . ' days)</span>';
                        } elseif ($daysToWarranty < 0) {
                            echo '<span class="days-remaining expired">(Expired)</span>';
                        }
                        ?>
                    </div>
                </div>
                <?php endif; ?>
                
                <?php if (!empty($asset['maintenance_provider'])): ?>
                <div class="detail-row">
                    <div class="detail-label">Maintenance:</div>
                    <div class="detail-value"><?php echo Security::escape($asset['maintenance_provider']); ?></div>
                </div>
                <?php endif; ?>
                
                <?php if (!empty($asset['last_service_date'])): ?>
                <div class="detail-row">
                    <div class="detail-label">Last Service:</div>
                    <div class="detail-value"><?php echo date('d/m/Y', strtotime($asset['last_service_date'])); ?></div>
                </div>
                <?php endif; ?>
                
                <?php if (!empty($asset['next_service_date'])): ?>
                <div class="detail-row">
                    <div class="detail-label">Next Service:</div>
                    <div class="detail-value">
                        <?php echo date('d/m/Y', strtotime($asset['next_service_date'])); ?>
                        <?php
                        $nextService = strtotime($asset['next_service_date']);
                        $daysToService = round(($nextService - $today) / (60 * 60 * 24));
                        if ($daysToService <= 7 && $daysToService >= 0) {
                            echo '<span class="days-remaining warning">(' . $daysToService . ' days)</span>';
                        } elseif ($daysToService < 0) {
                            echo '<span class="days-remaining expired">(Overdue)</span>';
                        }
                        ?>
                    </div>
                </div>
                <?php endif; ?>
            </div>
        </div>

        <!-- Status Card -->
        <div class="detail-card">
            <div class="card-header">
                <h3><i class="fas fa-clipboard-check"></i> Status</h3>
            </div>
            <div class="card-body">
                <div class="detail-row">
                    <div class="detail-label">Current Status:</div>
                    <div class="detail-value">
                        <?php 
                        $statusClass = '';
                        $status = $asset['current_status'] ?? '';
                        if ($status == 'In Use') $statusClass = 'status-active';
                        elseif ($status == 'Available') $statusClass = 'status-available';
                        elseif ($status == 'Under Repair') $statusClass = 'status-warning';
                        elseif ($status == 'Decommissioned') $statusClass = 'status-rejected';
                        ?>
                        <span class="status-badge <?php echo $statusClass; ?>">
                            <?php echo Security::escape($status ?: 'Not Set'); ?>
                        </span>
                    </div>
                </div>
            </div>
        </div>

        <!-- Remarks Card -->
        <?php if (!empty($asset['remarks'])): ?>
        <div class="detail-card full-width">
            <div class="card-header">
                <h3><i class="fas fa-sticky-note"></i> Remarks</h3>
            </div>
            <div class="card-body">
                <p class="remarks-text"><?php echo nl2br(Security::escape($asset['remarks'])); ?></p>
            </div>
        </div>
        <?php endif; ?>

        <!-- Documents Card -->
        <?php if (!empty($documents)): ?>
        <div class="detail-card full-width">
            <div class="card-header">
                <h3><i class="fas fa-file-alt"></i> Attached Documents</h3>
            </div>
            <div class="card-body">
                <div class="documents-grid">
                    <?php foreach ($documents as $doc): ?>
                    <div class="document-item">
                        <div class="document-icon">
                            <?php
                            $ext = pathinfo($doc['file_name'], PATHINFO_EXTENSION);
                            $icon = 'fa-file';
                            if (in_array($ext, ['pdf'])) $icon = 'fa-file-pdf';
                            elseif (in_array($ext, ['jpg', 'jpeg', 'png'])) $icon = 'fa-file-image';
                            elseif (in_array($ext, ['doc', 'docx'])) $icon = 'fa-file-word';
                            elseif (in_array($ext, ['xls', 'xlsx'])) $icon = 'fa-file-excel';
                            ?>
                            <i class="fas <?php echo $icon; ?>"></i>
                        </div>
                        <div class="document-info">
                            <h4><?php echo Security::escape($doc['file_name']); ?></h4>
                            <p>
                                <span class="file-size"><?php echo round($doc['file_size'] / 1024, 2); ?> KB</span>
                                <span class="upload-date">Uploaded: <?php echo date('d/m/Y', strtotime($doc['created_at'] ?? $doc['uploaded_at'] ?? 'now')); ?></span>
                            </p>
                        </div>
                        <div class="document-actions">
                            <a href="<?php echo BASE_URL . '/' . ltrim($doc['file_path'], '/'); ?>" target="_blank" class="btn-icon" title="View">
                                <i class="fas fa-eye"></i>
                            </a>
                            <a href="<?php echo BASE_URL . '/' . ltrim($doc['file_path'], '/'); ?>" download class="btn-icon" title="Download">
                                <i class="fas fa-download"></i>
                            </a>
                        </div>
                    </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
        <?php endif; ?>

        <!-- Metadata Card -->
        <div class="detail-card full-width">
            <div class="card-header">
                <h3><i class="fas fa-history"></i> Record Information</h3>
            </div>
            <div class="card-body">
                <div class="metadata-grid">
                    <div class="metadata-item">
                        <span class="metadata-label">Created By:</span>
                        <span class="metadata-value"><?php echo Security::escape($asset['created_by_name'] ?? 'System'); ?></span>
                    </div>
                    <div class="metadata-item">
                        <span class="metadata-label">Created At:</span>
                        <span class="metadata-value"><?php echo !empty($asset['created_at']) ? date('d/m/Y H:i:s', strtotime($asset['created_at'])) : 'N/A'; ?></span>
                    </div>
                    <div class="metadata-item">
                        <span class="metadata-label">Last Updated:</span>
                        <span class="metadata-value"><?php echo !empty($asset['updated_at']) ? date('d/m/Y H:i:s', strtotime($asset['updated_at'])) : 'N/A'; ?></span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Action Buttons -->
    <div class="action-buttons-group">
        <?php if (Auth::can('ict.edit')): ?>
        <a href="<?php echo BASE_URL; ?>/ict/edit/<?php echo $asset['id']; ?>" class="btn btn-success">
            <i class="fas fa-edit"></i> Edit Asset
        </a>
        <?php endif; ?>
        
        <?php if (Auth::can('ict.delete')): ?>
        <a href="<?php echo BASE_URL; ?>/ict/delete/<?php echo $asset['id']; ?>" class="btn btn-danger" 
           onclick="return confirm('Are you sure you want to delete this ICT asset? This action cannot be undone.')">
            <i class="fas fa-trash"></i> Delete Asset
        </a>
        <?php endif; ?>
        
        <a href="<?php echo BASE_URL; ?>/ict" class="btn btn-secondary">
            <i class="fas fa-arrow-left"></i> Back to ICT Assets
        </a>
    </div>
</div>

<style>
.asset-details-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.detail-card {
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    overflow: hidden;
}

.detail-card.full-width {
    grid-column: 1 / -1;
}

.card-header {
    padding: 15px 20px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    color: white;
}

.card-header h3 {
    margin: 0;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body {
    padding: 20px;
}

.detail-row {
    display: flex;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.detail-row:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.detail-label {
    flex: 0 0 120px;
    font-weight: 600;
    color: var(--text-secondary);
}

.detail-value {
    flex: 1;
    color: var(--text-primary);
    word-break: break-word;
}

.highlight {
    font-weight: 700;
    color: var(--success-color);
    font-size: 1.1rem;
}

.asset-code {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    color: var(--primary-color);
    background: var(--light-bg);
    padding: 4px 8px;
    border-radius: 4px;
}

.serial-number {
    font-family: 'Courier New', monospace;
    background: var(--light-bg);
    padding: 2px 6px;
    border-radius: 4px;
}

code {
    font-family: 'Courier New', monospace;
    background: #272822;
    color: #f8f8f2;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9rem;
}

.remarks-text {
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
}

/* Status Banner */
.status-banner {
    background: white;
    border-radius: 10px;
    padding: 20px 25px;
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    border-left: 6px solid;
}

.status-banner.status-success {
    border-left-color: var(--success-color);
}

.status-banner.status-warning {
    border-left-color: var(--warning-color);
}

.status-banner.status-danger {
    border-left-color: var(--danger-color);
}

.status-icon i {
    font-size: 2.5rem;
}

.status-success .status-icon i {
    color: var(--success-color);
}

.status-warning .status-icon i {
    color: var(--warning-color);
}

.status-danger .status-icon i {
    color: var(--danger-color);
}

.status-content h3 {
    margin: 0 0 5px 0;
    color: var(--text-primary);
}

.status-content p {
    margin: 0;
    color: var(--text-secondary);
}

/* Days remaining badge */
.days-remaining {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    margin-left: 8px;
}

.days-remaining.warning {
    background: #fff3cd;
    color: #856404;
}

.days-remaining.expired {
    background: #f8d7da;
    color: #721c24;
}

/* Badge Styles */
.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
}

.badge-hardware {
    background: #e8f5e9;
    color: #2e7d32;
}

.badge-software {
    background: #fff3e0;
    color: #ef6c00;
}

.badge-network {
    background: #e0f2f1;
    color: #00695c;
}

.badge-server {
    background: #d1c4e9;
    color: #512da8;
}

.badge-peripheral {
    background: #e1f5fe;
    color: #0277bd;
}

/* Status Badges */
.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.status-active {
    background: #d4edda;
    color: #155724;
}

.status-available {
    background: #d1ecf1;
    color: #0c5460;
}

.status-warning {
    background: #fff3cd;
    color: #856404;
}

.status-rejected {
    background: #f8d7da;
    color: #721c24;
}

/* Documents Grid */
.documents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 15px;
}

.document-item {
    display: flex;
    align-items: center;
    padding: 15px;
    background: var(--light-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: all 0.3s;
}

.document-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.document-icon {
    margin-right: 15px;
    font-size: 2rem;
    color: var(--success-color);
}

.document-info {
    flex: 1;
}

.document-info h4 {
    margin: 0 0 5px 0;
    font-size: 0.95rem;
    color: var(--text-primary);
    word-break: break-word;
}

.document-info p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.file-size {
    margin-right: 10px;
}

.upload-date {
    opacity: 0.8;
}

.document-actions {
    display: flex;
    gap: 5px;
}

/* Metadata Grid */
.metadata-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.metadata-item {
    padding: 10px;
    background: var(--light-bg);
    border-radius: 6px;
}

.metadata-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.metadata-value {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
}

/* Action Buttons */
.action-buttons-group {
    display: flex;
    gap: 15px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

@media (max-width: 768px) {
    .asset-details-grid {
        grid-template-columns: 1fr;
    }
    
    .detail-row {
        flex-direction: column;
    }
    
    .detail-label {
        margin-bottom: 5px;
    }
    
    .status-banner {
        flex-direction: column;
        text-align: center;
    }
    
    .documents-grid {
        grid-template-columns: 1fr;
    }
    
    .metadata-grid {
        grid-template-columns: 1fr;
    }
    
    .action-buttons-group {
        flex-direction: column;
    }
    
    .action-buttons-group .btn {
        width: 100%;
    }
}

@media print {
    .header-actions,
    .action-buttons-group,
    .sidebar,
    footer,
    .status-banner {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 20px !important;
    }
    
    .detail-card {
        break-inside: avoid;
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
    
    .card-header {
        background: #f8f9fa !important;
        color: #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* Alert Styles */
.alert {
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
}

.alert-success {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.alert-danger {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.alert i {
    font-size: 1.2rem;
}

.btn-close {
    margin-left: auto;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
}

.btn-close:hover {
    opacity: 1;
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}
</style>

<script>
// Auto-hide success/error messages after 5 seconds
document.addEventListener('DOMContentLoaded', function() {
    const successAlert = document.getElementById('successAlert');
    if (successAlert) {
        setTimeout(function() {
            successAlert.style.display = 'none';
        }, 5000);
    }
    
    const errorAlert = document.getElementById('errorAlert');
    if (errorAlert) {
        setTimeout(function() {
            errorAlert.style.display = 'none';
        }, 5000);
    }
});
</script>

<?php require_once __DIR__ . '/../layouts/footer.php'; ?>