* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f5f5;
    min-height: 100vh;
}

.container {
    max-width: 100%;
    margin: 0 auto;
}

/* 页面切换 */
.page {
    display: none;
    min-height: 100vh;
}

.page.active {
    display: block;
}

/* 移动端头部 */
.mobile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    position: sticky;
    top: 0;
    z-index: 100;
}

.mobile-header h1 {
    font-size: 1.1em;
    font-weight: 600;
}

.btn-icon {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.2em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon.back {
    font-size: 1.4em;
}

.placeholder {
    width: 36px;
}

/* 卡片 */
.card {
    background: white;
    margin: 12px;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.card h2 {
    color: #333;
    margin-bottom: 16px;
    font-size: 1em;
    font-weight: 600;
}

/* 添加表单 */
.add-form {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.add-form input:nth-child(1) {
    flex: 2;
    min-width: 100px;
}

.add-form input:nth-child(2) {
    flex: 1;
    min-width: 80px;
}

.add-form input {
    flex: 1;
    padding: 12px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    background: #f8f9fa;
}

.add-form input:focus {
    outline: none;
    border-color: #667eea;
    background: white;
}

.add-form button {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.4em;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 列表 */
.list {
    max-height: calc(100vh - 280px);
    overflow-y: auto;
}

.item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 12px;
    background: #f8f9fa;
    border-radius: 10px;
    margin-bottom: 8px;
}

.item-info {
    flex: 1;
    min-width: 0;
}

.item-name {
    font-weight: 500;
    color: #333;
    margin-bottom: 4px;
    font-size: 0.95em;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.item-amount {
    color: #667eea;
    font-size: 1.15em;
    font-weight: 700;
}

.item-amount.zero {
    color: #999;
}

.item-amount.negative {
    color: #ff6b6b;
}

.item-used {
    font-size: 0.8em;
    color: #888;
    margin-top: 2px;
}

.item-actions {
    display: flex;
    gap: 6px;
    margin-left: 8px;
}

.item-actions button {
    padding: 8px 14px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-danger {
    background: #ff6b6b;
    color: white;
}

.item-actions button.disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

/* 摘要栏 */
.summary-bar {
    display: flex;
    justify-content: space-around;
    padding-top: 16px;
    margin-top: 16px;
    border-top: 1px solid #f0f0f0;
}

.summary-item {
    text-align: center;
    flex: 1;
}

.summary-item .label {
    display: block;
    font-size: 0.8em;
    color: #888;
    margin-bottom: 4px;
}

.summary-item .value {
    display: block;
    font-size: 1.1em;
    font-weight: 700;
    color: #333;
}

.summary-item .value.negative {
    color: #ff6b6b;
}

/* 分类详情 */
.category-detail {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed #e0e0e0;
}

.category-source-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.8em;
    color: #666;
    padding: 2px 0;
}

.wish-badge {
    font-size: 0.75em;
    color: #999;
    background: #f0f0f0;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: normal;
}

.no-funds-hint {
    font-size: 0.8em;
    color: #ff6b6b;
    margin-top: 4px;
}

/* 弹窗 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    justify-content: flex-end;
    align-items: flex-end;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-height: 85vh;
    overflow: hidden;
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid #f0f0f0;
}

.modal-header h3 {
    color: #333;
    font-size: 1em;
}

.close {
    font-size: 24px;
    color: #999;
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    padding: 16px;
    max-height: 60vh;
    overflow-y: auto;
}

.category-title {
    font-size: 1.1em;
    font-weight: 600;
    color: #667eea;
    margin-bottom: 16px;
    text-align: center;
}

.allocation-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f5f5f5;
}

.allocation-item:last-child {
    border-bottom: none;
}

.allocation-info {
    flex: 1;
    min-width: 0;
}

.allocation-name {
    font-weight: 500;
    color: #333;
    font-size: 0.95em;
}

.allocation-available {
    font-size: 0.8em;
    color: #888;
    margin-top: 2px;
}

.allocation-input {
    width: 100px;
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    text-align: right;
    background: #f8f9fa;
}

.allocation-input:focus {
    outline: none;
    border-color: #667eea;
    background: white;
}

.allocation-input.error {
    border-color: #ff6b6b;
    background: #fff5f5;
}

.allocation-summary {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #f0f0f0;
    text-align: center;
}

.allocation-summary p {
    color: #666;
    font-size: 0.95em;
}

.allocation-summary strong {
    color: #667eea;
    font-size: 1.2em;
}

/* 修改资金来源 */
.edit-source-info {
    text-align: center;
    margin-bottom: 20px;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 10px;
}

.edit-source-name {
    font-size: 1.2em;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.edit-source-detail {
    display: flex;
    justify-content: center;
    gap: 20px;
    font-size: 0.9em;
    color: #666;
}

.edit-source-detail strong {
    color: #667eea;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #333;
    font-weight: 500;
    font-size: 0.95em;
}

.form-group .allocation-input {
    width: 100%;
    text-align: left;
}

.error-text {
    color: #ff6b6b;
    font-size: 0.85em;
    margin-top: 6px;
}

.hint-text {
    color: #888;
    font-size: 0.8em;
    margin-top: 6px;
}

.modal-footer {
    padding: 12px 16px 24px;
    border-top: 1px solid #f0f0f0;
}

.modal-footer button {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}

.empty-state-icon {
    font-size: 3em;
    margin-bottom: 10px;
}

/* 平板及以上 */
@media (min-width: 768px) {
    body {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        padding: 20px;
    }
    
    .container {
        max-width: 480px;
    }
    
    .page {
        min-height: auto;
    }
    
    .page.active {
        display: flex;
        flex-direction: column;
    }
    
    .mobile-header {
        border-radius: 12px 12px 0 0;
        position: relative;
    }
    
    .card {
        margin: 0;
        border-radius: 0 0 12px 12px;
        box-shadow: 0 10px 40px rgba(0,0,0,0.1);
    }
    
    .modal {
        justify-content: center;
        align-items: center;
        padding: 20px;
    }
    
    .modal-content {
        border-radius: 16px;
        max-width: 420px;
        max-height: 80vh;
        animation: fadeIn 0.2s ease;
    }
    
    @keyframes fadeIn {
        from {
            opacity: 0;
            transform: scale(0.95);
        }
        to {
            opacity: 1;
            transform: scale(1);
        }
    }
}
