/* ===== 全局样式 ===== */
:root {
    --primary: #4472C4;
    --primary-dark: #2F5597;
    --primary-light: #D6E0F0;
    --success: #27AE60;
    --danger: #E74C3C;
    --warning: #F39C12;
    --info: #3498DB;
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --text: #333333;
    --text-light: #666666;
    --border: #e0e0e0;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-hover: 0 4px 16px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

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

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

.login-container {
    width: 100%;
    max-width: 420px;
}

.login-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 40px 32px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.logo-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.login-header h1 {
    font-size: 20px;
    color: var(--text);
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-light);
    font-size: 14px;
}

.login-footer {
    text-align: center;
    color: rgba(255,255,255,0.7);
    font-size: 12px;
    margin-top: 20px;
}

/* ===== 面容识别 ===== */
.face-scan-area {
    position: relative;
    width: 200px;
    height: 200px;
    margin: 20px auto;
    border-radius: 50%;
    overflow: hidden;
    background: #1a1a2e;
    border: 3px solid var(--primary);
}

.face-scan-area video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

.face-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    pointer-events: none;
    padding-bottom: 20px;
}

.face-frame {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 140px;
    height: 170px;
    border: 2px solid rgba(255,255,255,0.5);
    border-radius: 50%;
}

.face-hint {
    color: rgba(255,255,255,0.8);
    font-size: 12px;
    background: rgba(0,0,0,0.5);
    padding: 4px 12px;
    border-radius: 12px;
}

.face-status {
    text-align: center;
    color: var(--text-light);
    font-size: 13px;
    margin: 8px 0;
    min-height: 20px;
}

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

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
    background: #fff;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

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

/* ===== 按钮 ===== */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    line-height: 1.4;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

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

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

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-warning {
    background: var(--warning);
    color: #fff;
}

.btn-block {
    display: block;
    width: 100%;
    text-align: center;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

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

/* ===== Tab ===== */
.tab-group {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    background: #f0f2f5;
    border-radius: var(--radius-sm);
    padding: 4px;
}

.tab-btn {
    flex: 1;
    padding: 8px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    color: var(--text-light);
    transition: all 0.2s;
}

.tab-btn.active {
    background: #fff;
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    font-weight: 500;
}

/* ===== 提示框 ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
}

.alert strong {
    display: block;
    margin-bottom: 4px;
}

.alert p {
    font-size: 13px;
    opacity: 0.8;
}

.alert-error {
    background: #fdeaea;
    color: var(--danger);
    border: 1px solid #f5c6c6;
}

.alert-info {
    background: #e8f4fd;
    color: var(--info);
    border: 1px solid #b8daff;
}

.alert-success {
    background: #e8f8e8;
    color: var(--success);
    border: 1px solid #c3e6c3;
}

.alert-warning {
    background: #fff8e1;
    color: var(--warning);
    border: 1px solid #ffe082;
}

/* ===== 随机密码展示 ===== */
.random-pwd {
    background: #f0f7ff;
    padding: 8px 12px;
    border-radius: 6px;
    font-family: monospace;
    font-size: 16px;
    color: var(--primary);
    text-align: center;
    font-weight: bold;
}

/* ===== Loading ===== */
.loading {
    text-align: center;
    padding: 20px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--primary-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

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

/* ===== 仪表盘布局 ===== */
.dashboard-page {
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 56px;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 16px;
    color: var(--primary-dark);
}

.topbar-brand .logo-icon {
    font-size: 24px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-user {
    font-size: 14px;
    color: var(--text-light);
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: #f0f2f5;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: #e0e3eb;
}

/* ===== 侧边导航 ===== */
.layout {
    display: flex;
    min-height: calc(100vh - 56px);
}

.sidebar {
    width: 200px;
    background: #fff;
    border-right: 1px solid var(--border);
    padding: 12px 0;
    flex-shrink: 0;
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    cursor: pointer;
    color: var(--text-light);
    font-size: 14px;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

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

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 500;
}

.nav-icon {
    font-size: 18px;
    width: 20px;
    text-align: center;
}

.main-content {
    flex: 1;
    padding: 20px;
    overflow-x: hidden;
    min-width: 0;
}

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

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

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

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

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
}

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

.stat-label {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
}

.stat-card.income .stat-value { color: var(--success); }
.stat-card.expense .stat-value { color: var(--danger); }
.stat-card.profit .stat-value { color: var(--warning); }
.stat-card.balance .stat-value { color: var(--info); }

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

/* ===== 表格 ===== */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

table.data-table th {
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
    position: sticky;
    top: 0;
}

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

table.data-table tr:hover {
    background: #f8f9fa;
}

.text-income { color: var(--success); font-weight: 500; }
.text-expense { color: var(--danger); font-weight: 500; }
.text-profit { color: var(--warning); font-weight: 500; }

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

.modal {
    background: #fff;
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

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

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

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-light);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.modal-close:hover {
    background: #f0f2f5;
}

.modal-body {
    padding: 20px;
}

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

/* ===== 标签 ===== */
.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.tag-income {
    background: #e8f8e8;
    color: var(--success);
}

.tag-expense {
    background: #fdeaea;
    color: var(--danger);
}

.tag-normal {
    background: #e8f4fd;
    color: var(--info);
}

.tag-warning {
    background: #fff8e1;
    color: var(--warning);
}

.tag-danger {
    background: #fdeaea;
    color: var(--danger);
}

/* ===== 过滤器 ===== */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
    align-items: center;
}

.filter-bar select,
.filter-bar input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    min-width: 100px;
}

.filter-bar .spacer {
    flex: 1;
}

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

.pagination button {
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.pagination button.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.pagination button:disabled {
    opacity: 0.5;
}

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

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

/* ===== 响应式：手机端 ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        width: 240px;
        z-index: 99;
        transition: left 0.3s;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-backdrop {
        position: fixed;
        top: 56px; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.4);
        z-index: 98;
        display: none;
    }

    .sidebar-backdrop.show {
        display: block;
    }

    .menu-toggle {
        display: flex !important;
    }

    .main-content {
        padding: 12px;
    }

    .stat-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-value {
        font-size: 18px;
    }

    .stat-label {
        font-size: 12px;
    }

    .stat-sub {
        font-size: 11px;
    }

    .card {
        padding: 14px;
        margin-bottom: 14px;
    }

    .topbar-brand span:not(.logo-icon) {
        display: none;
    }

    .topbar-user {
        display: none;
    }

    .modal {
        max-width: 100%;
        margin: 0;
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-bar select,
    .filter-bar input {
        width: 100%;
    }

    .filter-bar .spacer {
        display: none;
    }

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

    table.data-table th,
    table.data-table td {
        padding: 8px;
    }

    .login-card {
        padding: 28px 20px;
    }

    .login-header h1 {
        font-size: 18px;
    }
}

/* 菜单按钮（手机端） */
.menu-toggle {
    display: none;
    width: 36px;
    height: 36px;
    border: none;
    background: #f0f2f5;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    align-items: center;
    justify-content: center;
}

@media (min-width: 769px) {
    .menu-toggle {
        display: none !important;
    }
}

/* ===== 浮动添加按钮（手机端） */
.fab {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(68,114,196,0.4);
    z-index: 50;
    align-items: center;
    justify-content: center;
}

@media (max-width: 768px) {
    .fab {
        display: flex;
    }
}

/* ===== 图表容器 ===== */
.chart-container {
    width: 100%;
    height: 300px;
    margin-top: 12px;
}

/* ===== Toast 通知 ===== */
.toast-container {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: #fff;
    border-radius: 8px;
    padding: 12px 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    font-size: 14px;
    animation: slideIn 0.3s ease;
    border-left: 4px solid var(--primary);
    max-width: 320px;
}

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

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

/* ===== 工具类 ===== */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-bold { font-weight: 600; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.hidden { display: none; }
