/* ============================================
 * 记账系统 - 统一风格样式表
 * 翡翠绿设计语言 (参考 so 系统)
 * 移动端优先
 * ============================================ */

/* ===== 设计令牌 ===== */
:root {
    /* 背景色 */
    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --slate-light: #F1F5F9;

    /* 边框 */
    --border: #E2E8F0;
    --border-dark: #CBD5E1;

    /* 文字 */
    --text: #0F172A;
    --text-secondary: #64748B;
    --text-muted: #94A3B8;

    /* 主色 - 翡翠绿 */
    --accent: #059669;
    --accent-dark: #047857;
    --accent-deep: #065F46;
    --accent-light: #ECFDF5;
    --accent-hover: #047857;

    /* 危险色 - 红色 */
    --danger: #DC2626;
    --danger-light: #FEF2F2;
    --danger-border: #FECACA;

    /* 警告色 */
    --warning: #F59E0B;
    --warning-light: #FFFBEB;

    /* 信息色 */
    --info: #3B82F6;
    --info-light: #EFF6FF;

    /* 渐变 */
    --gradient: linear-gradient(135deg, #059669 0%, #047857 100%);
    --gradient-deep: linear-gradient(135deg, #047857 0%, #065F46 100%);

    /* 圆角 */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    /* 阴影 */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
    --shadow-accent: 0 2px 8px rgba(5,150,105,0.25);
    --shadow-accent-lg: 0 8px 25px rgba(5,150,105,0.35);

    /* 字体 */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
    --font-mono: 'Inter', 'SF Mono', 'Courier New', monospace;
}

/* ===== 基础重置 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-sans);
}

html {
    scrollbar-gutter: stable;
}

body {
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
}

/* ===== 通用容器 ===== */
.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 12px;
}

.page-wrap {
    max-width: 640px;
    margin: 0 auto;
    padding: 12px;
    min-height: 100vh;
}

/* ===== 顶部导航栏 ===== */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.topbar-inner {
    max-width: 640px;
    margin: 0 auto;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
}

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

.topbar-back {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--accent);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}

.topbar-back:hover {
    background: var(--accent-light);
}

.topbar-back svg {
    width: 20px;
    height: 20px;
}

.topbar-action {
    color: var(--accent);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}

.topbar-action:hover {
    background: var(--accent-light);
}

/* ===== 底部导航栏 ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    z-index: 50;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav-inner {
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 56px;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    padding: 6px 0;
    transition: color 0.15s;
}

.nav-item svg {
    width: 24px;
    height: 24px;
    stroke-width: 2;
}

.nav-item.active {
    color: var(--accent);
}

.nav-item:hover:not(.active) {
    color: var(--text-secondary);
}

/* ===== 卡片 ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
}

.card-flat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
    overflow: hidden;
}

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

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

.card-body {
    padding: 16px;
}

/* ===== 按钮 ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-block {
    display: flex;
    width: 100%;
    padding: 13px;
    font-size: 15px;
}

.btn-primary {
    background: var(--gradient);
    color: #FFFFFF;
    box-shadow: var(--shadow-accent);
}

.btn-primary:hover {
    background: var(--gradient-deep);
    transform: translateY(-1px);
    box-shadow: var(--shadow-accent-lg);
}

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

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

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

.btn-danger {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid var(--danger-border);
}

.btn-danger:hover {
    background: #FEE2E2;
}

.btn-ghost {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--accent-light);
    border-color: var(--accent);
}

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

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

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

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

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 15px;
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: all 0.15s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(5,150,105,0.12);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-muted);
}

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

.form-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 18px;
    padding-right: 40px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ===== 统计卡片 ===== */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px;
    text-align: center;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    font-family: var(--font-mono);
    letter-spacing: -0.02em;
    word-break: break-all;
    line-height: 1.2;
}

.stat-value.income {
    color: var(--accent);
}

.stat-value.expense {
    color: var(--danger);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

/* ===== 统计栏（带渐变标题） ===== */
.stats-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 12px;
}

.stats-bar-title {
    background: var(--gradient);
    color: #FFFFFF;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.stats-bar-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1px;
    background: var(--border);
}

.stats-bar-item {
    background: var(--surface);
    padding: 12px 14px;
    text-align: center;
}

.stats-bar-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 2px;
}

.stats-bar-value {
    font-size: 15px;
    font-weight: 700;
    font-family: var(--font-mono);
    letter-spacing: -0.02em;
    color: var(--text);
    word-break: break-all;
    line-height: 1.2;
}

/* ===== 交易列表 ===== */
.txn-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.txn-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
    cursor: pointer;
}

.txn-item:last-child {
    border-bottom: none;
}

.txn-item:hover {
    background: var(--slate-light);
}

.txn-item:active {
    background: var(--accent-light);
}

.txn-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.txn-icon.income {
    background: var(--accent-light);
    color: var(--accent);
}

.txn-icon.expense {
    background: var(--danger-light);
    color: var(--danger);
}

.txn-icon.transfer {
    background: #EFF6FF;
    color: var(--info);
}

.txn-info {
    flex: 1;
    min-width: 0;
}

.txn-desc {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.txn-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.txn-amount {
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font-mono);
    text-align: right;
    flex-shrink: 0;
}

.txn-amount.income {
    color: var(--accent);
}

.txn-amount.expense {
    color: var(--danger);
}

.txn-amount.transfer {
    color: var(--info);
}

/* ===== 标签 ===== */
.tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
}

.tag-income {
    background: var(--accent-light);
    color: var(--accent);
}

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

.tag-transfer {
    background: #EFF6FF;
    color: var(--info);
}

/* ===== 日期芯片 ===== */
.date-chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 4px 0;
    -webkit-overflow-scrolling: touch;
}

.date-chips::-webkit-scrollbar {
    display: none;
}

.date-chip {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    background: var(--slate-light);
    color: var(--text-secondary);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}

.date-chip:hover {
    background: var(--border);
}

.date-chip.active {
    background: var(--accent-light);
    color: var(--accent);
    border-color: #A7F3D0;
    font-weight: 600;
}

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

.empty-state svg {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    opacity: 0.4;
}

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

/* ===== Toast ===== */
.toast {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: var(--text);
    color: #FFFFFF;
    font-size: 13px;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
    max-width: 90%;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    background: var(--accent);
}

.toast.error {
    background: var(--danger);
}

/* ===== 模态框 ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

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

.modal {
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: 0 8px 30px rgba(0,0,0,0.18);
    width: 100%;
    max-width: 400px;
    max-height: 85vh;
    overflow-y: auto;
}

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

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

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.modal-body {
    padding: 20px;
}

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

/* ===== 快捷操作按钮 ===== */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.quick-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    text-decoration: none;
    transition: all 0.15s;
}

.quick-btn:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-accent);
}

.quick-btn:active {
    transform: scale(0.97);
}

.quick-btn-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.quick-btn-icon svg {
    width: 22px;
    height: 22px;
    stroke-width: 2;
}

.quick-btn-icon.income {
    background: var(--accent-light);
    color: var(--accent);
}

.quick-btn-icon.expense {
    background: var(--danger-light);
    color: var(--danger);
}

.quick-btn-icon.transfer {
    background: #EFF6FF;
    color: var(--info);
}

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

/* ===== 表格 ===== */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    background: var(--slate-light);
    color: var(--accent-deep);
    font-weight: 500;
    font-size: 12px;
    padding: 9px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

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

.data-table tbody tr:hover {
    background: var(--accent-light);
}

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

/* ===== 进度条 ===== */
.progress-bar {
    height: 6px;
    background: var(--slate-light);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.progress-bar-fill.income {
    background: var(--accent);
}

.progress-bar-fill.expense {
    background: var(--danger);
}

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

.page-btn {
    height: 30px;
    min-width: 30px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    background: var(--slate-light);
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.page-btn:hover:not(:disabled) {
    background: var(--border);
}

.page-btn.active {
    background: var(--accent);
    color: #FFFFFF;
}

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

/* ===== 加载动画 ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.6);
    z-index: 90;
    display: none;
    align-items: center;
    justify-content: center;
}

.loading-overlay.show {
    display: flex;
}

.loading-box {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 20px 28px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
}

.loading-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ===== 列表组 ===== */
.list-group {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.list-group-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.list-group-item:last-child {
    border-bottom: none;
}

.list-group-item:hover {
    background: var(--slate-light);
}

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

/* ===== 文字工具类 ===== */
.text-income { color: var(--accent) !important; }
.text-expense { color: var(--danger) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-center { text-align: center !important; }
.text-right { text-align: right !important; }
.font-mono { font-family: var(--font-mono) !important; }
.font-bold { font-weight: 700 !important; }
.font-semibold { font-weight: 600 !important; }
.font-medium { font-weight: 500 !important; }
.text-sm { font-size: 13px !important; }
.text-xs { font-size: 12px !important; }
.text-lg { font-size: 16px !important; }
.text-xl { font-size: 18px !important; }
.text-2xl { font-size: 22px !important; }

/* ===== 布局工具类 ===== */
.flex { display: flex !important; }
.flex-col { flex-direction: column !important; }
.items-center { align-items: center !important; }
.justify-between { justify-content: space-between !important; }
.justify-center { justify-content: center !important; }
.gap-2 { gap: 8px !important; }
.gap-3 { gap: 12px !important; }
.gap-4 { gap: 16px !important; }
.flex-1 { flex: 1 !important; }
.mt-2 { margin-top: 8px !important; }
.mt-4 { margin-top: 16px !important; }
.mb-2 { margin-bottom: 8px !important; }
.mb-4 { margin-bottom: 16px !important; }
.w-full { width: 100% !important; }
.hidden { display: none !important; }

/* ===== 滚动条 ===== */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-dark);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== 打印 ===== */
@media print {
    .bottom-nav, .topbar, .btn, .no-print { display: none !important; }
    body { background: #fff; padding: 0; }
    .card, .card-flat { box-shadow: none; border: 1px solid #ccc; }
}

/* ===== 响应式增强 ===== */
@media (max-width: 380px) {
    .summary-value { font-size: 13px; }
    .stats-bar-value { font-size: 13px; }
}

@media (min-width: 640px) {
    .stats-bar-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .stat-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}
