{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Login - SwiftPOS</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap 5 -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">

    <!-- Modern Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Inter:wght@400;500;600&display=swap" rel="stylesheet">

    <!-- Global SwiftPOS Styles -->
    <link rel="stylesheet" href="{% static 'css/style.css' %}?v=login1">

    <style>
        :root {
            --sp-primary: #4F46E5;
            --sp-secondary: #6366F1;
            --sp-bg-dark: #0f172a;
            --sp-text-main: #1e293b;
            --sp-text-muted: #64748b;
        }

        body.auth-body {
            margin: 0;
            padding: 0;
            min-height: 100vh;
            font-family: 'Inter', sans-serif;
            background-color: #020617;
            background-image: 
                radial-gradient(circle at 15% 50%, rgba(79, 70, 229, 0.15), transparent 25%),
                radial-gradient(circle at 85% 30%, rgba(147, 51, 234, 0.15), transparent 25%);
            color: #f8fafc;
            display: flex;
            align-items: center;
        }

        h1, h2, h3, .auth-brand-title {
            font-family: 'Outfit', sans-serif;
        }

        .auth-wrapper {
            max-width: 1000px;
            margin: 0 auto;
            animation: fadeUp 0.8s ease-out forwards;
            opacity: 0;
            transform: translateY(20px);
        }

        @keyframes fadeUp {
            to { opacity: 1; transform: translateY(0); }
        }

        .auth-card {
            border-radius: 24px;
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
            background: transparent;
            overflow: hidden;
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        .auth-form-side {
            background-color: #ffffff;
            color: var(--sp-text-main);
            padding: 3rem 3.5rem;
            position: relative;
        }

        .auth-hero-side {
            background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
            color: #f8fafc;
            padding: 3rem 2.5rem;
            position: relative;
            overflow: hidden;
        }

        .auth-hero-side::before {
            content: '';
            position: absolute;
            top: 0; left: 0; right: 0; bottom: 0;
            background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
            opacity: 0.5;
        }

        .auth-brand-mark {
            width: 48px;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: transparent;
        }

        .brand-logo-img {
            height: 44px;
            width: auto;
            border-radius: 10px;
            box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
        }

        .auth-brand-title {
            font-size: 1.25rem;
            font-weight: 700;
            color: var(--sp-text-main);
            letter-spacing: -0.02em;
        }

        .auth-brand-subtitle {
            font-size: 0.8rem;
            color: var(--sp-text-muted);
            font-family: 'Inter', sans-serif;
        }

        .auth-badge {
            display: inline-flex;
            align-items: center;
            gap: 0.4rem;
            padding: 0.35rem 0.85rem;
            border-radius: 999px;
            font-size: 0.75rem;
            font-weight: 600;
            background-color: #f1f5f9;
            color: #475569;
            border: 1px solid #e2e8f0;
            transition: all 0.3s ease;
        }

        .auth-badge:hover {
            background-color: #e2e8f0;
        }

        .auth-title {
            font-size: 1.75rem;
            font-weight: 700;
            color: var(--sp-text-main);
            letter-spacing: -0.02em;
        }

        .auth-subtitle {
            font-size: 0.95rem;
            color: var(--sp-text-muted);
            line-height: 1.5;
        }

        .auth-input-label {
            font-size: 0.85rem;
            font-weight: 600;
            color: #334155;
            margin-bottom: 0.4rem;
        }

        .form-control-auth {
            border-radius: 12px;
            border: 1px solid #cbd5e1;
            font-size: 0.95rem;
            padding: 0.75rem 1rem;
            background-color: #f8fafc;
            transition: all 0.2s ease-in-out;
            color: #0f172a;
        }

        .form-control-auth:focus {
            background-color: #ffffff;
            border-color: var(--sp-primary);
            box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
        }

        .btn-auth-primary {
            background: var(--sp-primary);
            border: 1px solid var(--sp-primary);
            border-radius: 12px;
            font-size: 1rem;
            font-weight: 600;
            padding: 0.8rem;
            color: #ffffff;
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2), 0 2px 4px -1px rgba(79, 70, 229, 0.1);
            position: relative;
            overflow: hidden;
        }

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

        .btn-auth-primary:hover::after {
            left: 100%;
        }

        .btn-auth-primary:hover {
            transform: translateY(-1px);
            box-shadow: 0 10px 15px -3px rgba(79, 70, 229, 0.3), 0 4px 6px -2px rgba(79, 70, 229, 0.15);
            color: #ffffff;
            background: var(--sp-secondary);
        }
        
        .btn-auth-primary:active {
            transform: translateY(0);
        }

        .form-check-input {
            width: 1.1rem;
            height: 1.1rem;
            border-radius: 4px;
            border-color: #cbd5e1;
            cursor: pointer;
        }

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

        .auth-footer-text {
            font-size: 0.8rem;
            color: #94a3b8;
        }

        /* Hero Side Graphics */
        .auth-highlight-number {
            font-size: 2rem;
            font-weight: 700;
            font-family: 'Outfit', sans-serif;
            background: linear-gradient(to right, #a5b4fc, #c4b5fd);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .auth-highlight-label {
            font-size: 0.85rem;
            color: #cbd5e1;
            font-weight: 500;
        }

        .auth-divider {
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            margin: 2rem 0;
        }

        .auth-pill {
            border-radius: 12px;
            border: 1px solid rgba(255, 255, 255, 0.15);
            color: #e2e8f0;
            font-size: 0.85rem;
            padding: 0.5rem 1rem;
            background-color: rgba(255, 255, 255, 0.05);
            backdrop-filter: blur(4px);
            transition: all 0.3s ease;
        }

        .auth-pill:hover {
            background-color: rgba(255, 255, 255, 0.1);
            transform: translateY(-2px);
        }

        .auth-logo-mini {
            position: absolute;
            right: 2rem;
            top: 2rem;
            width: 40px;
            height: 40px;
            border-radius: 12px;
            background-color: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(8px);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1rem;
            color: #f1f5f9;
            border: 1px solid rgba(255, 255, 255, 0.2);
            z-index: 2;
        }

        .auth-quote {
            font-size: 0.95rem;
            color: #94a3b8;
            font-style: italic;
            line-height: 1.6;
            margin-top: 1rem;
            position: relative;
            padding-left: 1.5rem;
        }

        .auth-quote::before {
            content: '\201C';
            font-size: 3rem;
            position: absolute;
            left: -0.5rem;
            top: -1rem;
            color: rgba(255, 255, 255, 0.1);
            font-family: Georgia, serif;
        }

        @media (max-width: 767.98px) {
            .auth-form-side {
                padding: 2.5rem 1.5rem;
            }
            .auth-hero-side {
                display: none !important;
            }
            .auth-card {
                border-radius: 16px;
            }
        }
    </style>
</head>
<body class="auth-body">

{% block content %}
<div class="container-fluid min-vh-100 d-flex align-items-center justify-content-center py-4">
    <div class="auth-wrapper w-100">
        <div class="row justify-content-center">
            <div class="col-lg-10 col-xl-9">
                <div class="auth-card row g-0">
                    <!-- Form side -->
                    <div class="col-md-6 auth-form-side">
                        <div class="d-flex align-items-center justify-content-between mb-4">
                            <div class="d-flex align-items-center gap-3">
                                <div class="auth-brand-mark">
                                    {% load static %}
                                    <img src="{% static 'core/icons/icon-192.png' %}" alt="SwiftPOS logo" class="brand-logo-img" onerror="this.src='https://cdn-icons-png.flaticon.com/512/3225/3225066.png'"/>
                                </div>
                                <div>
                                    <div class="auth-brand-title">SwiftPOS</div>
                                    <div class="auth-brand-subtitle">Smart Retail System</div>
                                </div>
                            </div>
                            <span class="auth-badge d-none d-sm-inline-flex">
                                <i class="fas fa-bolt text-warning"></i>
                                Fast Checkout
                            </span>
                        </div>

                        <h1 class="auth-title mb-2">Welcome Back</h1>
                        <p class="auth-subtitle mb-4">
                            Sign in to your account to continue managing your sales and inventory.
                        </p>

                        <!-- Toast Messages -->
    <div class="swiftpos-toast-container">
        {% if messages %}
            {% for message in messages %}
                <div class="swiftpos-toast swiftpos-toast-{{ message.tags }}">
                    <div class="toast-icon">
                        {% if message.tags == 'success' %}
                            <i class="fas fa-check-circle"></i>
                        {% elif message.tags == 'error' or message.tags == 'danger' %}
                            <i class="fas fa-exclamation-circle"></i>
                        {% elif message.tags == 'warning' %}
                            <i class="fas fa-exclamation-triangle"></i>
                        {% else %}
                            <i class="fas fa-info-circle"></i>
                        {% endif %}
                    </div>
                    <div class="toast-text">
                        {{ message }}
                    </div>
                </div>
            {% endfor %}
        {% endif %}
    </div>

                        {% if form.non_field_errors %}
                            <div class="alert alert-danger mb-3" role="alert">
                                {% for error in form.non_field_errors %}
                                    <div>{{ error }}</div>
                                {% endfor %}
                            </div>
                        {% endif %}

                        <form method="post"
      data-offline="true"
      data-offline-type="login"
      novalidate>
                            {% csrf_token %}

                            <div class="mb-3">
                                <label for="id_username" class="auth-input-label mb-1">
                                    Username or Email
                                </label>
                                <input
                                    type="text"
                                    name="username"
                                    autofocus
                                    required
                                    id="id_username"
                                    class="form-control form-control-auth"
                                    placeholder="e.g. cashier01"
                                    value="{% if form.username.value %}{{ form.username.value }}{% endif %}">
                                {% if form.username.errors %}
                                    <div class="invalid-feedback d-block">
                                        {{ form.username.errors.0 }}
                                    </div>
                                {% endif %}
                            </div>

                            <div class="mb-3">
                                <label for="id_password" class="auth-input-label mb-1">
                                    Password
                                </label>
                                <input
                                    type="password"
                                    name="password"
                                    required
                                    id="id_password"
                                    class="form-control form-control-auth"
                                    placeholder="Enter your password">
                                {% if form.password.errors %}
                                    <div class="invalid-feedback d-block">
                                        {{ form.password.errors.0 }}
                                    </div>
                                {% endif %}
                            </div>

                            <div class="d-flex justify-content-between align-items-center mb-4">
                                <div class="form-check small">
                                    <input class="form-check-input" type="checkbox" value="1" id="rememberMe">
                                    <label class="form-check-label text-muted" for="rememberMe">
                                        Keep me signed in
                                    </label>
                                </div>
                                <!-- reserved for "Forgot password" later -->
                                <div>
                                    <a href="{% url 'password_reset' %}" class="text-decoration-none small fw-semibold" style="color: var(--sp-primary);">
                                        Forgot password?
                                    </a>
                                </div>
                            </div>

                            <div class="d-grid mb-2">
                                <button type="submit" class="btn btn-auth-primary">
                                    <i class="fas fa-right-to-bracket me-1"></i>
                                    Sign in
                                </button>
                            </div>

                            <div class="text-center auth-footer-text mt-3">
                                Having trouble logging in? Contact your supervisor or system admin.
                            </div>
                        </form>
                    </div>

                    <!-- Hero / info side (desktop only) -->
                    <div class="col-md-6 auth-hero-side d-none d-md-flex flex-column justify-content-between">
                        <div>
                            <div class="auth-logo-mini">
                                <i class="fas fa-receipt"></i>
                            </div>
                            <h2 class="mb-2 text-white">
                                See your day in one glance.
                            </h2>
                            <p class="mb-4" style="font-size: 0.9rem; color: #E5E7EB;">
                                SwiftPOS keeps your cashiers fast, your stock under control, and your reports always ready.
                            </p>

                            <div class="d-flex gap-3 mb-3">
                                <div>
                                    <div class="auth-highlight-number text-white">2x</div>
                                    <div class="auth-highlight-label">faster checkout</div>
                                </div>
                                <div>
                                    <div class="auth-highlight-number text-white">99.9%</div>
                                    <div class="auth-highlight-label">uptime</div>
                                </div>
                                <div>
                                    <div class="auth-highlight-number text-white">24/7</div>
                                    <div class="auth-highlight-label">access anywhere</div>
                                </div>
                            </div>

                            <div class="auth-divider"></div>

                            <div class="d-flex flex-wrap gap-2 mb-2">
                                <span class="auth-pill">
                                    <i class="fas fa-store me-1"></i> Track every sale
                                </span>
                                <span class="auth-pill">
                                    <i class="fas fa-boxes-stacked me-1"></i> Live stock balance
                                </span>
                                <span class="auth-pill">
                                    <i class="fas fa-chart-line me-1"></i> Daily summary
                                </span>
                            </div>
                        </div>

                        <div class="auth-quote mt-4">
                            “The moment cashier signs in, we know exactly what is sold, returned, or low in stock.”
                        </div>
                    </div>
                </div>

                <div class="text-center mt-3 auth-footer-text text-light">
                    &copy; {% now "Y" %} SwiftPOS. Trusted by ambitious shops and supermarkets.
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

<!-- Bootstrap JS (optional, if needed for alerts, etc.) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

</body>
</html>
