/* ========== 财务日记账系统 - 全局样式 ========== */
:root {
    --primary: #007AFF;
    --primary-hover: #0056b3;
    --bg: #f5f5f7;
    --card-bg: #ffffff;
    --text: #1d1d1f;
    --text-2: #86868b;
    --border: #d2d2d7;
    --danger: #ff3b30;
    --success: #34c759;
    --warning: #ff9500;
    --sidebar-w: 230px;
    --radius: 12px;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

a { text-decoration: none; color: var(--primary); }

/* ========== 布局 ========== */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-logo {
    width: 36px; height: 36px;
    background: var(--primary);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 18px; font-weight: 700;
}

.sidebar-title { font-size: 15px; font-weight: 600; }

.nav-section { padding: 8px 0; }
.nav-section-title {
    padding: 8px 20px;
    font-size: 11px;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s;
    font-size: 14px;
}

.nav-item:hover { background: rgba(0,0,0,0.04); }
.nav-item.active { background: rgba(0,122,255,0.08); color: var(--primary); font-weight: 500; }
.nav-item .icon { width: 20px; text-align: center; font-size: 16px; }

.main-area {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title { font-size: 17px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 16px; }

.user-badge {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 12px;
    background: var(--bg);
    border-radius: 20px;
    font-size: 13px;
}

.role-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
}
.role-主管 { background: #ffd60a; color: #1d1d1f; }
.role-开票 { background: #5ac8fa; color: #fff; }
.role-请款 { background: #ff9500; color: #fff; }
.role-出纳 { background: #34c759; color: #fff; }

.content { padding: 24px; flex: 1; }

/* ========== 卡片 ========== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 20px;
}

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

.card-title { font-size: 16px; font-weight: 600; }
.card-body { padding: 20px; }

/* ========== 按钮 ========== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg); color: var(--text); }
.btn-secondary:hover { background: #e8e8ed; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c8271f; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-icon { padding: 6px 10px; }

/* ========== 表格 ========== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.data-table th {
    background: var(--bg);
    padding: 10px 12px;
    text-align: left;
    /* 中文字体放最前 + 改用 500 字重：避免个别汉字（款等）在 YaHei-Bold 中
       字形偏大/偏粗造成的视觉不一致；标题层级靠背景色与底边线表达 */
    font-family: "Microsoft YaHei", "Microsoft YaHei UI", "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 500;
    color: var(--text-2);
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
    letter-spacing: 0;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f0f0f2;
    white-space: nowrap;
}

.data-table tr:hover td { background: rgba(0,122,255,0.03); }
.data-table .subtotal-row { background: #fff8e1; font-weight: 600; }
.data-table .subtotal-row td { border-bottom: 2px solid var(--warning); }

/* 批量删除：最右侧多选列（日记账列表） */
.data-table .sel-col { text-align: center; width: 44px; }
.data-table .sel-col input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; accent-color: var(--primary, #007AFF); }
#batch-del-btn:disabled { cursor: not-allowed; }

/* 报表层级分组：项目带行（如预算查询） */
.data-table .band-row td {
    background: #eef3fa;
    color: #1d1d1f;
    font-weight: 700;
    padding: 7px 12px;
    border-bottom: 1px solid #dbe4ef;
}
.data-table .band-row:hover td { background: #eef3fa; }

/* 列表页底部汇总行：数量 + 金额合计 */
.data-table tfoot .summary-row { background: #f2f4f8; font-weight: 600; }
.data-table tfoot .summary-row td {
    border-top: 2px solid var(--border);
    border-bottom: none;
    color: var(--text);
    position: sticky;
    bottom: 0;
    z-index: 1;
}
.data-table tfoot .summary-row td.num-col { text-align: right; }

.table-wrapper {
    overflow: auto;
    border: 1px solid #f0f0f2;
    border-radius: 8px;
    scrollbar-width: thin;
    max-width: 100%;
}
.card:has(.table-wrapper) { overflow: visible; }
.table-wrapper::-webkit-scrollbar { height: 12px; }
.table-wrapper::-webkit-scrollbar-track { background: #f5f5f7; border-radius: 6px; }
.table-wrapper::-webkit-scrollbar-thumb { background: #a0a0a5; border-radius: 6px; }
.table-wrapper::-webkit-scrollbar-thumb:hover { background: #6e6e73; }

/* 合同信息字段过宽时压缩表头，让操作列更容易进入视口 */
.data-table th, .data-table td { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.data-table th { white-space: nowrap; }

/* 数据管理表格：字段过多时主动撑开触发横向滚动条，避免操作列被窗口裁切 */
.card-body .table-wrapper .data-table { width: auto; min-width: 100%; }

/* 数字/金额列：靠右对齐 + 等宽数字，方便纵向比较位数 */
.data-table th.num-col, .data-table td.num-col {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ========== 表单 ========== */
.form-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field.colspan-2 { grid-column: span 2; }
.form-field.colspan-3 { grid-column: span 3; }

.form-label { font-size: 13px; font-weight: 500; color: var(--text); }
.form-label .req { color: var(--danger); }

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.1);
}

.form-textarea { resize: vertical; min-height: 60px; }
.form-hint { font-size: 12px; color: var(--text-2); }

/* 级联字段组：三个分类横向各占一列，与表单网格对齐 */
.cascade-group { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.cascade-col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
@media (max-width: 768px) {
    .cascade-group { grid-template-columns: 1fr; }
}

/* ========== 模糊搜索下拉 ========== */
.fuzzy-container { position: relative; }
.fuzzy-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
}
.fuzzy-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,122,255,0.1); }
.fuzzy-dropdown {
    position: absolute;
    top: 100%;
    left: 0; right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 0 0 8px 8px;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    display: none;
}
.fuzzy-dropdown.show { display: block; }
.fuzzy-option {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
}
.fuzzy-option:hover, .fuzzy-option.highlight { background: rgba(0,122,255,0.06); }

/* fuzzy 下拉列表底部的"＋ 新增"快捷入口行 */
.fuzzy-add-row {
    position: sticky;
    bottom: 0;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    color: var(--primary, #007AFF);
    background: #fff;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 4px;
    user-select: none;
}
.fuzzy-add-row:hover { background: rgba(0,122,255,0.06); }
.fuzzy-add-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary, #007AFF);
    color: #fff;
    font-size: 12px;
    line-height: 1;
    flex-shrink: 0;
}

/* ========== 弹窗 ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
    overflow-y: auto;
}
.modal-overlay.show { display: flex; }

.modal {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 720px;
    margin: auto;
}

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

.modal-title { font-size: 17px; font-weight: 600; }
.modal-close {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    color: var(--text-2);
    border: none;
    background: none;
}
.modal-close:hover { background: var(--bg); }

.modal-body { padding: 24px; max-height: 60vh; overflow-y: auto; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ========== 工具栏 ========== */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

/* 筛选栏：模糊筛选（多条件 AND 组合） */
.filter-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.filter-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 130px;
    max-width: 220px;
    flex: 1;
}
.filter-label {
    font-size: 12px;
    color: var(--text-2);
    white-space: nowrap;
}
.filter-input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
}
.filter-input:focus {
    outline: none;
    border-color: var(--primary);
}
.filter-reset-btn {
    margin-bottom: 1px;
}
/* 横向筛选栏（项目台账）：label 与输入框同一水平线 */
.filter-bar-inline { align-items: center; margin-bottom: 0; }
.filter-bar-inline .filter-item {
    flex-direction: row;
    align-items: center;
    min-width: 0;
    max-width: none;
    flex: none;
}
.filter-bar-inline .filter-input { width: 150px; }
/* 区间型筛选（期间、金额）：一行两个输入框 */
.filter-item-range {
    min-width: 200px;
    max-width: 300px;
}
.filter-range-row {
    display: flex;
    align-items: center;
    gap: 4px;
}
.filter-range-row .filter-input {
    min-width: 0;
    flex: 1;
}
.filter-range-sep {
    color: var(--text-2);
    font-size: 12px;
    flex: none;
}

.search-box {
    flex: 1;
    min-width: 200px;
    max-width: 400px;
    position: relative;
}

.search-input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
}

.search-icon {
    position: absolute;
    left: 10px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-2);
}

/* ========== 仪表盘 ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

/* 首页第一行：6 个卡片强制一行排列（5 指标 + 利润率水波图） */
.stats-grid-6 {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.stats-grid-6 .stat-card { padding: 14px 10px; display: flex; flex-direction: column; justify-content: center; }
.stats-grid-6 .stat-label { font-size: 12px; margin-bottom: 4px; white-space: nowrap; }
.stats-grid-6 .stat-value { font-size: 22px; }
.stats-grid-6 .wave-card { display: flex; align-items: center; justify-content: center; }

/* 项目台账紧凑表格：缩小字号/内边距，首列收窄，确保所有列一页显示完整 */
.pl-compact .data-table { font-size: 12px; }
.pl-compact .data-table th, .pl-compact .data-table td { padding: 6px 7px; }
.pl-compact .data-table td:first-child, .pl-compact .data-table th:first-child { max-width: 110px; overflow: hidden; text-overflow: ellipsis; }

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.stat-label { font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; }
.stat-value.income { color: var(--danger); }
.stat-value.expense { color: var(--success); }
.stat-value.balance { color: var(--primary); }

/* 项目经营分析图表 */
.chart-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 20px; }
.chart-box { min-width: 0; }
.chart-trend-box { border-top: 1px solid var(--border); padding-top: 16px; }
.chart-subtitle { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin-bottom: 6px; flex-wrap: wrap; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.chart-table { font-size: 12px; margin-top: 8px; }
.chart-table th, .chart-table td { padding: 6px 8px; }
#chart-trend { width: 100%; }
@media (max-width: 1400px) {
    .chart-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
    .chart-grid { grid-template-columns: 1fr; }
}

/* ========== 报表 ========== */
.report-info-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}

.report-info-card h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--primary);
}

.report-info-row {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    margin-bottom: 8px;
}

.report-info-item {
    font-size: 14px;
}

.report-info-item .label { color: var(--text-2); }
.report-info-item .value { font-weight: 600; }

/* ========== 登录页 ========== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 400px;
    max-width: 90%;
    overflow: hidden;
}

.login-header {
    padding: 32px 32px 16px;
    text-align: center;
}

.login-logo {
    width: 56px; height: 56px;
    background: var(--primary);
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 28px; font-weight: 700;
    margin: 0 auto 16px;
}

.login-title { font-size: 20px; font-weight: 600; }
.login-subtitle { font-size: 14px; color: var(--text-2); margin-top: 4px; }

.login-body { padding: 16px 32px 32px; }
.login-error {
    background: #fff2f2;
    color: var(--danger);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
    display: none;
}
.login-error.show { display: block; }

.login-field { margin-bottom: 16px; }
.login-field label { display: block; font-size: 13px; margin-bottom: 6px; font-weight: 500; }
.login-field input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
}
.login-field input:focus { outline: none; border-color: var(--primary); }
.login-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
}
.login-btn:hover { background: var(--primary-hover); }

.login-hint {
    margin-top: 20px;
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-2);
    line-height: 1.8;
}

/* ========== 移动端 ========== */
.hamburger {
    display: none;
    width: 40px; height: 40px;
    border: none;
    background: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 99;
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .main-area { margin-left: 0; }
    .hamburger { display: block; }
    .topbar { padding: 0 12px; }
    .content { padding: 12px; }
    .form-grid { grid-template-columns: 1fr; }
    .form-field.colspan-2, .form-field.colspan-3 { grid-column: span 1; }
    .modal { max-width: 100%; }
    .modal-body { padding: 16px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-value { font-size: 22px; }
    .report-info-row { flex-direction: column; gap: 8px; }
    .table-wrapper { font-size: 12px; }
    .nav-section-title { padding: 8px 16px; }
    .nav-item { padding: 10px 16px; }
}

/* ========== 提示框 ========== */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    transform: translateX(400px);
    transition: transform 0.3s ease;
}
.toast.show { transform: translateX(0); }
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }

/* ========== 空状态 ========== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-2);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }

/* ========== 分页 ========== */
.pagination {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
}
.page-btn {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
}
.page-btn:hover { background: var(--bg); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-info { font-size: 13px; color: var(--text-2); margin-right: 12px; }
