:root {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app-shell {
  max-width: 1360px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  padding-bottom: 72px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 10px 14px;
  background: var(--ui-white);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-weak);
  color: var(--brand);
  font-size: 18px;
}

.page {
  padding: 14px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 20px 0 10px;
}

.section-title h2 {
  margin: 0;
  font-size: 17px;
}

.link-btn {
  background: transparent;
  color: var(--brand);
  padding: 4px 0;
}

.primary-btn,
.secondary-btn,
.danger-btn {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 600;
}

.primary-btn {
  background: var(--brand);
  color: var(--ui-white);
}

.secondary-btn {
  background: var(--brand-weak);
  color: var(--brand);
}

.danger-btn {
  border: 1px solid var(--ui-border-strong);
  background: var(--ui-white);
  color: var(--ui-text);
}

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

.list-card,
.form-card {
  border-radius: 8px;
  background: var(--panel);
  box-shadow: none;
}

.product-image {
  display: grid;
  place-items: center;
  width: 104px;
  height: 104px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--ui-white);
}

.image-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--ui-white);
}

.image-frame img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
}

.image-preview-trigger {
  padding: 0;
  border: 1px solid var(--line);
  color: inherit;
  cursor: zoom-in;
}

.image-placeholder {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  background: var(--ui-white);
}

.image-placeholder[hidden] {
  display: none;
}

.store-selector {
  position: relative;
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.store-selector-current,
.store-selector-option {
  display: grid;
  grid-template-columns: minmax(120px, 0.7fr) minmax(0, 1.3fr) 24px;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  color: var(--text);
  text-align: left;
  background: transparent;
}

.store-selector-current strong,
.store-selector-option strong,
.store-selector-address {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.store-selector-address {
  color: var(--muted);
  font-size: 13px;
}

.store-selector-chevron,
.store-selector-check {
  justify-self: end;
  color: var(--brand);
  font-size: 18px;
  font-weight: 600;
}

.store-selector-options {
  border-top: 1px solid var(--line);
}

.store-selector-option + .store-selector-option {
  border-top: 1px solid var(--line);
}

.store-selector-option:hover,
.store-selector-option.selected {
  background: var(--brand-weak);
}

.list-card h3 {
  margin: 0 0 6px;
  font-size: 15px;
  line-height: 1.35;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.field-label {
  display: block;
  margin: 10px 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.price {
  color: var(--accent);
  font-size: 17px;
  font-weight: 600;
}

.price-stack {
  display: grid;
  gap: 2px;
}

.quote-state {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 24px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.quote-spinner {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: quote-spin 0.8s linear infinite;
}

@keyframes quote-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .quote-spinner { animation: none; }
}

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

.input,
.select,
.textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.textarea {
  min-height: 78px;
  padding-top: 10px;
  resize: vertical;
}

.tabs,
.segmented {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.tab,
.chip {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--ui-white);
  color: var(--muted);
  border: 1px solid var(--line);
}

.tab.active,
.chip.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 2vh 2vw;
  background: var(--ui-overlay);
}

.image-lightbox-content {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 96vw;
  height: 96vh;
}

.image-lightbox-canvas {
  display: block;
  width: 100%;
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  cursor: grab;
  touch-action: none;
}

.image-lightbox-canvas.dragging {
  cursor: grabbing;
}

.image-lightbox-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 100%;
  min-height: 100%;
}

.image-lightbox-stage > img {
  flex: 0 0 auto;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  object-fit: contain;
  object-position: center;
  user-select: none;
}

.image-lightbox-stage > .image-placeholder {
  width: min(420px, 70vw);
  height: min(420px, 70vw);
}

.image-lightbox-toolbar {
  z-index: 2;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 0 56px 8px;
  pointer-events: none;
}

.image-lightbox-toolbar button {
  min-width: 42px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 6px;
  color: var(--ui-white);
  font-size: 18px;
  background: rgba(15, 21, 25, 0.72);
  pointer-events: auto;
}

.image-lightbox-close,
.image-lightbox-nav {
  position: absolute;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 50%;
  color: #fff;
  font-size: 30px;
  line-height: 1;
  background: rgba(15, 21, 25, 0.72);
}

.image-lightbox-close {
  top: 0;
  right: 0;
}

.image-lightbox-nav {
  top: 50%;
  transform: translateY(-50%);
}

.image-lightbox-nav.previous {
  left: 0;
}

.image-lightbox-nav.next {
  right: 0;
}

.image-lightbox-counter {
  position: absolute;
  bottom: 0;
  left: 50%;
  padding: 5px 9px;
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  background: rgba(15, 21, 25, 0.72);
  transform: translateX(-50%);
}

.list-card {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
  padding: 12px;
}

.cart-item {
  grid-template-columns: 72px minmax(0, 1fr) auto;
  align-items: center;
}

.cart-item-image {
  width: 72px;
  height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.checkout-item {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.checkout-item:last-child {
  border-bottom: 0;
}

.checkout-item-image {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.qty {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
}

.checkout-bar {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #fff;
  border-top: 1px solid var(--line);
}

.quantity-input {
  width: 72px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--ui-white);
  color: var(--text);
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
  appearance: textfield;
}

.quantity-input::-webkit-inner-spin-button,
.quantity-input::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
}

.checkout-summary,
.account-toggle {
  display: flex;
  align-items: center;
  gap: 14px;
}

.checkout-summary {
  min-width: 0;
  flex-wrap: wrap;
}

@media (max-width: 600px) {
  .checkout-bar {
    grid-template-columns: minmax(0, 1fr);
  }

  .checkout-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: start;
    gap: 8px;
  }

  .checkout-summary > div {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .checkout-summary .account-toggle {
    grid-column: 1 / -1;
  }

  .checkout-bar > .primary-btn {
    width: 100%;
    min-width: 0;
  }
}

.account-toggle {
  gap: 6px;
  font-weight: 700;
  white-space: nowrap;
}

.inline-state,
.pickup-location-static {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--ui-gray);
}

.pickup-location-static {
  align-items: flex-start;
  flex-direction: column;
}

.error-state {
  border-color: var(--ui-border-strong);
  background: var(--ui-white);
  color: var(--ui-text);
}

.form-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  margin-bottom: 12px;
}

.form-card h2 {
  margin: 0;
  font-size: 16px;
}

.order-detail-item,
.payment-record {
  display: grid;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.order-detail-item:last-of-type,
.payment-record:last-of-type {
  border-bottom: 0;
}

.order-detail-item {
  grid-template-columns: 56px minmax(0, 1fr) auto;
}

.order-detail-item-image {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--ui-white);
}

.order-detail-item-copy,
.payment-record-main,
.payment-record-amount {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.order-detail-item-copy strong,
.order-detail-item-copy span {
  overflow-wrap: anywhere;
}

.order-detail-item-amount,
.payment-record-amount {
  text-align: right;
}

.payment-record {
  grid-template-columns: minmax(0, 1fr) auto;
}

.compact-empty {
  min-height: 72px;
}

.radio-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.radio-card.active {
  border-color: var(--brand);
  background: var(--brand-weak);
}

.order-status {
  width: max-content;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--ui-gray);
  color: var(--ui-text);
  font-size: 12px;
  font-weight: 600;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(1360px, 100%);
  transform: translateX(-50%);
  background: #fff;
  border-top: 1px solid var(--line);
}

.bottom-nav button {
  min-height: 58px;
  padding: 6px 4px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.bottom-nav button.active {
  color: var(--brand);
  font-weight: 600;
}

.empty {
  padding: 34px 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  line-height: 1.5;
  text-align: center;
}

.pickup-store-state {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ui-gray);
  color: var(--muted);
  line-height: 1.5;
}

.pickup-store-state.error {
  border-color: var(--ui-border-strong);
  background: var(--ui-white);
  color: var(--ui-text);
}

.profile-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-radius: 8px;
  background: var(--panel);
}

.profile-info {
  flex: 1;
  min-width: 0;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stack {
  display: grid;
  gap: 10px;
}

.small {
  font-size: 12px;
}

.product-pagination {
  display: grid;
  grid-template-columns: auto auto auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 100%;
  margin: 18px auto 0;
}

.product-pagination .secondary-btn {
  min-width: 88px;
  white-space: nowrap;
}

.product-page-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  white-space: nowrap;
}

.product-page-selector {
  position: relative;
}

.product-page-selector-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 58px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-weight: 600;
}

.product-page-selector-button:hover,
.product-page-selector-button:focus-visible,
.product-page-selector-button[aria-expanded="true"] {
  border-color: var(--brand);
  outline: 2px solid var(--brand-weak);
  outline-offset: 1px;
}

.product-page-selector-caret {
  font-size: 11px;
}

.product-page-menu {
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  z-index: 20;
  width: 94px;
  max-width: calc(100vw - 24px);
  max-height: 280px;
  padding: 4px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(17, 17, 17, 0.14);
  transform: translateX(-50%);
}

.product-page-option {
  display: grid;
  grid-template-columns: 1fr 16px;
  align-items: center;
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
}

.product-page-option:hover,
.product-page-option:focus-visible {
  background: var(--ui-gray);
  outline: none;
}

.product-page-option.selected {
  font-weight: 600;
}

.login-page {
  display: grid;
  min-height: calc(100vh - 53px);
  place-items: center;
}

.login-panel {
  width: min(440px, 100%);
  padding: 24px;
}

.login-heading {
  margin-bottom: 6px;
}

.login-heading p {
  margin: 6px 0 0;
}

.auth-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.auth-browse-link {
  justify-self: center;
}

.address-row,
.address-editor,
.cart-subtotal {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.address-row {
  min-height: 42px;
  border-bottom: 1px solid var(--line);
}

.address-row > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.address-editor .secondary-btn {
  flex: 0 0 auto;
}

.cart-subtotal {
  justify-content: flex-start;
  margin-top: 6px;
}

.cart-subtotal .price-stack {
  grid-auto-flow: column;
  align-items: baseline;
  gap: 8px;
}

.app-toast {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 2000;
  width: min(440px, calc(100vw - 24px));
  padding: 12px 14px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 8px;
  background: var(--ui-black);
  color: var(--ui-white);
  line-height: 1.4;
  text-align: center;
  transform: translateX(-50%);
}

.app-toast.success {
  background: var(--ui-white);
  color: var(--ui-black);
}

.app-shell[data-route="cart"] .checkout-bar {
  bottom: 58px;
}

@media (max-width: 900px) {

  .product-image {
    width: 88px;
    height: 88px;
  }

  .store-selector-current,
  .store-selector-option {
    grid-template-columns: minmax(90px, 0.8fr) minmax(0, 1.2fr) 22px;
    gap: 8px;
  }

  .image-lightbox {
    padding: 12px;
  }

  .image-lightbox-content {
    width: 96vw;
    height: 88vh;
  }

  .order-detail-item {
    grid-template-columns: 52px minmax(0, 1fr);
  }

  .order-detail-item-image {
    width: 52px;
    height: 52px;
  }

  .order-detail-item-amount {
    grid-column: 2;
    text-align: left;
  }
}

@media (max-width: 360px) {

  .page {
    padding: 10px;
  }

  .product-image {
    width: 76px;
    height: 76px;
  }

  .product-pagination {
    gap: 5px;
  }

  .product-pagination .secondary-btn {
    min-width: 0;
    min-height: 38px;
    padding: 0 8px;
    font-size: 12px;
  }

  .product-page-status {
    gap: 4px;
    font-size: 12px;
  }

  .product-page-selector-button {
    width: 48px;
    height: 38px;
  }

  .bottom-nav button {
    font-size: 11px;
  }

  .cart-item {
    grid-template-columns: 62px minmax(0, 1fr) auto;
  }

  .cart-item-image {
    width: 62px;
    height: 62px;
  }

  .checkout-item {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .checkout-item-image {
    width: 44px;
    height: 44px;
  }

  .checkout-item .price-stack,
  .checkout-item > strong {
    grid-column: 2;
    justify-self: start;
  }
}
.topbar .back-to-user { display: inline-flex; align-items: center; gap: 6px; width: auto; min-width: 76px; min-height: 44px; padding: 8px 10px; flex-shrink: 0; border-radius: 7px; background: #fff; color: #111; font-size: 16px; }
.debt-summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 0; border-bottom: 1px solid #ccc; }
.debt-summary h2 { margin: 0; font-size: 18px; }
.debt-summary .price-stack { min-width: 0; overflow-wrap: anywhere; }
.checkout-identity { margin: 12px 0 20px; display: grid; gap: 12px; }
.checkout-identity > div { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 12px; }
.checkout-identity dt { color: var(--muted, #666); }
.checkout-identity dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
