{% load i18n %}{% load static %}
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE }}" dir="{% if LANGUAGE_CODE == 'ar' %}rtl{% else %}ltr{% endif %}">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>{% block title %}{% trans "PX360 - Patient Experience Management" %}{% endblock %}</title>

    <!-- TomSelect CSS (must load before Tailwind/px360 so overrides win) -->
    <link href="https://cdn.jsdelivr.net/npm/tom-select@2.3.1/dist/css/tom-select.css" rel="stylesheet">

    <!-- TailwindCSS (includes px360.css with TomSelect overrides appended) -->
    <link rel="stylesheet" href="{% static 'dist/css/tailwind.css' %}">

    <!-- Lucide Icons -->
    <script src="{% static 'vendor/lucide/lucide.min.js' %}"></script>

    <!-- Fonts - Inter (LTR) + Noto Kufi Arabic (RTL) -->
    <link rel="stylesheet" href="{% static 'vendor/fonts/inter/latin.css' %}">
    <link rel="stylesheet" href="{% static 'vendor/fonts/noto-kufi-arabic/arabic.css' %}">

    <!-- SweetAlert2 -->
    <link rel="stylesheet" href="{% static 'vendor/sweetalert2/sweetalert2.min.css' %}">
    <script src="{% static 'vendor/sweetalert2/sweetalert2.all.min.js' %}"></script>

    <!-- Custom Styles -->
    <style>
        body {
            font-family: 'Inter', 'Noto Kufi Arabic', sans-serif;
        }
        [dir="rtl"] body,
        [dir="rtl"] input,
        [dir="rtl"] textarea,
        [dir="rtl"] select,
        [dir="rtl"] button {
            font-family: 'Noto Kufi Arabic', sans-serif;
        }

        /* Background Pattern */
        .public-bg {
            background: linear-gradient(135deg, #007bbd 0%, #005696 100%);
            min-height: 100vh;
            position: relative;
            overflow-x: hidden;
        }

        .public-bg::before {
            content: '';
            position: fixed;
            top: -100px;
            right: -100px;
            width: 200px;
            height: 200px;
            background: rgba(255,255,255,0.05);
            border-radius: 9999px;
            pointer-events: none;
            z-index: 0;
        }

        .public-bg::after {
            content: '';
            position: fixed;
            bottom: -75px;
            left: -75px;
            width: 150px;
            height: 150px;
            background: rgba(255,255,255,0.05);
            border-radius: 9999px;
            pointer-events: none;
            z-index: 0;
        }

        /* Glass morphism effect */
        .glass-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }

        /* RTL Support */
        [dir="rtl"] {
            text-align: right;
        }

        [dir="rtl"] .ms-2 {
            margin-left: 0;
            margin-right: 0.5rem;
        }

        /* Form Input Styles */
        .form-input {
            transition: all 0.2s ease;
        }

        .form-input:focus {
            transform: translateY(-1px);
        }

        /* Button hover effects */
        .btn-hover {
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .btn-hover:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 20px rgba(0, 86, 150, 0.2);
        }

        /* Custom scrollbar */
        ::-webkit-scrollbar {
            width: 8px;
            height: 8px;
        }

        ::-webkit-scrollbar-track {
            background: #f1f5f9;
        }

        ::-webkit-scrollbar-thumb {
            background: #cbd5e1;
            border-radius: 4px;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: #94a3b8;
        }

        /* Animations */
        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .animate-fade-in {
            animation: fadeIn 0.5s ease-out forwards;
        }

        @keyframes slideUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .animate-slide-up {
            animation: slideUp 0.4s ease-out forwards;
        }
    </style>

    {% block extra_css %}{% endblock %}
</head>
<body class="public-bg">
    <!-- Header -->
    <header class="glass-card shadow-lg sticky top-0 z-50">
        <div class="container mx-auto px-4 py-3">
            <div class="flex items-center justify-between">
                <div class="flex items-center gap-3">
                    {% load static %}
                    <div class="w-12 h-12 bg-white rounded-xl flex items-center justify-center shadow-md">
                        <img src="{% static 'img/hh-logo.png' %}" alt="HH Logo" class="h-8 w-auto object-contain">
                    </div>
                    <div>
                        <h1 class="text-xl font-bold text-navy">PX360</h1>
                        <p class="text-xs text-slate font-medium">{% trans "Patient Experience Management" %}</p>
                    </div>
                </div>

                <!-- Language Switcher -->
                <div class="flex items-center gap-2">
                    {% for lang_code, lang_name in LANGUAGES %}
                        <a href="{% url 'core:set_language' %}?language={{ lang_code }}"
                           class="px-4 py-2 rounded-xl border-2 transition-all duration-200 font-semibold text-sm flex items-center gap-2
                                  {% if LANGUAGE_CODE == lang_code %}
                                      border-navy bg-navy text-white shadow-md
                                  {% else %}
                                      border-navy/30 text-navy hover:bg-navy hover:text-white hover:border-navy
                                  {% endif %}">
                            <span class="text-lg">
                                {% if lang_code == 'en' %}🇬🇧{% elif lang_code == 'ar' %}🇸🇦{% endif %}
                            </span>
                            <span>{{ lang_name }}</span>
                        </a>
                    {% endfor %}
                </div>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="container mx-auto px-4 py-8">
        {% block content %}{% endblock %}
    </main>

    <!-- Footer -->
    <footer class="mt-12 py-6 bg-white/5 backdrop-blur-sm">
        <div class="container mx-auto px-4 text-center">
            <p class="text-white/70 text-sm">
                &copy; {% now "Y" %} <span class="font-semibold text-white">Al Hammadi Hospital</span> - PX360. {% trans "All rights reserved." %}
            </p>
            <p class="text-white/50 text-xs mt-2">
                {% trans "Your feedback helps us improve our services" %}
            </p>
            <p class="text-white/50 text-xs mt-1">
                Powered by <a href="https://tenhal.sa" target="_blank" class="text-white hover:text-white/80 hover:underline font-medium">tenhal.sa</a>
            </p>
        </div>
    </footer>

    <!-- TomSelect for searchable dropdowns -->
    <script src="https://cdn.jsdelivr.net/npm/tom-select@2.3.1/dist/js/tom-select.complete.min.js"></script>
    <script>
    document.addEventListener('DOMContentLoaded', function() {
        document.querySelectorAll('select[data-tomselect]').forEach(function(el) {
            var instance = new TomSelect(el, {
                create: false,
                allowEmptyOption: true,
                maxOptions: null,
                placeholder: el.querySelector('option[value=""]') ? el.querySelector('option[value=""]').textContent : 'Select...',
                sortField: {field: 'text', direction: 'asc'},
                dropdownParent: 'body',
            });
            if (el.hasAttribute('data-ts-compact')) {
                instance.wrapper.classList.add('ts-compact');
            }
        });
    });
    </script>

    {% block extra_js %}{% endblock %}
</body>
</html>
