/* Mobile-first safeguards shared by the storefront and the trade workspace. */
html {
  overflow-x: clip;
  scroll-padding-top: 132px;
}

body,
#root,
.ph-shell,
.tp-page {
  min-width: 0;
  max-width: 100%;
  overflow-x: clip;
}

img,
canvas,
svg {
  max-width: 100%;
}

.ph-container,
.ph-store-hero-left,
.ph-controls-top-row,
.ph-search-bar,
.ph-card,
.ph-card-body,
.ph-modal-dialog,
.tp-card,
.tp-card-heading > div {
  min-width: 0;
}

:where(a, button, input, select, textarea):focus-visible {
  outline: 3px solid color-mix(in srgb, var(--ph-brand-cyan) 75%, white);
  outline-offset: 3px;
}

@media (max-width: 768px) {
  html {
    scroll-padding-top: 112px;
  }

  .ph-container {
    padding-inline: clamp(14px, 4vw, 20px);
  }

  .ph-announcement-bar {
    padding-block: 7px;
  }

  .ph-announcement-content {
    min-height: 18px;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow: hidden;
    white-space: nowrap;
  }

  .ph-announcement-content > :not(:first-child) {
    display: none;
  }

  .ph-navbar {
    height: 60px;
    gap: 10px;
  }

  .ph-brand-logo {
    min-width: 0;
    gap: 9px;
  }

  .ph-brand-symbol {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
  }

  .ph-brand-titles {
    min-width: 0;
  }

  .ph-brand-name {
    overflow: hidden;
    font-size: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ph-brand-sub {
    font-size: 9px;
  }

  .ph-nav-actions {
    flex: 0 0 auto;
    gap: 8px;
  }

  .ph-theme-toggle,
  .ph-hamburger-btn {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
  }

  .ph-hamburger-btn {
    flex-direction: column;
    gap: 4px;
  }

  .ph-hamburger-btn > span {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    transition: transform 160ms ease, opacity 160ms ease;
  }

  .ph-hamburger-btn[aria-expanded="true"] > span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
  }

  .ph-hamburger-btn[aria-expanded="true"] > span:nth-child(2) {
    opacity: 0;
  }

  .ph-hamburger-btn[aria-expanded="true"] > span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
  }

  .ph-mobile-drawer.open {
    gap: 4px;
    padding: 8px 0 16px;
  }

  .ph-mobile-nav-btn {
    min-height: 48px;
    padding: 12px 4px;
  }

  .ph-mobile-drawer .ph-btn-kakao-nav {
    min-height: 48px;
  }

  .ph-store-tab-nav {
    top: 60px;
    padding-block: 7px;
  }

  .ph-tab-pill-group {
    margin-inline: calc(clamp(14px, 4vw, 20px) * -1);
    padding-inline: clamp(14px, 4vw, 20px);
    scroll-padding-inline: clamp(14px, 4vw, 20px);
    scroll-snap-type: x proximity;
    overscroll-behavior-inline: contain;
  }

  .ph-tab-pill-btn {
    min-height: 44px;
    padding: 9px 16px;
    scroll-snap-align: start;
  }

  .ph-store-hero {
    padding-top: 16px;
  }

  .ph-store-hero-card {
    align-items: stretch;
    gap: 18px;
    padding: 22px 18px;
    border-radius: 16px;
  }

  .ph-store-hero-left {
    flex-basis: 100%;
  }

  .ph-store-title,
  .ph-catalog-main-title,
  .ph-section-title {
    overflow-wrap: anywhere;
    font-size: clamp(22px, 7vw, 28px);
    line-height: 1.25;
  }

  .ph-btn-showroom-cta,
  .ph-sort-wrap,
  .ph-sort-select,
  .ph-material-select-wrap,
  .ph-material-select {
    width: 100%;
  }

  .ph-btn-showroom-cta {
    justify-content: center;
    min-height: 48px;
  }

  .ph-catalog-section {
    padding-bottom: 40px;
  }

  .ph-catalog-title-row,
  .ph-controls-top-row,
  .ph-catalog-meta-row {
    align-items: stretch;
  }

  .ph-search-bar {
    flex-basis: 100%;
    min-width: 0;
    height: 48px;
  }

  .ph-material-select-wrap {
    align-items: stretch;
    flex-direction: column;
  }

  .ph-sort-select,
  .ph-material-select {
    min-height: 48px;
    font-size: 16px;
  }

  .ph-catalog-controls {
    gap: 14px;
    margin-bottom: 24px;
    padding: 14px;
  }

  .ph-category-tabs {
    margin-inline: -14px;
    padding-inline: 14px;
    scroll-snap-type: x proximity;
  }

  .ph-category-tab {
    min-height: 44px;
    scroll-snap-align: start;
  }

  .ph-products-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }

  .ph-card-body {
    padding: 17px;
  }

  .ph-card-actions,
  .ph-card-dual-actions {
    gap: 8px;
  }

  .ph-card-actions :where(a, button),
  .ph-card-dual-actions :where(a, button) {
    min-height: 46px;
  }

  .ph-modal-backdrop {
    align-items: flex-end;
    padding: 0;
    z-index: 1100;
  }

  .ph-modal-dialog,
  .ph-checkout-dialog {
    width: 100%;
    max-width: none;
    max-height: 92svh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 18px 18px 0 0;
  }

  .ph-modal-dialog > .ph-modal-grid,
  .ph-modal-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
    padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
  }

  .ph-modal-media-wrap {
    width: 100%;
    height: 210px;
    min-height: 0;
  }

  .ph-modal-info,
  .ph-modal-form,
  .ph-modal-section,
  .ph-modal-specs-table {
    min-width: 0;
  }

  .ph-modal-title {
    padding-right: 38px;
    font-size: clamp(21px, 6.5vw, 25px);
    overflow-wrap: anywhere;
  }

  .ph-modal-desc {
    font-size: 14px;
    overflow-wrap: anywhere;
  }

  .ph-modal-specs-table {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ph-modal-specs-table > *,
  .ph-modal-section > * {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .ph-modal-close-btn {
    top: 10px;
    right: 10px;
    width: 44px;
    height: 44px;
    padding: 0;
    background: color-mix(in srgb, var(--ph-bg-surface-elevated) 92%, transparent);
  }

  .ph-modal-checkout-buttons :where(a, button),
  .ph-modal-form :where(input, select, textarea, button) {
    max-width: 100%;
    min-height: 48px;
    font-size: 16px;
  }

  .ph-modal-checkout-buttons :where(a, button) {
    width: 100%;
    height: auto;
    padding-block: 12px;
    white-space: normal;
    line-height: 1.4;
  }

  .ph-modal-content,
  .ph-checkout-content {
    padding-right: 16px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    padding-left: 16px;
  }

  .ph-mobile-sticky-bar {
    min-height: calc(64px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (max-width: 420px) {
  .ph-container {
    padding-inline: 12px;
  }

  .ph-brand-sub {
    display: none;
  }

  .ph-store-hero-card,
  .ph-catalog-controls {
    border-radius: 14px;
  }

  .ph-card-price-row,
  .ph-bank-account-box,
  .ph-success-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .ph-modal-media-wrap {
    height: 180px;
  }

  .ph-modal-specs-table {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Trade flow: upload -> options/quote -> optional precision calculation. */
@media (max-width: 1050px) {
  .tp-workspace {
    gap: 16px;
  }

  .tp-model-column {
    display: contents;
  }

  .tp-viewer-card { order: 1; }
  .tp-analysis-row { order: 2; }
  .tp-quote-card { order: 3; }
  .tp-prusa-card { order: 4; }
}

@media (max-width: 760px) {
  .tp-page {
    min-width: 0;
    background:
      radial-gradient(circle at 20% 8%, color-mix(in srgb, var(--ph-brand-cyan) 8%, transparent), transparent 18rem),
      var(--ph-bg-base);
  }

  .tp-intro {
    gap: 22px;
    padding-top: 30px;
    padding-bottom: 24px;
  }

  .tp-intro h1 {
    font-size: clamp(30px, 9vw, 40px);
    line-height: 1.14;
    overflow-wrap: anywhere;
  }

  .tp-intro-copy {
    margin-top: 16px;
    font-size: 14px;
    line-height: 1.7;
  }

  .tp-process li {
    min-height: 62px;
  }

  .tp-workspace {
    padding-bottom: 48px;
  }

  .tp-card {
    overflow: hidden;
  }

  .tp-viewer-card,
  .tp-prusa-card,
  .tp-quote-card {
    padding: 18px;
  }

  .tp-card-heading {
    gap: 10px;
    margin-bottom: 16px;
  }

  .tp-card-heading h2 {
    font-size: clamp(19px, 6vw, 24px);
    overflow-wrap: anywhere;
  }

  .tp-file-types,
  .tp-service-status {
    max-width: 42%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tp-drop-zone,
  .tp-canvas-wrap,
  #model-canvas {
    width: 100%;
    min-height: clamp(250px, 72vw, 330px);
    height: clamp(250px, 72vw, 330px);
  }

  .tp-empty-state {
    padding: 20px 14px;
  }

  .tp-empty-state strong {
    margin-top: 14px;
    font-size: 17px;
  }

  .tp-empty-state > span {
    margin: 7px 0 18px;
    font-size: 12px;
    line-height: 1.5;
  }

  .tp-upload-icon {
    width: 58px;
    height: 58px;
    border-radius: 16px;
  }

  .tp-button,
  .tp-prusa-actions .tp-button,
  .tp-next .tp-button {
    width: 100%;
    min-height: 48px;
  }

  .tp-prusa-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .tp-model-summary {
    padding: 13px;
  }

  .tp-status-card,
  .tp-privacy-card {
    min-height: 0;
    padding: 16px;
  }

  .tp-option-card,
  .tp-segmented label,
  .tp-field select,
  .tp-quantity {
    min-height: 48px;
  }

  .tp-option-card {
    justify-content: center;
  }

  .tp-field select,
  .tp-quantity input {
    font-size: 16px;
  }

  .tp-quantity {
    grid-template-columns: 48px 1fr 48px;
  }

  .tp-range-field input {
    height: 32px;
    margin-block: 4px;
  }

  .tp-switch-row {
    min-height: 60px;
  }

  .tp-next {
    gap: 20px;
    margin-bottom: 48px;
    padding: 22px 18px;
  }

  .tp-toast {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    left: 12px;
    max-width: none;
  }
}

@media (max-width: 380px) {
  .tp-intro h1 {
    font-size: 28px;
  }

  .tp-viewer-card,
  .tp-prusa-card,
  .tp-quote-card {
    padding: 14px;
  }

  .tp-card-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .tp-file-types,
  .tp-service-status {
    max-width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
