/* Phone-native secondary surfaces. The main studio and desktop overlays
   retain their own layouts; modal semantics, focus and cart logic are unchanged. */
@media (max-width: 640px) {
  .info-dialog,
  .ap-quote-dialog {
    position: fixed;
    inset: 0 0 0;
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - max(16px, env(safe-area-inset-top)));
    margin: auto 0 0;
    border: 0;
    border-radius: 26px 26px 0 0;
    color: #191c20;
    background: #fff;
    box-shadow: 0 -16px 60px #15212d25;
  }
  .info-dialog::backdrop,
  .ap-quote-dialog::backdrop {
    background: #111d2b60;
    backdrop-filter: blur(4px);
  }
  .info-dialog {
    padding: 0;
    overflow: auto;
    overscroll-behavior: contain;
  }
  .info-dialog .dialog-heading {
    position: sticky;
    z-index: 1;
    top: 0;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 23px max(22px, env(safe-area-inset-right)) 15px max(22px, env(safe-area-inset-left));
    margin: 0;
    background: #fff;
    border-bottom: 1px solid #eceef0;
  }
  .info-dialog .dialog-heading h2 {
    min-width: 0;
    font-size: clamp(24px, 6.6vw, 30px);
    font-weight: 640;
    line-height: 1.07;
    letter-spacing: -.046em;
    text-wrap: balance;
  }
  .info-dialog .round,
  .ap-quote-dialog .apq-close {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    background: #f2f3f5;
    border: 0;
    font-size: 25px;
    line-height: 1;
    display: grid;
    place-items: center;
    color: #24272d;
    border-radius: 50%;
  }
  #info-content {
    padding: 17px max(22px, env(safe-area-inset-right)) max(27px, calc(env(safe-area-inset-bottom) + 17px)) max(22px, env(safe-area-inset-left));
  }
  #info-content .specs {
    display: grid;
    border-radius: 16px;
    border: 1px solid #e6e8eb;
    background: #fafafb;
  }
  #info-content .specs div {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr);
    align-items: start;
    gap: 10px;
    padding: 13px 14px;
    border-top: 1px solid #e9eaed;
    font-size: 13px;
    line-height: 1.42;
  }
  #info-content .specs div:first-child { border-top: 0; }
  #info-content .specs dt { color: #626771; }
  #info-content .specs dd { color: #25282e; font-weight: 570; overflow-wrap: anywhere; }
  #info-content .pending-status {
    width: fit-content;
    min-height: 27px;
    padding: 5px 10px;
    color: #434b54;
    background: #ebedf0;
    border-radius: 99px;
    font-weight: 560;
    margin-bottom: 13px;
  }
  #info-content .pending-model > p:not(.pending-status) { font-size: 15px; line-height: 1.55; }
  #info-content .pending-return { width: 100%; min-height: 48px; margin-top: 24px; justify-content: space-between; }
  #info-content .finish-study img,
  #info-content .render-gallery img {
    width: 100%;
    max-height: min(55dvh, 420px);
    border-radius: 13px;
    object-fit: contain;
    background: #e6e8e8;
  }
  #info-content .finish-study figcaption,
  #info-content .render-gallery figcaption { margin: 13px 0 0; color: #646a73; font-size: 13px; line-height: 1.5; }
  #info-content .models { grid-template-columns: 1fr; }
  #info-content .models article { border-radius: 13px; }
  .render-dialog .render-wait,
  .render-dialog .render-result { margin: 18px max(17px, env(safe-area-inset-right)) 0 max(17px, env(safe-area-inset-left)); }
  .render-dialog .render-result img {
    width: 100%;
    max-height: 55dvh;
    border-radius: 13px;
    object-fit: contain;
    background: #f0f1f1;
  }
  .render-dialog .render-wait {
    min-height: 190px;
    border: 0;
    border-radius: 15px;
    padding: 18px;
    background: #f4f5f6;
    text-align: center;
  }
  .render-dialog .render-details {
    display: flex;
    flex-direction: column;
    padding: 0 max(22px, env(safe-area-inset-right)) max(24px, calc(env(safe-area-inset-bottom) + 12px)) max(22px, env(safe-area-inset-left));
    gap: 15px;
    font-size: 13px;
  }
  .render-dialog .render-details a {
    display: flex;
    width: 100%;
    min-height: 48px;
    border: 0;
    border-radius: 14px;
    justify-content: space-between;
    background: var(--mobile-accent, #20242a);
    color: #fff;
    font-size: 14px;
  }

  /* Project is a real sheet rather than squeezed desktop columns. */
  .ap-quote-dialog:not(.apq-share-dialog) {
    height: min(920px, calc(100dvh - max(12px, env(safe-area-inset-top))));
  }
  .ap-quote-dialog .apq-head {
    padding: 21px max(20px, env(safe-area-inset-right)) 15px max(20px, env(safe-area-inset-left));
    gap: 12px;
    align-items: flex-start;
    border-color: #eceef0;
  }
  .ap-quote-dialog .apq-head > div { min-width: 0; }
  .ap-quote-dialog h2 {
    font-size: clamp(26px, 7.2vw, 34px);
    line-height: 1.04;
    font-weight: 640;
    letter-spacing: -.048em;
  }
  .ap-quote-dialog .apq-eyebrow {
    font-size: 10px;
    font-weight: 620;
    letter-spacing: .075em;
    color: #646b73;
    margin: 0 0 6px;
  }
  .ap-quote-dialog .apq-subtitle { font-size: 13px; line-height: 1.4; margin-top: 6px; }
  .ap-quote-dialog .apq-body {
    padding: 16px max(19px, env(safe-area-inset-right)) 24px max(19px, env(safe-area-inset-left));
    background: #f3f4f1;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    scroll-padding-block: 12px;
  }
  .ap-quote-dialog h3 { font-size: 19px; letter-spacing: -.027em; font-weight: 640; }
  .ap-quote-dialog .apq-section-head { margin-bottom: 11px; }
  .ap-quote-dialog .apq-counter { font-size: 12px; background: #e7eaed; color: #444a53; }
  .ap-quote-dialog .apq-notice { background: #e6ecf3; border-radius: 13px; padding: 12px; margin-bottom: 20px; }
  .ap-quote-dialog .apq-notice .apq-dot { background: #597793; }
  .ap-quote-dialog .apq-notice p { color: #414d5a; font-size: 12px; }
  .ap-quote-dialog .apq-columns { gap: 25px; }
  .ap-quote-dialog .apq-court-list { gap: 14px; }
  .ap-quote-dialog .apq-court {
    grid-template-columns: minmax(0, 1fr);
    gap: 13px;
    padding: 12px;
    border-radius: 17px;
    border-color: #e1e4e7;
    box-shadow: 0 2px 6px #2a334b06;
  }
  .ap-quote-dialog .apq-court-image { aspect-ratio: 1.72; min-height: 0; border-radius: 10px; }
  .ap-quote-dialog .apq-court-image img { object-fit: contain; }
  .ap-quote-dialog .apq-court-main { padding: 0 3px; }
  .ap-quote-dialog .apq-court-name { font-size: 17px; margin-bottom: 9px; }
  .ap-quote-dialog .apq-specs {
    display: grid;
    grid-template-columns: repeat(2,minmax(0, 1fr));
    gap: 9px 12px;
  }
  .ap-quote-dialog .apq-spec { display: block; min-width: 0; font-size: 12px; }
  .ap-quote-dialog .apq-spec dt { color: #727783; font-size: 11px; }
  .ap-quote-dialog .apq-spec dd { min-width: 0; color: #30343b; font-size: 12px; line-height: 1.4; }
  .ap-quote-dialog .apq-court-price { font-size: 12px; color: #4c525a; margin-top: 14px; }
  .ap-quote-dialog .apq-court-controls { margin: 0 3px; padding-top: 11px; border-color: #e9eaed; flex-wrap: wrap; gap: 7px; }
  .ap-quote-dialog .apq-quantity { border-radius: 10px; border-color: #e1e3e7; }
  .ap-quote-dialog .apq-quantity button { width: 43px; height: 44px; background: #f3f4f6; font-size: 18px; font-weight: 560; }
  .ap-quote-dialog .apq-quantity input { width: 42px; height: 44px; font-size: 16px; border-color: #e1e4e7; }
  .ap-quote-dialog .apq-line-actions { gap: 9px; }
  .ap-quote-dialog .apq-link { min-height: 44px; min-width: 44px; padding: 8px 0; font-size: 13px; color: #31567b; }
  .ap-quote-dialog .apq-link.apq-remove { color: #9c4038; }
  .ap-quote-dialog .apq-continue { margin: 8px 0; }
  .ap-quote-dialog .apq-summary,
  .ap-quote-dialog .apq-empty { background: #fff; border: 1px solid #e1e4e7; border-radius: 16px; padding: 16px; }
  .ap-quote-dialog .apq-empty p { font-size: 13px; }
  .ap-quote-dialog .apq-empty .apq-btn { white-space: normal; }
  .ap-quote-dialog .apq-summary-row { padding: 11px 0; font-size: 13px; border-color: #e9eaed; gap: 10px; }
  .ap-quote-dialog .apq-summary-row dt { flex: 1; color: #626871; }
  .ap-quote-dialog .apq-summary-row dd { white-space: normal; min-width: 0; text-align: right; overflow-wrap: anywhere; }
  .ap-quote-dialog .apq-summary-row:last-child { font-size: 14px; }
  .ap-quote-dialog .apq-contact {
    padding: 19px 14px;
    border: 1px solid #e1e4e7;
    border-radius: 17px;
    background: #fff;
  }
  .ap-quote-dialog .apq-fields { grid-template-columns: 1fr; gap: 13px; }
  .ap-quote-dialog .apq-fields label,
  .ap-quote-dialog .apq-form-label { font-size: 12px; font-weight: 620; gap: 6px; }
  .ap-quote-dialog .apq-fields input,
  .ap-quote-dialog .apq-fields select,
  .ap-quote-dialog .apq-fields textarea,
  .ap-quote-dialog .apq-form-label input {
    font-size: 16px; /* Avoid Safari's focus zoom on text inputs. */
    min-height: 49px;
    height: 49px;
    border-color: #dfe2e8;
    border-radius: 11px;
    line-height: 1.25;
    padding: 11px 12px;
  }
  .ap-quote-dialog .apq-fields textarea { height: auto; min-height: 94px; }
  .ap-quote-dialog .apq-form h4 { font-size: 15px; }
  .ap-quote-dialog .apq-fineprint { font-size: 12px; color: #686d76; }
  .ap-quote-dialog .apq-foot {
    display: block;
    border-color: #e8eaed;
    padding: 12px max(17px, env(safe-area-inset-right)) max(13px, calc(env(safe-area-inset-bottom) + 8px)) max(17px, env(safe-area-inset-left));
    background: #fff;
  }
  .ap-quote-dialog .apq-actions { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.4fr); gap: 8px; }
  .ap-quote-dialog .apq-btn {
    min-height: 47px;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 12px;
    line-height: 1.2;
    font-size: 13px;
  }
  .ap-quote-dialog .apq-primary {
    background: var(--mobile-accent, #20453f);
    border-color: var(--mobile-accent, #20453f);
  }
  .ap-quote-dialog .apq-foot .apq-btn { white-space: normal; }
  .ap-quote-dialog .apq-modal-status {
    position: static;
    flex: none;
    max-width: none;
    margin: 0;
    padding: 9px 17px;
    border: 0;
    border-top: 1px solid #dee4df;
    background: #eef2ee;
    border-radius: 0;
    box-shadow: none;
    font-size: 12px;
  }
  .apq-share-dialog { height: fit-content; inset: auto 0 0; margin: 0; }
  .apq-share-dialog .apq-head { align-items: center; }
  .apq-share-dialog .apq-share-body {
    padding: 20px max(22px, env(safe-area-inset-right)) max(24px, calc(env(safe-area-inset-bottom) + 12px)) max(22px, env(safe-area-inset-left));
    min-height: 0;
    overflow: auto;
  }
  .apq-share-dialog .apq-share-description { font-size: 14px; line-height: 1.5; }
  .apq-share-dialog .apq-copy-button { margin-top: 16px; min-height: 49px; }

  /* Keep transient cart-edit UI at the top of the material dock without
     obstructing the sticky Add to project control. */
  .apq-edit-banner {
    z-index: 13;
    bottom: auto;
    top: calc(var(--mobile-header, 100px) + 57px);
    gap: 9px;
    max-width: calc(100% - 24px);
    padding: 8px 11px;
    width: max-content;
    white-space: normal;
  }
  .apq-edit-banner .apq-edit-message { font-size: 12px; line-height: 1.3; }
  .apq-edit-banner .apq-link { min-height: 44px; min-width: 44px; }
  .apq-edit-banner .apq-btn { min-height: 44px; font-size: 12px; white-space: normal; }
  .apq-edit-banner .apq-primary { background: var(--mobile-accent, #20453f); border-color: var(--mobile-accent, #20453f); }
  .apq-toast,
  #notice {
    bottom: calc(84px + env(safe-area-inset-bottom));
    width: max-content;
    max-width: calc(100% - 32px);
    border-radius: 14px;
    font-size: 13px;
  }
  body:has(.apq-edit-banner:not([hidden])) .apq-toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

@media (max-width: 640px) and (max-height: 700px) {
  .info-dialog .dialog-heading { padding-top: 17px; padding-bottom: 12px; }
  .ap-quote-dialog .apq-head { padding-top: 15px; padding-bottom: 13px; }
  .ap-quote-dialog h2 { font-size: 25px; }
  .ap-quote-dialog .apq-subtitle { font-size: 12px; }
}
