<?php
defined('BASEPATH') or exit('No direct script access allowed');
$site_name = config_item('website_name') ?: (config_item('company_name') ?: 'Zisco ERP');
$site_initial = strtoupper(substr(trim((string) $site_name), 0, 1));
?>
<!DOCTYPE html>
<html lang="en" class="h-full">

<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title><?php echo isset($title) ? html_escape($title) : 'Reset password'; ?> | <?php echo html_escape($site_name); ?></title>
	<link rel="stylesheet" href="<?php echo base_url('assets/css/tailwind.generated.css'); ?>">
	<link rel="stylesheet" href="<?php echo base_url('assets/css/app.css'); ?>">
	<style>
		body {
			font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
		}
	</style>
</head>

<body class="h-full bg-gradient-to-br from-slate-900 via-slate-950 to-black text-slate-50">
	<div class="min-h-full flex items-center justify-center px-4 py-12">
		<div class="w-full max-w-md">
			<div class="bg-slate-900/60 border border-white/10 rounded-2xl shadow-2xl shadow-primary/20 backdrop-blur-xl p-8">
				<div class="flex items-center justify-between mb-6">
					<div>
						<p class="text-xs uppercase tracking-[0.4em] text-primary/80">Account recovery</p>
						<h1 class="text-2xl font-bold mt-1 text-white">Choose a new password</h1>
					</div>
					<div class="h-10 w-10 rounded-full bg-gradient-to-br from-primary to-indigo-400 flex items-center justify-center text-white font-bold text-lg shadow-lg shadow-primary/40">
						<?php echo html_escape($site_initial); ?>
					</div>
				</div>

				<?php if (!empty($error) || validation_errors()): ?>
					<div class="mb-4 rounded-xl border border-red-500/30 bg-red-500/10 text-red-100 px-4 py-3 text-sm">
						<?php
						echo $error ? html_escape($error) . '<br>' : '';
						echo validation_errors();
						?>
					</div>
				<?php endif; ?>

				<form action="<?php echo site_url('login/reset_password/' . (int) $user_id . '/' . rawurlencode((string) $reset_key)); ?>" method="post" class="space-y-5">
					<?php if (config_item('csrf_protection')): ?>
						<input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">
					<?php endif; ?>
					<div class="space-y-2">
						<label for="password" class="text-sm font-medium text-slate-200">New password</label>
						<input
							type="password"
							id="password"
							name="password"
							class="w-full rounded-xl border border-white/10 bg-white/5 px-4 py-3 text-sm text-white placeholder-slate-400 focus:border-primary focus:ring-2 focus:ring-primary/50 transition"
							placeholder="Minimum 6 characters"
							required />
					</div>

					<div class="space-y-2">
						<label for="confirm_password" class="text-sm font-medium text-slate-200">Confirm password</label>
						<input
							type="password"
							id="confirm_password"
							name="confirm_password"
							class="w-full rounded-xl border border-white/10 bg-white/5 px-4 py-3 text-sm text-white placeholder-slate-400 focus:border-primary focus:ring-2 focus:ring-primary/50 transition"
							placeholder="Re-enter password"
							required />
					</div>

					<button
						type="submit"
						class="w-full inline-flex items-center justify-center gap-2 rounded-xl bg-primary px-4 py-3 text-sm font-semibold text-white shadow-lg shadow-primary/40 transition hover:translate-y-[-1px] hover:shadow-primary/60 focus:outline-none focus:ring-2 focus:ring-primary/60">
						<span>Reset password</span>
					</button>

					<div class="text-center text-sm">
						<a href="<?php echo site_url('login'); ?>" class="text-primary hover:text-primary/80">Back to sign in</a>
					</div>
				</form>
			</div>

			<p class="mt-6 text-center text-xs text-slate-400">
				© <?php echo date('Y'); ?> <?php echo html_escape($site_name); ?>. All rights reserved.
			</p>
		</div>
	</div>
</body>

</html>
