/* ============================================
   记品 - 物品库存管理系统
   样式表
   ============================================ */

/* CSS 变量 */
:root {
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --primary-dark: #3730a3;
    --primary-bg: #eef2ff;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-bg: #fef2f2;
    --warning-bg: #fffbeb;
    --success-bg: #ecfdf5;

    --bg: #f5f5f5;
    --card-bg: #ffffff;
    --text: #1f2937;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    --border: #e5e7eb;
    --border-light: #f3f4f6;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);

    --header-h: 56px;
    --nav-h: 60px;
    --max-width: 600px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

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

#app {
    max-width: var(--max-width);
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg);
    position: relative;
}

/* ============================================
   加载屏
   ============================================ */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    gap: 16px;
    color: var(--text-secondary);
}
.loader {
    width: 36px; height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================
   认证页
   ============================================ */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.auth-container {
    width: 100%;
    max-width: 380px;
    background: #fff;
    border-radius: 24px;
    padding: 36px 28px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.auth-logo {
    text-align: center;
    margin-bottom: 28px;
}
.logo-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 8px;
}
.auth-logo h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}
.auth-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}
.auth-tabs {
    display: flex;
    gap: 0;
    background: var(--border-light);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 24px;
}
.auth-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}
.auth-tab.active {
    background: #fff;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.form-group input,
.form-group select,
.form-group textarea {
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    color: var(--text);
    background: #fff;
    transition: border-color 0.2s;
    font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}
.form-group textarea { resize: vertical; min-height: 60px; }
.auth-error {
    color: var(--danger);
    font-size: 13px;
    text-align: center;
    min-height: 18px;
}

/* ============================================
   按钮
   ============================================ */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
    background: var(--border-light);
    color: var(--text);
}
.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon {
    padding: 8px 10px;
    background: var(--border-light);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
}
.btn-icon:hover { background: var(--border); }

/* ============================================
   顶部栏
   ============================================ */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #fff;
    border-bottom: 1px solid var(--border);
    height: var(--header-h);
}
.header-content {
    max-width: var(--max-width);
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}
.header-title {
    font-size: 18px;
    font-weight: 700;
}
.header-actions { display: flex; gap: 8px; }
.icon-btn {
    width: 36px; height: 36px;
    border: none;
    background: var(--border-light);
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.icon-btn:hover { background: var(--border); }

/* ============================================
   内容区域
   ============================================ */
.app-content {
    padding: 12px 16px;
    padding-bottom: calc(var(--nav-h) + 20px);
    min-height: calc(100vh - var(--header-h) - var(--nav-h));
}

/* ============================================
   搜索栏 & 筛选
   ============================================ */
.search-bar {
    position: relative;
    margin-bottom: 12px;
}
.search-bar input {
    width: 100%;
    padding: 10px 14px 10px 40px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    background: #fff;
}
.search-bar input:focus {
    outline: none;
    border-color: var(--primary);
}
.search-bar .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: var(--text-light);
}

.filter-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
}
.filter-tabs::-webkit-scrollbar { display: none; }
.filter-tab {
    padding: 6px 14px;
    border: 1.5px solid var(--border);
    border-radius: 20px;
    background: #fff;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}
.filter-tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.filter-tab.alert {
    border-color: var(--danger);
    color: var(--danger);
}
.filter-tab.alert.active {
    background: var(--danger);
    color: #fff;
}

/* ============================================
   物品卡片
   ============================================ */
.item-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.item-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s;
    border: 2px solid transparent;
}
.item-card.status-expired { border-color: var(--danger); background: var(--danger-bg); }
.item-card.status-expiring { border-color: var(--warning); background: var(--warning-bg); }
.item-card.status-low_stock { border-left: 4px solid var(--warning); }
.item-card.status-out_of_stock { border-left: 4px solid var(--danger); }

.item-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 6px;
}
.item-name {
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.item-batch-badge {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--primary-bg);
    color: var(--primary);
    font-weight: 600;
}
.item-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.item-action-btn {
    width: 30px; height: 30px;
    border: none;
    border-radius: 8px;
    background: var(--border-light);
    cursor: pointer;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.item-action-btn:hover { background: var(--border); }
.item-action-btn.qty-btn {
    width: 32px; height: 32px;
    font-size: 18px;
    font-weight: 700;
}
.item-action-btn.qty-plus { background: var(--success-bg); color: var(--success); }
.item-action-btn.qty-minus { background: var(--danger-bg); color: var(--danger); }

.item-card-body {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.item-meta {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}
.item-quantity {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    margin: 4px 0;
}
.item-quantity .unit {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-secondary);
}
.item-status-tag {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
}
.tag-expired { background: var(--danger); color: #fff; }
.tag-expiring { background: var(--warning); color: #fff; }
.tag-low_stock { background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning); }
.tag-out_of_stock { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.item-notes {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 2px;
    font-style: italic;
}

/* ============================================
   空状态
   ============================================ */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}
.empty-state .empty-icon {
    font-size: 56px;
    margin-bottom: 12px;
    opacity: 0.5;
}
.empty-state p {
    font-size: 15px;
    margin-bottom: 8px;
}

/* ============================================
   底部导航
   ============================================ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--max-width);
    height: var(--nav-h);
    background: #fff;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
    flex: 1;
    height: 100%;
    border: none;
    background: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    cursor: pointer;
    color: var(--text-light);
    transition: color 0.2s;
    font-family: inherit;
}
.nav-item.active { color: var(--primary); }
.nav-icon { font-size: 22px; }
.nav-label { font-size: 11px; font-weight: 600; }
.nav-add {
    flex: 0 0 auto;
    width: 56px; height: 56px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    margin-top: -20px;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
    transition: transform 0.2s;
}
.nav-add .nav-icon { font-size: 28px; }
.nav-add:active { transform: scale(0.9); }

/* ============================================
   统计页
   ============================================ */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 14px 10px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}
.stat-card.alert { border-top: 3px solid var(--danger); }
.stat-value {
    font-size: 24px;
    font-weight: 800;
    color: var(--text);
}
.stat-card.alert .stat-value { color: var(--danger); }
.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}
.section-title {
    font-size: 16px;
    font-weight: 700;
    margin: 16px 0 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.chart-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 12px;
}
.chart-card h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}
.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}
.bar-label {
    width: 70px;
    text-align: right;
    color: var(--text-secondary);
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bar-track {
    flex: 1;
    height: 22px;
    background: var(--border-light);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}
.bar-fill {
    height: 100%;
    border-radius: 6px;
    display: flex;
    align-items: center;
    padding-left: 8px;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    transition: width 0.5s ease;
    min-width: 24px;
}
.bar-value {
    width: 36px;
    text-align: left;
    color: var(--text);
    font-weight: 600;
    flex-shrink: 0;
}

/* 趋势柱状图 */
.trend-chart {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    height: 140px;
    gap: 4px;
    padding-top: 20px;
}
.trend-bar-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 1;
}
.trend-bars {
    display: flex;
    gap: 2px;
    align-items: flex-end;
    height: 100px;
}
.trend-bar {
    width: 10px;
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    transition: height 0.5s ease;
}
.trend-bar.in { background: var(--success); }
.trend-bar.out { background: var(--danger); }
.trend-bar-label {
    font-size: 10px;
    color: var(--text-secondary);
}
.trend-legend {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}
.trend-legend span {
    display: flex;
    align-items: center;
    gap: 4px;
}
.legend-dot {
    width: 10px; height: 10px;
    border-radius: 3px;
}

/* 预警列表 */
.alert-section { margin-bottom: 16px; }
.alert-item {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
}
.alert-item.expired { border-left: 4px solid var(--danger); }
.alert-item.expiring { border-left: 4px solid var(--warning); }
.alert-item.low_stock { border-left: 4px solid var(--warning); }
.alert-item-info { flex: 1; }
.alert-item-name { font-weight: 600; font-size: 15px; }
.alert-item-desc { font-size: 13px; color: var(--text-secondary); }
.alert-item-tag { flex-shrink: 0; }

/* 历史记录 */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.history-item {
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    font-size: 14px;
}
.history-item-left { flex: 1; }
.history-item-name { font-weight: 600; }
.history-item-time { font-size: 12px; color: var(--text-light); }
.history-item-right {
    text-align: right;
    font-weight: 700;
}
.history-type-tag {
    display: inline-block;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 4px;
    margin-right: 6px;
    font-weight: 600;
}
.type-add { background: var(--primary-bg); color: var(--primary); }
.type-in { background: var(--success-bg); color: var(--success); }
.type-out { background: var(--danger-bg); color: var(--danger); }
.type-edit { background: var(--warning-bg); color: var(--warning); }
.type-delete { background: var(--danger-bg); color: var(--danger); }

/* ============================================
   设置/自定义管理页
   ============================================ */
.settings-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
}
.settings-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}
.settings-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 15px;
}
.settings-item:last-child { border-bottom: none; }
.settings-item-label { display: flex; align-items: center; gap: 8px; }

.manage-tabs {
    display: flex;
    gap: 0;
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
}
.manage-tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.manage-tab.active {
    background: var(--primary);
    color: #fff;
}

.manage-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.manage-item {
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    font-size: 15px;
}
.manage-item-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}
.manage-item-icon { font-size: 20px; }
.manage-item-name { font-weight: 500; }
.manage-item-actions { display: flex; gap: 6px; }

/* ============================================
   模态框
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
    background: #fff;
    width: 100%;
    max-width: var(--max-width);
    border-radius: 20px 20px 0 0;
    padding: 24px 20px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.modal-title {
    font-size: 18px;
    font-weight: 700;
}
.modal-close {
    width: 32px; height: 32px;
    border: none;
    background: var(--border-light);
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-form { display: flex; flex-direction: column; gap: 14px; }
.form-row {
    display: flex;
    gap: 10px;
}
.form-row .form-group { flex: 1; }
.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}
.modal-actions .btn { flex: 1; }

/* Emoji 选择器 */
.emoji-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px;
    background: var(--border-light);
    border-radius: var(--radius-sm);
    max-height: 120px;
    overflow-y: auto;
}
.emoji-option {
    width: 34px; height: 34px;
    border: none;
    background: none;
    border-radius: 6px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.15s;
}
.emoji-option:hover { background: #fff; }
.emoji-option.selected { background: var(--primary); }

/* ============================================
   Toast
   ============================================ */
#toast-container {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    width: 100%;
    max-width: var(--max-width);
    padding: 0 16px;
    pointer-events: none;
}
.toast {
    background: rgba(31, 41, 55, 0.95);
    color: #fff;
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    animation: toastIn 0.3s, toastOut 0.3s 2.7s forwards;
    max-width: 100%;
    text-align: center;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-20px); } }

/* ============================================
   备份页
   ============================================ */
.backup-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
    text-align: center;
}
.backup-icon { font-size: 40px; margin-bottom: 8px; }
.backup-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.backup-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 14px; }
.danger-zone {
    border: 2px dashed var(--danger);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 16px;
    background: var(--danger-bg);
}
.danger-zone h3 {
    color: var(--danger);
    font-size: 15px;
    margin-bottom: 8px;
}
.danger-zone p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* ============================================
   响应式
   ============================================ */
@media (max-width: 380px) {
    .stats-cards { gap: 6px; }
    .stat-value { font-size: 20px; }
    .stat-label { font-size: 11px; }
}

/* 滚动条美化 */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
