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

:root {
    --primary: #1FD385;
    --primary-light: #4de0a0;
    --primary-dark: #17b871;
    --primary-bg: #edfaf4;
    --bg: #f5f5f7;
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --success: #1FD385;
    --success-bg: #edfaf4;
    --danger: #ef4444;
    --danger-bg: #fef2f2;
    --warning: #f59e0b;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --tab-bar-height: 56px;
}

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; min-height: 100vh; overflow-x: hidden;
}

#app { max-width: 480px; margin: 0 auto; height: 100vh; display: flex; flex-direction: column; }

/* ===== Header ===== */
.app-header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white; padding: 14px 20px;
    display: flex; justify-content: space-between; align-items: center;
    flex-shrink: 0; z-index: 100; box-shadow: var(--shadow-lg);
}
.app-header h1 { font-size: 18px; font-weight: 700; }
.header-actions { display: flex; gap: 6px; }
.icon-btn {
    background: rgba(255,255,255,0.2); border: none; border-radius: 8px;
    padding: 6px 10px; font-size: 15px; cursor: pointer; transition: background 0.2s; color: white;
}
.icon-btn:hover { background: rgba(255,255,255,0.35); }
.header-logo { height: 36px; object-fit: contain; margin-right: 8px; vertical-align: middle; }
.app-title { display: flex; align-items: center; font-size: 18px; font-weight: 700; }
.header-icon { width: 18px; height: 18px; }

/* ===== Main Content ===== */
.main-content {
    flex: 1; overflow: hidden; display: flex; flex-direction: column;
}

.tab-content { display: none; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 14px; animation: fadeIn 0.2s ease; }
.tab-content.active { display: block; }

/* Cashier tab - fill available space */
#tab-cashier { padding: 0; overflow: hidden; }
#tab-cashier.active { display: flex; flex-direction: column; }
#cashier-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ===== 底部 Tab Bar ===== */
.tab-bar {
    display: flex; flex-shrink: 0;
    background: var(--card-bg); border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
    padding: 4px 0;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 32px);
    z-index: 100;
}
.tab-bar-btn {
    flex: 1; border: none; background: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 6px 0; cursor: pointer; transition: color 0.2s;
    color: var(--text-secondary); gap: 2px;
}
.tab-bar-btn span { font-size: 10px; font-weight: 500; }
.tab-icon { width: 24px; height: 24px; }
.tab-bar-btn.active { color: var(--primary); }
.tab-bar-btn.active span { font-weight: 600; }

/* ===== Cashier Layout ===== */
.cashier-layout { display: flex; flex: 1; min-height: 0; overflow: hidden; }

.cashier-sidebar {
    width: 72px; flex-shrink: 0;
    background: var(--card-bg);
    box-shadow: var(--shadow); overflow-y: auto;
    display: flex; flex-direction: column;
    border-right: 1px solid var(--border);
}
.sidebar-item {
    padding: 10px 6px; text-align: center; font-size: 12px;
    color: var(--text-secondary); cursor: pointer; border-bottom: 1px solid var(--border);
    transition: all 0.15s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-item:hover { background: var(--primary-bg); }
.sidebar-item.active { background: #E1FFF2; color: #1FD385; font-weight: 600; }
.sidebar-item.sold-out-cat { opacity: 0.4; }

.cashier-main { flex: 1; overflow-y: auto; padding: 4px 8px; }
.product-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 4px 0; }

.grid-item {
    background: var(--card-bg); border-radius: var(--radius-sm);
    box-shadow: var(--shadow); cursor: pointer; transition: all 0.15s;
    overflow: hidden; display: flex; flex-direction: column; position: relative;
}
.grid-item:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.grid-item:active { transform: scale(0.96); }
.grid-item.sold-out { opacity: 0.4; cursor: not-allowed; }
.grid-item.in-order { border: 2px solid var(--primary); }

.grid-item-img {
    width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--bg);
    display: flex; align-items: center; justify-content: center; font-size: 32px;
}
.grid-item-img img { width: 100%; height: 100%; object-fit: cover; }
.grid-item-info { padding: 6px 8px; }
.grid-item-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid-item-price { font-size: 13px; font-weight: 700; color: var(--primary); }
.grid-item-stock { font-size: 10px; color: var(--text-secondary); }

.grid-item-badge {
    position: absolute; top: 4px; right: 4px;
    background: var(--primary); color: white;
    width: 20px; height: 20px; border-radius: 50%;
    font-size: 11px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.grid-item-badge.zero { background: var(--danger); }

/* ===== Order Bar ===== */
.order-bar {
    position: fixed; bottom: 0; z-index: 150;
    left: 50%; transform: translateX(-50%);
    width: 100%; max-width: 480px;
    background: var(--card-bg); border-top: 2px solid var(--primary);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
    padding: 8px 14px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
}
.order-bar-items {
    display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
}
.order-item {
    flex-shrink: 0; background: var(--primary-bg); border-radius: var(--radius-sm);
    padding: 4px 10px; display: flex; align-items: center; gap: 6px; font-size: 13px;
}
.order-item-name { font-weight: 500; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-item-qty { color: var(--primary); font-weight: 700; }
.order-item-price { color: var(--text-secondary); font-size: 12px; }
.order-item-remove { cursor: pointer; color: var(--danger); font-size: 14px; padding: 0 2px; }

.order-bar-footer { display: flex; align-items: center; gap: 10px; }
.order-total { flex: 1; font-size: 16px; font-weight: 700; }
.order-total span { color: var(--primary); font-size: 20px; }

.btn-checkout {
    padding: 10px 20px; border: none; border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white; font-size: 15px; font-weight: 700; cursor: pointer;
    box-shadow: 0 3px 10px rgba(31,211,133,0.3); transition: all 0.15s;
}
.btn-checkout:active { transform: scale(0.96); }

.btn-clear-order {
    padding: 10px 14px; border: 2px solid var(--border); border-radius: var(--radius-sm);
    background: white; font-size: 13px; color: var(--text-secondary); cursor: pointer;
}

/* ===== Checkout Modal ===== */
.modal-checkout { max-width: 360px; text-align: center; }
.btn-checkout-confirm {
    padding: 12px 28px; border: none; border-radius: var(--radius-sm);
    background: var(--primary); color: white; font-size: 16px; font-weight: 700;
    cursor: pointer; box-shadow: 0 3px 10px rgba(31,211,133,0.3);
}
.btn-checkout-confirm:active { transform: scale(0.96); }

.checkout-line {
    display: flex; justify-content: space-between; padding: 4px 0;
    font-size: 14px; border-bottom: 1px dashed var(--border);
}
.checkout-line:last-child { border-bottom: none; }

/* ===== 备货录入 ===== */
.product-management { background: var(--card-bg); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.add-product-form h3 { font-size: 15px; margin-bottom: 10px; color: var(--text); }

.form-row-compact { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.form-fields { flex: 1; display: flex; flex-direction: column; gap: 6px; }

input[type="text"], input[type="number"], textarea {
    width: 100%; padding: 9px 12px; border: 2px solid var(--border);
    border-radius: var(--radius-sm); font-size: 14px; color: var(--text);
    background: var(--bg); transition: border-color 0.2s; outline: none; font-family: inherit;
}
input[type="text"]:focus, input[type="number"]:focus, textarea:focus { border-color: var(--primary); background: white; }
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }

.img-upload-btn {
    width: 60px; height: 60px; border: 2px dashed var(--border); border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    font-size: 24px; overflow: hidden; flex-shrink: 0; background: var(--bg); transition: border-color 0.2s;
}
.img-upload-btn:hover { border-color: var(--primary); }
.img-upload-btn img { width: 100%; height: 100%; object-fit: cover; }

.btn-small {
    padding: 9px 16px; border: none; border-radius: var(--radius-sm);
    background: var(--primary); color: white; font-size: 13px; font-weight: 600;
    cursor: pointer; white-space: nowrap; transition: background 0.2s; flex-shrink: 0;
}
.btn-small:hover { background: var(--primary-dark); }
.btn-add { width: 100%; text-align: center; margin-top: 4px; }
.btn-batch { margin-top: 6px; width: 100%; text-align: center; }

.batch-input-section { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.batch-input-section h3 { font-size: 14px; margin-bottom: 6px; color: var(--text); }
.batch-input-section .hint { font-size: 11px; color: var(--text-secondary); font-weight: 400; }
textarea { resize: vertical; min-height: 80px; font-size: 13px; line-height: 1.6; }

.product-list-header { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.product-list-header h3 { font-size: 15px; color: var(--text); }

.btn-text-danger { background: none; border: none; font-size: 12px; color: var(--danger); cursor: pointer; padding: 4px 8px; }
.btn-text-danger:hover { text-decoration: underline; }
.btn-text { background: none; border: none; font-size: 12px; color: var(--primary); cursor: pointer; padding: 4px 8px; }
.btn-text:hover { text-decoration: underline; }

.product-list { margin-top: 10px; }
.product-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 0; border-bottom: 1px solid var(--border);
}
.product-item:last-child { border-bottom: none; }
.product-item-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.product-item-thumb {
    width: 40px; height: 40px; border-radius: 6px; overflow: hidden;
    background: var(--bg); display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0;
}
.product-item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-item-info { flex: 1; min-width: 0; }
.product-item-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-item-detail { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.product-item-detail span { margin-right: 8px; }
.product-item-cat { font-size: 11px; background: var(--primary-bg); color: var(--primary); padding: 1px 6px; border-radius: 4px; }
.product-item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.product-item-btn { background: none; border: none; cursor: pointer; padding: 4px 6px; border-radius: 4px; transition: background 0.2s; display: inline-flex; align-items: center; color: rgba(0,0,0,0.4); }
.product-item-btn:hover { background: var(--bg); }
.product-item-btn svg { width: 16px; height: 16px; }
.grid-item-img svg { width: 32px; height: 32px; }

/* ===== Stats ===== */
.stats-panel { background: var(--card-bg); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }

/* 顶部三列概览 */
.stats-summary-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stats-summary-card {
    background: linear-gradient(135deg, var(--primary-bg), #f0fdf8);
    border-radius: var(--radius-sm); padding: 12px 8px; text-align: center;
    border: 1px solid rgba(31,211,133,0.15);
}
.stats-summary-label { display: block; font-size: 11px; color: var(--text-secondary); margin-bottom: 2px; }
.stats-summary-value { display: block; font-size: 18px; font-weight: 700; color: #000000; }
.stats-summary-card:nth-child(3) .stats-summary-value { color: #1FD385; }

.stats-overview { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 18px; }
.stat-card { background: var(--bg); border-radius: var(--radius-sm); padding: 12px 10px; text-align: center; }
.stat-label { display: block; font-size: 11px; color: var(--text-secondary); margin-bottom: 2px; }
.stat-value { display: block; font-size: 18px; font-weight: 700; color: #000000; }
.stat-card:nth-child(3) .stat-value { color: #1FD385; }

.stats-orders, .stats-detail, .stats-history { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.stats-orders h3, .stats-detail h3, .stats-history h3 { font-size: 14px; margin-bottom: 8px; color: var(--text); }
.history-header { display: flex; justify-content: space-between; align-items: center; }

.btn-save-session {
    display: inline-flex; align-items: center;
    padding: 8px 16px;
    background: var(--primary); color: white;
    border: none; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600;
    cursor: pointer; box-shadow: 0 3px 10px rgba(31,211,133,0.3);
}
.btn-save-session:active { transform: scale(0.96); }

.detail-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.detail-item:last-child { border-bottom: none; }
.detail-name { font-weight: 500; flex: 1; }
.detail-qty { color: var(--text-secondary); margin: 0 10px; white-space: nowrap; min-width: 52px; text-align: right; }
.detail-amount { font-weight: 600; color: #000000; white-space: nowrap; min-width: 110px; text-align: right; }
.detail-name .product-item-cat { background: #EDFAFF; color: #467789; }

.order-card { background: var(--bg); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 8px; }
.order-card-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.order-card-time { font-size: 12px; color: var(--text-secondary); }
.order-card-total { font-weight: 700; color: #000000; font-size: 16px; flex: 1; }
.order-card-del {
    background: none; border: none; cursor: pointer; padding: 4px;
    color: rgba(0,0,0,0.3); display: inline-flex; align-items: center;
    transition: color 0.15s; flex-shrink: 0;
}
.order-card-del:hover { color: var(--danger); }
.order-card-items { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

.session-card { background: var(--bg); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 8px; }
.session-date { font-weight: 600; font-size: 14px; }
.session-summary { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.session-actions { margin-top: 6px; display: flex; gap: 8px; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.tag-soldout { background: var(--danger-bg); color: var(--danger); }
.tag-unsold { background: #f3f4f6; color: var(--text-secondary); }

/* ===== Modals ===== */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 200; animation: fadeIn 0.15s ease; }
.modal { background: white; border-radius: var(--radius); padding: 24px; width: 85%; max-width: 320px; text-align: center; box-shadow: var(--shadow-lg); }
.modal-wide { max-width: 380px; }
.modal p { font-size: 15px; margin-bottom: 18px; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }
.btn-cancel { padding: 9px 22px; border: 2px solid var(--border); border-radius: var(--radius-sm); background: white; font-size: 14px; cursor: pointer; }
#checkout-cancel { color: rgba(0,0,0,0.6); border-color: rgba(0,0,0,0.12); }
.btn-danger { padding: 9px 22px; border: none; border-radius: var(--radius-sm); background: var(--danger); color: white; font-size: 14px; font-weight: 600; cursor: pointer; }
.edit-form { text-align: left; margin-bottom: 16px; }

/* 下架开关 */
.shelf-toggle-row {
    display: flex; align-items: center; gap: 10px;
    margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
}
.shelf-label { font-size: 14px; font-weight: 500; }
.shelf-status { font-size: 13px; color: var(--text-secondary); }
.shelf-status.off { color: var(--danger); }

.switch { position: relative; width: 48px; height: 28px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background: #ccc; transition: 0.3s; border-radius: 28px;
}
.slider:before {
    position: absolute; content: ""; height: 22px; width: 22px;
    left: 3px; bottom: 3px; background: white;
    transition: 0.3s; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider:before { transform: translateX(20px); }

.product-item.off-shelf { opacity: 0.6; }
.product-item.off-shelf .product-item-name { text-decoration: line-through; }
.tag-off-shelf {
    background: var(--danger-bg); color: var(--danger);
    display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 600;
}

.empty-state { text-align: center; padding: 30px 20px; color: var(--text-secondary); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 10px; }
.empty-state p { font-size: 14px; }

.toast { position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); background: rgba(26,26,46,0.9); color: white; padding: 10px 24px; border-radius: 24px; font-size: 14px; z-index: 300; animation: toastIn 0.3s ease; white-space: nowrap; }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

@media (min-width: 481px) {
    #app { margin-top: 20px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-lg); }
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

button, input, textarea { -webkit-tap-highlight-color: transparent; user-select: none; }
input, textarea { user-select: text; }
.pop { animation: popNum 0.2s ease; }
@keyframes popNum { 0% { transform: scale(1); } 50% { transform: scale(1.3); } 100% { transform: scale(1); } }
