:root {
  --paper: #f3eee6;
  --ink: #1c1916;
  --ink2: #5c554c;
  --ink3: #8a8176;
  --line: #ddd4c6;
  --accent: #a33e2a;
  --gold: #b08948;
  --ok: #4f8a66;
  --warn: #c48a28;
  --fast: #c44830;
  --card: #faf6f0;
  --white: #fffdf8;
  --header-h: 96px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.45 "Noto Sans SC", "Microsoft YaHei", sans-serif;
}
header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 12px 16px 0;
}
header h1 { margin: 0; font-size: 17px; letter-spacing: 0.01em; }
header h1 span {
  display: block;
  color: var(--ink2);
  font-weight: 500;
  font-size: 12px;
  margin-top: 4px;
}
nav {
  display: flex;
  gap: 2px;
  margin-top: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
nav button {
  border: 0;
  background: transparent;
  color: var(--ink2);
  padding: 10px 14px 12px;
  cursor: pointer;
  font: inherit;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
nav button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 700; }
main { max-width: 920px; margin: 0 auto; padding: 16px 16px 40px; }
h2 { font-size: 13px; letter-spacing: 0.12em; color: var(--ink2); margin: 22px 0 10px; font-weight: 700; }
.hint { color: var(--ink2); font-size: 13px; margin: 0 0 14px; }
.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}
@media (min-width: 720px) {
  .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.stat {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  min-width: 0;
}
.stat span { display: block; color: var(--ink2); font-size: 12px; }
.stat b { display: block; font-size: 22px; margin-top: 4px; word-break: break-all; }
.stat.bad b { color: var(--fast); }
.stat.warn b { color: var(--warn); }
.stat.ok b, .pos { color: var(--ok); }
.neg { color: var(--fast); }
@media (min-width: 720px) {
  .cards-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.chip {
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink2);
  padding: 8px 12px;
  border-radius: 99px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.chip.on {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  font-weight: 700;
}
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 8px;
}
.grid {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.grid th, .grid td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.grid th:first-child, .grid td:first-child { text-align: left; white-space: normal; }
.grid th {
  background: var(--paper);
  font-weight: 600;
  color: var(--ink2);
  font-size: 12px;
}
.grid tr:last-child td { border-bottom: 0; }
.grid input.mini {
  width: 5.2em;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--white);
  text-align: right;
}
details.block {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px 14px;
  margin-top: 18px;
}
details.block summary {
  cursor: pointer;
  font-weight: 700;
  padding: 4px 0 8px;
}

.item, .row {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px 12px;
  margin-bottom: 10px;
}
.item.low { border-color: #e8b4a8; background: #fff8f6; }
.item.exp { border-color: #e6c97a; background: #fffbeb; }
.item-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.item-top h3 { margin: 0; font-size: 16px; }
.meta { color: var(--ink2); font-size: 12px; margin-top: 2px; }
.nums {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0 10px;
}
.num {
  background: var(--paper);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
.num label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink2);
  margin-bottom: 4px;
}
.num .line {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.num input[type="number"] {
  width: 4.2em;
  font-size: 16px;
  font-weight: 700;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--white);
}
.num .max { color: var(--ink3); font-size: 13px; }
.bar { height: 5px; background: #ebe3d6; border-radius: 3px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.bar.low > i { background: var(--fast); }
.bar.mid > i { background: var(--warn); }
.item-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}
.item-foot .meta { margin: 0; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; }
button, input, select { touch-action: manipulation; }
button.act, .ghost, .danger {
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  -webkit-user-select: none;
  user-select: none;
}
button.act { background: var(--ink); color: var(--paper); border-color: var(--ink); }
button.danger { color: var(--fast); border-color: #e8c4bc; }
button:disabled {
  cursor: default;
  background: #ebe6dc;
  color: #9a9288;
  border-color: var(--line);
}
.tag {
  display: inline-block;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 99px;
  margin-left: 6px;
  font-weight: 600;
  vertical-align: middle;
}
.tag.fast { background: #f4d4cc; color: #8a2e1e; }
.tag.week { background: #efe3c8; color: #7a5a18; }
.tag.slow { background: #dce8e0; color: #2f5c40; }
.tag.none { background: #e8e4dc; color: #5c554c; }
.filters {
  position: sticky;
  top: var(--header-h);
  z-index: 15;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: -8px -16px 12px;
  padding: 10px 16px;
  background: var(--paper);
  border-bottom: 1px solid transparent;
}
.filters input, .filters select {
  font: inherit;
  font-size: 16px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--white);
  min-width: 0;
}
.filters input { flex: 1 1 180px; }
.filters select { flex: 0 0 auto; }
#dlg {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 22, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 16px;
  pointer-events: none;
}
#dlg.is-open {
  display: flex;
  pointer-events: auto;
}
#dlg[hidden] { display: none !important; pointer-events: none; }
#dlg .box {
  background: var(--white);
  padding: 20px;
  border-radius: 10px;
  width: min(380px, 100%);
  border: 1px solid var(--line);
}
#dlg h3 { margin: 0 0 12px; }
#dlg label { display: block; margin: 10px 0; color: var(--ink2); font-size: 13px; }
#dlg input { width: 100%; margin-top: 4px; font: inherit; font-size: 16px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
.log { font-size: 13px; color: var(--ink2); padding: 6px 0; border-bottom: 1px solid var(--line); }
pre.log {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  white-space: pre-wrap;
}
footer {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 16px 28px;
  color: var(--ink3);
  font-size: 12px;
}
@media (max-width: 640px) {
  header h1 span { display: none; }
  .nums { grid-template-columns: 1fr 1fr; }
  .item-foot { flex-direction: column; align-items: stretch; }
  .btns { width: 100%; }
  .btns button { flex: 1; }
}
