:root {
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: #243331;
  background: #f4f6f8;
  font-size: 14px;
  --green: #16845c;
  --line: #e4e9ed;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
button,
input,
select,
textarea {
  font: inherit;
}
button,
a {
  touch-action: manipulation;
}
button,
.button {
  cursor: pointer;
  border: 1px solid #d9e0e4;
  border-radius: 6px;
  background: #fff;
  color: #35463f;
  padding: 9px 14px;
  text-decoration: none;
  display: inline-block;
}
button:hover,
.button:hover {
  border-color: var(--green);
  color: var(--green);
}
button:disabled {
  opacity: 0.5;
  cursor: wait;
}
.primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.primary:hover {
  background: #106b4a;
  color: #fff;
}
.danger {
  color: #b53535;
}
input,
select,
textarea {
  border: 1px solid #d6dfe3;
  border-radius: 5px;
  background: #fff;
  padding: 10px;
  width: 100%;
  color: inherit;
}
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #a3d5be;
  outline-offset: 1px;
}
label {
  display: block;
  color: #52635e;
  margin: 12px 0;
}
label input,
label select,
label textarea {
  display: block;
  margin-top: 7px;
}
aside {
  position: fixed;
  inset: 0 auto 0 0;
  width: 228px;
  background: #fff;
  border-right: 1px solid var(--line);
  z-index: 10;
}
.logo {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 25px 20px;
  font-size: 20px;
  font-weight: 700;
}
.logo small {
  display: block;
  font-size: 9px;
  letter-spacing: 1.2px;
  margin-top: 5px;
  color: #8a9995;
}
.brandmark {
  background: var(--green);
  color: white;
  border-radius: 10px;
  font-size: 25px;
  padding: 8px 12px;
  display: inline-block;
}
nav {
  padding: 10px 12px;
}
nav button {
  display: flex;
  gap: 15px;
  text-align: left;
  width: 100%;
  margin: 4px 0;
  padding: 13px 17px;
  border: 0;
  background: transparent;
  color: #61716b;
}
nav button.active {
  background: #e7f5ee;
  color: #128056;
  font-weight: 600;
}
nav button span {
  width: 20px;
  text-align: center;
}
.sidebar-bottom {
  position: absolute;
  bottom: 24px;
  left: 30px;
  color: #81918a;
  line-height: 1.9;
}
.workspace {
  margin-left: 228px;
}
header {
  height: 76px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
header > div {
  font-size: 12px;
  color: #65746f;
}
.inline {
  display: inline;
  margin-left: 10px;
}
.tag,
.badge {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  background: #e9f5ef;
  color: #258362;
  margin-left: 8px;
}
.warn {
  background: #fff3df;
  color: #ab6a1c;
}
.muted {
  color: #89968f;
  line-height: 1.7;
}
main {
  padding: 28px 32px;
  max-width: 1800px;
  margin: auto;
}
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  margin-bottom: 24px;
}
h1 {
  font-size: 24px;
  margin: 0 0 7px;
  font-weight: 650;
}
h2 {
  font-size: 17px;
  margin: 0 0 18px;
}
p {
  line-height: 1.6;
}
.page-head p {
  margin: 0;
  color: #81908a;
}
.cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.card,
.panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 9px;
}
.card {
  padding: 22px;
}
.card small {
  color: #7b8a84;
}
.card strong {
  display: block;
  font-size: 30px;
  margin: 14px 0 4px;
  font-weight: 600;
}
.card:last-child strong {
  color: #d08b2f;
}
.panel {
  padding: 22px;
  margin-bottom: 20px;
}
.quick {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  align-items: center;
}
.toolbar input {
  width: 230px;
}
.toolbar select {
  width: 150px;
}
.toolbar input[type="date"],
.toolbar input[type="number"] {
  width: 150px;
}
.table-wrap {
  overflow: auto;
}
table {
  border-collapse: collapse;
  width: 100%;
  white-space: nowrap;
  text-align: left;
  font-size: 13px;
}
th {
  background: #f6f8fa;
  color: #718079;
  font-weight: 500;
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
}
td {
  padding: 14px 12px;
  border-bottom: 1px solid #eef1f3;
}
tr:hover td {
  background: #fafcfb;
}
td img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 5px;
  vertical-align: middle;
  margin-right: 10px;
}
.number {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}
.pagination {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
  align-items: center;
  margin-top: 18px;
}
.empty {
  text-align: center;
  padding: 55px;
  color: #8b9892;
}
.error {
  color: #b93636;
  background: #fff0ef;
  padding: 12px;
  border-radius: 6px;
  white-space: pre-wrap;
}
.info {
  background: #eff7f3;
  padding: 14px;
  border-radius: 6px;
  color: #4a725f;
  line-height: 1.7;
}
.mobile {
  display: none;
}
footer {
  padding: 10px 32px 24px;
  color: #9ba8a1;
  font-size: 12px;
}
dialog {
  border: 0;
  border-radius: 12px;
  padding: 26px;
  width: min(760px, 94vw);
  max-height: 90vh;
  box-shadow: 0 24px 80px #0003;
}
dialog::backdrop {
  background: #19372d66;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 18px;
}
.full {
  grid-column: 1/-1;
}
.actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}
.scan-input {
  font-size: 19px;
  max-width: 480px;
}
.scan-layout {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 2fr;
  gap: 20px;
}
video {
  width: 100%;
  max-height: 320px;
  background: #112c23;
  border-radius: 8px;
}
#cart input {
  width: 100px;
}
.scan-product {
  white-space: normal;
  min-width: 180px;
}
.scan-product small {
  display: block;
  color: #88988f;
}
.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: linear-gradient(130deg, #e6f2eb, #f6f8fa);
}
.login-card {
  background: white;
  border: 1px solid #e0e9e3;
  box-shadow: 0 12px 50px #254c2d0a;
  border-radius: 14px;
  padding: 38px;
  width: min(430px, 94vw);
}
.login-card h1 {
  font-size: 23px;
  margin-top: 20px;
}
.login-card h2 {
  margin-top: 32px;
}
.login-card button {
  width: 100%;
  margin-top: 15px;
}
#toast {
  position: fixed;
  bottom: 25px;
  left: 50%;
  transform: translateX(-50%);
  background: #183e30;
  color: white;
  border-radius: 8px;
  padding: 14px 25px;
  z-index: 100;
  display: none;
  max-width: 90vw;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.detail-grid img {
  width: 140px;
}
.subtle {
  font-size: 12px;
  color: #7f8f86;
}
.nowrap {
  white-space: nowrap;
}
.dirty {
  color: #b16f19;
}
.loading {
  padding: 60px;
  text-align: center;
  color: #759080;
}
@media (max-width: 1200px) {
  .cards {
    grid-template-columns: repeat(3, 1fr);
  }
  .scan-layout {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 760px) {
  aside {
    transform: translateX(-100%);
    transition: transform 0.15s;
  }
  .nav-open aside {
    transform: translateX(0);
  }
  .workspace {
    margin-left: 0;
  }
  header {
    height: auto;
    min-height: 64px;
    padding: 12px 14px;
  }
  header > span {
    display: none;
  }
  .mobile {
    display: block;
  }
  main {
    padding: 22px 14px;
  }
  .cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .card {
    padding: 16px;
  }
  .card strong {
    font-size: 27px;
  }
  .panel {
    padding: 15px;
  }
  .page-head {
    align-items: flex-start;
  }
  .page-head h1 {
    font-size: 22px;
  }
  .form-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }
  .toolbar input,
  .toolbar select {
    width: 100%;
  }
  .scan-layout {
    display: block;
  }
  .scan-input {
    max-width: none;
  }
  td,
  th {
    padding: 12px 9px;
  }
  dialog {
    padding: 20px;
  }
  .sidebar-bottom {
    position: static;
    padding: 20px;
  }
  .actions {
    position: static;
    background: white;
    padding: 10px 0;
  }
  footer {
    padding-left: 15px;
  }
}

.unknown-row {
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}
.unknown-row p {
  margin: 0 0 8px;
}

.transaction-product {
  min-width: 220px;
  white-space: normal;
  padding: 7px 0;
}
.transaction-product + .transaction-product {
  border-top: 1px solid var(--line);
}
.transaction-product strong {
  font-weight: 500;
}
.transaction-product .number {
  margin-left: 16px;
}
.transaction-product small {
  display: block;
  margin-top: 5px;
}

.product-image-trigger {
  padding: 0;
  border: 1px solid var(--line);
  background: white;
  cursor: zoom-in;
  border-radius: 6px;
  overflow: hidden;
  vertical-align: middle;
}
td .product-image-trigger img {
  display: block;
  width: 48px;
  height: 48px;
  margin: 0;
  border: 0;
  border-radius: 0;
  object-fit: contain;
}
.product-image-preview {
  position: fixed;
  z-index: 100;
  width: min(340px, calc(100vw - 24px));
  padding: 10px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 35px #0003;
  cursor: zoom-out;
}
.product-image-preview[hidden] {
  display: none;
}
.product-image-preview img {
  display: block;
  width: 100%;
  height: min(300px, calc(100vh - 100px));
  object-fit: contain;
}
.product-image-preview span {
  display: block;
  text-align: center;
  color: #81908a;
  font-size: 12px;
  margin-top: 8px;
}

#results .product-image-trigger {
  margin-right: 10px;
}

.interactive-table {
  table-layout: fixed;
  min-width: 0;
}
.interactive-table th {
  position: relative;
  padding: 0;
  border-right: 1px solid #d6dfe3;
}
.interactive-table td {
  border-right: 1px solid #e4e9ed;
  overflow: hidden;
  text-overflow: ellipsis;
}
.table-sort {
  width: 100%;
  display: block;
  text-align: left;
  padding: 14px 25px 14px 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.table-sort:hover {
  background: #e9f3ed;
  color: #16845c;
}
.table-sort::after {
  content: "↕";
  position: absolute;
  right: 10px;
  color: #a1afa7;
  font-size: 11px;
}
th[aria-sort="ascending"] .table-sort::after {
  content: "▲";
  color: #16845c;
}
th[aria-sort="descending"] .table-sort::after {
  content: "▼";
  color: #16845c;
}
.column-resize {
  position: absolute;
  top: 0;
  bottom: 0;
  right: -3px;
  width: 7px;
  cursor: col-resize;
  touch-action: none;
  z-index: 2;
}
.column-resize:hover,
.column-resize:focus {
  background: #16845c66;
  outline: none;
}
.resizing-column {
  cursor: col-resize;
  user-select: none;
}

.interactive-table th.table-static {
  padding: 14px 12px;
}

.product-upload-preview {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 8px 0 16px;
}
.product-upload-preview img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafcfb;
}
.product-upload-preview img[hidden] {
  display: none;
}

.transaction-item-cell {
  height: 36px;
  line-height: 22px;
  padding: 7px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.transaction-item-cell + .transaction-item-cell {
  border-top: 1px solid var(--line);
}

.stock-sheet {
  background: #fff;
  border: 1px solid #dce3e9;
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 235px);
  overflow: hidden;
  min-width: 0;
}
.stock-sheet-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}
.stock-sheet-title h2 {
  font-size: 20px;
  font-weight: 500;
  margin: 0;
  white-space: nowrap;
}
.stock-document-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  color: #6b7a74;
  font-size: 12px;
}
.stock-document-meta strong {
  font-weight: 400;
  color: #98a39d;
}
.stock-draft-tag {
  background: #fff6dc;
  color: #a17b25;
  padding: 5px 12px;
  border-radius: 4px;
  white-space: nowrap;
}
.stock-sheet-meta {
  display: grid;
  grid-template-columns: minmax(300px, 2.2fr) minmax(180px, 1fr) minmax(
      140px,
      0.8fr
    );
  gap: 12px;
  padding: 12px 16px;
  background: #f6f8fa;
  border-bottom: 1px solid var(--line);
}
.stock-sheet-meta label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  white-space: nowrap;
  font-size: 12px;
}
.stock-sheet-meta input,
.stock-sheet-meta textarea {
  margin: 0;
  resize: vertical;
  min-height: 36px;
  height: 36px;
  font-size: 12px;
  padding: 8px;
}
.stock-sheet-meta input[readonly] {
  background: #fff;
  color: #66756c;
}
.stock-sheet-tools {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.stock-sheet-tools form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 0 1 auto;
  min-width: 0;
}
.stock-tool-label {
  font-size: 12px;
  color: #6c7e74;
  white-space: nowrap;
}
.stock-sheet-tools input {
  width: 230px;
  min-width: 0;
  padding: 9px;
  font-size: 13px;
}
.stock-sheet-tools #search-form input {
  width: 255px;
}
.stock-sheet-tools button {
  white-space: nowrap;
  font-size: 12px;
  padding: 9px 12px;
}
.stock-camera-tools {
  display: flex;
  gap: 6px;
  margin-left: auto;
}
.stock-sheet-feedback:empty,
.stock-search-results:empty {
  display: none;
}
.stock-sheet-feedback {
  padding: 0 16px;
}
.stock-sheet-feedback p {
  margin: 8px 0;
}
.stock-search-results {
  padding: 8px 16px;
  background: #f8fbf9;
  border-bottom: 1px solid var(--line);
  max-height: 230px;
  overflow: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
}
.stock-search-results p {
  margin: 4px 0;
}
.stock-camera-panel {
  padding: 12px 16px;
  max-width: 480px;
}
.stock-camera-panel[hidden] {
  display: none;
}
.stock-sheet-grid {
  flex: 1;
  min-height: 330px;
  min-width: 0;
}
.stock-sheet-grid .table-wrap {
  width: 100%;
}
.stock-sheet-grid th {
  background: #eaf2fa;
  color: #3d5266;
}
.stock-sheet-grid td {
  font-size: 12px;
  padding: 10px;
}
.stock-sheet-grid .table-sort {
  padding: 12px 22px 12px 10px;
}
.stock-sheet-grid td.stock-sheet-empty {
  text-align: center;
  height: 200px;
  color: #96a19c;
  background: #fff;
}
.stock-sheet-grid td img {
  margin: 0;
}
.stock-sheet-grid td .product-image-trigger img {
  width: 40px;
  height: 40px;
}
.stock-sheet-summary {
  display: flex;
  gap: 28px;
  align-items: center;
  background: #fffbeb;
  padding: 12px 18px;
  border-top: 1px solid #ede6c8;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.stock-sheet-summary b {
  margin-left: 10px;
  font-size: 16px;
}
.stock-sheet-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  gap: 15px;
}
.stock-sheet-bottom .actions {
  margin: 0;
  padding: 0;
}
.stock-sheet .error {
  margin: 10px 16px;
}
@media (max-width: 1200px) {
  .stock-sheet-meta {
    grid-template-columns: 1fr 1fr;
  }
  .stock-sheet-meta label:first-child {
    grid-column: 1/-1;
  }
  .stock-camera-tools {
    margin-left: 0;
  }
  .stock-sheet-title {
    flex-wrap: wrap;
  }
  .stock-document-meta {
    order: 3;
    width: 100%;
  }
}
@media (max-width: 760px) {
  .stock-sheet {
    min-height: calc(100vh - 190px);
  }
  .stock-sheet-title {
    padding: 14px;
  }
  .stock-sheet-title h2 {
    font-size: 19px;
  }
  .stock-sheet-meta {
    grid-template-columns: 1fr;
    padding: 12px;
  }
  .stock-sheet-meta label:first-child {
    grid-column: auto;
  }
  .stock-sheet-tools {
    padding: 12px;
    gap: 10px;
  }
  .stock-sheet-tools form {
    width: 100%;
  }
  .stock-sheet-tools input,
  .stock-sheet-tools #search-form input {
    width: 0;
    flex: 1;
  }
  .stock-sheet-tools button {
    padding: 9px;
  }
  .stock-sheet-grid {
    min-height: 260px;
  }
  .stock-sheet-bottom {
    flex-direction: column;
    align-items: stretch;
    padding: 12px;
  }
  .stock-sheet-bottom .actions {
    justify-content: flex-end;
  }
  .stock-sheet-summary {
    gap: 15px;
    flex-wrap: wrap;
    padding: 12px;
  }
  .stock-sheet-summary b {
    font-size: 14px;
    margin-left: 6px;
  }
  .stock-document-meta {
    font-size: 11px;
  }
  .stock-camera-tools {
    flex-wrap: wrap;
  }
}

.stock-sheet-grid > .stock-sheet-empty {
  min-height: 200px;
  display: grid;
  place-content: center;
  text-align: center;
  color: #96a19c;
  padding: 25px;
  line-height: 1.9;
}

.stock-row-actions {
  white-space: nowrap;
}
.stock-row-actions button {
  padding: 2px 4px;
  border: 0;
  background: transparent;
  color: #2276bd;
  font-size: 18px;
  line-height: 26px;
}
.stock-row-actions button:hover {
  background: #d9eafa;
}
.stock-entry-row td {
  background: #edf5ff !important;
}
.stock-sheet-grid .stock-entry-row input {
  width: 100% !important;
  min-width: 0;
  border: 1px solid transparent;
  background: transparent;
  padding: 7px 4px;
  border-radius: 3px;
  font-size: 12px;
}
.stock-sheet-grid .stock-entry-row input:focus {
  background: #fff;
  border-color: #7db7e7;
  outline: 1px solid #7db7e7;
}
.stock-entry-row input::placeholder {
  color: #8d9fae;
}
.stock-entry-help {
  color: #8c9d94;
  text-align: center;
  padding: 25px 15px;
  font-size: 12px;
}

.stock-sheet-grid td.stock-row-actions {
  padding: 4px;
}

.stock-row-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  color: #2276bd;
  background: transparent;
  line-height: 1;
}
.stock-row-actions button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  pointer-events: none;
}
.stock-row-actions button:hover,
.stock-row-actions button:focus-visible {
  background: #d9eafa;
  color: #2276bd;
}

.transaction-list-table .transaction-item-cell {
  height: 56px;
  display: flex;
  align-items: center;
  padding: 6px 0;
  line-height: 20px;
}
.transaction-list-table .transaction-image-cell .product-image-trigger {
  margin: 0 !important;
}
.transaction-list-table .transaction-image-cell .product-image-trigger img {
  width: 42px;
  height: 42px;
}

/* Camera scanning is available in the mobile layout only. */
@media (min-width: 761px) {
  .stock-camera-tools,
  .stock-camera-panel {
    display: none;
  }
}

/* Keep each table's data inside its own scrolling region. */
.table-wrap {
  max-height: 60dvh;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.table-wrap th,
.table-wrap .interactive-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  box-shadow: inset 0 -1px 0 var(--line);
}
dialog .table-wrap {
  max-height: 45dvh;
}
dialog:has(.batch-dialog-content) {
  width: min(1400px, 96vw);
}
@media (min-width: 761px) and (min-height: 650px) {
  body.table-workspace {
    height: 100dvh;
    overflow: hidden;
  }
  .table-workspace .workspace {
    height: 100dvh;
    display: flex;
    flex-direction: column;
  }
  .table-workspace .workspace > header {
    flex-shrink: 0;
  }
  .table-workspace .workspace > footer {
    flex-shrink: 0;
    padding: 6px 32px 10px;
  }
  .table-workspace main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    width: 100%;
    margin: 0 auto;
    padding-bottom: 12px;
  }
  .table-workspace .page-head,
  .table-workspace main > .info {
    flex-shrink: 0;
  }
  .table-workspace main > .panel,
  .table-workspace .stock-sheet {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    margin-bottom: 0;
  }
  .table-workspace .panel > :not(#results):not(#count-rows):not(.table-wrap) {
    flex-shrink: 0;
  }
  .table-workspace #results,
  .table-workspace #count-rows,
  .table-workspace .stock-sheet-grid {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    min-width: 0;
  }
  .table-workspace #results > .table-wrap,
  .table-workspace #count-rows > .table-wrap,
  .table-workspace .stock-sheet-grid > .table-wrap,
  .table-workspace .panel > .table-wrap {
    flex: 1;
    min-height: 0;
    max-height: none;
  }
  .table-workspace .pagination {
    flex-shrink: 0;
  }
  .table-workspace .stock-sheet > :not(.stock-sheet-grid) {
    flex-shrink: 0;
  }
  .table-workspace #count-matches .table-wrap {
    max-height: 140px;
  }
  .table-workspace .stock-search-results {
    max-height: 120px;
  }
}

.interactive-table th[draggable="true"] { cursor: grab; }
.interactive-table th.column-dragging { opacity: 0.5; }
.interactive-table th.column-drop-target { box-shadow: inset 4px 0 #16845c; }
