:root {
  --brand: #b01e3c; --brand-dark: #8a1530; --bg: #f4f4f6; --card: #fff; --text: #1d1d22;
  --muted: #6b6b76; --line: #e3e3e8; --ok: #1f8a4c; --warn: #c77700; --danger: #c62828;
  --radius: 12px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(64px + var(--safe-b)); }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .danger { color: var(--danger); }
.en { color: var(--muted); font-weight: normal; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--brand); color: #fff;
  padding: calc(10px + var(--safe-t)) 12px 10px; display: flex; align-items: center; gap: 8px; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar h1 small { font-weight: normal; opacity: .85; font-size: 13px; }
.topbar .tb-btn { background: rgba(255,255,255,.15); border: 0; color: #fff; padding: 7px 10px; border-radius: 8px; font-size: 14px; white-space: nowrap; }
.topbar .back { font-size: 20px; padding: 4px 12px; }

/* tab bar */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; background: #fff;
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 6px 0 5px; color: var(--muted); font-size: 12px; line-height: 1.1; text-align: center; }
.tabbar a small { font-size: 10px; }
.tabbar a .ti { font-size: 19px; line-height: 1.2; }
.tabbar a.active { color: var(--brand); font-weight: 600; }

/* generic */
.page { padding: 10px 12px 20px; max-width: 760px; margin: 0 auto; }
.card { background: var(--card); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card h2, .section-title { font-size: 16px; margin: 0 0 10px; }
.section-title { margin: 16px 2px 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; min-width: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; border: 1px solid var(--line);
  background: #fff; border-radius: 10px; padding: 10px 12px; min-height: 44px; font-size: 15px; cursor: pointer; text-align: center; line-height: 1.2; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.danger { color: var(--danger); border-color: #f2c4c4; }
.btn.block { display: flex; width: 100%; }
.btn.sm { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-grid .wide { grid-column: span 2; }

/* forms */
label.f { display: block; margin-bottom: 12px; }
label.f > span.l { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], input[type=tel], select, textarea {
  width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 16px; min-height: 44px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(176,30,60,.35); border-color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 6px 11px; font-size: 13px; cursor: pointer; user-select: none; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip .x { margin-left: 4px; opacity: .7; }
.tag { display: inline-block; background: #f0f0f3; border-radius: 6px; padding: 2px 7px; font-size: 12px; margin: 1px 2px 1px 0; }
.badge { display: inline-block; border-radius: 6px; padding: 2px 7px; font-size: 12px; font-weight: 600; }
.badge.active { background: #e3f4ea; color: var(--ok); } .badge.archived { background: #eee; color: #666; }
.badge.low { background: #fff1dc; color: var(--warn); }

/* home */
.searchbar { display: flex; gap: 6px; }
.searchbar input { flex: 1; background: #fff; }
.filters { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; padding-bottom: 2px; }
.filters select { width: auto; min-width: 0; flex: 0 0 auto; font-size: 14px; min-height: 36px; padding: 6px 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; flex: 0 0 auto; }
.seg button { border: 0; background: transparent; padding: 7px 10px; font-size: 13px; white-space: nowrap; }
.seg button.on { background: var(--brand); color: #fff; }
.alert { background: #fff6e5; border: 1px solid #ffd99a; color: #7a4a00; border-radius: 10px; padding: 9px 12px; margin: 10px 0 0; font-size: 14px; display: flex; justify-content: space-between; align-items: center; }
.count-line { margin: 10px 2px 6px; font-size: 13px; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.icard { background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.06); color: var(--text); display: block; }
.icard .thumb { position: relative; aspect-ratio: 1 / 1; background: #e9e9ee; }
.icard .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.codebadge { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.72); color: #fff; font-weight: 700; font-size: 15px; padding: 2px 8px; border-radius: 7px; letter-spacing: .5px; }
.icard .thumb .pc { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 6px; }
.icard .thumb .arch { position: absolute; right: 6px; top: 6px; background: #555; color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 6px; }
.icard .meta { padding: 7px 9px 9px; font-size: 13px; }
.icard .meta .cat { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icard .meta .nums { display: flex; justify-content: space-between; margin-top: 2px; color: var(--muted); }
.icard .meta .price { color: var(--brand); font-weight: 700; }
.noimg { display: flex; align-items: center; justify-content: center; height: 100%; color: #aaa; font-size: 13px; }
.fab { position: fixed; right: 16px; bottom: calc(76px + var(--safe-b)); z-index: 25; background: var(--brand); color: #fff; border: 0;
  border-radius: 28px; padding: 0 18px; height: 52px; font-size: 16px; font-weight: 600; box-shadow: 0 4px 12px rgba(176,30,60,.4); }

/* item page */
.gallery { position: relative; background: #111; }
.gallery .track { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.gallery .track::-webkit-scrollbar { display: none; }
.gallery .track img { flex: 0 0 100%; width: 100%; height: 62vw; max-height: 460px; object-fit: contain; scroll-snap-align: center; background: #111; }
.gallery .counter { position: absolute; right: 10px; bottom: 10px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 10px; }
.gallery .codebadge { font-size: 20px; left: 10px; top: 10px; }
.strip { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px 0; }
.strip img { width: 54px; height: 54px; object-fit: cover; border-radius: 6px; flex: 0 0 auto; border: 2px solid transparent; }
.strip img.on { border-color: var(--brand); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; font-size: 14px; }
.kv .k { color: var(--muted); white-space: nowrap; }
.kv .v { font-weight: 500; word-break: break-word; }
.big-stock { font-size: 26px; font-weight: 700; }
.stat3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; margin-bottom: 12px; }
.stat3 > div { background: #fff; border-radius: 10px; padding: 9px 4px; }
.stat3 .n { font-size: 19px; font-weight: 700; }
.stat3 .l { font-size: 11px; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li .grow { flex: 1; min-width: 0; }
.list li img.lt { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; flex: 0 0 auto; background: #eee; }
.list li .amt { font-weight: 700; white-space: nowrap; text-align: right; }
.xbtn { border: 0; background: #f3f3f5; color: #888; border-radius: 8px; width: 32px; height: 32px; font-size: 15px; flex: 0 0 auto; }
.empty { color: var(--muted); text-align: center; padding: 18px 0; font-size: 14px; }

/* photo editor */
.pgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.pgrid .ph { position: relative; aspect-ratio: 1 / 1; border-radius: 8px; overflow: hidden; background: #eee; }
.pgrid .ph img { width: 100%; height: 100%; object-fit: cover; }
.pgrid .ph.cover { outline: 3px solid var(--brand); outline-offset: -3px; }
.pgrid .ph .pb { position: absolute; border: 0; background: rgba(0,0,0,.6); color: #fff; width: 28px; height: 28px; border-radius: 14px; font-size: 14px; }
.pgrid .ph .star { left: 4px; top: 4px; } .pgrid .ph .del { right: 4px; top: 4px; }
.pgrid .ph .cl { position: absolute; left: 0; right: 0; bottom: 0; background: var(--brand); color: #fff; font-size: 10px; text-align: center; padding: 1px; }
.pgrid .ph .newl { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 10px; text-align: center; }
.filebtn { position: relative; overflow: hidden; }
.filebtn input { position: absolute; inset: 0; opacity: 0; font-size: 100px; }
.progress { height: 6px; background: #eee; border-radius: 3px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--brand); width: 0; transition: width .2s; }

/* sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0;
  padding: 14px 14px calc(16px + var(--safe-b)); animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(40px); } to { transform: none; } }
.sheet h3 { margin: 0 0 12px; font-size: 17px; display: flex; justify-content: space-between; align-items: center; }
.sheet .total { font-size: 18px; font-weight: 700; margin: 4px 0 12px; }
.viewer { position: fixed; inset: 0; background: #000; z-index: 60; display: flex; flex-direction: column; }
.viewer .track { flex: 1; display: flex; overflow-x: auto; scroll-snap-type: x mandatory; }
.viewer .track img { flex: 0 0 100%; width: 100%; height: 100%; object-fit: contain; scroll-snap-align: center; }
.viewer .vbar { color: #fff; display: flex; justify-content: space-between; align-items: center; padding: calc(10px + var(--safe-t)) 12px 10px; }
.viewer .vbar button { background: rgba(255,255,255,.18); color: #fff; border: 0; border-radius: 8px; padding: 8px 12px; }

/* reports */
.cards2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.cards2 .c { background: #fff; border-radius: 10px; padding: 10px; }
.cards2 .c .l { font-size: 12px; color: var(--muted); }
.cards2 .c .n { font-size: 20px; font-weight: 700; }
.cards2 .c .s { font-size: 12px; color: var(--muted); }
.chart { display: flex; align-items: flex-end; gap: 2px; height: 140px; padding-top: 6px; overflow-x: auto; }
.chart .bar { flex: 1 0 8px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; }
.chart .bar .rv { background: #e9a9b6; border-radius: 3px 3px 0 0; min-height: 1px; }
.chart .bar .pf { background: var(--brand); position: absolute; bottom: 0; left: 25%; right: 25%; border-radius: 2px 2px 0 0; }
.chart-x { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin-top: 3px; }
.legend { font-size: 12px; color: var(--muted); display: flex; gap: 12px; margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 3px; vertical-align: -1px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th, table.t td { padding: 7px 4px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t th { font-size: 11px; color: var(--muted); font-weight: 600; }
.scroll-x { overflow-x: auto; }

/* login */
.login { max-width: 380px; margin: 0 auto; padding: calc(50px + var(--safe-t)) 20px 20px; }
.login .logo { width: 84px; height: 84px; border-radius: 20px; display: block; margin: 0 auto 14px; }
.login h1 { text-align: center; font-size: 22px; margin: 0 0 4px; }
.login p.sub { text-align: center; color: var(--muted); margin: 0 0 24px; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); background: rgba(20,20,25,.92); color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 100; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; }
.more-list a, .more-list button { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 13px 4px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--text); font-size: 15px; text-align: left; }
.more-list > :last-child { border-bottom: 0; }
