/* 库房整理 — mobile-first */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #1a1f1c;
  --muted: #5c6b63;
  --border: #d8e0db;
  --primary: #1a5f4a;
  --primary-press: #134839;
  --danger: #b33a2b;
  --danger-press: #8f2e22;
  --in: #1a5f4a;
  --out: #b33a2b;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 72px;
  --tab-h: 56px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 16px);
}

.app-header {
  background: var(--primary);
  color: #fff;
  padding: 16px 20px 14px;
  padding-top: max(16px, env(safe-area-inset-top));
}

.app-header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 0.8rem;
  opacity: 0.85;
}

.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 40;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.04);
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  min-height: var(--tab-h);
  cursor: pointer;
}

.tab.active {
  color: var(--primary);
}

.content {
  padding: 14px 14px 8px;
  max-width: 560px;
  margin: 0 auto;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.toolbar.filters {
  flex-direction: row;
  gap: 8px;
}

.toolbar.filters .input {
  flex: 1;
}

.input {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  min-height: 48px;
}

.input:focus {
  outline: 2px solid rgba(26, 95, 74, 0.35);
  border-color: var(--primary);
}

select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235c6b63' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 600;
  min-height: 48px;
  cursor: pointer;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:active {
  background: var(--primary-press);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:active {
  background: var(--danger-press);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-block {
  width: 100%;
  margin-top: 8px;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.stock-badge {
  flex-shrink: 0;
  background: #e8f3ee;
  color: var(--primary);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
}

.stock-badge.zero {
  background: #f5eaea;
  color: var(--danger);
}

.card-meta {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.form-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.form-card h2 {
  margin: 0 0 14px;
  font-size: 1.15rem;
}

.field {
  display: block;
  margin-bottom: 12px;
}

.field > span {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.field em {
  color: var(--danger);
  font-style: normal;
}

.hint {
  margin: -4px 0 12px;
  font-size: 0.85rem;
  color: var(--primary);
  font-weight: 600;
}

.empty-hint {
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
  font-size: 0.95rem;
}

.hidden {
  display: none !important;
}

/* history cards */
.tx-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.tx-type {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
}

.tx-type.in {
  background: var(--in);
}

.tx-type.out {
  background: var(--out);
}

.tx-body {
  flex: 1;
  min-width: 0;
}

.tx-body strong {
  display: block;
  font-size: 1rem;
}

.tx-body .tx-detail {
  margin-top: 4px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

.tx-qty {
  font-weight: 700;
  white-space: nowrap;
}

.tx-qty.in {
  color: var(--in);
}

.tx-qty.out {
  color: var(--out);
}

/* modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.22s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(40%);
  }
  to {
    transform: translateY(0);
  }
}

.modal-sheet h2 {
  margin: 0 0 14px;
  font-size: 1.15rem;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 20px);
  transform: translateX(-50%);
  background: rgba(26, 31, 28, 0.92);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  z-index: 200;
  max-width: 90%;
  text-align: center;
  pointer-events: none;
}

@media (min-width: 600px) {
  .toolbar:not(.filters) {
    flex-direction: row;
    align-items: stretch;
  }

  .toolbar:not(.filters) .search {
    flex: 1;
  }
}
