<!DOCTYPE html>
<html lang="zh-hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}天璇{% endblock %}</title>
    <link rel="icon" type="image/svg+xml" href="/static/tianxuan/favicon.svg">
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f5f7fa; color: #1a1a2e; }
        nav { background: #1a1a2e; padding: 1rem 2rem; display: flex; align-items: center; gap: 2rem; }
        nav a { color: #e0e0e0; text-decoration: none; font-size: 0.95rem; }
        nav a:hover { color: #fff; }
        nav .brand { color: #fff; font-size: 1.2rem; font-weight: 700; }
        .container { max-width: 1200px; margin: 0 auto; padding: 2rem; }
        .card { background: #fff; border-radius: 8px; padding: 1.5rem; margin-bottom: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
        .card h2 { margin-bottom: 1rem; color: #1a1a2e; font-size: 1.1rem; }
        table { width: 100%; border-collapse: collapse; }
        th, td { text-align: left; padding: 0.75rem 0.5rem; border-bottom: 1px solid #eee; font-size: 0.9rem; }
        th { font-weight: 600; color: #666; }
        .badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 12px; font-size: 0.8rem; font-weight: 600; }
        .badge-success { background: #d4edda; color: #155724; }
        .badge-warning { background: #fff3cd; color: #856404; }
        .badge-info { background: #d1ecf1; color: #0c5460; }
        .badge-danger { background: #f8d7da; color: #721c24; }
        .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
        .grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1.5rem; }
        .stat { font-size: 2rem; font-weight: 700; color: #1a1a2e; }
        .stat-label { font-size: 0.85rem; color: #666; margin-top: 0.25rem; }
        .btn { display: inline-block; padding: 0.5rem 1rem; border-radius: 6px; text-decoration: none; font-size: 0.9rem; cursor: pointer; border: none; }
        .btn-primary { background: #4361ee; color: #fff; }
        .btn-primary:hover { background: #3a56d4; }
        .scatter-canvas { max-height: 500px; }
        .pagination { display: flex; justify-content: center; gap: 0.5rem; margin-top: 1.5rem; }
        .pagination a, .pagination span { padding: 0.4rem 0.8rem; border-radius: 4px; text-decoration: none; color: #4361ee; background: #fff; border: 1px solid #ddd; }
        .pagination .active { background: #4361ee; color: #fff; border-color: #4361ee; }
        .empty-state { text-align: center; padding: 3rem; color: #999; }
        .empty-state p { font-size: 1rem; margin-top: 0.5rem; }

        /* Toast notification system */
        #toastContainer {
            position: fixed; top: 1rem; right: 1rem; z-index: 9999;
            display: flex; flex-direction: column; gap: 0.5rem;
            pointer-events: none; max-width: 400px;
        }
        .toast {
            pointer-events: auto;
            padding: 0.85rem 1.25rem; border-radius: 8px;
            box-shadow: 0 4px 16px rgba(0,0,0,0.18);
            font-size: 0.9rem; line-height: 1.4;
            animation: toastSlideIn 0.3s ease-out;
            display: flex; align-items: flex-start; gap: 0.6rem;
            word-break: break-word;
        }
        .toast.toast-hiding { animation: toastSlideOut 0.25s ease-in forwards; }
        .toast-error { background: #dc3545; color: #fff; }
        .toast-success { background: #28a745; color: #fff; }
        .toast-warning { background: #e67e22; color: #fff; }
        .toast-icon { flex-shrink: 0; font-size: 1.1rem; line-height: 1.4; }
        .toast-close {
            margin-left: auto; cursor: pointer; opacity: 0.8; flex-shrink: 0;
            font-size: 1rem; line-height: 1.4; padding-left: 0.5rem; user-select: none;
        }
        .toast-close:hover { opacity: 1; }
        @keyframes toastSlideIn {
            from { transform: translateX(100%); opacity: 0; }
            to { transform: translateX(0); opacity: 1; }
        }
        @keyframes toastSlideOut {
            from { transform: translateX(0); opacity: 1; }
            to { transform: translateX(100%); opacity: 0; }
        }
    </style>
</head>
<body>
    <nav>
        <span class="brand">天璇</span>
        <a href="{% url 'analysis:dashboard' %}">首页</a>
        <a href="{% url 'analysis:upload' %}">上传数据</a>
        <a href="{% url 'analysis:manual' %}">手动分析</a>
        <a href="{% url 'analysis:auto' %}">LLM分析</a>
        <a href="{% url 'analysis:run_list' %}">运行记录</a>
        <a href="{% url 'analysis:globe' %}">态势</a>
        <a href="{% url 'analysis:config' %}">配置</a>
        <a href="{% url 'simple_analysis:index' %}" style="color:#f4a261;font-weight:600;">简单分析</a>
    </nav>
    <div class="container">
        {% block content %}{% endblock %}
    </div>

    <div id="toastContainer"></div>

    <script>
    function showError(msg) {
        if (!msg) return;
        const container = document.getElementById('toastContainer');
        const t = document.createElement('div');
        t.className = 'toast toast-error';
        t.innerHTML = '<span class="toast-icon">✕</span><span>' + escapeHtml(msg) + '</span><span class="toast-close" onclick="dismissToast(this.parentElement)">✕</span>';
        container.appendChild(t);
        setTimeout(() => dismissToast(t), 5000);
    }
    function showSuccess(msg) {
        if (!msg) return;
        const container = document.getElementById('toastContainer');
        const t = document.createElement('div');
        t.className = 'toast toast-success';
        t.innerHTML = '<span class="toast-icon">✓</span><span>' + escapeHtml(msg) + '</span><span class="toast-close" onclick="dismissToast(this.parentElement)">✕</span>';
        container.appendChild(t);
        setTimeout(() => dismissToast(t), 5000);
    }
    function showWarning(msg) {
        if (!msg) return;
        const container = document.getElementById('toastContainer');
        const t = document.createElement('div');
        t.className = 'toast toast-warning';
        t.innerHTML = '<span class="toast-icon">⚠</span><span>' + escapeHtml(msg) + '</span><span class="toast-close" onclick="dismissToast(this.parentElement)">✕</span>';
        container.appendChild(t);
        setTimeout(() => dismissToast(t), 6000);
    }
    function dismissToast(el) {
        if (!el || el.classList.contains('toast-hiding')) return;
        el.classList.add('toast-hiding');
        setTimeout(() => { if (el.parentNode) el.parentNode.removeChild(el); }, 250);
    }
    function escapeHtml(str) {
        if (str == null) return '';
        return String(str).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
    }

    // Global: catch unhandled promise rejections
    window.addEventListener('unhandledrejection', function (event) {
        const msg = event.reason && event.reason.message ? event.reason.message : String(event.reason || 'Unknown error');
        showError('未处理的错误: ' + msg);
    });
    </script>
</body>
</html>
