/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary-color: #007AFF;
    --primary-light: #E8F0FE;
    --success-color: #34C759;
    --warning-color: #FF9500;
    --danger-color: #FF3B30;
    --text-primary: #1D1D1F;
    --text-secondary: #86868B;
    --bg-primary: #F5F5F7;
    --bg-card: #FFFFFF;
    --border-color: #E5E5EA;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    padding-bottom: env(safe-area-inset-bottom, 20px);
}

/* App 容器 */
.app-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
}

/* 顶部导航 */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 4px 20px;
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 100;
}

.app-header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.header-buttons {
    display: flex;
    gap: 8px;
}

.btn-backup {
    background: white;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-backup:active {
    transform: scale(0.96);
}

.btn-add {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-add:active {
    transform: scale(0.96);
}

/* 统计概览 */
.stats-overview {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 16px 12px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

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

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

.total-value .stat-value {
    color: var(--primary-color);
}

.daily-cost .stat-value {
    color: var(--warning-color);
}

.item-count .stat-value {
    color: var(--success-color);
}

/* 筛选栏 */
.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.filter-bar select {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: white;
    color: var(--text-primary);
    appearance: none;
    background-image: 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='%2386868B' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

/* 资产列表 */
.assets-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.asset-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}

.asset-card:active {
    transform: scale(0.98);
}

.asset-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--primary-color);
}

.asset-card.status-idle::before {
    background: var(--warning-color);
}

.asset-card.status-sold::before,
.asset-card.status-scrapped::before {
    background: var(--text-secondary);
}

.asset-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

.asset-name {
    font-size: 16px;
    font-weight: 600;
    flex: 1;
    margin-right: 8px;
}

.asset-category {
    display: inline-block;
    font-size: 12px;
    padding: 3px 8px;
    background: var(--primary-light);
    color: var(--primary-color);
    border-radius: 6px;
    font-weight: 500;
}

.asset-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.info-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.info-item .label {
    opacity: 0.7;
}

.info-item .value {
    color: var(--text-primary);
    font-weight: 500;
}

.price-highlight {
    color: var(--primary-color) !important;
    font-weight: 700 !important;
}

.daily-cost-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: #FFF3E0;
    color: var(--warning-color);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    margin-top: 10px;
}

.warranty-warning {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: #FFEBEE;
    color: var(--danger-color);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    margin-top: 6px;
}

.warranty-ok {
    background: #E8F5E9;
    color: var(--success-color);
}

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

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 16px;
    margin-bottom: 8px;
}

.empty-state .hint {
    font-size: 14px;
    opacity: 0.7;
}

/* 弹窗样式 */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

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

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

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-content {
    background: var(--bg-card);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
    padding-bottom: env(safe-area-inset-bottom, 20px);
}

.detail-modal {
    border-radius: var(--radius-lg);
    margin: 20px;
    max-height: 80vh;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.btn-close {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.btn-close:active {
    background: var(--border-color);
}

/* 表单样式 */
#assetForm {
    padding: 20px;
}

.form-group {
    margin-bottom: 16px;
}

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

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

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.btn-cancel,
.btn-save,
.btn-edit,
.btn-delete {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
}

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

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

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

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

.btn-cancel:active,
.btn-save:active,
.btn-edit:active,
.btn-delete:active {
    transform: scale(0.97);
    opacity: 0.9;
}

/* 详情页样式 */
.detail-content {
    padding: 20px;
}

.detail-section {
    margin-bottom: 20px;
}

.detail-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.detail-item {
    background: var(--bg-primary);
    padding: 12px;
    border-radius: var(--radius-sm);
}

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

.detail-item-value {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.detail-full-width {
    grid-column: span 2;
}

.detail-cost-highlight {
    background: linear-gradient(135deg, #FFF3E0 0%, #FFE0B2 100%);
    padding: 16px;
    border-radius: var(--radius-md);
    text-align: center;
    margin-top: 16px;
}

.detail-cost-highlight .cost-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.detail-cost-highlight .cost-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--warning-color);
}

.detail-actions {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

/* 滚动条美化 */
::-webkit-scrollbar {
    width: 4px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

/* 响应式适配 */
@media (max-width: 380px) {
    .stats-overview {
        gap: 8px;
    }

    .stat-card {
        padding: 12px 8px;
    }

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

    .asset-info {
        grid-template-columns: 1fr;
    }
}

/* 安全区域适配（iPhone X+） */
@supports (padding: env(safe-area-inset-bottom)) {
    .modal-content {
        padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
    }

    body {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ============================================
   备份功能样式
   ============================================ */

.backup-modal {
    max-height: 85vh;
}

.backup-options {
    padding: 20px;
}

.backup-section {
    margin-bottom: 24px;
}

.backup-section h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.backup-hint {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.backup-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 10px;
    text-align: left;
}

.backup-btn:active {
    transform: scale(0.98);
    background: #E8E8ED;
}

.import-label {
    cursor: pointer;
}

.backup-icon {
    font-size: 28px;
    width: 40px;
    text-align: center;
}

.backup-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.backup-info strong {
    font-size: 15px;
    color: var(--text-primary);
}

.backup-info span {
    font-size: 12px;
    color: var(--text-secondary);
}

.backup-divider {
    height: 1px;
    background: var(--border-color);
    margin: 20px 0;
}

.backup-tips {
    background: #F0F4FF;
    padding: 14px;
    border-radius: var(--radius-sm);
    margin-top: 16px;
}

.backup-tips h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 8px;
}

.backup-tips ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.backup-tips li {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    padding-left: 16px;
    position: relative;
}

.backup-tips li::before {
    content: '•';
    position: absolute;
    left: 4px;
    color: var(--primary-color);
}

/* Toast 提示 */
.toast-message {
    position: fixed;
    bottom: -60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 500;
    z-index: 9999;
    transition: bottom 0.3s ease;
    white-space: nowrap;
    max-width: 90vw;
    text-align: center;
}

.toast-message.show {
    bottom: 30px;
}
