/*
 * Builder mobile UX, isolated to the /builder/ experience.
 * Orange primary + restrained lime status; no expensive live glass blur.
 * The existing desktop sidebar and server-rendered purchase logic stay intact.
 */
.builder-mobile-dock,
.builder-mobile-progress,
.builder-mobile-summary-scrim,
.builder-mobile-sheet-close,
.builder-mobile-sheet-handle,
.bsc-mobile-state {
  display: none;
}
@media (max-width: 992px) {
  body[data-bsg-page="builder"]:not(.admin-page) {
    --builder-orange: #ff5b24;
    --builder-orange-soft: rgba(255,91,36,.12);
    --builder-ink: var(--text, #eef1f6);
    --builder-muted: var(--text-muted, #adb7c8);
    padding-bottom: calc(224px + env(safe-area-inset-bottom, 0px)) !important;
  }
  body[data-bsg-page="builder"] .page-body {
    overflow-x: clip;
  }
  body[data-bsg-page="builder"] .builder-hero {
    width: min(100% - 28px, 570px);
    margin: 10px auto 8px !important;
    padding: 16px 5px 3px !important;
    text-align: right !important;
  }
  body[data-bsg-page="builder"] .builder-hero h1 {
    display: block !important;
    margin: 0 0 8px !important;
    max-width: 100% !important;
    padding: 0 !important;
    font-size: clamp(1.12rem, 4.6vw, 1.5rem) !important;
    line-height: 1.8 !important;
    letter-spacing: normal !important;
    word-break: normal !important;
    white-space: normal !important;
    overflow-wrap: normal !important;
    text-wrap: balance;
    text-align: right !important;
    color: var(--builder-ink) !important;
    background: none !important;
    -webkit-text-fill-color: currentColor !important;
  }
  body[data-bsg-page="builder"] .builder-hero h1 i { color: var(--builder-orange); }
  /* The fixed 2-step purchase dock occupies the bottom-left corner. The
     floating global back-to-top button must never cover its primary action. */
  body[data-bsg-page="builder"] #topButton {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }
  body[data-bsg-page="builder"] .builder-hero p {
    margin: 0;
    font-size: .77rem;
    line-height: 1.9;
    text-align: right;
    color: var(--builder-muted) !important;
  }
  body[data-bsg-page="builder"] .builder-flow { display: none !important; }
  body[data-bsg-page="builder"] .builder-hero + .container,
  body[data-bsg-page="builder"] .builder-workspace {
    width: calc(100% - 28px) !important;
    max-width: 570px !important;
    padding: 0 !important;
    margin-inline: auto !important;
    min-width: 0;
  }
  body[data-bsg-page="builder"] .builder-smart-entry {
    display: grid !important;
    grid-template-columns: minmax(0,1fr) !important;
    align-items: stretch !important;
    gap: 10px !important;
    padding: 13px !important;
    margin: 8px 0 12px !important;
    border: 1px solid var(--border) !important;
    border-radius: 18px !important;
    background: var(--surface) !important;
    box-shadow: 0 6px 22px rgba(0,0,0,.045) !important;
  }
  body[data-bsg-page="builder"] .builder-purpose-form {
    width: 100% !important;
    display: grid !important;
    grid-template-columns: minmax(0,1fr) auto !important;
    align-items: end !important;
    gap: 8px !important;
    margin: 0 !important;
  }
  body[data-bsg-page="builder"] .builder-purpose-form label {
    grid-column: 1 / -1;
    margin: 0 !important;
    color: var(--builder-muted);
    font-size: .78rem;
    font-weight: 750;
  }
  body[data-bsg-page="builder"] .builder-purpose-form select {
    width: 100%;
    min-width: 0;
    min-height: 46px;
    font-size: 16px !important; /* prevent iOS focus zoom */
  }
  body[data-bsg-page="builder"] .builder-purpose-form button {
    min-height: 46px;
    padding-inline: 12px;
    font-size: .77rem !important;
    white-space: nowrap;
  }
  body[data-bsg-page="builder"] .builder-smart-entry > a[href*="suggestions"] {
    width: 100%;
    min-height: 44px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 7px;
    background: var(--builder-orange-soft) !important;
    border: 1px solid rgba(255,91,36,.28) !important;
    border-radius: 12px;
    box-shadow: none !important;
    color: var(--builder-orange) !important;
    font-size: .79rem !important;
  }
  body[data-bsg-page="builder"] .builder-smart-entry .builder-assemble-cta { display: none !important; }

  /* Replace a static three-step paragraph with actionable progress. */
  body.builder-mobile-enhanced[data-bsg-page="builder"] .builder-mobile-progress {
    display: grid;
    gap: 12px;
    padding: 15px;
    margin: 0 0 14px;
    border: 1px solid rgba(255,91,36,.25);
    border-radius: 19px;
    background: linear-gradient(142deg, rgba(255,91,36,.09), transparent 55%), var(--surface);
    box-shadow: 0 7px 24px rgba(0,0,0,.05);
  }
  body[data-bsg-page="builder"] .builder-mobile-progress__heading {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
    min-width: 0;
  }
  body[data-bsg-page="builder"] .builder-mobile-progress__heading > div {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
  }
  body[data-bsg-page="builder"] .builder-mobile-progress__eyebrow {
    color: var(--builder-orange);
    font-size: .68rem;
    font-weight: 800;
  }
  body[data-bsg-page="builder"] [data-builder-progress-label] {
    font-size: .97rem;
    color: var(--builder-ink);
  }
  body[data-bsg-page="builder"] [data-builder-progress-hint] {
    color: var(--builder-muted);
    font-size: .73rem;
    line-height: 1.75;
  }
  body[data-bsg-page="builder"] .builder-mobile-progress__count {
    white-space: nowrap;
    color: var(--builder-orange);
    background: var(--builder-orange-soft);
    border-radius: 100px;
    padding: 5px 9px;
    font-size: .76rem;
    font-weight: 850;
    font-variant-numeric: tabular-nums;
  }
  body[data-bsg-page="builder"] .builder-mobile-progress__track {
    height: 7px;
    background: var(--surface-2);
    border-radius: 100px;
    overflow: hidden;
    border: 1px solid rgba(255,91,36,.08);
  }
  body[data-bsg-page="builder"] .builder-mobile-progress__track > span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #ff783f, #ff5b24);
    transition: width .22s ease;
  }
  body[data-bsg-page="builder"] .builder-mobile-progress__next {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border: none;
    border-radius: 12px;
    background: #ff5b24;
    color: #fff;
    font: inherit;
    font-size: .8rem;
    font-weight: 850;
    cursor: pointer;
  }

  body[data-bsg-page="builder"] .builder-grid {
    display: grid !important;
    grid-template-columns: minmax(0,1fr) !important;
    gap: 0 !important;
    padding: 0 0 12px !important;
    min-width: 0;
  }
  body[data-bsg-page="builder"] .builder-main-col {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  body[data-bsg-page="builder"] .builder-main-col .builder-slots { order: 0; }
  body[data-bsg-page="builder"] .builder-main-col .pc-preview-block { order: 1; }
  body[data-bsg-page="builder"] .builder-slots {
    display: grid !important;
    grid-template-columns: minmax(0,1fr) !important;
    gap: 10px !important;
  }
  body[data-bsg-page="builder"] .builder-slot-card {
    padding: 13px !important;
    border: 1px solid var(--border) !important;
    border-radius: 17px !important;
    background: var(--surface) !important;
    box-shadow: 0 5px 16px rgba(0,0,0,.035) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    transform: none !important;
    transition: border-color .15s ease !important;
  }
  body[data-bsg-page="builder"] .builder-slot-card.filled {
    border-color: rgba(255,91,36,.36) !important;
  }
  body[data-bsg-page="builder"] .bsc-head { gap: 7px; flex-wrap: wrap; }
  body[data-bsg-page="builder"] .bsc-step {
    background: #ff5b24 !important;
    color: #fff !important;
    width: 25px;
    height: 25px;
  }
  body[data-bsg-page="builder"] .bsc-head > i { color: var(--builder-orange) !important; }
  body[data-bsg-page="builder"] .bsc-title { font-size: .87rem; }
  body[data-bsg-page="builder"] .bsc-badge {
    background: rgba(255,91,36,.09) !important;
    color: var(--builder-orange) !important;
    font-size: .68rem;
  }
  body[data-bsg-page="builder"] .bsc-mobile-state {
    display: block;
    color: var(--builder-muted);
    font-size: .73rem;
    font-weight: 700;
  }
  body[data-bsg-page="builder"] .builder-slot-card.filled .bsc-mobile-state {
    color: #70a621;
  }
  body[data-bsg-page="builder"] .bsc-item {
    min-width: 0;
    gap: 9px;
    padding: 8px;
    background: var(--surface-2);
    border-color: var(--border);
  }
  body[data-bsg-page="builder"] .bsc-info { flex: 1; min-width: 0; }
  body[data-bsg-page="builder"] .bsc-name { font-size: .78rem; overflow-wrap: anywhere; }
  body[data-bsg-page="builder"] .bsc-price { color: var(--builder-orange); }
  body[data-bsg-page="builder"] .bsc-qty-btn { min-width: 40px; min-height: 40px; }
  body[data-bsg-page="builder"] .bsc-actions { gap: 7px; flex-wrap: wrap; }
  body[data-bsg-page="builder"] .bsc-actions .btn {
    flex: 1 1 auto;
    min-height: 44px;
    border-radius: 11px;
    font-size: .78rem;
  }
  body[data-bsg-page="builder"] .bsc-actions .btn-primary {
    background: #ff5b24 !important;
    color: #fff !important;
  }
  body[data-bsg-page="builder"] .pc-preview-block {
    margin-top: 4px;
    content-visibility: auto;
    contain-intrinsic-size: auto 300px;
  }
  body[data-bsg-page="builder"] .pc-preview-block .preview-head button { display: none; }

  /* The mobile rail sits above the global five-tab navigation (76px + inset). */
  body.builder-mobile-enhanced[data-bsg-page="builder"] .builder-mobile-dock {
    position: fixed !important;
    display: grid !important;
    grid-template-columns: minmax(0,1fr) auto auto;
    align-items: center;
    gap: 7px;
    z-index: 1400;
    bottom: calc(94px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    width: min(570px, calc(100vw - 24px));
    min-height: 70px;
    padding: 9px 11px;
    background: var(--surface);
    border: 1px solid rgba(255,91,36,.23);
    border-radius: 21px;
    box-shadow: 0 9px 30px rgba(0,0,0,.21);
    direction: rtl;
  }
  body[data-bsg-page="builder"] .builder-mobile-dock__price {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 3px;
    line-height: 1.3;
  }
  body[data-bsg-page="builder"] [data-builder-mobile-count] {
    color: var(--builder-muted);
    font-size: .68rem;
    white-space: nowrap;
  }
  body[data-bsg-page="builder"] [data-builder-mobile-total] {
    color: var(--builder-ink);
    font-size: clamp(.77rem,2.9vw,.98rem);
    font-weight: 900;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
  }
  body[data-bsg-page="builder"] .builder-mobile-dock__summary,
  body[data-bsg-page="builder"] .builder-mobile-dock__analyse {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 46px;
    min-width: 57px;
    padding: 5px 8px;
    font: inherit;
    font-size: .67rem;
    font-weight: 800;
    line-height: 1.2;
    border-radius: 12px;
    text-decoration: none;
    cursor: pointer;
  }
  body[data-bsg-page="builder"] .builder-mobile-dock__summary {
    color: var(--builder-ink);
    border: 1px solid var(--border);
    background: var(--surface-2);
  }
  body[data-bsg-page="builder"] .builder-mobile-dock__analyse {
    color: #fff !important;
    background: #ff5b24;
    border: 1px solid #ff5b24;
  }
  body[data-bsg-page="builder"] .builder-mobile-dock :is(button,a):focus-visible,
  body[data-bsg-page="builder"] .builder-mobile-progress__next:focus-visible {
    outline: 2px solid #ff783f;
    outline-offset: 2px;
  }

  /* Selected products are already rendered with editable controls in each
     slot card. The summary sheet contains outcomes and next actions only. */
  body[data-bsg-page="builder"]:not(.admin-page) .mybuild-list {
    display: none !important;
  }
  /* With the dock out of the layout, keep the summary entirely off-page
     until opened by the user; no second inline "my build" block. */
  /* Summary opens as a native-feeling sheet without moving the page. */
  body[data-bsg-page="builder"]:not(.admin-page) .builder-mobile-summary-scrim {
    display: block;
    position: fixed;
    z-index: 2100;
    inset: 0;
    width: 100%;
    border: 0;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    background: rgba(0,0,0,.56);
    transition: opacity .18s ease, visibility .18s;
  }
  body[data-bsg-page="builder"]:not(.admin-page) .mybuild-panel {
    position: fixed !important;
    z-index: 2200;
    top: auto !important;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-height: min(86dvh, 820px) !important;
    padding: 12px 17px max(22px, env(safe-area-inset-bottom, 0px)) !important;
    margin: 0 !important;
    border-radius: 25px 25px 0 0 !important;
    border: 1px solid var(--border);
    background: var(--surface) !important;
    box-shadow: 0 -13px 44px rgba(0,0,0,.26) !important;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(18px);
    transition: opacity .2s ease, transform .2s ease, visibility .2s !important;
    backdrop-filter: none !important;
  }
  body.builder-mobile-summary-open[data-bsg-page="builder"] .builder-mobile-summary-scrim {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }
  body.builder-mobile-summary-open[data-bsg-page="builder"] .mybuild-panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
  }
  body.builder-mobile-summary-open { overflow: hidden; }
  body[data-bsg-page="builder"] .builder-mobile-sheet-handle {
    display: block;
    width: 43px;
    height: 5px;
    border-radius: 20px;
    background: var(--border);
    margin: 0 auto 10px;
  }
  body[data-bsg-page="builder"] .builder-mobile-sheet-close {
    display: inline-grid;
    place-items: center;
    min-width: 44px;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--surface-2);
    color: var(--builder-ink);
    cursor: pointer;
  }
  body[data-bsg-page="builder"] .mybuild-panel .mybuild-head {
    position: sticky;
    top: -12px;
    z-index: 1;
    background: var(--surface);
    padding: 1px 0 10px;
  }
  body[data-bsg-page="builder"] .mybuild-row { min-height: 58px; }
  body[data-bsg-page="builder"] .mybuild-ops button {
    min-width: 42px;
    min-height: 42px;
  }
  body[data-bsg-page="builder"] .mybuild-panel .builder-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  body[data-bsg-page="builder"] .mybuild-panel .builder-actions .btn {
    min-height: 44px;
  }
  body[data-bsg-page="builder"] .mybuild-panel .builder-analysis-launch {
    min-height: 48px;
    background: #ff5b24 !important;
    color: #fff !important;
    border: 0;
  }

  /* Picker uses the usable visual viewport, with comfortably sized controls. */
  body[data-bsg-page="builder"] .builder-drawer { z-index: 2400; }
  body[data-bsg-page="builder"] .builder-drawer-panel {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    border: none;
    box-shadow: none;
    animation: none !important;
    background: var(--surface) !important;
  }
  body[data-bsg-page="builder"] .builder-drawer-head {
    padding: 13px 15px 11px;
    flex-shrink: 0;
  }
  body[data-bsg-page="builder"] .builder-drawer-head h3 {
    font-size: 1.03rem;
  }
  body[data-bsg-page="builder"] .builder-drawer-head p {
    font-size: .74rem;
    line-height: 1.65;
  }
  body[data-bsg-page="builder"] .builder-drawer-head .modal-close {
    min-width: 44px;
    min-height: 44px;
    flex: 0 0 44px;
  }
  body[data-bsg-page="builder"] .builder-drawer-filters {
    display: grid;
    grid-template-columns: minmax(0,1fr) auto;
    gap: 8px;
    padding: 11px 14px;
    flex-shrink: 0;
  }
  body[data-bsg-page="builder"] .builder-drawer-filters .drawer-search {
    grid-column: 1/-1;
    min-width: 0;
    margin: 0;
  }
  body[data-bsg-page="builder"] .drawer-search input {
    height: 46px;
    font-size: 16px !important;
  }
  body[data-bsg-page="builder"] #pickerBrand {
    width: 100%;
    min-height: 44px;
    min-width: 0;
    font-size: 16px !important;
  }
  body[data-bsg-page="builder"] #pickerAdvancedLink {
    min-height: 44px;
    padding-inline: 11px;
    font-size: .75rem;
  }
  body[data-bsg-page="builder"] .builder-filter-popup {
    max-height: min(55dvh, 500px);
    overflow-y: auto;
    padding: 12px 14px 16px;
    animation: none !important;
  }
  body[data-bsg-page="builder"] .filter-popup-body {
    max-height: 40dvh;
    grid-template-columns: 1fr;
  }
  body[data-bsg-page="builder"] .builder-drawer-results {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 13px 14px 24px;
  }
  body[data-bsg-page="builder"] .picker-grid {
    display: grid;
    grid-template-columns: minmax(0,1fr);
    gap: 10px;
  }
  body[data-bsg-page="builder"] .picker-card {
    display: grid;
    grid-template-columns: 100px minmax(0,1fr);
    grid-template-rows: auto 1fr;
    min-width: 0;
    border-radius: 16px;
    background: var(--surface) !important;
    box-shadow: none !important;
    border: 1px solid var(--border);
    transition: border-color .15s ease !important;
    transform: none !important;
    backdrop-filter: none !important;
  }
  body[data-bsg-page="builder"] .picker-card .pc-type {
    grid-column: 1/-1;
    grid-row: 1;
    padding: 7px 12px;
    font-size: .69rem;
    background: var(--surface-2);
  }
  body[data-bsg-page="builder"] .picker-card .pc-img {
    grid-column: 1;
    grid-row: 2;
    height: 100%;
    min-height: 120px;
    max-height: 185px;
    align-self: stretch;
    padding: 9px;
  }
  body[data-bsg-page="builder"] .picker-card .pc-img img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
  body[data-bsg-page="builder"] .picker-card .pc-body {
    grid-column: 2;
    grid-row: 2;
    padding: 10px;
    gap: 6px;
    min-width: 0;
  }
  body[data-bsg-page="builder"] .picker-card .pc-title {
    line-height: 1.6;
    font-size: .78rem;
    overflow-wrap: anywhere;
  }
  body[data-bsg-page="builder"] .picker-card .pc-specs {
    max-height: 47px;
    overflow: hidden;
    font-size: .69rem;
  }
  body[data-bsg-page="builder"] .picker-card .pc-foot {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  body[data-bsg-page="builder"] .picker-card .pc-price {
    color: var(--builder-orange) !important;
    font-size: .83rem;
  }
  body[data-bsg-page="builder"] .picker-card .builder-add-btn {
    min-height: 44px;
    margin-top: auto;
    border-radius: 11px;
    background: #ff5b24 !important;
    color: #fff !important;
    border-color: #ff5b24 !important;
    font-size: .76rem;
  }
  body[data-bsg-page="builder"] .picker-card .builder-add-btn:disabled {
    background: var(--surface-2) !important;
    color: var(--builder-muted) !important;
    border-color: var(--border) !important;
  }
}
@media (max-width: 360px) {
  body[data-bsg-page="builder"] .builder-mobile-dock {
    gap: 5px;
    padding: 7px 8px;
  }
  body[data-bsg-page="builder"] .builder-mobile-dock :is(button,a) {
    min-width: 48px;
    padding-inline: 5px;
  }
  body[data-bsg-page="builder"] .picker-card {
    grid-template-columns: 84px minmax(0,1fr);
  }
  body[data-bsg-page="builder"] .bsc-item {
    flex-wrap: wrap;
  }
}
@media (prefers-reduced-motion: reduce) {
  body[data-bsg-page="builder"] *,
  body[data-bsg-page="builder"] *::before,
  body[data-bsg-page="builder"] *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}

/* The global site navigation uses z-index:9990; lower it only here so the
   builder sheet and picker can cover it, including on iOS Safari. */
@media (max-width: 992px) {
  body[data-bsg-page="builder"]:not(.admin-page) .mobile-bottom-bar {
    z-index: 1200 !important;
  }
  body[data-bsg-page="builder"] #builderSaveModal.open {
    z-index: 2600 !important;
  }
  body[data-bsg-page="builder"] #builderSaveModal .modal {
    max-height: 92dvh;
    overflow-y: auto;
  }
}

@media (max-width: 992px) {
  body[data-bsg-page="builder"] .mybuild-panel .mybuild-head {
    flex-wrap: wrap;
    gap: 7px;
  }
  body[data-bsg-page="builder"] .mybuild-panel .mybuild-head h3 {
    flex: 1;
    min-width: 120px;
  }
  body[data-bsg-page="builder"] #builderSaveModal.open {
    position: fixed !important;
    inset: 0 !important;
    display: flex !important;
  }
}

/* RAM card: never let a long motherboard-spec badge crush the Persian title
   into one-character lines on narrow screens. Capacity belongs below items. */
@media (max-width: 992px) {
  body[data-bsg-page="builder"] .builder-slot-card .bsc-title--ram {
    flex: 1 1 auto;
    min-width: max-content !important;
    white-space: nowrap !important;
    word-break: keep-all !important;
    overflow-wrap: normal !important;
  }
  body[data-bsg-page="builder"] .builder-slot-card .bsc-capacity-info {
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 7px 13px;
  }
  body[data-bsg-page="builder"] .builder-slot-card .bsc-capacity-info .bsc-cap-item {
    max-width: 100%;
    overflow-wrap: normal;
    word-break: keep-all;
    white-space: nowrap;
  }
}
