/* Banco Shell — stili minimi per cornice riutilizzata (namespace shell-*)
   Classi UI (pl-*, viewer-*, banco-*, btn-ghost) vengono da:
   case-app.css, banco.css, banco-scene.css, tools/prima-lettura.css */

/* ── Overlay shell — parità .viewer-overlay (case-app.css) + Atto 1 mobile ── */
.shell-host.viewer-overlay.banco-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 6, 0.88);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}

/* Atto II in atto2.html: host montato su body, sopra viewer fascicolo (z 500) */
body > #banco-shell-host.shell-host.viewer-overlay.banco-overlay {
  z-index: 1100;
}

body.skin-rich .shell-host.viewer-overlay.banco-overlay {
  align-items: center;
  overflow-y: visible;
}

/* Dev lab: host dentro .lab-wrap riempie lo spazio sotto la dev-bar (chip-lab.html) */
.lab-wrap > .shell-host.viewer-overlay.banco-overlay {
  position: absolute;
  inset: 0;
}

/* ── banco-body: flex column per inventory (sopra) + pl-stage (assoluto dietro) ── */
.shell-banco-body {
  display: flex;
  flex-direction: column;
}

/* ── Stage: host / frame / module ── */
.shell-stage-host {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
}

.shell-stage-frame {
  position: absolute;
  top: var(--shell-frame-top, 0%);
  left: var(--shell-frame-left, 0%);
  width: var(--shell-frame-width, 100%);
  height: var(--shell-frame-height, 100%);
  transform: rotate(var(--shell-frame-rotation, 0deg));
  transform-origin: center;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.shell-stage-module {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* ── Sfondo custom (override scrivania-scheda-bg.png su banco-scene-plate) ── */
.shell-custom-bg {
  background-image: var(--shell-bg-desktop) !important;
}

@media (max-width: 700px) {
  /* Mobile: host full-screen. Annulla la regola desktop (padding:1rem/justify-center)
     che trapelava su Atto 1 classic. inset:0 RESTA (così il lab .lab-wrap si
     dimensiona dal suo contenitore, non da 100dvh). */
  .shell-host.viewer-overlay.banco-overlay {
    padding: 0;
    align-items: flex-start;
    justify-content: flex-start;
    overflow: hidden;
  }
  /* La card riempie l'host con percentuali, NON 100vw/100dvh: su iOS Safari le
     unità viewport sforavano di qualche px (bordi fuori schermo). */
  .shell-host.viewer-overlay.banco-overlay .viewer-card.banco-card {
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
    border-width: 0 !important;
  }
  /* Solo host reale di pagina (fisso su body): altezza = viewport visibile (dvh),
     così il fondo non finisce sotto la barra URL di iOS. Il lab resta inset:0. */
  body > #banco-shell-host.shell-host.viewer-overlay.banco-overlay {
    height: 100svh;
    height: 100dvh;
  }
  .shell-custom-bg {
    background-image: var(--shell-bg-mobile, var(--shell-bg-desktop)) !important;
  }
  /* Catena flex mobile: ogni nodo intermedio deve poter cedere altezza */
  .shell-banco-body {
    min-height: 0;
  }
  .shell-stage-host {
    min-height: 0;
  }
}

/* ── Inventario / strumenti / lente — base condivisa dello shell ──
   Promosse da tools/prima-lettura.css per rendere BancoShell CSS-autonomo
   (atto2.html non carica prima-lettura.css). Gli override mobile restano in
   banco-scene.css (@media): in atto2.html banco-shell.css è caricato PRIMA di
   banco-scene.css, quindi su mobile vincono gli override di layout. */

/* Token offset lente letti da readLenteOffsets() su .pl-stage */
.pl-stage {
  --lente-offset-x-desktop: 30px;
  --lente-offset-y-desktop: -55px;
  --lente-offset-x-mobile: 40px;
  --lente-offset-y-mobile: -90px;
}

.pl-inventory {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1rem;
  background: linear-gradient(180deg, rgba(14, 9, 5, 0.92) 0%, rgba(8, 5, 3, 0.96) 100%);
  border-bottom: 1px solid rgba(185, 161, 116, 0.22);
  flex-shrink: 0;
  z-index: 25;
  position: relative;
}
.pl-tool {
  appearance: none;
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-main);
  background: rgba(185, 161, 116, 0.06);
  border: 1px solid rgba(185, 161, 116, 0.32);
  padding: 0.45rem 0.65rem;
  min-width: 48px;
  min-height: 48px;
  cursor: pointer;
  transition: background 160ms, border-color 160ms, box-shadow 160ms;
}
.pl-tool:hover:not(:disabled) {
  background: rgba(185, 161, 116, 0.12);
  border-color: rgba(185, 161, 116, 0.55);
}
.pl-tool.is-active {
  background: rgba(183, 131, 59, 0.18);
  border-color: var(--amber);
  box-shadow: 0 0 8px rgba(183, 131, 59, 0.35) inset;
  color: var(--amber);
}
.pl-tool.is-locked,
.pl-tool:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.pl-tool-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}
.pl-tool-icon-img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.pl-tool-icon-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}
.pl-tool-icon:has(.pl-tool-icon-img) .pl-tool-icon-fallback {
  display: none;
}
.pl-tool-label {
  font-weight: 500;
  white-space: nowrap;
}

.pl-handedness-toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  color: rgba(185, 161, 116, 0.72);
  background: rgba(185, 161, 116, 0.05);
  border: 1px solid rgba(185, 161, 116, 0.22);
  border-radius: 50%;
  cursor: pointer;
  transition: color 160ms, border-color 160ms, background 160ms;
}
.pl-handedness-toggle:hover {
  color: var(--amber);
  border-color: rgba(183, 131, 59, 0.45);
  background: rgba(183, 131, 59, 0.1);
}
.pl-handedness-toggle.is-left {
  color: var(--amber);
  border-color: rgba(183, 131, 59, 0.45);
}
.pl-handedness-icon {
  display: block;
  width: 18px;
  height: 18px;
  fill: currentColor;
  transform-origin: center;
  transition: transform 160ms ease-out;
}
.pl-handedness-toggle.is-left .pl-handedness-icon {
  transform: scaleX(-1);
}

.pl-lente-cursor {
  position: absolute;
  width: 140px;
  height: 140px;
  margin-left: -70px;
  margin-top: -70px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 140ms ease-out;
  z-index: 10;
}
.pl-lente-cursor.is-visible {
  opacity: 1;
}
.pl-lente-cursor-glass {
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: 50%;
  border: 2px solid rgba(183, 131, 59, 0.85);
  background: radial-gradient(circle at 35% 30%, rgba(245, 237, 216, 0.12) 0%, rgba(245, 237, 216, 0.02) 55%, transparent 100%);
  box-shadow:
    0 0 0 1px rgba(14, 9, 5, 0.5),
    0 8px 22px rgba(0, 0, 0, 0.45),
    inset 0 0 10px rgba(255, 255, 255, 0.08);
  pointer-events: none;
}
.pl-lente-magnifier {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: 50%;
  overflow: hidden;
  background: #0e0905;
  isolation: isolate;
  contain: paint;
  clip-path: circle(50% at 50% 50%);
  -webkit-clip-path: circle(50% at 50% 50%);
}
.pl-lente-magnifier-img {
  position: absolute;
  max-width: none;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  border-radius: 0;
  box-shadow: none;
  border: none;
  outline: none;
  clip-path: none;
  -webkit-clip-path: none;
}

@media (prefers-reduced-motion: reduce) {
  .pl-lente-cursor,
  .pl-tool,
  .pl-handedness-toggle,
  .pl-handedness-icon {
    transition: none !important;
    animation: none !important;
  }
}

/* ── Lettera angolo ── */
.shell-letter {
  position: absolute;
  z-index: 15;
  appearance: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  min-width: 44px;
  min-height: 44px;
  background: rgba(14, 9, 5, 0.75);
  border: 1px solid rgba(183, 131, 59, 0.45);
  border-radius: 2px;
}

.shell-letter img {
  width: 30px;
  height: auto;
  display: block;
  pointer-events: none;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.6));
  transition: transform 160ms ease-out, filter 160ms ease-out;
}

.shell-letter:hover img,
.shell-letter:focus-visible img {
  transform: scale(1.06);
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.75));
}

/* [hidden] deve vincere su display:inline-flex: setLetterVisible(false)
   altrimenti non nasconde mai la lettera (bug presente anche in Atto 2) */
.shell-letter[hidden] { display: none; }

.shell-letter--bottom-left { left: 0.65rem; bottom: 0.65rem; }
.shell-letter--bottom-right { right: 0.65rem; bottom: 0.65rem; }
.shell-letter--top-left { left: 0.65rem; top: 0.65rem; }
.shell-letter--top-right { right: 0.65rem; top: 0.65rem; }

/* ── Toast ── */
.shell-toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%) translateY(calc(100% + 2rem));
  z-index: 5000;
  max-width: min(92vw, 340px);
  padding: 0.6rem 0.85rem;
  font-family: var(--font-mono, 'IBM Plex Mono', Consolas, monospace);
  font-size: 9px;
  letter-spacing: 0.08em;
  line-height: 1.55;
  text-align: center;
  border: 1px solid rgba(185, 161, 116, 0.12);
  background: rgba(23, 19, 15, 0.97);
  color: #ede6d8;
  visibility: hidden;
  pointer-events: none;
  transition: transform 320ms ease, visibility 320ms ease;
}

.shell-toast.is-visible {
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.shell-toast.is-error {
  border-color: rgba(200, 80, 80, 0.55);
  background: rgba(28, 12, 12, 0.97);
  color: #f0dede;
}

.shell-toast.is-success {
  border-color: rgba(90, 180, 100, 0.45);
  background: rgba(18, 42, 32, 0.97);
  color: var(--success-text, #5A9A74);
}

.shell-stage-hint.success {
  border-color: rgba(90, 180, 100, 0.45);
  background: rgba(18, 42, 32, 0.97);
  color: var(--success-text, #5A9A74);
}

/* Hint persistente sul banco — stile toast, sopra i messaggi effimeri */
.shell-stage-hint {
  z-index: 5100;
  pointer-events: none;
  bottom: 4.75rem;
}

.shell-host.banco-overlay .shell-stage-hint.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Chrome rows ── */
.banco-chrome-row:empty {
  display: none;
}

.shell-chrome-commands {
  gap: 0.5rem;
}

.shell-chrome-commands .btn-ghost.is-primary {
  border-color: var(--amber, #b7833b);
  color: var(--amber, #b7833b);
}

.shell-chrome-machinery {
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ── #6 Desktop: toast e hint del banco più grandi/leggibili ── */
@media (min-width: 701px) {
  .shell-toast,
  .shell-stage-hint {
    font-size: 13px;
    letter-spacing: 0.06em;
    line-height: 1.6;
    padding: 0.9rem 1.3rem;
    max-width: min(90vw, 460px);
  }
}

/* ── #2 Mobile: barra comandi a capo (non tagliata a destra) ── */
@media (max-width: 700px) {
  .banco-chrome-row.shell-chrome-commands {
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 0.4rem;
  }
}

/* ── #5 Mobile: hint/banner in alto sotto la barra tool (non sopra i comandi) ── */
@media (max-width: 700px) {
  .shell-stage-hint {
    top: calc(env(safe-area-inset-top, 0px) + 7rem);
    bottom: auto;
  }
}

/* ── Calibratore frame (lab) ── */
.shell-stage-frame.lab-cal-active {
  outline: 2px solid rgba(255, 90, 60, 0.95);
  outline-offset: -2px;
  z-index: 22;
  cursor: move;
  touch-action: none;
}

.lab-cal-handles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.lab-cal-label {
  position: absolute;
  top: -1.35rem;
  left: 0;
  font-size: 8px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ff8a65;
  pointer-events: none;
  white-space: nowrap;
}

.lab-cal-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #ff8a65;
  border: 2px solid #1a0f08;
  border-radius: 2px;
  pointer-events: auto;
  touch-action: none;
  z-index: 4;
}

.lab-cal-handle--nw { top: -7px; left: -7px; cursor: nwse-resize; }
.lab-cal-handle--ne { top: -7px; right: -7px; cursor: nesw-resize; }
.lab-cal-handle--sw { bottom: -7px; left: -7px; cursor: nesw-resize; }
.lab-cal-handle--se { bottom: -7px; right: -7px; cursor: nwse-resize; }
