<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}Llamaball - Document Chat & RAG System{% endblock %}</title>
    
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
    <!-- Custom CSS -->
    <style>
        :root {
            --primary-color: #00D4AA;
            --secondary-color: #0066CC;
            --success-color: #00C851;
            --warning-color: #FFB84D;
            --error-color: #FF4444;
            --info-color: #33B5E5;
            --muted-color: #6C757D;
            --accent-color: #9C27B0;
            --highlight-color: #FFD700;
        }
        
        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        .navbar {
            background: rgba(255, 255, 255, 0.95) !important;
            backdrop-filter: blur(10px);
            border-bottom: 1px solid rgba(255, 255, 255, 0.2);
        }
        
        .navbar-brand {
            font-weight: bold;
            color: var(--primary-color) !important;
            font-size: 1.5rem;
        }
        
        .main-container {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 15px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
            margin: 2rem auto;
            padding: 2rem;
            max-width: 1200px;
        }
        
        .card {
            border: none;
            border-radius: 15px;
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
        }
        
        .btn-primary {
            background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
            border: none;
            border-radius: 25px;
            padding: 0.75rem 2rem;
            font-weight: 600;
            transition: all 0.3s ease;
        }
        
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 16px rgba(0, 212, 170, 0.3);
        }
        
        .btn-success {
            background: linear-gradient(45deg, var(--success-color), #28a745);
            border: none;
            border-radius: 25px;
        }
        
        .btn-warning {
            background: linear-gradient(45deg, var(--warning-color), #ffc107);
            border: none;
            border-radius: 25px;
        }
        
        .btn-info {
            background: linear-gradient(45deg, var(--info-color), #17a2b8);
            border: none;
            border-radius: 25px;
        }
        
        .alert {
            border: none;
            border-radius: 15px;
            border-left: 4px solid;
        }
        
        .alert-success {
            border-left-color: var(--success-color);
            background: rgba(0, 200, 81, 0.1);
        }
        
        .alert-warning {
            border-left-color: var(--warning-color);
            background: rgba(255, 184, 77, 0.1);
        }
        
        .alert-danger {
            border-left-color: var(--error-color);
            background: rgba(255, 68, 68, 0.1);
        }
        
        .alert-info {
            border-left-color: var(--info-color);
            background: rgba(51, 181, 229, 0.1);
        }
        
        .progress {
            height: 8px;
            border-radius: 10px;
            background: rgba(0, 0, 0, 0.1);
        }
        
        .progress-bar {
            background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
            border-radius: 10px;
        }
        
        .form-control, .form-select {
            border-radius: 10px;
            border: 2px solid rgba(0, 0, 0, 0.1);
            transition: border-color 0.3s ease;
        }
        
        .form-control:focus, .form-select:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 0.2rem rgba(0, 212, 170, 0.25);
        }
        
        .stat-card {
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            color: white;
            border-radius: 15px;
            padding: 1.5rem;
            text-align: center;
            margin-bottom: 1rem;
        }
        
        .stat-number {
            font-size: 2.5rem;
            font-weight: bold;
            margin-bottom: 0.5rem;
        }
        
        .stat-label {
            font-size: 0.9rem;
            opacity: 0.9;
        }
        
        .chat-container {
            height: 500px;
            overflow-y: auto;
            border: 2px solid rgba(0, 0, 0, 0.1);
            border-radius: 15px;
            padding: 1rem;
            background: rgba(255, 255, 255, 0.5);
        }
        
        .message {
            margin-bottom: 1rem;
            padding: 1rem;
            border-radius: 15px;
            max-width: 80%;
        }
        
        .message.user {
            background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
            color: white;
            margin-left: auto;
        }
        
        .message.assistant {
            background: rgba(255, 255, 255, 0.9);
            border: 2px solid rgba(0, 0, 0, 0.1);
        }
        
        .loading {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 3px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top-color: white;
            animation: spin 1s ease-in-out infinite;
        }
        
        @keyframes spin {
            to { transform: rotate(360deg); }
        }
        
        .footer {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-top: 1px solid rgba(0, 0, 0, 0.1);
            padding: 2rem 0;
            margin-top: 3rem;
        }
        
        .nav-link {
            color: var(--muted-color) !important;
            font-weight: 500;
            transition: color 0.3s ease;
        }
        
        .nav-link:hover, .nav-link.active {
            color: var(--primary-color) !important;
        }
        
        .file-upload-area {
            border: 3px dashed var(--primary-color);
            border-radius: 15px;
            padding: 3rem;
            text-align: center;
            background: rgba(0, 212, 170, 0.05);
            transition: all 0.3s ease;
            cursor: pointer;
        }
        
        .file-upload-area:hover {
            background: rgba(0, 212, 170, 0.1);
            border-color: var(--secondary-color);
        }
        
        .file-upload-area.dragover {
            background: rgba(0, 212, 170, 0.2);
            border-color: var(--accent-color);
        }
        
        .badge {
            border-radius: 10px;
            padding: 0.5rem 1rem;
        }
        
        .badge-primary {
            background: var(--primary-color);
        }
        
        .badge-success {
            background: var(--success-color);
        }
        
        .badge-warning {
            background: var(--warning-color);
        }
        
        .badge-info {
            background: var(--info-color);
        }
    </style>
    
    {% block extra_css %}{% endblock %}
</head>
<body>
    <!-- Navigation -->
    <nav class="navbar navbar-expand-lg navbar-light fixed-top">
        <div class="container">
            <a class="navbar-brand" href="{{ url_for('index') }}">
                <i class="bi bi-chat-dots-fill"></i> Llamaball
            </a>
            
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('index') }}">
                            <i class="bi bi-house-fill"></i> Dashboard
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('chat_page') }}">
                            <i class="bi bi-chat-fill"></i> Chat
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('upload_page') }}">
                            <i class="bi bi-cloud-upload-fill"></i> Upload
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('stats_page') }}">
                            <i class="bi bi-graph-up"></i> Statistics
                        </a>
                    </li>
                </ul>
                
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" href="/api/health" target="_blank">
                            <i class="bi bi-heart-pulse-fill"></i> Health
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    
    <!-- Main Content -->
    <div class="container" style="margin-top: 100px;">
        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="alert alert-{{ 'danger' if category == 'error' else category }} alert-dismissible fade show" role="alert">
                        <i class="bi bi-{{ 'exclamation-triangle-fill' if category == 'error' else 'info-circle-fill' }}"></i>
                        {{ message }}
                        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                    </div>
                {% endfor %}
            {% endif %}
        {% endwith %}
        
        <div class="main-container">
            {% block content %}{% endblock %}
        </div>
    </div>
    
    <!-- Footer -->
    <footer class="footer">
        <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <h5><i class="bi bi-chat-dots-fill"></i> Llamaball</h5>
                    <p class="text-muted">Accessible, ethical, and actually useful document chat and RAG system.</p>
                </div>
                <div class="col-md-6 text-end">
                    <p class="text-muted">
                        Built with ❤️ for accessibility and local AI<br>
                        <small>Powered by Ollama • Version 1.1.0</small>
                    </p>
                </div>
            </div>
        </div>
    </footer>
    
    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    
    <!-- Common JavaScript -->
    <script>
        // Global utilities
        function showAlert(message, type = 'info') {
            const alertDiv = document.createElement('div');
            alertDiv.className = `alert alert-${type} alert-dismissible fade show`;
            alertDiv.innerHTML = `
                <i class="bi bi-info-circle-fill"></i>
                ${message}
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            `;
            
            const container = document.querySelector('.container');
            container.insertBefore(alertDiv, container.firstChild);
            
            // Auto-dismiss after 5 seconds
            setTimeout(() => {
                alertDiv.remove();
            }, 5000);
        }
        
        function formatFileSize(bytes) {
            if (bytes === 0) return '0 Bytes';
            const k = 1024;
            const sizes = ['Bytes', 'KB', 'MB', 'GB'];
            const i = Math.floor(Math.log(bytes) / Math.log(k));
            return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
        }
        
        function formatDate(timestamp) {
            return new Date(timestamp * 1000).toLocaleString();
        }
        
        // Set active nav link
        document.addEventListener('DOMContentLoaded', function() {
            const currentPath = window.location.pathname;
            const navLinks = document.querySelectorAll('.nav-link');
            
            navLinks.forEach(link => {
                if (link.getAttribute('href') === currentPath) {
                    link.classList.add('active');
                }
            });
        });
    </script>
    
    {% block extra_js %}{% endblock %}
</body>
</html> 