:root {
  --green: #0f7d61;
  --green-dark: #09694f;
  --green-soft: #e8f4ef;
  --line: #d7e3de;
  --text: #10231d;
  --muted: #6d7a76;
  --bg: #f2f6f4;
  --white: #fff;
}

* {
  box-sizing: border-box;
}

html,
body,
#root {
  width: 100%;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 7px;
  background: var(--green);
  color: var(--white);
  font-weight: 800;
}

input,
select,
textarea {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--white);
  color: var(--text);
  text-align: center;
  font-weight: 800;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.login-view {
  display: grid;
  min-height: 100dvh;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  place-items: center;
}

.login-panel {
  width: min(100%, 360px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.login-panel h1 {
  margin: 0 0 16px;
  font-size: 26px;
  text-align: center;
}

.login-panel label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 700;
}

.login-panel input {
  height: 46px;
  padding: 0 10px;
  text-align: left;
}

.login-panel button {
  width: 100%;
  height: 46px;
  margin-top: 2px;
}

.form-error {
  min-height: 20px;
  margin: 10px 0 0;
  color: #b42318;
  text-align: center;
  font-weight: 700;
}

.app-shell {
  display: flex;
  width: 100%;
  max-width: 430px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 7px max(8px, env(safe-area-inset-bottom));
  flex-direction: column;
  gap: 7px;
}

.top-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: 7px;
  background: var(--green);
  color: var(--white);
}

.top-card strong {
  display: block;
  overflow: hidden;
  font-size: 20px;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-card span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 700;
  opacity: 0.92;
}

.top-actions {
  display: grid;
  grid-template-columns: 76px 66px;
  gap: 6px;
}

.top-actions button,
.tab,
.pager button,
.export-row button {
  height: 38px;
}

.ghost-btn {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
}

.light-btn {
  background: var(--white);
  color: var(--green);
}

.tab-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--green-soft);
}

.tab {
  background: var(--white);
  color: var(--green);
}

.tab.active {
  background: var(--green);
  color: var(--white);
}

.pager {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 82px;
  gap: 8px;
  align-items: center;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--green-soft);
  text-align: center;
}

.pager button {
  background: var(--white);
  color: var(--green);
}

.pager button:last-child {
  background: var(--green);
  color: var(--white);
}

.pager strong {
  display: block;
  overflow: hidden;
  font-size: 18px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pager span {
  display: block;
  overflow: hidden;
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view-panel {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 7px;
}

.batch-grid {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 118px;
  gap: 7px;
  align-items: stretch;
}

.sequence-rail {
  position: relative;
}

.sequence-pill {
  display: grid;
  width: 100%;
  min-height: 44px;
  border-radius: 7px;
  background: var(--green);
  color: var(--white);
  font-size: 25px;
  font-weight: 900;
  place-items: center;
}

.batch-jump-panel {
  position: absolute;
  left: 0;
  top: calc(100% + 5px);
  z-index: 7;
  display: grid;
  width: min(168px, calc(100vw - 22px));
  max-height: 310px;
  gap: 5px;
  padding: 7px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  box-shadow: 0 12px 26px rgba(16, 35, 29, 0.18);
}

.batch-jump-panel button {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  min-height: 36px;
  gap: 6px;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--green);
  text-align: left;
}

.batch-jump-panel button.active {
  background: var(--green);
  color: var(--white);
}

.batch-jump-panel span {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-field,
.batch-field,
.autocomplete-field,
.summary-grid label {
  position: relative;
  display: block;
}

.product-field span {
  position: absolute;
  left: 10px;
  top: 50%;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  transform: translateY(-50%);
}

.product-field input,
.batch-field input {
  width: 100%;
  height: 44px;
  padding: 0 8px;
  font-size: 20px;
}

.product-field input {
  padding-left: 46px;
  text-align: left;
}

.batch-code-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  gap: 5px;
}

.batch-field input {
  font-size: 16px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.stock-toggle {
  height: 44px;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--green);
}

.stock-toggle.active {
  border-color: var(--green);
  background: var(--green);
  color: var(--white);
}

.batch-code-lock.locked input {
  border-color: var(--green);
  border-radius: 999px;
  background: var(--green);
  color: var(--white);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
}

.summary-grid > div,
.summary-grid label {
  min-height: 52px;
  padding: 5px 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--white);
  text-align: center;
}

.summary-grid strong,
.summary-grid input {
  display: block;
  width: 100%;
  height: 26px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  line-height: 26px;
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.price-lock.locked input {
  width: 56px;
  margin: 0 auto;
  border-radius: 999px;
  background: var(--green);
  color: var(--white);
}

.add-line-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px 68px 66px;
  gap: 5px;
}

.add-line-form input,
.add-line-form button {
  width: 100%;
  height: 42px;
}

.suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 8;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--white);
  box-shadow: 0 10px 22px rgba(16, 35, 29, 0.12);
}

.suggestions button {
  display: block;
  width: 100%;
  height: 34px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--white);
  color: var(--text);
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suggestions button:last-child {
  border-bottom: 0;
}

.readonly input,
.readonly button,
.readonly select,
.readonly textarea,
input:disabled,
button:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.58;
}

.data-table {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.packing-table {
  flex: 1;
  min-height: 220px;
  overflow-y: auto;
}

.table-row {
  display: grid;
  min-height: 40px;
  border-bottom: 1px solid var(--line);
}

.packing-table .table-row {
  grid-template-columns: minmax(84px, 1fr) 90px 52px 58px 48px;
}

.customer-table .table-row {
  grid-template-columns: minmax(64px, 1fr) 88px 46px 46px 56px 42px;
}

.table-row:last-child {
  border-bottom: 0;
}

.table-row > span,
.table-row > input {
  display: grid;
  min-width: 0;
  padding: 0 3px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  align-items: center;
  justify-items: center;
  text-align: center;
  font-size: 14px;
  font-weight: 850;
}

.table-row > span:last-child,
.table-row > input:last-child {
  border-right: 0;
}

.table-head {
  position: sticky;
  top: 0;
  z-index: 1;
  min-height: 36px;
  background: #edf5f2;
}

.table-head span {
  color: #314a43;
  font-size: 13px;
}

.name-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qty-cell {
  height: 39px;
  font-size: 15px !important;
}

.slot-cell {
  color: var(--green);
}

.empty-state {
  display: grid;
  min-height: 110px;
  color: var(--muted);
  font-weight: 850;
  place-items: center;
  text-align: center;
}

.export-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}

.export-row button {
  font-size: 14px;
}

.customer-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.customer-add-panel,
.group-order-panel {
  display: grid;
  gap: 6px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--green-soft);
}

.customer-add-grid,
.group-add-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px 58px 56px;
  gap: 5px;
}

.customer-add-grid select,
.group-add-grid select,
.customer-add-grid input,
.group-add-grid input,
.customer-add-grid button,
.group-add-grid button,
.group-order-panel .autocomplete-field input {
  width: 100%;
  height: 38px;
}

.smart-add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 5px;
}

.smart-add-row textarea {
  width: 100%;
  min-height: 42px;
  max-height: 82px;
  padding: 7px;
  text-align: left;
  font-size: 13px;
  font-weight: 800;
  resize: vertical;
}

.smart-add-row button {
  min-height: 42px;
  padding: 0 4px;
  font-size: 13px;
}

.customer-title {
  padding: 18px 8px 14px;
  background: #fbfdfc;
  text-align: center;
}

.customer-title h2 {
  margin: 0;
  overflow: hidden;
  font-size: 24px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.customer-title p {
  margin: 7px 0 0;
  color: var(--green);
  font-size: 17px;
  font-weight: 900;
}

.status-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 4px 2px 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.status-bar span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-bar button {
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--green);
  font-size: 11px;
}

.export-sheet {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 10px;
  background: rgba(8, 25, 20, 0.42);
}

.export-panel {
  display: grid;
  width: min(100%, 430px);
  max-height: calc(100dvh - 28px - env(safe-area-inset-top));
  gap: 8px;
  padding: 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.export-panel header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 66px;
  gap: 8px;
  align-items: center;
}

.export-panel header strong,
.export-panel header span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.export-panel header strong {
  font-size: 18px;
}

.export-panel header span,
.export-tip {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.export-preview-image {
  width: 100%;
  max-height: 62dvh;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--white);
  touch-action: manipulation;
}

.export-tip {
  margin: 0;
  padding: 8px;
  border-radius: 7px;
  background: var(--green-soft);
  text-align: center;
}

.export-table-preview {
  max-height: 38dvh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.export-table-preview table {
  width: 100%;
  min-width: 390px;
  border-collapse: collapse;
}

.export-table-preview th,
.export-table-preview td {
  padding: 8px 6px;
  border: 1px solid var(--line);
  text-align: center;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.export-table-preview th {
  background: var(--green-soft);
  color: var(--green);
}

#export-copy-text {
  width: 100%;
  min-height: 86px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}

.export-sheet-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.export-sheet-actions button {
  min-height: 42px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 10;
  max-width: min(330px, calc(100vw - 28px));
  padding: 10px 14px;
  border-radius: 7px;
  background: rgba(15, 35, 29, 0.9);
  color: var(--white);
  font-weight: 800;
  text-align: center;
  transform: translateX(-50%);
}

@media (max-width: 360px) {
  .app-shell {
    padding-left: 5px;
    padding-right: 5px;
  }

  .top-actions {
    grid-template-columns: 68px 58px;
  }

  .batch-grid {
    grid-template-columns: 38px minmax(0, 1fr) 106px;
  }

  .batch-code-wrap {
    grid-template-columns: minmax(0, 1fr) 28px;
  }

  .summary-grid {
    gap: 4px;
  }

  .summary-grid strong,
  .summary-grid input {
    font-size: 18px;
  }

  .customer-add-grid,
  .group-add-grid {
    grid-template-columns: minmax(0, 1fr) 50px 50px 48px;
  }

  .packing-table .table-row {
    grid-template-columns: minmax(76px, 1fr) 82px 48px 54px 44px;
  }

  .customer-table .table-row {
    grid-template-columns: minmax(58px, 1fr) 80px 42px 42px 50px 38px;
  }
}
