/* ========================================
   FinBooks 财务记账系统 - 主样式表
   ======================================== */

/* ===== 基础重置 ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #1677ff;
    --primary-hover: #4096ff;
    --primary-bg: #e6f4ff;
    --success: #52c41a;
    --warning: #faad14;
    --danger: #ff4d4f;
    --text-primary: #1f1f1f;
    --text-secondary: #595959;
    --text-muted: #999;
    --border-color: #d9d9d9;
    --bg-page: #f5f5f5;
    --bg-white: #ffffff;
    --sidebar-width: 220px;
    --sidebar-header-height: 60px;
    --topbar-height: 56px;
    --radius: 6px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

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

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

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

/* ===== 侧边栏 ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-white);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-header {
    height: var(--sidebar-header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

.version {
    font-size: 10px;
    color: var(--text-muted);
    margin-left: 6px;
}

.sidebar-nav ul {
    list-style: none;
    padding: 8px 0;
}

.nav-section {
    padding: 8px 20px 4px;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.nav-item a {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    color: var(--text-secondary);
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

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

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

/* ===== 主内容 ===== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

/* ===== 顶部栏 ===== */
.top-bar {
    height: var(--topbar-height);
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

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

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-info {
    color: var(--text-secondary);
    font-size: 13px;
}

.logout-btn {
    color: var(--text-muted);
    font-size: 13px;
    padding: 4px 12px;
    border-radius: var(--radius);
    transition: all 0.2s;
}

.logout-btn:hover {
    color: var(--danger);
    background: #fff1f0;
}

/* ===== 内容区 ===== */
.content-area {
    padding: 24px;
    flex: 1;
}

/* ===== 按钮 ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 16px;
    font-size: 13px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-white);
    color: var(--text-primary);
    font-family: inherit;
}

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

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

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

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

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

.btn-sm {
    padding: 3px 10px;
    font-size: 12px;
}

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ===== 表格 ===== */
.table-container {
    background: var(--bg-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: #fafafa;
}

th, td {
    padding: 10px 16px;
    text-align: left;
    border-bottom: 1px solid #f0f0f0;
    font-size: 13px;
}

th {
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

tbody tr:hover {
    background: #fafafa;
}

.text-right {
    text-align: right;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-muted);
}

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

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

.form-control {
    width: 100%;
    padding: 6px 12px;
    font-size: 13px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

select.form-control {
    appearance: none;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23595959' d='M6 8L2 4h8z'/%3E%3C/svg%3E") no-repeat right 8px center;
    padding-right: 28px;
}

/* ===== 卡片 ===== */
.card {
    background: var(--bg-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

.card-body {
    padding: 16px;
}

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

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

.stat-card .stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

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

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

/* ===== 标签/徽章 ===== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
}

.badge-success { background: #f6ffed; color: var(--success); border: 1px solid #b7eb8f; }
.badge-warning { background: #fffbe6; color: #d48806; border: 1px solid #ffe58f; }
.badge-danger   { background: #fff2f0; color: var(--danger); border: 1px solid #ffa39e; }
.badge-info     { background: #e6f4ff; color: var(--primary); border: 1px solid #91caff; }
.badge-default { background: #f5f5f5; color: var(--text-muted); border: 1px solid #d9d9d9; }

/* ===== 弹窗/模态框 ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-white);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
}

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

.modal-body {
    padding: 24px;
}

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

/* ===== 凭证录入特殊样式 ===== */
.voucher-form {
    max-width: 900px;
}

.voucher-header {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.voucher-entries {
    margin-top: 16px;
}

.voucher-entries table th,
.voucher-entries table td {
    padding: 6px 8px;
}

.voucher-entries .amount-input {
    text-align: right;
    font-family: 'Consolas', monospace;
    width: 140px;
}

.voucher-total {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-top: 2px solid var(--text-primary);
    margin-top: 8px;
    font-weight: 600;
}

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

.login-card {
    background: var(--bg-white);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 400px;
    padding: 40px;
}

.login-card h2 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 24px;
}

.login-card .form-group {
    margin-bottom: 20px;
}

.login-card .btn {
    width: 100%;
    padding: 10px;
    font-size: 15px;
}

/* ===== 安装页 ===== */
.install-wrapper {
    max-width: 700px;
    margin: 60px auto;
    background: var(--bg-white);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 40px;
}

.install-wrapper h2 {
    text-align: center;
    margin-bottom: 24px;
}

.install-steps {
    counter-reset: step;
}

.install-step {
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: 12px;
    position: relative;
    padding-left: 60px;
}

.install-step::before {
    counter-increment: step;
    content: counter(step);
    position: absolute;
    left: 16px;
    top: 16px;
    width: 28px;
    height: 28px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

.install-step.completed {
    border-color: var(--success);
}

.install-step.completed::before {
    content: '✓';
    background: var(--success);
}

.install-step.error {
    border-color: var(--danger);
}

.install-step.error::before {
    content: '✗';
    background: var(--danger);
}

/* ===== 分页 ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 16px;
}

.pagination .page-btn {
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    background: var(--bg-white);
    font-size: 13px;
}

.pagination .page-btn:hover,
.pagination .page-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ===== 消息提示 ===== */
.alert {
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}

.alert-success {
    background: #f6ffed;
    border: 1px solid #b7eb8f;
    color: #389e0d;
}

.alert-error {
    background: #fff2f0;
    border: 1px solid #ffa39e;
    color: #cf1322;
}

.alert-info {
    background: #e6f4ff;
    border: 1px solid #91caff;
    color: #0958d9;
}

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

.empty-state svg {
    width: 120px;
    height: 120px;
    margin-bottom: 16px;
    opacity: 0.3;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .login-card {
        width: 90%;
        padding: 24px;
    }
}

/* ===== 打印样式 ===== */
@media print {
    .sidebar, .top-bar, .table-toolbar, .btn, .pagination {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .content-area {
        padding: 0;
    }
    
    table {
        font-size: 11px;
    }
    
    th, td {
        padding: 4px 8px;
    }
}
