/* ============================================================
   绩效分配系统 - 现代化 UI 样式
   ============================================================ */

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #eef2ff;
    --accent: #8b5cf6;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --surface: #ffffff;
    --bg: #f1f5f9;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 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);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    line-height: 1.6;
    min-height: 100vh;
}

/* ---- 导航栏 ---- */
.navbar {
    background: linear-gradient(135deg, #4338ca 0%, #6366f1 50%, #8b5cf6 100%) !important;
    box-shadow: var(--shadow-md);
    padding: 0.75rem 0;
}

.navbar-brand {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.navbar .btn-light {
    font-size: 0.8rem;
    padding: 0.3rem 0.65rem;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    color: white;
    font-weight: 500;
}

.navbar .btn-light:hover {
    background: rgba(255,255,255,0.25);
    border-color: rgba(255,255,255,0.4);
    color: white;
}

/* ---- 标签页 ---- */
.nav-tabs {
    border-bottom: 2px solid var(--border);
    gap: 0.5rem;
}

.nav-tabs .nav-link {
    border: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    color: var(--text-muted);
    font-weight: 500;
    padding: 0.75rem 1.5rem;
    transition: var(--transition);
    position: relative;
}

.nav-tabs .nav-link:hover {
    color: var(--primary);
    background: transparent;
}

.nav-tabs .nav-link.active {
    color: var(--primary);
    background: var(--surface);
    font-weight: 600;
}

.nav-tabs .nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
}

/* ---- 卡片 ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    margin-bottom: 1rem;
}

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

.card-header {
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.875rem 1.25rem;
    border-radius: var(--radius) var(--radius) 0 0 !important;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-header i {
    color: var(--primary);
    font-size: 1.1rem;
}

.card-body { padding: 1.25rem; }

/* ---- 区块标题 ---- */
.section-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    font-size: 0.8rem;
    font-weight: 700;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

/* ---- 表单 ---- */
.form-label {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.form-control, .form-select {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    transition: var(--transition);
    background: #fafbfc;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
    background: white;
    outline: none;
}

.form-control-sm { padding: 0.35rem 0.5rem; font-size: 0.8rem; }
.form-select-sm { padding: 0.35rem 1.5rem 0.35rem 0.5rem; font-size: 0.8rem; }

/* ---- 表格 ---- */
.table {
    margin-bottom: 0;
    font-size: 0.875rem;
}

.table th {
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: #f8fafc;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    padding: 0.625rem 0.75rem;
}

.table td {
    padding: 0.5rem 0.75rem;
    vertical-align: middle;
    border-color: #f1f5f9;
}

.table tbody tr {
    transition: var(--transition);
}

.table tbody tr:hover {
    background: #f8fafc;
}

.table-danger {
    background: #fef2f2 !important;
}

.table-danger:hover {
    background: #fee2e2 !important;
}

/* ---- 可排序列 ---- */
.sortable {
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.sortable:hover {
    background: #eef2ff !important;
    color: var(--primary) !important;
}

.sort-icon {
    font-size: 0.65rem;
    opacity: 0.35;
    margin-left: 2px;
    vertical-align: middle;
}

.sort-icon.active {
    opacity: 1;
    color: var(--primary);
}

/* ---- 按钮 ---- */
.btn {
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding: 0.5rem 1rem;
    transition: var(--transition);
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border: none;
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

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

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

.btn-outline-danger {
    color: var(--danger);
    border-color: transparent;
}

.btn-outline-danger:hover {
    background: #fef2f2;
    border-color: #fecaca;
    color: var(--danger);
}

.btn-lg {
    padding: 0.75rem 2rem;
    font-size: 1rem;
    border-radius: var(--radius);
}

.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

/* ---- 资金池卡片 ---- */
.pool-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

@media (max-width: 768px) {
    .pool-cards { grid-template-columns: repeat(2, 1fr); }
}

.pool-card {
    padding: 1.25rem;
    border-radius: var(--radius);
    color: white;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

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

.pool-card::after {
    content: '';
    position: absolute;
    top: -20px;
    right: -20px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    pointer-events: none;
}

.pool-card .pool-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    opacity: 0.9;
}

.pool-card .pool-label {
    font-size: 0.8rem;
    opacity: 0.85;
    margin-bottom: 0.25rem;
}

.pool-card .pool-value {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.pool-card .pool-sub {
    font-size: 0.72rem;
    opacity: 0.7;
    margin-top: 0.25rem;
}

.pool-card.primary  { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.pool-card.success  { background: linear-gradient(135deg, #059669, #10b981); }
.pool-card.warning  { background: linear-gradient(135deg, #d97706, #f59e0b); }
.pool-card.info     { background: linear-gradient(135deg, #0284c7, #38bdf8); }

/* ---- 上传区域 ---- */
.upload-area {
    background: #fafbfc;
    border: 2px dashed var(--border) !important;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
}

.upload-area:hover {
    border-color: var(--primary) !important;
    background: var(--primary-light);
}

.upload-area.dragover {
    border-color: var(--primary) !important;
    background: #eef2ff;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.upload-area .upload-icon {
    font-size: 3rem;
    color: #94a3b8;
    transition: var(--transition);
}

.upload-area:hover .upload-icon {
    color: var(--primary);
    transform: translateY(-4px);
}

/* ---- 结果区域 ---- */
.result-section {
    animation: fadeInUp 0.5s ease;
}

.result-search { width: 180px; }
.result-filter { width: 130px; }

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

/* ---- 校验结果 ---- */
.check-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-size: 0.82rem;
    font-weight: 500;
    margin: 0.25rem;
}

.check-badge.pass {
    background: #ecfdf5;
    color: #059669;
    border: 1px solid #a7f3d0;
}

.check-badge.fail {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

/* ---- Toast 通知 ---- */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast-msg {
    background: white;
    border-radius: var(--radius-sm);
    padding: 0.875rem 1.25rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.875rem;
    font-weight: 500;
    animation: slideIn 0.3s ease;
    min-width: 280px;
    border-left: 4px solid var(--primary);
}

.toast-msg.error { border-left-color: var(--danger); }
.toast-msg.success { border-left-color: var(--success); }
.toast-msg.warning { border-left-color: var(--warning); }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(100%); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ---- 徽章 ---- */
.badge-coeff {
    background: #eef2ff;
    color: #4338ca;
    font-weight: 600;
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.badge-rate {
    background: #f0fdf4;
    color: #166534;
    font-weight: 600;
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

/* ---- 标签 ---- */
.tag {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.72rem;
    font-weight: 500;
}

.tag-teacher { background: #eef2ff; color: #4338ca; }
.tag-counselor { background: #fef3c7; color: #92400e; }
.tag-admin { background: #f0fdf4; color: #166534; }

/* ---- 空状态 ---- */
.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}

/* ---- 页脚 ---- */
.footer-note {
    text-align: center;
    padding: 2rem 0;
    color: var(--text-muted);
    font-size: 0.82rem;
}

/* ---- 滚动条 ---- */
::-webkit-scrollbar { height: 6px; width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ---- 数量输入框 ---- */
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { opacity: 1; }

/* ============================================================ */
/* 历史记录侧边栏                                                   */
/* ============================================================ */

.history-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 1050;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.history-overlay.show {
    opacity: 1;
    visibility: visible;
}

.history-panel {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    height: 100vh;
    background: white;
    z-index: 1060;
    box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.history-panel.open {
    right: 0;
}

.history-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.history-header h5 {
    margin: 0;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.history-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.history-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.history-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.history-item:hover {
    background: #f8fafc;
    border-color: var(--border);
}

.history-item-content {
    flex: 1;
    min-width: 0;
}

.history-item-name {
    font-weight: 600;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

.history-item-del {
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.history-item:hover .history-item-del {
    opacity: 1;
}

/* ============================================================ */
/* 打印样式                                                        */
/* ============================================================ */

@media print {
    body {
        background: white;
        color: black;
        font-size: 12px;
    }

    .navbar, .nav-tabs, #mainTabContent, .footer-note,
    #historyOverlay, #historyPanel, .toast-container,
    #resultSection > div:first-child .btn,
    #resultSection > div:first-child input,
    #resultSection > div:first-child select,
    #resultSection .card-header .btn,
    #chartsRow {
        display: none !important;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
        break-inside: avoid;
    }

    .card-header {
        background: #eee !important;
        color: black !important;
    }

    .pool-cards {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.5rem;
    }

    .pool-card {
        box-shadow: none !important;
        padding: 0.75rem;
        color: black !important;
        background: #f5f5f5 !important;
        border: 1px solid #ddd !important;
    }

    .pool-card .pool-value {
        font-size: 1.1rem;
        color: black !important;
    }

    .table th {
        background: #eee !important;
        color: black !important;
    }

    .result-section {
        animation: none;
    }

    @page {
        margin: 1cm;
        size: A4 landscape;
    }
}

/* ============================================================ */
/* 响应式                                                          */
/* ============================================================ */

@media (max-width: 992px) {
    .pool-cards { grid-template-columns: repeat(2, 1fr); }
    #chartsRow .col-lg-5,
    #chartsRow .col-lg-7 {
        width: 100%;
        margin-bottom: 1rem;
    }
}

@media (max-width: 768px) {
    /* 容器 */
    .container { padding-left: 0.75rem; padding-right: 0.75rem; }

    /* 导航栏 */
    .navbar { padding: 0.5rem 0; }
    .navbar .container { flex-direction: column; gap: 0.5rem; }
    .navbar-brand { font-size: 0.9rem; white-space: normal; text-align: center; }
    .navbar .btn-sm { font-size: 0.7rem; padding: 0.25rem 0.5rem; }

    /* 标签页 */
    .nav-tabs .nav-link { padding: 0.5rem 0.75rem; font-size: 0.8rem; }

    /* 卡片 */
    .card-header { font-size: 0.85rem; padding: 0.65rem 0.75rem; flex-wrap: wrap; gap: 0.5rem; }
    .card-body { padding: 0.75rem; }

    /* 参数行 */
    .row.g-3 > [class*="col-"] { margin-bottom: 0.5rem; }

    /* 表格 - 横向滚动 + 渐变提示 */
    .table-responsive {
        position: relative;
        -webkit-overflow-scrolling: touch;
        overflow-x: auto;
    }
    .table-responsive::after {
        content: '';
        position: absolute;
        top: 0; right: 0; bottom: 0;
        width: 24px;
        background: linear-gradient(to right, transparent, rgba(0,0,0,0.06));
        pointer-events: none;
        border-radius: 0 0 var(--radius) 0;
    }
    .table th { font-size: 0.68rem; padding: 0.4rem 0.35rem; white-space: nowrap; }
    .table td { font-size: 0.75rem; padding: 0.35rem 0.35rem; }
    .table .form-control-sm { font-size: 0.72rem; padding: 0.25rem 0.3rem; min-width: 48px; }
    .table .form-select-sm { font-size: 0.72rem; padding: 0.25rem 1rem 0.25rem 0.3rem; }

    /* 人员表 - 强制最小宽度保证每列可见 */
    #staffTable .table-responsive { overflow-x: auto; }
    #staffTable table { min-width: 900px; }
    /* 缩短否决列表头 */
    #staffTable th:nth-child(9),
    #staffTable th:nth-child(10) { font-size: 0.6rem; letter-spacing: 0; }

    /* 资金池卡片 */
    .pool-cards { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .pool-card { padding: 0.875rem; }
    .pool-card .pool-value { font-size: 1.2rem; }
    .pool-card .pool-label { font-size: 0.72rem; }
    .pool-card .pool-icon { font-size: 1.2rem; margin-bottom: 0.25rem; }

    /* 结果工具栏 - 换行 */
    #resultSection > div:first-child { gap: 0.5rem; }
    #resultSection h4 { font-size: 1rem; width: 100%; }
    .result-search { width: 100% !important; }
    .result-filter { width: 100% !important; }
    #resultSection .btn-sm { font-size: 0.72rem; padding: 0.3rem 0.5rem; }

    /* 图表高度 */
    #poolChart, #barChart { height: 250px !important; }
    #chartsRow .card-body { padding: 0.5rem; }

    /* 校验标签 */
    .check-badge { font-size: 0.7rem; padding: 0.35rem 0.6rem; }

    /* 历史面板 - 全屏 */
    .history-panel { width: 100vw; right: -100vw; }

    /* 对比模态框 */
    .modal-xl { max-width: 100%; margin: 0.5rem; }

    /* 按钮 */
    .btn { font-size: 0.8rem; padding: 0.45rem 0.75rem; min-height: 38px; }
    .btn-lg { font-size: 0.9rem; padding: 0.65rem 1.5rem; }
    .btn-sm { min-height: 32px; }

    /* 空状态 */
    .empty-state { padding: 1.5rem; }

    /* 结果区域间距 */
    .result-section { margin-top: 1rem; }

    /* 上传区域 */
    .upload-area { padding: 2rem 1rem !important; }
    .upload-area .upload-icon { font-size: 2rem; }
}

@media (max-width: 480px) {
    /* 更小屏幕 */
    .pool-cards { grid-template-columns: 1fr; }
    .navbar-brand { font-size: 0.78rem; }
    .navbar .btn-sm { font-size: 0.65rem; padding: 0.2rem 0.4rem; }
    .navbar .container > div { flex-wrap: wrap; gap: 0.35rem !important; justify-content: center; }
    .navbar .container > div span { display: none; }

    /* 表格更紧凑 */
    .table th { font-size: 0.6rem; padding: 0.3rem 0.25rem; letter-spacing: 0; }
    .table td { font-size: 0.68rem; padding: 0.25rem 0.25rem; }
    .table .form-control-sm { font-size: 0.7rem; padding: 0.2rem 0.25rem; min-width: 42px; }
    .table .form-select-sm { font-size: 0.7rem; padding: 0.2rem 0.8rem 0.2rem 0.25rem; }
    #staffTable table { min-width: 850px; }

    /* 表单更紧凑 */
    .form-label { font-size: 0.75rem; }

    /* 参数预览 */
    #paramPreview { font-size: 0.72rem !important; padding: 0.5rem !important; }

    /* 区块序号 */
    .section-number { width: 22px; height: 22px; font-size: 0.7rem; }

    /* 图表再小一点 */
    #poolChart, #barChart { height: 220px !important; }

    /* Toast */
    .toast-msg { min-width: auto; max-width: 90vw; font-size: 0.78rem; padding: 0.65rem 0.85rem; }

    /* 计算按钮全宽 */
    .text-center .btn-primary.btn-lg { width: 100%; }

    /* 模板说明 */
    #upload + .tab-pane .card .card-body .row { font-size: 0.72rem; }
}
