:root {
  --bg: #0f1512;
  --surface: #17201b;
  --surface-2: #1e2a23;
  --line: #2b3a31;
  --text: #e8f0ea;
  --muted: #8fa398;
  --accent: #7ee0a8;
  --accent-ink: #08210f;
  --warn: #f2c14e;
  --danger: #ff7b72;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(15, 21, 18, .88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: .02em; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.tabs { display: flex; background: var(--surface); border-radius: 999px; padding: 3px; }
.tab {
  border: 0; background: transparent; color: var(--muted);
  font-size: 14px; padding: 6px 14px; border-radius: 999px; cursor: pointer;
  font-family: inherit; transition: .18s;
}
.tab.active { background: var(--surface-2); color: var(--text); }
.badge {
  display: inline-block; min-width: 16px; height: 16px; line-height: 16px;
  margin-left: 5px; padding: 0 4px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 11px; text-align: center;
}
.hidden { display: none !important; }

/* ---------- 面板 ---------- */
.pane { display: none; flex: 1; min-height: 0; flex-direction: column; }
.pane.active { display: flex; }

/* ---------- 对话 ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.msg { max-width: 88%; display: flex; flex-direction: column; gap: 6px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
}
.msg.user .bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.msg.bot .bubble {
  background: var(--surface); border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.msg.bot .bubble.err { border-color: rgba(255, 123, 114, .5); }

.actions { display: flex; gap: 8px; margin-top: 2px; }
.btn {
  font-family: inherit; font-size: 14px; padding: 7px 14px;
  border-radius: 10px; cursor: pointer; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn:active { transform: scale(.97); }

/* ---------- 库存 ---------- */
.inv-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 6px;
}
.summary { color: var(--muted); font-size: 13px; }
.summary b { color: var(--text); font-weight: 600; }

.cards {
  flex: 1; overflow-y: auto; padding: 6px 14px 16px;
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  align-content: start;
}
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 13px; position: relative; overflow: hidden;
}
.card::after {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--muted);
}
.card.expired::after { background: var(--danger); }
.card.soon::after { background: var(--warn); }
.card.ok::after { background: var(--accent); }
.card.unknown::after { background: var(--line); }

.card .name { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.card .qty { color: var(--muted); font-size: 13px; }
.card .meta { margin-top: 8px; display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12px; }
.card .loc { color: var(--muted); }
.card .days { font-variant-numeric: tabular-nums; }
.card.expired .days { color: var(--danger); }
.card.soon .days { color: var(--warn); }
.card.ok .days { color: var(--accent); }

.empty { color: var(--muted); text-align: center; padding: 40px 20px; grid-column: 1 / -1; }

.inv-foot {
  display: flex; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.inv-foot .ghost { flex: 1; }
.ghost {
  font-family: inherit; font-size: 14px; padding: 9px 12px;
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.ghost:active { background: var(--surface); }

/* ---------- 输入区 ---------- */
.composer {
  border-top: 1px solid var(--line);
  background: rgba(15, 21, 18, .96);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; font-family: inherit; font-size: 13px; padding: 5px 12px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); cursor: pointer;
}
.chip:active { color: var(--text); }

.inputrow { display: flex; gap: 8px; align-items: center; }
#input {
  flex: 1; font-family: inherit; font-size: 16px;
  padding: 11px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  outline: none;
}
#input:focus { border-color: var(--accent); }
.send {
  width: 44px; height: 44px; flex: none; border-radius: 12px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  font-size: 20px; font-weight: 700; cursor: pointer;
}
.send:active { transform: scale(.95); }
.send:disabled { opacity: .45; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translate(-50%, 10px);
  background: var(--surface-2); color: var(--text);
  padding: 9px 16px; border-radius: 999px; font-size: 13px;
  border: 1px solid var(--line);
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50;
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8f6; --surface: #ffffff; --surface-2: #eef3ef; --line: #dde5df;
    --text: #16211a; --muted: #6b7f72; --accent: #1f8f5f; --accent-ink: #ffffff;
  }
  .topbar { background: rgba(246, 248, 246, .9); }
  .composer { background: rgba(246, 248, 246, .97); }
}
