:root {
  --bg: var(--tg-theme-bg-color, #f4f6f8);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #6b7280);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --sec: var(--tg-theme-secondary-bg-color, #fff);
  --bad: #c62828;
}

* { box-sizing: border-box; }

html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-x: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC",
    "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px 120px;
  overflow-x: hidden;
}

/* 手机：壳子高度一次定死，弹键盘不改布局（防顶掉）；滚动只在 #app 内 */
html.is-mobile,
html.is-mobile body {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  width: 100%;
  height: var(--app-h, 100lvh);
  max-height: var(--app-h, 100lvh);
  overflow: hidden;
  overscroll-behavior: none;
}

html.is-mobile #app {
  height: 100%;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* 页面内弹键盘：加大底垫，输入框可滚到键盘上方 */
html.is-mobile.kb-open #app {
  padding-bottom: calc(24px + var(--kb-h, 0px));
}

html.is-desktop #app {
  max-width: 560px;
  padding-bottom: 48px;
}

/* 已废弃「请竖屏」全屏遮罩：手机弹键盘时可视区变矮会被误判横屏，导致输入框失焦 */
#rotate-tip {
  display: none !important;
}

.muted {
  color: var(--hint);
  font-size: 0.9rem;
  margin: 0 0 12px;
}

.hidden { display: none !important; }

.error {
  background: #fdecea;
  color: var(--bad);
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 12px;
}

#view-home {
  position: relative;
  min-height: calc(100vh - 132px);
  min-height: calc(100dvh - 132px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

html.is-mobile #view-home {
  min-height: calc(var(--app-h, 100lvh) - 132px);
}

html.is-desktop #view-home {
  min-height: calc(100vh - 80px);
  min-height: calc(100dvh - 80px);
}

.home-top {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
}

.clear-all-btn {
  margin: 0;
  padding: 8px 12px;
  border: 1px solid rgba(198, 40, 40, 0.35);
  border-radius: 10px;
  background: #fdecea;
  color: var(--bad);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

#view-home .menu {
  margin-top: 0;
  width: 100%;
  align-items: stretch;
}

#view-home .menu-btn {
  text-align: center;
}

#view-home #home-hint {
  width: 100%;
  text-align: center;
}

#view-home #home-hint:empty {
  display: none;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.menu-btn {
  width: 100%;
  padding: 18px 16px;
  border: none;
  border-radius: 14px;
  background: var(--sec);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  max-width: 100%;
}

.cat-heading {
  margin: 16px 0 8px;
  padding: 0 2px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.cat-heading:first-child {
  margin-top: 4px;
}

.grid > .cat-heading {
  grid-column: 1 / -1;
}

.inbound-qty-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.inbound-qty-row input {
  flex: 1;
  min-width: 0;
  margin: 0;
}

.inbound-qty-row button {
  flex: 0 0 auto;
  margin: 0;
  width: auto;
  padding: 10px 16px;
}

.cat-filter {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.cat-filter-btn {
  box-sizing: border-box;
  width: 100%;
  min-height: 48px;
  height: 48px;
  margin: 0;
  padding: 0 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  background: var(--sec);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.2;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.cat-filter-btn.active {
  border-color: var(--btn);
  background: var(--btn);
  color: var(--btn-text);
}

.claim-review-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.claim-review-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.claim-review-info strong {
  font-size: 0.98rem;
}

.claim-review-heading {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 700;
}

.claim-review-hint {
  margin: 0 0 10px;
}

.claim-review-top {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.claim-review-list {
  margin: 0;
}

.claim-review-form-block {
  margin-top: 18px;
  padding-top: 4px;
}

.cat-manage-fold {
  margin-top: 20px;
  background: var(--sec);
  border-radius: 12px;
  padding: 4px 12px 12px;
}

.cat-manage-fold > summary {
  cursor: pointer;
  padding: 12px 4px;
  font-weight: 600;
  list-style: none;
}

.cat-manage-fold > summary::-webkit-details-marker {
  display: none;
}

.cat-manage-fold > summary::before {
  content: "▸ ";
  color: var(--hint);
}

.cat-manage-fold[open] > summary::before {
  content: "▾ ";
}

.cat-manage-body label {
  display: block;
  margin-top: 4px;
}

.cat-manage-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.cat-manage-actions button {
  flex: 1;
  margin: 0;
  padding: 10px 8px;
}

button.danger-outline {
  border: 1px solid rgba(198, 40, 40, 0.35);
  border-radius: 10px;
  background: #fdecea;
  color: var(--bad);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.cat-add-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.cat-add-row input {
  flex: 1;
  min-width: 0;
}

.cat-add-row button {
  flex: 0 0 auto;
  margin: 0;
  white-space: nowrap;
}

.cat-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg);
  font-size: 0.88rem;
}

.cat-chip button {
  margin: 0;
  padding: 0 4px;
  border: none;
  background: transparent;
  color: var(--bad);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.item {
  background: var(--sec);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 12px 10px;
  text-align: left;
  color: var(--text);
  font: inherit;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

.item .name { font-weight: 600; display: block; }
.item .qty { font-size: 0.8rem; color: var(--hint); display: block; }
.item.selected {
  border-color: var(--btn);
  box-shadow: inset 0 0 0 1px var(--btn);
}

.item-ctrl {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 2px;
}

.item-ctrl .pick-qty {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--btn);
}

.tri-btn {
  width: 40px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: #e8eef5;
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.tri-btn:active {
  opacity: 0.75;
}

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

.card {
  background: var(--sec);
  border-radius: 12px;
  padding: 12px;
}

.card .title {
  font-weight: 600;
  margin-bottom: 4px;
}

.card .meta {
  font-size: 0.85rem;
  color: var(--hint);
  line-height: 1.45;
}

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-row input {
  flex: 1;
  margin: 0;
}

input, select, textarea, button, pre, .card, .menu-btn, .report-box, #done-detail {
  max-width: 100%;
}

label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.9rem;
}

.reason-field {
  display: block;
  margin-bottom: 10px;
  font-size: 0.9rem;
}

.reason-label {
  display: block;
}

.reason-presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}

.reason-preset {
  margin: 0;
  width: 100%;
  padding: 10px 8px;
  border: 2px solid #d1d5db;
  border-radius: 10px;
  background: var(--sec);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.25;
}

.reason-preset.active {
  border-color: var(--btn);
  background: rgba(36, 129, 204, 0.12);
  color: var(--btn);
}

.reason-field input {
  margin-top: 8px;
}

input, select, textarea {
  display: block;
  width: 100%;
  max-width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font: inherit;
  background: var(--sec);
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 88px;
  line-height: 1.4;
}

.primary, .secondary {
  width: 100%;
  margin-top: 8px;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

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

.secondary {
  width: auto;
  margin-top: 0;
  padding: 10px 14px;
  background: var(--btn);
  color: var(--btn-text);
  white-space: nowrap;
}

.primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font: inherit;
  background: var(--sec);
  color: var(--text);
}

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

.card-actions button {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  background: #e5e7eb;
  color: var(--text);
}

.card-actions button.danger {
  background: #fdecea;
  color: var(--bad);
}

#done-detail {
  background: var(--sec);
  padding: 12px;
  border-radius: 10px;
  white-space: pre-wrap;
  font-size: 0.9rem;
}

.secondary-block {
  width: 100%;
  margin-top: 8px;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: #e5e7eb;
  color: var(--text);
}

.report-box {
  background: var(--sec);
  padding: 12px;
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 0.82rem;
  line-height: 1.45;
  max-height: 50vh;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  margin: 12px 0 0;
}

/* 物资编辑弹窗 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden {
  display: none !important;
}

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

.modal-sheet {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  max-height: min(88vh, 720px);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.12);
}

/* 手机：弹窗挂在固定壳子上用 absolute，高度不用 vh（弹键盘改 vh 会闪） */
html.is-mobile .modal {
  position: absolute;
  height: 100%;
  max-height: 100%;
}

html.is-mobile .modal-sheet {
  max-height: 88%;
  transition: none;
}

/* 弹窗内弹键盘：整块上移到键盘上方，内部可继续滚 */
html.is-mobile .modal.kb-open .modal-sheet {
  margin-bottom: var(--kb-h, 0px);
  max-height: calc(var(--app-h, 100%) - var(--kb-h, 0px) - 8px);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.modal-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: #e5e7eb;
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

body.modal-open {
  overflow: hidden;
}

/* 电脑端弹窗居中，更适合宽窗口 */
html.is-desktop .modal {
  align-items: center;
  padding: 16px;
}

html.is-desktop .modal-sheet {
  border-radius: 16px;
  max-height: min(86vh, 720px);
  width: min(480px, 100%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

.alert-sheet {
  text-align: center;
  padding: 28px 20px 20px;
}

.alert-text {
  margin: 0 0 20px;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.55;
}

.field {
  margin: 10px 0;
}

.field > .label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.select-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.select-row select {
  flex: 1;
  margin: 0;
}

.opt-add,
.opt-del {
  flex: 0 0 44px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.opt-del {
  color: #c0392b;
  border-color: rgba(192, 57, 43, 0.45);
}

.opt-del.hidden,
.opt-add.hidden {
  display: none;
}
