/* ===== 全局变量与基础 ===== */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --info: #06b6d4;
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    font-size: 14px;
    line-height: 1.6;
}

a { color: var(--primary); }
a:hover { color: var(--primary-dark); }

/* ===== 导航侧边栏 ===== */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 220px;
    background: linear-gradient(180deg, #1a2744 0%, #15203a 100%);
    color: #fff;
    z-index: 1040;
    overflow-y: auto;
    transition: transform 0.3s ease;
}
.sidebar .brand {
    display: flex; align-items: center; gap: 10px;
    padding: 20px 16px;
    font-size: 18px; font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar .nav-link {
    color: rgba(255,255,255,0.75);
    padding: 10px 20px;
    display: flex; align-items: center; gap: 10px;
    text-decoration: none;
    font-size: 14px;
    border-radius: 6px;
    margin: 2px 8px;
    transition: all 0.2s;
}
.sidebar .nav-link:hover { background: rgba(255,255,255,0.1); color: #fff; }
.sidebar .nav-link.active { background: var(--primary); color: #fff; }

/* ===== 主内容区 ===== */
.main-content {
    margin-left: 220px;
    padding: 20px 24px;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}
.page-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px;
}

/* ===== 卡片 ===== */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s, transform 0.15s;
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    font-weight: 600;
}
.card-body { padding: 16px; }
.card-footer { background: var(--card-bg); border-top: 1px solid var(--border); padding: 8px 16px; }

.stat-card { cursor: pointer; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

/* ===== 表格 ===== */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table thead th {
    background: #f8fafc;
    border-bottom: 2px solid var(--border);
    padding: 10px 12px;
    font-weight: 600;
    white-space: nowrap;
    color: var(--text-muted);
    text-transform: none;
}
.table tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:nth-child(even) { background: #fafbfc; }
.table tbody tr:hover { background: #f0f4ff; }
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* 排序 */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #eef2ff; color: var(--primary); }
th.sortable.asc .sort-arrow,
th.sortable.desc .sort-arrow { color: var(--primary); }
.sort-arrow { margin-left: 4px; font-size: 11px; color: #cbd5e1; }

/* 截图缩略图 */
.screenshot-thumb {
    width: 60px; height: 60px; object-fit: cover;
    border-radius: 4px; border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.15s;
}
.screenshot-thumb:hover { transform: scale(1.08); }

/* 全屏遮罩查看图片 */
.img-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85); z-index: 9999;
    justify-content: center; align-items: center; cursor: pointer;
}
.img-overlay.show { display: flex; }
.img-overlay img { max-width: 95vw; max-height: 95vh; object-fit: contain; border-radius: 8px; }
.img-overlay .img-close {
    position: absolute; top: 16px; right: 24px; color: #fff; font-size: 32px;
    cursor: pointer; z-index: 10000;
}

/* ===== 按钮 ===== */
.btn {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 8px 16px; font-size: 14px; font-weight: 500;
    border-radius: 6px; border: 1px solid transparent;
    cursor: pointer; transition: all 0.15s;
    text-decoration: none;
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline-primary { background: transparent; border-color: var(--primary); color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); color: #fff; }
.btn-outline-secondary { background: transparent; border-color: #cbd5e1; color: var(--text-muted); }
.btn-outline-secondary:hover { background: #f1f5f9; }
.btn-outline-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-secondary { background: #64748b; color: #fff; }
.btn-secondary:hover { background: #475569; }

/* ===== 表单 ===== */
.form-control, .form-select {
    width: 100%; padding: 8px 12px;
    border: 1px solid var(--border); border-radius: 6px;
    font-size: 14px; transition: border-color 0.15s;
    background: #fff;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
    outline: none;
}
.form-control-sm { padding: 5px 10px; font-size: 13px; }
.form-label { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; display: block; font-weight: 500; }

/* ===== 模态框 ===== */
.modal { display: none; }
.modal.show { display: block; }

/* ===== 汉堡菜单 ===== */
.sidebar-toggle { display: none; }
.sidebar-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 1035;
}

/* ===== 分页 ===== */
.pagination {
    display: flex; gap: 4px; justify-content: center; align-items: center;
    padding: 12px 0; flex-wrap: wrap;
}
.pagination a, .pagination span {
    padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
    text-decoration: none; font-size: 13px; color: var(--text);
}
.pagination a:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.pagination .disabled { color: #cbd5e1; pointer-events: none; }

/* ===== badge ===== */
.badge {
    display: inline-block; padding: 3px 8px; font-size: 11px; font-weight: 600;
    border-radius: 4px; white-space: nowrap;
}
.bg-primary { background: var(--primary); color: #fff; }
.bg-secondary { background: #94a3b8; color: #fff; }
.bg-success { background: var(--success); color: #fff; }
.bg-danger { background: var(--danger); color: #fff; }
.bg-warning { background: var(--warning); color: #fff; }
.bg-info { background: var(--info); color: #fff; }
.bg-light { background: #f1f5f9; }
.text-dark { color: var(--text); }
.text-success { color: var(--success); }
.text-muted { color: var(--text-muted); }

/* ===== 用户统计卡片展开 ===== */
.user-stat-header { transition: background 0.15s; }
.user-stat-header:hover { background: #eef2ff; }
.user-stat-header .badge { transition: transform 0.2s; }

/* ===== 告警表格 ===== */
.table-danger { background: var(--danger-light) !important; }
.table-warning { background: var(--warning-light) !important; }

/* ================================================
   响应式：手机端 (max-width: 768px)
   ================================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 260px;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .sidebar-toggle {
        display: inline-flex; align-items: center; justify-content: center;
        width: 44px; height: 44px; font-size: 22px; background: none; border: none;
        color: var(--text); cursor: pointer; border-radius: 8px;
        position: fixed; top: 8px; left: 8px; z-index: 1039;
        background: rgba(255,255,255,0.9); box-shadow: 0 1px 4px rgba(0,0,0,0.12);
    }
    .sidebar-toggle:hover { background: #f1f5f9; }
    .main-content {
        margin-left: 0;
        padding: 56px 12px 16px;  /* 顶部留出汉堡菜单的空间 */
    }
    .page-header { flex-direction: column; align-items: flex-start; gap: 8px; }

    /* 概览卡片 — 2列，数字更大显眼 */
    #overviewCards .card-body .fs-3 { font-size: 1.5rem !important; }
    #overviewCards .card-body .fs-1 { font-size: 2rem !important; }
    #overviewCards .card-body { padding: 12px 8px; }
    #overviewCards small { font-size: 11px; }

    /* 日期筛选区域手机单行滚动 */
    .date-filter-form { overflow-x: auto; flex-wrap: nowrap !important; }
    .date-filter-form .col-auto { flex-shrink: 0; }

    /* 表格卡片化 */
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr {
        background: var(--card-bg);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
        margin-bottom: 10px;
        padding: 6px 0;
    }
    .table td {
        padding: 7px 14px;
        border: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
        font-size: 13px;
        min-height: 36px;
    }
    .table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        font-size: 11px;
        white-space: nowrap;
        flex-shrink: 0;
        min-width: 72px;
    }
    /* 操作按钮单独一行居右 */
    .table td:last-child { justify-content: flex-end; padding-top: 6px; padding-bottom: 8px; }
    .table td:last-child::before { display: none; }

    .screenshot-thumb { width: 44px; height: 44px; }

    /* 按钮最小44px触控区域 */
    .btn { min-height: 44px; padding: 10px 16px; }
    .btn-sm { min-height: 38px; padding: 7px 12px; font-size: 13px; }

    /* 模态框全屏 */
    .modal-dialog { max-width: 100vw; margin: 0; }
    .modal-content { border-radius: 0; min-height: 100vh; }
    .modal-body { padding-bottom: 80px; } /* 防止被虚拟键盘遮住 */

    /* 表单输入框足够大 */
    .form-control, .form-select { height: 46px; font-size: 16px; border-radius: 8px; }
    textarea.form-control { height: auto; min-height: 80px; }

    /* 仪表盘 — 使用人统计全宽 */
    #userStats .col-lg-4, #userStats .col-md-6 { width: 100%; max-width: 100%; flex: 0 0 100%; }

    /* 排名列表 */
    #rankingList .list-group-item { flex-direction: column; align-items: flex-start; gap: 4px; }

    /* 分页按钮 */
    .pagination a, .pagination span { padding: 9px 11px; font-size: 14px; min-width: 38px; text-align: center; }

    /* 搜索区换行 */
    .row.g-2.mb-3 .col-md-4 { width: 100%; max-width: 100%; flex: 0 0 100%; }
    .row.g-2.mb-3 .col-auto { width: 100%; max-width: 100%; flex: 0 0 100%; display: flex; gap: 8px; }

    /* 待办卡片按钮适配 */
    .card.border-danger .table td { flex-wrap: wrap; }
}

/* ================================================
   响应式：小屏手机 (max-width: 480px)
   ================================================ */
@media (max-width: 480px) {
    body { font-size: 13px; }
    .main-content { padding: 52px 8px 12px; }
    #overviewCards > .col { padding: 4px; }
    #overviewCards .card-body { padding: 10px 6px; }
    #overviewCards .card-body .fs-3 { font-size: 1.3rem !important; }
    #overviewCards .card-body .fs-1 { font-size: 1.7rem !important; }
    #overviewCards small { font-size: 10px; }
    .btn { font-size: 13px; }
    .screenshot-thumb { width: 36px; height: 36px; }
    .modal-dialog { margin: 0; }
    .modal-content { border-radius: 12px 12px 0 0; position: fixed; bottom: 0; left: 0; right: 0; margin: 0; min-height: auto; max-height: 92vh; overflow-y: auto; }
}

/* ================================================
   通用手机体验增强
   ================================================ */
/* 防止 iOS 点击延迟 */
a, button, [role="button"] { touch-action: manipulation; }

/* 滚动条美化（Webkit） */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== 筛选区域手机优化 ===== */
@media (max-width: 768px) {
    .row.g-2.mb-3 {
        flex-direction: column;
    }
    .row.g-2.mb-3 > [class*="col-"] {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }
    .row.g-2.mb-3 > .col-auto {
        display: flex;
        gap: 6px;
        flex-wrap: wrap;
    }
    .row.g-2.mb-3 select,
    .row.g-2.mb-3 input[type="date"] {
        height: 46px;
        font-size: 16px;
    }
}

/* ===== 页面标题美化 ===== */
.page-header h4 {
    font-weight: 700;
    color: #1e293b;
}
.page-header .btn {
    border-radius: 8px;
    font-weight: 600;
}

/* ===== 统计卡片美化 ===== */
.stat-num {
    line-height: 1.2;
}
.card.border-0.shadow-sm {
    transition: transform 0.2s, box-shadow 0.2s;
}
.card.border-0.shadow-sm:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.1) !important;
}

/* ===== 分享弹窗移动端 ===== */
@media (max-width: 768px) {
    .share-modal .sm-content {
        max-width: 92vw;
        padding: 20px 16px;
        border-radius: 14px;
    }
    .share-modal .sm-content h5 {
        font-size: 1rem;
    }
}

/* ===== 列表筛选区域美化 ===== */
.row.g-2.mb-3 {
    background: #fff;
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 16px !important;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    border: 1px solid #f1f5f9;
}

/* ===== 按钮组间距 ===== */
.col-auto .btn + .btn {
    margin-left: 4px;
}

/* ===== 数据卡片行 ===== */
.row.g-3.mb-3 .card.border-0.shadow-sm {
    border-radius: 14px !important;
}

/* ===== 列表空状态 ===== */
.text-center.text-muted.py-4 {
    font-size: 14px;
    padding: 40px 0 !important;
}

/* ===== 徽章样式增强 ===== */
.badge {
    letter-spacing: 0.3px;
}
.badge.bg-warning {
    color: #92400e !important;
    background: #fef3c7 !important;
}
.badge.bg-info {
    color: #1e40af !important;
    background: #dbeafe !important;
}

/* ===== 表单标签 ===== */
.form-label-sm {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 4px;
    font-weight: 600;
}

/* ===== 安全区底部 ===== */
.main-content {
    padding-bottom: max(24px, env(safe-area-inset-bottom));
}

/* ===== 触控优化：链接/按钮最小可触控区域 ===== */
@media (pointer: coarse) {
    .nav-link {
        min-height: 48px;
        align-items: center;
    }
    table a, table button {
        min-height: 36px;
    }
}
