/* 喵喵家 —— 暖色猫主题，移动端优先 */
:root {
  --bg: #fff7ef;
  --card: #ffffff;
  --ink: #4a3b2e;
  --muted: #9a8a78;
  --primary: #ff8a3d;
  --primary-dark: #e06f1f;
  --line: #f0e0cf;
  --radius: 16px;
  --star: #f5b83d;
  --green: #4caf7d;
  --yellow: #f0b32a;
  --red: #e05b4d;
  --cat: #ffb36b;
  --can: #5b9bd5;
  --treat: #7fb56b;
  --freeze: #b48ad8;
  --snack: #e8a0c0;
  --other: #9aa5b1;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button, .btn, .tab, .icon-btn, .cell, .stars-mini .s, .big-stars .bs, .smell-stars .s, .stock-btn, .emoji-pick, .color-pick { touch-action: manipulation; -webkit-user-select: none; user-select: none; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
  min-height: 100dvh;
}

/* ---- 顶部 ---- */
.topbar { background: linear-gradient(135deg, #ffb36b, #ff8a3d); color: #fff; position: sticky; top: 0; z-index: 20; box-shadow: 0 2px 10px rgba(224,111,31,.25); padding-top: env(safe-area-inset-top); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px; padding: 10px 14px 2px; }
.brand { font-size: 19px; font-weight: 800; letter-spacing: .5px; display: flex; align-items: baseline; gap: 8px; }
.brand small { font-size: 11px; font-weight: 500; opacity: .85; }
.topbar-right { display: flex; gap: 8px; position: relative; z-index: 30; }
.btn { border: none; cursor: pointer; font-size: 14px; border-radius: 999px; padding: 8px 14px; font-weight: 600; transition: transform .06s; }
.btn:active { transform: scale(.96); }
.btn-ghost { background: rgba(255,255,255,.22); color: #fff; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary.big { width: 100%; padding: 13px; font-size: 16px; margin-top: 10px; }
.btn-danger { background: #fff; color: var(--red); border: 1px solid #f3c9c4; }
.btn-soft { background: #fbeadd; color: var(--primary-dark); }
.me-row { display: flex; align-items: center; gap: 8px; padding: 6px 14px 10px; font-size: 13px; }
.me-row label { opacity: .95; white-space: nowrap; }
#meName { flex: 1; max-width: 180px; border: none; border-radius: 999px; padding: 6px 12px; font-size: 14px; color: var(--ink); background: rgba(255,255,255,.92); outline: none; }
.sync-status { margin-left: auto; font-size: 12px; opacity: .9; white-space: nowrap; }

/* ---- 标签页 ---- */
.tabs { position: sticky; top: calc(76px + env(safe-area-inset-top)); z-index: 19; display: flex; gap: 6px; padding: 8px 10px; background: var(--bg); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab { flex: 1; min-width: max-content; border: none; background: #fff; color: var(--muted); font-size: 14px; font-weight: 700; padding: 9px 14px; border-radius: 999px; cursor: pointer; box-shadow: 0 1px 4px rgba(74,59,46,.08); }
.tab.active { background: var(--primary); color: #fff; }

main { max-width: 860px; margin: 0 auto; padding: 12px 14px 60px; }

/* ---- 卡片 / 区块 ---- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 2px 8px rgba(74,59,46,.07); }
.card h3 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.section-hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

.form-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.form-field { flex: 1 1 140px; min-width: 120px; }
.form-field.full { flex-basis: 100%; }
label.f { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=number], select, textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px;
  font-size: 15px; color: var(--ink); background: #fffdf9; outline: none; font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 54px; }

/* 表情 & 颜色选择 */
.emoji-row, .color-row { display: flex; flex-wrap: wrap; gap: 8px; }
.emoji-pick, .color-pick { font-size: 26px; width: 46px; height: 46px; display: flex; align-items: center; justify-content: center; border-radius: 12px; border: 2px solid transparent; background: #fdf3e6; cursor: pointer; }
.emoji-pick.sel, .color-pick.sel { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 2px rgba(255,138,61,.25); }
.color-pick { width: 38px; height: 38px; border-radius: 50%; }

/* ---- 列表 ---- */
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-bottom: 1px dashed var(--line); }
.list-item:last-child { border-bottom: none; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; word-break: break-all; }
.item-actions { display: flex; gap: 6px; }
.icon-btn { border: none; background: #fbeadd; border-radius: 10px; width: 40px; height: 40px; font-size: 17px; cursor: pointer; }
.icon-btn.danger { background: #fdeeea; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 14px; }
.empty .big-emoji { font-size: 40px; display: block; margin-bottom: 8px; }

.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 9px; border-radius: 999px; color: #fff; }
.badge.cat { background: var(--cat); }
.badge.can { background: var(--can); }
.badge.treat { background: var(--treat); }
.badge.freeze { background: var(--freeze); }
.badge.snack { background: var(--snack); }
.badge.other { background: var(--other); }
.badge.type { background: #8d9db8; }
.badge.plain { background: #e9d9c8; color: var(--ink); }

/* ---- 评分矩阵 ---- */
.matrix-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 14px; box-shadow: 0 2px 8px rgba(74,59,46,.07); background: #fff; }
table.matrix { border-collapse: separate; border-spacing: 0; min-width: 560px; width: 100%; }
.matrix th, .matrix td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 8px; text-align: center; }
.matrix thead th { position: sticky; top: 0; background: #fff7ef; font-size: 12.5px; z-index: 3; }
.matrix th.cat-head, .matrix td.cat-cell { position: sticky; left: 0; background: #fff7ef; z-index: 2; text-align: left; font-size: 13px; font-weight: 700; min-width: 110px; max-width: 140px; }
.matrix thead th.cat-head { z-index: 4; }
.matrix td.cat-cell { cursor: pointer; }
.food-head { display: flex; flex-direction: column; gap: 2px; align-items: center; }
.food-head .fn { font-weight: 700; }
.cell { cursor: pointer; min-width: 96px; min-height: 52px; }
.stars-mini { display: flex; justify-content: center; gap: 1px; }
.stars-mini .s { font-size: 15px; color: #e8d9c4; cursor: pointer; padding: 2px; }
.stars-mini .s.on { color: var(--star); }
.cell.empty { color: #d8c9b8; font-size: 13px; }
.cell .cell-comment { font-size: 10.5px; color: var(--muted); max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.cell.sel { outline: 2.5px solid var(--primary); outline-offset: -1px; border-radius: 10px; }
.cell-avg { font-size: 11px; color: var(--muted); font-weight: 600; }

/* 评分编辑面板 */
.editor { border: 2px dashed var(--primary); }
.editor .edit-target { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.big-stars { display: flex; gap: 6px; margin: 8px 0 12px; }
.big-stars .bs { font-size: 30px; background: none; border: none; cursor: pointer; filter: grayscale(1); opacity: .45; padding: 2px; }
.big-stars .bs.on { filter: none; opacity: 1; }
.rate-label { font-size: 13px; font-weight: 700; margin-bottom: 10px; min-height: 18px; }
.rate-label.low { color: var(--green); } .rate-label.mid { color: var(--yellow); } .rate-label.high { color: var(--red); }
.editor-meta { font-size: 12px; color: var(--muted); margin-top: 8px; }
.editor-btns { display: flex; gap: 10px; margin-top: 12px; }

/* ---- 猫砂 ---- */
.smell-stars { display: flex; gap: 4px; align-items: center; }
.smell-stars .s { font-size: 26px; filter: grayscale(1); opacity: .45; cursor: pointer; background: none; border: none; padding: 2px; }
.smell-stars .s.on { filter: none; opacity: 1; }
.smell-label { font-size: 13px; font-weight: 700; }
.litter-card .stars-mini .s { font-size: 18px; }
.price-tag { font-size: 12px; color: var(--primary-dark); font-weight: 700; }

/* ---- 统计 ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.stat-card { background: #fff; border-radius: 14px; padding: 14px; box-shadow: 0 2px 8px rgba(74,59,46,.07); }
.stat-card h4 { margin: 0 0 8px; font-size: 14px; }
.stat-line { font-size: 13px; margin: 4px 0; color: var(--ink); }
.stat-line b { color: var(--primary-dark); }
.rank { display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-bottom: 1px dashed var(--line); }
.rank:last-child { border-bottom: none; }
.rank .no { width: 26px; height: 26px; border-radius: 50%; background: #fbeadd; color: var(--primary-dark); font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 13px; flex: none; }
.rank.good .no { background: #e6f4ec; color: var(--green); }
.rank.bad .no { background: #fdeeea; color: var(--red); }
.rank .r-main { flex: 1; min-width: 0; }
.rank .r-smell { font-size: 20px; letter-spacing: 1px; }
.activity { font-size: 13px; padding: 8px 4px; border-bottom: 1px dashed var(--line); }
.activity:last-child { border-bottom: none; }
.activity .who { font-weight: 700; }
.activity time { color: var(--muted); font-size: 12px; }

/* ---- 分享弹层 ---- */
.overlay { position: fixed; inset: 0; background: rgba(74,59,46,.5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.overlay-card { background: #fff; border-radius: 20px; padding: 22px; max-width: 400px; width: 100%; text-align: center; max-height: 86vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#addOverlayCard { text-align: left; }
.overlay-card h3 { margin: 0 0 14px; text-align: center; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0; }
.qr-wrap { display: flex; justify-content: center; margin: 12px 0; }
#qrBox img, #qrBox svg { width: 190px; height: 190px; border-radius: 10px; }
.url-text { font-size: 13px; font-weight: 700; color: var(--primary-dark); word-break: break-all; }
.hidden { display: none !important; }
.small { font-size: 12px; color: var(--muted); }

/* ---- 添加弹层（次级页面） ---- */
.add-entry { padding: 4px; }
.add-entry .btn { margin: 0; }
.modal-btns { display: flex; gap: 8px; margin-top: 12px; }
.modal-btns .big { flex: 1; margin: 0; }
.w-row { display: flex; align-items: stretch; gap: 0; flex-wrap: nowrap; }
/* 注意：iOS Safari 上 input 不能 flex:1 + min-width:0（会塌成 0 宽、无法输入），
   所以给最小宽度；16px 字号防止 iOS 聚焦自动放大页面 */
.w-row input { flex: 1 1 auto; min-width: 90px; font-size: 16px; }
.w-unit { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; background: #fdf3e6; border: 1px solid #f0dfc9; border-left: none; border-radius: 0 10px 10px 0; padding: 0 12px; font-size: 14px; font-weight: 700; color: var(--primary-dark); white-space: nowrap; }
select.w-unit { border-left: none; cursor: pointer; width: auto; flex: 0 0 auto; }

/* ---- 库存（按地点分区） ---- */
.stock-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.stock-chip { display: inline-flex; align-items: center; gap: 4px; background: #fdf3e6; border: 1px solid #f0dfc9; border-radius: 999px; padding: 3px 6px 3px 10px; font-size: 12.5px; font-weight: 600; }
.stock-chip.zero { opacity: .55; }
.stock-chip b { color: var(--primary-dark); }
.stock-btn { border: none; background: #fff; border-radius: 8px; width: 28px; height: 28px; font-size: 15px; font-weight: 800; cursor: pointer; color: var(--primary-dark); box-shadow: 0 1px 2px rgba(74,59,46,.15); }
.stock-btn:disabled { opacity: .35; cursor: default; }
.stock-tag { font-size: 11.5px; font-weight: 700; margin-left: 4px; }
.stock-tag.ok { color: var(--green); }
.stock-tag.warn { color: #c98a1b; }
.stock-tag.bad { color: var(--red); }
.inv-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.inv-line:last-child { border-bottom: none; }
.inv-qty { white-space: nowrap; font-weight: 700; }
.inv-wt { font-weight: 600; color: var(--primary-dark); }
.inv-wt.dim { color: var(--muted); font-weight: 400; }
.inv-adj { display: flex; gap: 4px; flex: 0 0 auto; }
.inv-adj .stock-btn { width: 24px; height: 24px; font-size: 14px; border-radius: 7px; }
.inv-total { font-size: 12px; color: var(--muted); margin-top: 6px; padding: 5px 0 0; border-top: 1px dashed var(--line); }
.inv-total b { color: var(--primary-dark); }

/* ---- 猫粮剩余估算（库存一览顶部条） ---- */
.est-strip { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; background: #fdf3e6; border: 1px solid #f0dfc9; border-radius: 12px; margin-bottom: 12px; }
.est-days { font-size: 15px; font-weight: 800; color: var(--primary-dark); }
.est-days .small { font-weight: 500; }
.est-sub { font-size: 13px; color: var(--muted); }

/* ---- 安装引导 ---- */
.install-steps { text-align: left; margin: 12px 0; }
.istep { display: flex; align-items: flex-start; gap: 10px; font-size: 13.5px; padding: 7px 4px; border-bottom: 1px dashed var(--line); }
.istep:last-child { border-bottom: none; }
.istep b:first-child { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; margin-top: 1px; }

/* ---- 导入 ---- */
.import-text { min-height: 120px; font-family: Menlo, Consolas, monospace; font-size: 12px; }
.btn-ghost-dark { background: #f0e0cf; color: var(--ink); }

/* ---- 食物卡片里的「每只猫的评分」 ---- */
.food-rating { margin-top: 8px; }
.fr-title { font-size: 12px; font-weight: 700; color: var(--muted); cursor: pointer; padding: 2px 0; user-select: none; -webkit-user-select: none; display: flex; align-items: center; gap: 4px; }
.fr-title:hover { color: var(--primary-dark); }
.fr-caret { font-size: 11px; }
.cat-rate { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; background: #fdf3e6; border: 1px solid #f0dfc9; border-radius: 12px; padding: 5px 9px; margin-top: 4px; }
.cr-cat { font-size: 13px; font-weight: 700; white-space: nowrap; }
.cr-stars { display: inline-flex; gap: 1px; }
.fr-star { border: none; background: none; font-size: 17px; line-height: 1; color: #e6d8c4; cursor: pointer; padding: 0 1px; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
.fr-star.on { color: var(--star); }
.fr-comment { flex: 1; min-width: 80px; max-width: 180px; border: 1px dashed #e6d8c4; background: #fff; border-radius: 8px; font-size: 12px; padding: 4px 8px; }
.fr-comment:disabled { opacity: .5; }
.fr-clear { border: none; background: #fff; border-radius: 50%; width: 22px; height: 22px; font-size: 12px; line-height: 1; cursor: pointer; color: var(--muted); box-shadow: 0 1px 2px rgba(74,59,46,.15); }
