:root {
  color-scheme: light;
  --bg: #f1f5f8;
  --surface: #ffffff;
  --surface-strong: #f5f8fb;
  --ink: #172033;
  --muted: #778596;
  --line: #dce4ec;
  --accent: #2f6fec;
  --accent-strong: #1f56c7;
  --warm: #ed7545;
  --danger: #b33d38;
  --gold: #9a6a2f;
  --edge-line: #555b61;
  --shadow: 0 14px 36px rgba(33, 52, 79, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-size: 16px;
  min-height: 100vh;
  min-height: 100dvh;
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.app-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 20px;
  padding: max(18px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 18px max(24px, env(safe-area-inset-left));
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 0;
  box-shadow: 0 3px 14px rgba(33, 52, 79, 0.06);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-topbar::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--edge-line);
  pointer-events: none;
}

.brand {
  grid-column: 2;
  justify-self: center;
  display: flex;
  align-items: center;
  min-width: 0;
}

.brand-mark {
  display: block;
  flex: 0 0 auto;
  width: 118px;
  height: 40px;
  object-fit: contain;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  font-weight: 700;
}

h2 {
  font-size: 18px;
  font-weight: 700;
}

p {
  color: var(--muted);
  line-height: 1.5;
}

.top-actions,
.stage-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.top-actions {
  grid-column: 3;
  justify-self: end;
}

.button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease, color 140ms ease;
  white-space: nowrap;
}

.button:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.button.primary:hover {
  background: var(--accent-strong);
}

.button.secondary {
  background: var(--surface-strong);
}

.button.danger {
  border-color: #cda29b;
  color: #9d392f;
  background: #fff8f6;
}

.button.danger:hover {
  border-color: #9d392f;
  background: #fff1ee;
}

.button.compact {
  min-height: 36px;
  padding: 0 12px;
}

#favoriteTryOnButton {
  border-color: #b9cdf7;
  color: var(--accent);
}

#favoriteTryOnButton[data-saved="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.tryon-social-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.share-link-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  min-width: 36px;
  padding: 0;
  border-color: #b9cdf7;
  color: var(--accent);
}

.share-link-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.stage-catalog-button {
  border-color: #b9cdf7;
  background: #edf3ff;
  color: var(--accent);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(320px, 430px);
  grid-template-areas:
    "stage catalog"
    "controls catalog"
    "package catalog";
  gap: 20px;
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 20px 24px 28px;
  align-items: start;
}

.site-footer {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 0 24px 28px;
  text-align: center;
}

.app-downloads {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}

.app-downloads[hidden] {
  display: none;
}

.app-download-action {
  min-height: 36px;
  border: 1px solid #b9cdf7;
  border-radius: 8px;
  background: #ffffff;
  color: var(--accent);
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 18px;
  text-decoration: none;
  cursor: pointer;
}

.app-download-action:hover,
.app-download-action:focus-visible {
  border-color: var(--accent);
  background: var(--surface-strong);
}

.app-download-action[hidden] {
  display: none;
}

.site-footer p {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.site-footer a {
  color: inherit;
  text-decoration: none;
}

.site-footer a:hover,
.site-footer a:focus-visible {
  color: var(--accent);
  text-decoration: underline;
}

.workspace,
.catalog {
  min-width: 0;
}

.workspace {
  display: grid;
  gap: 14px;
  grid-area: stage;
}

.stage-header,
.catalog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.stage-option-pickers {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px 18px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  container-type: inline-size;
}

.stage-color-picker,
.stage-size-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stage-color-picker {
  --stage-swatch-size: 30px;
  --stage-color-gap: 7px;
  flex: 0 1 auto;
  min-width: calc((var(--stage-swatch-size) * 4) + (var(--stage-color-gap) * 3) + 4px + 26px + 10px);
}

.stage-size-picker {
  flex: 1 1 0;
}

.stage-color-picker[hidden],
.stage-size-picker[hidden] {
  display: none;
}

.stage-color-options,
.product-color-options,
.stage-size-options,
.product-size-options {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.stage-color-options,
.stage-size-options {
  flex: 1 1 auto;
  overflow-x: auto;
  padding: 2px;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
}

.stage-color-options {
  gap: var(--stage-color-gap, 7px);
  min-width: calc((var(--stage-swatch-size, 30px) * 4) + (var(--stage-color-gap, 7px) * 3) + 4px);
}

.stage-color-options::-webkit-scrollbar,
.stage-size-options::-webkit-scrollbar {
  display: none;
}

.size-option-button {
  min-width: 58px;
  height: 30px;
  flex: 0 0 auto;
  padding: 0 10px;
  border: 1px solid #d4dde7;
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.size-option-button:hover {
  border-color: #8eabd9;
  color: var(--accent);
}

.size-option-button[data-selected="true"] {
  border-color: var(--accent);
  background: #edf3ff;
  color: var(--accent);
  box-shadow: 0 0 0 2px rgba(47, 111, 236, 0.12);
}

.size-option-button:focus-visible {
  outline: 3px solid rgba(47, 111, 236, 0.2);
  outline-offset: 2px;
}

.color-swatch-button {
  position: relative;
  width: var(--stage-swatch-size, 30px);
  height: var(--stage-swatch-size, 30px);
  flex: 0 0 var(--stage-swatch-size, 30px);
  padding: 0;
  border: 2px solid #d4dde7;
  border-radius: 50%;
  background: var(--swatch-color, #151716);
  box-shadow: inset 0 0 0 2px #fff;
  cursor: pointer;
}

.color-swatch-button[data-loading="true"] {
  cursor: progress;
}

.color-swatch-button[data-loading="true"]::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: swatch-loading-spin 0.7s linear infinite;
}

.size-option-button[data-loading="true"] {
  cursor: progress;
  opacity: 0.72;
}

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

.color-swatch-button:hover {
  border-color: #8eabd9;
}

.color-swatch-button[data-selected="true"] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px #fff, 0 0 0 2px rgba(47, 111, 236, 0.18);
}

.color-swatch-button:focus-visible {
  outline: 3px solid rgba(47, 111, 236, 0.2);
  outline-offset: 2px;
}

@container (max-width: 460px) {
  .stage-option-pickers {
    gap: 8px 12px;
  }

  .stage-color-picker {
    --stage-swatch-size: 26px;
    --stage-color-gap: 5px;
    gap: 7px;
  }

  .stage-size-picker {
    gap: 7px;
  }

  .stage-color-options,
  .stage-size-options {
    gap: 5px;
  }
}

@container (max-width: 360px) {
  .stage-option-pickers {
    gap: 6px 8px;
  }

  .stage-color-picker {
    --stage-swatch-size: 22px;
    --stage-color-gap: 4px;
    gap: 5px;
  }

  .stage-size-picker {
    gap: 5px;
  }

  .stage-color-options,
  .stage-size-options {
    gap: 4px;
  }

  .stage-size-picker .size-option-button {
    min-width: 50px;
    padding: 0 7px;
  }
}

.library-progress {
  margin-top: 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.library-progress[data-complete="false"] {
  color: #8a5b10;
}

.tracking-state,
.tracking-toggle {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.tracking-state {
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.tracking-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: #b88b39;
}

.tracking-state[data-state="ready"] .tracking-dot {
  background: var(--accent);
}

.tracking-state[data-state="active"] .tracking-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(47, 111, 236, 0.14);
}

.tracking-state[data-state="warning"] .tracking-dot {
  background: #b88b39;
  box-shadow: 0 0 0 4px rgba(184, 139, 57, 0.14);
}

.tracking-state[data-state="error"] .tracking-dot {
  background: #b6493d;
}

.tracking-toggle {
  cursor: pointer;
  white-space: nowrap;
}

.tracking-toggle input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 28, 25, 0.52);
}

.modal-backdrop[hidden] {
  display: none;
}

.confirm-modal {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 20px;
}

.confirm-modal p {
  margin-top: 8px;
}

.ios-install-modal {
  width: min(480px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ios-install-head {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.ios-install-head img {
  width: 56px;
  height: 56px;
  border-radius: 8px;
}

.ios-install-head h2 {
  font-size: 18px;
}

.ios-install-head p {
  margin-top: 3px;
  font-size: 13px;
}

.ios-install-steps {
  display: grid;
  gap: 16px;
  margin: 0;
  padding: 18px 18px 8px;
  list-style: none;
}

.ios-install-steps li {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.ios-install-steps li > span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #edf3ff;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.ios-install-steps strong {
  display: block;
  line-height: 28px;
}

.ios-install-steps p {
  margin-top: 2px;
  font-size: 13px;
  line-height: 1.55;
}

.ios-install-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px 18px 0;
}

.ios-install-actions .button[hidden] {
  display: none;
}

.ios-install-actions .button:only-child,
#shareIosInstallButton[hidden] + #copyIosInstallLinkButton {
  grid-column: 1 / -1;
}

.ios-install-status {
  min-height: 38px;
  margin: 0;
  padding: 8px 18px 14px;
  color: var(--accent);
  font-size: 13px;
  text-align: center;
}

.tryon-favorites-modal {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(760px, 100%);
  max-height: calc(100dvh - 40px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tryon-favorites-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.tryon-favorites-head p {
  margin-top: 3px;
  font-size: 13px;
}

.favorite-close-button {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.favorite-close-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tryon-favorites-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  overflow-y: auto;
  padding: 16px;
  overscroll-behavior: contain;
}

.tryon-favorite-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.tryon-favorite-card img {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 11;
  object-fit: cover;
  background: #e9eef3;
}

.tryon-favorite-details {
  display: grid;
  gap: 5px;
  padding: 10px;
}

.tryon-favorite-details h3 {
  overflow: hidden;
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tryon-favorite-details p {
  overflow: hidden;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tryon-favorite-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 4px;
}

.tryon-favorite-actions .button {
  min-width: 0;
  min-height: 36px;
  padding: 0 6px;
  font-size: 12px;
}

.tryon-favorites-empty {
  grid-column: 1 / -1;
  padding: 44px 12px;
  text-align: center;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.canvas-wrap {
  background: #202624;
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 420px;
}

#tryonCanvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100vh - 260px);
  min-height: 420px;
  object-fit: contain;
  touch-action: none;
  cursor: grab;
}

#tryonCanvas:active {
  cursor: grabbing;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
  padding: 14px;
}

.control-panel {
  grid-area: controls;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.control-panel > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

.control-panel > summary::-webkit-details-marker {
  display: none;
}

.control-panel > summary::after {
  content: "+";
  flex: 0 0 auto;
  color: var(--accent-strong);
  font-size: 22px;
  font-weight: 400;
}

.control-panel[open] > summary::after {
  content: "−";
}

.control-panel > summary small {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.control-panel[open] > summary {
  border-bottom: 1px solid var(--line);
}

.control {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.control span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.control strong {
  color: var(--ink);
  font-weight: 700;
}

.measurement-calibration {
  display: grid;
  gap: 11px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
  background: #fbfcfe;
}

.measurement-calibration-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.measurement-calibration-head > strong {
  color: var(--ink);
  font-size: 14px;
}

#scaleCalibrationStatus {
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid #d6dde6;
  border-radius: 6px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
  text-align: right;
}

#scaleCalibrationStatus[data-state="calibrated"] {
  border-color: #a9c4fa;
  background: #edf3ff;
  color: var(--accent-strong);
}

#scaleCalibrationStatus[data-state="error"] {
  border-color: #efb7b4;
  background: #fff5f4;
  color: var(--danger);
}

.measurement-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 220px));
  gap: 10px;
}

.measurement-field {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.measurement-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
}

.measurement-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(47, 111, 236, 0.1);
}

.measurement-input:has(input[aria-invalid="true"]) {
  border-color: var(--danger);
}

.measurement-input input {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  padding: 0 10px;
  font: inherit;
  font-weight: 700;
}

.measurement-input input::placeholder {
  color: #98a4b3;
  font-weight: 400;
}

.measurement-input em {
  padding-right: 10px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.ai-panel {
  display: grid;
  grid-area: ai;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.ai-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.consent-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--muted);
  line-height: 1.5;
}

.consent-row input {
  margin-top: 5px;
  accent-color: var(--accent);
}

.ai-result {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  overflow: hidden;
}

.ai-result img {
  display: block;
  width: 100%;
  height: auto;
}

.catalog {
  display: grid;
  grid-area: catalog;
  grid-template-rows: auto auto minmax(220px, 1fr) auto auto;
  gap: 16px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  max-height: calc(100vh - 112px);
  position: sticky;
  top: 82px;
}

.package-panel {
  grid-area: package;
  overflow: hidden;
  border: 1px solid #e2e9f0;
  border-radius: 8px;
  background: var(--surface);
}

.package-panel > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 12px;
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

.package-panel > summary::-webkit-details-marker {
  display: none;
}

.package-panel > summary small {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.package-panel > summary::after {
  content: "+";
  flex: 0 0 auto;
  color: var(--accent-strong);
  font-size: 22px;
  font-weight: 400;
}

.package-panel[open] > summary {
  border-bottom: 1px solid var(--line);
}

.package-panel[open] > summary::after {
  content: "−";
}

.package-content {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #fbfcfe;
}

.package-content p {
  margin: 0;
}

.package-offer {
  padding: 10px 11px;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  background: #edf3ff;
  color: #536276;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.package-offer strong {
  color: var(--ink);
}

.catalog-filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border: 1px solid #e2e9f0;
  border-radius: 8px;
  background: var(--surface);
}

.filter-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.filter-field > span,
.filter-reset-field > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.filter-reset-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.filter-reset-field button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.filter-reset-field button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.filter-field input,
.filter-field select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f9fc;
  color: var(--ink);
  padding: 0 12px;
}

.filter-field input {
  min-width: 0;
}

.search-field {
  grid-column: 1 / -1;
}

.filter-field input:focus,
.filter-field select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(47, 111, 236, 0.12);
}

.frame-uploader {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 12px;
}

.uploader-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
}

.frame-uploader[open] .uploader-content {
  margin-top: 10px;
}

.uploader-title h3 {
  margin: 0;
  font-size: 15px;
}

.uploader-title span {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.uploader-content {
  display: grid;
  gap: 10px;
}

.uploader-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.uploader-tabs button {
  min-height: 36px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
}

.uploader-tabs button:last-child {
  border-right: 0;
}

.uploader-tabs button[aria-selected="true"] {
  background: var(--ink);
  color: white;
}

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

.upload-form[hidden] {
  display: none;
}

.upload-field {
  display: grid;
  gap: 5px;
}

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

.upload-form input,
.upload-form select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 10px;
}

.upload-form .button {
  width: 100%;
}

.upload-form #frameImageButton,
.upload-form #addFrameButton {
  grid-column: 1 / -1;
}

.purchase-url-field {
  grid-column: 1 / -1;
}

.frame-quality {
  grid-column: 1 / -1;
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.frame-quality[data-state="good"] {
  color: var(--accent-strong);
}

.frame-quality[data-state="warning"] {
  color: #8a5b10;
}

.frame-quality[data-state="error"] {
  color: var(--danger);
}

.batch-upload {
  display: grid;
  gap: 10px;
}

.batch-upload[hidden] {
  display: none;
}

.batch-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}

.batch-actions .button,
.batch-upload > .button {
  width: 100%;
}

.batch-file-state {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 12px;
  color: var(--muted);
  font-size: 13px;
}

.batch-upload progress {
  width: 100%;
  height: 8px;
  accent-color: var(--accent);
}

.batch-summary {
  min-height: 20px;
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
}

.batch-issues {
  max-height: 120px;
  margin: 0;
  overflow: auto;
  padding-left: 20px;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.5;
}

.batch-issues li[data-tone="warning"] {
  color: #8a5b10;
}

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

.fit-summary div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-strong);
}

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

.fit-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 15px;
}

#frameFitStat[data-fit="good"] strong {
  color: var(--accent-strong);
}

#frameFitStat[data-fit="large"] strong,
#frameFitStat[data-fit="small"] strong {
  color: var(--danger);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  overflow: auto;
  padding: 2px 4px 8px 2px;
}

.catalog-state {
  grid-column: 1 / -1;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 12px;
  color: var(--muted);
  text-align: center;
}

.catalog-state p {
  margin: 0;
}

.catalog-state[data-state="loading"]::before,
.product-media[data-asset-state="loading"]::after {
  content: "";
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  border: 2px solid #d8e2f4;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: catalog-loading-spin 780ms linear infinite;
}

.catalog-state[data-state="error"] {
  flex-direction: column;
}

.catalog-retry-button {
  min-width: 96px;
}

.catalog-pagination {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 78px;
  align-items: center;
  gap: 10px;
  padding: 10px 2px 2px;
  border-top: 1px solid #e1e7ee;
}

.catalog-pagination[hidden] {
  display: none;
}

.catalog-pagination-center {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 6px;
}

.catalog-page-summary {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  white-space: nowrap;
}

.catalog-page-numbers {
  max-width: 100%;
  display: flex;
  justify-content: center;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
}

.catalog-page-numbers::-webkit-scrollbar {
  display: none;
}

.catalog-page-button {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border: 1px solid #d7e0eb;
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.catalog-page-button[data-current="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.pagination-step {
  width: 100%;
  min-width: 0;
  white-space: nowrap;
}

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

.product-item {
  position: relative;
  min-width: 0;
}

.product-card {
  width: 100%;
  height: 100%;
  border: 1px solid #e4eaf0;
  border-radius: 8px;
  background: var(--surface);
  padding: 0;
  text-align: left;
  cursor: default;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 250px;
  overflow: hidden;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.product-card[data-selected="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 236, 0.14), 0 10px 26px rgba(33, 52, 79, 0.12);
}

.product-card:hover {
  border-color: var(--accent);
  box-shadow: 0 10px 26px rgba(33, 52, 79, 0.12);
  transform: translateY(-2px);
}

.product-media {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 104px;
  padding: 10px;
  border-bottom: 0;
  background: #ffffff;
}

.product-media[data-asset-state="loading"] .thumb {
  opacity: 0;
}

.product-media[data-asset-state="loading"]::after {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
}

.product-media[data-asset-state="error"] .thumb {
  opacity: 0.16;
}

.thumb {
  width: 100%;
  aspect-ratio: 2.35 / 1;
  border-radius: 4px;
  background: transparent;
}

.product-details {
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
  padding: 10px;
}

.product-title {
  min-width: 0;
  font-weight: 700;
  line-height: 1.3;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.product-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.product-price {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.3;
  white-space: nowrap;
}

.product-price[data-available="false"] {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.product-sub {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.product-specs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 20px;
}

.product-specs span {
  max-width: 100%;
  padding: 2px 5px;
  border-radius: 4px;
  background: #f2f6fa;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-color-options,
.product-size-options {
  min-height: 28px;
  overflow-x: auto;
  padding: 2px 1px;
  scrollbar-width: none;
}

.product-color-options::-webkit-scrollbar,
.product-size-options::-webkit-scrollbar {
  display: none;
}

.product-color-options .color-swatch-button {
  width: 26px;
  height: 26px;
  flex-basis: 26px;
}

.product-size-options .size-option-button {
  min-width: 52px;
  height: 26px;
  padding: 0 7px;
  font-size: 11px;
}

.product-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.product-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 3px;
}

.product-width {
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.product-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
  min-height: 36px;
  padding: 5px 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
}

.product-action:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.purchase-action:not(:disabled) {
  border-color: #bdd0f8;
  background: #f7faff;
  color: var(--accent);
}

.product-card[data-selected="true"] .try-action {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.customer-panel {
  display: grid;
  grid-area: customer;
  gap: 16px;
  min-width: 0;
  padding: 22px 0 4px;
  border-top: 1px solid var(--line);
}

.customer-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.customer-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.customer-tabs button {
  min-height: 42px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.customer-tabs button:last-child {
  border-right: 0;
}

.customer-tabs button[aria-selected="true"] {
  background: var(--ink);
  color: #fff;
  font-weight: 700;
}

.customer-tabs span {
  font-variant-numeric: tabular-nums;
}

.customer-tab-panel {
  min-width: 0;
}

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

.customer-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.customer-field > span {
  color: var(--muted);
  font-size: 13px;
}

.customer-field input,
.customer-field textarea {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 10px;
}

.customer-field textarea {
  resize: vertical;
}

.contact-form > .button,
.vision-form > .button {
  grid-column: 1 / -1;
  justify-self: start;
}

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

.vision-basics {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(2, minmax(0, 220px));
  gap: 12px;
}

.eye-prescription {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.eye-prescription h3 {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 15px;
}

.vision-notes {
  grid-column: 1 / -1;
}

.vision-records {
  display: grid;
  gap: 0;
  margin-top: 22px;
  border-top: 1px solid var(--line);
}

.vision-record,
.favorite-item {
  display: grid;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.vision-record {
  grid-template-columns: minmax(120px, 0.7fr) minmax(170px, 1fr) minmax(170px, 1fr) auto;
}

.vision-record h3,
.favorite-item h3 {
  margin: 0;
  font-size: 15px;
}

.vision-record p,
.favorite-item p {
  font-size: 13px;
}

.vision-record-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.vision-record-notes {
  grid-column: 1 / -1;
  padding: 10px 12px;
  border-left: 3px solid var(--line);
  background: var(--surface-strong);
}

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

.favorite-item {
  grid-template-columns: 104px minmax(0, 1fr) auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.favorite-item canvas {
  display: block;
  width: 104px;
  height: auto;
  border-radius: 6px;
}

.favorite-item-actions {
  display: grid;
  gap: 8px;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 18px 0;
  color: var(--muted);
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "stage"
      "controls"
      "package"
      "catalog";
  }

  .catalog {
    max-height: none;
    position: static;
  }

  .product-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-height: 520px;
  }
}

@media (max-width: 720px) {
  body {
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
    background: var(--bg);
  }

  .app-topbar {
    min-height: 62px;
    padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
    background: #fff;
    backdrop-filter: none;
  }

  .app-shell {
    grid-template-areas:
      "stage"
      "controls"
      "package"
      "catalog";
    gap: 18px;
    padding: 14px max(12px, env(safe-area-inset-right)) 24px max(12px, env(safe-area-inset-left));
  }

  .site-footer {
    padding: 0 max(12px, env(safe-area-inset-right)) 18px max(12px, env(safe-area-inset-left));
  }

  .app-downloads {
    margin-bottom: 8px;
  }

  .stage-header {
    display: grid;
    gap: 10px;
  }

  .brand {
    width: auto;
    justify-content: center;
  }

  .top-actions {
    position: fixed;
    z-index: 40;
    grid-column: auto;
    justify-self: stretch;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: none;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    padding: 7px env(safe-area-inset-right) calc(7px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
    border-top: 0;
    background: rgba(255, 255, 255, 0.76);
    box-shadow: 0 -8px 24px rgba(33, 52, 79, 0.1);
    -webkit-backdrop-filter: saturate(145%) blur(18px);
    backdrop-filter: saturate(145%) blur(18px);
  }

  .top-actions::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 2px;
    background: var(--edge-line);
    pointer-events: none;
  }

  .top-actions .button {
    width: 100%;
    min-width: 0;
    min-height: 50px;
    padding: 0 4px;
    border-color: transparent;
    border-radius: 0;
    background: rgba(47, 111, 236, 0.1);
    color: var(--accent);
    font-size: 12px;
    white-space: normal;
  }

  .top-actions .button:hover {
    transform: none;
  }

  .stage-actions {
    width: 100%;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 1px 1px 3px;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
  }

  .stage-color-picker,
  .stage-size-picker {
    gap: 8px;
  }

  .stage-actions::-webkit-scrollbar,
  .product-grid::-webkit-scrollbar {
    display: none;
  }

  .stage-actions > * {
    flex: 0 0 auto;
  }

  .tryon-social-actions {
    gap: 6px;
  }

  .stage-actions .button {
    padding: 0 8px;
    font-size: 14px;
  }

  .stage-actions .tracking-state {
    display: none;
  }

  .canvas-wrap {
    aspect-ratio: 10 / 11;
    max-height: 59.4dvh;
    min-height: 0;
    border: 1px solid #dce4ec;
    box-shadow: 0 10px 28px rgba(33, 52, 79, 0.13);
  }

  #tryonCanvas {
    min-height: 0;
    max-height: none;
    position: relative;
    top: 50%;
    transform: translateY(-50%);
  }

  .catalog {
    gap: 14px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .catalog-head {
    align-items: center;
    padding: 0 2px;
  }

  .catalog-head .button {
    flex: 0 0 auto;
  }

  .library-progress {
    font-size: 12px;
  }

  .catalog-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    padding: 12px;
    border-color: #e2e9f0;
    background: #fff;
    box-shadow: 0 8px 22px rgba(33, 52, 79, 0.06);
  }

  .package-panel {
    border-color: #e2e9f0;
    background: #fff;
    box-shadow: 0 8px 22px rgba(33, 52, 79, 0.06);
  }

  .package-panel > summary {
    min-height: 50px;
    padding: 0 12px;
  }

  .package-panel > summary small {
    font-size: 11px;
  }

  .package-content {
    padding: 12px;
  }

  .package-offer {
    font-size: 12px;
  }

  .filter-field,
  .filter-reset-field {
    gap: 4px;
    padding: 8px 9px;
    border: 1px solid #edf1f5;
    border-radius: 8px;
    background: #f8fafc;
  }

  .filter-field input,
  .filter-field select,
  .filter-reset-field button {
    min-height: 32px;
    padding: 0;
    border: 0;
    background: transparent;
    font-size: 13px;
  }

  .filter-reset-field button {
    color: var(--accent);
    text-align: left;
  }

  .search-field {
    padding: 9px 12px;
  }

  .product-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 10px;
    max-height: none;
    margin: 0;
    overflow: visible;
    padding: 2px 1px 8px;
  }

  .catalog-pagination {
    grid-template-columns: 66px minmax(0, 1fr) 66px;
    gap: 6px;
    padding-top: 12px;
  }

  .pagination-step {
    padding-right: 5px;
    padding-left: 5px;
    font-size: 12px;
  }

  .product-item {
    min-width: 0;
  }

  .product-card {
    min-height: 278px;
    border-color: rgba(220, 228, 236, 0.82);
    box-shadow: 0 7px 20px rgba(33, 52, 79, 0.08);
  }

  .product-title {
    font-size: 14px;
  }

  .product-price {
    font-size: 14px;
  }

  .product-price[data-available="false"] {
    font-size: 10px;
  }

  .product-sub {
    font-size: 12px;
  }

  .product-media {
    min-height: 116px;
    padding: 10px 8px;
  }

  .product-details {
    gap: 5px;
    padding: 10px;
  }

  .product-specs {
    min-height: 38px;
  }

  .product-action {
    min-height: 38px;
    font-size: 12px;
  }

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

  .fit-summary div {
    min-width: 0;
    padding: 8px;
  }

  .fit-summary span {
    font-size: 11px;
  }

  .fit-summary strong {
    overflow-wrap: anywhere;
    font-size: 13px;
  }

  .frame-uploader {
    background: var(--surface);
  }

  .control-panel > summary {
    min-height: 52px;
  }

  .control-panel > summary small {
    display: block;
    min-width: 0;
    line-height: 1.35;
    text-align: right;
    white-space: normal;
  }

  .control-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 12px;
    padding: 14px 12px;
  }

  .measurement-calibration {
    padding: 12px;
  }

  .measurement-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #scaleCalibrationStatus {
    max-width: 58%;
  }

  .modal-backdrop {
    padding: 12px;
  }

  .tryon-favorites-modal {
    max-height: calc(100dvh - 24px);
  }

  .ios-install-modal {
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
  }

  .tryon-favorites-head {
    min-height: 64px;
    padding: 10px 12px;
  }

  .tryon-favorites-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 10px;
  }

  .control {
    min-width: 0;
    font-size: 13px;
  }

  .customer-panel {
    gap: 14px;
    padding-top: 18px;
  }

  .contact-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .vision-basics,
  .vision-notes {
    grid-column: 1;
  }

  .vision-record {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .vision-record-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

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

  .ai-panel-head {
    display: grid;
  }

  .ai-panel-head .button,
  .ai-panel > .button {
    width: 100%;
  }

  .ai-result {
    min-height: 180px;
  }
}

@media (max-width: 460px) {
  .brand {
    align-items: center;
    gap: 10px;
  }

  .brand-mark {
    width: 94px;
    height: 32px;
  }

  h1 {
    font-size: 18px;
  }

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

  .contact-form,
  .vision-basics {
    grid-template-columns: 1fr;
  }

  .contact-form > .button,
  .vision-form > .button {
    width: 100%;
  }

  .eye-prescription {
    gap: 8px;
  }

  .customer-field > span {
    overflow-wrap: anywhere;
  }

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

  .favorite-item canvas {
    width: 88px;
  }

  .uploader-title {
    align-items: flex-start;
  }

  .uploader-title span {
    max-width: 48%;
  }
}
