<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5">
    <title>{% block title %}服务监测{% endblock %} - 运行维护平台</title>
    <style>
        :root {
            --primary: #2563eb;
            --primary-hover: #1d4ed8;
            --green: #16a34a;
            --yellow: #d97706;
            --red: #dc2626;
            --gray-50: #f9fafb;
            --gray-100: #f3f4f6;
            --gray-200: #e5e7eb;
            --gray-400: #9ca3af;
            --gray-500: #6b7280;
            --gray-700: #374151;
            --gray-900: #111827;
        }
        * { box-sizing: border-box; margin: 0; padding: 0; }
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Microsoft YaHei", sans-serif;
            background: #f3f4f6;
            min-height: 100vh;
        }

        /* 侧边栏 */
        .sidebar {
            position: fixed;
            left: 0;
            top: 0;
            width: 200px;
            height: 100vh;
            background: linear-gradient(180deg, #1e293b 0%, #334155 100%);
            z-index: 100;
            transition: transform 0.3s ease;
        }
        .sidebar-brand {
            color: #fff;
            font-size: 18px;
            font-weight: 700;
            padding: 20px;
            border-bottom: 1px solid rgba(255,255,255,0.1);
        }
        .sidebar-nav {
            padding: 16px 0;
        }
        .nav-item {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 14px 20px;
            color: #94a3b8;
            text-decoration: none;
            font-size: 14px;
            transition: all 0.2s;
        }
        .nav-item:hover {
            background: rgba(255,255,255,0.05);
            color: #fff;
        }
        .nav-item.active {
            background: var(--primary);
            color: #fff;
        }
        .nav-icon {
            font-size: 16px;
            width: 20px;
            text-align: center;
        }

        /* 顶部条 */
        .topbar {
            position: fixed;
            left: 200px;
            top: 0;
            right: 0;
            height: 56px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 24px;
            z-index: 99;
        }
        .topbar-left {
            display: flex;
            align-items: center;
            gap: 16px;
        }
        .hamburger {
            display: none;
            background: rgba(255,255,255,0.2);
            border: 1px solid rgba(255,255,255,0.35);
            color: #fff;
            font-size: 18px;
            padding: 8px 12px;
            border-radius: 6px;
            cursor: pointer;
        }
        .topbar-home {
            background: rgba(255,255,255,0.2);
            color: #fff;
            border: 1px solid rgba(255,255,255,0.35);
            padding: 6px 14px;
            border-radius: 8px;
            font-size: 13px;
            font-weight: 600;
            text-decoration: none;
        }
        .topbar-home:hover {
            background: rgba(255,255,255,0.3);
        }
        .topbar-user {
            color: #fff;
            display: flex;
            align-items: center;
            gap: 14px;
            font-size: 14px;
        }
        .btn-logout {
            background: rgba(255,255,255,0.15);
            color: #fff;
            border: 1px solid rgba(255,255,255,0.3);
            padding: 8px 16px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 14px;
        }
        .btn-logout:hover {
            background: rgba(255,255,255,0.25);
        }

        /* 主内容区 */
        .main-content {
            margin-left: 200px;
            padding: 84px 24px 28px;
            min-height: 100vh;
        }

        /* 通用组件样式 */
        .section-head {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 16px;
        }
        .section-title {
            font-size: 18px;
            font-weight: 700;
            color: var(--gray-900);
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .btn-add {
            background: var(--primary);
            color: #fff;
            border: none;
            padding: 8px 16px;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            text-decoration: none;
        }
        .btn-add:hover {
            background: var(--primary-hover);
        }
        .empty {
            text-align: center;
            padding: 40px;
            color: var(--gray-500);
        }
        .footer {
            text-align: center;
            padding: 20px;
            color: var(--gray-500);
            font-size: 12px;
        }

        /* 移动端响应式 */
        @media screen and (max-width: 768px) {
            .sidebar {
                transform: translateX(-200px);
            }
            .sidebar.open {
                transform: translateX(0);
            }
            .topbar {
                left: 0;
            }
            .main-content {
                margin-left: 0;
                padding: 84px 14px 28px;
            }
            .hamburger {
                display: block;
            }
            .topbar-home {
                display: none;
            }
        }
    </style>
    {% block extra_css %}{% endblock %}
</head>
<body>
    <!-- 侧边栏 -->
    <aside class="sidebar" id="sidebar">
        <div class="sidebar-brand">🛠️ 运维</div>
        <nav class="sidebar-nav">
            <a href="/service-monitor" class="nav-item {{ 'active' if active_menu == 'targets' }}">
                <span class="nav-icon">📊</span>
                <span>监测目标</span>
            </a>
            <a href="/service-monitor/reports" class="nav-item {{ 'active' if active_menu == 'reports' }}">
                <span class="nav-icon">📋</span>
                <span>巡检报告</span>
            </a>
            <a href="/service-monitor/schedule" class="nav-item {{ 'active' if active_menu == 'schedule' }}">
                <span class="nav-icon">⏰</span>
                <span>定时任务</span>
            </a>
            {% if is_admin %}
            <a href="/service-monitor/notification" class="nav-item {{ 'active' if active_menu == 'notification' }}">
                <span class="nav-icon">🔔</span>
                <span>通知配置</span>
            </a>
            <a href="/service-monitor/targets" class="nav-item {{ 'active' if active_menu == 'manage' }}">
                <span class="nav-icon">⚙️</span>
                <span>目标管理</span>
            </a>
            {% endif %}
        </nav>
    </aside>

    <!-- 顶部条 -->
    <header class="topbar">
        <div class="topbar-left">
            <button class="hamburger" id="hamburger" onclick="toggleSidebar()">☰</button>
            <a href="/" class="topbar-home">🏠 返回首页</a>
        </div>
        <div class="topbar-user">
            <span>{{ user.username }}（{{ '管理员' if is_admin else '用户' }}）</span>
            <button class="btn-logout" onclick="handleLogout()">🚪 退出</button>
        </div>
    </header>

    <!-- 主内容区 -->
    <main class="main-content">
        {% block content %}{% endblock %}
    </main>

    {% if not no_footer %}
    <div class="footer">运行维护平台 · 服务监测模块</div>
    {% endif %}

    <script>
        function toggleSidebar() {
            document.getElementById('sidebar').classList.toggle('open');
        }

        // 点击遮罩关闭侧边栏
        document.addEventListener('click', function(e) {
            const sidebar = document.getElementById('sidebar');
            const hamburger = document.getElementById('hamburger');
            if (sidebar.classList.contains('open') &&
                !sidebar.contains(e.target) &&
                !hamburger.contains(e.target)) {
                sidebar.classList.remove('open');
            }
        });

        async function handleLogout() {
            try {
                await fetch('/logout', {
                    method: 'POST',
                    headers: {'Content-Type': 'application/json'},
                    credentials: 'include'
                });
            } catch (e) {}
            window.location.href = '/login';
        }
    </script>
    {% block extra_js %}{% endblock %}
</body>
</html>