/* Phone and touch layout, loaded last so it settles the sizes for every module.
   Rules: every control is at least 44px tall, nothing scrolls the page sideways, and an open bottom sheet
   never hides the van. The 3D view (or the 2D plan) shrinks to the part of the screen the sheet leaves free. */

.vb-rent { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; height: 34px; border-radius: 8px; border: 1px solid var(--vb-accent); color: var(--vb-accent); font-weight: 700; font-size: 12.5px; text-decoration: none; white-space: nowrap; flex: none; }
.vb-rent:hover { background: var(--vb-accent); color: var(--vb-on-accent); }
.vb-sheet-head { display: none; }
.vb-embed .vb-rent span { display: none; }
.vb-embed .vb-rent { padding: 0 9px; }

@media (max-width: 860px), (max-width: 960px) and (max-height: 500px) {
  :root { --vb-sheet-h: 46dvh; --vb-tabbar-h: 58px; --vb-stats-h: 44px; }
  html, body { overflow: hidden; max-width: 100%; }
  .vb-app { max-width: 100vw; overflow: hidden; }

  /* header: name and the rental link on the first row, the three views across the second */
  .vb-header { flex-wrap: wrap; gap: 4px 8px; padding: 4px 8px 6px; }
  .vb-brand { order: 0; flex: 1 1 0; min-height: 44px; }
  .vb-brand-text strong { font-size: 14px; overflow: visible; }
  .vb-brand { flex: 1 0 auto; }
  .vb-header-right { order: 1; flex: none; align-items: center; }
  .vb-modes { order: 2; flex: 1 1 100%; }
  .vb-mode { flex: 1 1 0; justify-content: center; min-height: 44px; padding: 6px 4px; }
  .vb-rent { height: 44px; padding: 0 8px; gap: 5px; font-size: 12px; flex: 0 1 auto; min-width: 0; overflow: hidden; }
  .vb-header-right .vb-icon-btn { display: none; } /* light / dark moves into the View menu on a phone */
  .vb-embed .vb-header-right .vb-icon-btn { display: inline-flex; }
  .vb-embed .vb-header { flex-wrap: nowrap; }
  .vb-embed .vb-modes { order: 0; flex: 1 1 0; }

  /* toolbar and bars */
  .vb-toolbar { padding: 2px 6px; gap: 2px; -webkit-overflow-scrolling: touch; touch-action: pan-x; }
  .vb-tool, .vb-icon-btn { min-width: 44px; width: auto; height: 44px; min-height: 44px; }
  .vb-icon-btn { width: 44px; }
  .vb-tool-select { height: 44px; min-height: 44px; font-size: 14px; }
  .vb-stats { height: var(--vb-stats-h); min-height: var(--vb-stats-h); touch-action: pan-x; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .vb-stats::-webkit-scrollbar { display: none; }
  .vb-widget { min-height: 44px; }
  .vb-tabs { height: var(--vb-tabbar-h); padding: 3px 6px; touch-action: pan-x; }
  .vb-tab { min-width: 62px; min-height: 50px; padding: 6px 4px 4px; }

  /* bottom sheets */
  .vb-sidebar.is-open .vb-panels { display: flex; flex-direction: column; }
  .vb-panels, .vb-inspector { bottom: calc(var(--vb-tabbar-h) + env(safe-area-inset-bottom)); height: var(--vb-sheet-h); max-height: var(--vb-sheet-h); transition: height 0.18s ease; }
  .vb-inspector { height: var(--vb-sheet-h); padding-top: 6px; }
  .vb-app.vb-sheet-tall .vb-panels { height: 82dvh; max-height: 82dvh; }
  .vb-panel { flex: 1 1 0; min-height: 0; height: auto; }
  .vb-sheet-head { order: -1; flex: none; display: flex; align-items: center; gap: 4px; min-height: 48px; padding: 0 6px 0 14px; border-bottom: 1px solid var(--vb-border); position: relative; touch-action: none; }
  .vb-sheet-grip { position: absolute; left: 50%; top: 6px; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--vb-border); }
  .vb-sheet-title { flex: 1; font-size: 14px; }

  /* the van stays in view above an open sheet */
  .vb-app:has(.vb-sidebar.is-open) .vb-view3d,
  .vb-app:has(.vb-sidebar.is-open) .vb-labels,
  .vb-app:has(.vb-sidebar.is-open) .vb-blueprint,
  .vb-app:has(.vb-inspector.is-open) .vb-view3d,
  .vb-app:has(.vb-inspector.is-open) .vb-labels,
  .vb-app:has(.vb-inspector.is-open) .vb-blueprint { bottom: calc(var(--vb-sheet-h) - var(--vb-stats-h)); height: auto; }
  .vb-app:has(.vb-sidebar.is-open) .vb-selbar,
  .vb-app:has(.vb-inspector.is-open) .vb-selbar { bottom: calc(var(--vb-sheet-h) - var(--vb-stats-h) + 6px); }

  /* 44px touch targets everywhere */
  button, select, summary, a.vb-btn, a.vb-buy, [role="button"] { min-height: 44px !important; }
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]) { min-height: 44px !important; font-size: 16px; }
  input[type="color"] { min-height: 44px !important; min-width: 48px; }
  input[type="range"] { min-height: 44px; }
  input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; flex: none; }
  label:has(> input[type="checkbox"]), label:has(> input[type="radio"]) { min-height: 44px; display: flex; align-items: center; gap: 8px; }
  textarea { font-size: 16px; }
  .vb-link { display: inline-flex; align-items: center; }
  a:not(.vb-btn):not(.vb-buy):not(.vb-rent) { display: inline-flex; align-items: center; min-height: 44px; }
  button, a.vb-buy, a.vb-btn { min-width: 44px; }
  small, .vb-chip, .vb-menu-title { font-size: 11.5px !important; }
  .vb-buy, .vb-buy-compact { padding: 0 12px; font-size: 13px; }
  .vb-btn, .vb-btn-small { padding-top: 0; padding-bottom: 0; }
  .vb-selbtn { min-width: 46px; justify-content: center; }
  .vb-menu-item { min-height: 46px; }
  .vb-muted, .vb-chip, .vb-field, .vb-disclosure { font-size: 12.5px; }
  .vb-section-title, .vb-widget-label { font-size: 11px; }

  /* dialogs fill the phone */
  .vb-overlay { padding: 8px; align-items: flex-end; }
  .vb-modal, .vb-modal-wide { width: 100%; max-height: calc(100dvh - 16px - env(safe-area-inset-top)); }
  .vb-modal-foot { flex-wrap: wrap; }
  .vb-popover { max-width: calc(100vw - 16px); }
  .vb-toasts { left: 8px; right: 8px; max-width: none; align-items: stretch; }
}

/* ==== added in fix round 1 ==================================================================================== */

/* rental link: full label normally, a short visible label in embed mode (never an icon alone) */
.vb-embed .vb-rent span { display: inline; }
.vb-embed .vb-rent { padding: 0 10px; }
.vb-embed .vb-header::before { content: "Virtual Van Builder"; font-weight: 700; font-size: 13px; white-space: nowrap; margin-right: 4px; }
@media (max-width: 720px) { .vb-embed .vb-header::before { display: none; } }

/* toasts sit below the "Get this built" button instead of under it */
.vb-toasts { top: 58px; }
.vb-stage:has(.vb-hint:not([hidden])) .vb-toasts { top: 98px; }

/* rotation: quarter turns or any typed angle */
.vb-rot-row { display: flex; align-items: center; gap: 6px; }
.vb-rot-row > span:first-child { flex: 1; }
.vb-rot-row .vb-select { width: 84px; }
.vb-rot-row .vb-rot-free { width: 64px; text-align: right; }
.vb-insp-actions .vb-btn { white-space: normal; text-align: left; line-height: 1.2; }
.vb-inspector .vb-btn { max-width: 100%; white-space: normal; height: auto; min-height: 30px; }

/* 2D plan layers */
.vb-bp-layers { position: absolute; left: 10px; top: 10px; z-index: 4; display: flex; gap: 4px; flex-wrap: wrap; max-width: calc(100% - 190px); }
.vb-bp-layer { border: 1px solid var(--vb-border); background: var(--vb-surface); color: var(--vb-muted); border-radius: 999px; padding: 5px 11px; font-size: 12px; font-weight: 600; white-space: nowrap; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); text-decoration: line-through; }
.vb-bp-layer[aria-pressed="true"] { color: var(--vb-text); border-color: var(--vb-accent); text-decoration: none; background: color-mix(in srgb, var(--vb-accent) 12%, var(--vb-surface)); }
.vb-stage:has(.vb-bp-layers:not([hidden])) .vb-hint { top: 48px; }

/* scroll hints: a fade where a bar has more to the side */
.vb-tabs.vb-more-right, .vb-stats.vb-more-right { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 34px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 34px), transparent); }
.vb-tabs.vb-more-left, .vb-stats.vb-more-left { -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 34px), transparent); mask-image: linear-gradient(to left, #000 calc(100% - 34px), transparent); }
.vb-tabs.vb-more-left.vb-more-right, .vb-stats.vb-more-left.vb-more-right { -webkit-mask-image: linear-gradient(to right, transparent, #000 34px, #000 calc(100% - 34px), transparent); mask-image: linear-gradient(to right, transparent, #000 34px, #000 calc(100% - 34px), transparent); }
.vb-tool-more { display: none; }
.vb-toolbar.vb-more-right .vb-tool-more, .vb-toolbar.vb-more-left .vb-tool-more { display: inline-flex; position: sticky; right: 0; order: 99; margin-left: auto; flex: none; gap: 2px; padding: 0 6px 0 22px; font-size: 12px; font-weight: 700; color: var(--vb-accent); background: linear-gradient(to right, transparent, var(--vb-surface) 18px); border-radius: 0; }
.vb-toolbar.vb-more-left:not(.vb-more-right) .vb-tool-more .vb-icon { transform: rotate(180deg); }
.calc-zoom { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.calc-assumed { font-size: 10.5px; }

@media (max-width: 860px), (max-width: 960px) and (max-height: 500px) {
  /* all eight tabs fit across a phone; long names wrap to a second line instead of being cut */
  .vb-tabs { gap: 0; padding: 3px 2px; }
  .vb-tab { min-width: 0; flex: 1 1 0; padding: 5px 1px 3px; font-size: 10px; }
  .vb-tab-label { white-space: normal; overflow: visible; text-overflow: clip; line-height: 1.05; text-align: center; }
  .vb-toasts { top: 58px; }
  .vb-stage:has(.vb-hint:not([hidden])) .vb-toasts { top: 108px; }
  .vb-bp-layers { left: 6px; top: 6px; max-width: calc(100% - 150px); }
  .vb-bp-layer { min-height: 36px !important; padding: 4px 9px; font-size: 11.5px; }
  .vb-stage:has(.vb-bp-layers:not([hidden])) .vb-hint { top: 92px; }
  /* the request form comes before the long summary on a phone */
  .flow-quote-form { order: -1; }
  .calc-zoom { margin-left: 0; }
  .vb-label { font-size: 10.5px; padding: 1px 4px; }
}

/* ---- phone turned sideways: one-line header, tabs down the left edge, panels as a side sheet --------------- */
@media (max-width: 960px) and (max-height: 500px) and (orientation: landscape) {
  :root { --vb-rail-l: 56px; --vb-side-w: 44vw; --vb-stats-h: 32px; }
  .vb-app { display: grid; grid-template-columns: var(--vb-rail-l) minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto; }
  .vb-header { grid-column: 1 / -1; grid-row: 1; flex-wrap: nowrap; padding: 2px 8px; min-height: 40px; gap: 8px; }
  .vb-brand { flex: 0 1 auto; min-height: 0; min-width: 0; }
  .vb-brand-text strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
  .vb-modes { order: 1; flex: 0 1 auto; margin-left: auto; }
  .vb-mode { min-height: 36px !important; padding: 2px 10px; flex: 0 0 auto; }
  .vb-header-right { order: 2; }
  .vb-rent { height: 36px; min-height: 36px !important; }
  .vb-toolbar { grid-column: 1 / -1; grid-row: 2; padding: 0 6px; }
  .vb-tool, .vb-icon-btn, .vb-tool-select { height: 38px; min-height: 38px !important; }
  .vb-sidebar { grid-column: 1; grid-row: 3 / span 2; order: 0; border-top: 0; border-right: 1px solid var(--vb-border); padding-bottom: 0; min-height: 0; overflow: hidden; }
  .vb-tabs { flex-direction: column; width: var(--vb-rail-l); height: 100%; overflow-x: hidden; overflow-y: auto; padding: 2px; touch-action: pan-y; -webkit-mask-image: none !important; mask-image: none !important; }
  .vb-tab { flex: none; width: 100%; min-height: 44px; padding: 4px 1px 3px; }
  .vb-stage { grid-column: 2; grid-row: 3; }
  .vb-stats { grid-column: 2; grid-row: 4; height: var(--vb-stats-h); min-height: var(--vb-stats-h); }
  .vb-widget { min-height: 0; padding: 1px 10px; flex-direction: row; align-items: center; gap: 6px; font-size: 12px; }
  .vb-widget, .vb-widget * { min-height: 0 !important; }

  /* side sheets instead of bottom sheets: the van stays in view beside them */
  .vb-panels, .vb-inspector { top: 82px; bottom: 0; left: var(--vb-rail-l); right: auto; width: var(--vb-side-w); height: auto; max-height: none; border-radius: 0 14px 0 0; border-top: 1px solid var(--vb-border); border-right: 1px solid var(--vb-border); }
  .vb-app.vb-sheet-tall .vb-panels { height: auto; max-height: none; width: 62vw; }
  .vb-inspector { left: auto; right: 0; width: 42vw; border-radius: 14px 0 0 0; border-right: 0; border-left: 1px solid var(--vb-border); overflow-y: auto; }
  .vb-sheet-head { min-height: 40px; }
  .vb-app:has(.vb-sidebar.is-open) .vb-view3d,
  .vb-app:has(.vb-sidebar.is-open) .vb-labels,
  .vb-app:has(.vb-sidebar.is-open) .vb-blueprint { left: var(--vb-side-w); right: 0; bottom: 0; width: auto; height: auto; }
  .vb-app.vb-sheet-tall:has(.vb-sidebar.is-open) .vb-view3d,
  .vb-app.vb-sheet-tall:has(.vb-sidebar.is-open) .vb-labels,
  .vb-app.vb-sheet-tall:has(.vb-sidebar.is-open) .vb-blueprint { left: 62vw; }
  .vb-app:has(.vb-inspector.is-open) .vb-view3d,
  .vb-app:has(.vb-inspector.is-open) .vb-labels,
  .vb-app:has(.vb-inspector.is-open) .vb-blueprint { left: 0; right: 42vw; bottom: 0; width: auto; height: auto; }
  .vb-app:has(.vb-sidebar.is-open) .vb-selbar { bottom: 6px; left: calc(var(--vb-side-w) + (100% - var(--vb-side-w)) / 2); max-width: calc(100% - var(--vb-side-w) - 12px); }
  .vb-app:has(.vb-inspector.is-open) .vb-selbar { bottom: 6px; left: calc((100% - 42vw) / 2); max-width: calc(100% - 42vw - 12px); }
  .vb-app:has(.vb-sidebar.is-open) .vb-bp-layers { left: calc(var(--vb-side-w) + 6px); }
  .vb-app:has(.vb-sidebar.is-open) .vb-hint { left: calc(var(--vb-side-w) + (100% - var(--vb-side-w)) / 2); max-width: calc(100% - var(--vb-side-w) - 16px); }
  .vb-overlay { align-items: center; }
  .vb-modal, .vb-modal-wide { max-height: calc(100dvh - 12px); }
  .calc-drawer { left: var(--vb-rail-l); }
  .flow-quote { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .flow-quote-form { order: 0; }
}

/* ==== added in fix round 2 ==================================================================================== */
@media (max-width: 860px), (max-width: 960px) and (max-height: 500px) {
  /* Units moves into Options; the Shopping list and Drawings buttons come first, where a thumb finds them */
  .vb-toolbar .vb-tool-units { display: none; }
  .vb-toolbar > .vb-tool-modules { order: -1; }
  /* the "More" cue covered the control under it: the toolbar fades at the edge instead, like the tab bar */
  .vb-toolbar.vb-more-right .vb-tool-more, .vb-toolbar.vb-more-left .vb-tool-more { display: none; }
  .vb-toolbar.vb-more-right { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); }
  .vb-toolbar.vb-more-left { -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 40px), transparent); mask-image: linear-gradient(to left, #000 calc(100% - 40px), transparent); }
  .vb-toolbar.vb-more-left.vb-more-right { -webkit-mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent); mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent); }
  /* tab names never run into each other */
  .vb-tabs { gap: 1px; }
  .vb-tab { padding: 5px 1px 3px; font-size: 9px; }
  .vb-tab-label { overflow-wrap: normal; word-break: normal; hyphens: none; letter-spacing: -0.2px; max-width: 100%; }
  /* in the 2D plan, toasts sit below the layer buttons */
  .vb-stage:has(.vb-bp-layers:not([hidden])) .vb-toasts { top: 96px; }
}
