:root {
  --bg: #f3efe6;
  --fg: #1f2a24;
  --accent: #2f5d45;
  --danger: #8b3a2f;
  --muted: #6a776f;
  --card: #fbf8f1;
  --border: rgba(31, 42, 36, 0.12);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(47,110,86,0.12), transparent 40%),
    radial-gradient(circle at bottom right, rgba(180,120,60,0.1), transparent 35%),
    var(--bg);
  color: var(--fg);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }
.top {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  gap: 12px; border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;
}
.brand small { letter-spacing: .12em; color: var(--accent); font-size: 12px; }
.brand h1 { margin: 4px 0 0; font-size: 22px; font-weight: 600; }
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-text-wrap {
  text-align: center;
  margin-bottom: 8px;
}
.brand-text {
  font-size: clamp(18px, 4.5vw, 24px);
  font-weight: 700;
  color: #1a3a7a;
  letter-spacing: 0.06em;
  line-height: 1.35;
}
.brand-text-header {
  font-size: 15px;
  font-weight: 700;
  color: #1a3a7a;
  letter-spacing: 0.04em;
  line-height: 1.3;
}
.brand-logo-header,
.brand-logo,
.brand-logo-wrap { display: none; }
.nav { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.nav a {
  padding: 8px 12px; border-radius: 8px; color: var(--fg); background: transparent;
}
.nav a.active, .nav a:hover { background: var(--accent); color: #f7f3ea; text-decoration: none; }
.card {
  background: color-mix(in srgb, var(--card) 92%, white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 18px; }
.grid { display: grid; gap: 12px; }
@media (min-width: 800px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}
.stat { font-size: 22px; font-weight: 600; margin-top: 4px; }
label { display: block; font-size: 13px; margin-bottom: 4px; color: var(--muted); }
.remember-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--fg);
  cursor: pointer;
  user-select: none;
}
.remember-row input {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}
.item-picker {
  grid-column: 1 / -1;
}
.row-5 .item-picker {
  grid-column: 1 / -1;
}
.item-picker-search-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.item-picker-search-row .item-picker-search {
  flex: 1;
  min-width: 0;
}
.item-picker-search-row .item-picker-search-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}
.item-picker-list {
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  overflow: auto;
  min-height: 140px;
}
.item-picker-empty {
  padding: 14px 12px;
}
.item-picker-option {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  background: transparent;
  color: var(--fg);
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 10px 12px;
  min-height: 44px;
  cursor: pointer;
}
.item-picker-option.is-filtered-out,
.item-picker-option[hidden] {
  display: none !important;
}
.item-picker-option:last-child {
  border-bottom: none;
}
.item-picker-option:hover:not(:disabled) {
  background: rgba(47, 93, 69, 0.08);
}
.item-picker-option.is-selected {
  background: rgba(47, 93, 69, 0.16);
}
.item-picker-option.is-disabled,
.item-picker-option:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.item-picker-option-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}
.item-picker-option-name {
  font-weight: 560;
}
.item-picker-option-meta {
  flex: 0 0 auto;
  font-size: 13px;
}
.badge-yjt {
  display: inline-block;
  background: #141414;
  color: #f3f3f3;
  font-size: 11px;
  line-height: 1.3;
  padding: 2px 7px;
  border-radius: 3px;
  margin-left: 2px;
  letter-spacing: 0.08em;
  vertical-align: middle;
  font-weight: 650;
  white-space: nowrap;
  border: 1px solid #2a2a2a;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
}
.item-name-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.item-name-cell .badge-yjt {
  margin-left: 0;
  margin-right: 0;
}
.price-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.price-cell-compact {
  gap: 2px;
}
.price-inline-form {
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
}
.price-inline-form input {
  width: auto;
  min-width: 0;
  padding: 6px 8px;
}
.price-edit summary,
.price-history summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 12px;
  line-height: 1.3;
  list-style: none;
}
.price-edit summary::-webkit-details-marker,
.price-history summary::-webkit-details-marker {
  display: none;
}
.price-edit-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  padding: 10px;
  background: rgba(47, 93, 69, 0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.price-edit-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
.price-history-list {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  max-height: 160px;
  overflow: auto;
}
.price-history-list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.price-history-list li:last-child {
  border-bottom: none;
}
.txn-check, #txn-check-all {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
input, select, textarea, button {
  font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
}
input, select, textarea { width: 100%; background: #fff; }
button, .btn {
  background: var(--accent); color: #f7f3ea; border: none; cursor: pointer;
  display: inline-block; padding: 8px 12px; border-radius: 8px;
}
button.secondary, .btn.secondary { background: transparent; color: var(--fg); border: 1px solid var(--border); }
button.danger { background: var(--danger); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.flash { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.flash.ok { background: rgba(47,93,69,.12); color: var(--accent); }
.flash.err { background: rgba(139,58,47,.12); color: var(--danger); }
.msg-mask {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 28, 24, 0.45);
  box-sizing: border-box;
}
.msg-box {
  width: min(400px, 100%);
  background: #fbf8f1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 18px 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
  text-align: center;
}
.msg-box p {
  margin: 0 0 16px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--fg);
  word-break: break-word;
}
.msg-box.err p { color: var(--danger); }
.msg-box.ok p { color: var(--accent); }
.msg-box button { min-width: 96px; }
.form-mask[hidden] { display: none !important; }
.form-box {
  width: min(440px, 100%);
  background: #fbf8f1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
  text-align: left;
  max-height: calc(100vh - 32px);
  overflow: auto;
}
.form-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.form-box-head h3 { margin: 0; font-size: 18px; }
.form-stack label {
  display: block;
  margin-bottom: 10px;
}
.form-stack label input,
.form-stack label select {
  margin-top: 4px;
}
.muted { color: var(--muted); font-size: 13px; }
html, body.login-page {
  height: 100%;
  margin: 0;
}
.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
  background: #1b2e24;
}
.login-box {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  background: #f7f2e8;
  border-radius: 16px;
  padding: 28px;
  box-sizing: border-box;
  text-align: center;
}
.login-box label {
  text-align: left;
}
.login-box .row {
  text-align: left;
}
.login-box .brand-text-wrap {
  text-align: center;
}
.login-box .brand-text {
  text-align: center;
}
.login-box .muted {
  text-align: center;
}
.row { display: grid; gap: 10px; margin-bottom: 12px; }
@media (min-width: 700px) {
  .row-3 { grid-template-columns: repeat(3, 1fr); }
  .row-4 { grid-template-columns: repeat(4, 1fr); }
  .row-5 { grid-template-columns: 2fr 1fr 1fr 1fr auto; }
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.low { color: var(--danger); font-weight: 600; }

.search-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.search-bar input[type="search"],
.search-bar input[type="date"],
.search-bar select {
  width: auto;
  min-width: 140px;
}
.search-bar-wrap input[type="search"] { min-width: 200px; flex: 1; }

.mono { font-variant-numeric: tabular-nums; font-family: Consolas, "Courier New", monospace; font-size: 13px; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
}
.badge.txn-in, .txn-in .badge { background: #d8f0e2; color: #1f6b45; }
.badge.txn-out, .txn-out .badge { background: #f8ddd8; color: #8b3a2f; }
.badge.txn-return, .txn-return .badge { background: #dcebff; color: #2a5f9e; }
.badge.txn-adjust, .txn-adjust .badge { background: #f3e6c8; color: #8a6a1f; }

tr.txn-row.txn-in { background: rgba(47, 93, 69, 0.06); }
tr.txn-row.txn-out { background: rgba(139, 58, 47, 0.06); }
tr.txn-row.txn-return { background: rgba(42, 95, 158, 0.06); }
tr.txn-row.txn-adjust { background: rgba(138, 106, 31, 0.06); }

.qty-plus { color: #1f6b45; font-weight: 700; }
.qty-minus { color: #8b3a2f; font-weight: 700; }

.user-edit-table td { vertical-align: middle; }
.user-edit-table input,
.user-edit-table select {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  font-size: 14px;
  background: #fff;
}
.user-edit-table input:focus,
.user-edit-table select:focus {
  outline: 2px solid rgba(47, 93, 69, 0.35);
  border-color: var(--accent);
}

input[readonly],
input:disabled,
select:disabled {
  background: #f0eee8;
  color: var(--fg);
  cursor: not-allowed;
  opacity: 1;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 0 4px;
}
.table-scroll table { margin: 0; }

/* ---- 手机端适配 ---- */
@media (max-width: 768px) {
  .wrap {
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .top {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .brand-text-header {
    font-size: 13px;
    letter-spacing: 0.02em;
  }
  .brand h1 {
    font-size: 18px;
  }
  .top .actions {
    width: 100%;
    justify-content: space-between;
  }

  .nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    margin: 0 -12px 14px;
    padding: 0 12px 8px;
    scrollbar-width: thin;
  }
  .nav::-webkit-scrollbar { height: 3px; }
  .nav a {
    flex: 0 0 auto;
    white-space: nowrap;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    font-size: 14px;
  }

  .card {
    padding: 12px;
    border-radius: 10px;
  }
  .card h2 { font-size: 16px; }

  input, select, textarea, button, .btn {
    font-size: 16px; /* 避免 iOS 聚焦放大 */
    min-height: 44px;
  }
  button, .btn {
    padding: 10px 14px;
    text-align: center;
  }

  .row { gap: 8px; }
  .row > button,
  .row > .btn {
    width: 100%;
  }

  .search-bar,
  .search-bar-wrap {
    width: 100%;
  }
  .search-bar input[type="search"],
  .search-bar input[type="date"],
  .search-bar select,
  .search-bar-wrap input[type="search"] {
    width: 100%;
    min-width: 0;
    flex: 1 1 100%;
  }
  .search-bar button,
  .search-bar .btn {
    flex: 1 1 auto;
  }

  .actions {
    gap: 8px;
  }
  .card > .actions {
    flex-direction: column;
    align-items: stretch;
  }
  .card > .actions > h2,
  .card > .actions > div {
    width: 100%;
  }
  .card > .actions .search-bar {
    width: 100%;
  }

  .table-scroll {
    margin: 0 -12px;
    padding: 0 12px;
  }
  .table-scroll table.wide {
    min-width: 560px;
  }
  th, td {
    padding: 10px 8px;
    font-size: 13px;
  }
  .mono {
    white-space: nowrap;
    font-size: 12px;
  }

  td .actions {
    flex-direction: column;
    align-items: stretch;
  }
  td .actions form,
  td .actions button,
  td .actions .btn {
    width: 100%;
  }

  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }

  .login-page {
    padding: 12px;
    padding-top: max(12px, env(safe-area-inset-top, 0px));
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    align-items: flex-start;
  }
  .login-box {
    padding: 20px 16px;
    border-radius: 14px;
    margin-top: 8vh;
  }
  .login-box .brand-text {
    font-size: clamp(16px, 5vw, 20px);
  }
  .login-box button,
  .login-box .btn {
    width: 100%;
  }

  .stat { font-size: 20px; }
  .legend { gap: 6px; }
  .badge { font-size: 11px; }
}

@media (max-width: 420px) {
  .table-scroll table.wide {
    min-width: 480px;
  }
  .brand-text-header {
    font-size: 12px;
  }
}

