/* ==========================================================================
   topblat.ro — „Blatul tău în 3D”: blocul de SUB galeria produsului (partials/vizual3d.blade.php + js/vizual3d.js).
   Doar blatul, într-un studio neutru (degradeul de sub pânza transparentă), cu cote fine și rândul cu ce se vede.
   Galeria rămâne cum e (pătrată); blocul 3D e separat:
     - desktop (≥ 992 px): coloana din stânga, sub miniaturi; lipicios lângă calculator (omul vede blatul cât configurează);
     - telefon / tabletă (≤ 991 px): imediat DEASUPRA calculatorului (grid + order, calculatorul nu se mută în markup),
       lipit sus și compact (~34svh) cât omul lucrează la pasul 1 al calculatorului; la pasul 2 (datele de contact) se dezlipește.
   Se încarcă doar pe paginile cu blocul (produsele cu preț și cu textura plăcii). Sobru: fără umbre, fără pastile, fără linii.
   ========================================================================== */

.tbv { --tbv-sus: 80px; --tbv-g: 20px; min-width: 0; color: #1a1f1c; }
.tbv[hidden] { display: none !important; }

/* titlul și uneltele */
.tbv__cap { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 10px; }
.tbv__titlu { margin: 0; font-size: 20px; line-height: 1.25; font-weight: 700; color: var(--tb-verde, #0a5c48); letter-spacing: -.005em; }
.tbv__unelte { display: flex; gap: 6px; flex: 0 0 auto; }
.tbv__btn {
    display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 1px solid #8a9096; border-radius: 4px;   /* conturul: ≥ 3:1 față de alb și de scenă */
    background: #fff; color: #1a1f1c; cursor: pointer; transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}
.tbv__btn svg { display: block; }
.tbv__btn:hover { border-color: #1a1f1c; }
.tbv__btn:focus-visible { outline: 2px solid var(--tb-verde, #0a5c48); outline-offset: 2px; }
.tbv__btn[aria-pressed="true"] { background: var(--tb-verde, #0a5c48); border-color: var(--tb-verde, #0a5c48); color: #fff; }

/* scena: fundalul de studio (continuu, neutru, deschis); pânza 3D e transparentă peste el */
.tbv__scena {
    position: relative; overflow: hidden; aspect-ratio: 3 / 2; border-radius: 4px;   /* 3:2: blatul e lung și jos; rândul de sub scenă încape lângă calculator */
    background: #e6e4df radial-gradient(130% 95% at 50% 36%, #f4f3f0 0%, #eae8e4 50%, #dddad4 100%);
}
.tbv__scena canvas {
    position: absolute; inset: 0; display: block; width: 100% !important; height: 100% !important; max-width: none;
    touch-action: pan-y; cursor: grab; opacity: 0; transition: opacity .3s ease;   /* glisarea verticală derulează pagina (vizual3d.js: legaDerularea) */
}
.tbv__scena.is-gata canvas { opacity: 1; }
.tbv__scena canvas:active { cursor: grabbing; }
.tbv__scena canvas:focus { outline: none; }
.tbv__scena canvas:focus-visible { outline: 2px solid var(--tb-verde, #0a5c48); outline-offset: -2px; }
.tbv__stare {
    position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; margin: 0; padding: 16px;
    text-align: center; font-size: 14px; line-height: 20px; color: #4b5563;
}
.tbv__stare[hidden] { display: none; }

/* cotele: linii fine (SVG) și etichete sobre — lungimea pe față, lățimea (intervalul) pe capăt, cantul la detaliu */
.tbv-cote { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; overflow: visible; pointer-events: none; opacity: 0; transition: opacity .3s ease; }
.tbv__scena.is-gata .tbv-cote { opacity: 1; }
.tbv-cote path { fill: none; stroke: #2c302e; stroke-width: 1; stroke-linecap: butt; opacity: .78; }
/* vederea de sus pe placa închisă: conturul fin, deschis, al decupajelor (muchia tăiată), ca într-o schiță tehnică */
.tbv-cote path.tbv-cote__decupaj { stroke: #fff; opacity: .5; stroke-linejoin: round; }
.tbv-cota {
    position: absolute; left: 0; top: 0; z-index: 2; padding: 1px 6px; border-radius: 2px; background: rgba(255, 255, 255, .92);
    color: #1a1f1c; font-size: 12px; line-height: 16px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: .01em;
    white-space: nowrap; pointer-events: none; will-change: transform; visibility: hidden;
}
.tbv__scena:not(.is-gata) .tbv-cota { opacity: 0; }

/* ce se vede, cu denumirile din calculator; înălțimea e rezervată de la început (2 rânduri; pe telefon 3), ca la pornirea
   scenei și când rândul se lungește calculatorul de dedesubt să nu se miște */

/* fără WebGL: poza plăcii, cu un mesaj */
.tbv__poza { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; }
.tbv.is-indisponibil .tbv__unelte { display: none; }
.tbv.is-indisponibil .tbv__stare {
    inset: auto 0 0 0; z-index: 2; display: block; padding: 10px 14px; text-align: left; background: rgba(255, 255, 255, .94);
    color: #1a1f1c; font-size: 13px;
}

/* ecranul complet: tot blocul (titlul cu uneltele + scena + rândul de sub ea) */
.tbv:fullscreen { display: flex; flex-direction: column; padding: 14px 18px 18px; background: #fff; }
.tbv.is-ecran-plin, .tbv.is-ecran { display: flex; flex-direction: column; padding: 14px 18px calc(18px + env(safe-area-inset-bottom)); background: #fff; }
.tbv.is-ecran { position: fixed !important; inset: 0; z-index: 100000; margin: 0 !important; }
.tbv:fullscreen .tbv__scena { flex: 1 1 auto; aspect-ratio: auto; height: auto !important; min-height: 0; max-height: none; }
.tbv.is-ecran-plin .tbv__scena, .tbv.is-ecran .tbv__scena { flex: 1 1 auto; aspect-ratio: auto; height: auto !important; min-height: 0; max-height: none; }
.tbv.is-ecran-plin .tbv__cap, .tbv.is-ecran .tbv__cap { position: static; margin: 0 0 10px; }
html.tbv-fara-derulare { overflow: hidden; }

/* ---------- desktop: sub galerie, în coloana din stânga ---------- */
@media (min-width: 992px) {
    .tbp-sus--3d { grid-template-rows: auto 1fr; row-gap: 28px; }
    .tbp-sus--3d > .tbp-galerie { grid-column: 1; grid-row: 1; }
    .tbp-sus--3d > .tbv { grid-column: 1; grid-row: 2; align-self: start; }
    /* pe ecranele de laptop joase (768–860 px) scena e mai joasă (până la 250 px), ca blocul să încapă lângă calculator: cu
       calculatorul sus pe ecran, blocul se vede întreg (aceeași lățime, doar mai puțin înaltă; încadrarea camerei se calculează) */
    .tbp-sus--3d > .tbv:not(:fullscreen):not(.is-ecran):not(.is-ecran-plin) .tbv__scena { width: 100%; max-height: max(250px, calc(100vh - 500px)); }
    .tbp-sus--3d > .tbp-rezumat { grid-column: 2; grid-row: 1 / span 2; }
    /* 7–9 imagini: miniaturile pe un singur rând (puțin mai mici), nu pe două — blocul 3D urcă cu un rând (~86 px) și se vede
       întreg lângă calculator și la produsele cu multe poze (Neolith); de la 10 imagini rămân pe două rânduri */
    .tbp-sus--3d .tbp-galerie__miniaturi:has(> li:nth-child(7)):not(:has(> li:nth-child(10))) {
        grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 74px); gap: 10px;
    }
}
/* lipicios lângă calculator, sub header-ul lipit (80 px), doar dacă încape pe ecran */
@media (min-width: 992px) and (min-height: 660px) {
    .tbp-sus--3d > .tbv { position: sticky; top: calc(var(--tbv-sus) + 16px); }
}

/* ---------- telefon / tabletă: imediat deasupra calculatorului, lipit sus cât omul configurează ---------- */
@media (max-width: 991px) {
    .tbv { --tbv-sus: 61px; }
    /* coloana rezumatului își lasă copiii în grila paginii, ca blocul 3D să intre între butoane și calculator;
       distanțele rămân cele de până acum (în grilă marginile nu se mai suprapun, deci se scriu explicit) */
    .tbp-sus--3d { row-gap: 0; }
    .tbp-sus--3d > .tbp-galerie { margin-bottom: 26px; }
    .tbp-sus--3d > .tbp-rezumat { display: contents; }
    .tbp-sus--3d .tbp-stoc { justify-self: start; margin-top: 5px; }
    .tbp-sus--3d .tbp-titlu + .tbp-pret { margin-top: 8px; }
    .tbp-sus--3d .tbp-cta { margin-top: 0; }
    .tbp-sus--3d > .tbv { order: 1; }
    .tbp-sus--3d .tbc { order: 2; margin-top: 14px; }
    .tbp-sus--3d .tbp-meta { order: 3; }

    .tbp-sus--3d > .tbv {
        position: sticky; top: var(--tbv-sus); z-index: 20; margin: 24px calc(-1 * var(--tbv-g)) 0; padding: 8px var(--tbv-g) 8px;
        background: #fff;
    }
    /* la pasul 2 (rezultatul și datele de contact), cât tastatura nu lasă loc sub bloc, pe ecranele joase (telefonul ținut
       orizontal: blocul + antetul + bara de jos ar acoperi calculatorul; is-mic din vizual3d.js) și fără WebGL (acolo e doar
       poza plăcii): blocul nu se lipește */
    .tbp-sus--3d:has([data-tbc-panou="2"]:not([hidden])) > .tbv, .tbp-sus--3d > .tbv.is-liber,
    .tbp-sus--3d > .tbv.is-mic, .tbp-sus--3d > .tbv.is-indisponibil { position: relative; top: auto; }
    .tbv__scena { aspect-ratio: auto; height: 34vh; height: 34svh; min-height: 200px; max-height: 440px; }
    /* titlul și uneltele stau peste scenă (sus), ca blocul lipit să fie compact */
    .tbv__cap {
        position: absolute; top: 16px; left: calc(var(--tbv-g) + 10px); right: calc(var(--tbv-g) + 8px); z-index: 4; margin: 0;
        pointer-events: none;
    }
    .tbv__cap > * { pointer-events: auto; }
    .tbv__titlu { font-size: 15px; line-height: 20px; }
    .tbv__unelte { gap: 5px; }
    .tbv__btn { width: 40px; height: 40px; }
    .tbv-cota { font-size: 11.5px; line-height: 15px; padding: 0 5px; }
}
/* același lucru fără JS (înainte de pornirea scenei): telefonul ținut orizontal */
@media (max-width: 991px) and (max-height: 480px) {
    .tbp-sus--3d > .tbv { position: relative; top: auto; }
}
/* ecranul complet „din CSS” (iPhone, fără Fullscreen API pe elemente): peste antet, bara de jos și asistent, de sus până jos
   (regula de mai sus, „lipit sub antet”, are aceeași specificitate și ar câștiga: top 61 px, z-index 20) */
.tbp-sus--3d > .tbv.is-ecran, .tbv.is-ecran {
    position: fixed !important; inset: 0 !important; top: 0 !important; z-index: 100000 !important; margin: 0 !important;
    padding: calc(14px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
}
@media (max-width: 640px) {
    .tbv { --tbv-g: 16px; }
}
@media (max-width: 360px) {
    .tbv__titlu { font-size: 14px; }
    .tbv__btn { width: 36px; height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
    .tbv *, .tbv { transition: none !important; }
}
