/* =========================
   LAYOUT BASE
   ========================= */

.sessao-main {
    position: relative;
    display: block;
    min-width: 0;
    min-height: 100vh;
    overflow: hidden;
}

.sessao-work-area {
    position: relative;
    width: 100%;
    height: 100vh;
    min-height: 0;
}

.sessao-mapa-area {
    position: absolute;
    inset: 0;
    min-width: 0;
    min-height: 0;
}

#viewport.viewport {
    position: absolute;
    inset: 0;
    overflow: auto;
    display: block;
    padding: 14px;
    touch-action: none;
}


/* =========================
   TOPBAR
   ========================= */

.sessao-topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;

    height: 46px;
    padding: 6px 10px;
    box-sizing: border-box;

    background: rgba(7, 10, 15, 0.72);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sessao-topbar-left,
.sessao-topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    min-width: 0;
}

.sessao-topbar-right {
    overflow: hidden;
}

.sessao-topbar-btn,
.sessao-badge {
    flex: 0 0 auto;
}

.sessao-topbar-btn {
    height: 34px;
    padding: 0 12px;
    border-radius: 9px;
    white-space: nowrap;
}

.sessao-badge {
    height: 34px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    font-size: 13px;
}

.sessao-topbar-btn.ativo {
    background: rgba(255, 255, 255, 0.14);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.10);
}


/* =========================
   PAINEL LATERAL
   ========================= */

.sessao-painel-lateral {
    position: absolute;
    top: 46px;
    left: 0;
    bottom: 0;
    width: 320px;
    min-width: 320px;
    z-index: 45;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;

    background: rgba(7, 10, 15, 0.72);
    backdrop-filter: blur(6px);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.4);
}

.sessao-painel-lateral.fechado {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

.sessao-painel-header h3 {
    color: rgba(255, 255, 255, 0.9);
}

.sessao-painel-acoes {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 0 8px 8px;
}

.sessao-painel-acoes button {
    min-height: 30px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.88);
    cursor: pointer;
}

.sessao-painel-acoes button:hover {
    background: rgba(80, 180, 255, 0.18);
    border-color: rgba(80, 180, 255, 0.34);
}

.mesa-menu-lista,
.mesa-mapa-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 8px 12px;
}

.mesa-menu-item,
.mesa-mapa-form button,
.mesa-mapa-form select {
    width: 100%;
    min-height: 36px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.9);
    font: inherit;
}

.mesa-menu-item {
    display: flex;
    align-items: center;
    padding: 0 10px;
    text-decoration: none;
    cursor: pointer;
}

button.mesa-menu-item {
    justify-content: flex-start;
}

.mesa-menu-item:hover,
.mesa-mapa-form button:hover {
    background: rgba(80, 180, 255, 0.18);
    border-color: rgba(80, 180, 255, 0.34);
}

.mesa-menu-item.perigo,
.mesa-mapa-form .perigo {
    border-color: rgba(255, 96, 96, 0.26);
    color: rgba(255, 190, 190, 0.95);
}

.mesa-mapa-form label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.72);
}

.mesa-mapa-form select {
    padding: 0 8px;
    background-color: rgba(18, 24, 30, 0.96);
    color: rgba(255, 255, 255, 0.92);
}

.mesa-mapa-form select option {
    background: #10161c;
    color: rgba(255, 255, 255, 0.92);
}

.mesa-mapa-form select option:checked {
    background: #1b6bd6;
    color: #fff;
}

.mesa-mapa-status {
    min-height: 18px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.66);
}


/* =========================
   MODO UI OCULTA
   ========================= */

body.ui-oculta .sessao-painel-lateral,
body.ui-oculta .workspace-topbar,
body.ui-oculta .workspace-actions,
body.ui-oculta .somente-mestre {
    display: none !important;
}

body.ui-oculta .sessao-topbar {
    height: 32px;
    padding: 4px 8px;
    background: rgba(7, 10, 15, 0.45);
}

body.ui-oculta .sessao-topbar-right {
    display: none;
}

body.ui-oculta .sessao-topbar-btn {
    height: 24px;
    padding: 0 8px;
    font-size: 12px;
}


/* =========================
   STAGE / MAPA / OVERLAYS
   ========================= */

#tabuleiroStage.tabuleiro-stage {
    position: relative;
    transform-origin: 0 0;
    overflow: visible;
}

#tabuleiro.tabuleiro,
#sessaoGridOverlay,
#sessaoCamadasOverlay {
    position: absolute;
    top: 0;
    left: 0;
}

#tabuleiro.tabuleiro {
    z-index: 1;
    transform-origin: 0 0;
}

#tabuleiro.tabuleiro,
#tabuleiro .slot,
#tabuleiro .slot.has-piece {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

#sessaoGridOverlay {
    z-index: 20;
    pointer-events: none;
    opacity: 0;
    transition: opacity 120ms ease;
}

#sessaoGridOverlay.ativo {
    opacity: 1;
}

#sessaoGridOverlay.grade-catalogo {
    background-image:
            linear-gradient(to right, rgba(80, 210, 255, 0.55) var(--sessao-grid-major-line, 2px), transparent var(--sessao-grid-major-line, 2px)),
            linear-gradient(to bottom, rgba(80, 210, 255, 0.55) var(--sessao-grid-major-line, 2px), transparent var(--sessao-grid-major-line, 2px)),
            linear-gradient(to right, rgba(80, 210, 255, 0.22) var(--sessao-grid-minor-line, 1px), transparent var(--sessao-grid-minor-line, 1px)),
            linear-gradient(to bottom, rgba(80, 210, 255, 0.22) var(--sessao-grid-minor-line, 1px), transparent var(--sessao-grid-minor-line, 1px));
    background-size:
            400px 400px,
            400px 400px,
            40px 40px,
            40px 40px;
    background-position: 0 0;
    box-shadow:
            inset 0 0 0 var(--sessao-grid-minor-line, 1px) rgba(80, 210, 255, 0.20),
            0 0 18px rgba(80, 210, 255, 0.12);
}

#sessaoGridOverlay.oculto {
    display: none;
}

#sessaoCamadasOverlay {
    z-index: 30;
    pointer-events: none;
}

.sessao-marco-zero {
    position: absolute;
    z-index: 25;
    width: 22px;
    height: 22px;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.sessao-marco-zero::before,
.sessao-marco-zero::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    background: rgba(255, 255, 255, 0.78);
    box-shadow: 0 0 10px rgba(80, 180, 255, 0.55);
    transform: translate(-50%, -50%);
}

.sessao-marco-zero::before {
    width: 22px;
    height: 2px;
}

.sessao-marco-zero::after {
    width: 2px;
    height: 22px;
}


/* =========================
   GRID GLOBAL DA SESSÃO
   ========================= */

.sessao-grid-canvas {
    position: absolute;
    inset: 0;
    background-image:
            linear-gradient(to right, rgba(80, 180, 255, 0.14) 1px, transparent 1px),
            linear-gradient(to bottom, rgba(80, 180, 255, 0.14) 1px, transparent 1px);
    background-size: 40px 40px;
    background-position: 0 0;
    box-shadow: inset 0 0 0 1px rgba(80, 180, 255, 0.08);
}

.sessao-grid-highlight {
    position: absolute;
    border: 2px solid rgba(80, 180, 255, 0.92);
    box-shadow:
            0 0 0 1px rgba(80, 180, 255, 0.25),
            0 0 18px rgba(80, 180, 255, 0.28),
            inset 0 0 18px rgba(80, 180, 255, 0.10);
    background: rgba(80, 180, 255, 0.10);
    border-radius: 8px;
    pointer-events: none;
}

.sessao-bolha-foco {
    position: absolute;
    pointer-events: none;
    border-radius: 999px;
    background: radial-gradient(
            circle,
            rgba(80, 180, 255, 0.18) 0%,
            rgba(80, 180, 255, 0.08) 45%,
            rgba(80, 180, 255, 0.00) 72%
    );
    filter: blur(2px);
    z-index: 19;
}


/* =========================
   CAMADAS SOLTAS / OVERLAY
   ========================= */

.sessao-camadas-overlay {
    z-index: 30;
    pointer-events: none;
}

.sessao-camadas-overlay .camada-overlay-wrapper,
#sessaoCamadasOverlay .camada-overlay-wrapper {
    pointer-events: auto;
}

.sessao-camadas-overlay .camada-overlay-wrapper img,
#sessaoCamadasOverlay .camada-overlay-wrapper img {
    user-select: none;
    -webkit-user-drag: none;
}

.camada-overlay-wrapper.dragando {
    opacity: 0.88;
    cursor: grabbing !important;
}

.camada-overlay-wrapper.selecionada-mapa,
.camada-layer.selecionada-mapa {
    filter:
            drop-shadow(0 0 6px rgba(80, 180, 255, 0.95))
            drop-shadow(0 0 14px rgba(80, 180, 255, 0.45));
}


/* =========================
   HANDLE DE REDIMENSIONAR
   ========================= */

.camada-resize-handle {
    position: absolute;
    width: 16px;
    height: 16px;
    right: -8px;
    bottom: -8px;
    border-radius: 999px;
    background: #00e5ff;
    box-shadow:
            0 0 0 2px rgba(7, 10, 15, 0.85),
            0 0 10px rgba(0, 229, 255, 0.75);
    cursor: nwse-resize;
    pointer-events: auto;
    z-index: 5;
}


/* =========================
   ÁRVORE DE CAMADAS
   ========================= */

.sessao-vis-no {
    margin-bottom: 8px;
}

.sessao-vis-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
}

.sessao-vis-row:hover {
    background: rgba(255, 255, 255, 0.12);
}

.sessao-vis-row.arrastando {
    opacity: 0.45;
}

.sessao-vis-row.nivel-2 {
    margin-left: 18px;
}

.sessao-vis-row-grupo {
    background: rgba(80, 180, 255, 0.10);
    border: 1px solid rgba(80, 180, 255, 0.16);
}

.sessao-vis-drop-target {
    outline: 2px solid rgba(80, 210, 255, 0.95);
    outline-offset: 2px;
    background: rgba(80, 210, 255, 0.18) !important;
}

.sessao-vis-drop-soltas {
    margin: 4px 8px 8px;
    padding: 7px 8px;
    border: 1px dashed rgba(255, 255, 255, 0.20);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.64);
    font-size: 12px;
    text-align: center;
}

.sessao-vis-folder-icon {
    width: 14px;
    flex: 0 0 auto;
    color: rgba(80, 210, 255, 0.95);
}

.sessao-vis-row.aberto {
    background: rgba(255, 255, 255, 0.08);
}

.sessao-vis-row.selecionado,
.sessao-vis-no.selecionado > .sessao-vis-row {
    box-shadow:
            0 0 0 2px rgba(80, 180, 255, 0.95),
            0 0 14px rgba(80, 180, 255, 0.45);
    background: rgba(80, 180, 255, 0.14);
}

.sessao-vis-row.selecionado:hover {
    background: rgba(80, 180, 255, 0.18);
}

.sessao-vis-titulo {
    background: none;
    border: 0;
    color: inherit;
    text-align: left;
    cursor: pointer;
    font: inherit;
    padding: 0;
    flex: 1;
}

.sessao-vis-titulo.sem-toggle {
    cursor: default;
    opacity: 0.9;
}

.sessao-vis-titulo-conteudo {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.sessao-vis-titulo-texto {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sessao-vis-acoes {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sessao-vis-filhos {
    margin-top: 4px;
}

.sessao-vis-filhos.fechado {
    display: none;
}

.sessao-vis-check {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    opacity: 0.9;
}

.sessao-vis-check input {
    width: 13px;
    height: 13px;
}

.sessao-vis-vazio {
    padding: 8px;
    opacity: 0.7;
}

.sessao-vis-thumb {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    object-fit: cover;
    flex: 0 0 auto;
    display: block;
    background: rgba(255, 255, 255, 0.06);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.sessao-vis-row.nivel-2 .sessao-vis-thumb {
    width: 22px;
    height: 22px;
    border-radius: 5px;
}

.sessao-vis-subgrupo {
    margin-top: 6px;
    margin-left: 18px;
}

.sessao-vis-subgrupo-titulo {
    font-size: 11px;
    opacity: 0.72;
    padding: 2px 8px 6px 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}


/* =========================
   AURA NO MAPA
   ========================= */

.slot.selecionada-mapa {
    box-shadow:
            0 0 0 2px rgba(80, 180, 255, 0.95),
            0 0 14px rgba(80, 180, 255, 0.35);
    border-radius: 8px;
}


/* =========================
   DRAG LEGADO / COMPAT
   ========================= */

.camada-layer.dragando {
    opacity: 0.6;
    transform: scale(1.05);
    cursor: grabbing;
}

.camada-layer.camada-solta {
    position: absolute;
    inset: 0;
    z-index: 30;
    pointer-events: auto;
}


/* =========================
   HUD
   ========================= */

#sessaoHud {
    position: fixed;
    bottom: 8px;
    right: 10px;
    z-index: 80;

    display: flex;
    gap: 10px;
    align-items: center;

    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);

    background: rgba(0, 0, 0, 0.35);
    padding: 4px 8px;
    border-radius: 6px;
    backdrop-filter: blur(4px);
}

#sessaoHud span {
    white-space: nowrap;
}


/* =========================
   LOADING
   ========================= */

.sessao-loading {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(7, 10, 15, 0.72);
    backdrop-filter: blur(4px);
}

.sessao-loading.oculto {
    display: none;
}

.sessao-loading-card {
    min-width: 180px;
    padding: 18px 20px;
    border-radius: 12px;
    background: rgba(20, 24, 31, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    text-align: center;
}

.sessao-loading-spinner {
    width: 34px;
    height: 34px;
    margin: 0 auto 10px auto;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.16);
    border-top-color: #39d0ff;
    animation: sessao-spin 0.9s linear infinite;
}

.sessao-loading-texto {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
}

@keyframes sessao-spin {
    to {
        transform: rotate(360deg);
    }
}
.sessao-vis-texto {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sessao-vis-subtitulo-texto {
    font-size: 11px;
    opacity: 0.72;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* =========================
   RESPONSIVO
   ========================= */

@media (max-width: 768px) {
    .sessao-topbar {
        height: auto;
        flex-direction: column;
        align-items: stretch;
        padding: 4px 6px;
        gap: 4px;
    }

    .sessao-topbar-left,
    .sessao-topbar-right {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 6px;
    }

    .sessao-topbar-btn,
    .sessao-badge {
        height: 28px;
        font-size: 11px;
        padding: 0 8px;
    }

    #sessaoTopbarTitulo {
        font-size: 13px;
        text-align: center;
        width: 100%;
        display: block;
    }

    #viewport {
        padding: 4px;
    }

    #btnZoomIn,
    #btnZoomOut,
    #btnZoomFit,
    #zoomLabel {
        display: none !important;
    }
}
#painelCatalogoSessao {
    padding-right: 8px;
}

#painelCatalogoSessao .sessao-catalogo-topo,
#painelCatalogoSessao .sessao-catalogo-acoes,
#painelCatalogoSessao .sessao-catalogo-indicator,
#painelCatalogoSessao .sessao-lista-itens {
    width: 240px;
    max-width: 100%;
}

#painelCatalogoSessao .sessao-catalogo-topo,
#painelCatalogoSessao .sessao-catalogo-acoes {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#painelCatalogoSessao .sessao-catalogo-linha {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 40px 40px;
    gap: 8px;
}

#painelCatalogoSessao .sessao-catalogo-linha > button {
    width: 40px;
    min-width: 40px;
    padding: 0;
}

#painelCatalogoSessao .sessao-catalogo-acoes button {
    width: 100%;
}

#painelCatalogoSessao .sessao-lista-itens {
    margin-top: 10px;
    display: grid;
    grid-template-columns: repeat(2, 108px);
    gap: 10px;
    align-content: start;
    overflow: visible;
    padding-right: 12px;
}

#painelCatalogoSessao .sessao-lista-itens .catalogo-item-card {
    width: 108px;
    text-align: center;
}

.sessao-lista-itens .catalogo-item-card img {
    width: 100px;
    height: 100px;
    object-fit: contain;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: grab;
}

.sessao-catalogo-indicator {
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(0,229,255,0.08);
    border: 1px solid rgba(0,229,255,0.25);
    color: #00e5ff;
    font-size: 12px;
}

.sessao-preview-container {
    width: 160px;
    height: 160px;
    border: 1px solid #444;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sessao-preview-container {
    position: relative;
    width: 100%;
    min-height: 260px;
    height: 260px;
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(5, 10, 16, 0.72);
    overflow: hidden;
}

.sessao-preview-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    position: relative;
    z-index: 1;
}

.sessao-preview-placeholder {
    position: absolute;
    color: rgba(255,255,255,0.34);
    font-size: 14px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    pointer-events: none;
}

.sessao-preview-container img[src] + .sessao-preview-placeholder {
    display: none;
}

.sessao-drawer-overlay {
    position: fixed;
    inset: 0;
    z-index: 2200;
    display: none;
    justify-content: flex-end;
    background: rgba(2, 7, 12, 0.34);
    backdrop-filter: blur(2px);
}

.sessao-drawer-card {
    width: min(480px, 100vw);
    height: 100%;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, rgba(17, 23, 31, 0.98), rgba(8, 12, 18, 0.98));
    border-left: 1px solid rgba(0, 229, 255, 0.16);
    box-shadow: -18px 0 38px rgba(0, 0, 0, 0.42);
    transform: translateX(100%);
    transition: transform 0.22s ease;
}

.sessao-drawer-overlay.aberto .sessao-drawer-card {
    transform: translateX(0);
}

.sessao-drawer-card-sm {
    width: min(420px, 100vw);
}

.sessao-drawer-header {
    padding: 20px 22px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sessao-drawer-kicker {
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(0, 229, 255, 0.84);
    margin-bottom: 6px;
}

.sessao-drawer-header h3 {
    margin: 0;
    font-size: 24px;
    color: #f3fbff;
}

.sessao-drawer-header p {
    margin: 8px 0 0;
    font-size: 13px;
    line-height: 1.45;
    color: rgba(255,255,255,0.72);
}

.sessao-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 22px 22px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sessao-drawer-label {
    font-size: 14px;
    color: rgba(255,255,255,0.92);
}

.sessao-drawer-checks {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sessao-drawer-check {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: rgba(255,255,255,0.86);
}

.sessao-conversao-config {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border-radius: 12px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
}

.sessao-drawer-file-btn,
.sessao-drawer-actions button {
    border: 1px solid rgba(0, 229, 255, 0.2);
    background: rgba(0, 229, 255, 0.08);
    color: #dffbff;
    border-radius: 10px;
    min-height: 40px;
    padding: 0 14px;
}

.sessao-drawer-file-btn:hover,
.sessao-drawer-actions button:hover {
    background: rgba(0, 229, 255, 0.16);
}

.sessao-drawer-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 16px 22px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

#modalSessaoExcluirCatalogo .sessao-drawer-actions button:first-child {
    background: rgba(198, 40, 40, 0.16);
    border-color: rgba(198, 40, 40, 0.35);
}

#modalSessaoExcluirCatalogo .sessao-drawer-actions button:first-child:hover {
    background: rgba(198, 40, 40, 0.25);
}

@media (max-width: 768px) {
    .sessao-drawer-card,
    .sessao-drawer-card-sm {
        width: 100vw;
    }

    .sessao-drawer-header {
        padding: 16px 16px 12px;
    }

    .sessao-drawer-body {
        padding: 14px 16px 18px;
    }

    .sessao-drawer-actions {
        padding: 14px 16px 16px;
    }
}
