/* Device-code purchase and after-sales surfaces */

.device-code-purchase-entry,
.device-code-purchase-inline,
.device-code-overlay,
.device-code-dialog {
  --payment-surface: var(--surface, oklch(99% 0.006 225));
  --payment-surface-soft: var(--surface-raised, oklch(96.8% 0.022 230));
  --payment-ink: var(--ink, oklch(22% 0.04 248));
  --payment-text: var(--text, oklch(31% 0.034 250));
  --payment-muted: var(--muted, oklch(54% 0.03 242));
  --payment-line: var(--line, oklch(87% 0.03 228));
  --payment-primary: var(--sky, oklch(62% 0.19 236));
  --payment-primary-strong: var(--sky-strong, oklch(52% 0.21 244));
  --payment-primary-soft: var(--sky-soft, oklch(93% 0.052 230));
  --payment-success: var(--success, oklch(65% 0.14 164));
  --payment-danger: var(--danger, oklch(63% 0.19 28));
  --payment-motion: var(--fast, 180ms cubic-bezier(0.22, 1, 0.36, 1));
}

.device-code-purchase-entry,
.device-code-purchase-inline,
.device-code-dialog,
.device-code-dialog * {
  box-sizing: border-box;
}

.device-code-purchase-entry {
  display: inline-flex;
  min-height: 44px;
  max-width: 100%;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid oklch(72% 0.1 236);
  border-radius: 6px;
  color: var(--payment-primary-strong);
  background: oklch(97% 0.028 232);
  padding: 0 14px;
  font-size: 0.8rem;
  font-weight: 820;
  line-height: 1.35;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition:
    border-color var(--payment-motion),
    background var(--payment-motion),
    box-shadow var(--payment-motion),
    color var(--payment-motion),
    transform var(--payment-motion);
}

.device-code-purchase-entry:hover {
  border-color: var(--payment-primary-strong);
  color: oklch(98% 0.008 230);
  background: var(--payment-primary-strong);
  box-shadow: 0 8px 20px oklch(45% 0.14 242 / 16%);
  transform: translateY(-1px);
}

.device-code-purchase-entry svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.device-code-purchase-inline {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid oklch(82% 0.052 232);
  border-radius: 6px;
  color: var(--payment-text);
  background: oklch(96.5% 0.026 230);
  padding: 10px 12px;
  font-size: 0.76rem;
  line-height: 1.5;
}

.device-code-purchase-inline > :where(p, span, small) {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.device-code-purchase-inline .device-code-purchase-entry {
  min-height: 38px;
  flex: 0 0 auto;
  padding-inline: 12px;
  background: var(--payment-surface);
}

.device-code-purchase-inline .device-code-purchase-entry:hover {
  background: var(--payment-primary-strong);
}

.device-code-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  min-width: 0;
  place-items: center;
  overflow: hidden;
  padding:
    max(20px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
  background:
    linear-gradient(90deg, oklch(96% 0.015 230 / 5%) 1px, transparent 1px) 0 0 / 24px 24px,
    oklch(20% 0.035 248 / 42%);
  animation: payment-overlay-enter 180ms ease-out both;
}

:where(
  .device-code-purchase-entry,
  .device-code-purchase-inline,
  .device-code-overlay,
  .device-code-dialog,
  .device-code-head,
  .device-code-close,
  .device-code-body,
  .device-code-offer,
  .payment-price,
  .payment-methods,
  .payment-method-option,
  #payment-start-button,
  #payment-status,
  .customer-service-panel,
  .customer-service-qr,
  .payment-order-number
)[hidden] {
  display: none !important;
}

.device-code-dialog {
  display: grid;
  width: min(880px, calc(100vw - 40px));
  min-width: 0;
  max-width: 100%;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid oklch(76% 0.07 233);
  border-radius: 8px;
  color: var(--payment-text);
  background: var(--payment-surface);
  box-shadow:
    inset 0 1px 0 oklch(100% 0 0 / 60%),
    0 26px 70px oklch(20% 0.05 248 / 26%);
  animation: payment-dialog-enter 200ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.device-code-head {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid oklch(85% 0.036 230);
  background:
    linear-gradient(90deg, oklch(64% 0.1 236 / 7%) 1px, transparent 1px) 0 0 / 22px 22px,
    oklch(96.8% 0.022 230);
  padding: 18px 20px 16px;
}

.device-code-head > :first-child {
  min-width: 0;
}

.device-code-head :where(h1, h2, h3) {
  margin: 0 0 5px;
  color: var(--payment-ink);
  font-size: 1.25rem;
  font-weight: 850;
  line-height: 1.3;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.device-code-head :where(p, .eyebrow) {
  max-width: 68ch;
  margin: 0;
  color: var(--payment-muted);
  font-size: 0.8rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.device-code-head .eyebrow {
  margin-bottom: 4px;
  color: var(--payment-primary-strong);
  font-size: 0.7rem;
  font-weight: 840;
}

.device-code-close {
  display: inline-grid;
  width: 38px;
  height: 38px;
  min-height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--payment-line);
  border-radius: 5px;
  color: var(--payment-muted);
  background: var(--payment-surface);
  padding: 0;
  cursor: pointer;
  box-shadow: inset 0 1px 0 oklch(100% 0 0 / 76%);
  transition:
    border-color var(--payment-motion),
    background var(--payment-motion),
    color var(--payment-motion);
}

.device-code-close:hover {
  border-color: var(--payment-primary);
  color: var(--payment-primary-strong);
  background: var(--payment-primary-soft);
}

.device-code-close svg {
  width: 18px;
  height: 18px;
}

.device-code-body {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-columns: minmax(0, 1.22fr) minmax(280px, 0.78fr);
  align-items: stretch;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.device-code-offer,
.customer-service-panel {
  min-width: 0;
  padding: 22px;
}

.device-code-offer {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.device-code-offer > :where(h2, h3),
.customer-service-panel > :where(h2, h3) {
  margin: 0;
  color: var(--payment-ink);
  font-size: 1rem;
  font-weight: 830;
  line-height: 1.4;
  letter-spacing: 0;
}

.device-code-offer > :where(p, small),
.customer-service-panel > :where(p, small) {
  margin: 0;
  color: var(--payment-muted);
  font-size: 0.78rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.payment-price {
  display: flex;
  min-width: 0;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 9px;
  color: var(--payment-primary-strong);
  font-size: 2.35rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: 0;
}

.payment-price :where(small, span:not(:first-child)) {
  color: var(--payment-muted);
  font-size: 0.75rem;
  font-weight: 720;
  line-height: 1.45;
}

.payment-methods {
  display: grid;
  min-width: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  border: 0;
  padding: 0;
}

.payment-methods > legend {
  width: 100%;
  margin: 0 0 8px;
  color: var(--payment-ink);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.4;
}

.payment-method-option {
  display: flex;
  min-width: 0;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid oklch(82% 0.04 231);
  border-radius: 6px;
  color: var(--payment-text);
  background: oklch(98.5% 0.009 227);
  padding: 9px 12px;
  font-size: 0.78rem;
  font-weight: 780;
  line-height: 1.35;
  text-align: center;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition:
    border-color var(--payment-motion),
    background var(--payment-motion),
    box-shadow var(--payment-motion),
    color var(--payment-motion);
}

.payment-method-option:hover {
  border-color: oklch(70% 0.11 236);
  background: oklch(96% 0.03 231);
}

.payment-method-option:has(input:checked),
.payment-method-option.is-selected,
.payment-method-option[aria-checked="true"] {
  border-color: var(--payment-primary-strong);
  color: var(--payment-primary-strong);
  background: var(--payment-primary-soft);
  box-shadow: inset 0 0 0 1px oklch(55% 0.17 240 / 16%);
}

.payment-method-option input[type="radio"] {
  width: 17px;
  height: 17px;
  min-width: 17px;
  margin: 0;
  accent-color: var(--payment-primary-strong);
}

.payment-method-option :where(svg, img) {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  object-fit: contain;
}

#payment-start-button,
.customer-service-panel :where(a, button) {
  display: inline-flex;
  min-height: 44px;
  max-width: 100%;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 6px;
  padding: 0 16px;
  font-size: 0.82rem;
  font-weight: 840;
  line-height: 1.35;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition:
    border-color var(--payment-motion),
    background var(--payment-motion),
    box-shadow var(--payment-motion),
    color var(--payment-motion),
    filter var(--payment-motion),
    transform var(--payment-motion);
}

#payment-start-button {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--payment-primary-strong);
  color: oklch(98% 0.008 230);
  background: linear-gradient(180deg, var(--payment-primary), var(--payment-primary-strong));
  box-shadow:
    inset 0 1px 0 oklch(100% 0 0 / 24%),
    0 10px 24px oklch(45% 0.16 242 / 20%);
}

#payment-start-button:hover:not(:disabled) {
  filter: saturate(1.08) brightness(1.02);
  box-shadow:
    inset 0 1px 0 oklch(100% 0 0 / 26%),
    0 14px 30px oklch(45% 0.16 242 / 25%);
  transform: translateY(-1px);
}

#payment-start-button:disabled,
#payment-start-button[aria-disabled="true"] {
  cursor: not-allowed;
  filter: saturate(0.55);
  opacity: 0.62;
  transform: none;
}

#payment-start-button:is(.is-loading, .loading, [aria-busy="true"], [data-state="loading"]) {
  cursor: wait;
}

#payment-start-button:is(.is-loading, .loading, [aria-busy="true"], [data-state="loading"])::before {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  border: 2px solid oklch(98% 0.008 230 / 42%);
  border-top-color: oklch(98% 0.008 230);
  border-radius: 50%;
  content: "";
  animation: payment-spin 700ms linear infinite;
}

#payment-status {
  display: flex;
  min-width: 0;
  min-height: 38px;
  align-items: center;
  gap: 8px;
  margin: 0;
  border: 1px solid oklch(82% 0.05 232);
  border-radius: 6px;
  color: var(--payment-primary-strong);
  background: oklch(96% 0.03 231);
  padding: 8px 10px;
  font-size: 0.75rem;
  font-weight: 740;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

#payment-status:empty {
  display: none;
}

#payment-status:is(.is-loading, .loading, [data-state="loading"]),
.device-code-dialog:is(.is-loading, .loading, [data-state="loading"]) #payment-status {
  color: var(--payment-primary-strong);
}

#payment-status:is(.is-loading, .loading, [data-state="loading"])::before,
.device-code-dialog:is(.is-loading, .loading, [data-state="loading"]) #payment-status::before {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border: 2px solid oklch(55% 0.17 240 / 22%);
  border-top-color: var(--payment-primary-strong);
  border-radius: 50%;
  content: "";
  animation: payment-spin 700ms linear infinite;
}

#payment-status:is(.is-success, .success, [data-state="success"]),
.device-code-dialog:is(.is-success, .success, [data-state="success"]) #payment-status {
  border-color: oklch(74% 0.08 164);
  color: oklch(45% 0.13 164);
  background: oklch(95% 0.035 164);
}

#payment-status:is(.is-error, .error, [data-state="error"]),
.device-code-dialog:is(.is-error, .error, [data-state="error"]) #payment-status {
  border-color: oklch(78% 0.08 28);
  color: var(--payment-danger);
  background: oklch(96% 0.028 28);
}

.customer-service-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  border-left: 1px solid var(--payment-line);
  background:
    linear-gradient(90deg, oklch(64% 0.09 235 / 5%) 1px, transparent 1px) 0 0 / 22px 22px,
    oklch(97.5% 0.014 228);
  text-align: center;
}

.customer-service-qr {
  display: block;
  width: min(100%, 260px);
  height: auto;
  max-width: 260px;
  aspect-ratio: 1 / 1;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid oklch(78% 0.055 232);
  border-radius: 6px;
  background: oklch(99% 0.004 225);
  padding: 8px;
  object-fit: contain;
  object-position: center;
  image-rendering: auto;
  box-shadow:
    inset 0 1px 0 oklch(100% 0 0 / 80%),
    0 8px 20px oklch(42% 0.08 240 / 10%);
}

.customer-service-qr :where(img, canvas, svg) {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  object-fit: contain;
  object-position: center;
}

img.customer-service-qr {
  height: auto;
}

.customer-service-panel :where(a, button) {
  width: min(100%, 260px);
  border: 1px solid oklch(70% 0.1 236);
  color: var(--payment-primary-strong);
  background: var(--payment-surface);
}

.customer-service-panel :where(a, button):hover {
  border-color: var(--payment-primary-strong);
  color: oklch(98% 0.008 230);
  background: var(--payment-primary-strong);
  box-shadow: 0 8px 20px oklch(45% 0.14 242 / 16%);
  transform: translateY(-1px);
}

.payment-order-number {
  max-width: 100%;
  margin: 0;
  border: 1px solid var(--payment-line);
  border-radius: 5px;
  color: var(--payment-ink);
  background: var(--payment-surface);
  padding: 7px 9px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
  overflow-wrap: anywhere;
  user-select: all;
}

.device-code-purchase-entry:focus-visible,
.device-code-close:focus-visible,
.payment-method-option:focus-visible,
.payment-method-option:has(input:focus-visible),
#payment-start-button:focus-visible,
.customer-service-panel :where(a, button):focus-visible {
  outline: 3px solid oklch(62% 0.18 236 / 28%);
  outline-offset: 2px;
}

.payment-method-option input[type="radio"]:focus-visible {
  outline: none;
}

@keyframes payment-overlay-enter {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes payment-dialog-enter {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

@media (min-width: 721px) and (max-width: 940px) {
  .device-code-dialog {
    width: min(820px, calc(100vw - 28px));
  }

  .device-code-body {
    grid-template-columns: minmax(0, 1fr) minmax(232px, 0.68fr);
  }

  .device-code-offer,
  .customer-service-panel {
    padding: 18px;
  }

  .customer-service-qr,
  .customer-service-panel :where(a, button) {
    width: min(100%, 230px);
    max-width: 230px;
  }
}

@media (max-width: 720px) {
  .device-code-purchase-entry {
    min-height: 44px;
  }

  .device-code-purchase-inline {
    align-items: stretch;
    flex-direction: column;
  }

  .device-code-purchase-inline .device-code-purchase-entry {
    width: 100%;
    min-height: 44px;
  }

  .device-code-overlay {
    align-items: end;
    justify-items: stretch;
    padding:
      max(8px, env(safe-area-inset-top))
      env(safe-area-inset-right)
      0
      env(safe-area-inset-left);
  }

  .device-code-dialog {
    width: 100%;
    max-width: 100%;
    max-height: calc(100vh - max(8px, env(safe-area-inset-top)));
    max-height: calc(100dvh - max(8px, env(safe-area-inset-top)));
    border-radius: 8px 8px 0 0;
    animation-name: payment-drawer-enter;
  }

  .device-code-head {
    gap: 10px;
    padding: 14px 12px 12px;
  }

  .device-code-head :where(h1, h2, h3) {
    font-size: 1.05rem;
  }

  .device-code-head :where(p, .eyebrow) {
    font-size: 0.75rem;
  }

  .device-code-close {
    width: 44px;
    height: 44px;
    min-height: 44px;
  }

  .device-code-body {
    grid-template-columns: minmax(0, 1fr);
    overflow-x: hidden;
    padding-bottom: env(safe-area-inset-bottom);
    scrollbar-gutter: auto;
  }

  .device-code-offer,
  .customer-service-panel {
    width: 100%;
    max-width: 100%;
    padding: 18px 14px;
  }

  .device-code-offer {
    gap: 14px;
  }

  .payment-price {
    font-size: 2rem;
  }

  .payment-method-option,
  #payment-start-button,
  .customer-service-panel :where(a, button) {
    min-height: 48px;
  }

  .customer-service-panel {
    border-top: 1px solid var(--payment-line);
    border-left: 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .customer-service-qr,
  .customer-service-panel :where(a, button) {
    width: min(100%, 240px);
    max-width: 240px;
  }
}

@media (max-width: 390px) {
  .device-code-head {
    padding-left: 10px;
  }

  .device-code-offer,
  .customer-service-panel {
    padding-right: 12px;
    padding-left: 12px;
  }

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

  .payment-price {
    font-size: 1.85rem;
  }
}

@keyframes payment-drawer-enter {
  from {
    opacity: 0;
    transform: translateY(24px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .device-code-overlay,
  .device-code-dialog,
  .device-code-purchase-entry,
  .device-code-close,
  .payment-method-option,
  #payment-start-button,
  .customer-service-panel :where(a, button) {
    animation: none;
    scroll-behavior: auto;
    transition: none;
  }

  #payment-start-button:is(.is-loading, .loading, [aria-busy="true"], [data-state="loading"])::before,
  #payment-status:is(.is-loading, .loading, [data-state="loading"])::before,
  .device-code-dialog:is(.is-loading, .loading, [data-state="loading"]) #payment-status::before {
    border-color: oklch(55% 0.17 240 / 28%);
    border-top-color: currentColor;
    animation: none;
  }
}
