/* Simulator Modal CSS */
.sim-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5); backdrop-filter: none; -webkit-backdrop-filter: none;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.sim-modal-overlay.active {
    display: flex;
}

.sim-modal {
    background: #fff;
    width: 90%;
    max-width: 900px;
    height: 90vh;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.sim-header {
    background-color: #0088c4;
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    font-size: 1.1rem;
}

.sim-banner {
    background-color: #0088c4;
    background-image: url('../img/fondo-D0v1EIkB.jpg');
    background-size: cover;
    background-position: center;
    background-blend-mode: multiply;
    padding: 15px 20px;
}

.sim-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.sim-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Orange Button */
.sim-btn-orange {
    background: #ff9800;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    align-self: flex-start;
}
.sim-btn-orange:hover {
    background: #f57c00;
}

/* Status Box */
.sim-status-box {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    padding: 12px 15px;
    border-radius: 5px;
    color: #0369a1;
}

/* Cards */
.sim-card {
    border: 1px solid #e5e7eb;
    border-radius: 5px;
    padding: 15px;
}
.sim-card-title {
    font-weight: bold;
    margin-bottom: 15px;
    color: #374151;
    font-size: 0.95rem;
}

/* Inputs and Buttons Inline */
.sim-input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}
.sim-input-group input[type="text"] {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    outline: none;
    background-color: #ffffff !important;
    color: #333333 !important;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.sim-input-group input[type="text"]:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.sim-input-group button {
    padding: 8px 15px;
    border: 1px solid #d1d5db;
    background: #fff;
    color: #9ca3af;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
}
.sim-input-group button:hover {
    background: #f3f4f6;
}

/* Subtext */
.sim-subtext {
    font-size: 0.8rem;
    color: #6b7280;
    margin-top: 10px;
}

/* Sliders */
.sim-slider-group {
    margin-bottom: 15px;
}
.sim-slider-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: #4b5563;
    margin-bottom: 5px;
}
.sim-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    background: #bfdbfe;
    border-radius: 2px;
    outline: none;
}
.sim-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #3b82f6;
    cursor: pointer;
}

/* Toggles & Presets */
.sim-controls-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    margin-bottom: 15px;
}
.sim-toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: #374151;
    cursor: pointer;
}
/* Switch styling */
.sim-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}
.sim-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.sim-switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 20px;
}
.sim-switch-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
.sim-switch input:checked + .sim-switch-slider {
    background-color: #3b82f6;
}
.sim-switch input:checked + .sim-switch-slider:before {
    transform: translateX(16px);
}

.sim-preset-btn {
    border: 1px solid #3b82f6;
    color: #3b82f6;
    background: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    font-weight: 600;
}
.sim-preset-btn:hover {
    background: #eff6ff;
}

.sim-auto-select {
    display: flex;
    flex-direction: column;
}
.sim-auto-select span {
    font-size: 0.7rem;
    color: #9ca3af;
    text-align: center;
    margin-bottom: -5px;
}
.sim-auto-select select {
    padding: 5px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    outline: none;
    color: #6b7280;
}

/* Board Image */
.sim-board-container {
    text-align: center;
    padding: 10px;
}
.sim-board-img {
    max-width: 100%;
    height: auto;
    border-radius: 5px;
}

/* Terminal */
.sim-terminal-container {
    background: #181818;
    border-radius: 8px;
    padding: 15px;
    color: #94a3b8;
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 15px;
}
.sim-terminal-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}
.sim-terminal-title-area {
    display: flex;
    align-items: center;
    gap: 10px;
}
.sim-terminal-title {
    color: #38bdf8;
    font-weight: bold;
    font-size: 0.95rem;
}
.sim-terminal-dots {
    font-size: 0.75rem;
    color: #888888;
}
.sim-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-left: 2px;
}
.sim-dot.serial { background: #facc15; }
.sim-dot.bt { background: #3b82f6; }
.sim-dot.ir { background: #10b981; }
.sim-dot.sys { background: #f43f5e; }

.sim-terminal-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    font-size: 0.85rem;
    color: white;
    font-weight: bold;
}
.sim-terminal-filters .sim-toggle-label {
    color: white;
}

.sim-terminal-actions {
    display: flex;
    gap: 15px;
    align-items: center;
}
.sim-mui-select {
    position: relative;
    display: inline-block;
}
.sim-mui-select span {
    position: absolute;
    top: -8px;
    left: 8px;
    background: white;
    padding: 0 4px;
    font-size: 0.65rem;
    color: #6b7280;
}
.sim-mui-select select {
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    outline: none;
    color: #374151;
    background: transparent;
    font-size: 0.85rem;
    min-width: 100px;
}
.sim-terminal-container .sim-mui-select span {
    background: #181818;
    color: #94a3b8;
}
.sim-terminal-container .sim-mui-select select {
    border-color: #383838;
    color: white;
}

.sim-btn-clear {
    background: transparent;
    border: 1px solid #383838;
    color: white;
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.8rem;
}
.sim-btn-clear:hover {
    background: #262626;
}

.sim-terminal-logs {
    background: #020617;
    border-radius: 5px;
    padding: 10px;
    height: 120px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 0.85rem;
    border: 1px solid #262626;
}
.sim-log-line {
    margin-bottom: 3px;
}
.sim-log-serial { color: #facc15; }
.sim-log-bt { color: #3b82f6; }
.sim-log-ir { color: #10b981; }
.sim-log-sys { color: #f43f5e; }

.sim-footer {
    text-align: center;
    padding: 15px;
    font-size: 0.85rem;
    color: #6b7280;
    background: #fef3c7;
    border: 1px solid #fde68a;
    border-radius: 5px;
    margin-top: 10px;
}

/* -------------------------------------------------------------
   RESPONSIVE DESIGN PARA TABLETS Y TELÉFONOS (SIMULADOR)
   ------------------------------------------------------------- */
@media (max-width: 900px) {
    .sim-modal {
        width: 96% !important;
        max-width: 96vw !important;
        height: 94vh !important;
    }
    .sim-header {
        padding: 10px 15px !important;
        font-size: 1rem !important;
    }
    .sim-body {
        padding: 12px !important;
        gap: 10px !important;
    }
}

@media (max-width: 600px) {
    .sim-modal {
        width: 100% !important;
        max-width: 100vw !important;
        height: 100% !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }
    .sim-banner {
        padding: 10px 12px !important;
    }
    .sim-banner-title {
        font-size: 1.1rem !important;
    }
    .sim-banner-subtitle {
        font-size: 0.8rem !important;
    }
    .sim-controls {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }
    .sim-btn-orange {
        padding: 8px 12px !important;
        font-size: 0.85rem !important;
    }
    .kit-board-container {
        max-width: 100% !important;
        overflow-x: auto !important;
    }
}


/* =============================================================
   MODO PANTALLA GRANDE / EXPLICACIÓN PARA EL SIMULADOR AUTANA
   ============================================================= */

/* Aceleración por Hardware y optimización para PCs de bajos recursos */
.MuiDrawer-paper svg[viewBox="0 0 2560 1440"] {
    transform: translateZ(0) !important;
    backface-visibility: hidden !important;
    will-change: transform !important;
    /* contain removed to avoid svg viewBox clipping */
}

.MuiDrawer-paper svg[viewBox="0 0 2560 1440"] image {
    image-rendering: -webkit-optimize-contrast !important;
}

/* Animaciones de entrada para el Drawer del simulador */
@keyframes simDrawerSlideIn {
    0% {
        transform: translate3d(100%, 0, 0);
        opacity: 0.6;
    }
    100% {
        transform: translate3d(0, 0, 0);
        opacity: 1;
    }
}

@keyframes simContentEntrance {
    0% {
        opacity: 0;
        transform: translateY(22px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes simChipPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.08);
    }
}

/* Efectos visuales e interacción animada para el botón flotante morado del chip */
div[style*="translateY(-50%)"] .MuiIconButton-colorSecondary,
div[style*="translateY(-50%)"] button:nth-of-type(2) {
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.25s ease, filter 0.25s ease !important;
}

div[style*="translateY(-50%)"] .MuiIconButton-colorSecondary:hover,
div[style*="translateY(-50%)"] button:nth-of-type(2):hover {
    transform: translateX(-6px) scale(1.07) !important;
    filter: brightness(1.12) !important;
    box-shadow: -4px 3px 18px rgba(156, 39, 176, 0.55) !important;
}

div[style*="translateY(-50%)"] .MuiIconButton-colorSecondary:active,
div[style*="translateY(-50%)"] button:nth-of-type(2):active,
div[style*="translateY(-50%)"] .MuiIconButton-colorSecondary.sim-btn-active-pop,
div[style*="translateY(-50%)"] button:nth-of-type(2).sim-btn-active-pop {
    transform: translateX(-3px) scale(0.92) !important;
    transition-duration: 0.08s !important;
}

div[style*="translateY(-50%)"] .MuiIconButton-colorSecondary svg,
div[style*="translateY(-50%)"] button:nth-of-type(2) svg {
    transition: transform 0.28s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
}

div[style*="translateY(-50%)"] .MuiIconButton-colorSecondary:hover svg,
div[style*="translateY(-50%)"] button:nth-of-type(2):hover svg {
    transform: rotate(-10deg) scale(1.15) !important;
}

/* Drawer del simulador al abrir con animación fluida */
body:not(.low-perf-mode) .MuiDrawer-paper.sim-drawer-enter {
    animation: simDrawerSlideIn 0.38s cubic-bezier(0.16, 1, 0.3, 1) forwards !important;
    will-change: transform, opacity;
}

body:not(.low-perf-mode) .MuiDrawer-paper.sim-drawer-enter .sim-presentation-grid > * {
    animation: simContentEntrance 0.44s cubic-bezier(0.16, 1, 0.3, 1) both;
}

body:not(.low-perf-mode) .MuiDrawer-paper.sim-drawer-enter .sim-presentation-grid > *:nth-child(1) {
    animation-delay: 0.04s;
}

body:not(.low-perf-mode) .MuiDrawer-paper.sim-drawer-enter .sim-presentation-grid > *:nth-child(2) {
    animation-delay: 0.1s;
}

body:not(.low-perf-mode) .MuiDrawer-paper.sim-drawer-enter .sim-presentation-grid > *:nth-child(3) {
    animation-delay: 0.16s;
}

/* =============================================================
   MODO PRESENTACIÓN KIT PEQUEÑOS INGENIEROS (EXCLUSIVO PARA PC / ESCRITORIO >= 993px)
   ============================================================= */
@media (min-width: 993px) {
    /* Modo pantalla grande para el cajón del simulador en PC */
    .MuiDrawer-paper.sim-fullscreen-drawer,
    .MuiDrawer-paper:has(svg[viewBox="0 0 2560 1440"]):not(.sim-lateral-drawer):not(.sim-mobile-drawer),
    .MuiDrawer-paper:has(#sim-custom-container-bottom):not(.sim-lateral-drawer):not(.sim-mobile-drawer) {
        width: 100vw !important;
        max-width: 100vw !important;
        left: auto !important;
        right: 0 !important;
        transition: transform 320ms cubic-bezier(0.16, 1, 0.3, 1), width 0.25s ease !important;
    }

    /* Solo si el usuario activa voluntariamente el modo lateral en PC se achica */
    .MuiDrawer-paper.sim-lateral-drawer {
        width: 850px !important;
        max-width: 85vw !important;
        left: auto !important;
        right: 0 !important;
        transition: width 0.2s ease !important;
    }

    /* Layout vertical en renglones: Tarjeta grande arriba cubriendo el ancho + Controles en renglón abajo */
    .MuiDrawer-paper.sim-fullscreen-drawer .sim-presentation-grid {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        width: 100% !important;
        padding: 12px 20px 40px 20px !important;
        box-sizing: border-box !important;
        overflow-y: auto !important;
        background: #f8fafc !important;
    }

    /* 1. Barra de estado y botón simular arriba */
    .MuiDrawer-paper.sim-fullscreen-drawer .sim-presentation-grid > *:nth-child(1) {
        width: 100% !important;
        max-width: 1600px !important;
        margin: 0 auto 12px auto !important;
        box-sizing: border-box !important;
    }

    /* 2. Placa del Kit en Pantalla Grande: Cubriendo la parte de arriba en tamaño grande */
    .MuiDrawer-paper.sim-fullscreen-drawer .sim-board-sticky-wrap,
    .MuiDrawer-paper.sim-fullscreen-drawer .kit-board-container,
    .MuiDrawer-paper:has(svg[viewBox="0 0 2560 1440"]) div:has(> svg[viewBox="0 0 2560 1440"]) {
        width: 100% !important;
        max-width: 1600px !important;
        height: auto !important;
        min-height: 460px !important;
        margin: 0 auto 16px auto !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        background: #ffffff !important;
        border: 1.5px solid #cbd5e1 !important;
        border-radius: 12px !important;
        padding: 10px 14px !important;
        box-sizing: border-box !important;
        box-shadow: 0 4px 20px rgba(0,0,0,0.06) !important;
        position: relative !important;
        z-index: 1 !important;
    }

    .MuiDrawer-paper.sim-fullscreen-drawer .sim-board-sticky-wrap svg,
    .MuiDrawer-paper.sim-fullscreen-drawer .kit-board-container svg,
    .MuiDrawer-paper:has(svg[viewBox="0 0 2560 1440"]) svg[viewBox="0 0 2560 1440"] {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: 460px !important;
        max-height: 68vh !important;
        aspect-ratio: 2560 / 1440 !important;
        object-fit: contain !important;
        display: block !important;
        margin: 0 auto !important;
        transform: translateZ(0);
    }

    /* Eliminar por completo el recuadro/borde pulsante y la línea atravesada sobre la placa en simulación */
    .MuiDrawer-paper div:has(> svg[viewBox="0 0 2560 1440"]) > div,
    .MuiDrawer-paper .kit-board-container > div:not(:has(svg)),
    .MuiDrawer-paper .sim-board-sticky-wrap > div:not(:has(svg)),
    .MuiDrawer-paper div[style*="position: absolute"][style*="border"],
    .MuiDrawer-paper div[style*="position:absolute"][style*="border"] {
        display: none !important;
        border: none !important;
        outline: none !important;
        box-shadow: none !important;
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    .sim-custom-controls-bottom {
        position: relative !important;
        z-index: 2 !important;
    }

    /* 3. Renglón de Controles de Sensores: 2 columnas simétricas perfectamente combinadas */
    .MuiDrawer-paper.sim-fullscreen-drawer .sim-custom-controls-bottom {
        width: 100% !important;
        max-width: 1600px !important;
        margin: 0 auto 18px auto !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 18px !important;
        box-sizing: border-box !important;
        align-items: stretch !important;
    }

    .MuiDrawer-paper.sim-fullscreen-drawer .sim-custom-controls-bottom .sim-card {
        margin-bottom: 0 !important;
        height: 100% !important;
        box-sizing: border-box !important;
        background: #ffffff !important;
        border: 1.5px solid #cbd5e1 !important;
        border-radius: 12px !important;
        box-shadow: 0 2px 10px rgba(0,0,0,0.04) !important;
        display: flex !important;
        flex-direction: column !important;
    }

    /* 4. Renglón del Terminal del Simulador: Abarcando todo el ancho abajo */
    .MuiDrawer-paper.sim-fullscreen-drawer .sim-custom-controls-top {
        width: 100% !important;
        max-width: 1600px !important;
        margin: 0 auto 18px auto !important;
        box-sizing: border-box !important;
    }

    .MuiDrawer-paper.sim-fullscreen-drawer .sim-custom-controls-top .sim-terminal-container {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* 5. Pie de página o mensaje informativo */
    .MuiDrawer-paper.sim-fullscreen-drawer .sim-presentation-grid > *:last-child {
        width: 100% !important;
        max-width: 1600px !important;
        margin: 0 auto !important;
        box-sizing: border-box !important;
    }
}

/* =============================================================
   RESPONSIVE DESIGN PARA TABLETS Y TELÉFONOS (MODO ANTERIOR ADAPTADO <= 992px)
   ============================================================= */
@media (max-width: 992px) {
    /* El botón de modo presentación de PC no debe verse en móviles o tablets */
    #btnSimExpandToggle {
        display: none !important;
    }

    /* Panel lateral estándar proporcional en Tablets */
    .MuiDrawer-paper,
    .MuiDrawer-paper.sim-mobile-drawer {
        width: 520px !important;
        max-width: 88vw !important;
        left: auto !important;
        right: 0 !important;
        transition: transform 220ms ease !important;
    }

    /* Placa adaptada limpia al ancho del dispositivo sin deformar ni forzar alturas gigantes */
    .MuiDrawer-paper svg[viewBox="0 0 2560 1440"],
    .sim-board-sticky-wrap svg,
    .kit-board-container svg {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: 36vh !important;
        object-fit: contain !important;
        display: block !important;
        margin: 0 auto !important;
    }

    .sim-board-sticky-wrap,
    .kit-board-container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 6px !important;
        margin: 4px 0 10px 0 !important;
        border-radius: 8px !important;
        box-sizing: border-box !important;
    }

    /* Controles de sensores en 1 sola columna vertical */
    .sim-custom-controls-bottom {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: 12px !important;
        margin: 10px 0 !important;
    }

    .sim-custom-controls-bottom .sim-card {
        width: 100% !important;
        margin-bottom: 0 !important;
        box-sizing: border-box !important;
    }

    .sim-custom-controls-top,
    .sim-terminal-container {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .sim-terminal-logs {
        max-height: 120px !important;
        min-height: 80px !important;
    }
}

@media (max-width: 600px) {
    /* Teléfonos móviles: Cajón a pantalla completa limpio con scroll vertical */
    .MuiDrawer-paper,
    .MuiDrawer-paper.sim-mobile-drawer {
        width: 100vw !important;
        max-width: 100vw !important;
        left: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
    }

    .MuiDrawer-paper .MuiBox-root:has(h2) {
        padding: 8px 12px !important;
    }

    .MuiDrawer-paper svg[viewBox="0 0 2560 1440"],
    .sim-board-sticky-wrap svg,
    .kit-board-container svg {
        max-height: 25vh !important;
        min-height: 0 !important;
    }

    .sim-card {
        padding: 10px 12px !important;
    }

    .sim-slider-header,
    .sim-card-title {
        font-size: 13px !important;
    }

    .sim-btn-press {
        min-height: 42px !important;
        font-size: 13px !important;
    }

    .sim-terminal-logs {
        max-height: 100px !important;
        min-height: 65px !important;
        font-size: 11px !important;
    }
}

/* Reglas comunes de interacción y cierre */
.MuiDrawer-root,
.MuiDrawer-root *,
.MuiDrawer-paper,
.MuiDrawer-paper *,
.MuiModal-root,
.MuiModal-root *,
div[data-testid="sentinelStart"],
div[data-testid="sentinelEnd"] {
    outline: none !important;
}

.MuiDrawer-paper .MuiBox-root:has(h2) {
    overflow: visible !important;
    position: relative !important;
    z-index: 100 !important;
}

.MuiDrawer-paper .MuiBox-root button:last-child,
.MuiDrawer-paper button:has(svg[data-testid="CloseIcon"]) {
    position: relative !important;
    z-index: 9999 !important;
    pointer-events: auto !important;
    cursor: pointer !important;
    min-width: 40px !important;
    min-height: 40px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    opacity: 1 !important;
    margin-right: 4px !important;
}

/* =============================================================
   ADAPTACION TOTAL DEL SIMULADOR A MODO OSCURO (DARK MODE)
   ============================================================= */

/* 1. Fondo del cajon del simulador y grid de presentacion */
body.dark-mode .MuiDrawer-paper.sim-fullscreen-drawer,
body.dark-mode .MuiDrawer-paper.sim-lateral-drawer,
body.dark-mode .MuiDrawer-paper:has(svg[viewBox="0 0 2560 1440"]),
body.dark-mode .MuiDrawer-paper:has(#sim-custom-container-bottom),
body.dark-mode .sim-modal {
    background: #181818 !important;
    color: #f1f5f9 !important;
}

body.dark-mode .MuiDrawer-paper.sim-fullscreen-drawer .sim-presentation-grid,
body.dark-mode .sim-presentation-grid {
    background: #141414 !important;
    color: #f1f5f9 !important;
}

/* 2. Cabecera del simulador (Banner azul/oscuro y titulo) */
body.dark-mode .MuiDrawer-paper .MuiBox-root:has(h2),
body.dark-mode .sim-header,
body.dark-mode .sim-banner {
    background-color: #121212 !important;
    background-image: none !important;
    border-bottom: 1px solid #262626 !important;
}

body.dark-mode .MuiDrawer-paper h2 {
    color: #ffffff !important;
}

body.dark-mode #btnSimExpandToggle {
    background: rgba(255, 255, 255, 0.12) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    color: #ffffff !important;
}

body.dark-mode #btnSimExpandToggle:hover {
    background: rgba(255, 255, 255, 0.22) !important;
}

/* 3. Barra de estado superior y alerta "Listo para simular" */
body.dark-mode .sim-presentation-grid > *:nth-child(1) .MuiBox-root,
body.dark-mode .MuiDrawer-paper .MuiBox-root:has(> p):not(:has(button)),
body.dark-mode .sim-status-box {
    background: #1e1e1e !important;
    border: 1px solid #333333 !important;
    color: #38bdf8 !important;
}

body.dark-mode .sim-presentation-grid > *:nth-child(1) p,
body.dark-mode .sim-status-box p {
    color: #38bdf8 !important;
}

/* 4. Tarjeta del circuito PCB (Marco de la placa) */
body.dark-mode .MuiDrawer-paper.sim-fullscreen-drawer .sim-board-sticky-wrap,
body.dark-mode .MuiDrawer-paper.sim-fullscreen-drawer .kit-board-container,
      body.dark-mode .MuiDrawer-paper:has(svg[viewBox="0 0 2560 1440"]) div:has(> svg[viewBox="0 0 2560 1440"]),
body.dark-mode .sim-board-sticky-wrap,
body.dark-mode .kit-board-container,
body.dark-mode .sim-board-container {
    background: #1e1e1e !important;
    border: 1.5px solid #2e2e2e !important;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5) !important;
}

/* 5. Tarjetas de Controles Inferiores (Pulsadores, Comandos y Sensores) */
body.dark-mode .sim-custom-controls-bottom,
body.dark-mode .MuiDrawer-paper .sim-custom-controls-bottom {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

body.dark-mode .sim-card,
body.dark-mode .sim-card-actions-unified,
body.dark-mode .sim-card-sensors,
body.dark-mode .MuiDrawer-paper.sim-fullscreen-drawer .sim-custom-controls-bottom .sim-card {
    background: #1e1e1e !important;
    border: 1.5px solid #2e2e2e !important;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35) !important;
    color: #f1f5f9 !important;
}

body.dark-mode .sim-card-title,
body.dark-mode .sim-card-title span,
body.dark-mode .sim-card-title i {
    color: #38bdf8 !important;
    border-bottom-color: rgba(56, 189, 248, 0.2) !important;
}

body.dark-mode .sim-card p,
body.dark-mode .sim-subtext {
    color: #94a3b8 !important;
}

body.dark-mode .sim-card hr {
    border-top: 1px solid rgba(255, 255, 255, 0.08) !important;
}

/* 6. Pulsadores de la Placa (SW1 - SW5) */
body.dark-mode .sim-piano-key {
    background: linear-gradient(180deg, #262626 0%, #181818 100%) !important;
    border: 1.5px solid #383838 !important;
    border-bottom: 4px solid #0284c7 !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3) !important;
    color: #ffffff !important;
}

body.dark-mode .sim-piano-key:hover {
    background: linear-gradient(180deg, #383838 0%, #262626 100%) !important;
    border-color: #38bdf8 !important;
    border-bottom-color: #38bdf8 !important;
    transform: translateY(-1px) !important;
}

body.dark-mode .sim-piano-key:active,
body.dark-mode .sim-piano-key.active {
    background: #0284c7 !important;
    border-bottom-width: 2px !important;
    transform: translateY(2px) !important;
}

body.dark-mode .sim-piano-key .key-name {
    color: #38bdf8 !important;
}

body.dark-mode .sim-piano-key .key-sub {
    color: #94a3b8 !important;
}

body.dark-mode .sim-note-badge {
    background: rgba(2, 132, 199, 0.2) !important;
    border: 1px solid rgba(56, 189, 248, 0.35) !important;
    color: #38bdf8 !important;
}

/* 7. Entradas de texto y botones de comando (BT, IR, Serial) */
body.dark-mode .sim-input-group input[type="text"] {
    background-color: #141414 !important;
    color: #f1f5f9 !important;
    border: 1px solid #383838 !important;
}

body.dark-mode .sim-input-group input[type="text"]::placeholder {
    color: #888888 !important;
}

body.dark-mode .sim-input-group input[type="text"]:focus {
    border-color: #38bdf8 !important;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2) !important;
}

body.dark-mode .sim-input-group button {
    background: #0284c7 !important;
    color: #ffffff !important;
    border: none !important;
    font-weight: 700 !important;
    box-shadow: 0 2px 6px rgba(2, 132, 199, 0.3) !important;
}

body.dark-mode .sim-input-group button:hover {
    background: #0369a1 !important;
    box-shadow: 0 3px 8px rgba(2, 132, 199, 0.45) !important;
}

/* 8. Deslizadores (Sliders) y Botones de Sensores */
body.dark-mode .sim-slider-header,
body.dark-mode .sim-slider-header span {
    color: #cbd5e1 !important;
}

body.dark-mode .sim-slider {
    background: #262626 !important;
}

body.dark-mode .sim-slider::-webkit-slider-thumb {
    background: #38bdf8 !important;
    box-shadow: 0 0 8px rgba(56, 189, 248, 0.6) !important;
}

body.dark-mode .sim-toggle-label,
body.dark-mode .sim-toggle-label span {
    color: #cbd5e1 !important;
}

body.dark-mode .sim-switch-slider {
    background-color: #383838 !important;
}

body.dark-mode .sim-switch input:checked + .sim-switch-slider {
    background-color: #0284c7 !important;
}

body.dark-mode .sim-preset-btn {
    background: #262626 !important;
    color: #38bdf8 !important;
    border: 1px solid #0284c7 !important;
}

body.dark-mode .sim-preset-btn:hover {
    background: rgba(56, 189, 248, 0.15) !important;
    color: #7dd3fc !important;
    border-color: #38bdf8 !important;
}

body.dark-mode .sim-auto-select select,
body.dark-mode .sim-mui-select select {
    background: #141414 !important;
    color: #f1f5f9 !important;
    border: 1px solid #383838 !important;
}

body.dark-mode .sim-auto-select span,
body.dark-mode .sim-mui-select span {
    background: #1e1e1e !important;
    color: #94a3b8 !important;
}

/* 9. Terminal del Simulador */
body.dark-mode .sim-terminal-container,
body.dark-mode .MuiDrawer-paper .sim-custom-controls-top .sim-terminal-container {
    background: #111111 !important;
    border: 1px solid #2e2e2e !important;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4) !important;
}

body.dark-mode .sim-terminal-title {
    color: #38bdf8 !important;
}

body.dark-mode .sim-terminal-dots {
    color: #888888 !important;
}

body.dark-mode .sim-terminal-logs {
    background: #0d0d0d !important;
    border: 1px solid #262626 !important;
    color: #cbd5e1 !important;
}

body.dark-mode .sim-btn-clear {
    background: #1e1e1e !important;
    border: 1px solid #383838 !important;
    color: #94a3b8 !important;
}

body.dark-mode .sim-btn-clear:hover {
    background: #2e2e2e !important;
    color: #f87171 !important;
    border-color: #ef4444 !important;
}

/* 10. Pie informativo del simulador */
body.dark-mode .sim-footer,
body.dark-mode .MuiDrawer-paper .MuiPaper-root {
    background: #1e1e1e !important;
    border: 1px solid #333333 !important;
    color: #94a3b8 !important;
}

body.dark-mode .MuiDrawer-paper .MuiPaper-root p {
    color: #94a3b8 !important;
}

/* 11. Scrollbars en Modo Oscuro */
body.dark-mode .sim-presentation-grid::-webkit-scrollbar,
body.dark-mode .sim-terminal-logs::-webkit-scrollbar,
body.dark-mode .MuiDrawer-paper::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

body.dark-mode .sim-presentation-grid::-webkit-scrollbar-track,
body.dark-mode .sim-terminal-logs::-webkit-scrollbar-track,
body.dark-mode .MuiDrawer-paper::-webkit-scrollbar-track {
    background: #141414;
}

body.dark-mode .sim-presentation-grid::-webkit-scrollbar-thumb,
body.dark-mode .sim-terminal-logs::-webkit-scrollbar-thumb,
body.dark-mode .MuiDrawer-paper::-webkit-scrollbar-thumb {
    background: #383838;
    border-radius: 4px;
}

body.dark-mode .sim-presentation-grid::-webkit-scrollbar-thumb:hover,
body.dark-mode .sim-terminal-logs::-webkit-scrollbar-thumb:hover,
body.dark-mode .MuiDrawer-paper::-webkit-scrollbar-thumb:hover {
    background: #505050;
}


/* ========================================================
   FONDOS TRASLÚCIDOS NATURALES PARA TODOS LOS MODALES
   (Permiten ver claramente el área de trabajo y bloques detrás con rgba(0, 0, 0, 0.5))
   ======================================================== */
.compiler-overlay,
.editor-overlay,
.sim-modal-overlay,
.pm-modal-overlay,
.autana-notice-overlay,
#custom-compiler-modal,
#custom-serial-modal,
#custom-examples-modal,
#pmOverlay,
#pinMapOverlay,
#autanaNoticeModal,
.MuiDialog-root .MuiBackdrop-root,
.MuiDrawer-root .MuiBackdrop-root,
.MuiModal-root .MuiBackdrop-root,
.MuiBackdrop-root:not(.MuiBackdrop-invisible),
.swal2-container:not(.swal2-top-end):not(.swal2-bottom-end):not(.swal2-toast-shown):not(:has(.swal2-toast)) {
    --swal2-backdrop: rgba(0, 0, 0, 0.5) !important;
    background: rgba(0, 0, 0, 0.5) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

body.dark-mode .compiler-overlay,
body.dark-mode .editor-overlay,
body.dark-mode .sim-modal-overlay,
body.dark-mode .pm-modal-overlay,
body.dark-mode .autana-notice-overlay,
body.dark-mode #custom-compiler-modal,
body.dark-mode #custom-serial-modal,
body.dark-mode #custom-examples-modal,
body.dark-mode #pmOverlay,
body.dark-mode #pinMapOverlay,
body.dark-mode #autanaNoticeModal,
body.dark-mode .MuiDialog-root .MuiBackdrop-root,
body.dark-mode .MuiDrawer-root .MuiBackdrop-root,
body.dark-mode .MuiModal-root .MuiBackdrop-root,
body.dark-mode .MuiBackdrop-root:not(.MuiBackdrop-invisible),
body.dark-mode .swal2-container:not(.swal2-top-end):not(.swal2-bottom-end):not(.swal2-toast-shown):not(:has(.swal2-toast)) {
    --swal2-backdrop: rgba(0, 0, 0, 0.5) !important;
    background: rgba(0, 0, 0, 0.5) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

/* MODO RENDIMIENTO (PC ANTIGUA): Elimina animaciones pesadas pero NUNCA quita los fondos oscuros */
body.low-perf-mode .compiler-overlay,
body.low-perf-mode .editor-overlay,
body.low-perf-mode .sim-modal-overlay,
body.low-perf-mode .pm-modal-overlay,
body.low-perf-mode .autana-notice-overlay,
body.low-perf-mode #custom-compiler-modal,
body.low-perf-mode #custom-serial-modal,
body.low-perf-mode #custom-examples-modal,
body.low-perf-mode #projectManagerModal,
body.low-perf-mode #pmOverlay,
body.low-perf-mode #pinMapOverlay,
body.low-perf-mode #autanaNoticeModal,
body.low-perf-mode .MuiDialog-root .MuiBackdrop-root,
body.low-perf-mode .MuiDrawer-root .MuiBackdrop-root,
body.low-perf-mode .MuiModal-root .MuiBackdrop-root,
body.low-perf-mode .MuiBackdrop-root:not(.MuiBackdrop-invisible),
body.low-perf-mode .swal2-container:not(.swal2-top-end):not(.swal2-bottom-end):not(.swal2-toast-shown):not(:has(.swal2-toast)),
body.dark-mode.low-perf-mode .compiler-overlay,
body.dark-mode.low-perf-mode .editor-overlay,
body.dark-mode.low-perf-mode .sim-modal-overlay,
body.dark-mode.low-perf-mode .pm-modal-overlay,
body.dark-mode.low-perf-mode .autana-notice-overlay,
body.dark-mode.low-perf-mode #custom-compiler-modal,
body.dark-mode.low-perf-mode #custom-serial-modal,
body.dark-mode.low-perf-mode #custom-examples-modal,
body.dark-mode.low-perf-mode #projectManagerModal,
body.dark-mode.low-perf-mode #pmOverlay,
body.dark-mode.low-perf-mode #pinMapOverlay,
body.dark-mode.low-perf-mode #autanaNoticeModal,
body.dark-mode.low-perf-mode .MuiDialog-root .MuiBackdrop-root,
body.dark-mode.low-perf-mode .MuiDrawer-root .MuiBackdrop-root,
body.dark-mode.low-perf-mode .MuiModal-root .MuiBackdrop-root,
body.dark-mode.low-perf-mode .MuiBackdrop-root:not(.MuiBackdrop-invisible),
body.dark-mode.low-perf-mode .swal2-container:not(.swal2-top-end):not(.swal2-bottom-end):not(.swal2-toast-shown):not(:has(.swal2-toast)) {
    background: rgba(0, 0, 0, 0.5) !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
    opacity: 1 !important;
}

/* NOTIFICACIONES Y TOASTS: CERO DIFUMINADO Y FONDO 100% TRANSPARENTE */
body.swal2-toast-shown .swal2-container,
div:where(.swal2-container):has(.swal2-toast),
.swal2-container.swal2-top-end,
.swal2-container.swal2-top-start,
.swal2-container.swal2-bottom-end,
.swal2-container.swal2-bottom-start,
.swal2-container:has(> .swal2-toast),
body.dark-mode.swal2-toast-shown .swal2-container,
body.dark-mode div:where(.swal2-container):has(.swal2-toast),
body.dark-mode .swal2-container.swal2-top-end,
body.dark-mode .swal2-container.swal2-bottom-end,
body.dark-mode .swal2-container:has(> .swal2-toast) {
    background: transparent !important;
    background-color: transparent !important;
    --swal2-backdrop: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    pointer-events: none !important;
}

.swal2-popup.swal2-toast,
body.dark-mode .swal2-popup.swal2-toast {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16) !important;
    pointer-events: auto !important;
}

/* Modal GPIO: fondo unificado sin degradados */
.autana-pin-modal-popup,
.swal2-popup.autana-pin-modal-popup {
    background: #ffffff !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 12px !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25) !important;
}
body.dark-mode .autana-pin-modal-popup,
body.dark-mode .swal2-popup.autana-pin-modal-popup {
    background: #1e293b !important;
    border: 1px solid #334155 !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5) !important;
}

/* Modales apilados: cuando Selección de Dispositivo está abierto sobre el Drawer, el backdrop del Drawer se apaga para que Selección de Dispositivo cubra toda la pantalla uniformemente con 0.5 sin doble oscurecimiento */
body.has-compiler-modal-open .MuiDrawer-root .MuiBackdrop-root,
body.dark-mode.has-compiler-modal-open .MuiDrawer-root .MuiBackdrop-root {
    opacity: 0 !important;
}

/* Sub-modales y monitor serial abiertos sobre Selección de Dispositivo */
body.has-compiler-modal-open #custom-serial-modal,
body.has-compiler-modal-open .MuiDialog-root .MuiBackdrop-root,
body.dark-mode.has-compiler-modal-open #custom-serial-modal,
body.dark-mode.has-compiler-modal-open .MuiDialog-root .MuiBackdrop-root {
    background: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}
/* NUNCA oscurecer ni difuminar el fondo cuando se abre un menú desplegable (Opciones, Ejemplos, etc.) */
.MuiBackdrop-invisible,
.MuiMenu-root .MuiBackdrop-root,
.MuiPopover-root .MuiBackdrop-root,
body.dark-mode .MuiBackdrop-invisible,
body.dark-mode .MuiMenu-root .MuiBackdrop-root,
body.dark-mode .MuiPopover-root .MuiBackdrop-root,
div[role="presentation"]:not(.MuiDialog-root):not(.MuiDrawer-root) .MuiBackdrop-root {
    background: transparent !important;
    background-color: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
}

/* El Monitor Serial siempre debe estar por encima de todos los modales */
#custom-serial-modal {
    z-index: 500000 !important;
    pointer-events: auto !important;
}

#custom-serial-modal > div {
    position: relative !important;
    z-index: 500001 !important;
    pointer-events: auto !important;
}
