:root {
  color-scheme: light;
  --bg: #f4f5f1;
  --surface: #ffffff;
  --surface-soft: #f8f9f6;
  --ink: #1e2722;
  --muted: #69736d;
  --line: #dde2dc;
  --line-strong: #cbd2cb;
  --green: #246b49;
  --green-dark: #185437;
  --green-soft: #e7f1ea;
  --amber: #9a6200;
  --amber-soft: #fff1ce;
  --red: #a43d36;
  --red-soft: #fbe9e6;
  --blue: #35688b;
  --blue-soft: #e6f0f5;
  --shadow: 0 18px 50px rgba(28, 40, 33, 0.12);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(36, 107, 73, 0.2);
  outline-offset: 1px;
}

.app-shell { display: grid; grid-template-columns: 238px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  width: 238px;
  flex-direction: column;
  padding: 26px 18px 20px;
  border-right: 1px solid var(--line);
  background: #fafbf8;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 28px; }
.brand-mark {
  display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 8px; background: var(--green); color: white; font-size: 18px; font-weight: 700;
}
.brand strong, .brand span { display: block; }
.brand strong { font-size: 17px; }
.brand span { margin-top: 2px; color: var(--muted); font-size: 11px; }

.nav-list, .category-nav, .category-list { display: grid; gap: 5px; }
.nav-item, .category-item {
  display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; min-height: 42px;
  width: 100%; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: #4c5851;
  text-align: left;
}
.nav-item:hover:not(:disabled), .category-item:hover { background: #eff2ed; color: var(--ink); }
.nav-item.active, .category-item.active { background: var(--green-soft); color: var(--green-dark); font-weight: 700; }
.nav-item.disabled { cursor: default; opacity: .62; }
.nav-symbol { font-size: 20px; line-height: 1; }
.nav-count, .category-item > :last-child { color: var(--muted); font-size: 12px; font-weight: 600; }
.nav-count.warning:not(:empty) { color: var(--amber); }
.coming-soon { padding: 3px 5px; border-radius: 4px; background: #eef0ec; color: #7b837d; font-size: 10px; }

.category-nav { margin-top: 28px; }
.category-nav-header { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 5px 10px; }
.nav-label { margin: 0; color: #8b938e; font-size: 11px; font-weight: 700; }
.category-add-button {
  display: grid; place-items: center; width: 26px; height: 26px; padding: 0; border: 1px solid var(--line);
  border-radius: 5px; background: var(--surface); color: var(--green); font-size: 17px; line-height: 1;
}
.category-add-button:hover { border-color: #9cab9f; background: var(--green-soft); }
.category-dot { width: 9px; height: 9px; margin-left: 4px; border-radius: 50%; }

.storage-note {
  display: flex; align-items: center; gap: 10px; margin-top: auto; padding: 12px;
  border: 1px solid var(--line); border-radius: 7px; background: var(--surface);
}
.storage-note-icon { color: var(--green); font-size: 20px; }
.storage-note strong, .storage-note span { display: block; }
.storage-note strong { font-size: 11px; }
.storage-note span { margin-top: 3px; color: var(--muted); font-size: 10px; }

.main-content { grid-column: 2; min-width: 0; padding: 30px clamp(24px, 4vw, 54px) 48px; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.eyebrow { margin: 0 0 5px; color: var(--green); font-size: 11px; font-weight: 800; }
h1 { margin: 0; font-size: 27px; line-height: 1.2; letter-spacing: 0; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.search-box {
  display: flex; align-items: center; gap: 7px; width: min(30vw, 310px); height: 40px;
  padding: 0 11px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--muted);
}
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 13px; }
.primary-button, .secondary-button {
  min-height: 40px; padding: 0 15px; border-radius: 6px; font-size: 13px; font-weight: 700;
}
.primary-button { border: 1px solid var(--green); background: var(--green); color: white; }
.primary-button:hover { border-color: var(--green-dark); background: var(--green-dark); }
.secondary-button { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); }
.secondary-button:hover { background: var(--surface-soft); }
.mobile-menu { display: none; width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 6px; background: white; }

.summary-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 30px 0 24px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
.summary-item { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 18px 20px; }
.summary-item + .summary-item { border-left: 1px solid var(--line); }
.summary-item div { min-width: 0; }
.summary-item span:not(.summary-icon), .summary-item strong { display: block; }
.summary-item div span { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.summary-item strong { margin-top: 3px; font-size: 22px; }
.summary-icon { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 34px; border-radius: 7px; font-weight: 800; }
.summary-icon.neutral { background: #edf0ec; color: #536059; }
.summary-icon.green { background: var(--green-soft); color: var(--green); }
.summary-icon.amber { background: var(--amber-soft); color: var(--amber); }
.summary-icon.red { background: var(--red-soft); color: var(--red); }

.inventory-section { overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.section-toolbar { display: flex; justify-content: space-between; gap: 20px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.filter-group { display: flex; gap: 3px; }
.filter-button { min-height: 32px; padding: 0 11px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); font-size: 12px; }
.filter-button:hover, .filter-button.active { background: #eef1ed; color: var(--ink); }
.filter-button.active { font-weight: 700; }
.sort-wrap { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.sort-wrap select { height: 32px; padding: 0 28px 0 9px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); color: var(--ink); font-size: 12px; }

.table-wrap { min-height: 370px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 16px; border-bottom: 1px solid var(--line); background: #fafbf8; color: #808983; font-size: 10px; text-align: left; }
td { height: 66px; padding: 10px 16px; border-bottom: 1px solid #edf0ec; font-size: 12px; vertical-align: middle; }
tbody tr:hover { background: #fbfcfa; }
.item-name { display: block; max-width: 230px; overflow: hidden; font-size: 13px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.item-note { display: block; max-width: 230px; margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.category-badge, .status-badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 4px; font-size: 11px; white-space: nowrap; }
.category-badge { background: #eff2ee; color: #4e5a52; }
.status-badge.good { background: var(--green-soft); color: var(--green-dark); }
.status-badge.neutral { background: #edf0ec; color: #5e6861; }
.status-badge.warning { background: var(--amber-soft); color: #7b4e00; }
.status-badge.urgent { background: #fce6cf; color: #934a0b; }
.status-badge.danger { background: var(--red-soft); color: #8d332d; }
.expiry-date { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.expiry-progress { width: 118px; height: 5px; margin-top: 7px; overflow: hidden; border-radius: 3px; background: #e5e9e4; }
.expiry-progress span { display: block; height: 100%; border-radius: inherit; }
.expiry-progress.good span { background: var(--green); }
.expiry-progress.warning span { background: #d09326; }
.expiry-progress.urgent span { background: #c86a1b; }
.expiry-progress.danger span { background: var(--red); }
.expiry-percent { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }
.specification-value { display: block; max-width: 150px; overflow: hidden; color: #4c5851; text-overflow: ellipsis; white-space: nowrap; }
.quantity-control { display: grid; grid-template-columns: 28px minmax(58px, auto) 28px; align-items: stretch; width: max-content; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.quantity-control button { width: 28px; min-height: 30px; border: 0; background: #f6f8f5; color: #425048; font-size: 17px; }
.quantity-control button:hover { background: var(--green-soft); color: var(--green-dark); }
.quantity-value { display: grid; place-items: center; min-height: 30px; padding: 0 7px; border-right: 1px solid var(--line); border-left: 1px solid var(--line); font-weight: 700; white-space: nowrap; }
.edit-button { min-height: 31px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; background: white; color: #4c5851; font-size: 11px; }
.edit-button:hover { border-color: #9cab9f; background: #f6f8f5; }

.empty-state { display: grid; justify-items: center; max-width: 450px; margin: 0 auto; padding: 66px 24px; text-align: center; }
.empty-state[hidden] { display: none; }
.empty-illustration { position: relative; width: 120px; height: 82px; margin-bottom: 18px; }
.shelf-top, .shelf-line { position: absolute; left: 7px; right: 7px; height: 5px; border-radius: 2px; background: #9daf9f; }
.shelf-top { top: 4px; }
.shelf-line { bottom: 5px; }
.jar, .box-shape { position: absolute; bottom: 10px; border: 2px solid #6f8675; background: #e4ede5; }
.jar { border-radius: 5px 5px 3px 3px; }
.jar::before { content: ""; position: absolute; left: 3px; right: 3px; top: -6px; height: 4px; border-radius: 2px; background: #6f8675; }
.jar-one { left: 17px; width: 27px; height: 41px; }
.jar-two { left: 51px; width: 24px; height: 54px; background: #f1e5bf; }
.box-shape { right: 15px; width: 24px; height: 34px; border-color: #9c7551; background: #f0dbc7; }
.empty-state h2 { margin: 0; font-size: 17px; }
.empty-state p { max-width: 390px; margin: 8px 0 18px; color: var(--muted); font-size: 12px; line-height: 1.7; }

.item-dialog { width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; overflow: hidden; border: 0; border-radius: 8px; box-shadow: var(--shadow); }
.category-dialog { width: min(420px, calc(100vw - 32px)); padding: 0; overflow: hidden; border: 0; border-radius: 8px; box-shadow: var(--shadow); }
.item-dialog::backdrop, .category-dialog::backdrop { background: rgba(26, 35, 30, .48); }
.item-dialog form { display: flex; max-height: calc(100vh - 32px); flex-direction: column; }
.category-dialog form { display: flex; flex-direction: column; }
.category-form-body { padding: 22px; }
.dialog-header, .dialog-footer { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; }
.dialog-header { border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: 20px; }
.icon-button { display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); font-size: 25px; }
.icon-button:hover { background: #eff2ee; color: var(--ink); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px 18px; padding: 21px 22px 24px; overflow-y: auto; }
.field { display: grid; align-content: start; gap: 6px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field > span, .toggle-field > span { color: #536059; font-size: 11px; font-weight: 700; }
.field b { color: var(--red); }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line-strong); border-radius: 5px; background: white; color: var(--ink); }
.field input, .field select { height: 39px; padding: 0 10px; }
.field textarea { padding: 9px 10px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); }
.field-error { min-height: 13px; color: var(--red); font-size: 10px; }
.toggle-field { align-content: start; }
.toggle { display: flex; align-items: center; gap: 9px; min-height: 39px; cursor: pointer; font-size: 12px; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { position: relative; width: 36px; height: 20px; border-radius: 10px; background: #c8cfca; transition: background .2s; }
.toggle-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: white; transition: transform .2s; }
.toggle input:checked + .toggle-track { background: var(--green); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }
.expiry-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 18px; padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-soft); }
.expiry-fields[hidden] { display: none; }
.date-divider { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 10px; }
.date-divider::before, .date-divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.date-preview { align-self: end; margin: 0 0 10px; color: var(--green-dark); font-size: 11px; }
.dialog-footer { border-top: 1px solid var(--line); background: #fafbf8; }
.dialog-footer-actions { display: flex; gap: 8px; margin-left: auto; }
.danger-text-button { padding: 8px 0; border: 0; background: transparent; color: var(--red); font-size: 12px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: min(350px, calc(100vw - 48px)); padding: 11px 14px; border-radius: 6px; background: #25342b; color: white; box-shadow: var(--shadow); font-size: 12px; opacity: 0; pointer-events: none; transform: translateY(10px); transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.sidebar-scrim { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 210px minmax(0, 1fr); }
  .sidebar { width: 210px; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-item:nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
  .summary-item:nth-child(4) { border-top: 1px solid var(--line); }
  .table-wrap { min-height: 350px; }
  table { min-width: 820px; }
}

@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar { width: min(280px, 84vw); transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 15; background: rgba(22, 31, 26, .4); }
  body.sidebar-open .sidebar-scrim { display: block; }
  .main-content { padding: 20px 16px 36px; }
  .mobile-menu { display: block; flex: 0 0 40px; }
  .topbar { align-items: center; flex-wrap: wrap; }
  .topbar > div:first-of-type { flex: 1; }
  h1 { font-size: 22px; }
  .top-actions { width: 100%; }
  .search-box { width: auto; flex: 1; }
  .summary-grid { margin-top: 20px; }
  .summary-item { padding: 14px; }
  .section-toolbar { align-items: stretch; flex-direction: column; gap: 10px; }
  .filter-group { overflow-x: auto; }
  .filter-button { flex: 0 0 auto; }
  .sort-wrap { justify-content: flex-end; }
  .form-grid { grid-template-columns: 1fr; }
  .field.wide, .expiry-fields { grid-column: auto; }
  .expiry-fields { grid-template-columns: 1fr; }
  .date-divider { grid-column: auto; }
}

@media (max-width: 470px) {
  .top-actions { align-items: stretch; flex-direction: column; }
  .search-box { width: 100%; }
  .summary-grid { grid-template-columns: 1fr; }
  .summary-item + .summary-item { border-top: 1px solid var(--line); border-left: 0; }
  .summary-item div { display: flex; align-items: baseline; justify-content: space-between; width: 100%; }
  .summary-item strong { margin: 0; }
  .dialog-header, .dialog-footer { padding: 15px 16px; }
  .form-grid { padding: 18px 16px; }
}

.pwa-tools{display:flex;gap:10px;align-items:center;flex-wrap:wrap;padding:12px 0;font-size:13px}.pwa-tools button,.import-label{background:#fff;border:1px solid #cdd8d0;border-radius:8px;padding:8px 10px;color:#345840;cursor:pointer}#pwaStatus{flex:1;min-width:160px}

.sr-only{clip-path:inset(50%);white-space:nowrap}.table-wrap{max-width:100%}

.sr-only{left:0;top:0}
