/* ===== 基础 ===== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", "Segoe UI", sans-serif;
    font-size: 14px;
    color: #222;
    background: #f4f5f7;
    line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
.muted { color: #8a8f99; }
.cnt { color: #9aa0aa; font-size: 12px; }

:root {
    --brand: #d43d3d;
    --brand-dark: #b62f2f;
    --admin: #2c3e50;
    --line: #e6e8eb;
    --bg: #f4f5f7;
    --text: #222;
}

/* ===== 通用按钮 ===== */
.btn-primary {
    background: var(--brand); color: #fff; border: none; border-radius: 8px;
    padding: 10px 18px; font-weight: 600;
}
.btn-primary:disabled { background: #ccc; cursor: not-allowed; }
.btn-ghost {
    background: #fff; color: #333; border: 1px solid var(--line); border-radius: 8px;
    padding: 8px 14px;
}
.btn-ghost:disabled { color: #bbb; }
.btn-link { background: none; border: none; color: var(--brand); padding: 4px 0; }
.btn-block { display: block; text-align: center; margin: 12px 16px; }
.mini-btn {
    background: #fff; border: 1px solid var(--line); border-radius: 6px;
    padding: 3px 8px; font-size: 12px; color: #555;
}
.mini-btn.danger { color: var(--brand); border-color: #f0c4c4; }

.empty-state {
    text-align: center; color: #9aa0aa; padding: 40px 16px; font-size: 14px;
}
.empty-state a { color: var(--brand); }

/* ===== 提示条 ===== */
.toast {
    position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%) translateY(20px);
    background: rgba(0, 0, 0, .82); color: #fff; padding: 10px 18px; border-radius: 8px;
    font-size: 14px; z-index: 999; opacity: 0; transition: all .2s; max-width: 86vw;
    text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ==================== 商城端 ==================== */
.store .topbar {
    position: sticky; top: 0; z-index: 50;
    background: var(--brand); color: #fff;
    padding: 10px 12px calc(10px + env(safe-area-inset-top));
    padding-top: calc(10px + env(safe-area-inset-top));
    box-shadow: 0 1px 4px rgba(0, 0, 0, .12);
}
.store .brand { display: block; text-align: center; font-size: 17px; font-weight: 700; color: #fff; }
.searchbar { display: flex; gap: 8px; margin-top: 10px; }
.searchbar input {
    flex: 1; border: none; border-radius: 8px; padding: 9px 12px; outline: none;
    background: #fff; min-width: 0;
}
.searchbar button {
    border: none; background: #8f1f1f; color: #fff; border-radius: 8px; padding: 0 16px;
    font-weight: 600;
}
.order-search { margin: 10px 12px 0; }
.order-search input { border: 1px solid var(--line); }
.content { padding-bottom: calc(76px + env(safe-area-inset-bottom)); min-height: 60vh; }

.hero {
    background: linear-gradient(135deg, #e85555, #c22f2f);
    color: #fff; padding: 18px 16px;
}
.hero h1 { margin: 0; font-size: 20px; }
.hero p { margin: 4px 0 0; font-size: 12px; opacity: .9; }

.section-title {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 14px 6px; font-weight: 700; font-size: 15px;
}
.section-title a { color: #777; font-size: 12px; font-weight: 400; }

/* 商品网格 */
.product-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
    gap: 10px; padding: 8px 12px;
}
.product-card {
    background: #fff; border-radius: 10px; overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .05);
    display: flex; flex-direction: column;
}
.thumb { position: relative; aspect-ratio: 1 / 1; background: #fafafa; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-ph {
    width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
    color: #c4c9d1; font-size: 30px; font-weight: 700; background: #f2f3f5;
}
.thumb-sm { width: 64px; height: 64px; border-radius: 8px; flex: none; }
.thumb-sm .thumb-ph { font-size: 18px; }
.p-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.p-name {
    font-size: 13px; font-weight: 600; line-height: 1.35;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
    min-height: 35px;
}
.p-spec { font-size: 11px; color: #9aa0aa; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.p-stock { font-size: 11px; color: #2e9e5b; }
.p-stock.out { color: var(--brand); }
.p-row { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 4px; }
.p-price { color: var(--brand); font-weight: 700; font-size: 15px; }
.add-btn {
    width: 28px; height: 28px; border-radius: 50%; border: none;
    background: var(--brand); color: #fff; font-size: 17px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
}
.add-btn:disabled { background: #ddd; color: #999; }
.load-more { text-align: center; padding: 6px 0 14px; }
.result-info { padding: 10px 14px 0; color: #777; font-size: 12px; }

/* 底部导航 */
.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    display: flex; background: #fff; border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 8px 0 6px; color: #8a8f99; font-size: 11px; position: relative;
}
.nav-item.active { color: var(--brand); font-weight: 600; }
.nav-icon { font-size: 19px; line-height: 1; }
.badge {
    position: absolute; top: 4px; right: calc(50% - 20px);
    background: var(--brand); color: #fff; font-size: 10px; font-style: normal;
    min-width: 16px; height: 16px; border-radius: 8px; padding: 0 4px;
    display: flex; align-items: center; justify-content: center; z-index: 1;
}
/* hidden 属性必须压过上面的 display:flex */
#cartBadge[hidden] { display: none !important; }

/* 分类页 */
.cat-layout { display: flex; min-height: 70vh; }
.cat-big {
    width: 88px; flex: none; background: #eceef1;
    /* 左栏常驻：页面滚动时保持在顶部 */
    position: sticky; top: calc(96px + env(safe-area-inset-top));
    align-self: flex-start;
    height: calc(100vh - 168px - env(safe-area-inset-top));
    overflow-y: auto;
}
.cat-big-item {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    width: 100%; padding: 12px 4px; background: none; border: none;
    border-left: 3px solid transparent; color: #555; font-size: 13px; text-align: center;
}
.cat-big-item.active { background: #fff; border-left-color: var(--brand); color: var(--brand); font-weight: 700; }
.cat-right { flex: 1; min-width: 0; background: #f4f5f7; padding-bottom: 80px; }
.cat-small-head { padding: 8px 10px 0; }
.btn-back { background: none; border: none; color: var(--brand); padding: 4px 0; }
.cat-small-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
    gap: 8px; padding: 8px 12px;
}
.cat-small-item {
    background: #fff; border: 1px solid var(--line); border-radius: 8px;
    padding: 12px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px;
    font-size: 13px; color: #333;
}
.cat-small-item .cat-count { font-size: 11px; }
.cat-small-item.active {
    border-color: var(--brand); color: var(--brand); background: #fff5f5; font-weight: 700;
}
.cat-products-head {
    padding: 10px 12px 2px; font-weight: 700; font-size: 14px; color: #333;
}
.cat-products { padding-top: 4px; }

/* 购物车 */
.cart-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px 4px; }
.cart-head h1 { font-size: 17px; margin: 0; }
.cart-list { padding: 4px 12px; }
.cart-item {
    display: flex; gap: 10px; background: #fff; border-radius: 10px;
    padding: 10px; margin-bottom: 10px; align-items: flex-start;
}
.cart-check { padding-top: 24px; }
.cart-check input { width: 20px; height: 20px; accent-color: var(--brand); }
.cart-info { flex: 1; min-width: 0; }
.cart-row { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.step-btn { width: 30px; height: 30px; border: none; background: #f5f6f8; font-size: 16px; color: #333; }
.stepper input {
    width: 44px; border: none; text-align: center; outline: none; padding: 4px 0;
    -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cart-remove { background: none; border: none; color: #aaa; font-size: 12px; padding: 2px 4px; }
.cart-footer {
    /* 让开底部导航（导航固定在底部），否则「确认下单」会被导航盖住 */
    position: fixed; left: 0; right: 0;
    bottom: calc(56px + env(safe-area-inset-bottom)); z-index: 55;
    display: flex; align-items: center; gap: 10px;
    background: #fff; border-top: 1px solid var(--line);
    padding: 10px 12px;
    box-shadow: 0 -1px 6px rgba(0, 0, 0, .06);
}
.cart-page .content { padding-bottom: calc(140px + env(safe-area-inset-bottom)); }
.check-all { display: flex; align-items: center; gap: 4px; font-size: 12px; color: #555; }
.check-all input { width: 18px; height: 18px; accent-color: var(--brand); }
.cart-total { flex: 1; font-size: 12px; color: #555; }
.cart-total b { color: var(--brand); font-size: 15px; }
.cart-footer .btn-primary { border-radius: 22px; padding: 10px 22px; }

/* 下单成功 */
.success-card {
    margin: 16px 12px 0; background: #fff; border-radius: 12px; text-align: center;
    padding: 24px 16px;
}
.success-icon {
    width: 56px; height: 56px; border-radius: 50%; background: #2e9e5b; color: #fff;
    font-size: 30px; display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;
}
.success-card h1 { font-size: 19px; margin: 0 0 4px; }
.order-no { color: #777; font-size: 13px; margin: 4px 0; }
.status-line { font-size: 13px; }
.panel {
    background: #fff; border-radius: 12px; margin: 12px; padding: 14px;
}
.panel-title { font-weight: 700; font-size: 15px; margin-bottom: 10px; }
.panel-subtitle { font-weight: 600; font-size: 13px; margin: 14px 0 6px; }
.detail-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.detail-table th, .detail-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.summary { text-align: right; padding-top: 10px; color: #555; font-size: 13px; }

/* 状态徽标 */
.status-pill {
    display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 600;
}
.st-pending { background: #fff3e0; color: #c07a12; }
.st-shipping { background: #e3f0ff; color: #1e6fc0; }
.st-done { background: #e5f6ec; color: #2e9e5b; }
.st-cancelled { background: #f0f1f3; color: #8a8f99; }
.danger-btn { color: var(--brand) !important; border-color: #efc4c4 !important; }

/* ==================== 后台 ==================== */
.admin .admin-top {
    position: sticky; top: 0; z-index: 50; background: var(--admin); color: #fff;
    padding: 10px 12px calc(10px + env(safe-area-inset-top));
    padding-top: calc(10px + env(safe-area-inset-top));
}
.admin-brand { display: flex; align-items: baseline; gap: 10px; }
.admin-brand a { color: #fff; font-weight: 700; font-size: 16px; }
.admin-brand .muted { color: rgba(255, 255, 255, .7); font-size: 12px; }
.admin-nav { display: flex; gap: 16px; margin-top: 8px; overflow-x: auto; }
.admin-nav a { color: rgba(255, 255, 255, .8); font-size: 13px; padding-bottom: 2px; white-space: nowrap; }
.admin-nav a.active { color: #fff; font-weight: 700; border-bottom: 2px solid #fff; }
.admin-content { padding-bottom: 40px; }

.page-head {
    display: flex; align-items: center; gap: 10px; padding: 12px 14px 4px;
}
.page-head h1 { font-size: 17px; margin: 0; flex: 1; }

.status-tabs {
    display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px;
}
.status-tabs button {
    background: #fff; border: 1px solid var(--line); border-radius: 18px;
    padding: 6px 12px; white-space: nowrap; color: #555; font-size: 13px;
}
.status-tabs button.active {
    background: var(--admin); color: #fff; border-color: var(--admin); font-weight: 600;
}
.status-tabs .cnt { color: inherit; opacity: .75; }

.order-list { padding: 4px 12px; }
.order-card {
    display: block; background: #fff; border-radius: 10px; padding: 12px;
    margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}
.oc-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.oc-meta { color: #8a8f99; font-size: 12px; margin-top: 4px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 10px; }

.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.meta-grid span { display: block; color: #9aa0aa; font-size: 12px; }
.meta-grid b { font-size: 14px; font-weight: 600; }
.remark-line { margin-top: 10px; color: #666; font-size: 13px; white-space: pre-wrap; }
.remark-box { color: #555; white-space: pre-wrap; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.item-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 560px; }
.item-table th, .item-table td {
    padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle;
}
.item-table th { color: #9aa0aa; font-weight: 500; font-size: 12px; }
.item-table .num { text-align: right; }
.cell-name { font-weight: 600; }
.cell-sub { color: #9aa0aa; font-size: 11px; font-weight: 400; }
.actual-input {
    width: 72px; padding: 6px; border: 1px solid var(--line); border-radius: 6px; text-align: center;
}
.panel-actions { margin-top: 12px; }
#statusNote {
    width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px;
    margin-bottom: 10px; resize: vertical;
}
.status-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.status-actions .btn-primary, .status-actions .btn-ghost { flex: 1; min-width: 130px; }

.photo-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.photo-item { position: relative; width: 92px; height: 92px; }
.photo-item img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.photo-del {
    position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%;
    border: none; background: rgba(0, 0, 0, .65); color: #fff; line-height: 1;
}
.upload-btn {
    display: inline-block; background: #fff; border: 1px dashed #b8bec7; border-radius: 8px;
    padding: 10px 16px; color: #555; margin-bottom: 8px;
}

.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.form-row input, .form-row select {
    border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff;
    flex: 1; min-width: 100px;
}
.form-row .input-sm { flex: none; width: 80px; }
.inline-check { font-size: 12px; color: #555; display: flex; align-items: center; gap: 4px; }

.cat-block-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cat-block-head > b { font-size: 15px; }
.head-actions { margin-left: auto; display: flex; gap: 6px; }
.cat-children { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-child {
    display: inline-flex; align-items: center; gap: 6px; background: #f7f8fa;
    border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 13px;
}
.cc-name { font-weight: 600; }

.assign-results { margin-top: 8px; }
.assign-row {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 8px 0; border-bottom: 1px solid var(--line);
}
.assign-row:last-child { border-bottom: none; }

/* ===== PC 适配 ===== */
@media (min-width: 760px) {
    .product-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
    .content { max-width: 980px; margin: 0 auto; }
    .bottom-nav { max-width: 980px; margin: 0 auto; }
    .cart-footer { max-width: 980px; margin: 0 auto; }
    .admin-content { max-width: 1080px; margin: 0 auto; }
    .toast { bottom: 40px; }
}
