/* ══════════════════════════════════════════════════════
   NEXUS — layout.css
   Estructura principal del visor (fuentes IBM Plex Sans)
   ══════════════════════════════════════════════════════ */

/* 🔥 FORZAR IBM PLEX SANS EN TODOS LOS ELEMENTOS DE LAYOUT */
.viewer-container,
.header,
.logo,
.toolbar,
.tool-btn,
.panel-drawer,
.panel-inner,
.panel-tab,
.panel-close-bar,
.panel-close-bar .pcb-label,
.control-panel,
.control-section,
.control-section h3,
.control-label,
.stats-panel,
.stat-item,
.stat-label,
.stat-value,
#nexusProgressBar,
#nexusProgressLabel,
#mobileToolbarToggle,
#mobileToolbarDropdown,
.mobile-tool-item,
.mobile-tool-item span,
.mobile-nav-row button,
.panel-drawer.right .panel-tab .tab-arrow::before,
.panel-drawer .panel-tab .tab-arrow {
    font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif !important;
}

/* PESOS ESPECÍFICOS */
.logo {
    font-weight: 700 !important;
    letter-spacing: -0.5px;
}
.logo span {
    font-weight: 400 !important;
}

.tool-btn {
    font-weight: 500 !important;
    letter-spacing: 0.3px;
}

.panel-close-bar .pcb-label {
    font-weight: 600 !important;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.control-section h3 {
    font-weight: 600 !important;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.control-label {
    font-weight: 500 !important;
}

.stat-label {
    font-weight: 400 !important;
}

.stat-value {
    font-weight: 600 !important;
}

#nexusProgressLabel {
    font-weight: 400 !important;
}

.mobile-tool-item {
    font-weight: 400 !important;
}
.mobile-tool-item span {
    font-weight: 400 !important;
    letter-spacing: 0.3px;
}

.mobile-nav-row button {
    font-weight: 600 !important;
}

.panel-tab .tab-arrow {
    font-weight: 400 !important;
    letter-spacing: 2px;
}

/* ── FIN FUENTES ── */

.viewer-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: -webkit-fill-available;
    position: relative;
}

/* ══════════════════════════════════════════
   HEADER
══════════════════════════════════════════ */
.header {
    background: #212C3E;
    border-bottom: 1px solid var(--border-color);
    padding: 16px 24px;
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
    display: flex;
    align-items: center;
    justify-content: space-between;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    z-index: 100;
}

.logo {
    font-size: 20px;
    color: #FFFFFF;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.logo span {
    color: #96A1B2;
    font-size: 13px;
}
.logo svg {
    width: 110px;
    height: auto;
    flex-shrink: 0;
}
.logo svg .cls-nexus2 {
    fill: #3C96FE !important;
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* ── Toolbar ── */
.toolbar {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    padding: 0 12px;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: #96A1B2;
    font-size: 11px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
}
.tool-btn span { pointer-events: none; }
.tool-btn:hover {
    background: rgba(150, 161, 178, 0.08);
    border-color: var(--border-color);
    color: #FFFFFF;
    transform: translateY(-1px);
}
.tool-btn.active {
    background: rgba(60, 150, 255, 0.15);
    border-color: #3C96FE;
    color: #3C96FE;
}

/* ══════════════════════════════════════════
   CONTENIDO PRINCIPAL
══════════════════════════════════════════ */
.main-content {
    display: flex;
    flex: 1;
    position: relative;
    overflow: hidden;
}

#viewer {
    flex: 1;
    position: relative;
    background: radial-gradient(ellipse at center, #2C3749 0%, #1C202B 100%);
    touch-action: none;
}
#viewer canvas {
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}
#viewer.measuring {
    cursor: crosshair;
}

/* ══════════════════════════════════════════
   PANEL DRAWERS
══════════════════════════════════════════ */
.panel-drawer {
    position: absolute;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: stretch;
    z-index: 70;
    pointer-events: none;
}
.panel-drawer.left  { left: 0; flex-direction: row; }
.panel-drawer.right { right: 0; flex-direction: row-reverse; }

.panel-drawer .panel-inner {
    width: 320px;
    background: rgba(28, 32, 43, 0.97);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    padding: 16px 16px 80px;
    overflow-y: auto;
    box-shadow: 4px 0 32px rgba(0,0,0,0.5);
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: all;
    height: 100%;
    box-sizing: border-box;
}
.panel-drawer.right .panel-inner {
    border-right: none;
    border-left: 1px solid var(--border-color);
    box-shadow: -4px 0 32px rgba(0,0,0,0.5);
}

.panel-drawer.left  .panel-inner { transform: translateX(-100%); }
.panel-drawer.right .panel-inner { transform: translateX(100%); }
.panel-drawer.left.open  .panel-inner { transform: translateX(0); }
.panel-drawer.right.open .panel-inner { transform: translateX(0); }

.panel-tab {
    width: 22px;
    align-self: center;
    background: rgba(28, 32, 43, 0.97);
    border: 1px solid var(--border-color);
    border-radius: 0 8px 8px 0;
    padding: 18px 3px;
    cursor: pointer;
    pointer-events: all;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    user-select: none;
    transition: background 0.2s, border-color 0.2s;
    position: relative;
    z-index: 1;
}
.panel-drawer.right .panel-tab {
    border-radius: 8px 0 0 8px;
    border-right: none;
    border-left: 1px solid var(--border-color);
}
.panel-tab:hover {
    background: rgba(60, 150, 255, 0.08);
    border-color: #3C96FE;
}
.panel-tab .tab-icon {
    font-size: 14px;
    line-height: 1;
}
.panel-tab .tab-arrow {
    font-size: 9px;
    color: #96A1B2;
    transition: transform 0.3s;
    writing-mode: vertical-lr;
    letter-spacing: 2px;
}
.panel-drawer.right .panel-tab .tab-arrow::before { content: '◀'; }
.panel-drawer.right.open .panel-tab .tab-arrow::before { content: '▶'; }

.panel-close-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px 10px;
    margin: -16px -16px 12px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255,255,255,0.02);
}
.panel-close-bar .pcb-label {
    font-size: 11px;
    color: #96A1B2;
}
.panel-close-bar .pcb-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    color: #96A1B2;
    font-size: 16px;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
    user-select: none;
}
.panel-close-bar .pcb-close:hover {
    background: rgba(217, 92, 92, 0.12);
    border-color: rgba(217, 92, 92, 0.3);
    color: #D95C5C;
}

.control-panel {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    width: auto;
    max-height: none;
    overflow-y: visible;
    box-shadow: none;
    z-index: auto;
    animation: none;
}

.control-section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
}
.control-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}
.control-section h3 {
    font-size: 13px;
    color: #96A1B2;
    margin-bottom: 16px;
}
.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.control-label {
    font-size: 14px;
    color: #FFFFFF;
}

/* ══════════════════════════════════════════
   STATS PANEL
══════════════════════════════════════════ */
.stats-panel {
    position: absolute;
    bottom: 90px;
    right: 20px;
    background: rgba(28, 32, 43, 0.95);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    min-width: 200px;
    z-index: 50;
}
.stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 13px;
}
.stat-item:last-child { margin-bottom: 0; }
.stat-label { color: #96A1B2; }
.stat-value {
    color: #96A1B2;
}

/* ══════════════════════════════════════════
   PROGRESS BAR
══════════════════════════════════════════ */
#nexusProgressBar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    width: 100%;
    height: 3px;
    z-index: 10000;
    pointer-events: none;
    background: rgba(255,255,255,0.04);
    opacity: 0;
    transition: opacity 0.2s ease;
}
#nexusProgressBar.active { opacity: 1; }

#nexusProgressFill {
    height: 100%;
    width: 0%;
    max-width: 100%;
    background: linear-gradient(90deg, #1B4E8C 0%, #3C96FE 55%, #8FC4FF 100%);
    transition: width 0.12s linear;
    box-shadow: 0 0 8px rgba(60,150,255,0.5);
}

#nexusProgressLabel {
    position: fixed;
    top: calc(var(--header-h) + 6px);
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: #3C96FE;
    letter-spacing: 0.05em;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100vw - 32px);
    z-index: 10000;
    background: rgba(33, 44, 62, 0.9);
    padding: 2px 10px;
    border-radius: 0 0 6px 6px;
}
#nexusProgressLabel.active { opacity: 1; }
@media (max-width: 640px) {
    #nexusProgressLabel { display: none !important; }
}

/* ══════════════════════════════════════════
   MOBILE TOOLBAR
══════════════════════════════════════════ */
#mobileToolbarToggle {
    display: none;
    width: 38px;
    height: 38px;
    background: #2C3749;
    border: none;
    border-radius: 8px;
    color: #FFFFFF;
    font-size: 18px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    z-index: 201;
}

#mobileToolbarDropdown {
    display: none;
    position: fixed;
    top: 52px;
    left: 0;
    right: 0;
    background: rgba(28, 32, 43, 0.98);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    z-index: 200;
    padding: 10px 12px;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}
#mobileToolbarDropdown.open { display: flex; }

.mobile-tool-row {
    display: flex;
    gap: 8px;
    align-items: center;
    width: 100%;
}
.mobile-tool-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 6px;
    background: rgba(44, 55, 73, 0.5);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 8px;
    color: #FFFFFF;
    font-size: 10px;
    cursor: pointer;
    transition: background 0.2s;
    text-align: center;
    min-width: 0;
}
.mobile-tool-item:active,
.mobile-tool-item.active {
    background: rgba(60, 150, 255, 0.15);
    border-color: #3C96FE;
}
.mobile-tool-item svg { width: 20px; height: 20px; fill: #FFFFFF; }
.mobile-tool-item span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    font-size: 9px;
    letter-spacing: 0.3px;
}
.mobile-tool-divider {
    height: 1px;
    background: rgba(255,255,255,0.04);
    width: 100%;
    margin: 2px 0;
}
.mobile-nav-row {
    display: flex;
    gap: 8px;
    width: 100%;
}
.mobile-nav-row button {
    flex: 1;
    padding: 10px 8px;
    border-radius: 8px;
    font-size: 11px;
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* ══════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════ */
@media (max-width: 768px) {
    .control-panel,
    .measurement-panel { width: 280px; }
}

@media (max-width: 640px) {
    .header {
        padding: 7px 10px;
        gap: 6px;
        flex-wrap: nowrap;
        min-height: 52px;
        height: 52px;
        overflow: hidden;
    }

    .logo svg { width: 64px !important; height: auto !important; }
    .toolbar { display: none !important; }
    #mobileToolbarToggle { display: flex !important; }

    #openSlicerHeaderBtn {
        font-size: 0 !important;
        padding: 9px !important;
        width: 38px !important;
        height: 38px !important;
        min-width: 38px;
        justify-content: center;
        border-radius: 8px;
        flex-shrink: 0;
    }
    #openSlicerHeaderBtn .carbon-icon {
        width: 18px !important;
        height: 18px !important;
        display: block;
    }

    #pBackBtn {
        font-size: 10px !important;
        padding: 7px 10px !important;
        white-space: nowrap;
        flex-shrink: 0;
        border-radius: 8px;
    }

    .panel-drawer .panel-inner {
        width: 100vw !important;
        max-width: 340px !important;
    }
    .control-panel { font-size: 12px; }

    .stats-panel {
        bottom: 70px;
        right: 8px;
        min-width: 150px;
        padding: 10px;
        font-size: 11px;
    }
}

@media (max-width: 400px) {
    .header { padding: 6px 8px; }
    .logo svg { width: 54px !important; }
    #pBackBtn { font-size: 9px !important; padding: 6px 8px !important; }
    .panel-drawer .panel-inner { max-width: 100vw !important; }
}