:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #172033;
  --muted: #667085;
  --primary: #1867c0;
  --primary-dark: #0f4d94;
  --danger: #b42318;
  --ok: #067647;
  --warn: #b54708;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding-bottom: 74px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.unified-body {
  padding-bottom: 0;
}

.unified-topbar {
  position: sticky;
}

.unified-switch {
  display: flex;
  gap: 8px;
  align-items: center;
}

.unified-switch button.active {
  background: var(--primary);
  color: #fff;
}

.unified-main {
  height: calc(100vh - 59px);
}

.unified-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
}

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

button {
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  background: var(--primary-dark);
}

button.secondary {
  background: #eef2f7;
  color: var(--text);
}

button.danger {
  background: var(--danger);
}

button:disabled {
  background: #aab4c3;
  cursor: not-allowed;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  min-height: 40px;
  padding: 8px 10px;
}

textarea {
  min-height: 74px;
  resize: vertical;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

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

.brand strong {
  font-size: 18px;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

.layout {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px 16px 38px;
}

.app-layout {
  padding-bottom: 24px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 14px;
}

.lookup-panel {
  margin-bottom: 14px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.order-shell {
  width: min(560px, 100%);
  margin: 0 auto;
}

.products {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 190px;
  padding: 14px;
}

.card h3,
.panel h2,
.panel h3 {
  margin: 0;
}

.card h3 {
  font-size: 17px;
}

.product-img {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
  background: #f1f4f8;
}

.product-img.placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #eef2f7;
  min-height: 24px;
  padding: 2px 8px;
}

.price {
  font-size: 22px;
  font-weight: 700;
}

.stock.ok {
  color: var(--ok);
}

.stock.warn {
  color: var(--warn);
}

.card.sold-out {
  opacity: 0.5;
  pointer-events: none;
}

.card.sold-out .product-img {
  filter: grayscale(0.35);
}

.lot-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.lot-option {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.panel {
  padding: 16px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.summary-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.summary-card strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
}

.sticky {
  position: sticky;
  top: 74px;
}

.cart-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 0;
}

.cart-inputs {
  display: flex;
  gap: 6px;
  align-items: center;
}
.cart-inputs label {
  font-size: 12px;
  color: var(--muted);
}
.cart-inputs input {
  width: 56px;
  padding: 4px 6px;
  font-size: 13px;
}
.cart-note-label {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.cart-note-label input {
  flex: 1;
  padding: 5px 8px;
  font-size: 13px;
}
.cart-row,
.admin-row,
.order-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px auto;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.product-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
#adminProducts {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
#adminProducts::-webkit-scrollbar {
  height: 10px;
}
#adminProducts::-webkit-scrollbar-track {
  background: #f1f4f8;
  border-radius: 5px;
}
#adminProducts::-webkit-scrollbar-thumb {
  background: #c5cad3;
  border-radius: 5px;
}
#adminProducts::-webkit-scrollbar-thumb:hover {
  background: #9ea4ae;
}
.product-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}
.product-table th {
  background: #f1f4f8;
  padding: 10px 8px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
.product-table td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.product-table td button {
  margin: 2px 4px 2px 0;
  font-size: 13px;
}
.product-table tbody tr:hover {
  background: #f8fafc;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
}
.badge-success { background: #ecfdf5; color: #065f46; }
.badge-danger { background: #fef2f2; color: #991b1b; }

.admin-edit-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.cart-row:last-child,
.admin-row:last-child,
.order-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.muted {
  color: var(--muted);
}

.total {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  margin-top: 12px;
  padding-top: 12px;
  font-size: 18px;
  font-weight: 700;
}

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

.form-grid .wide {
  grid-column: 1 / -1;
}

.variant-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 8px;
  margin-top: 8px;
  align-items: start;
}
.variant-image-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.variant-image-cell input[type="file"] {
  max-width: 96px;
}
.variant-fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.variant-fields-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 8px;
}

.lot-rows {
  display: grid;
  gap: 6px;
}

.lot-row {
  display: grid;
  grid-template-columns: minmax(70px, 0.5fr) minmax(90px, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.upload-preview {
  width: 100%;
  max-width: 220px;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
  background: #f1f4f8;
}

.status {
  min-height: 28px;
  margin: 10px 0;
  color: var(--muted);
}

.status.error {
  color: var(--danger);
}

.status.success {
  color: var(--ok);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.45);
}

.modal {
  width: min(520px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  border-radius: 8px;
  background: #fff;
  padding: 18px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.confirm-details {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.payment-modal {
  text-align: center;
}

.payment-qr {
  display: block;
  width: min(330px, 100%);
  max-height: 70vh;
  margin: 12px auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
  background: #fff;
  -webkit-touch-callout: default;
  user-select: auto;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
}

.tabs button {
  flex: 0 0 auto;
}

.bottom-tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 15;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  border-top: 1px solid var(--line);
  background: var(--line);
}

.bottom-tabs button {
  border-radius: 0;
  background: #fff;
  color: var(--text);
  min-height: 58px;
}

.bottom-tabs button.active {
  background: var(--primary);
  color: #fff;
}

.admin-list,
.orders {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    padding: 10px 14px;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .sticky {
    position: static;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .products {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .variant-row {
    grid-template-columns: 100%;
    gap: 6px;
  }
  .variant-image-cell {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }
  .variant-image-cell input[type="file"] {
    max-width: none;
    font-size: 11px;
  }
  .variant-fields-row {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .lot-row {
    grid-template-columns: 1fr 1fr;
  }

  .lot-row button {
    grid-column: 1 / -1;
  }

  .product-table th,
  .product-table td {
    padding: 6px 8px;
    font-size: 13px;
  }

  .cart-row,
  .admin-row,
  .order-row,
  .admin-edit-row {
    grid-template-columns: 1fr;
  }

  .modal-actions {
    grid-template-columns: 1fr;
  }
}

/* 图片显示修复 */
.variant-preview {
  width: 100%;
  max-width: 120px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #f1f4f8;
}
.variant-image-cell input[type="file"] {
  margin-top: 4px;
}
