/* Studio foundation (package F): shared mounts, phone panel tabs, selection chip, toast and the z-index contract.
 * z-index contract: canvas auto · .studio-overlay 3 · #blueprint 4 · .addon-tray/.addon-instruction/#feature-tree 5 ·
 * .tools/.hint/#viewport-status/#selection-chip 6 · header 20 · phone sheet 40 · toggle pill 50 · #studio-toast 60 ·
 * header with open menu and drag ghost 100. Only transform and opacity animate. */
:root { --sf-navy: #1e3a5f; --sf-blue: #3d6bb4; --sf-sky: #b8d0ec; --sf-ink: #14314d; --sf-ease: cubic-bezier(.2,.9,.25,1.15); }

.blueprint[hidden], .panel-tabs[hidden], #selection-chip[hidden], #studio-toast[hidden],
#blueprint-toggle[hidden], #blueprint-print[hidden], #barn-code[hidden], #panel-features[hidden], #panel-customize[hidden] { display: none !important; }

/* ---- mounts inside #viewport ------------------------------------------------------------- */
.studio-overlay { position: absolute; inset: 0; z-index: 3; pointer-events: none; overflow: hidden; }
.blueprint { position: absolute; inset: 0; z-index: 4; }
.tools, .hint { z-index: 6; }
.addon-tray, .addon-instruction { z-index: 5; }
.viewport-status { position: absolute; z-index: 6; left: 30px; top: calc(var(--scene-title-bottom, 218px) + 8px); display: flex; flex-wrap: wrap; gap: 6px; max-width: min(420px, calc(100% - 260px)); pointer-events: none; }
.viewport-status > * { pointer-events: auto; }
.viewport-status:empty { display: none; }

/* ---- phone panel tabs (Customize / Features) ----------------------------------------------- */
.panel-tabs { display: none; }
html.studio-phone.has-features-tab .panel-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; position: sticky; top: 0; z-index: 2;
  margin: 0 0 8px; padding: 4px; border-radius: 16px; border: 1px solid #ffffffe0;
  background: linear-gradient(135deg, #f7fbfe, #e4eef6); box-shadow: inset 0 1px 0 white, 0 6px 16px #12304a14, 0 -24px 0 #edf5fa; /* the last shadow masks content scrolling under the sheet padding */
}
.panel-tabs button { min-height: 44px; touch-action: manipulation; border: 0; border-radius: 12px; background: transparent; box-shadow: none; font-weight: 650; font-size: 13px; color: var(--sf-ink); }
.panel-tabs button:hover { background: #ffffffc4; }
.panel-tabs button:active { transform: scale(.97); }
.panel-tabs button:focus-visible { outline: 3px solid #4d8ecc; outline-offset: 2px; }
.panel-tabs button[aria-selected="true"] { color: #fff; background: linear-gradient(150deg, #345979, #122f4b); box-shadow: 0 4px 11px #16365028, inset 0 1px 0 #ffffff35; }
html.studio-phone.has-features-tab #building-controls nav { top: var(--panel-tabs-h, 52px); }

/* Crossing to desktop always shows the inspector; the Features panel is phone-only. */
html:not(.studio-phone) #panel-customize { display: block !important; }
html:not(.studio-phone) #panel-features { display: none !important; }

/* Half-height sheet (blueprint taps) */
.studio-standalone.inspector-open.sheet-half #building-controls { max-height: 45dvh; }

/* ---- phone selection chip ----------------------------------------------------------------- */
#selection-chip {
  position: absolute; z-index: 6; left: 50%; bottom: calc(var(--inset-bottom, 140px) + 4px); transform: translateX(-50%);
  min-height: 44px; max-width: calc(100% - 32px); padding: 10px 18px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  border: 1px solid #e3f3ff; border-radius: 999px; color: #fff; font-weight: 600; font-size: 13px; touch-action: manipulation;
  background: linear-gradient(130deg, #2e5674f0, #102e46f2); box-shadow: 0 10px 28px #08253750, inset 0 1px 0 #ffffff55;
  animation: sf-rise .32s var(--sf-ease) both;
}
#selection-chip:hover { background: linear-gradient(130deg, #386584f2, #14354ff4); }
#selection-chip:active { transform: translateX(-50%) scale(.97); }
#selection-chip:focus-visible { outline: 3px solid var(--sf-sky); outline-offset: 3px; }

/* ---- "Show in 3D" inside the selection note (phones) --------------------------------------- */
.selected-note .show-in-3d { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 44px; margin-top: 10px; font-weight: 650; color: var(--sf-ink); touch-action: manipulation; }
.selected-note .show-in-3d:hover { border-color: #8fb0cc; }
.selected-note .show-in-3d:active { transform: scale(.98); }
.selected-note .show-in-3d:focus-visible { outline: 3px solid #4d8ecc; outline-offset: 2px; }

/* ---- stepper (studio.ui.stepper) ----------------------------------------------------------- */
.field.stepper .stepper-box { display: inline-flex; align-items: center; gap: 4px; }
.field.stepper .stepper-box input[type=number] { width: 64px; text-align: center; }
.field.stepper .stepper-box button { min-width: 44px; min-height: 44px; padding: 0; font-size: 18px; line-height: 1; touch-action: manipulation; }
.field.stepper .stepper-box button:active { transform: scale(.94); }
.field.stepper .stepper-box button:focus-visible { outline: 3px solid #4d8ecc; outline-offset: 2px; }
.field select[data-key="addition.type"], .field select[data-key="ui.side"] { width: 190px; max-width: 100%; }

/* Phone properties use full-width rows and real finger-sized controls. A 16px input also avoids
 * Safari zooming the sheet when a customer types a precise dimension. */
@media (max-width: 650px), (max-width: 1000px) and (max-height: 500px) {
  #inspector .field { align-items: stretch; flex-direction: column; gap: 6px; margin: 14px 0; }
  #inspector .field:has(input[type=checkbox]) { flex-direction: row; align-items: center; min-height: 44px; }
  #inspector .field input[type=number], #inspector .field input[type=text], #inspector .field select { width: 100%; min-height: 44px; font-size: 16px; }
  #inspector .field.stepper .stepper-box { display: grid; grid-template-columns: 44px minmax(0,1fr) 44px; width: 100%; }
  #inspector .field.stepper .stepper-box input[type=number] { width: 100%; min-width: 0; }
}

/* ---- field pulse (studio.focusField) ------------------------------------------------------- */
.field-pulse { position: relative; }
.field-pulse::after { content: ""; position: absolute; inset: -4px -6px; border-radius: 10px; pointer-events: none; box-shadow: 0 0 0 3px var(--sf-blue); animation: sf-pulse 1.2s ease-out both; }

/* ---- toast (studio.notify) ----------------------------------------------------------------- */
#studio-toast {
  position: fixed; z-index: 60; left: var(--toast-x, 50%); bottom: var(--toast-bottom, 120px); transform: translateX(-50%);
  max-width: min(460px, calc(100vw - 32px)); padding: 11px 16px; border-radius: 14px; font-size: 13px; line-height: 1.45; font-weight: 550;
  color: #fff; background: linear-gradient(130deg, #2b5372f2, #102c44f4); border: 1px solid #d9ecfa; box-shadow: 0 14px 40px #06243a55;
  pointer-events: auto; animation: sf-toast .3s var(--sf-ease) both;
}
#studio-toast[data-tone="warn"] { background: linear-gradient(130deg, #7a4a12f2, #4d2c08f4); border-color: #f6d9ae; }
html.studio-phone #studio-toast { left: 50%; bottom: calc(var(--inset-bottom-page, 96px) + 12px); }
html.studio-phone.inspector-open #studio-toast { bottom: calc(68dvh + 12px); }
html.studio-phone.inspector-open.sheet-half #studio-toast { bottom: calc(45dvh + 12px); }

@keyframes sf-rise { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes sf-toast { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes sf-pulse { 0% { opacity: 1; transform: scale(1.04); } 70% { opacity: .9; transform: scale(1); } 100% { opacity: 0; transform: scale(1); } }

@media (max-width: 650px), (max-width: 1000px) and (max-height: 500px) {
  .viewport-status { left: 18px; max-width: calc(100% - 200px); }
}
@media (prefers-reduced-motion: reduce) {
  #selection-chip, #studio-toast { animation: none; }
  .field-pulse::after { animation: none; transform: none; box-shadow: none; outline: 2px solid var(--sf-blue); outline-offset: 2px; }
  .panel-tabs button:active, #selection-chip:active, .selected-note .show-in-3d:active, .field.stepper .stepper-box button:active { transform: none; }
  #selection-chip:active { transform: translateX(-50%); }
}
