/* ================================================================
   STC ALLCONTROL — MOBILE APP UI (< 768px)
   Interfaz nativa diseñada para celular — reemplaza desktop
   ================================================================ */

@media (max-width: 768px) {

    /* ===== OCULTAR TODO EL DESKTOP ===== */
    .top-header,
    .sidebar,
    .sidebar-toggle,
    .tab-bar,
    .panels-container,
    .content-wrapper,
    .bg-grid,
    .bg-particles,
    .bg-layer,
    #appBody {
        display: none !important;
    }

    .app-shell {
        display: flex !important;
        flex-direction: column !important;
        height: 100vh !important;
        height: 100dvh !important;
        background: #f1f5f9 !important;
    }

    /* ===== MOBILE APP STRUCTURE ===== */
    #m-app {
        display: flex;
        flex-direction: column;
        flex: 1;
        overflow: hidden;
    }

    /* ===== MOBILE HEADER ===== */
    #m-app-header {
        display: flex;
        align-items: center;
        padding: 14px 16px;
        background: #1e293b;
        gap: 10px;
        flex-shrink: 0;
        box-shadow: 0 2px 10px rgba(0,0,0,0.25);
        padding-top: calc(14px + env(safe-area-inset-top, 0px));
    }

    #m-app-header img {
        width: 30px;
        height: 30px;
        border-radius: 8px;
        border: 1.5px solid rgba(255,255,255,0.2);
    }

    #m-app-header .m-h-title {
        flex: 1;
        font-size: 14px;
        font-weight: 800;
        color: #f1f5f9;
    }

    #m-app-header .m-h-sub {
        font-size: 9px;
        color: #93c5fd;
        font-weight: 500;
        margin-top: 1px;
    }

    .m-h-btn {
        width: 32px;
        height: 32px;
        border-radius: 8px;
        border: none;
        background: rgba(255,255,255,0.08);
        color: #94a3b8;
        font-size: 13px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .m-h-btn:active {
        background: rgba(255,255,255,0.15);
    }

    /* ===== MOBILE CONTENT AREA ===== */
    #m-app-body {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        background: #f1f5f9;
    }

    /* ===== MOBILE BOTTOM NAV ===== */
    #m-app-nav {
        display: flex;
        align-items: stretch;
        justify-content: space-around;
        background: #1e293b;
        border-top: 1px solid rgba(148,163,184,0.1);
        flex-shrink: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .m-nav-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 10px 12px;
        cursor: pointer;
        flex: 1;
        border: none;
        background: none;
    }

    .m-nav-btn i {
        font-size: 17px;
        color: #64748b;
        transition: color 0.2s;
    }

    .m-nav-btn span {
        font-size: 9px;
        font-weight: 600;
        color: #64748b;
        transition: color 0.2s;
    }

    .m-nav-btn.active i { color: #3b82f6; }
    .m-nav-btn.active span { color: #3b82f6; }

    .m-nav-btn:active {
        background: rgba(255,255,255,0.05);
    }

    /* ===== EMPRESA CARDS ===== */
    .m-emp-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        padding: 16px;
    }

    .m-emp-card {
        background: white;
        border-radius: 14px;
        padding: 18px 14px;
        text-align: center;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06);
        cursor: pointer;
        transition: transform 0.15s;
        border: 2px solid transparent;
    }

    .m-emp-card:active {
        transform: scale(0.95);
    }

    .m-emp-card .dot {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        margin: 0 auto 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
        font-size: 12px;
        font-weight: 800;
    }

    .m-emp-card .name {
        font-size: 11px;
        font-weight: 700;
        color: #0f172a;
        line-height: 1.3;
    }

    /* ===== MÓDULOS GRID ===== */
    .m-mod-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
        padding: 16px;
    }

    .m-mod-card {
        background: white;
        border-radius: 14px;
        padding: 16px 8px;
        text-align: center;
        box-shadow: 0 2px 6px rgba(0,0,0,0.05);
        cursor: pointer;
        transition: transform 0.15s;
    }

    .m-mod-card:active {
        transform: scale(0.93);
    }

    .m-mod-card .icon {
        width: 38px;
        height: 38px;
        border-radius: 10px;
        margin: 0 auto 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 15px;
        color: white;
    }

    .m-mod-card .label {
        font-size: 9px;
        font-weight: 700;
        color: #334155;
        line-height: 1.2;
    }

    /* ===== SECTION TITLES ===== */
    .m-section {
        font-size: 10px;
        font-weight: 800;
        text-transform: uppercase;
        color: #64748b;
        letter-spacing: 1px;
        padding: 14px 16px 6px;
    }

    /* ===== MODULE VIEW ===== */
    #m-module-view {
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* ===== FORMS — mobile single column ===== */
    #m-module-view [style*="grid-template-columns:1fr 1fr 1fr"],
    #m-module-view [style*="grid-template-columns: 1fr 1fr 1fr"],
    #m-module-view [style*="grid-template-columns:1fr 1fr"],
    #m-module-view [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* ===== TABLES — horizontal scroll ===== */
    #m-module-view table {
        font-size: 10px !important;
    }

    #m-module-view [style*="overflow:hidden"],
    #m-module-view [style*="overflow: hidden"] {
        overflow: auto !important;
    }

    /* ===== INPUTS — prevent iOS zoom ===== */
    #m-module-view input,
    #m-module-view select,
    #m-module-view textarea {
        font-size: 16px !important;
    }

    /* ===== MODALS ON MOBILE ===== */
    [style*="position:fixed"][style*="z-index:99999"] > div:first-child,
    [style*="position:fixed"][style*="z-index: 99999"] > div:first-child {
        width: 95vw !important;
        max-width: 95vw !important;
        max-height: 88vh !important;
        border-radius: 14px !important;
    }

    /* ===== LOGIN — mobile friendly ===== */
    .login-overlay {
        padding: 16px !important;
    }

    .login-content {
        max-width: 100% !important;
    }
}

/* ===== DESKTOP — hide mobile elements ===== */
@media (min-width: 769px) {
    #m-app {
        display: none !important;
    }
}
