/* ========== CSS 变量 ========== */
:root {
    --sidebar-width: 230px;
    --sidebar-collapsed-width: 64px;
    --topbar-height: 56px;
    --primary: #667eea;
    --primary-dark: #5a6fd6;
    --primary-light: #eef0ff;
    --secondary: #764ba2;
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --card-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    --card-shadow-hover: 0 6px 24px rgba(0, 0, 0, 0.10);
    --transition: all 0.25s ease;
}

/* ========== 全局基础 ========== */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
        "Microsoft YaHei", sans-serif;
    background-color: #f0f2f5;
    min-height: 100vh;
    font-size: 14px;
}

/* ========== 顶部导航栏 ========== */
.navbar {
    padding: 0 1.2rem;
    height: var(--topbar-height);
    background: var(--primary-gradient) !important;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.25);
    z-index: 1030;
}

.navbar-brand {
    font-size: 17px;
    letter-spacing: 0.5px;
    font-weight: 700;
}

.navbar .nav-link {
    font-size: 14px;
    padding: 0.4rem 0.8rem !important;
}

.navbar .dropdown-menu {
    border: none;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    padding: 0.4rem 0;
    min-width: 160px;
}

.navbar .dropdown-item {
    padding: 0.5rem 1.2rem;
    font-size: 14px;
    transition: var(--transition);
}

.navbar .dropdown-item:hover {
    background-color: var(--primary-light);
    color: var(--primary);
}

.navbar .dropdown-item i {
    width: 20px;
    text-align: center;
    margin-right: 6px;
}

/* ========== 侧边栏 ========== */
.sidebar {
    min-height: calc(100vh - var(--topbar-height));
    width: var(--sidebar-width);
    padding-top: 0;
    background: #fff !important;
    border-right: 1px solid #e8eaed;
    transition: var(--transition);
    position: sticky;
    top: var(--topbar-height);
    z-index: 1020;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar .nav-link {
    color: #555;
    padding: 10px 16px;
    border-radius: 8px;
    margin: 2px 10px;
    font-size: 14px;
    transition: var(--transition);
    white-space: nowrap;
    display: flex;
    align-items: center;
}

.sidebar .nav-link:hover {
    background-color: #f0f3ff;
    color: var(--primary);
    transform: translateX(2px);
}

.sidebar .nav-link.active {
    background: var(--primary-gradient);
    color: #fff !important;
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.3);
}

.sidebar .nav-link i {
    margin-right: 10px;
    width: 20px;
    text-align: center;
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-heading {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 700;
    color: #aaa !important;
    padding: 0 16px;
    margin-bottom: 4px;
}

/* 侧边栏折叠按钮 */
.sidebar-toggle {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #e0e0e0;
    color: #888;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    z-index: 10;
}

.sidebar-toggle:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

/* 侧边栏收起状态 */
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .nav-link {
    padding: 10px;
    margin: 2px 8px;
    justify-content: center;
}

.sidebar.collapsed .nav-link i {
    margin-right: 0;
    font-size: 18px;
}

.sidebar.collapsed .nav-link span,
.sidebar.collapsed .sidebar-heading,
.sidebar.collapsed .sidebar-heading small {
    display: none;
}

.sidebar.collapsed .sidebar-toggle {
    left: 50%;
}

/* ========== 主内容区 ========== */
main {
    padding-top: 1rem;
    padding-bottom: 2rem;
    min-height: calc(100vh - var(--topbar-height));
    transition: var(--transition);
}

main.expanded {
    margin-left: 0;
}

/* 页面标题栏 */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    padding: 0.75rem 0;
    margin-bottom: 1.25rem;
    border-bottom: 2px solid #eef0f5;
}

.page-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: #2c3e50;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-header h1 i {
    color: var(--primary);
    font-size: 1.3rem;
}

/* ========== 统计卡片（仪表盘 & 统计页） ========== */
.stat-card {
    border: none;
    border-radius: 14px;
    transition: var(--transition);
    box-shadow: var(--card-shadow);
    overflow: hidden;
    position: relative;
}

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

.stat-card .card-body {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-card .stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.stat-card .stat-info {
    flex: 1;
    min-width: 0;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    line-height: 1.2;
    margin: 0;
    color: #2c3e50;
}

.stat-card .stat-label {
    font-size: 13px;
    color: #888;
    margin: 4px 0 0 0;
}

/* 各类型卡片配色 */
.stat-card.card-blue .stat-icon { background: linear-gradient(135deg, #eef2ff, #e0e7ff); color: #4f6ef7; }
.stat-card.card-cyan .stat-icon { background: linear-gradient(135deg, #ecfeff, #cffafe); color: #06b6d4; }
.stat-card.card-amber .stat-icon { background: linear-gradient(135deg, #fffbeb, #fef3c7); color: #f59e0b; }
.stat-card.card-green .stat-icon { background: linear-gradient(135deg, #ecfdf5, #d1fae5); color: #10b981; }
.stat-card.card-red .stat-icon { background: linear-gradient(135deg, #fef2f2, #fee2e2); color: #ef4444; }
.stat-card.card-purple .stat-icon { background: linear-gradient(135deg, #faf5ff, #ede9fe); color: #8b5cf6; }

.stat-card.card-blue { border-left: 4px solid #4f6ef7; }
.stat-card.card-cyan { border-left: 4px solid #06b6d4; }
.stat-card.card-amber { border-left: 4px solid #f59e0b; }
.stat-card.card-green { border-left: 4px solid #10b981; }
.stat-card.card-red { border-left: 4px solid #ef4444; }
.stat-card.card-purple { border-left: 4px solid #8b5cf6; }

/* ========== 通用卡片 ========== */
.card {
    border: none;
    border-radius: 12px;
    transition: var(--transition);
    box-shadow: var(--card-shadow);
}

.card:hover {
    box-shadow: var(--card-shadow-hover);
}

.card-header {
    border-bottom: 1px solid #f0f0f0;
    border-radius: 12px 12px 0 0 !important;
    padding: 14px 20px;
    background-color: #fafbfc;
    font-weight: 600;
}

.card-body.p-0 {
    border-radius: 0 0 12px 12px;
    overflow: hidden;
}

.card-footer {
    border-top: 1px solid #f0f0f0;
    border-radius: 0 0 12px 12px !important;
    background-color: #fafbfc;
    padding: 12px 20px;
}

/* ========== 筛选面板（可折叠） ========== */
.filter-card .card-header {
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.filter-card .collapse-icon {
    transition: transform 0.3s ease;
    font-size: 14px;
    color: #999;
}

.filter-card .collapse-icon.open {
    transform: rotate(180deg);
}

.filter-card .collapse-tip {
    font-size: 12px;
    color: #aaa;
    margin-right: 8px;
    font-weight: 400;
}

.filter-card .table-count {
    font-size: 13px;
    color: #888;
    font-weight: 400;
}

/* ========== 表格优化 ========== */
.table {
    margin-bottom: 0;
}

.table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.table th {
    font-weight: 650;
    font-size: 12px;
    text-transform: none;
    color: #666;
    padding: 12px 14px;
    border-bottom: 2px solid #e8eaed;
    background: #f8f9fb;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.table td {
    font-size: 13px;
    padding: 10px 14px;
    vertical-align: middle;
    border-color: #f0f2f5;
}

.table > tbody > tr {
    transition: background-color 0.15s ease;
}

.table > tbody > tr:hover {
    background-color: #f5f6ff !important;
}

.table > tbody > tr:last-child td {
    border-bottom: none;
}

/* 空数据状态 */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: #bbb;
}

.empty-state i {
    font-size: 48px;
    display: block;
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-state p {
    margin: 0;
    font-size: 14px;
}

/* ========== 按钮优化 ========== */
.btn {
    border-radius: 8px;
    font-weight: 500;
    padding: 6px 16px;
    font-size: 13px;
    transition: var(--transition);
    border: 1px solid transparent;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 6px;
}

.btn-lg {
    padding: 10px 24px;
    font-size: 15px;
    border-radius: 10px;
}

.btn-primary {
    background: var(--primary-gradient);
    border: none;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #5a6fd6 0%, #6a3f8f 100%);
    box-shadow: 0 4px 14px rgba(102, 126, 234, 0.4);
    transform: translateY(-1px);
}

.btn-outline-primary {
    border-color: #d0d5f0;
    color: var(--primary);
}

.btn-outline-primary:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary-dark);
}

.btn-success {
    background: linear-gradient(135deg, #10b981, #059669);
    border: none;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
    background: linear-gradient(135deg, #059669, #047857);
}

/* 操作按钮组 */
.action-btns {
    display: flex;
    gap: 4px;
    justify-content: center;
    flex-wrap: wrap;
}

.action-btns .btn-sm {
    width: 30px;
    height: 30px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

/* ========== 表单控件优化 ========== */
.form-control, .form-select {
    border-radius: 8px;
    border: 1px solid #e0e3e8;
    padding: 8px 12px;
    font-size: 13px;
    transition: var(--transition);
    background-color: #fafbfc;
}

.form-control:hover, .form-select:hover {
    border-color: #c5cad3;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
    background-color: #fff;
}

.form-label {
    font-size: 13px;
    font-weight: 600;
    color: #555;
    margin-bottom: 5px;
}

/* ========== 分页优化 ========== */
.pagination {
    margin-bottom: 0;
    gap: 2px;
}

.page-link {
    border-radius: 8px;
    margin: 0 2px;
    border: none;
    color: var(--primary);
    font-size: 13px;
    padding: 6px 12px;
    transition: var(--transition);
}

.page-link:hover {
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: 8px;
}

.page-item.active .page-link {
    background: var(--primary-gradient);
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
}

.page-item.disabled .page-link {
    background: transparent;
    color: #ccc;
}

/* ========== 徽章优化 ========== */
.badge {
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    letter-spacing: 0.2px;
}

/* ========== 提示消息 ========== */
.alert {
    border-radius: 10px;
    border: none;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========== 图表容器 ========== */
.chart-container {
    width: 100%;
    min-height: 320px;
}

.chart-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 320px;
    color: #ccc;
    font-size: 14px;
}

/* ========== 动画 ========== */
.fade-in {
    animation: fadeInUp 0.35s ease-out;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in-delay-1 { animation-delay: 0.05s; animation-fill-mode: both; }
.fade-in-delay-2 { animation-delay: 0.10s; animation-fill-mode: both; }
.fade-in-delay-3 { animation-delay: 0.15s; animation-fill-mode: both; }
.fade-in-delay-4 { animation-delay: 0.20s; animation-fill-mode: both; }
.fade-in-delay-5 { animation-delay: 0.25s; animation-fill-mode: both; }
.fade-in-delay-6 { animation-delay: 0.30s; animation-fill-mode: both; }

/* ========== 响应式 ========== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        top: var(--topbar-height);
        z-index: 1025;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
        transition: left 0.3s ease;
    }

    .sidebar.mobile-open {
        left: 0;
    }

    .sidebar-toggle {
        display: none;
    }

    main {
        margin-left: 0 !important;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .page-header h1 {
        font-size: 1.2rem;
    }

    .stat-card .stat-value {
        font-size: 1.4rem;
    }

    .stat-card .stat-icon {
        width: 42px;
        height: 42px;
        font-size: 20px;
        border-radius: 10px;
    }

    .table td, .table th {
        padding: 8px 10px;
        font-size: 12px;
    }
}

/* 移动端侧边栏遮罩 */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 1024;
}

@media (max-width: 768px) {
    .sidebar-overlay.show {
        display: block;
    }
}

/* ========== 滚动条美化 ========== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #d0d5e0;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #b0b8c8;
}

/* ========== 打印优化 ========== */
@media print {
    .sidebar, .navbar, .btn-toolbar, .filter-card, .action-btns {
        display: none !important;
    }
    main {
        margin-left: 0 !important;
        width: 100% !important;
    }
}
