<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    @php
        $appSettings = \App\Models\SoftwareSetting::getCurrent();
        $appName = $appSettings->app_name ?? config('app.name', 'Harshana Systems');
    @endphp
    <title>Login - {{ $appName }}</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        @php
            $appColor = \App\Models\SoftwareSetting::getCurrent()->app_color ?? 'blue';
            $colorMap = [
                'blue' => ['primary' => '#3b82f6', 'secondary' => '#1d4ed8'],
                'green' => ['primary' => '#10b981', 'secondary' => '#059669'],
                'red' => ['primary' => '#ef4444', 'secondary' => '#dc2626'],
                'purple' => ['primary' => '#8b5cf6', 'secondary' => '#7c3aed'],
                'orange' => ['primary' => '#f97316', 'secondary' => '#ea580c'],
                'pink' => ['primary' => '#ec4899', 'secondary' => '#db2777'],
                'teal' => ['primary' => '#14b8a6', 'secondary' => '#0f766e'],
                'lime' => ['primary' => '#84cc16', 'secondary' => '#65a30d'],
                'slate' => ['primary' => '#64748b', 'secondary' => '#475569'],
                'cyan' => ['primary' => '#06b6d4', 'secondary' => '#0891b2']
            ];
            $currentColors = $colorMap[$appColor] ?? $colorMap['blue'];
        @endphp
        :root {
            --primary-color: {{ $currentColors['primary'] }};
            --secondary-color: {{ $currentColors['secondary'] }};
            --success-color: #10b981;
            --danger-color: #ef4444;
            --warning-color: #f59e0b;
            --info-color: #3b82f6;
            --light-color: #f8fafc;
            --dark-color: #1e293b;
            --gray-100: #f1f5f9;
            --gray-200: #e2e8f0;
            --gray-300: #cbd5e1;
            --gray-400: #94a3b8;
            --gray-500: #64748b;
            --gray-600: #475569;
            --gray-700: #334155;
            --gray-800: #1e293b;
            --gray-900: #0f172a;
        }

        body {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
            min-height: 100vh;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        .login-container {
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

        .login-card {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 20px;
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
            overflow: hidden;
            width: 100%;
            max-width: 400px;
            backdrop-filter: blur(20px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            position: relative;
        }

        .login-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(135deg,
                rgba(255, 255, 255, 0.1) 0%,
                rgba(255, 255, 255, 0.05) 50%,
                rgba(255, 255, 255, 0.1) 100%);
            border-radius: 20px;
            pointer-events: none;
        }

        .login-header {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
            color: white;
            padding: 2rem;
            text-align: center;
        }

        .login-header h2.app-name {
            margin: 0 0 0.5rem 0;
            font-size: 1.2rem;
            font-weight: 600;
            opacity: 0.9;
            letter-spacing: 1px;
            text-transform: uppercase;
        }

        .login-header h1 {
            margin: 0;
            font-size: 1.75rem;
            font-weight: 700;
        }

        .login-header p {
            margin: 0.5rem 0 0 0;
            opacity: 0.9;
            font-size: 0.9rem;
        }

        .login-body {
            padding: 2rem;
            background: rgba(255, 255, 255, 0.8);
            border-radius: 0 0 20px 20px;
            position: relative;
            z-index: 1;
        }

        .form-floating {
            margin-bottom: 1rem;
        }

        .form-floating > .form-control {
            border: 2px solid var(--gray-200);
            border-radius: 12px;
            padding: 1rem 0.75rem;
            font-size: 1rem;
            transition: all 0.3s ease;
        }

        .form-floating > .form-control:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.25);
        }

        .form-floating > label {
            padding: 1rem 0.75rem;
            color: var(--gray-500);
        }

        .btn-login {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
            border: none;
            border-radius: 12px;
            padding: 0.875rem 1.5rem;
            font-size: 1rem;
            font-weight: 600;
            color: white;
            width: 100%;
            transition: all 0.3s ease;
            margin-top: 1rem;
        }

        .btn-login:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 25px -5px rgba(79, 70, 229, 0.4);
            color: white;
        }

        .btn-login:active {
            transform: translateY(0);
        }

        .remember-me {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            margin-top: 1rem;
        }

        .form-check-input {
            border-radius: 6px;
            border: 2px solid var(--gray-300);
        }

        .form-check-input:checked {
            background-color: var(--primary-color);
            border-color: var(--primary-color);
        }

        .alert {
            border: none;
            border-radius: 12px;
            padding: 1rem;
            margin-bottom: 1rem;
        }

        .alert-danger {
            background-color: #fef2f2;
            color: var(--danger-color);
        }

        .logo-icon {
            width: 80px;
            height: 80px;
            margin: 0 auto 1rem auto;
            border-radius: 50%;
            overflow: hidden;
            box-shadow: 0 8px 25px -8px rgba(0, 0, 0, 0.3);
            border: 3px solid rgba(255, 255, 255, 0.2);
            transition: all 0.3s ease;
        }

        .logo-icon:hover {
            transform: scale(1.05);
            box-shadow: 0 12px 35px -8px rgba(0, 0, 0, 0.4);
        }

        /* Mobile Responsive */
        @media (max-width: 768px) {
            .login-container {
                padding: 10px;
            }
            
            .login-card {
                max-width: 100%;
                margin: 0;
            }
            
            .login-header {
                padding: 1.5rem;
            }
            
            .login-header h1 {
                font-size: 1.5rem;
            }
            
            .login-header h2.app-name {
                font-size: 1rem;
            }
            
            .login-body {
                padding: 1.5rem;
            }
        }

        @media (max-width: 480px) {
            .login-header {
                padding: 1rem;
            }
            
            .login-body {
                padding: 1rem;
            }
            
            .logo-icon {
                width: 70px;
                height: 70px;
            }
            
            .login-header h2.app-name {
                font-size: 0.9rem;
            }
        }

        /* Loading state */
        .btn-login.loading {
            pointer-events: none;
            opacity: 0.7;
        }

        .btn-login.loading::after {
            content: "";
            width: 16px;
            height: 16px;
            margin-left: 10px;
            border: 2px solid transparent;
            border-top-color: white;
            border-radius: 50%;
            display: inline-block;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <div class="login-container">
        <div class="login-card">
            <div class="login-header">
                <div class="logo-icon">
                    @php
                        $appSettings = \App\Models\SoftwareSetting::getCurrent();
                        $appName = $appSettings->app_name ?? config('app.name', 'Harshana Systems');
                        $iconVersion = config('app.icon_version', env('ICON_VERSION', time()));
                    @endphp
                    <img src="/icons/icon-192x192.png?v={{ $iconVersion }}" alt="{{ $appName }} Icon" style="width: 100%; height: 100%; border-radius: 50%; object-fit: cover;">
                </div>
                <h2 class="app-name">{{ $appName }}</h2>
                <h1>Welcome Back</h1>
                <p>Sign in to your account</p>
            </div>
            <div class="login-body">
                @if(session('success'))
                    <div class="alert alert-success">
                        <i class="fas fa-check-circle me-2"></i>
                        {!! session('success') !!}
                    </div>
                @endif

                @if(session('warning'))
                    <div class="alert alert-warning">
                        <i class="fas fa-exclamation-triangle me-2"></i>
                        {!! session('warning') !!}
                    </div>
                @endif

                @if(session('error'))
                    <div class="alert alert-danger">
                        <i class="fas fa-times-circle me-2"></i>
                        {!! session('error') !!}
                    </div>
                @endif

                @if ($errors->any())
                    <div class="alert alert-danger">
                        <i class="fas fa-exclamation-circle me-2"></i>
                        {{ $errors->first() }}
                    </div>
                @endif

                <form method="POST" action="{{ route('login') }}" id="loginForm">
                    @csrf
                    
                    <div class="form-floating">
                        <input type="text" class="form-control" id="username" name="username" 
                               placeholder="Username" value="{{ old('username') }}" required>
                        <label for="username">
                            <i class="fas fa-user me-2"></i>Username
                        </label>
                    </div>

                    <div class="form-floating">
                        <input type="password" class="form-control" id="password" name="password" 
                               placeholder="Password" required>
                        <label for="password">
                            <i class="fas fa-lock me-2"></i>Password
                        </label>
                    </div>

                    <div class="remember-me">
                        <input class="form-check-input" type="checkbox" id="remember" name="remember">
                        <label class="form-check-label" for="remember">
                            Remember me
                        </label>
                    </div>

                    <button type="submit" class="btn btn-login" id="loginBtn">
                        <i class="fas fa-sign-in-alt me-2"></i>Sign In
                    </button>
                </form>

                <div class="text-center mt-3">
                    <small class="text-muted">
                        Contact-0775897772
                    </small>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
    <script>
        document.getElementById('loginForm').addEventListener('submit', function() {
            const btn = document.getElementById('loginBtn');
            btn.classList.add('loading');
            btn.innerHTML = '<i class="fas fa-sign-in-alt me-2"></i>Signing In...';
        });

        // Auto-focus username field
        document.getElementById('username').focus();
    </script>
</body>
</html>