/* ============================================
   对账管理系统 - 样式表
   响应式设计：PC + 移动端适配
   ============================================ */

/* CSS 变量 */
:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #818cf8;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --income: #10b981;
    --expense: #ef4444;
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-width: 260px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   页面切换
   ============================================ */
.page {
    display: none;
    min-height: 100vh;
}

.page.active {
    display: block;
}

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

.login-box {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    animation: slideUp 0.5s ease;
}

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

.login-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
}

.login-icon i {
    font-size: 36px;
    color: white;
}

.login-box h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text);
}

.login-subtitle {
    color: var(--text-light);
    margin-bottom: 32px;
    font-size: 15px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.input-group i {
    position: absolute;
    left: 16px;
    color: var(--text-light);
    font-size: 16px;
}

.input-group input {
    width: 100%;
    padding: 14px 16px 14px 48px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    transition: var(--transition);
    background: var(--card-bg);
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.error-msg {
    color: var(--danger);
    font-size: 14px;
    margin-top: 12px;
    min-height: 20px;
}

/* ============================================
   按钮样式
   ============================================ */
.btn-primary, .btn-secondary, .btn-logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

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

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    background: #cbd5e1;
}

.btn-logout {
    background: transparent;
    color: var(--text-light);
    padding: 10px 16px;
    width: 100%;
    justify-content: flex-start;
    border-radius: var(--radius-sm);
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

/* ============================================
   侧边栏
   ============================================ */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: var(--transition);
}

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

.sidebar-header i {
    font-size: 28px;
    color: var(--primary);
}

.sidebar-header span {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
}

.nav-menu {
    list-style: none;
    padding: 16px 12px;
    flex: 1;
    overflow-y: auto;
}

.nav-item {
    display: none; /* 默认隐藏，由 JS 根据权限动态显示，防止无权限菜单闪现 */
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 4px;
    color: var(--text-light);
    font-weight: 500;
}

.nav-item i {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.nav-item:hover {
    background: rgba(79, 70, 229, 0.08);
    color: var(--primary);
}

.nav-item.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid var(--border);
}

/* ============================================
   主内容区
   ============================================ */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 32px;
    min-height: 100vh;
    transition: var(--transition);
}

.page-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
}

.page-title i {
    color: var(--primary);
}

/* ============================================
   筛选栏 - 内容自适应宽度
   ============================================ */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    align-items: flex-end;
    margin-bottom: 20px;
    padding: 14px 18px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 0 1 auto;
    min-width: 70px;
    max-width: 200px;
}

.filter-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-light);
    white-space: nowrap;
}

.filter-group select,
.filter-group input {
    padding: 7px 10px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    min-width: 0;
    width: 100%;
    background: var(--card-bg);
    transition: var(--transition);
    height: 36px;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2364748b'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}

.filter-group select {
    padding-right: 28px;
}

.filter-group input[type="text"] {
    background-image: none;
    padding-right: 8px;
}

.filter-group input[type="date"] {
    background-image: none;
    padding-right: 8px;
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: var(--primary);
}

/* 日期区间 - 比其他筛选稍宽 */
.filter-group.date-range-wrap {
    flex: 0 1 220px;
    min-width: 150px;
    max-width: 260px;
}
.filter-group.date-range-wrap input {
    font-size: 12px;
    padding: 7px 10px;
    background-image: none !important;
    cursor: pointer;
}

/* 项目输入框 - 比其他筛选稍宽 */
.filter-group:has(input#filter-project),
.filter-group:has(input#summary-project) {
    flex: 0 1 180px;
    min-width: 110px;
    max-width: 220px;
}

/* 筛选栏中的按钮 */
.filter-bar .btn-primary,
.filter-bar .btn-secondary {
    flex: 0 0 auto;
    padding: 7px 18px;
    font-size: 13px;
    align-self: flex-end;
    height: 36px;
}

/* ============================================
   统计卡片
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 18px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
}

.stat-card.income::before { background: var(--income); }
.stat-card.expense::before { background: var(--expense); }
.stat-card.prepayment::before { background: var(--warning); }
.stat-card.profit::before { background: var(--info); }

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

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.stat-card.income .stat-icon { background: rgba(16, 185, 129, 0.1); color: var(--income); }
.stat-card.expense .stat-icon { background: rgba(239, 68, 68, 0.1); color: var(--expense); }
.stat-card.prepayment .stat-icon { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.stat-card.profit .stat-icon { background: rgba(59, 130, 246, 0.1); color: var(--info); }

.stat-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.stat-label {
    font-size: 12px;
    color: var(--text-light);
    font-weight: 500;
}

.stat-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
    word-break: break-all;
}

.stat-sub {
    font-size: 10px;
    color: var(--text-light);
    margin-top: 1px;
}

/* ============================================
   图表区域
   ============================================ */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.chart-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 18px 16px;
    box-shadow: var(--shadow);
}

.chart-card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

.chart-card h3 i {
    color: var(--primary);
}

.chart-card.full-width {
    grid-column: 1 / -1;
}

/* 饼图 */
.pie-chart-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    padding: 10px 0;
}

.pie-placeholder {
    width: 160px;
    height: 160px;
    border-radius: 50%;
    position: relative;
    background: conic-gradient(
        var(--income) 0% var(--income-percent, 60%),
        var(--expense) var(--income-percent, 60%) 100%
    );
    flex-shrink: 0;
}

.pie-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 96px;
    height: 96px;
    background: var(--card-bg);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.pie-income { color: var(--income); font-weight: 600; font-size: 12px; }
.pie-expense { color: var(--expense); font-weight: 600; font-size: 12px; }

/* 饼图图例 */
.pie-legend {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 100px;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}
.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}
.legend-dot.income { background: var(--income); }
.legend-dot.expense { background: var(--expense); }
.legend-label { color: var(--text-light); font-size: 13px; }
.legend-value { font-weight: 600; color: var(--text); margin-left: auto; font-size: 13px; }

/* 柱状图 */
.bar-chart-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 260px;
    overflow-y: auto;
}

.bar-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bar-label {
    width: 60px;
    font-size: 12px;
    color: var(--text-light);
    text-align: right;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bar-track {
    flex: 1;
    height: 24px;
    background: var(--bg);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

.bar-fill {
    height: 100%;
    border-radius: 12px;
    transition: width 0.8s ease;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 8px;
    font-size: 11px;
    font-weight: 600;
    color: white;
}

.bar-fill.income { background: linear-gradient(90deg, var(--income), #34d399); }
.bar-fill.expense { background: linear-gradient(90deg, var(--expense), #f87171); }

/* 趋势图 */
.trend-chart-container {
    height: 240px;
    position: relative;
}

.trend-chart {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    height: 100%;
    padding: 16px 0;
    gap: 4px;
}

.trend-month {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 36px;
}

.trend-bars {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 160px;
    width: 100%;
    justify-content: center;
}

.trend-bar {
    width: 16px;
    border-radius: 3px 3px 0 0;
    transition: height 0.8s ease;
    position: relative;
}

.trend-bar.income { background: var(--income); }
.trend-bar.expense { background: var(--expense); }

.trend-bar:hover::after {
    content: attr(data-value);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 10;
}

.trend-label {
    font-size: 10px;
    color: var(--text-light);
}

/* ============================================
   表格 - 基础样式
   ============================================ */
.table-container {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 600px;
}

.data-table thead {
    background: var(--bg);
}

.data-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-light);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    white-space: nowrap;
}

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

.data-table tbody tr:hover {
    background: rgba(79, 70, 229, 0.03);
}

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

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-income {
    background: rgba(16, 185, 129, 0.1);
    color: var(--income);
}

.badge-expense {
    background: rgba(239, 68, 68, 0.1);
    color: var(--expense);
}

.badge-active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--info);
}

.badge-completed {
    background: #28a745;
    color: #ffffff;
    padding: 2px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    display: inline-block;
    white-space: nowrap;
}

/* 操作按钮 */
.action-btns {
    display: flex;
    gap: 4px;
    align-items: center;
    white-space: nowrap;
}

.btn-icon {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    font-size: 13px;
    background: transparent;
    flex-shrink: 0;
}

.btn-edit {
    color: var(--primary);
}
.btn-edit:hover {
    background: var(--primary);
    color: white;
}

.btn-delete {
    color: #dc3545;
}
.btn-delete:hover {
    background: #dc3545;
    color: white;
}

.btn-verify {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}
.btn-verify:hover {
    background: var(--success);
    color: white;
}

.btn-view {
    color: var(--secondary);
}
.btn-view:hover {
    background: var(--secondary);
    color: white;
}

.btn-danger {
    background: #dc3545;
    color:#fff;
    border:none;
    padding:4px 10px;
    border-radius:4px;
    cursor:pointer;
    font-size:12px;
    white-space:nowrap;
}

.btn-text.btn-verify-btn {
    border: 1px solid #28a745;
    color: #28a745;
    background: transparent;
    border-radius: 4px;
    padding: 2px 10px;
    font-size: 12px;
    white-space: nowrap;
    cursor: pointer;
    transition: 0.2s;
}
.btn-text.btn-verify-btn:hover {
    background-color: #28a745;
    color: #ffffff;
}

/* ============================================
   分页
   ============================================ */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 16px;
    padding: 12px 0;
}

.page-btn {
    min-width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 13px;
    transition: var(--transition);
    color: var(--text);
    padding: 0 12px;
}

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

.page-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   操作栏
   ============================================ */
.action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 10px;
}

.tab-switch {
    display: flex;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 3px;
}

.tab-btn {
    padding: 6px 16px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-light);
    transition: var(--transition);
}

.tab-btn.active {
    background: var(--card-bg);
    color: var(--primary);
    box-shadow: var(--shadow);
}

/* ============================================
   类型管理
   ============================================ */
.types-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.type-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 18px 16px;
    box-shadow: var(--shadow);
}

.type-section h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.type-section h3 i {
    color: var(--primary);
}

.type-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.type-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.type-item:hover {
    background: rgba(79, 70, 229, 0.08);
}

.type-name {
    font-weight: 500;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.type-name::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
}

/* ============================================
   导入导出
   ============================================ */
.import-export-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.ie-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px 20px;
    box-shadow: var(--shadow);
    text-align: center;
}

.ie-icon {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.ie-icon i {
    font-size: 24px;
    color: white;
}

.ie-card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 6px;
}

.ie-card > p {
    color: var(--text-light);
    margin-bottom: 18px;
    font-size: 13px;
}

.ie-filters {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
    text-align: left;
}

.ie-filters .filter-group {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: unset;
    max-width: unset;
}

.ie-filters .filter-group label {
    min-width: 60px;
    font-size: 12px;
    white-space: nowrap;
}

.ie-filters .filter-group select,
.ie-filters .filter-group input {
    flex: 1;
    min-width: unset;
    padding: 6px 10px;
    font-size: 12px;
    height: 32px;
}

.import-template {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 16px;
    text-align: left;
}

.template-title {
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 13px;
}

.template-content {
    font-size: 12px;
    color: var(--text-light);
    line-height: 1.8;
}

.template-content code {
    display: block;
    background: var(--card-bg);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    margin: 6px 0;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: var(--primary);
    word-break: break-all;
}

.template-example {
    color: var(--text);
    font-style: italic;
}

.file-upload {
    margin-bottom: 14px;
}

.file-upload input {
    display: none;
}

.file-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 24px 16px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-light);
}

.file-label:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(79, 70, 229, 0.02);
}

.file-label i {
    font-size: 28px;
}

.file-label span {
    font-size: 13px;
}

.import-result {
    margin-top: 12px;
    padding: 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    display: none;
}

.import-result.success {
    display: block;
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.import-result.error {
    display: block;
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

/* ============================================
   模态框
   ============================================ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
    padding: 20px;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    transition: var(--transition);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

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

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    width: 30px;
    height: 30px;
    border: none;
    background: var(--bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-light);
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--danger);
    color: white;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
}

/* 表单 */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    transition: var(--transition);
    background: var(--card-bg);
    font-family: inherit;
}

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

.form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

/* 核销记录模态框 */
.logs-modal {
    max-width: 600px;
}

.prepayment-info {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 16px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.prepayment-info-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.prepayment-info-item label {
    font-size: 11px;
    color: var(--text-light);
}

.prepayment-info-item span {
    font-size: 14px;
    font-weight: 600;
}

/* ============================================
   Toast 提示
   ============================================ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 90%;
}

.toast {
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-lg);
    animation: slideInRight 0.3s ease;
    min-width: 240px;
    border-left: 4px solid;
}

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

.toast i {
    font-size: 18px;
}

.toast.success i { color: var(--success); }
.toast.error i { color: var(--danger); }
.toast.warning i { color: var(--warning); }
.toast.info i { color: var(--info); }

.toast-message {
    flex: 1;
    font-size: 13px;
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
}

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

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ============================================
   移动端菜单按钮
   ============================================ */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 101;
    width: 40px;
    height: 40px;
    background: var(--card-bg);
    border: none;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--text);
    cursor: pointer;
}

.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

/* ============================================
   空状态
   ============================================ */
.empty-state {
    text-align: center;
    padding: 40px 16px;
    color: var(--text-light);
}

.empty-state i {
    font-size: 36px;
    margin-bottom: 12px;
    opacity: 0.5;
}

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

/* ============================================
   预收底部统计
   ============================================ */
.pre-footer-stats {
    margin: 12px 0;
    display: flex;
    gap: 16px;
    font-size: 13px;
    padding: 10px 14px;
    background: #f8f9fa;
    border-radius: 6px;
    flex-wrap: wrap;
}

.pre-footer-stats div {
    white-space: nowrap;
}

.pre-footer-stats span {
    font-weight: 500;
}

/* ============================================
   明细底部统计
   ============================================ */
.trans-footer-stats {
    margin: 12px 0;
    display: flex;
    gap: 20px;
    font-size: 14px;
    padding: 10px 14px;
    background: #f8f9fa;
    border-radius: 6px;
    flex-wrap: wrap;
}

.trans-footer-stats div {
    white-space: nowrap;
}

/* ============================================
   加载动画
   ============================================ */
.loading {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

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

.stat-value {
    animation: countUp 0.5s ease;
}

/* ============================================
   日期区间日历面板
   ============================================ */
.range-calendar-panel {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    box-shadow: var(--shadow-lg);
    z-index: 9999;
}
.range-calendar-panel .cal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.range-calendar-panel .cal-header button {
    background: transparent;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 10px;
    color: var(--text);
}
.range-calendar-panel .cal-header button:hover {
    color: var(--primary);
}
.range-calendar-panel .cal-header span {
    font-weight: 600;
    font-size: 14px;
}
.range-calendar-panel .cal-table {
    border-collapse: collapse;
    text-align: center;
    width: 100%;
}
.range-calendar-panel .cal-table th {
    width: 36px;
    padding: 4px;
    font-size: 11px;
    font-weight: normal;
    color: var(--text-light);
}
.range-calendar-panel .cal-table td {
    padding: 4px;
    height: 32px;
    line-height: 32px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 13px;
}
.range-calendar-panel .cal-table td:hover {
    background: rgba(79, 70, 229, 0.08);
}
.range-calendar-panel .cal-footer {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ============================================
   ========== 响应式设计 ==========
   ============================================ */

/* 平板 */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .charts-grid {
        grid-template-columns: 1fr;
    }
    .types-grid,
    .import-export-grid {
        grid-template-columns: 1fr;
    }
}

/* 手机端 */
@media (max-width: 768px) {
    /* 侧边栏 */
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
        padding: 56px 10px 20px;
    }
    .mobile-menu-btn {
        display: flex;
    }
    .overlay.active {
        display: block;
    }

    /* 页面标题 */
    .page-title {
        font-size: 17px;
        margin-bottom: 12px;
        gap: 8px;
    }
    .page-title i {
        font-size: 17px;
    }

    /* ===== 筛选栏 - 移动端自适应 ===== */
    .filter-bar {
        padding: 10px 12px;
        gap: 6px 8px;
        position: relative;
        z-index: 10;
        display: flex;
        flex-wrap: wrap;
    }

    .filter-group {
        flex: 0 1 auto;
        min-width: 55px;
        max-width: 130px;
    }
    .filter-group label {
        font-size: 10px;
        white-space: nowrap;
    }
    .filter-group select,
    .filter-group input {
        padding: 5px 8px;
        font-size: 12px;
        height: 32px;
        padding-right: 24px;
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    /* ===== 日期区间 - 自适应屏幕宽度 ===== */
    .filter-group.date-range-wrap {
        flex: 0 1 auto !important;
        min-width: 80px !important;
        max-width: 140px !important;
        width: auto !important;
    }
    .filter-group.date-range-wrap input {
        font-size: 10px !important;
        padding: 5px 6px !important;
        min-width: 0 !important;
        width: 100% !important;
        box-sizing: border-box !important;
        text-overflow: ellipsis !important;
        letter-spacing: 0px !important;
    }

    /* ===== 项目输入框 ===== */
    .filter-group:has(input#filter-project),
    .filter-group:has(input#summary-project) {
        flex: 0 1 100px !important;
        min-width: 70px !important;
        max-width: 130px !important;
    }

    /* ===== 按钮 - 自动换行 ===== */
    .filter-bar .btn-primary,
    .filter-bar .btn-secondary {
        padding: 5px 12px;
        font-size: 12px;
        height: 32px;
        flex: 0 0 auto;
        margin-left: auto;
        order: 999;
    }

    /* ===== 日期日历面板 - 居中弹出 ===== */
    .range-calendar-panel {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        width: 92% !important;
        max-width: 340px !important;
        z-index: 99999 !important;
        padding: 14px !important;
        border-radius: 10px !important;
        background: #fff !important;
        box-shadow: 0 8px 40px rgba(0,0,0,0.25) !important;
    }
    .range-calendar-panel .cal-table td {
        padding: 2px !important;
        height: 28px !important;
        line-height: 28px !important;
        font-size: 13px !important;
    }

    /* ===== 项目下拉框 - 移动端 ===== */
    #project-dropdown,
    #summary-project-dropdown {
        position: fixed !important;
        left: 10px !important;
        right: 10px !important;
        top: auto !important;
        max-height: 180px !important;
        border-radius: 8px !important;
        z-index: 99999 !important;
        background: #fff !important;
        border: 1px solid var(--border) !important;
        box-shadow: 0 4px 20px rgba(0,0,0,0.15) !important;
    }

    /* ===== 表格 - 强制单行 + 左右滑动 ===== */
    .table-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        overflow-y: visible !important;
    }

    .data-table {
        font-size: 12px !important;
        min-width: 700px !important;
        width: auto !important;
        table-layout: auto !important;
    }

    .data-table th,
    .data-table td {
        padding: 8px 12px !important;
        white-space: nowrap !important;
        word-break: keep-all !important;
        word-wrap: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        vertical-align: middle !important;
        line-height: 1.4 !important;
        max-width: none !important;
    }

    .data-table th {
        font-size: 11px !important;
    }

    .data-table td {
        font-size: 12px !important;
    }

    /* 表格内的 badge 和标签保持单行 */
    .data-table .badge,
    .data-table .badge-completed,
    .data-table .badge-income,
    .data-table .badge-expense,
    .data-table .badge-active {
        white-space: nowrap !important;
        display: inline-block !important;
        font-size: 11px !important;
        padding: 2px 10px !important;
        line-height: 1.4 !important;
    }

    /* 操作按钮保持单行 */
    .data-table .action-btns {
        white-space: nowrap !important;
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 4px !important;
    }

    .data-table .action-btns .btn-icon,
    .data-table .action-btns .btn-text {
        flex-shrink: 0 !important;
        white-space: nowrap !important;
    }

    /* 空状态 */
    .data-table .empty-state {
        white-space: normal !important;
        padding: 30px 16px !important;
    }

    /* ===== 统计卡片 ===== */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .stat-card {
        padding: 12px 10px;
        gap: 10px;
    }
    .stat-icon {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    .stat-value {
        font-size: 16px;
    }
    .stat-label {
        font-size: 11px;
    }
    .stat-sub {
        font-size: 9px;
    }

    /* ===== 图表 ===== */
    .charts-grid {
        gap: 12px;
    }
    .chart-card {
        padding: 14px 12px;
    }
    .chart-card h3 {
        font-size: 13px;
        margin-bottom: 10px;
    }
    .pie-chart-container {
        flex-direction: column;
        align-items: center;
        gap: 12px;
        padding: 0;
    }
    .pie-placeholder {
        width: 140px;
        height: 140px;
    }
    .pie-center {
        width: 84px;
        height: 84px;
    }
    .pie-center span {
        font-size: 11px !important;
    }
    .pie-legend {
        flex-direction: row;
        gap: 16px;
        min-width: unset;
    }
    .legend-item {
        font-size: 12px;
    }
    .legend-value {
        font-size: 12px;
    }

    /* ===== 操作栏 ===== */
    .action-bar {
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }
    .action-bar .btn-primary {
        width: 100%;
        justify-content: center;
        padding: 10px;
        font-size: 13px;
    }
    .tab-switch {
        width: 100%;
        justify-content: stretch;
    }
    .tab-btn {
        flex: 1;
        text-align: center;
        padding: 6px 8px;
        font-size: 12px;
    }

    /* ===== 类型管理 ===== */
    .types-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .type-section {
        padding: 14px 12px;
    }
    .type-item {
        padding: 8px 12px;
    }
    .type-name {
        font-size: 13px;
    }

    /* ===== 导入导出 ===== */
    .import-export-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .ie-card {
        padding: 18px 14px;
    }
    .ie-card h3 {
        font-size: 15px;
    }
    .ie-card > p {
        font-size: 12px;
    }
    .ie-filters .filter-group {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        min-width: unset;
        max-width: unset;
    }
    .ie-filters .filter-group label {
        min-width: unset;
        font-size: 11px;
    }
    .ie-filters .filter-group select,
    .ie-filters .filter-group input {
        width: 100%;
        min-width: unset;
    }
    .file-label {
        padding: 18px 12px;
    }
    .file-label i {
        font-size: 24px;
    }
    .file-label span {
        font-size: 12px;
    }

    /* ===== 模态框 ===== */
    .modal {
        max-width: 100%;
        margin: 0 12px;
        max-height: 95vh;
    }
    .modal-header {
        padding: 14px 16px;
    }
    .modal-header h3 {
        font-size: 15px;
    }
    .modal-body {
        padding: 16px;
    }
    .modal-footer {
        padding: 12px 16px;
    }
    .modal-footer .btn-primary,
    .modal-footer .btn-secondary {
        padding: 10px 18px;
        font-size: 13px;
        flex: 1;
    }
    .form-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .form-group {
        margin-bottom: 12px;
    }
    .form-group label {
        font-size: 12px;
    }
    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 8px 10px;
        font-size: 13px;
    }

    /* ===== 预收信息卡片 ===== */
    .prepayment-info {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 12px;
    }
    .prepayment-info-item span {
        font-size: 13px;
    }

    /* ===== 底部统计 ===== */
    .pre-footer-stats {
        gap: 8px 14px;
        font-size: 12px;
        padding: 8px 12px;
        flex-wrap: wrap;
    }
    .pre-footer-stats div {
        white-space: nowrap;
    }
    .trans-footer-stats {
        gap: 10px 16px;
        font-size: 12px;
        padding: 8px 12px;
        flex-wrap: wrap;
    }
    .trans-footer-stats div {
        white-space: nowrap;
    }

    /* ===== Toast ===== */
    .toast-container {
        left: 12px;
        right: 12px;
        top: 12px;
        max-width: 100%;
    }
    .toast {
        min-width: unset;
        padding: 10px 14px;
        font-size: 13px;
    }

    /* ===== 分页 ===== */
    .pagination {
        gap: 4px;
        padding: 10px 0;
        flex-wrap: wrap;
    }
    .page-btn {
        min-width: 28px;
        height: 28px;
        font-size: 12px;
        padding: 0 10px;
    }
    .pagination span {
        font-size: 12px;
    }

    /* ===== 登录 ===== */
    .login-box {
        padding: 32px 20px;
    }
    .login-box h1 {
        font-size: 22px;
    }
    .login-icon {
        width: 64px;
        height: 64px;
    }
    .login-icon i {
        font-size: 28px;
    }

    /* ===== 操作按钮 ===== */
    .action-btns .btn-text.btn-verify-btn {
        font-size: 11px;
        padding: 2px 8px;
    }
    .action-btns .btn-icon {
        width: 24px;
        height: 24px;
        font-size: 12px;
    }

    /* ===== 趋势图 ===== */
    .trend-chart-container {
        height: 180px;
    }
    .trend-bars {
        height: 120px;
    }
    .trend-bar {
        width: 12px;
    }
    .trend-label {
        font-size: 9px;
    }

    /* ===== 预收管理 - 表格强制单行 ===== */
    #prepayments-table.data-table {
        min-width: 750px !important;
    }
    #prepayments-table.data-table th,
    #prepayments-table.data-table td {
        white-space: nowrap !important;
    }
}

/* 小手机（<400px） */
@media (max-width: 400px) {
    .main-content {
        padding: 52px 6px 16px;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .stat-card {
        padding: 8px 6px;
        gap: 6px;
    }
    .stat-icon {
        width: 28px;
        height: 28px;
        font-size: 11px;
    }
    .stat-value {
        font-size: 13px;
    }
    .stat-label {
        font-size: 9px;
    }
    .stat-sub {
        font-size: 8px;
    }

    .filter-bar {
        padding: 8px 8px;
        gap: 4px 6px;
    }
    .filter-group {
        min-width: 45px;
        max-width: 90px;
    }
    .filter-group label {
        font-size: 9px;
    }
    .filter-group select,
    .filter-group input {
        padding: 4px 6px;
        font-size: 10px;
        height: 26px;
        padding-right: 20px;
    }

    /* 日期区间 - 小手机更窄 */
    .filter-group.date-range-wrap {
        min-width: 60px !important;
        max-width: 110px !important;
    }
    .filter-group.date-range-wrap input {
        font-size: 9px !important;
        padding: 4px 4px !important;
    }

    .filter-group:has(input#filter-project),
    .filter-group:has(input#summary-project) {
        min-width: 55px !important;
        max-width: 100px !important;
    }

    .filter-bar .btn-primary,
    .filter-bar .btn-secondary {
        padding: 4px 8px;
        font-size: 10px;
        height: 26px;
    }

    .page-title {
        font-size: 15px;
    }

    /* 表格更紧凑 */
    .data-table {
        min-width: 550px !important;
        font-size: 11px !important;
    }
    #prepayments-table.data-table {
        min-width: 600px !important;
    }
    .data-table th,
    .data-table td {
        padding: 5px 8px !important;
        font-size: 11px !important;
    }
    .data-table th {
        font-size: 10px !important;
    }

    .pie-placeholder {
        width: 110px;
        height: 110px;
    }
    .pie-center {
        width: 64px;
        height: 64px;
    }
    .pie-center span {
        font-size: 9px !important;
    }
    .pre-footer-stats {
        font-size: 10px;
        gap: 4px 8px;
        padding: 6px 8px;
    }
    .trans-footer-stats {
        font-size: 10px;
        gap: 4px 10px;
        padding: 6px 8px;
    }
    .modal {
        margin: 0 6px;
    }
    .modal-header h3 {
        font-size: 14px;
    }
    .modal-body {
        padding: 12px;
    }
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 12px;
        padding: 6px 8px;
    }
}

/* ============================================
   权限控制元素默认隐藏（防止异步权限加载前的闪现）
   ============================================ */
#add-trans-btn,
#add-type-btn,
#add-user-btn,
#add-account-btn,
#export-btn,
#import-btn {
    display: none;
}