:root {
  --bg: #0c1210;
  --panel: #141d19;
  --panel-2: #1a2620;
  --panel-3: #203029;
  --line: #2b4036;
  --text: #e9f2ed;
  --muted: #8fa69a;
  --green: #35c27b;
  --green-dark: #1c6d47;
  --amber: #e3b35b;
  --danger: #e05d5d;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}
button, input, textarea, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--green-dark); }
button:disabled { opacity: .38; cursor: not-allowed; }
button.primary { background: var(--green); border-color: var(--green); color: #06120c; font-weight: 700; }
button.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
button.ghost { background: transparent; }
input, textarea, select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--green); }
textarea { resize: vertical; min-height: 90px; }

#app { max-width: 1100px; margin: 0 auto; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  background: rgba(12,18,16,.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.title-wrap { min-width: 0; flex: 1; }
.title { font-size: 19px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions, .panel-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.icon-btn { padding: 7px 11px; }

main { padding: 14px 18px 60px; }
.searchbar { margin: 2px 0 14px; }
.searchbar input { padding: 11px 14px; border-radius: 11px; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.item-card {
  display: flex; min-height: 128px; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer;
}
.item-card:hover { border-color: var(--green-dark); }
.thumb { width: 42%; min-width: 110px; aspect-ratio: 4 / 3; background: var(--panel-3); flex: none; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .placeholder { width: 100%; height: 100%; display: grid; place-items: center; color: #54756a; font-size: 26px; }
.item-body { flex: 1; width: 0; padding: 11px 12px; min-width: 0; display: flex; flex-direction: column; }
.item-name { font-weight: 800; font-size: 15px; line-height: 1.25; height: 38px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item-desc { margin-top: 5px; color: var(--muted); font-size: 12px; height: 34px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item-tags { margin-top: 4px; height: 22px; overflow: hidden; display: flex; gap: 5px; flex-wrap: nowrap; justify-content: flex-end; }
.item-stock { margin-top: auto; text-align: right; color: var(--amber); font-size: 12px; font-weight: 800; }
.chip { font-size: 11px; color: #a8d8bf; background: #1c3a2d; border: 1px solid #2c5a44; border-radius: 999px; padding: 1px 7px; white-space: nowrap; }
.stock-badge { font-size: 11px; color: var(--amber); }

.empty { padding: 60px 16px; text-align: center; color: var(--muted); }
.loading { padding: 14px; text-align: center; color: var(--muted); font-size: 12px; }
.sentinel { height: 1px; }

.panel-view { padding-top: 4px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 4px 0 14px; }
.panel-head h2 { margin: 0; font-size: 18px; }
.section-title { margin: 22px 0 10px; color: var(--muted); font-size: 13px; }

.warehouse-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.warehouse-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px; display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.warehouse-card:hover { border-color: var(--green-dark); }
.warehouse-card.current {
  border: 2px solid var(--green);
  background: var(--panel-3);
  box-shadow: inset 4px 0 0 var(--green), 0 0 0 1px rgba(62, 207, 137, .12);
}
.current-badge {
  display: inline-block;
  margin-top: 5px;
  padding: 1px 7px;
  border-radius: 999px;
  color: #8ce6ba;
  background: #1c3a2d;
  border: 1px solid #2c5a44;
  font-size: 10px;
  font-weight: 700;
}
.warehouse-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.warehouse-name { font-weight: 800; font-size: 15px; }
.warehouse-desc { color: var(--muted); font-size: 12px; height: 34px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.warehouse-meta { color: var(--muted); font-size: 11px; display: flex; gap: 10px; flex-wrap: wrap; }
.role-badge { font-size: 11px; color: var(--amber); border: 1px solid #5b4726; background: #2a2114; border-radius: 999px; padding: 1px 7px; }

.detail-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.detail-image { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: var(--panel-3); }
.detail-placeholder { width: 100%; aspect-ratio: 4 / 3; display: grid; place-items: center; color: #54756a; font-size: 40px; background: var(--panel-3); }
.detail-body { padding: 16px; }
.detail-title { font-size: 27px; font-weight: 850; line-height: 1.2; word-break: break-word; }
.detail-stock { margin-top: 6px; color: var(--amber); font-weight: 700; }
.info-lines { margin: 14px 0; border-top: 1px solid var(--line); }
.info-line { padding: 8px 0; border-bottom: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; }
.info-line b { color: #b9e6cd; }
.detail-meta { color: var(--muted); font-size: 12px; display: grid; gap: 4px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

.history-list { display: flex; flex-direction: column; gap: 0; }
.month-sep { display: flex; align-items: center; gap: 12px; margin: 22px 0 8px; color: var(--muted); font-size: 12px; }
.month-sep::before, .month-sep::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.history-row { padding: 11px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; }
.history-line1 { display: flex; justify-content: space-between; gap: 10px; }
.history-item { font-size: 16px; font-weight: 750; }
.history-type { font-size: 11px; border-radius: 6px; padding: 1px 6px; border: 1px solid var(--line); color: var(--amber); white-space: nowrap; }
.history-type.in { color: #78d6a6; border-color: #2c5a44; }
.history-type.out { color: #e8a06a; border-color: #6a472c; }
.history-type.edit, .history-type.create { color: var(--text); border-color: var(--line); }
.history-type.delete { color: var(--danger); border-color: #6a3030; }
.history-detail { margin-top: 5px; color: var(--text-secondary, #b8c6bf); font-size: 13px; }
.history-action.in { color: #78d6a6; font-weight: 800; }
.history-action.out { color: #e8a06a; font-weight: 800; }
.history-stock { color: var(--text); font-weight: 800; }
.history-note { color: var(--muted); font-size: 12px; margin-top: 4px; white-space: pre-wrap; }
.history-meta { color: #71857b; font-size: 11px; margin-top: 5px; }

.menu {
  position: fixed; z-index: 60; min-width: 150px; padding: 6px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 14px 40px rgba(0,0,0,.45);
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 10px; }
.menu button:hover { background: var(--panel-3); }

.overlay { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.62); display: grid; place-items: center; padding: 18px; }
.modal { width: min(640px, 100%); max-height: 88vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.modal.narrow { width: min(420px, 100%); }
.modal.wide { width: min(820px, 100%); }
.modal h3 { margin: 0 0 12px; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.form-row { margin-bottom: 10px; }
.form-row label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.form-hint { color: #71857b; font-size: 11px; margin-top: 4px; }
.thumb-picker { display: flex; gap: 10px; align-items: center; }
.thumb-preview { width: 128px; aspect-ratio: 4 / 3; border-radius: 9px; background: var(--panel-3); overflow: hidden; display: grid; place-items: center; color: #54756a; }
.thumb-preview img { width: 100%; height: 100%; object-fit: cover; }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { width: 42px; padding: 6px 0; font-size: 18px; }
.stepper input { text-align: center; }

.crop-stage { position: relative; width: 100%; aspect-ratio: 4 / 3; background: #050807; overflow: hidden; border-radius: 10px; touch-action: none; cursor: grab; }
.crop-stage canvas { width: 100%; height: 100%; display: block; }
.crop-tools { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.crop-tools input[type=range] { flex: 1; }

.member-row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); align-items: center; }
.member-name { font-weight: 700; }
.member-role { color: var(--muted); font-size: 12px; }
.invite-row { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); align-items: center; }
.code { font-family: ui-monospace, monospace; letter-spacing: 1px; color: #a8d8bf; }
.error { color: var(--danger); font-size: 12px; margin-top: 8px; }

@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
  .topbar { padding: 10px 12px; gap: 8px; }
  .title { font-size: 16px; }
  .top-actions button { padding: 7px 9px; font-size: 12px; }
  main { padding: 10px 12px 50px; }
  .item-card { min-height: 118px; }
  .thumb { width: 40%; min-width: 96px; }
  .item-name { font-size: 14px; height: 36px; }
  .warehouse-list { grid-template-columns: 1fr; }
}

/* 窄长屏（宽高比低于 3:4）也切为单列，避免卡片过挤 */
@media (max-aspect-ratio: 3/4) {
  .grid { grid-template-columns: 1fr; }
}
