:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #1f2733;
  --muted: #7a869a;
  --line: #e6eaf2;
  --brand: #3b6df0;
  --brand-ink: #ffffff;
  --ok: #1faa6b;
  --warn: #e0a106;
  --danger: #e0533d;
  --shadow: 0 2px 10px rgba(31,39,51,0.06);
  --radius: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}
#app { min-height: 100vh; display: flex; flex-direction: column; }

/* —— 本地图标基础样式 —— */
/* 所有 <svg class="i"> 引用 assets/icons.svg 的 symbol */
.i {
  display: inline-block;
  width: 1em; height: 1em;
  vertical-align: -0.16em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.i.isf { fill: currentColor; stroke: none; }
/* 品牌色图标（用于品牌名） */
.brand .i.i-brand { color: var(--brand); width: 1.15em; height: 1.15em; vertical-align: -0.18em; }
/* 标题前的图标稍大 */
h2 > .i { width: 1.05em; height: 1.05em; vertical-align: -0.18em; margin-right: 4px; color: var(--brand); }

/* 顶栏 */
.topbar {
  height: 54px; display: flex; align-items: center; gap: 10px;
  padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.brand { font-weight: 700; font-size: 17px; flex: 1; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.sync { font-size: 12px; color: var(--ok); margin-right: 4px; }
.icon-btn {
  border: none; background: transparent; color: var(--ink); cursor: pointer;
  width: 38px; height: 38px; border-radius: 10px; font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}
.icon-btn .i { width: 19px; height: 19px; }
.icon-btn:hover { background: var(--bg); }
#menuBtn { display: none; }

/* 布局 */
.layout { flex: 1; display: flex; align-items: stretch; }

/* 侧边栏 */
.sidebar {
  width: 264px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; font-weight: 600; border-bottom: 1px solid var(--line);
}
.cat-tree { padding: 8px; overflow-y: auto; flex: 1; }

/* 分类树 */
.cat-node { user-select: none; }
.cat-row {
  display: flex; align-items: center; gap: 4px; padding: 6px 6px; border-radius: 8px; cursor: pointer;
}
.cat-row:hover { background: var(--bg); }
.cat-row.active { background: #e8f0ff; }
.cat-toggle {
  width: 20px; height: 20px; border: none; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 12px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}
.cat-toggle .i { width: 12px; height: 12px; }
.cat-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-count { font-size: 12px; color: var(--muted); background: var(--bg); border-radius: 10px; padding: 0 7px; }
.cat-row.active .cat-count { background: #d6e4ff; color: var(--brand); }
.cat-act {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  width: 24px; height: 24px; border-radius: 6px; font-size: 13px; opacity: 0; transition: .15s;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.cat-act .i { width: 13px; height: 13px; }
.cat-row:hover .cat-act, .cat-row.active .cat-act { opacity: 1; }
.cat-act:hover { background: #dfe6f5; color: var(--ink); }
.cat-children { margin-left: 14px; border-left: 1px dashed var(--line); padding-left: 4px; }

/* 全部 */
.all-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px;
  cursor: pointer; font-weight: 600; margin-bottom: 4px;
}
.all-row .i { width: 16px; height: 16px; color: var(--brand); }
.all-row:hover { background: var(--bg); }
.all-row.active { background: #e8f0ff; }

/* 主内容 */
.content { flex: 1; padding: 16px 22px; overflow-y: auto; }
.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.breadcrumb span.sep { margin: 0 6px; }
.breadcrumb b { color: var(--ink); }
.content-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.content-head h2 { margin: 0; font-size: 20px; }
.content-head-right { display: flex; gap: 8px; align-items: center; }

/* 主视图 tab（物品 / 统计） */
.view-tabs { display: flex; gap: 4px; margin-bottom: 12px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); width: fit-content; box-shadow: var(--shadow); }
.view-tabs .tab { background: transparent; border: none; padding: 8px 16px; border-radius: calc(var(--radius) - 4px); cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 500; transition: all .15s; display: inline-flex; align-items: center; gap: 5px; }
.view-tabs .tab .i { width: 15px; height: 15px; }
.view-tabs .tab:hover { color: var(--ink); }
.view-tabs .tab.active { background: var(--brand); color: #fff; }

/* 视图模式切换（卡片/列表） */
.view-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.view-switch .vs-btn { background: var(--panel); border: none; padding: 6px 10px; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.view-switch .vs-btn .i { width: 15px; height: 15px; }
.view-switch .vs-btn:hover { background: var(--bg); color: var(--ink); }
.view-switch .vs-btn.active { background: var(--brand); color: #fff; }
.view-switch .vs-btn + .vs-btn { border-left: 1px solid var(--line); }

/* 统计卡 */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat-card .n { font-size: 22px; font-weight: 700; }
.stat-card .l { font-size: 12px; color: var(--muted); }
.stat-card.warn .n { color: var(--warn); }

/* —— 列表视图（紧凑表格） —— */
.items-list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 0; box-shadow: var(--shadow); overflow-x: auto; }
.list-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.list-table thead th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--bg); white-space: nowrap; }
.list-table thead th.num { text-align: right; }
.list-table tbody td { padding: 10px 12px; border-bottom: 1px dashed var(--line); vertical-align: middle; }
.list-table tbody tr:last-child td { border-bottom: none; }
.list-table tbody tr:hover { background: rgba(80, 110, 220, .04); }
.list-table .num { text-align: right; white-space: nowrap; }
.list-table .op { white-space: nowrap; }
.list-table .op .btn { margin-right: 4px; }
.list-table .td-name { font-weight: 500; word-break: break-all; }
.list-table tr.low td { background: rgba(243, 210, 138, .12); }
.list-table tr.zero td { background: rgba(220, 53, 69, .08); }
.list-table .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; vertical-align: middle; margin-left: 4px; }
.list-table .dot-low { background: var(--warn); }
.list-table .dot-zero { background: var(--danger); }

/* —— 统计视图 —— */
.stats-filter {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.stats-filter .field.inline { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.stats-filter .field.inline label { font-size: 12px; color: var(--muted); margin: 0; }
.stats-filter input[type=date], .stats-filter select {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  padding: 6px 10px; border-radius: 6px; font: inherit; min-width: 130px;
}
.stats-filter .quick-range { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }

.stats-toolbar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 12px; margin-bottom: 12px; box-shadow: var(--shadow);
}

.stat-summary {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 14px;
}
.sum-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.sum-card .n { font-size: 20px; font-weight: 700; }
.sum-card .l { font-size: 12px; color: var(--muted); }
.sum-card.in .n { color: var(--ok); }
.sum-card.out .n { color: var(--danger); }

.stats-table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.stats-table thead th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 12px;
  padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--bg); white-space: nowrap;
}
.stats-table thead th.num { text-align: right; }
.stats-table thead th.th-sortable { cursor: pointer; user-select: none; transition: color .15s, background .15s; }
.stats-table thead th.th-sortable:hover { color: var(--ink); background: #eef2fb; }
.stats-table thead th.sorted { color: var(--brand); }
/* 三角符号样式：当前列 ↑/↓ 用品牌蓝实心，未排序用浅灰菱形 */
.stats-table thead th.th-sortable .s-tri {
  display: inline-flex; align-items: center; justify-content: center;
  width: 12px; height: 12px; margin-left: 4px; line-height: 1;
  color: var(--brand);
}
.stats-table thead th.th-sortable .s-tri .i { width: 100%; height: 100%; }
.stats-table thead th.th-sortable:not(.sorted) .s-tri { color: #b9c2d4; }
.stats-table tbody td { padding: 10px 12px; border-bottom: 1px dashed var(--line); }
.stats-table tbody tr:last-child td { border-bottom: none; }
.stats-table tbody tr:hover { background: rgba(80, 110, 220, .04); }
.stats-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats-table .num.in { color: var(--ok); }
.stats-table .num.out { color: var(--danger); }
.stats-table .td-name { font-weight: 500; word-break: break-all; }
.stats-table .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; vertical-align: middle; margin-left: 4px; }

/* —— 设置里的分段控件 —— */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-btn { background: var(--panel); border: none; padding: 6px 12px; cursor: pointer; color: var(--muted); font: inherit; font-size: 13px; }
.seg-btn:hover { background: var(--bg); color: var(--ink); }
.seg-btn.active { background: var(--brand); color: #fff; }
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.stat-card.danger .n { color: var(--danger); }

/* 物品网格 */
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }

/* 物品子分类标签（聚合视图下用） */
.item-subcat {
  font-size: 11px; color: var(--brand); background: #eaf0ff;
  border-radius: 6px; padding: 2px 8px; align-self: flex-start;
  margin-top: -4px;
}

/* 排序工具条（物品） */
.item-toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  margin: 0 0 12px; padding: 8px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow);
}
.toolbar-label { font-size: 12px; color: var(--muted); margin-right: 4px; }
.chip {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font-size: 13px; padding: 5px 11px; border-radius: 16px; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover { background: #e8f0ff; border-color: #c8d4ee; }
.chip.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* 分类树排序工具条 */
.cat-sortbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px;
  padding: 6px 8px; margin-bottom: 4px; border-bottom: 1px solid var(--line);
}
.cat-sortbar .chip { font-size: 12px; padding: 3px 9px; }
.item-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 16px 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px; position: relative;
  transition: border-color .15s, box-shadow .15s;
}
.item-card:hover { border-color: #c8d4ee; box-shadow: 0 4px 14px rgba(31,39,51,0.08); }
.item-card.low { border-color: #f3d28a; background: #fffaf0; }
.item-card.low:hover { border-color: #e8b95f; }
.item-head {
  display: flex; align-items: center; gap: 8px; min-height: 32px;
}
.item-name {
  font-weight: 600; font-size: 16px; word-break: break-all;
  flex: 1; line-height: 1.3; min-width: 0;
}
.item-badge {
  font-size: 11px; background: #fdeccd; color: var(--warn);
  padding: 2px 7px; border-radius: 8px; white-space: nowrap; flex-shrink: 0;
}
.item-edit {
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--line); background: #fbfcfe;
  color: var(--muted); cursor: pointer; font-size: 14px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
  transition: color .15s, border-color .15s, background .15s;
}
.item-edit .i { width: 14px; height: 14px; }
.item-edit:hover { color: var(--brand); border-color: var(--brand); background: #f0f5ff; }
.item-unit {
  font-size: 12px; color: var(--muted);
  margin-top: -4px; padding-left: 2px;
}
.item-qty { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.qty-val { text-align: center; flex: 1; }
.qty-val .v { font-size: 26px; font-weight: 800; }
.qty-val .u { font-size: 13px; color: var(--muted); margin-left: 2px; }
.qty-btn {
  width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  font-size: 22px; cursor: pointer; color: var(--ink); flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.qty-btn .i { width: 18px; height: 18px; }
.qty-btn.plus { color: var(--ok); }
.qty-btn.minus { color: var(--danger); }
.qty-btn:active { transform: scale(.94); }
.item-actions { display: flex; gap: 6px; margin-top: 2px; }
.item-actions .btn { flex: 1; }

/* 按钮 */
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 8px 12px; border-radius: 9px; cursor: pointer; font-size: 14px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 5px;
}
.btn .i { width: 14px; height: 14px; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.small { padding: 5px 9px; font-size: 13px; }
.btn.danger { color: var(--danger); border-color: #f0c4bb; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; }

/* 模态框 */
.modal-mask { position: fixed; inset: 0; background: rgba(20,28,40,.4); z-index: 50; display: none; }
.modal-mask.show { display: block; }
.modal {
  position: fixed; z-index: 51; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(440px, 92vw); max-height: 88vh; overflow-y: auto; background: var(--panel);
  border-radius: 16px; box-shadow: 0 18px 50px rgba(0,0,0,.25); padding: 20px; display: none;
}
.modal.show { display: block; }
.modal h3 { margin: 0 0 14px; font-size: 18px; }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 15px; background: #fbfcfe; color: var(--ink); font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); background: #fff; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* 编辑物品：原值对比小框 */
.orig-diff {
  margin: 14px 0 6px; padding: 10px 12px;
  background: #f6f8fc; border: 1px dashed #d3dbe7; border-radius: 8px;
  font-size: 13px; color: var(--ink);
}
.orig-diff .orig-title { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.orig-diff .orig-row {
  display: flex; align-items: center; gap: 8px; padding: 3px 0; line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
.orig-diff .orig-k { color: var(--muted); min-width: 56px; }
.orig-diff .orig-old { color: #8694a8; text-decoration: line-through; }
.orig-diff .orig-arrow { color: var(--brand); }
.orig-diff .orig-new { color: var(--ink); font-weight: 600; }
.orig-diff .orig-empty { color: var(--muted); font-size: 12px; }

/* 流水列表 */
.tx-list { max-height: 50vh; overflow-y: auto; }
.tx-item { display: flex; justify-content: space-between; padding: 9px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.tx-delta.in { color: var(--ok); font-weight: 700; }
.tx-delta.out { color: var(--danger); font-weight: 700; }
.tx-meta { color: var(--muted); font-size: 12px; }

/* 抽屉遮罩 */
.drawer-mask { position: fixed; inset: 0; background: rgba(20,28,40,.4); z-index: 25; display: none; }
.drawer-mask.show { display: block; }

/* 轻提示 */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(20px);
  background: #1f2733; color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 14px;
  z-index: 80; opacity: 0; transition: .25s; pointer-events: none; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty-tip { color: var(--muted); text-align: center; padding: 50px 10px; }

/* —— 手机端 —— */
@media (max-width: 768px) {
  #menuBtn { display: block; }
  .sidebar {
    position: fixed; top: 54px; bottom: 0; left: 0; z-index: 26;
    transform: translateX(-100%); transition: transform .25s; width: 80vw; max-width: 320px;
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 12px 14px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .items { grid-template-columns: 1fr; }
  .content-head h2 { font-size: 18px; }
  .qty-btn { width: 48px; height: 48px; }
  .sync { display: none; }
  .item-toolbar { padding: 6px 8px; }
  .chip { font-size: 12px; padding: 4px 9px; }
  .cat-sortbar .chip { font-size: 11px; padding: 3px 7px; }
  .list-table { font-size: 13px; }
  .list-table thead th, .list-table tbody td { padding: 8px 8px; }
  .stat-summary { grid-template-columns: repeat(2, 1fr); }
  .stats-filter { flex-direction: column; align-items: stretch; }
  .stats-filter .quick-range { margin-left: 0; }
  /* 手机端没有 hover，常驻显示分类行的 + / 编辑按钮（否则无法编辑/添加子分类） */
  .cat-act { opacity: 1; }
  .cat-row .cat-act { opacity: 1; }
  /* 列表表格也保持按钮可点 */
  .list-table .op .btn { padding: 6px 8px; }
}
