@extends('admin.layouts.app')

@section('page-title', 'Customer Details')

@section('content')

<style>
:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --success-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --warning-gradient: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    --info-gradient: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    --glass-bg: rgba(255, 255, 255, 0.95);
    --shadow-strong: 0 20px 60px rgba(0, 0, 0, 0.15);
    --shadow-medium: 0 12px 40px rgba(0, 0, 0, 0.1);
}

/* Main Card Animations */
.customer-card {
    background: var(--glass-bg);
    border-radius: 24px;
    box-shadow: var(--shadow-strong);
    border: 1px solid rgba(255, 255, 255, 0.3);
    animation: cardEntrance 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    overflow: hidden;
}

.customer-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, 
        rgba(102, 126, 234, 0.03) 0%, 
        rgba(118, 75, 162, 0.03) 50%, 
        rgba(16, 185, 129, 0.03) 100%);
    pointer-events: none;
}

@keyframes cardEntrance {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header Section */
.page-header {
    background: var(--primary-gradient);
    border-radius: 20px;
    padding: 30px;
    color: white;
    margin-bottom: 30px;
    position: relative;
    overflow: hidden;
    animation: headerSlide 0.6s ease-out;
}

@keyframes headerSlide {
    0% {
        opacity: 0;
        transform: translateX(-30px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

.page-header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, 
        transparent 0%, 
        rgba(255, 255, 255, 0.1) 50%, 
        transparent 100%);
    animation: headerShimmer 8s infinite linear;
    transform: rotate(45deg);
}

@keyframes headerShimmer {
    0% { transform: translateX(-100%) rotate(45deg); }
    100% { transform: translateX(100%) rotate(45deg); }
}

/* Customer Profile Section */
.profile-header {
    padding: 40px 35px 30px;
    position: relative;
}

.avatar-container {
    position: relative;
    display: inline-block;
}

.customer-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 800;
    font-size: 2.5rem;
    box-shadow: 0 12px 30px rgba(102, 126, 234, 0.4);
    border: 4px solid white;
    position: relative;
    z-index: 2;
    animation: avatarPulse 2s ease-in-out infinite;
}

@keyframes avatarPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.avatar-status {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 3px solid white;
    z-index: 3;
}

.status-active { background: var(--success-gradient); }
.status-inactive { background: #ef4444; }

/* Info Cards */
.info-card {
    background: white;
    border-radius: 20px;
    padding: 25px;
    box-shadow: var(--shadow-medium);
    border: 1px solid #f1f5f9;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    height: 100%;
    position: relative;
    overflow: hidden;
}

.info-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 5px;
    height: 100%;
    background: var(--primary-gradient);
}

.info-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
}

.info-card h6 {
    color: #64748b;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.8rem;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.info-card h6::before {
    content: '';
    width: 3px;
    height: 12px;
    background: var(--primary-gradient);
    border-radius: 2px;
    display: inline-block;
}

/* Stats Cards */
.stats-card {
    background: white;
    border-radius: 20px;
    padding: 25px;
    text-align: center;
    box-shadow: var(--shadow-medium);
    border: 1px solid #f1f5f9;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.stats-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--primary-gradient);
}

.stats-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.12);
}

.stats-card.orders { --card-color: #3b82f6; }
.stats-card.amount { --card-color: #10b981; }
.stats-card.marks { --card-color: #8b5cf6; }

.stats-icon {
    width: 60px;
    height: 60px;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 15px;
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--card-color), var(--card-color));
    color: white;
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);
}

.stats-card.orders .stats-icon { background: var(--info-gradient); }
.stats-card.amount .stats-icon { background: var(--success-gradient); }
.stats-card.marks .stats-icon { background: var(--primary-gradient); }

.stats-value {
    font-size: 2.2rem;
    font-weight: 800;
    color: #1e293b;
    margin-bottom: 5px;
    line-height: 1;
}

.stats-label {
    color: #64748b;
    font-weight: 600;
    font-size: 0.9rem;
}

/* Mark Numbers List */
.marks-section {
    background: white;
    border-radius: 20px;
    box-shadow: var(--shadow-medium);
    border: 1px solid #f1f5f9;
    overflow: hidden;
}

.section-header {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    padding: 25px 30px;
    border-bottom: 1px solid #e2e8f0;
}

.section-header h5 {
    margin: 0;
    color: #1e293b;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-header h5::before {
    content: '';
    width: 4px;
    height: 20px;
    background: var(--primary-gradient);
    border-radius: 2px;
    display: inline-block;
}

.mark-item {
    display: flex;
    align-items: center;
    padding: 20px 30px;
    border-bottom: 1px solid #f1f5f9;
    transition: all 0.3s ease;
    animation: itemEntrance 0.5s ease-out both;
}

@keyframes itemEntrance {
    0% {
        opacity: 0;
        transform: translateX(-20px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

.mark-item:last-child {
    border-bottom: none;
}

.mark-item:hover {
    background: #f8fafc;
    transform: translateX(5px);
}

.mark-badge {
    background: var(--primary-gradient);
    color: white;
    padding: 8px 16px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.9rem;
    margin-right: 15px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.mark-route {
    color: #64748b;
    font-weight: 500;
}

/* Buttons - FIXED POSITIONING */
.btn-back {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    padding: 12px 25px;
    color: white;
    font-weight: 700;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-back::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(255, 255, 255, 0.2), 
        transparent);
    transition: left 0.6s ease;
}

.btn-back:hover::before {
    left: 100%;
}

.btn-back:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
    color: white;
    text-decoration: none;
}

.btn-premium {
    background: var(--primary-gradient);
    border: none;
    border-radius: 12px;
    padding: 12px 25px;
    color: white;
    font-weight: 700;
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.btn-premium::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(255, 255, 255, 0.2), 
        transparent);
    transition: left 0.6s ease;
}

.btn-premium:hover::before {
    left: 100%;
}

.btn-premium:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 35px rgba(102, 126, 234, 0.5);
}

.btn-outline-secondary {
    border: 2px solid #64748b;
    border-radius: 12px;
    padding: 12px 25px;
    color: #64748b;
    font-weight: 700;
    background: transparent;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-outline-secondary:hover {
    border-color: #475569;
    color: #475569;
    background: rgba(100, 116, 139, 0.05);
    transform: translateY(-2px);
    text-decoration: none;
}

/* Badges */
.type-badge {
    padding: 8px 16px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-premium {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(240, 147, 251, 0.4);
}

.badge-regular {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(79, 172, 254, 0.4);
}

.status-badge {
    padding: 8px 16px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.8rem;
}

.badge-active {
    background: var(--success-gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}

.badge-inactive {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}

/* Animations */
.animate-fade-in {
    animation: fadeInUp 0.6s ease-out both;
}

@keyframes fadeInUp {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.animation-delay-1 { animation-delay: 0.1s; }
.animation-delay-2 { animation-delay: 0.2s; }
.animation-delay-3 { animation-delay: 0.3s; }
.animation-delay-4 { animation-delay: 0.4s; }

/* Header Button Container - FIXED */
.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 15px;
}

/* Responsive */
@media (max-width: 768px) {
    .profile-header {
        padding: 25px 20px;
        text-align: center;
    }
    
    .customer-avatar {
        width: 80px;
        height: 80px;
        font-size: 2rem;
    }
    
    .page-header {
        padding: 20px;
    }
    
    .stats-card {
        padding: 20px;
    }
    
    .stats-value {
        font-size: 1.8rem;
    }
    
    .header-actions {
        justify-content: center;
        margin-top: 15px;
    }
    
    .page-header .row {
        text-align: center;
    }
}

@media (max-width: 576px) {
    .btn-back, .btn-outline-secondary {
        padding: 10px 20px;
        font-size: 0.9rem;
    }
    
    .header-actions {
        flex-direction: column;
        gap: 10px;
        width: 100%;
    }
    
    .header-actions a {
        width: 100%;
        justify-content: center;
    }
}
</style>

<div class="container py-4">

    {{-- HEADER - FIXED BUTTON POSITION --}}
    <div class="page-header animate-fade-in">
        <div class="row align-items-center">
            <div class="col-md-8">
                <h1 class="fw-bold mb-2">Customer Details</h1>
                <p class="mb-0 opacity-90">Complete customer information and analytics</p>
            </div>
            <div class="col-md-4">
                <div class="header-actions">
                    <a href="{{ route('admin.customers.index') }}" class="btn-back">
                        <i class="bi bi-arrow-left"></i>
                        Back to List
                    </a>
                </div>
            </div>
        </div>
    </div>

    {{-- CUSTOMER PROFILE CARD --}}
    <div class="customer-card mb-4">
        <div class="profile-header">
            <div class="row align-items-center">
                <div class="col-auto">
                    <div class="avatar-container">
                        <div class="customer-avatar">
                            {{ strtoupper(substr($customer->customer_name,0,1)) }}
                        </div>
                        <div class="avatar-status {{ $customer->status == 'active' ? 'status-active' : 'status-inactive' }}"></div>
                    </div>
                </div>
                <div class="col">
                    <div class="d-flex align-items-center mb-2">
                        <h2 class="fw-bold mb-0 me-3">{{ $customer->customer_name }}</h2>
                        @if($customer->customer_type == 'premium')
                            <span class="type-badge badge-premium">
                                <i class="bi bi-award me-1"></i>Premium
                            </span>
                        @else
                            <span class="type-badge badge-regular">
                                <i class="bi bi-person me-1"></i>Regular
                            </span>
                        @endif
                    </div>
                    <p class="text-muted mb-2">
                        <i class="bi bi-building me-2"></i>
                        {{ $customer->company_name ?? 'No company specified' }}
                    </p>
                    <div class="d-flex align-items-center gap-3">
                        <span class="status-badge {{ $customer->status == 'active' ? 'badge-active' : 'badge-inactive' }}">
                            <i class="bi bi-circle-fill me-1" style="font-size: 0.6rem;"></i>
                            {{ ucfirst($customer->status) }}
                        </span>
                        <span class="text-muted">
                            <i class="bi bi-calendar me-1"></i>
                            Joined {{ $customer->created_at ? $customer->created_at->format('M d, Y') : 'N/A' }}
                        </span>
                    </div>
                </div>
            </div>
        </div>

        {{-- CUSTOMER INFORMATION --}}
        <div class="row g-4 p-4">
            {{-- Contact Information --}}
            <div class="col-md-6 animate-fade-in animation-delay-1">
                <div class="info-card">
                    <h6><i class="bi bi-telephone me-2"></i>Contact Information</h6>
                    <div class="mb-3">
                        <div class="d-flex align-items-center mb-2">
                            <i class="bi bi-envelope text-primary me-2"></i>
                            <strong class="me-2">Email:</strong>
                            <span>{{ $customer->email }}</span>
                        </div>
                        <div class="d-flex align-items-center mb-2">
                            <i class="bi bi-phone text-primary me-2"></i>
                            <strong class="me-2">Mobile:</strong>
                            <span>{{ $customer->mobile_no }}</span>
                        </div>
                        <div class="d-flex align-items-center mb-2">
                            <i class="bi bi-geo-alt text-primary me-2"></i>
                            <strong class="me-2">Address:</strong>
                            <span>{{ $customer->address ?? 'N/A' }}</span>
                        </div>
                        <div class="d-flex align-items-center">
                            <i class="bi bi-pin-map text-primary me-2"></i>
                            <strong class="me-2">Pincode:</strong>
                            <span>{{ $customer->pincode ?? 'N/A' }}</span>
                        </div>
                    </div>
                </div>
            </div>

            {{-- Account Information --}}
            <div class="col-md-6 animate-fade-in animation-delay-2">
                <div class="info-card">
                    <h6><i class="bi bi-person-badge me-2"></i>Account Information</h6>
                    <div class="mb-3">
                        <div class="d-flex align-items-center mb-2">
                            <i class="bi bi-id-card text-primary me-2"></i>
                            <strong class="me-2">Customer ID:</strong>
                            <code class="bg-light px-2 py-1 rounded">{{ $customer->customer_id }}</code>
                        </div>
                        <div class="d-flex align-items-center mb-2">
                            <i class="bi bi-calendar-check text-primary me-2"></i>
                            <strong class="me-2">Registered On:</strong>
                            <span>{{ $customer->created_at ? $customer->created_at->format('d M, Y') : '-' }}</span>
                        </div>
                        <div class="d-flex align-items-center">
                            <i class="bi bi-briefcase text-primary me-2"></i>
                            <strong class="me-2">Designation:</strong>
                            <span>{{ $customer->designation ?? 'N/A' }}</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {{-- STATISTICS --}}
    <div class="row g-4 mb-4">
        {{-- Total Orders --}}
        <div class="col-md-4 animate-fade-in animation-delay-1">
            <div class="stats-card orders">
                <div class="stats-icon">
                    <i class="bi bi-cart-check"></i>
                </div>
                <div class="stats-value">{{ $totalOrders }}</div>
                <div class="stats-label">Total Orders</div>
            </div>
        </div>

        {{-- Total Amount --}}
        <div class="col-md-4 animate-fade-in animation-delay-2">
            <div class="stats-card amount">
                <div class="stats-icon">
                    <i class="bi bi-currency-rupee"></i>
                </div>
                <div class="stats-value">₹{{ number_format($totalAmount, 2) }}</div>
                <div class="stats-label">Total Amount Spent</div>
            </div>
        </div>

        {{-- Mark Count --}}
        <div class="col-md-4 animate-fade-in animation-delay-3">
            <div class="stats-card marks">
                <div class="stats-icon">
                    <i class="bi bi-hash"></i>
                </div>
                <div class="stats-value">{{ $customer->marks->count() }}</div>
                <div class="stats-label">Mark Numbers</div>
            </div>
        </div>
    </div>

    {{-- MARK NUMBERS SECTION --}}
    <div class="marks-section animate-fade-in animation-delay-4">
        <div class="section-header">
            <h5>
                <i class="bi bi-hash"></i>
                Customer Mark Numbers
                <span class="badge bg-primary ms-2">{{ $customer->marks->count() }}</span>
            </h5>
        </div>
        
        <div class="section-body">
            @if($customer->marks->count() == 0)
                <div class="text-center py-5">
                    <i class="bi bi-inbox display-4 text-muted mb-3"></i>
                    <p class="text-muted mb-0">No mark numbers found for this customer.</p>
                </div>
            @else
                @foreach($customer->marks as $index => $mark)
                    <div class="mark-item" style="animation-delay: {{ $index * 0.1 }}s">
                        <div class="mark-badge">
                            <i class="bi bi-tag me-1"></i>{{ $mark->mark_no }}
                        </div>
                        <div class="mark-route">
                            <i class="bi bi-arrow-right me-1"></i>
                            {{ $mark->origin }} → {{ $mark->destination }}
                        </div>
                    </div>
                @endforeach
            @endif
        </div>
    </div>

</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
    // Add hover effects to interactive elements
    const interactiveElements = document.querySelectorAll('.info-card, .stats-card, .mark-item');
    
    interactiveElements.forEach(element => {
        element.addEventListener('mouseenter', function() {
            this.style.transform = this.classList.contains('mark-item') ? 'translateX(5px)' : 'translateY(-5px)';
        });
        
        element.addEventListener('mouseleave', function() {
            this.style.transform = 'translateY(0)';
        });
    });

    // Add loading animation to stats cards
    const statsValues = document.querySelectorAll('.stats-value');
    statsValues.forEach(value => {
        const originalText = value.textContent;
        value.textContent = '0';
        
        setTimeout(() => {
            value.textContent = originalText;
            value.style.transform = 'scale(1.1)';
            setTimeout(() => {
                value.style.transform = 'scale(1)';
            }, 300);
        }, 500);
    });
});
</script>

@endsection