/* ============ 基础 ============ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: #eef4ef;
  color: #1f2937;
  line-height: 1.5;
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; font-size: 16px; }
.hidden { display: none !important; }

.app {
  max-width: 540px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #e9f5ec 0%, #f4f8f4 240px);
}

/* ============ 顶栏 ============ */
.app-header {
  background: linear-gradient(135deg, #10b981 0%, #059669 60%, #047857 100%);
  color: #fff;
  padding: calc(18px + env(safe-area-inset-top)) 18px 22px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 52px; height: 52px; border-radius: 15px;
  background: rgba(255,255,255,.22);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}
.brand-text h1 { margin: 0; font-size: 20px; letter-spacing: .5px; }
.tagline { margin: 2px 0 0; font-size: 12.5px; opacity: .92; }

/* ============ 统计条 ============ */
.stat-bar {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin: -12px 14px 0;
  position: relative; z-index: 1;
}
.stat {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 14px;
  padding: 10px 4px; text-align: center; box-shadow: 0 3px 10px rgba(16,60,35,.07);
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.stat:active { transform: scale(.97); }
.stat b { display: block; font-size: 22px; color: #111827; line-height: 1.2; }
.stat span { font-size: 12px; color: #6b7280; }
.stat.active { border-color: #059669; background: #ecfdf5; }
.stat.active b { color: #059669; }
.stat[data-filter="warning"].active { border-color: #f59e0b; background: #fffbeb; }
.stat[data-filter="warning"].active b { color: #d97706; }

/* ============ 通知横幅 ============ */
.notify-banner {
  margin: 12px 14px 0; padding: 10px 12px;
  background: #fff7ed; border: 1px solid #fed7aa; border-radius: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.nb-text { font-size: 13px; color: #9a3412; flex: 1; }

/* ============ 按钮 ============ */
.btn {
  border: 1px solid transparent; border-radius: 10px;
  padding: 9px 14px; font-size: 14px; line-height: 1.2;
  background: #fff; transition: filter .12s ease, transform .12s ease;
}
.btn:active { transform: scale(.97); filter: brightness(.95); }
.btn-primary { background: #059669; color: #fff; font-weight: 600; }
.btn-primary:active { background: #047857; }
.btn-block { width: 100%; padding: 12px; font-size: 16px; border-radius: 12px; }
.btn-light { background: #fff; color: #059669; font-weight: 600; padding: 7px 12px; font-size: 13px; }
.btn-outline { border-color: #d1d5db; color: #374151; background: #fff; }
.btn-danger-ghost { border-color: #fecaca; color: #dc2626; background: #fff; }
.btn-small { padding: 7px 12px; font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row.gap { margin: 10px 0; }
.upload { position: relative; overflow: hidden; }
.upload input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

/* ============ 添加按钮 ============ */
.btn-add {
  display: block; width: calc(100% - 28px); margin: 14px auto 4px;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff; border: none; border-radius: 14px;
  padding: 14px; font-size: 16.5px; font-weight: 700;
  box-shadow: 0 6px 16px rgba(5,150,105,.32);
}
.btn-add:active { filter: brightness(.94); }

/* ============ 商品列表 ============ */
main { padding: 6px 14px 0; }
.item-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.item {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 16px;
  padding: 13px 14px; box-shadow: 0 2px 10px rgba(16,60,35,.05);
  animation: rise .25s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.item.warn-item { border-color: #fcd34d; background: #fffdf5; }
.item.due-item { border-color: #fca5a5; background: #fff7f7; }
.item-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.item-title { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; }
.item-name { font-size: 16.5px; font-weight: 700; word-break: break-all; }
.badge {
  background: #fef3c7; color: #b45309; border: 1px solid #fde68a;
  font-size: 11px; padding: 1px 7px; border-radius: 999px; white-space: nowrap;
}
.badge.due-badge { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.btn-del {
  border: none; background: transparent; color: #c0c6cc;
  font-size: 16px; padding: 4px; border-radius: 8px; flex: 0 0 auto; line-height: 1;
}
.btn-del:active { color: #dc2626; background: #fee2e2; }
.item-meta { margin-top: 5px; font-size: 12.5px; color: #6b7280; }
.item-meta b { color: #374151; font-weight: 600; }
.item-bottom { margin-top: 9px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.expiry { font-size: 12.5px; color: #6b7280; }
.expiry b { font-weight: 700; color: #374151; }
.warn-item .expiry b, .due-item .expiry b { color: #dc2626; }

.pill {
  border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 700;
  white-space: nowrap; flex: 0 0 auto;
}
.pill.ok { background: #ecfdf5; color: #059669; border: 1px solid #a7f3d0; }
.pill.warn { background: #fff7ed; color: #c2410c; border: 1px solid #fdba74; }
.pill.due { background: #dc2626; color: #fff; border: 1px solid #dc2626; }

.empty { text-align: center; padding: 44px 16px; color: #6b7280; }
.empty-emoji { font-size: 52px; margin-bottom: 8px; }
.empty p { margin: 4px 0; font-size: 15px; color: #374151; }
.empty .empty-sub { font-size: 13px; color: #9ca3af; }

/* ============ 折叠面板 ============ */
.panel {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 16px;
  margin-top: 12px; overflow: hidden;
}
.panel summary {
  padding: 13px 15px; font-size: 14px; font-weight: 600; color: #374151;
  list-style: none; display: flex; align-items: center; justify-content: space-between; cursor: pointer;
}
.panel summary::-webkit-details-marker { display: none; }
.panel summary::after { content: "▾"; color: #9ca3af; transition: transform .15s ease; }
.panel[open] summary::after { transform: rotate(180deg); }
.panel-body { padding: 0 15px 15px; border-top: 1px dashed #eceff1; }
.panel-body > * { margin-top: 12px; }
.panel-body > .field { margin-top: 14px; }
.hint { font-size: 12px; color: #9ca3af; line-height: 1.6; margin: 12px 0 0; }

.archive-list { list-style: none; margin: 0; padding: 4px 15px 6px; }
.archive-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 2px; border-bottom: 1px dashed #eceff1; font-size: 13px;
}
.archive-list li:last-child { border-bottom: none; }
.ar-name { font-weight: 600; color: #374151; word-break: break-all; }
.ar-info { color: #9ca3af; font-size: 12px; text-align: right; }
.archive-empty { color: #9ca3af; font-size: 13px; padding: 8px 15px; margin: 0; }

/* ============ 表单 ============ */
.field { display: block; margin-bottom: 15px; }
.field > span { display: block; font-size: 14px; font-weight: 600; color: #374151; margin-bottom: 6px; }
.field > span i { color: #dc2626; font-style: normal; }
.field input[type="text"], .field input[type="date"], .field input[type="number"], .custom-shelf select {
  width: 100%; border: 1.5px solid #d1d5db; border-radius: 11px;
  padding: 11px 12px; font-size: 16px; background: #fff; color: #111827;
  outline: none; transition: border-color .12s ease, box-shadow .12s ease;
}
.field input:focus, .custom-shelf select:focus {
  border-color: #059669; box-shadow: 0 0 0 3px rgba(5,150,105,.14);
}
.field small { display: block; margin-top: 5px; color: #9ca3af; font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid #d1d5db; background: #fff; color: #374151;
  border-radius: 999px; padding: 8px 15px; font-size: 14px; transition: all .12s ease;
}
.chip.active { border-color: #059669; background: #ecfdf5; color: #059669; font-weight: 700; }

.custom-shelf { display: flex; align-items: center; gap: 8px; margin: -4px 0 15px; }
.custom-shelf input { width: 110px; border: 1.5px solid #d1d5db; border-radius: 11px; padding: 10px 12px; }
.custom-shelf select { width: auto; border: 1.5px solid #d1d5db; border-radius: 11px; padding: 10px 8px; background: #fff; }
.custom-preview { font-size: 13px; color: #059669; font-weight: 600; flex: 1; text-align: right; }

.form-error {
  background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
  border-radius: 10px; padding: 9px 12px; font-size: 13.5px; margin: 0 0 12px;
}

/* ============ 弹窗 ============ */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15,30,20,.45);
  display: flex; align-items: flex-end; justify-content: center;
  padding: env(safe-area-inset-bottom);
}
.modal {
  background: #fff; width: 100%; max-width: 540px;
  border-radius: 22px 22px 0 0;
  max-height: 88dvh; overflow-y: auto;
  padding: 0 18px calc(18px + env(safe-area-inset-bottom));
  animation: sheet .22s ease;
}
@keyframes sheet { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head {
  position: sticky; top: 0; background: #fff; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 0 12px;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.icon-btn {
  border: none; background: #f3f4f6; color: #374151;
  width: 34px; height: 34px; border-radius: 50%; font-size: 14px;
}
.icon-btn:active { background: #e5e7eb; }

/* ============ Toast ============ */
.toast-wrap {
  position: fixed; left: 0; right: 0; bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 99; display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; padding: 0 16px;
}
.toast {
  background: rgba(17,24,39,.92); color: #fff; border-radius: 12px;
  padding: 10px 16px; font-size: 13.5px; max-width: 92%;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  animation: toast-in .2s ease; text-align: center;
}
.toast.warn { background: rgba(217,119,6,.96); }
.toast.danger { background: rgba(220,38,38,.96); }
.toast.ok { background: rgba(5,150,105,.96); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ============ 页脚 ============ */
.app-footer { padding: 18px 18px 6px; text-align: center; }
.app-footer p { margin: 3px 0; font-size: 11.5px; color: #9ca3af; }

@media (min-width: 600px) {
  .overlay { align-items: center; padding: 20px; }
  .modal { border-radius: 22px; max-height: 86dvh; }
}
