{% load i18n hospital_filters %}
<!DOCTYPE html>
<html lang="{% get_current_language as LANGUAGE_CODE %}{{ 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">
    <meta name="theme-color" content="#0097a7">
    <title>{% block title %}{% trans "PX360 - Patient Experience Management" %}{% endblock %}</title>
    
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    
    <!-- Bootstrap Icons -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
    
    <!-- Google Fonts - Arabic Support -->
    <link href="https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700&family=Open+Sans:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    
    <!-- ApexCharts -->
    <script src="https://cdn.jsdelivr.net/npm/apexcharts@3.45.1/dist/apexcharts.min.js"></script>
    
    <!-- HTMX for dynamic updates -->
    <script src="https://unpkg.com/htmx.org@1.9.10"></script>
    
    <!-- Select2 for better selects -->
    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
    <link href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" rel="stylesheet" />
    
    <!-- Al Hammadi Theme CSS -->
    <style>
        /* ============================================
           AL HAMMADI HOSPITAL THEME - PX360
           Color Palette:
           - Primary Teal: #0097a7 / #00838f
           - Red Accent: #c62828 / #d32f2f
           - Dark Blue: #1a237e / #283593
           - Light Teal: #4dd0e1 / #80deea
           ============================================ */
        
        :root {
            /* Layout Variables */
            --sidebar-width: 260px;
            --topbar-height: 60px;
            
            /* Al Hammadi Color Palette */
            --hh-primary: #0086d2;
            --hh-primary-dark: #005d93;
            --hh-primary-light: #4caadf;
            --hh-primary-lighter: #b2ebf2;
            --hh-primary-bg: rgba(0, 151, 167, 0.1);
            
            --hh-secondary: #1a237e;
            --hh-secondary-dark: #0d1642;
            --hh-secondary-light: #283593;
            
            --hh-accent: #c62828;
            --hh-accent-light: #d32f2f;
            --hh-accent-dark: #b71c1c;
            
            --hh-success: #00897b;
            --hh-success-light: #26a69a;
            --hh-warning: #f9a825;
            --hh-warning-light: #fbc02d;
            --hh-danger: #c62828;
            --hh-info: #0097a7;
            
            --hh-text-dark: #263238;
            --hh-text-muted: #607d8b;
            --hh-text-light: #90a4ae;
            
            --hh-bg-light: #f5f7fa;
            --hh-bg-white: #ffffff;
            --hh-border: #e0e6ed;
            
            /* Shadows */
            --hh-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
            --hh-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            --hh-shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
        }
        
        /* ============================================
           TYPOGRAPHY
           ============================================ */
        body {
            font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background-color: var(--hh-bg-light);
            color: var(--hh-text-dark);
        }
        
        [dir="rtl"] body {
            font-family: 'Cairo', 'Open Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        }
        
        h1, h2, h3, h4, h5, h6 {
            font-weight: 600;
            color: var(--hh-text-dark);
        }
        
        a {
            color: var(--hh-primary);
            text-decoration: none;
            transition: color 0.2s ease;
        }
        
        a:hover {
            color: var(--hh-primary-dark);
        }
        
        /* ============================================
           SIDEBAR - Al Hammadi Teal Theme (Simplified for Source Users)
           ============================================ */
        .sidebar {
            position: fixed;
            top: 0;
            left: 0;
            height: 100vh;
            width: var(--sidebar-width);
            background: linear-gradient(180deg, var(--hh-primary-dark) 0%, var(--hh-primary) 50%, var(--hh-primary-dark) 100%);
            color: white;
            overflow-y: auto;
            z-index: 1000;
            box-shadow: 2px 0 15px rgba(0, 0, 0, 0.15);
        }
        
        .sidebar-brand {
            padding: 1.5rem 1rem;
            font-size: 1.4rem;
            font-weight: 700;
            border-bottom: 1px solid rgba(255,255,255, 0.15);
            background: rgba(0, 0, 0, 0.1);
            display: flex;
            align-items: center;
            gap: 0.75rem;
        }
        
        .sidebar-brand i {
            color: var(--hh-accent);
            font-size: 1.6rem;
        }
        
        .sidebar-nav {
            padding: 1rem 0;
        }
        
        .sidebar-nav .nav-link {
            color: rgba(255, 255, 255, 0.85);
            padding: 0.75rem 1.25rem;
            border-left: 3px solid transparent;
            transition: all 0.25s ease;
            display: flex;
            align-items: center;
            font-size: 0.95rem;
        }
        
        .sidebar-nav .nav-link:hover {
            color: white;
            background: rgba(255, 255, 255, 0.1);
            border-left-color: var(--hh-accent);
        }
        
        .sidebar-nav .nav-link.active {
            color: white;
            background: rgba(255, 255, 255, 0.15);
            border-left-color: var(--hh-accent);
            font-weight: 600;
        }
        
        .sidebar-nav .nav-link i {
            width: 24px;
            margin-right: 0.75rem;
            font-size: 1.15rem;
        }
        
        .sidebar-nav .badge {
            margin-left: auto;
            font-size: 0.7rem;
            padding: 0.3em 0.6em;
        }
        
        .sidebar-nav .badge.bg-danger {
            background-color: var(--hh-accent) !important;
        }
        
        .sidebar-nav .badge.bg-success {
            background-color: var(--hh-success) !important;
        }
        
        .sidebar-nav .badge.bg-warning {
            background-color: var(--hh-warning) !important;
            color: var(--hh-text-dark) !important;
        }
        
        .sidebar-nav .badge.bg-info {
            background-color: var(--hh-primary-light) !important;
        }
        
        .sidebar-nav hr {
            border-color: rgba(255, 255, 255, 0.1);
            margin: 1rem 1rem;
        }
        
        /* ============================================
           TOPBAR
           ============================================ */
        .topbar {
            position: fixed;
            top: 0;
            left: var(--sidebar-width);
            right: 0;
            height: var(--topbar-height);
            background: var(--hh-bg-white);
            border-bottom: 1px solid var(--hh-border);
            z-index: 999;
            box-shadow: var(--hh-shadow-sm);
            display: flex;
            align-items: center;
            padding: 0 1.5rem;
            justify-content: space-between;
        }
        
        .topbar .navbar-brand {
            color: var(--hh-primary);
            font-weight: 600;
        }
        
        .topbar .nav-link {
            color: var(--hh-text-muted);
            padding: 0.5rem 0.75rem;
        }
        
        .topbar .nav-link:hover {
            color: var(--hh-primary);
        }
        
        .topbar .dropdown-menu {
            border: 1px solid var(--hh-border);
            box-shadow: var(--hh-shadow);
        }
        
        /* ============================================
           MAIN CONTENT
           ============================================ */
        .main-content {
            margin-left: var(--sidebar-width);
            margin-top: var(--topbar-height);
            padding: 1.5rem 2rem;
            min-height: calc(100vh - var(--topbar-height));
            background: var(--hh-bg-light);
        }
        
        /* ============================================
           CARDS - Al Hammadi Style
           ============================================ */
        .card {
            border: none;
            border-radius: 0.5rem;
            box-shadow: var(--hh-shadow-sm);
            margin-bottom: 1.5rem;
            background: var(--hh-bg-white);
            transition: box-shadow 0.2s ease, transform 0.2s ease;
        }
        
        .card:hover {
            box-shadow: var(--hh-shadow);
        }
        
        .card-header {
            background: var(--hh-bg-white);
            border-bottom: 1px solid var(--hh-border);
            padding: 1rem 1.25rem;
            font-weight: 600;
            color: var(--hh-text-dark);
        }
        
        .card-header.bg-primary,
        .card-header.bg-teal {
            background: linear-gradient(135deg, var(--hh-primary) 0%, var(--hh-primary-dark) 100%) !important;
            color: white;
            border-bottom: none;
        }
        
        .card-title {
            font-size: 1rem;
            font-weight: 600;
            color: var(--hh-text-dark);
            margin-bottom: 0;
        }
        
        .card-body {
            padding: 1.25rem;
        }
        
        /* Stat Cards */
        .stat-card {
            border: none;
            border-radius: 0.5rem;
            box-shadow: var(--hh-shadow-sm);
            transition: transform 0.2s ease, box-shadow 0.2s ease;
            overflow: hidden;
        }
        
        .stat-card:hover {
            transform: translateY(-3px);
            box-shadow: var(--hh-shadow-lg);
        }
        
        .stat-card .card-body {
            padding: 1.5rem;
            position: relative;
        }
        
        .stat-card .stat-icon {
            position: absolute;
            top: 1rem;
            right: 1rem;
            width: 48px;
            height: 48px;
            border-radius: 0.5rem;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.5rem;
        }
        
        [dir="rtl"] .stat-card .stat-icon {
            right: auto;
            left: 1rem;
        }
        
        .stat-card .stat-icon.bg-teal {
            background: var(--hh-primary-bg);
            color: var(--hh-primary);
        }
        
        .stat-card .stat-icon.bg-red {
            background: rgba(198, 40, 40, 0.1);
            color: var(--hh-accent);
        }
        
        .stat-card .stat-icon.bg-blue {
            background: rgba(26, 35, 126, 0.1);
            color: var(--hh-secondary);
        }
        
        .stat-card .stat-icon.bg-green {
            background: rgba(0, 137, 123, 0.1);
            color: var(--hh-success);
        }
        
        .stat-value {
            font-size: 2rem;
            font-weight: 700;
            color: var(--hh-text-dark);
            margin: 0.25rem 0;
            line-height: 1.2;
        }
        
        .stat-label {
            color: var(--hh-text-muted);
            font-size: 0.8rem;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            font-weight: 600;
        }
        
        /* ============================================
           BUTTONS - Al Hammadi Style
           ============================================ */
        .btn {
            font-weight: 500;
            padding: 0.5rem 1rem;
            border-radius: 0.375rem;
            transition: all 0.2s ease;
        }
        
        .btn-primary {
            background-color: var(--hh-primary);
            border-color: var(--hh-primary);
        }
        
        .btn-primary:hover,
        .btn-primary:focus {
            background-color: var(--hh-primary-dark);
            border-color: var(--hh-primary-dark);
        }
        
        .btn-secondary {
            background-color: var(--hh-secondary);
            border-color: var(--hh-secondary);
        }
        
        .btn-danger {
            background-color: var(--hh-accent);
            border-color: var(--hh-accent);
        }
        
        .btn-success {
            background-color: var(--hh-success);
            border-color: var(--hh-success);
        }
        
        .btn-warning {
            background-color: var(--hh-warning);
            border-color: var(--hh-warning);
            color: var(--hh-text-dark);
        }
        
        .btn-info {
            background-color: var(--hh-primary-light);
            border-color: var(--hh-primary-light);
        }
        
        .btn-outline-primary {
            color: var(--hh-primary);
            border-color: var(--hh-primary);
        }
        
        .btn-outline-primary:hover {
            background-color: var(--hh-primary);
            border-color: var(--hh-primary);
            color: white;
        }
        
        /* ============================================
           TABLES
           ============================================ */
        .table {
            margin-bottom: 0;
        }
        
        .table thead th {
            background: var(--hh-bg-light);
            border-bottom: 2px solid var(--hh-border);
            color: var(--hh-text-dark);
            font-weight: 600;
            font-size: 0.85rem;
            text-transform: uppercase;
            letter-spacing: 0.03em;
            padding: 0.875rem 1rem;
        }
        
        .table tbody td {
            padding: 0.875rem 1rem;
            vertical-align: middle;
            border-bottom: 1px solid var(--hh-border);
            color: var(--hh-text-dark);
        }
        
        .table tbody tr:hover {
            background-color: var(--hh-primary-bg);
        }
        
        /* ============================================
           BADGES
           ============================================ */
        .badge {
            padding: 0.4em 0.7em;
            font-weight: 600;
            font-size: 0.75rem;
            border-radius: 0.25rem;
        }
        
        .badge.bg-primary {
            background-color: var(--hh-primary) !important;
        }
        
        .badge.bg-secondary {
            background-color: var(--hh-secondary) !important;
        }
        
        .badge.bg-success {
            background-color: var(--hh-success) !important;
        }
        
        .badge.bg-danger {
            background-color: var(--hh-accent) !important;
        }
        
        .badge.bg-warning {
            background-color: var(--hh-warning) !important;
            color: var(--hh-text-dark) !important;
        }
        
        .badge.bg-info {
            background-color: var(--hh-primary-light) !important;
        }
        
        /* ============================================
           FORMS
           ============================================ */
        .form-control {
            border: 1px solid var(--hh-border);
            border-radius: 0.375rem;
            padding: 0.5rem 0.875rem;
            transition: border-color 0.2s ease, box-shadow 0.2s ease;
        }
        
        .form-control:focus {
            border-color: var(--hh-primary);
            box-shadow: 0 0 0 0.2rem var(--hh-primary-bg);
        }
        
        .form-label {
            font-weight: 500;
            color: var(--hh-text-dark);
            margin-bottom: 0.375rem;
        }
        
        /* ============================================
           ALERTS
           ============================================ */
        .alert {
            border: none;
            border-radius: 0.375rem;
            padding: 1rem 1.25rem;
        }
        
        .alert-primary {
            background-color: var(--hh-primary-bg);
            color: var(--hh-primary-dark);
        }
        
        .alert-success {
            background-color: rgba(0, 137, 123, 0.1);
            color: var(--hh-success);
        }
        
        .alert-danger {
            background-color: rgba(198, 40, 40, 0.1);
            color: var(--hh-accent);
        }
        
        .alert-info {
            background-color: var(--hh-primary-bg);
            color: var(--hh-primary);
        }
        
        /* ============================================
           RTL SUPPORT
           ============================================ */
        [dir="rtl"] .sidebar {
            left: auto;
            right: 0;
            border-left: none;
            border-right: none;
        }
        
        [dir="rtl"] .sidebar-nav .nav-link {
            border-left: none;
            border-right: 3px solid transparent;
        }
        
        [dir="rtl"] .sidebar-nav .nav-link:hover,
        [dir="rtl"] .sidebar-nav .nav-link.active {
            border-left-color: transparent;
            border-right-color: var(--hh-accent);
        }
        
        [dir="rtl"] .sidebar-nav .nav-link i {
            margin-right: 0;
            margin-left: 0.75rem;
        }
        
        [dir="rtl"] .sidebar-nav .badge {
            margin-left: 0;
            margin-right: auto;
        }
        
        [dir="rtl"] .topbar {
            left: 0;
            right: var(--sidebar-width);
        }
        
        [dir="rtl"] .main-content {
            margin-left: 0;
            margin-right: var(--sidebar-width);
        }
        
        /* ============================================
           RESPONSIVE
           ============================================ */
        @media (max-width: 991.98px) {
            .sidebar {
                transform: translateX(-100%);
                transition: transform 0.3s ease;
            }
            
            .sidebar.show {
                transform: translateX(0);
            }
            
            [dir="rtl"] .sidebar {
                transform: translateX(100%);
            }
            
            [dir="rtl"] .sidebar.show {
                transform: translateX(0);
            }
            
            .topbar {
                left: 0;
                right: 0;
            }
            
            [dir="rtl"] .topbar {
                left: 0;
                right: 0;
            }
            
            .main-content {
                margin-left: 0;
                margin-right: 0;
                padding: 1rem;
            }
            
            [dir="rtl"] .main-content {
                margin-left: 0;
                margin-right: 0;
            }
        }
    </style>
    
    {% block extra_css %}{% endblock %}
</head>
<body>
    <!-- Simplified Sidebar for Source Users -->
    <div class="sidebar">
        <!-- Brand -->
        <div class="sidebar-brand">
            <i class="bi bi-heart-pulse-fill"></i> PX360
        </div>

        <!-- Navigation -->
        <nav class="sidebar-nav">
            <ul class="nav flex-column">
                <!-- Dashboard -->
                <li class="nav-item">
                    <a class="nav-link {% if request.resolver_match.url_name == 'source_user_dashboard' %}active{% endif %}"
                       href="{% url 'px_sources:source_user_dashboard' %}">
                        <i class="bi bi-speedometer2"></i>
                        {% trans "Dashboard" %}
                    </a>
                </li>

                <hr>

                <!-- Create Complaint -->
                <li class="nav-item">
                    <a class="nav-link {% if request.resolver_match.url_name == 'complaint_create' %}active{% endif %}"
                       href="{% url 'complaints:complaint_create' %}">
                        <i class="bi bi-plus-circle"></i>
                        {% trans "Create Complaint" %}
                    </a>
                </li>

                <!-- Create Inquiry -->
                <li class="nav-item">
                    <a class="nav-link {% if request.resolver_match.url_name == 'inquiry_create' %}active{% endif %}"
                       href="{% url 'complaints:inquiry_create' %}">
                        <i class="bi bi-plus-circle"></i>
                        {% trans "Create Inquiry" %}
                    </a>
                </li>

                <hr>

                <!-- My Complaints -->
                <li class="nav-item">
                    <a class="nav-link {% if 'source_user_complaint_list' in request.path %}active{% endif %}"
                       href="{% url 'px_sources:source_user_complaint_list' %}">
                        <i class="bi bi-exclamation-triangle"></i>
                        {% trans "My Complaints" %}
                    </a>
                </li>

                <!-- My Inquiries -->
                <li class="nav-item">
                    <a class="nav-link {% if 'source_user_inquiry_list' in request.path %}active{% endif %}"
                       href="{% url 'px_sources:source_user_inquiry_list' %}">
                        <i class="bi bi-question-circle"></i>
                        {% trans "My Inquiries" %}
                    </a>
                </li>

                <!-- Logout -->
                <li class="nav-item">
                    <a class="nav-link" href="{% url 'accounts:logout' %}">
                        <i class="bi bi-box-arrow-right"></i>
                        {% trans "Logout" %}
                    </a>
                </li>
            </ul>
        </nav>
    </div>

    <!-- Topbar -->
    <div class="topbar">
        <div class="d-flex align-items-center">
            <!-- Toggle Sidebar (Mobile) -->
            <button class="btn btn-outline-secondary me-3 d-lg-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#sidebarOffcanvas">
                <i class="bi bi-list"></i>
            </button>

            <!-- Hospital Display -->
            {% if current_hospital %}
            <div class="d-flex align-items-center">
                <i class="bi bi-hospital me-2 text-primary"></i>
                <div>
                    <div class="fw-semibold" style="font-size: 0.9rem;">
                        {{ current_hospital.name|truncatewords:3 }}
                    </div>
                    <div class="text-muted" style="font-size: 0.75rem;">
                        {% if current_hospital.city %}{{ current_hospital.city }}{% endif %}
                    </div>
                </div>
            </div>
            {% endif %}
        </div>

        <!-- User Menu -->
        <div class="d-flex align-items-center">
            <div class="dropdown">
                <button class="btn btn-light d-flex align-items-center" type="button" data-bs-toggle="dropdown">
                    <i class="bi bi-person-circle me-2 text-primary"></i>
                    <div class="text-start">
                        <div class="fw-semibold" style="font-size: 0.85rem;">
                            {{ request.user.get_full_name|truncatewords:2 }}
                        </div>
                        <div class="text-muted" style="font-size: 0.75rem;">
                            {{ request.user.email|truncatewords:2 }}
                        </div>
                    </div>
                    <i class="bi bi-chevron-down text-muted"></i>
                </button>
                <ul class="dropdown-menu dropdown-menu-end">
                    <li>
                        <a class="dropdown-item" href="{% url 'accounts:password_change' %}">
                            <i class="bi bi-key me-2"></i>{% trans "Change Password" %}
                        </a>
                    </li>
                    <li><hr class="dropdown-divider"></li>
                    <li>
                        <a class="dropdown-item text-danger" href="{% url 'accounts:logout' %}">
                            <i class="bi bi-box-arrow-right me-2"></i>{% trans "Logout" %}
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="main-content">
        <!-- Flash Messages -->
        {% include 'layouts/partials/flash_messages.html' %}
        
        <!-- Page Content -->
        {% block content %}{% endblock %}
    </div>

    <!-- Mobile Sidebar Offcanvas -->
    <div class="offcanvas offcanvas-start" tabindex="-1" id="sidebarOffcanvas" aria-labelledby="sidebarOffcanvasLabel">
        <div class="offcanvas-header">
            <h5 class="offcanvas-title" id="sidebarOffcanvasLabel">
                <i class="bi bi-heart-pulse-fill me-2"></i> PX360
            </h5>
            <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
        </div>
        <div class="offcanvas-body">
            <nav class="sidebar-nav">
                <ul class="nav flex-column">
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'px_sources:source_user_dashboard' %}">
                            <i class="bi bi-speedometer2"></i>{% trans "Dashboard" %}
                        </a>
                    </li>
                    <hr>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'complaints:complaint_create' %}">
                            <i class="bi bi-plus-circle"></i>{% trans "Create Complaint" %}
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'complaints:inquiry_create' %}">
                            <i class="bi bi-plus-circle"></i>{% trans "Create Inquiry" %}
                        </a>
                    </li>
                    <hr>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'px_sources:source_user_complaint_list' %}">
                            <i class="bi bi-exclamation-triangle"></i>{% trans "My Complaints" %}
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'px_sources:source_user_inquiry_list' %}">
                            <i class="bi bi-question-circle"></i>{% trans "My Inquiries" %}
                        </a>
                    </li>
                    <hr>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'accounts:logout' %}">
                            <i class="bi bi-box-arrow-right"></i>{% trans "Logout" %}
                        </a>
                    </li>
                </ul>
            </nav>
        </div>
    </div>

    <!-- jQuery (required for Select2) -->
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
    
    <!-- Bootstrap 5 JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    
    <!-- Select2 -->
    <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
    
    <!-- Initialize Select2 -->
    <script>
        $(document).ready(function() {
            $('.select2').select2({
                theme: 'bootstrap-5'
            });
        });
    </script>
    
    {% block extra_js %}{% endblock %}
</body>
</html>
</html>
